cfe.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/linkage.h>
  21. #include <linux/mm.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/pm.h>
  25. #include <linux/smp.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/reboot.h>
  28. #include <asm/setup.h>
  29. #include <asm/sibyte/board.h>
  30. #include <asm/smp-ops.h>
  31. #include <asm/fw/cfe/cfe_api.h>
  32. #include <asm/fw/cfe/cfe_error.h>
  33. /* Max ram addressable in 32-bit segments */
  34. #ifdef CONFIG_64BIT
  35. #define MAX_RAM_SIZE (~0ULL)
  36. #else
  37. #ifdef CONFIG_HIGHMEM
  38. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  39. #define MAX_RAM_SIZE (~0ULL)
  40. #else
  41. #define MAX_RAM_SIZE (0xffffffffULL)
  42. #endif
  43. #else
  44. #define MAX_RAM_SIZE (0x1fffffffULL)
  45. #endif
  46. #endif
  47. #define SIBYTE_MAX_MEM_REGIONS 8
  48. phys_addr_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
  49. phys_addr_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
  50. unsigned int board_mem_region_count;
  51. int cfe_cons_handle;
  52. #ifdef CONFIG_BLK_DEV_INITRD
  53. extern unsigned long initrd_start, initrd_end;
  54. #endif
  55. static void __noreturn cfe_linux_exit(void *arg)
  56. {
  57. int warm = *(int *)arg;
  58. if (smp_processor_id()) {
  59. static int reboot_smp;
  60. /* Don't repeat the process from another CPU */
  61. if (!reboot_smp) {
  62. /* Get CPU 0 to do the cfe_exit */
  63. reboot_smp = 1;
  64. smp_call_function(cfe_linux_exit, arg, 0);
  65. }
  66. } else {
  67. printk("Passing control back to CFE...\n");
  68. cfe_exit(warm, 0);
  69. printk("cfe_exit returned??\n");
  70. }
  71. while (1);
  72. }
  73. static void __noreturn cfe_linux_restart(char *command)
  74. {
  75. static const int zero;
  76. cfe_linux_exit((void *)&zero);
  77. }
  78. static void __noreturn cfe_linux_halt(void)
  79. {
  80. static const int one = 1;
  81. cfe_linux_exit((void *)&one);
  82. }
  83. static __init void prom_meminit(void)
  84. {
  85. u64 addr, size, type; /* regardless of PHYS_ADDR_T_64BIT */
  86. int mem_flags = 0;
  87. unsigned int idx;
  88. int rd_flag;
  89. #ifdef CONFIG_BLK_DEV_INITRD
  90. unsigned long initrd_pstart;
  91. unsigned long initrd_pend;
  92. initrd_pstart = CPHYSADDR(initrd_start);
  93. initrd_pend = CPHYSADDR(initrd_end);
  94. if (initrd_start &&
  95. ((initrd_pstart > MAX_RAM_SIZE)
  96. || (initrd_pend > MAX_RAM_SIZE))) {
  97. panic("initrd out of addressable memory");
  98. }
  99. #endif /* INITRD */
  100. for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
  101. idx++) {
  102. rd_flag = 0;
  103. if (type == CFE_MI_AVAILABLE) {
  104. /*
  105. * See if this block contains (any portion of) the
  106. * ramdisk
  107. */
  108. #ifdef CONFIG_BLK_DEV_INITRD
  109. if (initrd_start) {
  110. if ((initrd_pstart > addr) &&
  111. (initrd_pstart < (addr + size))) {
  112. add_memory_region(addr,
  113. initrd_pstart - addr,
  114. BOOT_MEM_RAM);
  115. rd_flag = 1;
  116. }
  117. if ((initrd_pend > addr) &&
  118. (initrd_pend < (addr + size))) {
  119. add_memory_region(initrd_pend,
  120. (addr + size) - initrd_pend,
  121. BOOT_MEM_RAM);
  122. rd_flag = 1;
  123. }
  124. }
  125. #endif
  126. if (!rd_flag) {
  127. if (addr > MAX_RAM_SIZE)
  128. continue;
  129. if (addr+size > MAX_RAM_SIZE)
  130. size = MAX_RAM_SIZE - (addr+size) + 1;
  131. /*
  132. * memcpy/__copy_user prefetch, which
  133. * will cause a bus error for
  134. * KSEG/KUSEG addrs not backed by RAM.
  135. * Hence, reserve some padding for the
  136. * prefetch distance.
  137. */
  138. if (size > 512)
  139. size -= 512;
  140. add_memory_region(addr, size, BOOT_MEM_RAM);
  141. }
  142. board_mem_region_addrs[board_mem_region_count] = addr;
  143. board_mem_region_sizes[board_mem_region_count] = size;
  144. board_mem_region_count++;
  145. if (board_mem_region_count ==
  146. SIBYTE_MAX_MEM_REGIONS) {
  147. /*
  148. * Too many regions. Need to configure more
  149. */
  150. while(1);
  151. }
  152. }
  153. }
  154. #ifdef CONFIG_BLK_DEV_INITRD
  155. if (initrd_start) {
  156. add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
  157. BOOT_MEM_RESERVED);
  158. }
  159. #endif
  160. }
  161. #ifdef CONFIG_BLK_DEV_INITRD
  162. static int __init initrd_setup(char *str)
  163. {
  164. char rdarg[64];
  165. int idx;
  166. char *tmp, *endptr;
  167. unsigned long initrd_size;
  168. /* Make a copy of the initrd argument so we can smash it up here */
  169. for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
  170. if (!str[idx] || (str[idx] == ' ')) break;
  171. rdarg[idx] = str[idx];
  172. }
  173. rdarg[idx] = 0;
  174. str = rdarg;
  175. /*
  176. *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
  177. * e.g. initrd=3abfd@80010000. This is set up by the loader.
  178. */
  179. for (tmp = str; *tmp != '@'; tmp++) {
  180. if (!*tmp) {
  181. goto fail;
  182. }
  183. }
  184. *tmp = 0;
  185. tmp++;
  186. if (!*tmp) {
  187. goto fail;
  188. }
  189. initrd_size = simple_strtoul(str, &endptr, 16);
  190. if (*endptr) {
  191. *(tmp-1) = '@';
  192. goto fail;
  193. }
  194. *(tmp-1) = '@';
  195. initrd_start = simple_strtoul(tmp, &endptr, 16);
  196. if (*endptr) {
  197. goto fail;
  198. }
  199. initrd_end = initrd_start + initrd_size;
  200. printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
  201. return 1;
  202. fail:
  203. printk("Bad initrd argument. Disabling initrd\n");
  204. initrd_start = 0;
  205. initrd_end = 0;
  206. return 1;
  207. }
  208. #endif
  209. extern const struct plat_smp_ops sb_smp_ops;
  210. extern const struct plat_smp_ops bcm1480_smp_ops;
  211. /*
  212. * prom_init is called just after the cpu type is determined, from setup_arch()
  213. */
  214. void __init prom_init(void)
  215. {
  216. uint64_t cfe_ept, cfe_handle;
  217. unsigned int cfe_eptseal;
  218. int argc = fw_arg0;
  219. char **envp = (char **) fw_arg2;
  220. int *prom_vec = (int *) fw_arg3;
  221. _machine_restart = cfe_linux_restart;
  222. _machine_halt = cfe_linux_halt;
  223. pm_power_off = cfe_linux_halt;
  224. /*
  225. * Check if a loader was used; if NOT, the 4 arguments are
  226. * what CFE gives us (handle, 0, EPT and EPTSEAL)
  227. */
  228. if (argc < 0) {
  229. cfe_handle = (uint64_t)(long)argc;
  230. cfe_ept = (long)envp;
  231. cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
  232. } else {
  233. if ((int32_t)(long)prom_vec < 0) {
  234. /*
  235. * Old loader; all it gives us is the handle,
  236. * so use the "known" entrypoint and assume
  237. * the seal.
  238. */
  239. cfe_handle = (uint64_t)(long)prom_vec;
  240. cfe_ept = (uint64_t)((int32_t)0x9fc00500);
  241. cfe_eptseal = CFE_EPTSEAL;
  242. } else {
  243. /*
  244. * Newer loaders bundle the handle/ept/eptseal
  245. * Note: prom_vec is in the loader's useg
  246. * which is still alive in the TLB.
  247. */
  248. cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
  249. cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
  250. cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
  251. }
  252. }
  253. if (cfe_eptseal != CFE_EPTSEAL) {
  254. /* too early for panic to do any good */
  255. printk("CFE's entrypoint seal doesn't match. Spinning.");
  256. while (1) ;
  257. }
  258. cfe_init(cfe_handle, cfe_ept);
  259. /*
  260. * Get the handle for (at least) prom_putchar, possibly for
  261. * boot console
  262. */
  263. cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
  264. if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, COMMAND_LINE_SIZE) < 0) {
  265. if (argc >= 0) {
  266. /* The loader should have set the command line */
  267. /* too early for panic to do any good */
  268. printk("LINUX_CMDLINE not defined in cfe.");
  269. while (1) ;
  270. }
  271. }
  272. #ifdef CONFIG_BLK_DEV_INITRD
  273. {
  274. char *ptr;
  275. /* Need to find out early whether we've got an initrd. So scan
  276. the list looking now */
  277. for (ptr = arcs_cmdline; *ptr; ptr++) {
  278. while (*ptr == ' ') {
  279. ptr++;
  280. }
  281. if (!strncmp(ptr, "initrd=", 7)) {
  282. initrd_setup(ptr+7);
  283. break;
  284. } else {
  285. while (*ptr && (*ptr != ' ')) {
  286. ptr++;
  287. }
  288. }
  289. }
  290. }
  291. #endif /* CONFIG_BLK_DEV_INITRD */
  292. /* Not sure this is needed, but it's the safe way. */
  293. arcs_cmdline[COMMAND_LINE_SIZE-1] = 0;
  294. prom_meminit();
  295. #if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
  296. register_smp_ops(&sb_smp_ops);
  297. #endif
  298. #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
  299. register_smp_ops(&bcm1480_smp_ops);
  300. #endif
  301. }
  302. void __init prom_free_prom_memory(void)
  303. {
  304. /* Not sure what I'm supposed to do here. Nothing, I think */
  305. }
  306. void prom_putchar(char c)
  307. {
  308. int ret;
  309. while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
  310. ;
  311. }