setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1995 Linus Torvalds
  7. * Copyright (C) 1995 Waldorf Electronics
  8. * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 Ralf Baechle
  9. * Copyright (C) 1996 Stoned Elipot
  10. * Copyright (C) 1999 Silicon Graphics, Inc.
  11. * Copyright (C) 2000 2001, 2002 Maciej W. Rozycki
  12. */
  13. #include <linux/config.h>
  14. #include <linux/errno.h>
  15. #include <linux/init.h>
  16. #include <linux/ioport.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/module.h>
  21. #include <linux/stddef.h>
  22. #include <linux/string.h>
  23. #include <linux/unistd.h>
  24. #include <linux/slab.h>
  25. #include <linux/user.h>
  26. #include <linux/utsname.h>
  27. #include <linux/a.out.h>
  28. #include <linux/tty.h>
  29. #include <linux/bootmem.h>
  30. #include <linux/initrd.h>
  31. #include <linux/major.h>
  32. #include <linux/kdev_t.h>
  33. #include <linux/root_dev.h>
  34. #include <linux/highmem.h>
  35. #include <linux/console.h>
  36. #include <linux/mmzone.h>
  37. #include <linux/pfn.h>
  38. #include <asm/addrspace.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/cache.h>
  41. #include <asm/cpu.h>
  42. #include <asm/sections.h>
  43. #include <asm/setup.h>
  44. #include <asm/system.h>
  45. struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
  46. EXPORT_SYMBOL(cpu_data);
  47. #ifdef CONFIG_VT
  48. struct screen_info screen_info;
  49. #endif
  50. /*
  51. * Despite it's name this variable is even if we don't have PCI
  52. */
  53. unsigned int PCI_DMA_BUS_IS_PHYS;
  54. EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
  55. /*
  56. * Setup information
  57. *
  58. * These are initialized so they are in the .data section
  59. */
  60. unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
  61. unsigned long mips_machgroup __read_mostly = MACH_GROUP_UNKNOWN;
  62. EXPORT_SYMBOL(mips_machtype);
  63. EXPORT_SYMBOL(mips_machgroup);
  64. struct boot_mem_map boot_mem_map;
  65. static char command_line[CL_SIZE];
  66. char arcs_cmdline[CL_SIZE]=CONFIG_CMDLINE;
  67. /*
  68. * mips_io_port_base is the begin of the address space to which x86 style
  69. * I/O ports are mapped.
  70. */
  71. const unsigned long mips_io_port_base __read_mostly = -1;
  72. EXPORT_SYMBOL(mips_io_port_base);
  73. /*
  74. * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
  75. * for the processor.
  76. */
  77. unsigned long isa_slot_offset;
  78. EXPORT_SYMBOL(isa_slot_offset);
  79. static struct resource code_resource = { .name = "Kernel code", };
  80. static struct resource data_resource = { .name = "Kernel data", };
  81. void __init add_memory_region(phys_t start, phys_t size, long type)
  82. {
  83. int x = boot_mem_map.nr_map;
  84. struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1;
  85. /*
  86. * Try to merge with previous entry if any. This is far less than
  87. * perfect but is sufficient for most real world cases.
  88. */
  89. if (x && prev->addr + prev->size == start && prev->type == type) {
  90. prev->size += size;
  91. return;
  92. }
  93. if (x == BOOT_MEM_MAP_MAX) {
  94. printk("Ooops! Too many entries in the memory map!\n");
  95. return;
  96. }
  97. boot_mem_map.map[x].addr = start;
  98. boot_mem_map.map[x].size = size;
  99. boot_mem_map.map[x].type = type;
  100. boot_mem_map.nr_map++;
  101. }
  102. static void __init print_memory_map(void)
  103. {
  104. int i;
  105. const int field = 2 * sizeof(unsigned long);
  106. for (i = 0; i < boot_mem_map.nr_map; i++) {
  107. printk(" memory: %0*Lx @ %0*Lx ",
  108. field, (unsigned long long) boot_mem_map.map[i].size,
  109. field, (unsigned long long) boot_mem_map.map[i].addr);
  110. switch (boot_mem_map.map[i].type) {
  111. case BOOT_MEM_RAM:
  112. printk("(usable)\n");
  113. break;
  114. case BOOT_MEM_ROM_DATA:
  115. printk("(ROM data)\n");
  116. break;
  117. case BOOT_MEM_RESERVED:
  118. printk("(reserved)\n");
  119. break;
  120. default:
  121. printk("type %lu\n", boot_mem_map.map[i].type);
  122. break;
  123. }
  124. }
  125. }
  126. static inline void parse_cmdline_early(void)
  127. {
  128. char c = ' ', *to = command_line, *from = saved_command_line;
  129. unsigned long start_at, mem_size;
  130. int len = 0;
  131. int usermem = 0;
  132. printk("Determined physical RAM map:\n");
  133. print_memory_map();
  134. for (;;) {
  135. /*
  136. * "mem=XXX[kKmM]" defines a memory region from
  137. * 0 to <XXX>, overriding the determined size.
  138. * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from
  139. * <YYY> to <YYY>+<XXX>, overriding the determined size.
  140. */
  141. if (c == ' ' && !memcmp(from, "mem=", 4)) {
  142. if (to != command_line)
  143. to--;
  144. /*
  145. * If a user specifies memory size, we
  146. * blow away any automatically generated
  147. * size.
  148. */
  149. if (usermem == 0) {
  150. boot_mem_map.nr_map = 0;
  151. usermem = 1;
  152. }
  153. mem_size = memparse(from + 4, &from);
  154. if (*from == '@')
  155. start_at = memparse(from + 1, &from);
  156. else
  157. start_at = 0;
  158. add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
  159. }
  160. c = *(from++);
  161. if (!c)
  162. break;
  163. if (CL_SIZE <= ++len)
  164. break;
  165. *(to++) = c;
  166. }
  167. *to = '\0';
  168. if (usermem) {
  169. printk("User-defined physical RAM map:\n");
  170. print_memory_map();
  171. }
  172. }
  173. static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_end)
  174. {
  175. /*
  176. * "rd_start=0xNNNNNNNN" defines the memory address of an initrd
  177. * "rd_size=0xNN" it's size
  178. */
  179. unsigned long start = 0;
  180. unsigned long size = 0;
  181. unsigned long end;
  182. char cmd_line[CL_SIZE];
  183. char *start_str;
  184. char *size_str;
  185. char *tmp;
  186. strcpy(cmd_line, command_line);
  187. *command_line = 0;
  188. tmp = cmd_line;
  189. /* Ignore "rd_start=" strings in other parameters. */
  190. start_str = strstr(cmd_line, "rd_start=");
  191. if (start_str && start_str != cmd_line && *(start_str - 1) != ' ')
  192. start_str = strstr(start_str, " rd_start=");
  193. while (start_str) {
  194. if (start_str != cmd_line)
  195. strncat(command_line, tmp, start_str - tmp);
  196. start = memparse(start_str + 9, &start_str);
  197. tmp = start_str + 1;
  198. start_str = strstr(start_str, " rd_start=");
  199. }
  200. if (*tmp)
  201. strcat(command_line, tmp);
  202. strcpy(cmd_line, command_line);
  203. *command_line = 0;
  204. tmp = cmd_line;
  205. /* Ignore "rd_size" strings in other parameters. */
  206. size_str = strstr(cmd_line, "rd_size=");
  207. if (size_str && size_str != cmd_line && *(size_str - 1) != ' ')
  208. size_str = strstr(size_str, " rd_size=");
  209. while (size_str) {
  210. if (size_str != cmd_line)
  211. strncat(command_line, tmp, size_str - tmp);
  212. size = memparse(size_str + 8, &size_str);
  213. tmp = size_str + 1;
  214. size_str = strstr(size_str, " rd_size=");
  215. }
  216. if (*tmp)
  217. strcat(command_line, tmp);
  218. #ifdef CONFIG_64BIT
  219. /* HACK: Guess if the sign extension was forgotten */
  220. if (start > 0x0000000080000000 && start < 0x00000000ffffffff)
  221. start |= 0xffffffff00000000;
  222. #endif
  223. end = start + size;
  224. if (start && end) {
  225. *rd_start = start;
  226. *rd_end = end;
  227. return 1;
  228. }
  229. return 0;
  230. }
  231. #define MAXMEM HIGHMEM_START
  232. #define MAXMEM_PFN PFN_DOWN(MAXMEM)
  233. static inline void bootmem_init(void)
  234. {
  235. unsigned long start_pfn;
  236. unsigned long reserved_end = (unsigned long)&_end;
  237. #ifndef CONFIG_SGI_IP27
  238. unsigned long first_usable_pfn;
  239. unsigned long bootmap_size;
  240. int i;
  241. #endif
  242. #ifdef CONFIG_BLK_DEV_INITRD
  243. int initrd_reserve_bootmem = 0;
  244. /* Board specific code should have set up initrd_start and initrd_end */
  245. ROOT_DEV = Root_RAM0;
  246. if (parse_rd_cmdline(&initrd_start, &initrd_end)) {
  247. reserved_end = max(reserved_end, initrd_end);
  248. initrd_reserve_bootmem = 1;
  249. } else {
  250. unsigned long tmp;
  251. u32 *initrd_header;
  252. tmp = ((reserved_end + PAGE_SIZE-1) & PAGE_MASK) - sizeof(u32) * 2;
  253. if (tmp < reserved_end)
  254. tmp += PAGE_SIZE;
  255. initrd_header = (u32 *)tmp;
  256. if (initrd_header[0] == 0x494E5244) {
  257. initrd_start = (unsigned long)&initrd_header[2];
  258. initrd_end = initrd_start + initrd_header[1];
  259. reserved_end = max(reserved_end, initrd_end);
  260. initrd_reserve_bootmem = 1;
  261. }
  262. }
  263. #endif /* CONFIG_BLK_DEV_INITRD */
  264. /*
  265. * Partially used pages are not usable - thus
  266. * we are rounding upwards.
  267. */
  268. start_pfn = PFN_UP(CPHYSADDR(reserved_end));
  269. #ifndef CONFIG_SGI_IP27
  270. /* Find the highest page frame number we have available. */
  271. max_pfn = 0;
  272. first_usable_pfn = -1UL;
  273. for (i = 0; i < boot_mem_map.nr_map; i++) {
  274. unsigned long start, end;
  275. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  276. continue;
  277. start = PFN_UP(boot_mem_map.map[i].addr);
  278. end = PFN_DOWN(boot_mem_map.map[i].addr
  279. + boot_mem_map.map[i].size);
  280. if (start >= end)
  281. continue;
  282. if (end > max_pfn)
  283. max_pfn = end;
  284. if (start < first_usable_pfn) {
  285. if (start > start_pfn) {
  286. first_usable_pfn = start;
  287. } else if (end > start_pfn) {
  288. first_usable_pfn = start_pfn;
  289. }
  290. }
  291. }
  292. /*
  293. * Determine low and high memory ranges
  294. */
  295. max_low_pfn = max_pfn;
  296. if (max_low_pfn > MAXMEM_PFN) {
  297. max_low_pfn = MAXMEM_PFN;
  298. #ifndef CONFIG_HIGHMEM
  299. /* Maximum memory usable is what is directly addressable */
  300. printk(KERN_WARNING "Warning only %ldMB will be used.\n",
  301. MAXMEM >> 20);
  302. printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
  303. #endif
  304. }
  305. #ifdef CONFIG_HIGHMEM
  306. /*
  307. * Crude, we really should make a better attempt at detecting
  308. * highstart_pfn
  309. */
  310. highstart_pfn = highend_pfn = max_pfn;
  311. if (max_pfn > MAXMEM_PFN) {
  312. highstart_pfn = MAXMEM_PFN;
  313. printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
  314. (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
  315. }
  316. #endif
  317. memory_present(0, first_usable_pfn, max_low_pfn);
  318. /* Initialize the boot-time allocator with low memory only. */
  319. bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
  320. /*
  321. * Register fully available low RAM pages with the bootmem allocator.
  322. */
  323. for (i = 0; i < boot_mem_map.nr_map; i++) {
  324. unsigned long curr_pfn, last_pfn, size;
  325. /*
  326. * Reserve usable memory.
  327. */
  328. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  329. continue;
  330. /*
  331. * We are rounding up the start address of usable memory:
  332. */
  333. curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
  334. if (curr_pfn >= max_low_pfn)
  335. continue;
  336. if (curr_pfn < start_pfn)
  337. curr_pfn = start_pfn;
  338. /*
  339. * ... and at the end of the usable range downwards:
  340. */
  341. last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
  342. + boot_mem_map.map[i].size);
  343. if (last_pfn > max_low_pfn)
  344. last_pfn = max_low_pfn;
  345. /*
  346. * Only register lowmem part of lowmem segment with bootmem.
  347. */
  348. size = last_pfn - curr_pfn;
  349. if (curr_pfn > PFN_DOWN(HIGHMEM_START))
  350. continue;
  351. if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
  352. size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
  353. if (!size)
  354. continue;
  355. /*
  356. * ... finally, did all the rounding and playing
  357. * around just make the area go away?
  358. */
  359. if (last_pfn <= curr_pfn)
  360. continue;
  361. /* Register lowmem ranges */
  362. free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
  363. }
  364. /* Reserve the bootmap memory. */
  365. reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
  366. #endif /* CONFIG_SGI_IP27 */
  367. #ifdef CONFIG_BLK_DEV_INITRD
  368. initrd_below_start_ok = 1;
  369. if (initrd_start) {
  370. unsigned long initrd_size = ((unsigned char *)initrd_end) - ((unsigned char *)initrd_start);
  371. printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
  372. (void *)initrd_start, initrd_size);
  373. if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
  374. printk("initrd extends beyond end of memory "
  375. "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
  376. sizeof(long) * 2,
  377. (unsigned long long)CPHYSADDR(initrd_end),
  378. sizeof(long) * 2,
  379. (unsigned long long)PFN_PHYS(max_low_pfn));
  380. initrd_start = initrd_end = 0;
  381. initrd_reserve_bootmem = 0;
  382. }
  383. if (initrd_reserve_bootmem)
  384. reserve_bootmem(CPHYSADDR(initrd_start), initrd_size);
  385. }
  386. #endif /* CONFIG_BLK_DEV_INITRD */
  387. }
  388. static inline void resource_init(void)
  389. {
  390. int i;
  391. code_resource.start = virt_to_phys(&_text);
  392. code_resource.end = virt_to_phys(&_etext) - 1;
  393. data_resource.start = virt_to_phys(&_etext);
  394. data_resource.end = virt_to_phys(&_edata) - 1;
  395. /*
  396. * Request address space for all standard RAM.
  397. */
  398. for (i = 0; i < boot_mem_map.nr_map; i++) {
  399. struct resource *res;
  400. unsigned long start, end;
  401. start = boot_mem_map.map[i].addr;
  402. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  403. if (start >= MAXMEM)
  404. continue;
  405. if (end >= MAXMEM)
  406. end = MAXMEM - 1;
  407. res = alloc_bootmem(sizeof(struct resource));
  408. switch (boot_mem_map.map[i].type) {
  409. case BOOT_MEM_RAM:
  410. case BOOT_MEM_ROM_DATA:
  411. res->name = "System RAM";
  412. break;
  413. case BOOT_MEM_RESERVED:
  414. default:
  415. res->name = "reserved";
  416. }
  417. res->start = start;
  418. res->end = end;
  419. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  420. request_resource(&iomem_resource, res);
  421. /*
  422. * We don't know which RAM region contains kernel data,
  423. * so we try it repeatedly and let the resource manager
  424. * test it.
  425. */
  426. request_resource(res, &code_resource);
  427. request_resource(res, &data_resource);
  428. }
  429. }
  430. #undef MAXMEM
  431. #undef MAXMEM_PFN
  432. extern void plat_setup(void);
  433. void __init setup_arch(char **cmdline_p)
  434. {
  435. cpu_probe();
  436. prom_init();
  437. cpu_report();
  438. #if defined(CONFIG_VT)
  439. #if defined(CONFIG_VGA_CONSOLE)
  440. conswitchp = &vga_con;
  441. #elif defined(CONFIG_DUMMY_CONSOLE)
  442. conswitchp = &dummy_con;
  443. #endif
  444. #endif
  445. /* call board setup routine */
  446. plat_setup();
  447. strlcpy(command_line, arcs_cmdline, sizeof(command_line));
  448. strlcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
  449. *cmdline_p = command_line;
  450. parse_cmdline_early();
  451. bootmem_init();
  452. sparse_init();
  453. paging_init();
  454. resource_init();
  455. #ifdef CONFIG_SMP
  456. plat_smp_setup();
  457. #endif
  458. }
  459. int __init fpu_disable(char *s)
  460. {
  461. int i;
  462. for (i = 0; i < NR_CPUS; i++)
  463. cpu_data[i].options &= ~MIPS_CPU_FPU;
  464. return 1;
  465. }
  466. __setup("nofpu", fpu_disable);
  467. int __init dsp_disable(char *s)
  468. {
  469. cpu_data[0].ases &= ~MIPS_ASE_DSP;
  470. return 1;
  471. }
  472. __setup("nodsp", dsp_disable);