xref: /openbmc/linux/arch/mips/fw/sni/sniprom.c (revision a61127c2)
1 /*
2  * Big Endian PROM code for SNI RM machines
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 2005-2006 Florian Lohoff (flo@rfc822.org)
9  * Copyright (C) 2005-2006 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
10  */
11 
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
15 #include <linux/console.h>
16 
17 #include <asm/addrspace.h>
18 #include <asm/sni.h>
19 #include <asm/mipsprom.h>
20 #include <asm/mipsregs.h>
21 #include <asm/bootinfo.h>
22 #include <asm/setup.h>
23 
24 /* special SNI prom calls */
25 /*
26  * This does not exist in all proms - SINIX compares
27  * the prom env variable "version" against "2.0008"
28  * or greater. If lesser it tries to probe interesting
29  * registers
30  */
31 #define PROM_GET_MEMCONF	58
32 #define PROM_GET_HWCONF		61
33 
34 #define PROM_VEC		(u64 *)CKSEG1ADDR(0x1fc00000)
35 #define PROM_ENTRY(x)		(PROM_VEC + (x))
36 
37 #define ___prom_putchar		((int *(*)(int))PROM_ENTRY(PROM_PUTCHAR))
38 #define ___prom_getenv		((char *(*)(char *))PROM_ENTRY(PROM_GETENV))
39 #define ___prom_get_memconf	((void (*)(void *))PROM_ENTRY(PROM_GET_MEMCONF))
40 #define ___prom_get_hwconf	((u32 (*)(void))PROM_ENTRY(PROM_GET_HWCONF))
41 
42 #ifdef CONFIG_64BIT
43 
44 /* O32 stack has to be 8-byte aligned. */
45 static u64 o32_stk[4096];
46 #define O32_STK	  &o32_stk[sizeof(o32_stk)]
47 
48 #define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
49 				     __asm__(#fun " = call_o32")
50 
51 int   __PROM_O32(__prom_putchar, (int *(*)(int), void *, int));
52 char *__PROM_O32(__prom_getenv, (char *(*)(char *), void *, char *));
53 void  __PROM_O32(__prom_get_memconf, (void (*)(void *), void *, void *));
54 u32   __PROM_O32(__prom_get_hwconf, (u32 (*)(void), void *));
55 
56 #define _prom_putchar(x)     __prom_putchar(___prom_putchar, O32_STK, x)
57 #define _prom_getenv(x)	     __prom_getenv(___prom_getenv, O32_STK, x)
58 #define _prom_get_memconf(x) __prom_get_memconf(___prom_get_memconf, O32_STK, x)
59 #define _prom_get_hwconf()   __prom_get_hwconf(___prom_get_hwconf, O32_STK)
60 
61 #else
62 #define _prom_putchar(x)     ___prom_putchar(x)
63 #define _prom_getenv(x)	     ___prom_getenv(x)
64 #define _prom_get_memconf(x) ___prom_get_memconf(x)
65 #define _prom_get_hwconf(x)  ___prom_get_hwconf(x)
66 #endif
67 
68 void prom_putchar(char c)
69 {
70 	_prom_putchar(c);
71 }
72 
73 
74 char *prom_getenv(char *s)
75 {
76 	return _prom_getenv(s);
77 }
78 
79 void *prom_get_hwconf(void)
80 {
81 	u32 hwconf = _prom_get_hwconf();
82 
83 	if (hwconf == 0xffffffff)
84 		return NULL;
85 
86 	return (void *)CKSEG1ADDR(hwconf);
87 }
88 
89 void __init prom_free_prom_memory(void)
90 {
91 }
92 
93 /*
94  * /proc/cpuinfo system type
95  *
96  */
97 char *system_type = "Unknown";
98 const char *get_system_type(void)
99 {
100 	return system_type;
101 }
102 
103 static void __init sni_mem_init(void)
104 {
105 	int i, memsize;
106 	struct membank {
107 		u32		size;
108 		u32		base;
109 		u32		size2;
110 		u32		pad1;
111 		u32		pad2;
112 	} memconf[8];
113 	int brd_type = *(unsigned char *)SNI_IDPROM_BRDTYPE;
114 
115 
116 	/* MemSIZE from prom in 16MByte chunks */
117 	memsize = *((unsigned char *) SNI_IDPROM_MEMSIZE) * 16;
118 
119 	pr_debug("IDProm memsize: %u MByte\n", memsize);
120 
121 	/* get memory bank layout from prom */
122 	_prom_get_memconf(&memconf);
123 
124 	pr_debug("prom_get_mem_conf memory configuration:\n");
125 	for (i = 0; i < 8 && memconf[i].size; i++) {
126 		if (brd_type == SNI_BRD_PCI_TOWER ||
127 		    brd_type == SNI_BRD_PCI_TOWER_CPLUS) {
128 			if (memconf[i].base >= 0x20000000 &&
129 			    memconf[i].base <  0x30000000)
130 				memconf[i].base -= 0x20000000;
131 		}
132 		pr_debug("Bank%d: %08x @ %08x\n", i,
133 			memconf[i].size, memconf[i].base);
134 		add_memory_region(memconf[i].base, memconf[i].size,
135 				  BOOT_MEM_RAM);
136 	}
137 }
138 
139 void __init prom_init(void)
140 {
141 	int argc = fw_arg0;
142 	u32 *argv = (u32 *)CKSEG0ADDR(fw_arg1);
143 	int i;
144 
145 	sni_mem_init();
146 
147 	/* copy prom cmdline parameters to kernel cmdline */
148 	for (i = 1; i < argc; i++) {
149 		strcat(arcs_cmdline, (char *)CKSEG0ADDR(argv[i]));
150 		if (i < (argc - 1))
151 			strcat(arcs_cmdline, " ");
152 	}
153 }
154