ngx wrote:
* The memory map should be fixed before usage - fix overlapping areas and alignment
The UEFI memory map is always aligned, so you don't need to fix alignment. You could fix overlapping areas, but it might be better to refuse to boot if you find any.
ngx wrote:
So the size that linux pre-allocates for the memory map is 131 * (64(base address size) + 64(length size) + 32(type size)) which means it uses about 20 KB - isn't it a very large amount?
131 * 20 bytes = about 2.5KB
ngx wrote:
* You said that I should ignore the reserved memory areas, but they are in between the usable areas so I probably can't not include them in my bitmap, or should I have several bitmaps for each free area without including reserved regions?
You already mark everything reserved at the beginning, you don't need to mark it reserved again.
I don't think multiple bitmaps will have any benefit over a single bitmap. You can always come back later and change it once you can benchmark your PMM to see which one is better.
ngx wrote:
* Another question related to previous is that if reserved areas are not tracked in the bitmap then how would I give them out to the driver when it is requesting MMIO and make sure that what he is asking for is not intersecting with other areas(like free or allocated) or that another driver would not request this area for MMIO(for example if it has a bug) or that this MMIO even exists?
You should use a different structure to track non-memory physical address usage. Reserved ranges are not always MMIO, and MMIO is not always in reserved ranges.
ngx wrote:
* So if I use the ((highest_entry_start + highest_entry_size - 1) - lowest_entry_start) / 4096 to calculate the size of the bitmap then should I do this only between lowest free entry and highest free entry(and if the lowest one is reserved find next a bit higher which is free and the same with the highest, so the reserved regions like 3.5-4GB(ACPI and MMIO) area would not skyrocket my bitmap size when I have much less RAM. I mean that if bitmap is only from lowest free to highest free then if there even is something reserved higher it would not increase the bitmap size)?
That's the idea. (Divide by 8 for one bit per page.) Just about every PC has a reserved range near 4GB for the BIOS ROM, so if you include it your bitmap will be at least 128kB even when you have very small amounts of RAM.
ngx wrote:
But here we return to the previous question - how then I track and give out MMIO areas?
Perhaps a linked list? MMIO is not allocated or freed very frequently, so it doesn't need to be fast, and it can't be fragmented like ordinary memory.
ngx wrote:
Also I wanted to ask how to allocate space for memory map(I think that pre-allocating 20 is a pretty BIG), bitmap and others while there is no allocator. Is my method of just pointing them to largest free area good or is there anything more safe and easy?
It works fine as long as it doesn't overlap a reserved area.