0001
0002
0003
0004
0005
0006 #include <linux/init.h>
0007 #include <linux/kernel.h>
0008 #include <linux/linkage.h>
0009 #include <linux/mm.h>
0010 #include <linux/memblock.h>
0011 #include <linux/pm.h>
0012 #include <linux/smp.h>
0013
0014 #include <asm/bootinfo.h>
0015 #include <asm/reboot.h>
0016 #include <asm/setup.h>
0017 #include <asm/sibyte/board.h>
0018 #include <asm/smp-ops.h>
0019
0020 #include <asm/fw/cfe/cfe_api.h>
0021 #include <asm/fw/cfe/cfe_error.h>
0022
0023
0024 #ifdef CONFIG_64BIT
0025 #define MAX_RAM_SIZE (~0ULL)
0026 #else
0027 #ifdef CONFIG_HIGHMEM
0028 #ifdef CONFIG_PHYS_ADDR_T_64BIT
0029 #define MAX_RAM_SIZE (~0ULL)
0030 #else
0031 #define MAX_RAM_SIZE (0xffffffffULL)
0032 #endif
0033 #else
0034 #define MAX_RAM_SIZE (0x1fffffffULL)
0035 #endif
0036 #endif
0037
0038 #define SIBYTE_MAX_MEM_REGIONS 8
0039 phys_addr_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
0040 phys_addr_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
0041 unsigned int board_mem_region_count;
0042
0043 int cfe_cons_handle;
0044
0045 #ifdef CONFIG_BLK_DEV_INITRD
0046 extern unsigned long initrd_start, initrd_end;
0047 #endif
0048
0049 static void __noreturn cfe_linux_exit(void *arg)
0050 {
0051 int warm = *(int *)arg;
0052
0053 if (smp_processor_id()) {
0054 static int reboot_smp;
0055
0056
0057 if (!reboot_smp) {
0058
0059 reboot_smp = 1;
0060 smp_call_function(cfe_linux_exit, arg, 0);
0061 }
0062 } else {
0063 printk("Passing control back to CFE...\n");
0064 cfe_exit(warm, 0);
0065 printk("cfe_exit returned??\n");
0066 }
0067 while (1);
0068 }
0069
0070 static void __noreturn cfe_linux_restart(char *command)
0071 {
0072 static const int zero;
0073
0074 cfe_linux_exit((void *)&zero);
0075 }
0076
0077 static void __noreturn cfe_linux_halt(void)
0078 {
0079 static const int one = 1;
0080
0081 cfe_linux_exit((void *)&one);
0082 }
0083
0084 static __init void prom_meminit(void)
0085 {
0086 u64 addr, size, type;
0087 int mem_flags = 0;
0088 unsigned int idx;
0089 int rd_flag;
0090 #ifdef CONFIG_BLK_DEV_INITRD
0091 unsigned long initrd_pstart;
0092 unsigned long initrd_pend;
0093
0094 initrd_pstart = CPHYSADDR(initrd_start);
0095 initrd_pend = CPHYSADDR(initrd_end);
0096 if (initrd_start &&
0097 ((initrd_pstart > MAX_RAM_SIZE)
0098 || (initrd_pend > MAX_RAM_SIZE))) {
0099 panic("initrd out of addressable memory");
0100 }
0101
0102 #endif
0103
0104 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
0105 idx++) {
0106 rd_flag = 0;
0107 if (type == CFE_MI_AVAILABLE) {
0108
0109
0110
0111
0112 #ifdef CONFIG_BLK_DEV_INITRD
0113 if (initrd_start) {
0114 if ((initrd_pstart > addr) &&
0115 (initrd_pstart < (addr + size))) {
0116 memblock_add(addr,
0117 initrd_pstart - addr);
0118 rd_flag = 1;
0119 }
0120 if ((initrd_pend > addr) &&
0121 (initrd_pend < (addr + size))) {
0122 memblock_add(initrd_pend,
0123 (addr + size) - initrd_pend);
0124 rd_flag = 1;
0125 }
0126 }
0127 #endif
0128 if (!rd_flag) {
0129 if (addr > MAX_RAM_SIZE)
0130 continue;
0131 if (addr+size > MAX_RAM_SIZE)
0132 size = MAX_RAM_SIZE - (addr+size) + 1;
0133
0134
0135
0136
0137
0138
0139
0140 if (size > 512)
0141 size -= 512;
0142 memblock_add(addr, size);
0143 }
0144 board_mem_region_addrs[board_mem_region_count] = addr;
0145 board_mem_region_sizes[board_mem_region_count] = size;
0146 board_mem_region_count++;
0147 if (board_mem_region_count ==
0148 SIBYTE_MAX_MEM_REGIONS) {
0149
0150
0151
0152 while(1);
0153 }
0154 }
0155 }
0156 #ifdef CONFIG_BLK_DEV_INITRD
0157 if (initrd_start) {
0158 memblock_add(initrd_pstart, initrd_pend - initrd_pstart);
0159 memblock_reserve(initrd_pstart, initrd_pend - initrd_pstart);
0160 }
0161 #endif
0162 }
0163
0164 #ifdef CONFIG_BLK_DEV_INITRD
0165 static int __init initrd_setup(char *str)
0166 {
0167 char rdarg[64];
0168 int idx;
0169 char *tmp, *endptr;
0170 unsigned long initrd_size;
0171
0172
0173 for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
0174 if (!str[idx] || (str[idx] == ' ')) break;
0175 rdarg[idx] = str[idx];
0176 }
0177
0178 rdarg[idx] = 0;
0179 str = rdarg;
0180
0181
0182
0183
0184
0185 for (tmp = str; *tmp != '@'; tmp++) {
0186 if (!*tmp) {
0187 goto fail;
0188 }
0189 }
0190 *tmp = 0;
0191 tmp++;
0192 if (!*tmp) {
0193 goto fail;
0194 }
0195 initrd_size = simple_strtoul(str, &endptr, 16);
0196 if (*endptr) {
0197 *(tmp-1) = '@';
0198 goto fail;
0199 }
0200 *(tmp-1) = '@';
0201 initrd_start = simple_strtoul(tmp, &endptr, 16);
0202 if (*endptr) {
0203 goto fail;
0204 }
0205 initrd_end = initrd_start + initrd_size;
0206 printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
0207 return 1;
0208 fail:
0209 printk("Bad initrd argument. Disabling initrd\n");
0210 initrd_start = 0;
0211 initrd_end = 0;
0212 return 1;
0213 }
0214
0215 #endif
0216
0217 extern const struct plat_smp_ops sb_smp_ops;
0218 extern const struct plat_smp_ops bcm1480_smp_ops;
0219
0220
0221
0222
0223 void __init prom_init(void)
0224 {
0225 uint64_t cfe_ept, cfe_handle;
0226 unsigned int cfe_eptseal;
0227 int argc = fw_arg0;
0228 char **envp = (char **) fw_arg2;
0229 int *prom_vec = (int *) fw_arg3;
0230
0231 _machine_restart = cfe_linux_restart;
0232 _machine_halt = cfe_linux_halt;
0233 pm_power_off = cfe_linux_halt;
0234
0235
0236
0237
0238
0239 if (argc < 0) {
0240 cfe_handle = (uint64_t)(long)argc;
0241 cfe_ept = (long)envp;
0242 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
0243 } else {
0244 if ((int32_t)(long)prom_vec < 0) {
0245
0246
0247
0248
0249
0250 cfe_handle = (uint64_t)(long)prom_vec;
0251 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
0252 cfe_eptseal = CFE_EPTSEAL;
0253 } else {
0254
0255
0256
0257
0258
0259 cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
0260 cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
0261 cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
0262 }
0263 }
0264 if (cfe_eptseal != CFE_EPTSEAL) {
0265
0266 printk("CFE's entrypoint seal doesn't match. Spinning.");
0267 while (1) ;
0268 }
0269 cfe_init(cfe_handle, cfe_ept);
0270
0271
0272
0273
0274 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
0275 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, COMMAND_LINE_SIZE) < 0) {
0276 if (argc >= 0) {
0277
0278
0279 printk("LINUX_CMDLINE not defined in cfe.");
0280 while (1) ;
0281 }
0282 }
0283
0284 #ifdef CONFIG_BLK_DEV_INITRD
0285 {
0286 char *ptr;
0287
0288
0289 for (ptr = arcs_cmdline; *ptr; ptr++) {
0290 while (*ptr == ' ') {
0291 ptr++;
0292 }
0293 if (!strncmp(ptr, "initrd=", 7)) {
0294 initrd_setup(ptr+7);
0295 break;
0296 } else {
0297 while (*ptr && (*ptr != ' ')) {
0298 ptr++;
0299 }
0300 }
0301 }
0302 }
0303 #endif
0304
0305
0306 arcs_cmdline[COMMAND_LINE_SIZE-1] = 0;
0307
0308 prom_meminit();
0309
0310 #if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
0311 register_smp_ops(&sb_smp_ops);
0312 #endif
0313 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
0314 register_smp_ops(&bcm1480_smp_ops);
0315 #endif
0316 }
0317
0318 void prom_putchar(char c)
0319 {
0320 int ret;
0321
0322 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
0323 ;
0324 }