ISA DMA Allocation
Posted: Fri Jun 04, 2010 2:42 pm
I've made a function for allocating specifically for ISA DMA drivers, but it's not working correctly.
First off, I'm using a bitmap. This bitmap is to cover memory through the first 16 MB. But the base PFN is at the 4 MB because the first 4 MB are reserved for kernel use. So 1024 (frame) is where the 4 MB mark is.
Here's my function:
When I run it (for testing), I've already marked the first 4 MB as being used like:
..So the very first address (64K multiple) would be 4194304, but instead when ran prints out 4198400 which is a 64K multiple, but it should be printing out the VERY first free address multiple of 64K.
I'm calling it like:
Any help appreciated
First off, I'm using a bitmap. This bitmap is to cover memory through the first 16 MB. But the base PFN is at the 4 MB because the first 4 MB are reserved for kernel use. So 1024 (frame) is where the 4 MB mark is.
Here's my function:
Code: Select all
void* pmm_alloc_dma(uint32 size)
{
uint32 i;
uint32 j;
uint32 c;
uint32 k;
uint32 frame;
if (size == 0)
{
return 0;
}
for (i = 0; i < 128; i++)
{
if (bitmap[i] != 0xFFFFFFFF)
{
for (j = 0; j < 32; j++)
{
uint32 bit = 1 << j;
if ((1024 + (i * 32) + j) & 15)
{
uint32 sbit = i * 32;
sbit += bit;
uint32 free = 0;
for (c = 0; c <= size; c++)
{
if (! pmm_test(sbit + c))
{
free++;
}
if (free == size)
{
frame = i * 32 + j;
for (k = 0; k < size; k++)
{
pmm_set(frame + k);
}
paddr addr = frame * 4096;
return (void *) addr;
}
}
}
}
}
}
return 0;
}
Code: Select all
memset(&bitmap[0], 0xFF, 128);
I'm calling it like:
Code: Select all
printf("ISA DMA Allocation Test : %d", pmm_alloc_dma(1));