Mapping physical address to random virtual address?

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
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Mapping physical address to random virtual address?

Post 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
Please, correct my English...
Motherboard: ASUS Rampage II Extreme
CPU: Core i7 950 @ 3.06 GHz OC at 3.6 GHz
RAM: 4 GB 1600 MHz DDR3
Video: nVidia GeForce 210 GTS... it sucks...
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Re: Mapping physical address to random virtual address?

Post 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.
ALCA OS: Project temporarity suspended!
Current state: real-mode kernel-FS reader...
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Mapping physical address to random virtual address?

Post 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.
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Re: Mapping physical address to random virtual address?

Post 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);          
}
Please, correct my English...
Motherboard: ASUS Rampage II Extreme
CPU: Core i7 950 @ 3.06 GHz OC at 3.6 GHz
RAM: 4 GB 1600 MHz DDR3
Video: nVidia GeForce 210 GTS... it sucks...
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Mapping physical address to random virtual address?

Post 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.
Post Reply