blob: 113c293c03618dd25bd9cecbb61b7e31fd711f7b [file] [log] [blame]
wdenkaffae2b2002-08-17 09:36:01 +00001/*
2 * (C) Copyright 2002
3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25#include <common.h>
26#include <asm/processor.h>
27#include <asm/mmu.h>
Becky Bruce42b400e2008-08-04 14:01:53 -050028#include <asm/io.h>
Wolfgang Denkf8d47f62011-11-04 15:55:59 +000029#include <linux/compiler.h>
wdenkaffae2b2002-08-17 09:36:01 +000030
Becky Brucef93e1cb2009-02-03 18:10:52 -060031#ifdef CONFIG_ADDR_MAP
32#include <addr_map.h>
33#endif
34
35DECLARE_GLOBAL_DATA_PTR;
36
wdenkaffae2b2002-08-17 09:36:01 +000037int write_bat (ppc_bat_t bat, unsigned long upper, unsigned long lower)
38{
Wolfgang Denkf8d47f62011-11-04 15:55:59 +000039 __maybe_unused int batn = -1;
Becky Brucef93e1cb2009-02-03 18:10:52 -060040
Becky Bruce42b400e2008-08-04 14:01:53 -050041 sync();
42
wdenkaffae2b2002-08-17 09:36:01 +000043 switch (bat) {
Becky Bruce065b5772008-05-15 21:29:04 -050044 case DBAT0:
45 mtspr (DBAT0L, lower);
46 mtspr (DBAT0U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060047 batn = 0;
Becky Bruce065b5772008-05-15 21:29:04 -050048 break;
wdenkaffae2b2002-08-17 09:36:01 +000049 case IBAT0:
50 mtspr (IBAT0L, lower);
51 mtspr (IBAT0U, upper);
52 break;
Becky Bruce065b5772008-05-15 21:29:04 -050053 case DBAT1:
54 mtspr (DBAT1L, lower);
55 mtspr (DBAT1U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060056 batn = 1;
Becky Bruce065b5772008-05-15 21:29:04 -050057 break;
wdenkaffae2b2002-08-17 09:36:01 +000058 case IBAT1:
59 mtspr (IBAT1L, lower);
60 mtspr (IBAT1U, upper);
61 break;
Becky Bruce065b5772008-05-15 21:29:04 -050062 case DBAT2:
63 mtspr (DBAT2L, lower);
64 mtspr (DBAT2U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060065 batn = 2;
Becky Bruce065b5772008-05-15 21:29:04 -050066 break;
wdenkaffae2b2002-08-17 09:36:01 +000067 case IBAT2:
68 mtspr (IBAT2L, lower);
69 mtspr (IBAT2U, upper);
70 break;
Becky Bruce065b5772008-05-15 21:29:04 -050071 case DBAT3:
72 mtspr (DBAT3L, lower);
73 mtspr (DBAT3U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060074 batn = 3;
Becky Bruce065b5772008-05-15 21:29:04 -050075 break;
wdenkaffae2b2002-08-17 09:36:01 +000076 case IBAT3:
77 mtspr (IBAT3L, lower);
78 mtspr (IBAT3U, upper);
79 break;
Becky Bruce065b5772008-05-15 21:29:04 -050080#ifdef CONFIG_HIGH_BATS
81 case DBAT4:
82 mtspr (DBAT4L, lower);
83 mtspr (DBAT4U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060084 batn = 4;
wdenkaffae2b2002-08-17 09:36:01 +000085 break;
Becky Bruce065b5772008-05-15 21:29:04 -050086 case IBAT4:
87 mtspr (IBAT4L, lower);
88 mtspr (IBAT4U, upper);
wdenkaffae2b2002-08-17 09:36:01 +000089 break;
Becky Bruce065b5772008-05-15 21:29:04 -050090 case DBAT5:
91 mtspr (DBAT5L, lower);
92 mtspr (DBAT5U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -060093 batn = 5;
wdenkaffae2b2002-08-17 09:36:01 +000094 break;
Becky Bruce065b5772008-05-15 21:29:04 -050095 case IBAT5:
96 mtspr (IBAT5L, lower);
97 mtspr (IBAT5U, upper);
wdenkaffae2b2002-08-17 09:36:01 +000098 break;
Becky Bruce065b5772008-05-15 21:29:04 -050099 case DBAT6:
100 mtspr (DBAT6L, lower);
101 mtspr (DBAT6U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -0600102 batn = 6;
Becky Bruce065b5772008-05-15 21:29:04 -0500103 break;
104 case IBAT6:
105 mtspr (IBAT6L, lower);
106 mtspr (IBAT6U, upper);
107 break;
108 case DBAT7:
109 mtspr (DBAT7L, lower);
110 mtspr (DBAT7U, upper);
Becky Brucef93e1cb2009-02-03 18:10:52 -0600111 batn = 7;
Becky Bruce065b5772008-05-15 21:29:04 -0500112 break;
113 case IBAT7:
114 mtspr (IBAT7L, lower);
115 mtspr (IBAT7U, upper);
116 break;
117#endif
wdenkaffae2b2002-08-17 09:36:01 +0000118 default:
119 return (-1);
120 }
121
Becky Brucef93e1cb2009-02-03 18:10:52 -0600122#ifdef CONFIG_ADDR_MAP
123 if ((gd->flags & GD_FLG_RELOC) && (batn >= 0)) {
124 phys_size_t size;
125 if (!BATU_VALID(upper))
126 size = 0;
127 else
128 size = BATU_SIZE(upper);
129 addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower),
130 size, batn);
131 }
132#endif
133
Becky Bruce42b400e2008-08-04 14:01:53 -0500134 sync();
135 isync();
136
wdenkaffae2b2002-08-17 09:36:01 +0000137 return (0);
138}
139
140int read_bat (ppc_bat_t bat, unsigned long *upper, unsigned long *lower)
141{
142 unsigned long register u;
143 unsigned long register l;
144
145 switch (bat) {
Becky Bruce065b5772008-05-15 21:29:04 -0500146 case DBAT0:
147 l = mfspr (DBAT0L);
148 u = mfspr (DBAT0U);
149 break;
wdenkaffae2b2002-08-17 09:36:01 +0000150 case IBAT0:
151 l = mfspr (IBAT0L);
152 u = mfspr (IBAT0U);
153 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500154 case DBAT1:
155 l = mfspr (DBAT1L);
156 u = mfspr (DBAT1U);
157 break;
wdenkaffae2b2002-08-17 09:36:01 +0000158 case IBAT1:
159 l = mfspr (IBAT1L);
160 u = mfspr (IBAT1U);
161 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500162 case DBAT2:
163 l = mfspr (DBAT2L);
164 u = mfspr (DBAT2U);
165 break;
wdenkaffae2b2002-08-17 09:36:01 +0000166 case IBAT2:
167 l = mfspr (IBAT2L);
168 u = mfspr (IBAT2U);
169 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500170 case DBAT3:
171 l = mfspr (DBAT3L);
172 u = mfspr (DBAT3U);
173 break;
wdenkaffae2b2002-08-17 09:36:01 +0000174 case IBAT3:
175 l = mfspr (IBAT3L);
176 u = mfspr (IBAT3U);
177 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500178#ifdef CONFIG_HIGH_BATS
179 case DBAT4:
180 l = mfspr (DBAT4L);
181 u = mfspr (DBAT4U);
wdenkaffae2b2002-08-17 09:36:01 +0000182 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500183 case IBAT4:
184 l = mfspr (IBAT4L);
185 u = mfspr (IBAT4U);
wdenkaffae2b2002-08-17 09:36:01 +0000186 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500187 case DBAT5:
188 l = mfspr (DBAT5L);
189 u = mfspr (DBAT5U);
wdenkaffae2b2002-08-17 09:36:01 +0000190 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500191 case IBAT5:
192 l = mfspr (IBAT5L);
193 u = mfspr (IBAT5U);
wdenkaffae2b2002-08-17 09:36:01 +0000194 break;
Becky Bruce065b5772008-05-15 21:29:04 -0500195 case DBAT6:
196 l = mfspr (DBAT6L);
197 u = mfspr (DBAT6U);
198 break;
199 case IBAT6:
200 l = mfspr (IBAT6L);
201 u = mfspr (IBAT6U);
202 break;
203 case DBAT7:
204 l = mfspr (DBAT7L);
205 u = mfspr (DBAT7U);
206 break;
207 case IBAT7:
208 l = mfspr (IBAT7L);
209 u = mfspr (IBAT7U);
210 break;
211#endif
wdenkaffae2b2002-08-17 09:36:01 +0000212 default:
213 return (-1);
214 }
215
216 *upper = u;
217 *lower = l;
218
219 return (0);
220}
Becky Brucee7efd5b2008-05-09 15:41:35 -0500221
222void print_bats(void)
223{
224 printf("BAT registers:\n");
225
226 printf ("\tIBAT0L = 0x%08X ", mfspr (IBAT0L));
227 printf ("\tIBAT0U = 0x%08X\n", mfspr (IBAT0U));
228 printf ("\tDBAT0L = 0x%08X ", mfspr (DBAT0L));
229 printf ("\tDBAT0U = 0x%08X\n", mfspr (DBAT0U));
230 printf ("\tIBAT1L = 0x%08X ", mfspr (IBAT1L));
231 printf ("\tIBAT1U = 0x%08X\n", mfspr (IBAT1U));
232 printf ("\tDBAT1L = 0x%08X ", mfspr (DBAT1L));
233 printf ("\tDBAT1U = 0x%08X\n", mfspr (DBAT1U));
234 printf ("\tIBAT2L = 0x%08X ", mfspr (IBAT2L));
235 printf ("\tIBAT2U = 0x%08X\n", mfspr (IBAT2U));
236 printf ("\tDBAT2L = 0x%08X ", mfspr (DBAT2L));
237 printf ("\tDBAT2U = 0x%08X\n", mfspr (DBAT2U));
238 printf ("\tIBAT3L = 0x%08X ", mfspr (IBAT3L));
239 printf ("\tIBAT3U = 0x%08X\n", mfspr (IBAT3U));
240 printf ("\tDBAT3L = 0x%08X ", mfspr (DBAT3L));
241 printf ("\tDBAT3U = 0x%08X\n", mfspr (DBAT3U));
242
243#ifdef CONFIG_HIGH_BATS
244 printf ("\tIBAT4L = 0x%08X ", mfspr (IBAT4L));
245 printf ("\tIBAT4U = 0x%08X\n", mfspr (IBAT4U));
246 printf ("\tDBAT4L = 0x%08X ", mfspr (DBAT4L));
247 printf ("\tDBAT4U = 0x%08X\n", mfspr (DBAT4U));
248 printf ("\tIBAT5L = 0x%08X ", mfspr (IBAT5L));
249 printf ("\tIBAT5U = 0x%08X\n", mfspr (IBAT5U));
250 printf ("\tDBAT5L = 0x%08X ", mfspr (DBAT5L));
251 printf ("\tDBAT5U = 0x%08X\n", mfspr (DBAT5U));
252 printf ("\tIBAT6L = 0x%08X ", mfspr (IBAT6L));
253 printf ("\tIBAT6U = 0x%08X\n", mfspr (IBAT6U));
254 printf ("\tDBAT6L = 0x%08X ", mfspr (DBAT6L));
255 printf ("\tDBAT6U = 0x%08X\n", mfspr (DBAT6U));
256 printf ("\tIBAT7L = 0x%08X ", mfspr (IBAT7L));
257 printf ("\tIBAT7U = 0x%08X\n", mfspr (IBAT7U));
258 printf ("\tDBAT7L = 0x%08X ", mfspr (DBAT7L));
259 printf ("\tDBAT7U = 0x%08X\n", mfspr (DBAT7U));
260#endif
261}