Page 1 of 1

Mapping physical address to random virtual address?

Posted: Mon May 25, 2009 5:41 am
by AlfaOmega08
Hi, I'm trying to use ACPICA in my kernel. However it requires that the OS provides several functions. One of these is

Code: Select all

void *AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS *physical, ACPI_SIZE length);
This function should map length bytes starting from physical, in the current Page Directory, and return a pointer to the virtual address.

However I have no idea of where to map those pages. I'm in higher half, and memory from 0xC0000000 to 0xF0000000 is reserved for the kernel executable and Heap. So I thought to map the physical address at 0xF0000000. But if ACPICA calls AcpiOsMapMemory with new datas, before it have Unmapped it through AcpiOsUnmapMemory, it will overwrite the old Page directory, and probably this will cause some problems.

Do I need something like malloc/free for the virtual addresses? Or there is some easier solution to the problem?

Thanks

Re: Mapping physical address to random virtual address?

Posted: Mon May 25, 2009 5:53 am
by Masterkiller
Map them on the first free chunk of virtual memory that is length bytes. Randomness will has a chance to mess up everything.

Re: Mapping physical address to random virtual address?

Posted: Mon May 25, 2009 5:56 am
by NickJohnson
You definitely need to make an allocator for virtual addresses, but the kernel heap already is that, in essence. Just allocate a page aligned piece of address space from the heap, then map the ACPI memory to it.

Re: Mapping physical address to random virtual address?

Posted: Mon May 25, 2009 6:16 am
by AlfaOmega08
So your suggestion is:

Code: Select all

void *AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS *physical, ACPI_SIZE length) {
       void *tmp = valloc(length);
       PagingUnmapMemory(tmp, length);
       PagingMapMemory(tmp, (physical & 0xFFFFF000), length);
       return tmp + (physical & 0xFFF);
}
Uhm... I think this should work... Tell me if you mean this...

And what for unmapping? Is this enaugh?

Code: Select all

void AcpiOsMapMemory(void *virtual, ACPI_SIZE length) {
    free(virtual);          
}

Re: Mapping physical address to random virtual address?

Posted: Mon May 25, 2009 6:39 am
by NickJohnson
Yes, essentially. You just have to make sure that the addresses passed back by valloc() are page aligned. Also, if valloc() maps memory to the addresses it returns, you need to make sure to free the frame allocated to the address you get before allocating the ACPI frame, so you don't have a major memory leak.