This is an old revision of the document!
====== Piotr Jaroszyński: Usermode debugging under Linux ====== ===== Week 11 [ Aug 2 - Aug 8 2010 ] ===== ==== drivers in userspace ==== === addressing spaces === First a bit of background. There are four different kind of addresses in gPXE: * virtual - these are the ones you can access directly in gPXE via normal pointer derefence * user - these are a superset (sometimes not proper) of virtual, which possibly allow addressing more stuff * phys - these are physical memory addresses * bus - these are memory addresses how the devices see the memory In linux userpace there is a big (32 or 64 bit depending on arch) flat address space. This lets us easily make virtual addresses equal to user addresses. The problems begin with phys addresses. What a process sees as contiguous memory may not be physically contiguous at all. The kernel maps PAGEs from all over the physical memory to construct the process' address-space. Hence there is no way of converting user addresses to real physical addresses. The good news is that real physical addresses seem to be only really (i.e. passed somewhere to be derefenced) used by virtio and some infiniband drivers. For now we can live without them and currently phys addresses are equal to user and virtual addresses. Bus addresses have the same general problem as phys addresses. The difference is that all memory that is to be accessed by hardware (except infiniband) is allocated with malloc_dma() which can be controled. And indeed malloc_dma() is made to use memory allocated by an [[https://opensource.qualcomm.com/index.php?uiodma|UIO-DMA]] kernel module, which guarantees it's ready to be accessed by hardware and provides us with a bus address for it. Hence we can return a proper address when doing phys_to_bus conversion for these returned by malloc_dma(). The handling of bus addresses begs a question why not make phys == bus addresses and handle the conversion in user_to_phys as it seems to make more sense especially as the adresses are really equal on some hardware. This was tried and backed off because malloc() aligns allocations by their phys address. That could be worked around but doesn't really seem worth it. === some more improvements/cleanup === ==== bnx2 ====