mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-04 23:08:07 +02:00
physmem.c: improved correctness and efficiency of alignment
- physmem.c (align_brk): don't waste memory if already aligned - physmem.c (ALIGN, calloc_phys_vec): align by DMA transfer size - physmem.c (calloc_phys_vec): make sure allocations don't straddle page boundaries - physmem.c (xlat_one): print "unsigned long" with %lx, not %x
This commit is contained in:
parent
893884c91f
commit
0dbf29e599
@ -28,19 +28,24 @@
|
||||
#define PM_SWAPPED 62
|
||||
#define PM_PRESENT 63
|
||||
|
||||
#define ALIGN 32 /* DMA transfer size */
|
||||
|
||||
|
||||
static void align_brk(int alignment)
|
||||
{
|
||||
unsigned long addr;
|
||||
unsigned long addr, remainder;
|
||||
|
||||
addr = (unsigned long) sbrk(0);
|
||||
sbrk(alignment-(addr % alignment));
|
||||
remainder = addr % alignment;
|
||||
if (remainder)
|
||||
sbrk(alignment-remainder);
|
||||
}
|
||||
|
||||
|
||||
void **calloc_phys_vec(size_t n, size_t size)
|
||||
{
|
||||
void **vec;
|
||||
unsigned long pos;
|
||||
int i;
|
||||
|
||||
vec = malloc(sizeof(void *)*n);
|
||||
@ -50,7 +55,10 @@ void **calloc_phys_vec(size_t n, size_t size)
|
||||
}
|
||||
|
||||
for (i = 0; i != n; i++) {
|
||||
align_brk(512); /* crude page alignment */
|
||||
align_brk(ALIGN);
|
||||
pos = (unsigned long) sbrk(0);
|
||||
if ((pos & ~(PAGE_SIZE-1)) != ((pos+size) & ~(PAGE_SIZE-1)))
|
||||
sbrk(PAGE_SIZE-(pos & (PAGE_SIZE-1)));
|
||||
vec[i] = sbrk(size);
|
||||
memset(vec[i], 0, size);
|
||||
}
|
||||
@ -94,7 +102,7 @@ static unsigned long xlat_one(int fd, unsigned long vaddr)
|
||||
abort();
|
||||
}
|
||||
paddr = ((map & 0x7fffffffffffffULL) << pshift) | offset;
|
||||
// fprintf(stderr, "0x%x -> 0x%x\n", vaddr, paddr);
|
||||
// fprintf(stderr, "0x%lx -> 0x%lx\n", vaddr, paddr);
|
||||
return paddr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user