Thursday, June 3, 2010

LDD3 notes: DMA

My notes while reading Linux Device Drivers 3rd edition, Memory mapping and DMA.

Kernel addressing
  • Physical address
  • Logical Address
  • Virtual address
  • Bus address (physical address as understood by the DMA peripheral)
__pa() , __va() for low memory only

Concepts

PFN - page frame number. (virtual or physical) address / page size

struct page
  • 'handle' to a page of memory.
  • page_address() macro to get virtual address, if mapped
  • kmap() kernel virtual address for any page in the system
  • may sleep, but has an atomic version

VMA - virtual memory area. a contiguous, homogeneous region of process virtual address space.
  • visible in /proc/pid/maps
vm_area_struct
  • nopage() - process accessed a missing page, go get it
  • vm_pgoff, offset in pages into the backing file
mm_struct - a list of virtual memory areas for a single process. threads may share one.



implementing mmap
  • remap_pfn_range(), once and for all ( io_remap_page_range() )
  • - reserved pages only: locked in memory, outside of memory management
  • implement vm_ops->nopage() and map page at a time to fill the holes
  • - can map regular ram pages
generic dma layer
  • encapsulates cache coherency, bus addressing and implements bounce buffering as a fallback
  • device.dma_set_mask() - how many address bits the device sees
  • cache (in)coherency: cpu won't see dma ram writes, dma ram reads won't see cpu writes
  • buffer allocation and bus addressing: dma_addr_t
  • "one shot" operation streaming mappings - preferred
  • dma_[un]map_single()
  • long standing coherent mappings
  • dma_{alloc|free}_coherent()
  • dma_pool_{create|alloc|free|destroy}()


scullp_vma_open, mapping count non-atomic?
vsyscall page?

No comments:

Post a Comment