mips虚拟内存映射

内核空间通常的va到pa的转化为:

/*

 * 256MB standard MIPS32 virtual address map
 *
 * 8000_0000 - 8fff_ffff: lower 256MB, cached mapping  (kseg0)
 * 9000_0000 - 9fff_ffff: EBI/registers, cached mapping (unused)  (kseg0)
 * a000_0000 - afff_ffff: lower 256MB, uncached mapping   (kseg1)
 * b000_0000 - bfff_ffff: EBI/registers, uncached mapping     (kseg1)
 * c000_0000 - ff1f_7fff: vmalloc region
 * ff1f_8000 - ff1f_ffff: FIXMAP

 */


对于支持XKS01的cpu,kseg0可以支持1024M, 开启XKS01的方法为:(bmips_vec.S文件中定义)

/***********************************************************************
 * XKS01 support
 * Certain CPUs support extending kseg0 to 1024MB.
 ***********************************************************************/


__CPUINIT


LEAF(bmips_enable_xks01)


#if defined(CONFIG_XKS01)


#if defined(CONFIG_CPU_BMIPS4380)
mfc0 t0, $22, 3
li t1, 0x1ff0
li t2, (1 << 12) | (1 << 9)
or t0, t1
xor t0, t1
or t0, t2
mtc0 t0, $22, 3
BARRIER
#elif defined(CONFIG_CPU_BMIPS5000)
mfc0 t0, $22, 5
li t1, 0x01ff
li t2, (1 << 8) | (1 << 5)
or t0, t1
xor t0, t1
or t0, t2
mtc0 t0, $22, 5
BARRIER
#else


#error Missing XKS01 setup

#endif

此时的映射关系变为:

/*
 * 1024MB Broadcom 256+768 virtual address map
 *
 * 8000_0000 - 8fff_ffff: 256MB RAM @ 0000_0000, cached         (kseg0)
 * 9000_0000 - 9fff_ffff: 256MB EBI/Registers @ 1000_0000, uncached            (kseg0)
 * a000_0000 - cfff_ffff: 768MB RAM @ 2000_0000, cached                 (kseg0)
 * d000_0000 - dfff_ffff: TBD
 * e000_0000 - ff1f_7fff: vmalloc region
 * ff1f_8000 - ff1f_ffff: FIXMAP
 * ff40_0000 - ff7f_ffff: CONSISTENT region
 *
 * PA 5000_0000 and above are accessed through HIGHMEM (BMIPS5000 only).
 */

此时通过Kseg1访问寄存器时要特别小心,因为b000_0000 - bfff_ffff这时映射到的是DRAM而不是寄存器空间,所以想要通过这段地址空间访问寄存器之前要disable XKS01,如下:

/* disable XKS01 so that CFE can access the registers */


#if defined(CONFIG_CPU_BMIPS4380)
__write_32bit_c0_register($22, 3,
__read_32bit_c0_register($22, 3) & ~BIT(12));
#elif defined(CONFIG_CPU_BMIPS5000)
__write_32bit_c0_register($22, 5,
__read_32bit_c0_register($22, 5) & ~BIT(8));
#endif


通过XKS01机制,可以在不需要TLB的情况下访问1G的物理内存:256M DRAM + 256M register + 768M DRAM

你可能感兴趣的:(kernel基础)