xref: /OK3568_Linux_fs/kernel/arch/mips/bcm47xx/prom.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
3*4882a593Smuzhiyun  *  Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
4*4882a593Smuzhiyun  *  Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *  This program is free software; you can redistribute  it and/or modify it
7*4882a593Smuzhiyun  *  under  the terms of  the GNU General  Public License as published by the
8*4882a593Smuzhiyun  *  Free Software Foundation;  either version 2 of the  License, or (at your
9*4882a593Smuzhiyun  *  option) any later version.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
12*4882a593Smuzhiyun  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
13*4882a593Smuzhiyun  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
14*4882a593Smuzhiyun  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
15*4882a593Smuzhiyun  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*4882a593Smuzhiyun  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
17*4882a593Smuzhiyun  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
18*4882a593Smuzhiyun  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
19*4882a593Smuzhiyun  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20*4882a593Smuzhiyun  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  *  You should have received a copy of the  GNU General Public License along
23*4882a593Smuzhiyun  *  with this program; if not, write  to the Free Software Foundation, Inc.,
24*4882a593Smuzhiyun  *  675 Mass Ave, Cambridge, MA 02139, USA.
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include <linux/init.h>
28*4882a593Smuzhiyun #include <linux/types.h>
29*4882a593Smuzhiyun #include <linux/kernel.h>
30*4882a593Smuzhiyun #include <linux/memblock.h>
31*4882a593Smuzhiyun #include <linux/spinlock.h>
32*4882a593Smuzhiyun #include <linux/ssb/ssb_driver_chipcommon.h>
33*4882a593Smuzhiyun #include <linux/ssb/ssb_regs.h>
34*4882a593Smuzhiyun #include <linux/smp.h>
35*4882a593Smuzhiyun #include <asm/bootinfo.h>
36*4882a593Smuzhiyun #include <bcm47xx.h>
37*4882a593Smuzhiyun #include <bcm47xx_board.h>
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun static char bcm47xx_system_type[20] = "Broadcom BCM47XX";
40*4882a593Smuzhiyun 
get_system_type(void)41*4882a593Smuzhiyun const char *get_system_type(void)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	return bcm47xx_system_type;
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun 
bcm47xx_set_system_type(u16 chip_id)46*4882a593Smuzhiyun __init void bcm47xx_set_system_type(u16 chip_id)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun 	snprintf(bcm47xx_system_type, sizeof(bcm47xx_system_type),
49*4882a593Smuzhiyun 		 (chip_id > 0x9999) ? "Broadcom BCM%d" :
50*4882a593Smuzhiyun 				      "Broadcom BCM%04X",
51*4882a593Smuzhiyun 		 chip_id);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static unsigned long lowmem __initdata;
55*4882a593Smuzhiyun 
prom_init_mem(void)56*4882a593Smuzhiyun static __init void prom_init_mem(void)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun 	unsigned long mem;
59*4882a593Smuzhiyun 	unsigned long max;
60*4882a593Smuzhiyun 	unsigned long off;
61*4882a593Smuzhiyun 	struct cpuinfo_mips *c = &current_cpu_data;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	/* Figure out memory size by finding aliases.
64*4882a593Smuzhiyun 	 *
65*4882a593Smuzhiyun 	 * We should theoretically use the mapping from CFE using cfe_enummem().
66*4882a593Smuzhiyun 	 * However as the BCM47XX is mostly used on low-memory systems, we
67*4882a593Smuzhiyun 	 * want to reuse the memory used by CFE (around 4MB). That means cfe_*
68*4882a593Smuzhiyun 	 * functions stop to work at some point during the boot, we should only
69*4882a593Smuzhiyun 	 * call them at the beginning of the boot.
70*4882a593Smuzhiyun 	 *
71*4882a593Smuzhiyun 	 * BCM47XX uses 128MB for addressing the ram, if the system contains
72*4882a593Smuzhiyun 	 * less that that amount of ram it remaps the ram more often into the
73*4882a593Smuzhiyun 	 * available space.
74*4882a593Smuzhiyun 	 */
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	/* Physical address, without mapping to any kernel segment */
77*4882a593Smuzhiyun 	off = CPHYSADDR((unsigned long)prom_init);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	/* Accessing memory after 128 MiB will cause an exception */
80*4882a593Smuzhiyun 	max = 128 << 20;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	for (mem = 1 << 20; mem < max; mem += 1 << 20) {
83*4882a593Smuzhiyun 		/* Loop condition may be not enough, off may be over 1 MiB */
84*4882a593Smuzhiyun 		if (off + mem >= max) {
85*4882a593Smuzhiyun 			mem = max;
86*4882a593Smuzhiyun 			pr_debug("Assume 128MB RAM\n");
87*4882a593Smuzhiyun 			break;
88*4882a593Smuzhiyun 		}
89*4882a593Smuzhiyun 		if (!memcmp((void *)prom_init, (void *)prom_init + mem, 32))
90*4882a593Smuzhiyun 			break;
91*4882a593Smuzhiyun 	}
92*4882a593Smuzhiyun 	lowmem = mem;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	/* Ignoring the last page when ddr size is 128M. Cached
95*4882a593Smuzhiyun 	 * accesses to last page is causing the processor to prefetch
96*4882a593Smuzhiyun 	 * using address above 128M stepping out of the ddr address
97*4882a593Smuzhiyun 	 * space.
98*4882a593Smuzhiyun 	 */
99*4882a593Smuzhiyun 	if (c->cputype == CPU_74K && (mem == (128  << 20)))
100*4882a593Smuzhiyun 		mem -= 0x1000;
101*4882a593Smuzhiyun 	memblock_add(0, mem);
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun /*
105*4882a593Smuzhiyun  * This is the first serial on the chip common core, it is at this position
106*4882a593Smuzhiyun  * for sb (ssb) and ai (bcma) bus.
107*4882a593Smuzhiyun  */
108*4882a593Smuzhiyun #define BCM47XX_SERIAL_ADDR (SSB_ENUM_BASE + SSB_CHIPCO_UART0_DATA)
109*4882a593Smuzhiyun 
prom_init(void)110*4882a593Smuzhiyun void __init prom_init(void)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun 	prom_init_mem();
113*4882a593Smuzhiyun 	setup_8250_early_printk_port(CKSEG1ADDR(BCM47XX_SERIAL_ADDR), 0, 0);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
prom_free_prom_memory(void)116*4882a593Smuzhiyun void __init prom_free_prom_memory(void)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun #if defined(CONFIG_BCM47XX_BCMA) && defined(CONFIG_HIGHMEM)
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun #define EXTVBASE	0xc0000000
123*4882a593Smuzhiyun #define ENTRYLO(x)	((pte_val(pfn_pte((x) >> _PFN_SHIFT, PAGE_KERNEL_UNCACHED)) >> 6) | 1)
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun #include <asm/tlbflush.h>
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /* Stripped version of tlb_init, with the call to build_tlb_refill_handler
128*4882a593Smuzhiyun  * dropped. Calling it at this stage causes a hang.
129*4882a593Smuzhiyun  */
early_tlb_init(void)130*4882a593Smuzhiyun void early_tlb_init(void)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun 	write_c0_pagemask(PM_DEFAULT_MASK);
133*4882a593Smuzhiyun 	write_c0_wired(0);
134*4882a593Smuzhiyun 	temp_tlb_entry = current_cpu_data.tlbsize - 1;
135*4882a593Smuzhiyun 	local_flush_tlb_all();
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun 
bcm47xx_prom_highmem_init(void)138*4882a593Smuzhiyun void __init bcm47xx_prom_highmem_init(void)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun 	unsigned long off = (unsigned long)prom_init;
141*4882a593Smuzhiyun 	unsigned long extmem = 0;
142*4882a593Smuzhiyun 	bool highmem_region = false;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	if (WARN_ON(bcm47xx_bus_type != BCM47XX_BUS_TYPE_BCMA))
145*4882a593Smuzhiyun 		return;
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
148*4882a593Smuzhiyun 		highmem_region = true;
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun 	if (lowmem != 128 << 20 || !highmem_region)
151*4882a593Smuzhiyun 		return;
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	early_tlb_init();
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	/* Add one temporary TLB entry to map SDRAM Region 2.
156*4882a593Smuzhiyun 	 *      Physical        Virtual
157*4882a593Smuzhiyun 	 *      0x80000000      0xc0000000      (1st: 256MB)
158*4882a593Smuzhiyun 	 *      0x90000000      0xd0000000      (2nd: 256MB)
159*4882a593Smuzhiyun 	 */
160*4882a593Smuzhiyun 	add_temporary_entry(ENTRYLO(0x80000000),
161*4882a593Smuzhiyun 			    ENTRYLO(0x80000000 + (256 << 20)),
162*4882a593Smuzhiyun 			    EXTVBASE, PM_256M);
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	off = EXTVBASE + __pa(off);
165*4882a593Smuzhiyun 	for (extmem = 128 << 20; extmem < 512 << 20; extmem <<= 1) {
166*4882a593Smuzhiyun 		if (!memcmp((void *)prom_init, (void *)(off + extmem), 16))
167*4882a593Smuzhiyun 			break;
168*4882a593Smuzhiyun 	}
169*4882a593Smuzhiyun 	extmem -= lowmem;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	early_tlb_init();
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	if (!extmem)
174*4882a593Smuzhiyun 		return;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	pr_warn("Found %lu MiB of extra memory, but highmem is unsupported yet!\n",
177*4882a593Smuzhiyun 		extmem >> 20);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	/* TODO: Register extra memory */
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun #endif /* defined(CONFIG_BCM47XX_BCMA) && defined(CONFIG_HIGHMEM) */
183