01 July 2009

Linux Kernel Memory - 4

PCI devices have access to three address spaces;
PCI I/O, PCI Memory (used by the PCI initialization code) and PCI Configuration space (used by the device drivers).

virt_to_phys(virt_addr) = __pa(virt_addr) = Virt Addr - 0xC0000000
phys_to_virt(phy_addr) = __va(phy_addr) = Phy Addr + 0xC0000000

Check the given physical memory is in RAM:
if (phy_addr < virt_to_phys(high_memory)) {
    The given physical memory is in RAM
}

ioremap:
area = get_vm_area(size, VM_IOREMAP); (return a free area in virtual addres space)
remap_area_pages(virt_addr, phys_addr, size, flags); (update PGD, PMD and PTE table)

vmalloc:
area = get_vm_area(size, VM_ALLOC); (return a free area in virtual addres space)
vmalloc_area_pages(virt_addr, size, flags, prot); (update PGD, PMD and PTE table)

iounmap: vfree:
vmfree_area_pages(virt_addr, size); (update PGD, PMD and PTE table)

How does ioremap and vmalloc relatted???



request_mem_region (Phy Addr, Length, Name);
pci_request_regions (PDev, Name); (to update "/proc/iomem")
------------------------------------------------
ethtool –i eth0
driver: e1000
version: 7.0.38
firmware-version: N/A
bus-info: 02:03.0

./pcidump /proc/bus/pci/02/03.0

B0 Base Address 0: fc200004
B1 Base Address 1: 00000000
B2 Base Address 2: 00000000
B3 Base Address 3: 00000000
B4 Base Address 4: 00003001
B5 Base Address 5: 00000000


cat /proc/iomem

c2e2a000-c3f00000 : Bigphysarea
fc100000-fc4fffff : PCI Bus #01
fc200000-fc3fffff : PCI Bus #02
fc200000-fc21ffff : PCI device 8086:1010
fc200000-fc21ffff : e1000
fc300000-fc3fffff : PCI Bus #03
fc300000-fc30ffff : PCI device 170b:0100
fc400000-fc4fffff : PCI Bus #04
fc400000-fc41ffff : PCI device 8086:1079
fc400000-fc41ffff : e1000
fc500000-fc500fff : PCI device 1002:4752

------------------------------------------------

Reference:
http://tldp.org/LDP/tlk/dd/pci.html
http://linuxgazette.net/issue83/thangaraju.html

No comments:

Post a Comment