1*a47a12beSStefan Roese /* 2*a47a12beSStefan Roese * (C) Copyright 2002 3*a47a12beSStefan Roese * Rich Ireland, Enterasys Networks, rireland@enterasys.com. 4*a47a12beSStefan Roese * 5*a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 6*a47a12beSStefan Roese * project. 7*a47a12beSStefan Roese * 8*a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 9*a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 10*a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 11*a47a12beSStefan Roese * the License, or (at your option) any later version. 12*a47a12beSStefan Roese * 13*a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 14*a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*a47a12beSStefan Roese * GNU General Public License for more details. 17*a47a12beSStefan Roese * 18*a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 19*a47a12beSStefan Roese * along with this program; if not, write to the Free Software 20*a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*a47a12beSStefan Roese * MA 02111-1307 USA 22*a47a12beSStefan Roese * 23*a47a12beSStefan Roese */ 24*a47a12beSStefan Roese 25*a47a12beSStefan Roese #include <common.h> 26*a47a12beSStefan Roese #include <asm/processor.h> 27*a47a12beSStefan Roese #include <asm/mmu.h> 28*a47a12beSStefan Roese #include <asm/io.h> 29*a47a12beSStefan Roese 30*a47a12beSStefan Roese #ifdef CONFIG_ADDR_MAP 31*a47a12beSStefan Roese #include <addr_map.h> 32*a47a12beSStefan Roese #endif 33*a47a12beSStefan Roese 34*a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 35*a47a12beSStefan Roese 36*a47a12beSStefan Roese int write_bat (ppc_bat_t bat, unsigned long upper, unsigned long lower) 37*a47a12beSStefan Roese { 38*a47a12beSStefan Roese int batn = -1; 39*a47a12beSStefan Roese 40*a47a12beSStefan Roese sync(); 41*a47a12beSStefan Roese 42*a47a12beSStefan Roese switch (bat) { 43*a47a12beSStefan Roese case DBAT0: 44*a47a12beSStefan Roese mtspr (DBAT0L, lower); 45*a47a12beSStefan Roese mtspr (DBAT0U, upper); 46*a47a12beSStefan Roese batn = 0; 47*a47a12beSStefan Roese break; 48*a47a12beSStefan Roese case IBAT0: 49*a47a12beSStefan Roese mtspr (IBAT0L, lower); 50*a47a12beSStefan Roese mtspr (IBAT0U, upper); 51*a47a12beSStefan Roese break; 52*a47a12beSStefan Roese case DBAT1: 53*a47a12beSStefan Roese mtspr (DBAT1L, lower); 54*a47a12beSStefan Roese mtspr (DBAT1U, upper); 55*a47a12beSStefan Roese batn = 1; 56*a47a12beSStefan Roese break; 57*a47a12beSStefan Roese case IBAT1: 58*a47a12beSStefan Roese mtspr (IBAT1L, lower); 59*a47a12beSStefan Roese mtspr (IBAT1U, upper); 60*a47a12beSStefan Roese break; 61*a47a12beSStefan Roese case DBAT2: 62*a47a12beSStefan Roese mtspr (DBAT2L, lower); 63*a47a12beSStefan Roese mtspr (DBAT2U, upper); 64*a47a12beSStefan Roese batn = 2; 65*a47a12beSStefan Roese break; 66*a47a12beSStefan Roese case IBAT2: 67*a47a12beSStefan Roese mtspr (IBAT2L, lower); 68*a47a12beSStefan Roese mtspr (IBAT2U, upper); 69*a47a12beSStefan Roese break; 70*a47a12beSStefan Roese case DBAT3: 71*a47a12beSStefan Roese mtspr (DBAT3L, lower); 72*a47a12beSStefan Roese mtspr (DBAT3U, upper); 73*a47a12beSStefan Roese batn = 3; 74*a47a12beSStefan Roese break; 75*a47a12beSStefan Roese case IBAT3: 76*a47a12beSStefan Roese mtspr (IBAT3L, lower); 77*a47a12beSStefan Roese mtspr (IBAT3U, upper); 78*a47a12beSStefan Roese break; 79*a47a12beSStefan Roese #ifdef CONFIG_HIGH_BATS 80*a47a12beSStefan Roese case DBAT4: 81*a47a12beSStefan Roese mtspr (DBAT4L, lower); 82*a47a12beSStefan Roese mtspr (DBAT4U, upper); 83*a47a12beSStefan Roese batn = 4; 84*a47a12beSStefan Roese break; 85*a47a12beSStefan Roese case IBAT4: 86*a47a12beSStefan Roese mtspr (IBAT4L, lower); 87*a47a12beSStefan Roese mtspr (IBAT4U, upper); 88*a47a12beSStefan Roese break; 89*a47a12beSStefan Roese case DBAT5: 90*a47a12beSStefan Roese mtspr (DBAT5L, lower); 91*a47a12beSStefan Roese mtspr (DBAT5U, upper); 92*a47a12beSStefan Roese batn = 5; 93*a47a12beSStefan Roese break; 94*a47a12beSStefan Roese case IBAT5: 95*a47a12beSStefan Roese mtspr (IBAT5L, lower); 96*a47a12beSStefan Roese mtspr (IBAT5U, upper); 97*a47a12beSStefan Roese break; 98*a47a12beSStefan Roese case DBAT6: 99*a47a12beSStefan Roese mtspr (DBAT6L, lower); 100*a47a12beSStefan Roese mtspr (DBAT6U, upper); 101*a47a12beSStefan Roese batn = 6; 102*a47a12beSStefan Roese break; 103*a47a12beSStefan Roese case IBAT6: 104*a47a12beSStefan Roese mtspr (IBAT6L, lower); 105*a47a12beSStefan Roese mtspr (IBAT6U, upper); 106*a47a12beSStefan Roese break; 107*a47a12beSStefan Roese case DBAT7: 108*a47a12beSStefan Roese mtspr (DBAT7L, lower); 109*a47a12beSStefan Roese mtspr (DBAT7U, upper); 110*a47a12beSStefan Roese batn = 7; 111*a47a12beSStefan Roese break; 112*a47a12beSStefan Roese case IBAT7: 113*a47a12beSStefan Roese mtspr (IBAT7L, lower); 114*a47a12beSStefan Roese mtspr (IBAT7U, upper); 115*a47a12beSStefan Roese break; 116*a47a12beSStefan Roese #endif 117*a47a12beSStefan Roese default: 118*a47a12beSStefan Roese return (-1); 119*a47a12beSStefan Roese } 120*a47a12beSStefan Roese 121*a47a12beSStefan Roese #ifdef CONFIG_ADDR_MAP 122*a47a12beSStefan Roese if ((gd->flags & GD_FLG_RELOC) && (batn >= 0)) { 123*a47a12beSStefan Roese phys_size_t size; 124*a47a12beSStefan Roese if (!BATU_VALID(upper)) 125*a47a12beSStefan Roese size = 0; 126*a47a12beSStefan Roese else 127*a47a12beSStefan Roese size = BATU_SIZE(upper); 128*a47a12beSStefan Roese addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower), 129*a47a12beSStefan Roese size, batn); 130*a47a12beSStefan Roese } 131*a47a12beSStefan Roese #endif 132*a47a12beSStefan Roese 133*a47a12beSStefan Roese sync(); 134*a47a12beSStefan Roese isync(); 135*a47a12beSStefan Roese 136*a47a12beSStefan Roese return (0); 137*a47a12beSStefan Roese } 138*a47a12beSStefan Roese 139*a47a12beSStefan Roese int read_bat (ppc_bat_t bat, unsigned long *upper, unsigned long *lower) 140*a47a12beSStefan Roese { 141*a47a12beSStefan Roese unsigned long register u; 142*a47a12beSStefan Roese unsigned long register l; 143*a47a12beSStefan Roese 144*a47a12beSStefan Roese switch (bat) { 145*a47a12beSStefan Roese case DBAT0: 146*a47a12beSStefan Roese l = mfspr (DBAT0L); 147*a47a12beSStefan Roese u = mfspr (DBAT0U); 148*a47a12beSStefan Roese break; 149*a47a12beSStefan Roese case IBAT0: 150*a47a12beSStefan Roese l = mfspr (IBAT0L); 151*a47a12beSStefan Roese u = mfspr (IBAT0U); 152*a47a12beSStefan Roese break; 153*a47a12beSStefan Roese case DBAT1: 154*a47a12beSStefan Roese l = mfspr (DBAT1L); 155*a47a12beSStefan Roese u = mfspr (DBAT1U); 156*a47a12beSStefan Roese break; 157*a47a12beSStefan Roese case IBAT1: 158*a47a12beSStefan Roese l = mfspr (IBAT1L); 159*a47a12beSStefan Roese u = mfspr (IBAT1U); 160*a47a12beSStefan Roese break; 161*a47a12beSStefan Roese case DBAT2: 162*a47a12beSStefan Roese l = mfspr (DBAT2L); 163*a47a12beSStefan Roese u = mfspr (DBAT2U); 164*a47a12beSStefan Roese break; 165*a47a12beSStefan Roese case IBAT2: 166*a47a12beSStefan Roese l = mfspr (IBAT2L); 167*a47a12beSStefan Roese u = mfspr (IBAT2U); 168*a47a12beSStefan Roese break; 169*a47a12beSStefan Roese case DBAT3: 170*a47a12beSStefan Roese l = mfspr (DBAT3L); 171*a47a12beSStefan Roese u = mfspr (DBAT3U); 172*a47a12beSStefan Roese break; 173*a47a12beSStefan Roese case IBAT3: 174*a47a12beSStefan Roese l = mfspr (IBAT3L); 175*a47a12beSStefan Roese u = mfspr (IBAT3U); 176*a47a12beSStefan Roese break; 177*a47a12beSStefan Roese #ifdef CONFIG_HIGH_BATS 178*a47a12beSStefan Roese case DBAT4: 179*a47a12beSStefan Roese l = mfspr (DBAT4L); 180*a47a12beSStefan Roese u = mfspr (DBAT4U); 181*a47a12beSStefan Roese break; 182*a47a12beSStefan Roese case IBAT4: 183*a47a12beSStefan Roese l = mfspr (IBAT4L); 184*a47a12beSStefan Roese u = mfspr (IBAT4U); 185*a47a12beSStefan Roese break; 186*a47a12beSStefan Roese case DBAT5: 187*a47a12beSStefan Roese l = mfspr (DBAT5L); 188*a47a12beSStefan Roese u = mfspr (DBAT5U); 189*a47a12beSStefan Roese break; 190*a47a12beSStefan Roese case IBAT5: 191*a47a12beSStefan Roese l = mfspr (IBAT5L); 192*a47a12beSStefan Roese u = mfspr (IBAT5U); 193*a47a12beSStefan Roese break; 194*a47a12beSStefan Roese case DBAT6: 195*a47a12beSStefan Roese l = mfspr (DBAT6L); 196*a47a12beSStefan Roese u = mfspr (DBAT6U); 197*a47a12beSStefan Roese break; 198*a47a12beSStefan Roese case IBAT6: 199*a47a12beSStefan Roese l = mfspr (IBAT6L); 200*a47a12beSStefan Roese u = mfspr (IBAT6U); 201*a47a12beSStefan Roese break; 202*a47a12beSStefan Roese case DBAT7: 203*a47a12beSStefan Roese l = mfspr (DBAT7L); 204*a47a12beSStefan Roese u = mfspr (DBAT7U); 205*a47a12beSStefan Roese break; 206*a47a12beSStefan Roese case IBAT7: 207*a47a12beSStefan Roese l = mfspr (IBAT7L); 208*a47a12beSStefan Roese u = mfspr (IBAT7U); 209*a47a12beSStefan Roese break; 210*a47a12beSStefan Roese #endif 211*a47a12beSStefan Roese default: 212*a47a12beSStefan Roese return (-1); 213*a47a12beSStefan Roese } 214*a47a12beSStefan Roese 215*a47a12beSStefan Roese *upper = u; 216*a47a12beSStefan Roese *lower = l; 217*a47a12beSStefan Roese 218*a47a12beSStefan Roese return (0); 219*a47a12beSStefan Roese } 220*a47a12beSStefan Roese 221*a47a12beSStefan Roese void print_bats(void) 222*a47a12beSStefan Roese { 223*a47a12beSStefan Roese printf("BAT registers:\n"); 224*a47a12beSStefan Roese 225*a47a12beSStefan Roese printf ("\tIBAT0L = 0x%08X ", mfspr (IBAT0L)); 226*a47a12beSStefan Roese printf ("\tIBAT0U = 0x%08X\n", mfspr (IBAT0U)); 227*a47a12beSStefan Roese printf ("\tDBAT0L = 0x%08X ", mfspr (DBAT0L)); 228*a47a12beSStefan Roese printf ("\tDBAT0U = 0x%08X\n", mfspr (DBAT0U)); 229*a47a12beSStefan Roese printf ("\tIBAT1L = 0x%08X ", mfspr (IBAT1L)); 230*a47a12beSStefan Roese printf ("\tIBAT1U = 0x%08X\n", mfspr (IBAT1U)); 231*a47a12beSStefan Roese printf ("\tDBAT1L = 0x%08X ", mfspr (DBAT1L)); 232*a47a12beSStefan Roese printf ("\tDBAT1U = 0x%08X\n", mfspr (DBAT1U)); 233*a47a12beSStefan Roese printf ("\tIBAT2L = 0x%08X ", mfspr (IBAT2L)); 234*a47a12beSStefan Roese printf ("\tIBAT2U = 0x%08X\n", mfspr (IBAT2U)); 235*a47a12beSStefan Roese printf ("\tDBAT2L = 0x%08X ", mfspr (DBAT2L)); 236*a47a12beSStefan Roese printf ("\tDBAT2U = 0x%08X\n", mfspr (DBAT2U)); 237*a47a12beSStefan Roese printf ("\tIBAT3L = 0x%08X ", mfspr (IBAT3L)); 238*a47a12beSStefan Roese printf ("\tIBAT3U = 0x%08X\n", mfspr (IBAT3U)); 239*a47a12beSStefan Roese printf ("\tDBAT3L = 0x%08X ", mfspr (DBAT3L)); 240*a47a12beSStefan Roese printf ("\tDBAT3U = 0x%08X\n", mfspr (DBAT3U)); 241*a47a12beSStefan Roese 242*a47a12beSStefan Roese #ifdef CONFIG_HIGH_BATS 243*a47a12beSStefan Roese printf ("\tIBAT4L = 0x%08X ", mfspr (IBAT4L)); 244*a47a12beSStefan Roese printf ("\tIBAT4U = 0x%08X\n", mfspr (IBAT4U)); 245*a47a12beSStefan Roese printf ("\tDBAT4L = 0x%08X ", mfspr (DBAT4L)); 246*a47a12beSStefan Roese printf ("\tDBAT4U = 0x%08X\n", mfspr (DBAT4U)); 247*a47a12beSStefan Roese printf ("\tIBAT5L = 0x%08X ", mfspr (IBAT5L)); 248*a47a12beSStefan Roese printf ("\tIBAT5U = 0x%08X\n", mfspr (IBAT5U)); 249*a47a12beSStefan Roese printf ("\tDBAT5L = 0x%08X ", mfspr (DBAT5L)); 250*a47a12beSStefan Roese printf ("\tDBAT5U = 0x%08X\n", mfspr (DBAT5U)); 251*a47a12beSStefan Roese printf ("\tIBAT6L = 0x%08X ", mfspr (IBAT6L)); 252*a47a12beSStefan Roese printf ("\tIBAT6U = 0x%08X\n", mfspr (IBAT6U)); 253*a47a12beSStefan Roese printf ("\tDBAT6L = 0x%08X ", mfspr (DBAT6L)); 254*a47a12beSStefan Roese printf ("\tDBAT6U = 0x%08X\n", mfspr (DBAT6U)); 255*a47a12beSStefan Roese printf ("\tIBAT7L = 0x%08X ", mfspr (IBAT7L)); 256*a47a12beSStefan Roese printf ("\tIBAT7U = 0x%08X\n", mfspr (IBAT7U)); 257*a47a12beSStefan Roese printf ("\tDBAT7L = 0x%08X ", mfspr (DBAT7L)); 258*a47a12beSStefan Roese printf ("\tDBAT7U = 0x%08X\n", mfspr (DBAT7U)); 259*a47a12beSStefan Roese #endif 260*a47a12beSStefan Roese } 261