610 static struct map_desc mainstone_io_desc[] __initdata = {
611 { /* CPLD */
612 .virtual = MST_FPGA_VIRT,
613 .pfn = __phys_to_pfn(MST_FPGA_PHYS),
614 .length = 0x00100000,
615 .type = MT_DEVICE
616 }
617 };
618
619 static void __init mainstone_map_io(void)
620 {
621 pxa_map_io();
622 iotable_init(mainstone_io_desc, ARRAY_SIZE(mainstone_io_desc));
623
624 /* for use I SRAM as framebuffer. */
625 PSLR |= 0xF04;
626 PCFR = 0x66;
627 }
628
629 MACHINE_START(MAINSTONE, "Intel HCDDBBVA0 Development Platform (aka Mainstone)")
630 /* Maintainer: MontaVista Software Inc. */
631 .phys_io = 0x40000000,
632 .boot_params = 0xa0000100, /* BLOB boot parameter setting */
633 .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
634 .map_io = mainstone_map_io, //IO空间映射
635 .init_irq = mainstone_init_irq,
636 .timer = &pxa_timer,
637 .init_machine = mainstone_init,
638 MACHINE_END
_phys_to_pfn
_phys_to_pfn在arch/arm/include/asm/memory.h文件中定义:
120 /*
121 * Convert a physical address to a Page Frame Number and back
122 */
123 #define __phys_to_pfn(paddr) ((paddr) >> PAGE_SHIFT)
124 #define __pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT)
而下面这是LPC3250的io_p2v实现:
/* Start of virtual addresses for IO devices */
#define IO_BASE 0xF0000000
#define io_p2v(x) (IO_BASE | (((x) & 0xff000000) >> 4) | ((x) & 0x000fffff))
#define io_v2p(x) ((((x) & 0x0ff00000) << 4) | ((x) & 0x000fffff))
PAGE_SHIFT
见arch/arm/include/asm/page.h文件:
13 /* PAGE_SHIFT determines the page size */
14 #define PAGE_SHIFT 12
15 #define PAGE_SIZE (1UL << PAGE_SHIFT)
16 #define PAGE_MASK (~(PAGE_SIZE-1))
io_p2v
每个处理器都有自己的io_p2v实现,下面是PXA270处理器的,见arch/arm/mach-pxa/include/mach/hardware.h文件:
28 /*
29 * Intel PXA2xx internal register mapping:
30 *
31 * 0x40000000 - 0x41ffffff <--> 0xf2000000 - 0xf3ffffff
32 * 0x44000000 - 0x45ffffff <--> 0xf4000000 - 0xf5ffffff
33 * 0x48000000 - 0x49ffffff <--> 0xf6000000 - 0xf7ffffff
34 * 0x4c000000 - 0x4dffffff <--> 0xf8000000 - 0xf9ffffff
35 * 0x50000000 - 0x51ffffff <--> 0xfa000000 - 0xfbffffff
36 * 0x54000000 - 0x55ffffff <--> 0xfc000000 - 0xfdffffff
37 * 0x58000000 - 0x59ffffff <--> 0xfe000000 - 0xffffffff
38 *
39 * Note that not all PXA2xx chips implement all those addresses, and the
40 * kernel only maps the minimum needed range of this mapping.
41 */
42 #define io_p2v(x) (0xf2000000 + ((x) & 0x01ffffff) + (((x) & 0x1c000000) >> 1))
43 #define io_v2p(x) (0x3c000000 + ((x) & 0x01ffffff) + (((x) & 0x0e000000) << 1))
添加外扩设备寄存器
18 #define MST_FPGA_PHYS PXA_CS2_PHYS
19 #define MST_FPGA_VIRT (0xf0000000)
20 #define MST_P2V(x) ((x) - MST_FPGA_PHYS + MST_FPGA_VIRT)
21 #define MST_V2P(x) ((x) - MST_FPGA_VIRT + MST_FPGA_PHYS)
22
23 #ifndef __ASSEMBLY__
24 # define __MST_REG(x) (*((volatile unsigned long *)MST_P2V(x)))
25 #else
26 # define __MST_REG(x) MST_P2V(x)
27 #endif
28
29 /* board level registers in the FPGA */
30
31 #define MST_LEDDAT1 __MST_REG(0x08000010)
32 #define MST_LEDDAT2 __MST_REG(0x08000014)
33 #define MST_LEDCTRL __MST_REG(0x08000040)
34 #define MST_GPSWR __MST_REG(0x08000060)
35 #define MST_MSCWR1 __MST_REG(0x08000080)
36 #define MST_MSCWR2 __MST_REG(0x08000084)
37 #define MST_MSCWR3 __MST_REG(0x08000088)
38 #define MST_MSCRD __MST_REG(0x08000090)
39 #define MST_INTMSKENA __MST_REG(0x080000c0)
40 #define MST_INTSETCLR __MST_REG(0x080000d0)
41 #define MST_PCMCIA0 __MST_REG(0x080000e0)
42 #define MST_PCMCIA1 __MST_REG(0x080000e4)