1 | #include <sys/param.h> |
---|
2 | #include <rtems.h> |
---|
3 | #include <libcpu/mmu.h> |
---|
4 | #include <rtems/bspIo.h> |
---|
5 | #include <libcpu/pte121.h> |
---|
6 | |
---|
7 | /* Default setup of the page tables. This is a weak |
---|
8 | * alias, so applications may easily override this |
---|
9 | * default setup. |
---|
10 | * |
---|
11 | * NOTE: while it is possible to change the individual |
---|
12 | * mappings, the page table itself MUST be |
---|
13 | * allocated at the top of the physical memory! |
---|
14 | * bspstart.c RELIES on this. |
---|
15 | * Also, the 'setup' routine must reduce |
---|
16 | * *pmemsize by the size of the page table. |
---|
17 | */ |
---|
18 | /* to align the pointer to the (next) page boundary */ |
---|
19 | #define PAGE_ALIGN(addr) (((addr) + PAGE_MASK) & ~PAGE_MASK) |
---|
20 | |
---|
21 | |
---|
22 | /* |
---|
23 | * Authorship |
---|
24 | * ---------- |
---|
25 | * This software was created by |
---|
26 | * Till Straumann <strauman@slac.stanford.edu>, 4/2002, |
---|
27 | * Stanford Linear Accelerator Center, Stanford University. |
---|
28 | * |
---|
29 | * Acknowledgement of sponsorship |
---|
30 | * ------------------------------ |
---|
31 | * This software was produced by |
---|
32 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
33 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
34 | * |
---|
35 | * Government disclaimer of liability |
---|
36 | * ---------------------------------- |
---|
37 | * Neither the United States nor the United States Department of Energy, |
---|
38 | * nor any of their employees, makes any warranty, express or implied, or |
---|
39 | * assumes any legal liability or responsibility for the accuracy, |
---|
40 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
41 | * disclosed, or represents that its use would not infringe privately owned |
---|
42 | * rights. |
---|
43 | * |
---|
44 | * Stanford disclaimer of liability |
---|
45 | * -------------------------------- |
---|
46 | * Stanford University makes no representations or warranties, express or |
---|
47 | * implied, nor assumes any liability for the use of this software. |
---|
48 | * |
---|
49 | * Stanford disclaimer of copyright |
---|
50 | * -------------------------------- |
---|
51 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
52 | * copyright and all other rights in this software. Hence, anyone may |
---|
53 | * freely use it for any purpose without restriction. |
---|
54 | * |
---|
55 | * Maintenance of notices |
---|
56 | * ---------------------- |
---|
57 | * In the interest of clarity regarding the origin and status of this |
---|
58 | * SLAC software, this and all the preceding Stanford University notices |
---|
59 | * are to remain affixed to any copy or derivative of this software made |
---|
60 | * or distributed by the recipient and are to be affixed to any copy of |
---|
61 | * software made or distributed by the recipient that contains a copy or |
---|
62 | * derivative of this software. |
---|
63 | * |
---|
64 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
65 | */ |
---|
66 | |
---|
67 | Triv121PgTbl __BSP_default_pgtbl_setup(unsigned int *pmemsize); |
---|
68 | Triv121PgTbl BSP_pgtbl_setup(unsigned int *) |
---|
69 | __attribute__ (( weak, alias("__BSP_default_pgtbl_setup") )); |
---|
70 | |
---|
71 | /* get those from the linker script. |
---|
72 | * NOTE THAT THE CORRECTNESS OF THE LINKER SCRIPT IS CRUCIAL |
---|
73 | */ |
---|
74 | extern unsigned long __DATA_START__[], _etext[]; |
---|
75 | |
---|
76 | Triv121PgTbl |
---|
77 | __BSP_default_pgtbl_setup(unsigned int *pmemsize) |
---|
78 | { |
---|
79 | Triv121PgTbl pt; |
---|
80 | unsigned ldPtSize,tmp; |
---|
81 | |
---|
82 | /* Allocate a page table large enough to map |
---|
83 | * the entire physical memory. We put the page |
---|
84 | * table at the top of the physical memory. |
---|
85 | */ |
---|
86 | |
---|
87 | /* get minimal size (log base 2) of PT for |
---|
88 | * this board's memory |
---|
89 | */ |
---|
90 | ldPtSize = triv121PgTblLdMinSize(*pmemsize); |
---|
91 | ldPtSize++; /* double this amount -- then why? */ |
---|
92 | |
---|
93 | /* allocate the page table at the top of the physical |
---|
94 | * memory - THIS IS NOT AN OPTION - bspstart.c RELIES |
---|
95 | * ON THIS LAYOUT! (the size, however may be changed) |
---|
96 | */ |
---|
97 | if ( (pt = triv121PgTblInit(*pmemsize - (1<<ldPtSize), ldPtSize)) ) { |
---|
98 | /* map text and RO data read-only */ |
---|
99 | tmp = triv121PgTblMap( |
---|
100 | pt, |
---|
101 | TRIV121_121_VSID, |
---|
102 | 0, |
---|
103 | (PAGE_ALIGN((unsigned long)_etext) - 0) >> PG_SHIFT, |
---|
104 | 0, /* WIMG */ |
---|
105 | TRIV121_PP_RO_PAGE); |
---|
106 | if (TRIV121_MAP_SUCCESS != tmp) { |
---|
107 | printk("Unable to map page index %i; reverting to BAT0\n", |
---|
108 | tmp); |
---|
109 | pt = 0; |
---|
110 | } else { |
---|
111 | /* map the rest (without the page table itself) RW */ |
---|
112 | tmp = triv121PgTblMap( |
---|
113 | pt, |
---|
114 | TRIV121_121_VSID, |
---|
115 | (unsigned long)__DATA_START__, |
---|
116 | (*pmemsize - (1<<ldPtSize) - (unsigned long)__DATA_START__ )>> PG_SHIFT, |
---|
117 | 0, /* WIMG */ |
---|
118 | TRIV121_PP_RW_PAGE); |
---|
119 | if (TRIV121_MAP_SUCCESS != tmp) { |
---|
120 | printk("Unable to map page index %i; reverting to BAT0\n", |
---|
121 | tmp); |
---|
122 | pt = 0; |
---|
123 | } |
---|
124 | } |
---|
125 | } else { |
---|
126 | printk("WARNING: unable to allocate page table, keeping DBAT0\n"); |
---|
127 | } |
---|
128 | if (pt) { |
---|
129 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
130 | printk("Setting up page table mappings; protecting text/read-only data from write access\n"); |
---|
131 | #endif |
---|
132 | /* SUCCESS; reduce available memory by size of the page table */ |
---|
133 | *pmemsize -= (1<<ldPtSize); |
---|
134 | } |
---|
135 | return pt; |
---|
136 | } |
---|