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));