wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | /* |
| 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 Bruce | 42b400e | 2008-08-04 14:01:53 -0500 | [diff] [blame] | 28 | #include <asm/io.h> |
Wolfgang Denk | f8d47f6 | 2011-11-04 15:55:59 +0000 | [diff] [blame] | 29 | #include <linux/compiler.h> |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 30 | |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 31 | #ifdef CONFIG_ADDR_MAP |
| 32 | #include <addr_map.h> |
| 33 | #endif |
| 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 37 | int write_bat (ppc_bat_t bat, unsigned long upper, unsigned long lower) |
| 38 | { |
Wolfgang Denk | f8d47f6 | 2011-11-04 15:55:59 +0000 | [diff] [blame] | 39 | __maybe_unused int batn = -1; |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 40 | |
Becky Bruce | 42b400e | 2008-08-04 14:01:53 -0500 | [diff] [blame] | 41 | sync(); |
| 42 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 43 | switch (bat) { |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 44 | case DBAT0: |
| 45 | mtspr (DBAT0L, lower); |
| 46 | mtspr (DBAT0U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 47 | batn = 0; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 48 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 49 | case IBAT0: |
| 50 | mtspr (IBAT0L, lower); |
| 51 | mtspr (IBAT0U, upper); |
| 52 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 53 | case DBAT1: |
| 54 | mtspr (DBAT1L, lower); |
| 55 | mtspr (DBAT1U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 56 | batn = 1; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 57 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 58 | case IBAT1: |
| 59 | mtspr (IBAT1L, lower); |
| 60 | mtspr (IBAT1U, upper); |
| 61 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 62 | case DBAT2: |
| 63 | mtspr (DBAT2L, lower); |
| 64 | mtspr (DBAT2U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 65 | batn = 2; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 66 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 67 | case IBAT2: |
| 68 | mtspr (IBAT2L, lower); |
| 69 | mtspr (IBAT2U, upper); |
| 70 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 71 | case DBAT3: |
| 72 | mtspr (DBAT3L, lower); |
| 73 | mtspr (DBAT3U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 74 | batn = 3; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 75 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 76 | case IBAT3: |
| 77 | mtspr (IBAT3L, lower); |
| 78 | mtspr (IBAT3U, upper); |
| 79 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 80 | #ifdef CONFIG_HIGH_BATS |
| 81 | case DBAT4: |
| 82 | mtspr (DBAT4L, lower); |
| 83 | mtspr (DBAT4U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 84 | batn = 4; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 85 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 86 | case IBAT4: |
| 87 | mtspr (IBAT4L, lower); |
| 88 | mtspr (IBAT4U, upper); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 89 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 90 | case DBAT5: |
| 91 | mtspr (DBAT5L, lower); |
| 92 | mtspr (DBAT5U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 93 | batn = 5; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 94 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 95 | case IBAT5: |
| 96 | mtspr (IBAT5L, lower); |
| 97 | mtspr (IBAT5U, upper); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 98 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 99 | case DBAT6: |
| 100 | mtspr (DBAT6L, lower); |
| 101 | mtspr (DBAT6U, upper); |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 102 | batn = 6; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 103 | 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 Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 111 | batn = 7; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 112 | break; |
| 113 | case IBAT7: |
| 114 | mtspr (IBAT7L, lower); |
| 115 | mtspr (IBAT7U, upper); |
| 116 | break; |
| 117 | #endif |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 118 | default: |
| 119 | return (-1); |
| 120 | } |
| 121 | |
Becky Bruce | f93e1cb | 2009-02-03 18:10:52 -0600 | [diff] [blame] | 122 | #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 Bruce | 42b400e | 2008-08-04 14:01:53 -0500 | [diff] [blame] | 134 | sync(); |
| 135 | isync(); |
| 136 | |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 137 | return (0); |
| 138 | } |
| 139 | |
| 140 | int 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 Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 146 | case DBAT0: |
| 147 | l = mfspr (DBAT0L); |
| 148 | u = mfspr (DBAT0U); |
| 149 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 150 | case IBAT0: |
| 151 | l = mfspr (IBAT0L); |
| 152 | u = mfspr (IBAT0U); |
| 153 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 154 | case DBAT1: |
| 155 | l = mfspr (DBAT1L); |
| 156 | u = mfspr (DBAT1U); |
| 157 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 158 | case IBAT1: |
| 159 | l = mfspr (IBAT1L); |
| 160 | u = mfspr (IBAT1U); |
| 161 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 162 | case DBAT2: |
| 163 | l = mfspr (DBAT2L); |
| 164 | u = mfspr (DBAT2U); |
| 165 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 166 | case IBAT2: |
| 167 | l = mfspr (IBAT2L); |
| 168 | u = mfspr (IBAT2U); |
| 169 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 170 | case DBAT3: |
| 171 | l = mfspr (DBAT3L); |
| 172 | u = mfspr (DBAT3U); |
| 173 | break; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 174 | case IBAT3: |
| 175 | l = mfspr (IBAT3L); |
| 176 | u = mfspr (IBAT3U); |
| 177 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 178 | #ifdef CONFIG_HIGH_BATS |
| 179 | case DBAT4: |
| 180 | l = mfspr (DBAT4L); |
| 181 | u = mfspr (DBAT4U); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 182 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 183 | case IBAT4: |
| 184 | l = mfspr (IBAT4L); |
| 185 | u = mfspr (IBAT4U); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 186 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 187 | case DBAT5: |
| 188 | l = mfspr (DBAT5L); |
| 189 | u = mfspr (DBAT5U); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 190 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 191 | case IBAT5: |
| 192 | l = mfspr (IBAT5L); |
| 193 | u = mfspr (IBAT5U); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 194 | break; |
Becky Bruce | 065b577 | 2008-05-15 21:29:04 -0500 | [diff] [blame] | 195 | 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 |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 212 | default: |
| 213 | return (-1); |
| 214 | } |
| 215 | |
| 216 | *upper = u; |
| 217 | *lower = l; |
| 218 | |
| 219 | return (0); |
| 220 | } |
Becky Bruce | e7efd5b | 2008-05-09 15:41:35 -0500 | [diff] [blame] | 221 | |
| 222 | void 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 | } |