setup.c 14 KB

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