1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-12-27 12:01:45 +02:00

libubb/physmem.c (physmem_xlat_vec): more general version of physmem_xlat

This commit is contained in:
Werner Almesberger 2013-01-16 10:15:24 -03:00
parent 66080fe72e
commit 3161d5555b
2 changed files with 43 additions and 0 deletions

View File

@ -16,9 +16,17 @@
#include <sys/types.h>
struct physmem_vec {
unsigned long addr;
size_t len;
};
void *physmem_malloc(size_t size);
void *physmem_calloc(size_t size);
unsigned long physmem_xlat(void *v);
int physmem_xlat_vec(void *v, size_t len,
struct physmem_vec *vec, int vec_len);
int physmem_flush(const void *data, size_t size);
#endif /* !UBB_PHYSMEM_H */

View File

@ -144,6 +144,41 @@ unsigned long physmem_xlat(void *v)
}
int physmem_xlat_vec(void *v, size_t len,
struct physmem_vec *vec, int vec_len)
{
unsigned long vaddr = (unsigned long) v;
unsigned long offset, this_len;
int fd;
int n = 0;
fd = open(PAGEMAP_FILE, O_RDONLY);
if (fd < 0) {
perror(PAGEMAP_FILE);
exit(1);
}
while (len) {
if (n >= vec_len) {
close(fd);
errno = EOVERFLOW;
return -1;
}
offset = vaddr & (PAGE_SIZE-1);
this_len = PAGE_SIZE-offset;
if (this_len > len)
this_len = len;
vec->addr = xlat_one(fd, vaddr);
vec->len = this_len;
vec++;
n++;
vaddr += this_len;
len -= this_len;
}
close(fd);
return n;
}
int physmem_flush(const void *v, size_t size)
{
if (cacheflush((void *) v, size, DCACHE))