setup.c 14 KB

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