ISA DMA Allocation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

ISA DMA Allocation

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: ISA DMA Allocation

Post 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.
If a trainstation is where trains stop, what is a workstation ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: ISA DMA Allocation

Post by gerryg400 »

Yes I know, but the logic is reversed. Shouldn't it be...

Code: Select all

if (((1024 + (i * 32) + j) & 15) == 0)
?
If a trainstation is where trains stop, what is a workstation ?
Post Reply