Page 1 of 1

ISA DMA Allocation

Posted: Fri Jun 04, 2010 2:42 pm
by HitmanYesman
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:

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

When I run it (for testing), I've already marked the first 4 MB as being used like:

Code: Select all

memset(&bitmap[0], 0xFF, 128);
..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:

Code: Select all

printf("ISA DMA Allocation Test : %d", pmm_alloc_dma(1));
Any help appreciated

Re: ISA DMA Allocation

Posted: Sun Jun 06, 2010 12:07 am
by gerryg400
What's the purpose of this line ?

Code: Select all

            if ((1024 + (i * 32) + j) & 15)
It means that if j=0 or j=16 the body of the if is not executed. That must be a bug.

Re: ISA DMA Allocation

Posted: Mon Jun 07, 2010 2:51 am
by gerryg400
Yes I know, but the logic is reversed. Shouldn't it be...

Code: Select all

if (((1024 + (i * 32) + j) & 15) == 0)
?