setup.c 8.4 KB

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