/arch/mips/kernel/setup.c

https://bitbucket.org/evzijst/gittest · C · 571 lines · 392 code · 80 blank · 99 comment · 80 complexity · b7502d104d5dfada961204586b235ca7 MD5 · raw file

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