2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-08-17 09:36:01 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Rich Ireland, Enterasys Networks, rireland@enterasys.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/mmu.h>
|
2008-08-04 19:01:53 +00:00
|
|
|
#include <asm/io.h>
|
2011-11-04 15:55:59 +00:00
|
|
|
#include <linux/compiler.h>
|
2002-08-17 09:36:01 +00:00
|
|
|
|
2009-02-04 00:10:52 +00:00
|
|
|
#ifdef CONFIG_ADDR_MAP
|
|
|
|
#include <addr_map.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
int write_bat (ppc_bat_t bat, unsigned long upper, unsigned long lower)
|
|
|
|
{
|
2011-11-04 15:55:59 +00:00
|
|
|
__maybe_unused int batn = -1;
|
2009-02-04 00:10:52 +00:00
|
|
|
|
2008-08-04 19:01:53 +00:00
|
|
|
sync();
|
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
switch (bat) {
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT0:
|
|
|
|
mtspr (DBAT0L, lower);
|
|
|
|
mtspr (DBAT0U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 0;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT0:
|
|
|
|
mtspr (IBAT0L, lower);
|
|
|
|
mtspr (IBAT0U, upper);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT1:
|
|
|
|
mtspr (DBAT1L, lower);
|
|
|
|
mtspr (DBAT1U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 1;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT1:
|
|
|
|
mtspr (IBAT1L, lower);
|
|
|
|
mtspr (IBAT1U, upper);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT2:
|
|
|
|
mtspr (DBAT2L, lower);
|
|
|
|
mtspr (DBAT2U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 2;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT2:
|
|
|
|
mtspr (IBAT2L, lower);
|
|
|
|
mtspr (IBAT2U, upper);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT3:
|
|
|
|
mtspr (DBAT3L, lower);
|
|
|
|
mtspr (DBAT3U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 3;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT3:
|
|
|
|
mtspr (IBAT3L, lower);
|
|
|
|
mtspr (IBAT3U, upper);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
#ifdef CONFIG_HIGH_BATS
|
|
|
|
case DBAT4:
|
|
|
|
mtspr (DBAT4L, lower);
|
|
|
|
mtspr (DBAT4U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 4;
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case IBAT4:
|
|
|
|
mtspr (IBAT4L, lower);
|
|
|
|
mtspr (IBAT4U, upper);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT5:
|
|
|
|
mtspr (DBAT5L, lower);
|
|
|
|
mtspr (DBAT5U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 5;
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case IBAT5:
|
|
|
|
mtspr (IBAT5L, lower);
|
|
|
|
mtspr (IBAT5U, upper);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT6:
|
|
|
|
mtspr (DBAT6L, lower);
|
|
|
|
mtspr (DBAT6U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 6;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
|
|
|
case IBAT6:
|
|
|
|
mtspr (IBAT6L, lower);
|
|
|
|
mtspr (IBAT6U, upper);
|
|
|
|
break;
|
|
|
|
case DBAT7:
|
|
|
|
mtspr (DBAT7L, lower);
|
|
|
|
mtspr (DBAT7U, upper);
|
2009-02-04 00:10:52 +00:00
|
|
|
batn = 7;
|
2008-05-16 02:29:04 +00:00
|
|
|
break;
|
|
|
|
case IBAT7:
|
|
|
|
mtspr (IBAT7L, lower);
|
|
|
|
mtspr (IBAT7U, upper);
|
|
|
|
break;
|
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
default:
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2009-02-04 00:10:52 +00:00
|
|
|
#ifdef CONFIG_ADDR_MAP
|
|
|
|
if ((gd->flags & GD_FLG_RELOC) && (batn >= 0)) {
|
|
|
|
phys_size_t size;
|
|
|
|
if (!BATU_VALID(upper))
|
|
|
|
size = 0;
|
|
|
|
else
|
|
|
|
size = BATU_SIZE(upper);
|
|
|
|
addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower),
|
|
|
|
size, batn);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-04 19:01:53 +00:00
|
|
|
sync();
|
|
|
|
isync();
|
|
|
|
|
2002-08-17 09:36:01 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_bat (ppc_bat_t bat, unsigned long *upper, unsigned long *lower)
|
|
|
|
{
|
|
|
|
unsigned long register u;
|
|
|
|
unsigned long register l;
|
|
|
|
|
|
|
|
switch (bat) {
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT0:
|
|
|
|
l = mfspr (DBAT0L);
|
|
|
|
u = mfspr (DBAT0U);
|
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT0:
|
|
|
|
l = mfspr (IBAT0L);
|
|
|
|
u = mfspr (IBAT0U);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT1:
|
|
|
|
l = mfspr (DBAT1L);
|
|
|
|
u = mfspr (DBAT1U);
|
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT1:
|
|
|
|
l = mfspr (IBAT1L);
|
|
|
|
u = mfspr (IBAT1U);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT2:
|
|
|
|
l = mfspr (DBAT2L);
|
|
|
|
u = mfspr (DBAT2U);
|
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT2:
|
|
|
|
l = mfspr (IBAT2L);
|
|
|
|
u = mfspr (IBAT2U);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT3:
|
|
|
|
l = mfspr (DBAT3L);
|
|
|
|
u = mfspr (DBAT3U);
|
|
|
|
break;
|
2002-08-17 09:36:01 +00:00
|
|
|
case IBAT3:
|
|
|
|
l = mfspr (IBAT3L);
|
|
|
|
u = mfspr (IBAT3U);
|
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
#ifdef CONFIG_HIGH_BATS
|
|
|
|
case DBAT4:
|
|
|
|
l = mfspr (DBAT4L);
|
|
|
|
u = mfspr (DBAT4U);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case IBAT4:
|
|
|
|
l = mfspr (IBAT4L);
|
|
|
|
u = mfspr (IBAT4U);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT5:
|
|
|
|
l = mfspr (DBAT5L);
|
|
|
|
u = mfspr (DBAT5U);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case IBAT5:
|
|
|
|
l = mfspr (IBAT5L);
|
|
|
|
u = mfspr (IBAT5U);
|
2002-08-17 09:36:01 +00:00
|
|
|
break;
|
2008-05-16 02:29:04 +00:00
|
|
|
case DBAT6:
|
|
|
|
l = mfspr (DBAT6L);
|
|
|
|
u = mfspr (DBAT6U);
|
|
|
|
break;
|
|
|
|
case IBAT6:
|
|
|
|
l = mfspr (IBAT6L);
|
|
|
|
u = mfspr (IBAT6U);
|
|
|
|
break;
|
|
|
|
case DBAT7:
|
|
|
|
l = mfspr (DBAT7L);
|
|
|
|
u = mfspr (DBAT7U);
|
|
|
|
break;
|
|
|
|
case IBAT7:
|
|
|
|
l = mfspr (IBAT7L);
|
|
|
|
u = mfspr (IBAT7U);
|
|
|
|
break;
|
|
|
|
#endif
|
2002-08-17 09:36:01 +00:00
|
|
|
default:
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
*upper = u;
|
|
|
|
*lower = l;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
2008-05-09 20:41:35 +00:00
|
|
|
|
|
|
|
void print_bats(void)
|
|
|
|
{
|
|
|
|
printf("BAT registers:\n");
|
|
|
|
|
|
|
|
printf ("\tIBAT0L = 0x%08X ", mfspr (IBAT0L));
|
|
|
|
printf ("\tIBAT0U = 0x%08X\n", mfspr (IBAT0U));
|
|
|
|
printf ("\tDBAT0L = 0x%08X ", mfspr (DBAT0L));
|
|
|
|
printf ("\tDBAT0U = 0x%08X\n", mfspr (DBAT0U));
|
|
|
|
printf ("\tIBAT1L = 0x%08X ", mfspr (IBAT1L));
|
|
|
|
printf ("\tIBAT1U = 0x%08X\n", mfspr (IBAT1U));
|
|
|
|
printf ("\tDBAT1L = 0x%08X ", mfspr (DBAT1L));
|
|
|
|
printf ("\tDBAT1U = 0x%08X\n", mfspr (DBAT1U));
|
|
|
|
printf ("\tIBAT2L = 0x%08X ", mfspr (IBAT2L));
|
|
|
|
printf ("\tIBAT2U = 0x%08X\n", mfspr (IBAT2U));
|
|
|
|
printf ("\tDBAT2L = 0x%08X ", mfspr (DBAT2L));
|
|
|
|
printf ("\tDBAT2U = 0x%08X\n", mfspr (DBAT2U));
|
|
|
|
printf ("\tIBAT3L = 0x%08X ", mfspr (IBAT3L));
|
|
|
|
printf ("\tIBAT3U = 0x%08X\n", mfspr (IBAT3U));
|
|
|
|
printf ("\tDBAT3L = 0x%08X ", mfspr (DBAT3L));
|
|
|
|
printf ("\tDBAT3U = 0x%08X\n", mfspr (DBAT3U));
|
|
|
|
|
|
|
|
#ifdef CONFIG_HIGH_BATS
|
|
|
|
printf ("\tIBAT4L = 0x%08X ", mfspr (IBAT4L));
|
|
|
|
printf ("\tIBAT4U = 0x%08X\n", mfspr (IBAT4U));
|
|
|
|
printf ("\tDBAT4L = 0x%08X ", mfspr (DBAT4L));
|
|
|
|
printf ("\tDBAT4U = 0x%08X\n", mfspr (DBAT4U));
|
|
|
|
printf ("\tIBAT5L = 0x%08X ", mfspr (IBAT5L));
|
|
|
|
printf ("\tIBAT5U = 0x%08X\n", mfspr (IBAT5U));
|
|
|
|
printf ("\tDBAT5L = 0x%08X ", mfspr (DBAT5L));
|
|
|
|
printf ("\tDBAT5U = 0x%08X\n", mfspr (DBAT5U));
|
|
|
|
printf ("\tIBAT6L = 0x%08X ", mfspr (IBAT6L));
|
|
|
|
printf ("\tIBAT6U = 0x%08X\n", mfspr (IBAT6U));
|
|
|
|
printf ("\tDBAT6L = 0x%08X ", mfspr (DBAT6L));
|
|
|
|
printf ("\tDBAT6U = 0x%08X\n", mfspr (DBAT6U));
|
|
|
|
printf ("\tIBAT7L = 0x%08X ", mfspr (IBAT7L));
|
|
|
|
printf ("\tIBAT7U = 0x%08X\n", mfspr (IBAT7U));
|
|
|
|
printf ("\tDBAT7L = 0x%08X ", mfspr (DBAT7L));
|
|
|
|
printf ("\tDBAT7U = 0x%08X\n", mfspr (DBAT7U));
|
|
|
|
#endif
|
|
|
|
}
|