1 |
30 |
unneback |
/*
|
2 |
|
|
* mmu.c - this file contains functions for initializing the MMU
|
3 |
|
|
*
|
4 |
|
|
* Written by Jay Monkman (jmonkman@frasca.com)
|
5 |
|
|
*
|
6 |
|
|
* $Id: mmu.c,v 1.2 2001-09-27 12:00:36 chris Exp $
|
7 |
|
|
*/
|
8 |
|
|
|
9 |
|
|
#include <bsp.h>
|
10 |
|
|
#include <mpc860.h>
|
11 |
|
|
|
12 |
|
|
/* Macros for handling all the MMU SPRs */
|
13 |
|
|
#define PUT_MI_CTR(r) __asm__ volatile ("mtspr 0x310,%0\n" ::"r"(r))
|
14 |
|
|
#define GET_MI_CTR(r) __asm__ volatile ("mfspr %0,0x310\n" :"=r"(r))
|
15 |
|
|
#define PUT_MD_CTR(r) __asm__ volatile ("mtspr 0x318,%0\n" ::"r"(r))
|
16 |
|
|
#define GET_MD_CTR(r) __asm__ volatile ("mfspr %0,0x318\n" :"=r"(r))
|
17 |
|
|
#define PUT_M_CASID(r) __asm__ volatile ("mtspr 0x319,%0\n" ::"r"(r))
|
18 |
|
|
#define GET_M_CASID(r) __asm__ volatile ("mfspr %0,0x319\n" :"=r"(r))
|
19 |
|
|
#define PUT_MI_EPN(r) __asm__ volatile ("mtspr 0x313,%0\n" ::"r"(r))
|
20 |
|
|
#define GET_MI_EPN(r) __asm__ volatile ("mfspr %0,0x313\n" :"=r"(r))
|
21 |
|
|
#define PUT_MI_TWC(r) __asm__ volatile ("mtspr 0x315,%0\n" ::"r"(r))
|
22 |
|
|
#define GET_MI_TWC(r) __asm__ volatile ("mfspr %0,0x315\n" :"=r"(r))
|
23 |
|
|
#define PUT_MI_RPN(r) __asm__ volatile ("mtspr 0x316,%0\n" ::"r"(r))
|
24 |
|
|
#define GET_MI_RPN(r) __asm__ volatile ("mfspr %0,0x316\n" :"=r"(r))
|
25 |
|
|
#define PUT_MD_EPN(r) __asm__ volatile ("mtspr 0x313,%0\n" ::"r"(r))
|
26 |
|
|
#define GET_MD_EPN(r) __asm__ volatile ("mfspr %0,0x313\n" :"=r"(r))
|
27 |
|
|
#define PUT_M_TWB(r) __asm__ volatile ("mtspr 0x31c,%0\n" ::"r"(r))
|
28 |
|
|
#define GET_M_TWB(r) __asm__ volatile ("mfspr %0,0x31c\n" :"=r"(r))
|
29 |
|
|
#define PUT_MD_TWC(r) __asm__ volatile ("mtspr 0x31d,%0\n" ::"r"(r))
|
30 |
|
|
#define GET_MD_TWC(r) __asm__ volatile ("mfspr %0,0x31d\n" :"=r"(r))
|
31 |
|
|
#define PUT_MD_RPN(r) __asm__ volatile ("mtspr 0x31e,%0\n" ::"r"(r))
|
32 |
|
|
#define GET_MD_RPN(r) __asm__ volatile ("mfspr %0,0x31e\n" :"=r"(r))
|
33 |
|
|
#define PUT_MI_AP(r) __asm__ volatile ("mtspr 0x312,%0\n" ::"r"(r))
|
34 |
|
|
#define GET_MI_AP(r) __asm__ volatile ("mfspr %0,0x312\n" :"=r"(r))
|
35 |
|
|
#define PUT_MD_AP(r) __asm__ volatile ("mtspr 0x31a,%0\n" ::"r"(r))
|
36 |
|
|
#define GET_MD_AP(r) __asm__ volatile ("mfspr %0,0x31a\n" :"=r"(r))
|
37 |
|
|
#define PUT_M_TW(r) __asm__ volatile ("mtspr 0x31f,%0\n" ::"r"(r))
|
38 |
|
|
#define GET_M_TW(r) __asm__ volatile ("mfspr %0,0x31f\n" :"=r"(r))
|
39 |
|
|
#define PUT_MI_DCAM(r) __asm__ volatile ("mtspr 0x330,%0\n" ::"r"(r))
|
40 |
|
|
#define GET_MI_DCAM(r) __asm__ volatile ("mfspr %0,0x330\n" :"=r"(r))
|
41 |
|
|
#define PUT_MI_DRAM0(r) __asm__ volatile ("mtspr 0x331,%0\n" ::"r"(r))
|
42 |
|
|
#define GET_MI_DRAM0(r) __asm__ volatile ("mfspr %0,0x331\n" :"=r"(r))
|
43 |
|
|
#define PUT_MI_DRAM1(r) __asm__ volatile ("mtspr 0x332,%0\n" ::"r"(r))
|
44 |
|
|
#define GET_MI_DRAM1(r) __asm__ volatile ("mfspr %0,0x332\n" :"=r"(r))
|
45 |
|
|
#define PUT_MD_DCAM(r) __asm__ volatile ("mtspr 0x338,%0\n" ::"r"(r))
|
46 |
|
|
#define GET_MD_DCAM(r) __asm__ volatile ("mfspr %0,0x338\n" :"=r"(r))
|
47 |
|
|
#define PUT_MD_DRAM0(r) __asm__ volatile ("mtspr 0x339,%0\n" ::"r"(r))
|
48 |
|
|
#define GET_MD_DRAM0(r) __asm__ volatile ("mfspr %0,0x339\n" :"=r"(r))
|
49 |
|
|
#define PUT_MD_DRAM1(r) __asm__ volatile ("mtspr 0x33a,%0\n" ::"r"(r))
|
50 |
|
|
#define GET_MD_DRAM1(r) __asm__ volatile ("mfspr %0,0x33a\n" :"=r"(r))
|
51 |
|
|
#define PUT_IC_CST(r) __asm__ volatile ("mtspr 0x230,%0\n" ::"r"(r))
|
52 |
|
|
#define GET_IC_CST(r) __asm__ volatile ("mfspr %0,0x230\n" :"=r"(r))
|
53 |
|
|
#define PUT_DC_CST(r) __asm__ volatile ("mtspr 0x238,%0\n" ::"r"(r))
|
54 |
|
|
#define GET_DC_CST(r) __asm__ volatile ("mfspr %0,0x238\n" :"=r"(r))
|
55 |
|
|
#define PUT_IC_ADR(r) __asm__ volatile ("mtspr 0x231,%0\n" ::"r"(r))
|
56 |
|
|
#define GET_IC_ADR(r) __asm__ volatile ("mfspr %0,0x231\n" :"=r"(r))
|
57 |
|
|
#define PUT_IC_DAT(r) __asm__ volatile ("mtspr 0x232,%0\n" ::"r"(r))
|
58 |
|
|
#define GET_IC_DAT(r) __asm__ volatile ("mfspr %0,0x232\n" :"=r"(r))
|
59 |
|
|
|
60 |
|
|
extern rtems_configuration_table BSP_Configuration;
|
61 |
|
|
|
62 |
|
|
void mmu_init(void)
|
63 |
|
|
{
|
64 |
|
|
register unsigned long t1, t2;
|
65 |
|
|
|
66 |
|
|
/* Let's clear MSR[IR] and MSR[DR] */
|
67 |
|
|
t2 = PPC_MSR_IR | PPC_MSR_DR;
|
68 |
|
|
__asm__ volatile (
|
69 |
|
|
"mfmsr %0\n"
|
70 |
|
|
"andc %0, %0, %1\n"
|
71 |
|
|
"mtmsr %0\n" :"=r"(t1), "=r"(t2):
|
72 |
|
|
"1"(t2));
|
73 |
|
|
|
74 |
|
|
/* Invalidate the TLBs */
|
75 |
|
|
__asm__ volatile ("tlbia\n"::);
|
76 |
|
|
__asm__ volatile ("isync\n"::);
|
77 |
|
|
|
78 |
|
|
/* make sure no TLB entries are reserved */
|
79 |
|
|
t1 = 0;
|
80 |
|
|
PUT_MI_CTR(t1);
|
81 |
|
|
|
82 |
|
|
t1 = M860_MD_CTR_TWAM; /* 4K pages */
|
83 |
|
|
/* PUT_MD_CTR(t1); */
|
84 |
|
|
|
85 |
|
|
t1 = M860_MI_EPN_VALID; /* make entry valid */
|
86 |
|
|
/* PUT_MD_EPN(t1); */
|
87 |
|
|
PUT_MI_EPN(t1);
|
88 |
|
|
|
89 |
|
|
t1 = M860_MI_TWC_PS8 | M860_MI_TWC_VALID; /* 8 MB pages, valid */
|
90 |
|
|
/* PUT_MD_TWC(t1); */
|
91 |
|
|
PUT_MI_TWC(t1);
|
92 |
|
|
|
93 |
|
|
t1 = M860_MD_RPN_CHANGE | M860_MD_RPN_F | M860_MD_RPN_16K |
|
94 |
|
|
M860_MD_RPN_SHARED | M860_MD_RPN_VALID;
|
95 |
|
|
/* PUT_MD_RPN(t1); */
|
96 |
|
|
PUT_MI_RPN(t1);
|
97 |
|
|
|
98 |
|
|
t1 = M860_MI_AP_Kp << 30;
|
99 |
|
|
PUT_MI_AP(t1);
|
100 |
|
|
/* PUT_MD_AP(t1); */
|
101 |
|
|
|
102 |
|
|
t1 = M860_CACHE_CMD_UNLOCK;
|
103 |
|
|
/* PUT_DC_CST(t1); */
|
104 |
|
|
PUT_IC_CST(t1);
|
105 |
|
|
|
106 |
|
|
t1 = M860_CACHE_CMD_INVALIDATE;
|
107 |
|
|
/* PUT_DC_CST(t1); */
|
108 |
|
|
PUT_IC_CST(t1);
|
109 |
|
|
|
110 |
|
|
t1 = M860_CACHE_CMD_ENABLE;
|
111 |
|
|
PUT_IC_CST(t1);
|
112 |
|
|
|
113 |
|
|
t1 = M860_CACHE_CMD_SFWT;
|
114 |
|
|
/* PUT_DC_CST(t1); */
|
115 |
|
|
t1 = M860_CACHE_CMD_ENABLE;
|
116 |
|
|
/* PUT_DC_CST(t1);*/
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
/* Let's set MSR[IR] */
|
121 |
|
|
t2 = PPC_MSR_IR;
|
122 |
|
|
__asm__ volatile (
|
123 |
|
|
"mfmsr %0\n"
|
124 |
|
|
"or %0, %0, %1\n"
|
125 |
|
|
"mtmsr %0\n" :"=r"(t1), "=r"(t2):
|
126 |
|
|
"1"(t2));
|
127 |
|
|
|
128 |
|
|
}
|