PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/mips/kernel/setup.c

https://github.com/crystalfontz/linux-2.6
C | 611 lines | 375 code | 103 blank | 133 comment | 58 complexity | 1500ddb47d13f250acf72c05bc84c07a 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, 2007 Maciej W. Rozycki
  12. */
  13. #include <linux/init.h>
  14. #include <linux/ioport.h>
  15. #include <linux/module.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/bootmem.h>
  18. #include <linux/initrd.h>
  19. #include <linux/root_dev.h>
  20. #include <linux/highmem.h>
  21. #include <linux/console.h>
  22. #include <linux/pfn.h>
  23. #include <linux/debugfs.h>
  24. #include <asm/addrspace.h>
  25. #include <asm/bootinfo.h>
  26. #include <asm/bugs.h>
  27. #include <asm/cache.h>
  28. #include <asm/cpu.h>
  29. #include <asm/sections.h>
  30. #include <asm/setup.h>
  31. #include <asm/smp-ops.h>
  32. #include <asm/system.h>
  33. struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
  34. EXPORT_SYMBOL(cpu_data);
  35. #ifdef CONFIG_VT
  36. struct screen_info screen_info;
  37. #endif
  38. /*
  39. * Despite it's name this variable is even if we don't have PCI
  40. */
  41. unsigned int PCI_DMA_BUS_IS_PHYS;
  42. EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
  43. /*
  44. * Setup information
  45. *
  46. * These are initialized so they are in the .data section
  47. */
  48. unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
  49. EXPORT_SYMBOL(mips_machtype);
  50. struct boot_mem_map boot_mem_map;
  51. static char command_line[CL_SIZE];
  52. char arcs_cmdline[CL_SIZE]=CONFIG_CMDLINE;
  53. /*
  54. * mips_io_port_base is the begin of the address space to which x86 style
  55. * I/O ports are mapped.
  56. */
  57. const unsigned long mips_io_port_base __read_mostly = -1;
  58. EXPORT_SYMBOL(mips_io_port_base);
  59. static struct resource code_resource = { .name = "Kernel code", };
  60. static struct resource data_resource = { .name = "Kernel data", };
  61. void __init add_memory_region(phys_t start, phys_t size, long type)
  62. {
  63. int x = boot_mem_map.nr_map;
  64. struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1;
  65. /* Sanity check */
  66. if (start + size < start) {
  67. pr_warning("Trying to add an invalid memory region, skipped\n");
  68. return;
  69. }
  70. /*
  71. * Try to merge with previous entry if any. This is far less than
  72. * perfect but is sufficient for most real world cases.
  73. */
  74. if (x && prev->addr + prev->size == start && prev->type == type) {
  75. prev->size += size;
  76. return;
  77. }
  78. if (x == BOOT_MEM_MAP_MAX) {
  79. pr_err("Ooops! Too many entries in the memory map!\n");
  80. return;
  81. }
  82. boot_mem_map.map[x].addr = start;
  83. boot_mem_map.map[x].size = size;
  84. boot_mem_map.map[x].type = type;
  85. boot_mem_map.nr_map++;
  86. }
  87. static void __init print_memory_map(void)
  88. {
  89. int i;
  90. const int field = 2 * sizeof(unsigned long);
  91. for (i = 0; i < boot_mem_map.nr_map; i++) {
  92. printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
  93. field, (unsigned long long) boot_mem_map.map[i].size,
  94. field, (unsigned long long) boot_mem_map.map[i].addr);
  95. switch (boot_mem_map.map[i].type) {
  96. case BOOT_MEM_RAM:
  97. printk(KERN_CONT "(usable)\n");
  98. break;
  99. case BOOT_MEM_ROM_DATA:
  100. printk(KERN_CONT "(ROM data)\n");
  101. break;
  102. case BOOT_MEM_RESERVED:
  103. printk(KERN_CONT "(reserved)\n");
  104. break;
  105. default:
  106. printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
  107. break;
  108. }
  109. }
  110. }
  111. /*
  112. * Manage initrd
  113. */
  114. #ifdef CONFIG_BLK_DEV_INITRD
  115. static int __init rd_start_early(char *p)
  116. {
  117. unsigned long start = memparse(p, &p);
  118. #ifdef CONFIG_64BIT
  119. /* Guess if the sign extension was forgotten by bootloader */
  120. if (start < XKPHYS)
  121. start = (int)start;
  122. #endif
  123. initrd_start = start;
  124. initrd_end += start;
  125. return 0;
  126. }
  127. early_param("rd_start", rd_start_early);
  128. static int __init rd_size_early(char *p)
  129. {
  130. initrd_end += memparse(p, &p);
  131. return 0;
  132. }
  133. early_param("rd_size", rd_size_early);
  134. /* it returns the next free pfn after initrd */
  135. static unsigned long __init init_initrd(void)
  136. {
  137. unsigned long end;
  138. /*
  139. * Board specific code or command line parser should have
  140. * already set up initrd_start and initrd_end. In these cases
  141. * perfom sanity checks and use them if all looks good.
  142. */
  143. if (!initrd_start || initrd_end <= initrd_start) {
  144. #ifdef CONFIG_PROBE_INITRD_HEADER
  145. u32 *initrd_header;
  146. /*
  147. * See if initrd has been added to the kernel image by
  148. * arch/mips/boot/addinitrd.c. In that case a header is
  149. * prepended to initrd and is made up by 8 bytes. The first
  150. * word is a magic number and the second one is the size of
  151. * initrd. Initrd start must be page aligned in any cases.
  152. */
  153. initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
  154. if (initrd_header[0] != 0x494E5244)
  155. goto disable;
  156. initrd_start = (unsigned long)(initrd_header + 2);
  157. initrd_end = initrd_start + initrd_header[1];
  158. #else
  159. goto disable;
  160. #endif
  161. }
  162. if (initrd_start & ~PAGE_MASK) {
  163. pr_err("initrd start must be page aligned\n");
  164. goto disable;
  165. }
  166. if (initrd_start < PAGE_OFFSET) {
  167. pr_err("initrd start < PAGE_OFFSET\n");
  168. goto disable;
  169. }
  170. /*
  171. * Sanitize initrd addresses. For example firmware
  172. * can't guess if they need to pass them through
  173. * 64-bits values if the kernel has been built in pure
  174. * 32-bit. We need also to switch from KSEG0 to XKPHYS
  175. * addresses now, so the code can now safely use __pa().
  176. */
  177. end = __pa(initrd_end);
  178. initrd_end = (unsigned long)__va(end);
  179. initrd_start = (unsigned long)__va(__pa(initrd_start));
  180. ROOT_DEV = Root_RAM0;
  181. return PFN_UP(end);
  182. disable:
  183. initrd_start = 0;
  184. initrd_end = 0;
  185. return 0;
  186. }
  187. static void __init finalize_initrd(void)
  188. {
  189. unsigned long size = initrd_end - initrd_start;
  190. if (size == 0) {
  191. printk(KERN_INFO "Initrd not found or empty");
  192. goto disable;
  193. }
  194. if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  195. printk(KERN_ERR "Initrd extends beyond end of memory");
  196. goto disable;
  197. }
  198. reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
  199. initrd_below_start_ok = 1;
  200. pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
  201. initrd_start, size);
  202. return;
  203. disable:
  204. printk(KERN_CONT " - disabling initrd\n");
  205. initrd_start = 0;
  206. initrd_end = 0;
  207. }
  208. #else /* !CONFIG_BLK_DEV_INITRD */
  209. static unsigned long __init init_initrd(void)
  210. {
  211. return 0;
  212. }
  213. #define finalize_initrd() do {} while (0)
  214. #endif
  215. /*
  216. * Initialize the bootmem allocator. It also setup initrd related data
  217. * if needed.
  218. */
  219. #ifdef CONFIG_SGI_IP27
  220. static void __init bootmem_init(void)
  221. {
  222. init_initrd();
  223. finalize_initrd();
  224. }
  225. #else /* !CONFIG_SGI_IP27 */
  226. static void __init bootmem_init(void)
  227. {
  228. unsigned long reserved_end;
  229. unsigned long mapstart = ~0UL;
  230. unsigned long bootmap_size;
  231. int i;
  232. /*
  233. * Init any data related to initrd. It's a nop if INITRD is
  234. * not selected. Once that done we can determine the low bound
  235. * of usable memory.
  236. */
  237. reserved_end = max(init_initrd(),
  238. (unsigned long) PFN_UP(__pa_symbol(&_end)));
  239. /*
  240. * max_low_pfn is not a number of pages. The number of pages
  241. * of the system is given by 'max_low_pfn - min_low_pfn'.
  242. */
  243. min_low_pfn = ~0UL;
  244. max_low_pfn = 0;
  245. /*
  246. * Find the highest page frame number we have available.
  247. */
  248. for (i = 0; i < boot_mem_map.nr_map; i++) {
  249. unsigned long start, end;
  250. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  251. continue;
  252. start = PFN_UP(boot_mem_map.map[i].addr);
  253. end = PFN_DOWN(boot_mem_map.map[i].addr
  254. + boot_mem_map.map[i].size);
  255. if (end > max_low_pfn)
  256. max_low_pfn = end;
  257. if (start < min_low_pfn)
  258. min_low_pfn = start;
  259. if (end <= reserved_end)
  260. continue;
  261. if (start >= mapstart)
  262. continue;
  263. mapstart = max(reserved_end, start);
  264. }
  265. if (min_low_pfn >= max_low_pfn)
  266. panic("Incorrect memory mapping !!!");
  267. if (min_low_pfn > ARCH_PFN_OFFSET) {
  268. pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
  269. (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
  270. min_low_pfn - ARCH_PFN_OFFSET);
  271. } else if (min_low_pfn < ARCH_PFN_OFFSET) {
  272. pr_info("%lu free pages won't be used\n",
  273. ARCH_PFN_OFFSET - min_low_pfn);
  274. }
  275. min_low_pfn = ARCH_PFN_OFFSET;
  276. /*
  277. * Determine low and high memory ranges
  278. */
  279. max_pfn = max_low_pfn;
  280. if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
  281. #ifdef CONFIG_HIGHMEM
  282. highstart_pfn = PFN_DOWN(HIGHMEM_START);
  283. highend_pfn = max_low_pfn;
  284. #endif
  285. max_low_pfn = PFN_DOWN(HIGHMEM_START);
  286. }
  287. /*
  288. * Initialize the boot-time allocator with low memory only.
  289. */
  290. bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
  291. min_low_pfn, max_low_pfn);
  292. for (i = 0; i < boot_mem_map.nr_map; i++) {
  293. unsigned long start, end;
  294. start = PFN_UP(boot_mem_map.map[i].addr);
  295. end = PFN_DOWN(boot_mem_map.map[i].addr
  296. + boot_mem_map.map[i].size);
  297. if (start <= min_low_pfn)
  298. start = min_low_pfn;
  299. if (start >= end)
  300. continue;
  301. #ifndef CONFIG_HIGHMEM
  302. if (end > max_low_pfn)
  303. end = max_low_pfn;
  304. /*
  305. * ... finally, is the area going away?
  306. */
  307. if (end <= start)
  308. continue;
  309. #endif
  310. add_active_range(0, start, end);
  311. }
  312. /*
  313. * Register fully available low RAM pages with the bootmem allocator.
  314. */
  315. for (i = 0; i < boot_mem_map.nr_map; i++) {
  316. unsigned long start, end, size;
  317. /*
  318. * Reserve usable memory.
  319. */
  320. if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
  321. continue;
  322. start = PFN_UP(boot_mem_map.map[i].addr);
  323. end = PFN_DOWN(boot_mem_map.map[i].addr
  324. + boot_mem_map.map[i].size);
  325. /*
  326. * We are rounding up the start address of usable memory
  327. * and at the end of the usable range downwards.
  328. */
  329. if (start >= max_low_pfn)
  330. continue;
  331. if (start < reserved_end)
  332. start = reserved_end;
  333. if (end > max_low_pfn)
  334. end = max_low_pfn;
  335. /*
  336. * ... finally, is the area going away?
  337. */
  338. if (end <= start)
  339. continue;
  340. size = end - start;
  341. /* Register lowmem ranges */
  342. free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
  343. memory_present(0, start, end);
  344. }
  345. /*
  346. * Reserve the bootmap memory.
  347. */
  348. reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
  349. /*
  350. * Reserve initrd memory if needed.
  351. */
  352. finalize_initrd();
  353. }
  354. #endif /* CONFIG_SGI_IP27 */
  355. /*
  356. * arch_mem_init - initialize memory management subsystem
  357. *
  358. * o plat_mem_setup() detects the memory configuration and will record detected
  359. * memory areas using add_memory_region.
  360. *
  361. * At this stage the memory configuration of the system is known to the
  362. * kernel but generic memory management system is still entirely uninitialized.
  363. *
  364. * o bootmem_init()
  365. * o sparse_init()
  366. * o paging_init()
  367. *
  368. * At this stage the bootmem allocator is ready to use.
  369. *
  370. * NOTE: historically plat_mem_setup did the entire platform initialization.
  371. * This was rather impractical because it meant plat_mem_setup had to
  372. * get away without any kind of memory allocator. To keep old code from
  373. * breaking plat_setup was just renamed to plat_setup and a second platform
  374. * initialization hook for anything else was introduced.
  375. */
  376. static int usermem __initdata = 0;
  377. static int __init early_parse_mem(char *p)
  378. {
  379. unsigned long start, size;
  380. /*
  381. * If a user specifies memory size, we
  382. * blow away any automatically generated
  383. * size.
  384. */
  385. if (usermem == 0) {
  386. boot_mem_map.nr_map = 0;
  387. usermem = 1;
  388. }
  389. start = 0;
  390. size = memparse(p, &p);
  391. if (*p == '@')
  392. start = memparse(p + 1, &p);
  393. add_memory_region(start, size, BOOT_MEM_RAM);
  394. return 0;
  395. }
  396. early_param("mem", early_parse_mem);
  397. static void __init arch_mem_init(char **cmdline_p)
  398. {
  399. extern void plat_mem_setup(void);
  400. /* call board setup routine */
  401. plat_mem_setup();
  402. pr_info("Determined physical RAM map:\n");
  403. print_memory_map();
  404. strlcpy(command_line, arcs_cmdline, sizeof(command_line));
  405. strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  406. *cmdline_p = command_line;
  407. parse_early_param();
  408. if (usermem) {
  409. pr_info("User-defined physical RAM map:\n");
  410. print_memory_map();
  411. }
  412. bootmem_init();
  413. sparse_init();
  414. paging_init();
  415. }
  416. static void __init resource_init(void)
  417. {
  418. int i;
  419. if (UNCAC_BASE != IO_BASE)
  420. return;
  421. code_resource.start = __pa_symbol(&_text);
  422. code_resource.end = __pa_symbol(&_etext) - 1;
  423. data_resource.start = __pa_symbol(&_etext);
  424. data_resource.end = __pa_symbol(&_edata) - 1;
  425. /*
  426. * Request address space for all standard RAM.
  427. */
  428. for (i = 0; i < boot_mem_map.nr_map; i++) {
  429. struct resource *res;
  430. unsigned long start, end;
  431. start = boot_mem_map.map[i].addr;
  432. end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
  433. if (start >= HIGHMEM_START)
  434. continue;
  435. if (end >= HIGHMEM_START)
  436. end = HIGHMEM_START - 1;
  437. res = alloc_bootmem(sizeof(struct resource));
  438. switch (boot_mem_map.map[i].type) {
  439. case BOOT_MEM_RAM:
  440. case BOOT_MEM_ROM_DATA:
  441. res->name = "System RAM";
  442. break;
  443. case BOOT_MEM_RESERVED:
  444. default:
  445. res->name = "reserved";
  446. }
  447. res->start = start;
  448. res->end = end;
  449. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  450. request_resource(&iomem_resource, res);
  451. /*
  452. * We don't know which RAM region contains kernel data,
  453. * so we try it repeatedly and let the resource manager
  454. * test it.
  455. */
  456. request_resource(res, &code_resource);
  457. request_resource(res, &data_resource);
  458. }
  459. }
  460. void __init setup_arch(char **cmdline_p)
  461. {
  462. cpu_probe();
  463. prom_init();
  464. #ifdef CONFIG_EARLY_PRINTK
  465. setup_early_printk();
  466. #endif
  467. cpu_report();
  468. check_bugs_early();
  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. arch_mem_init(cmdline_p);
  477. resource_init();
  478. plat_smp_setup();
  479. }
  480. static int __init fpu_disable(char *s)
  481. {
  482. int i;
  483. for (i = 0; i < NR_CPUS; i++)
  484. cpu_data[i].options &= ~MIPS_CPU_FPU;
  485. return 1;
  486. }
  487. __setup("nofpu", fpu_disable);
  488. static int __init dsp_disable(char *s)
  489. {
  490. cpu_data[0].ases &= ~MIPS_ASE_DSP;
  491. return 1;
  492. }
  493. __setup("nodsp", dsp_disable);
  494. unsigned long kernelsp[NR_CPUS];
  495. unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  496. #ifdef CONFIG_DEBUG_FS
  497. struct dentry *mips_debugfs_dir;
  498. static int __init debugfs_mips(void)
  499. {
  500. struct dentry *d;
  501. d = debugfs_create_dir("mips", NULL);
  502. if (!d)
  503. return -ENOMEM;
  504. mips_debugfs_dir = d;
  505. return 0;
  506. }
  507. arch_initcall(debugfs_mips);
  508. #endif