/*1* Copyright (C) 2004 Florian Schirmer <[email protected]>2* Copyright (C) 2007 Aurelien Jarno <[email protected]>3* Copyright (C) 2010-2012 Hauke Mehrtens <[email protected]>4*5* This program is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License as published by the7* Free Software Foundation; either version 2 of the License, or (at your8* option) any later version.9*10* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED11* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN13* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,14* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT15* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF16* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON17* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT18* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF19* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.20*21* You should have received a copy of the GNU General Public License along22* with this program; if not, write to the Free Software Foundation, Inc.,23* 675 Mass Ave, Cambridge, MA 02139, USA.24*/2526#include <linux/init.h>27#include <linux/types.h>28#include <linux/kernel.h>29#include <linux/memblock.h>30#include <linux/spinlock.h>31#include <linux/ssb/ssb_driver_chipcommon.h>32#include <linux/ssb/ssb_regs.h>33#include <linux/smp.h>34#include <asm/bmips.h>35#include <asm/bootinfo.h>36#include <bcm47xx.h>37#include <bcm47xx_board.h>38#include "bcm47xx_private.h"3940static char bcm47xx_system_type[20] = "Broadcom BCM47XX";4142const char *get_system_type(void)43{44return bcm47xx_system_type;45}4647__init void bcm47xx_set_system_type(u16 chip_id)48{49snprintf(bcm47xx_system_type, sizeof(bcm47xx_system_type),50(chip_id > 0x9999) ? "Broadcom BCM%d" :51"Broadcom BCM%04X",52chip_id);53}5455static unsigned long lowmem __initdata;5657static __init void prom_init_mem(void)58{59unsigned long mem;60unsigned long max;61unsigned long off;62struct cpuinfo_mips *c = ¤t_cpu_data;6364/* Figure out memory size by finding aliases.65*66* We should theoretically use the mapping from CFE using cfe_enummem().67* However as the BCM47XX is mostly used on low-memory systems, we68* want to reuse the memory used by CFE (around 4MB). That means cfe_*69* functions stop to work at some point during the boot, we should only70* call them at the beginning of the boot.71*72* BCM47XX uses 128MB for addressing the ram, if the system contains73* less than that amount of ram it remaps the ram more often into the74* available space.75*/7677/* Physical address, without mapping to any kernel segment */78off = CPHYSADDR((unsigned long)prom_init);7980/* Accessing memory after 128 MiB will cause an exception */81max = 128 << 20;8283for (mem = 1 << 20; mem < max; mem += 1 << 20) {84/* Loop condition may be not enough, off may be over 1 MiB */85if (off + mem >= max) {86mem = max;87pr_debug("Assume 128MB RAM\n");88break;89}90if (!memcmp((void *)prom_init, (void *)prom_init + mem, 32))91break;92}93lowmem = mem;9495/* Ignoring the last page when ddr size is 128M. Cached96* accesses to last page is causing the processor to prefetch97* using address above 128M stepping out of the ddr address98* space.99*/100if (c->cputype == CPU_74K && (mem == (128 << 20)))101mem -= 0x1000;102memblock_add(0, mem);103}104105/*106* This is the first serial on the chip common core, it is at this position107* for sb (ssb) and ai (bcma) bus.108*/109#define BCM47XX_SERIAL_ADDR (SSB_ENUM_BASE + SSB_CHIPCO_UART0_DATA)110111void __init prom_init(void)112{113/* Cache CBR addr before CPU/DMA setup */114bmips_cbr_addr = BMIPS_GET_CBR();115prom_init_mem();116setup_8250_early_printk_port(CKSEG1ADDR(BCM47XX_SERIAL_ADDR), 0, 0);117}118119#if defined(CONFIG_BCM47XX_BCMA) && defined(CONFIG_HIGHMEM)120121#define EXTVBASE 0xc0000000122#define ENTRYLO(x) ((pte_val(pfn_pte((x) >> PFN_PTE_SHIFT, PAGE_KERNEL_UNCACHED)) >> 6) | 1)123124#include <asm/tlbflush.h>125126/* Stripped version of tlb_init, with the call to build_tlb_refill_handler127* dropped. Calling it at this stage causes a hang.128*/129static void early_tlb_init(void)130{131write_c0_pagemask(PM_DEFAULT_MASK);132write_c0_wired(0);133temp_tlb_entry = current_cpu_data.tlbsize - 1;134local_flush_tlb_all();135}136137void __init bcm47xx_prom_highmem_init(void)138{139unsigned long off = (unsigned long)prom_init;140unsigned long extmem = 0;141bool highmem_region = false;142143if (WARN_ON(bcm47xx_bus_type != BCM47XX_BUS_TYPE_BCMA))144return;145146if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)147highmem_region = true;148149if (lowmem != 128 << 20 || !highmem_region)150return;151152early_tlb_init();153154/* Add one temporary TLB entry to map SDRAM Region 2.155* Physical Virtual156* 0x80000000 0xc0000000 (1st: 256MB)157* 0x90000000 0xd0000000 (2nd: 256MB)158*/159add_temporary_entry(ENTRYLO(0x80000000),160ENTRYLO(0x80000000 + (256 << 20)),161EXTVBASE, PM_256M);162163off = EXTVBASE + __pa(off);164for (extmem = 128 << 20; extmem < 512 << 20; extmem <<= 1) {165if (!memcmp((void *)prom_init, (void *)(off + extmem), 16))166break;167}168extmem -= lowmem;169170early_tlb_init();171172if (!extmem)173return;174175pr_warn("Found %lu MiB of extra memory, but highmem is unsupported yet!\n",176extmem >> 20);177178/* TODO: Register extra memory */179}180181#endif /* defined(CONFIG_BCM47XX_BCMA) && defined(CONFIG_HIGHMEM) */182183184