setup.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. /*
  2. * arch/s390/kernel/setup.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Hartmut Penner (hp@de.ibm.com),
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * Derived from "arch/i386/kernel/setup.c"
  10. * Copyright (C) 1995, Linus Torvalds
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of initialization
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/module.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/stddef.h>
  21. #include <linux/unistd.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/a.out.h>
  26. #include <linux/tty.h>
  27. #include <linux/ioport.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/initrd.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/root_dev.h>
  33. #include <linux/console.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/kernel_stat.h>
  36. #include <linux/device.h>
  37. #include <linux/notifier.h>
  38. #include <linux/pfn.h>
  39. #include <linux/ctype.h>
  40. #include <linux/reboot.h>
  41. #include <asm/ipl.h>
  42. #include <asm/uaccess.h>
  43. #include <asm/system.h>
  44. #include <asm/smp.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/cpcmd.h>
  47. #include <asm/lowcore.h>
  48. #include <asm/irq.h>
  49. #include <asm/page.h>
  50. #include <asm/ptrace.h>
  51. #include <asm/sections.h>
  52. #include <asm/ebcdic.h>
  53. #include <asm/compat.h>
  54. long psw_kernel_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY |
  55. PSW_MASK_MCHECK | PSW_DEFAULT_KEY);
  56. long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  57. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  58. PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
  59. /*
  60. * User copy operations.
  61. */
  62. struct uaccess_ops uaccess;
  63. EXPORT_SYMBOL(uaccess);
  64. /*
  65. * Machine setup..
  66. */
  67. unsigned int console_mode = 0;
  68. unsigned int console_devno = -1;
  69. unsigned int console_irq = -1;
  70. unsigned long machine_flags = 0;
  71. struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
  72. volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
  73. static unsigned long __initdata memory_end;
  74. /*
  75. * This is set up by the setup-routine at boot-time
  76. * for S390 need to find out, what we have to setup
  77. * using address 0x10400 ...
  78. */
  79. #include <asm/setup.h>
  80. static struct resource code_resource = {
  81. .name = "Kernel code",
  82. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  83. };
  84. static struct resource data_resource = {
  85. .name = "Kernel data",
  86. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  87. };
  88. /*
  89. * cpu_init() initializes state that is per-CPU.
  90. */
  91. void __devinit cpu_init (void)
  92. {
  93. int addr = hard_smp_processor_id();
  94. /*
  95. * Store processor id in lowcore (used e.g. in timer_interrupt)
  96. */
  97. get_cpu_id(&S390_lowcore.cpu_data.cpu_id);
  98. S390_lowcore.cpu_data.cpu_addr = addr;
  99. /*
  100. * Force FPU initialization:
  101. */
  102. clear_thread_flag(TIF_USEDFPU);
  103. clear_used_math();
  104. atomic_inc(&init_mm.mm_count);
  105. current->active_mm = &init_mm;
  106. if (current->mm)
  107. BUG();
  108. enter_lazy_tlb(&init_mm, current);
  109. }
  110. /*
  111. * VM halt and poweroff setup routines
  112. */
  113. char vmhalt_cmd[128] = "";
  114. char vmpoff_cmd[128] = "";
  115. static char vmpanic_cmd[128] = "";
  116. static void strncpy_skip_quote(char *dst, char *src, int n)
  117. {
  118. int sx, dx;
  119. dx = 0;
  120. for (sx = 0; src[sx] != 0; sx++) {
  121. if (src[sx] == '"') continue;
  122. dst[dx++] = src[sx];
  123. if (dx >= n) break;
  124. }
  125. }
  126. static int __init vmhalt_setup(char *str)
  127. {
  128. strncpy_skip_quote(vmhalt_cmd, str, 127);
  129. vmhalt_cmd[127] = 0;
  130. return 1;
  131. }
  132. __setup("vmhalt=", vmhalt_setup);
  133. static int __init vmpoff_setup(char *str)
  134. {
  135. strncpy_skip_quote(vmpoff_cmd, str, 127);
  136. vmpoff_cmd[127] = 0;
  137. return 1;
  138. }
  139. __setup("vmpoff=", vmpoff_setup);
  140. static int vmpanic_notify(struct notifier_block *self, unsigned long event,
  141. void *data)
  142. {
  143. if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
  144. cpcmd(vmpanic_cmd, NULL, 0, NULL);
  145. return NOTIFY_OK;
  146. }
  147. #define PANIC_PRI_VMPANIC 0
  148. static struct notifier_block vmpanic_nb = {
  149. .notifier_call = vmpanic_notify,
  150. .priority = PANIC_PRI_VMPANIC
  151. };
  152. static int __init vmpanic_setup(char *str)
  153. {
  154. static int register_done __initdata = 0;
  155. strncpy_skip_quote(vmpanic_cmd, str, 127);
  156. vmpanic_cmd[127] = 0;
  157. if (!register_done) {
  158. register_done = 1;
  159. atomic_notifier_chain_register(&panic_notifier_list,
  160. &vmpanic_nb);
  161. }
  162. return 1;
  163. }
  164. __setup("vmpanic=", vmpanic_setup);
  165. /*
  166. * condev= and conmode= setup parameter.
  167. */
  168. static int __init condev_setup(char *str)
  169. {
  170. int vdev;
  171. vdev = simple_strtoul(str, &str, 0);
  172. if (vdev >= 0 && vdev < 65536) {
  173. console_devno = vdev;
  174. console_irq = -1;
  175. }
  176. return 1;
  177. }
  178. __setup("condev=", condev_setup);
  179. static int __init conmode_setup(char *str)
  180. {
  181. #if defined(CONFIG_SCLP_CONSOLE)
  182. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  183. SET_CONSOLE_SCLP;
  184. #endif
  185. #if defined(CONFIG_TN3215_CONSOLE)
  186. if (strncmp(str, "3215", 5) == 0)
  187. SET_CONSOLE_3215;
  188. #endif
  189. #if defined(CONFIG_TN3270_CONSOLE)
  190. if (strncmp(str, "3270", 5) == 0)
  191. SET_CONSOLE_3270;
  192. #endif
  193. return 1;
  194. }
  195. __setup("conmode=", conmode_setup);
  196. static void __init conmode_default(void)
  197. {
  198. char query_buffer[1024];
  199. char *ptr;
  200. if (MACHINE_IS_VM) {
  201. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  202. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  203. ptr = strstr(query_buffer, "SUBCHANNEL =");
  204. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  205. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  206. ptr = strstr(query_buffer, "CONMODE");
  207. /*
  208. * Set the conmode to 3215 so that the device recognition
  209. * will set the cu_type of the console to 3215. If the
  210. * conmode is 3270 and we don't set it back then both
  211. * 3215 and the 3270 driver will try to access the console
  212. * device (3215 as console and 3270 as normal tty).
  213. */
  214. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  215. if (ptr == NULL) {
  216. #if defined(CONFIG_SCLP_CONSOLE)
  217. SET_CONSOLE_SCLP;
  218. #endif
  219. return;
  220. }
  221. if (strncmp(ptr + 8, "3270", 4) == 0) {
  222. #if defined(CONFIG_TN3270_CONSOLE)
  223. SET_CONSOLE_3270;
  224. #elif defined(CONFIG_TN3215_CONSOLE)
  225. SET_CONSOLE_3215;
  226. #elif defined(CONFIG_SCLP_CONSOLE)
  227. SET_CONSOLE_SCLP;
  228. #endif
  229. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  230. #if defined(CONFIG_TN3215_CONSOLE)
  231. SET_CONSOLE_3215;
  232. #elif defined(CONFIG_TN3270_CONSOLE)
  233. SET_CONSOLE_3270;
  234. #elif defined(CONFIG_SCLP_CONSOLE)
  235. SET_CONSOLE_SCLP;
  236. #endif
  237. }
  238. } else if (MACHINE_IS_P390) {
  239. #if defined(CONFIG_TN3215_CONSOLE)
  240. SET_CONSOLE_3215;
  241. #elif defined(CONFIG_TN3270_CONSOLE)
  242. SET_CONSOLE_3270;
  243. #endif
  244. } else {
  245. #if defined(CONFIG_SCLP_CONSOLE)
  246. SET_CONSOLE_SCLP;
  247. #endif
  248. }
  249. }
  250. #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
  251. static void __init setup_zfcpdump(unsigned int console_devno)
  252. {
  253. static char str[64];
  254. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  255. return;
  256. if (console_devno != -1)
  257. sprintf(str, "cio_ignore=all,!0.0.%04x,!0.0.%04x",
  258. ipl_info.data.fcp.dev_id.devno, console_devno);
  259. else
  260. sprintf(str, "cio_ignore=all,!0.0.%04x",
  261. ipl_info.data.fcp.dev_id.devno);
  262. strcat(COMMAND_LINE, str);
  263. console_loglevel = 2;
  264. }
  265. #else
  266. static inline void setup_zfcpdump(unsigned int console_devno) {}
  267. #endif /* CONFIG_ZFCPDUMP */
  268. #ifdef CONFIG_SMP
  269. void (*_machine_restart)(char *command) = machine_restart_smp;
  270. void (*_machine_halt)(void) = machine_halt_smp;
  271. void (*_machine_power_off)(void) = machine_power_off_smp;
  272. #else
  273. /*
  274. * Reboot, halt and power_off routines for non SMP.
  275. */
  276. static void do_machine_restart_nonsmp(char * __unused)
  277. {
  278. do_reipl();
  279. }
  280. static void do_machine_halt_nonsmp(void)
  281. {
  282. if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
  283. __cpcmd(vmhalt_cmd, NULL, 0, NULL);
  284. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  285. }
  286. static void do_machine_power_off_nonsmp(void)
  287. {
  288. if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
  289. __cpcmd(vmpoff_cmd, NULL, 0, NULL);
  290. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  291. }
  292. void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
  293. void (*_machine_halt)(void) = do_machine_halt_nonsmp;
  294. void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
  295. #endif
  296. /*
  297. * Reboot, halt and power_off stubs. They just call _machine_restart,
  298. * _machine_halt or _machine_power_off.
  299. */
  300. void machine_restart(char *command)
  301. {
  302. if (!in_interrupt() || oops_in_progress)
  303. /*
  304. * Only unblank the console if we are called in enabled
  305. * context or a bust_spinlocks cleared the way for us.
  306. */
  307. console_unblank();
  308. _machine_restart(command);
  309. }
  310. void machine_halt(void)
  311. {
  312. if (!in_interrupt() || oops_in_progress)
  313. /*
  314. * Only unblank the console if we are called in enabled
  315. * context or a bust_spinlocks cleared the way for us.
  316. */
  317. console_unblank();
  318. _machine_halt();
  319. }
  320. void machine_power_off(void)
  321. {
  322. if (!in_interrupt() || oops_in_progress)
  323. /*
  324. * Only unblank the console if we are called in enabled
  325. * context or a bust_spinlocks cleared the way for us.
  326. */
  327. console_unblank();
  328. _machine_power_off();
  329. }
  330. /*
  331. * Dummy power off function.
  332. */
  333. void (*pm_power_off)(void) = machine_power_off;
  334. static int __init early_parse_mem(char *p)
  335. {
  336. memory_end = memparse(p, &p);
  337. return 0;
  338. }
  339. early_param("mem", early_parse_mem);
  340. /*
  341. * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
  342. */
  343. static int __init early_parse_ipldelay(char *p)
  344. {
  345. unsigned long delay = 0;
  346. delay = simple_strtoul(p, &p, 0);
  347. switch (*p) {
  348. case 's':
  349. case 'S':
  350. delay *= 1000000;
  351. break;
  352. case 'm':
  353. case 'M':
  354. delay *= 60 * 1000000;
  355. }
  356. /* now wait for the requested amount of time */
  357. udelay(delay);
  358. return 0;
  359. }
  360. early_param("ipldelay", early_parse_ipldelay);
  361. #ifdef CONFIG_S390_SWITCH_AMODE
  362. unsigned int switch_amode = 0;
  363. EXPORT_SYMBOL_GPL(switch_amode);
  364. static void set_amode_and_uaccess(unsigned long user_amode,
  365. unsigned long user32_amode)
  366. {
  367. psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
  368. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  369. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  370. #ifdef CONFIG_COMPAT
  371. psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
  372. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  373. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  374. psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
  375. PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
  376. PSW32_MASK_PSTATE;
  377. #endif
  378. psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  379. PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
  380. if (MACHINE_HAS_MVCOS) {
  381. printk("mvcos available.\n");
  382. memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
  383. } else {
  384. printk("mvcos not available.\n");
  385. memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
  386. }
  387. }
  388. /*
  389. * Switch kernel/user addressing modes?
  390. */
  391. static int __init early_parse_switch_amode(char *p)
  392. {
  393. switch_amode = 1;
  394. return 0;
  395. }
  396. early_param("switch_amode", early_parse_switch_amode);
  397. #else /* CONFIG_S390_SWITCH_AMODE */
  398. static inline void set_amode_and_uaccess(unsigned long user_amode,
  399. unsigned long user32_amode)
  400. {
  401. }
  402. #endif /* CONFIG_S390_SWITCH_AMODE */
  403. #ifdef CONFIG_S390_EXEC_PROTECT
  404. unsigned int s390_noexec = 0;
  405. EXPORT_SYMBOL_GPL(s390_noexec);
  406. /*
  407. * Enable execute protection?
  408. */
  409. static int __init early_parse_noexec(char *p)
  410. {
  411. if (!strncmp(p, "off", 3))
  412. return 0;
  413. switch_amode = 1;
  414. s390_noexec = 1;
  415. return 0;
  416. }
  417. early_param("noexec", early_parse_noexec);
  418. #endif /* CONFIG_S390_EXEC_PROTECT */
  419. static void setup_addressing_mode(void)
  420. {
  421. if (s390_noexec) {
  422. printk("S390 execute protection active, ");
  423. set_amode_and_uaccess(PSW_ASC_SECONDARY, PSW32_ASC_SECONDARY);
  424. return;
  425. }
  426. if (switch_amode) {
  427. printk("S390 address spaces switched, ");
  428. set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY);
  429. }
  430. }
  431. static void __init
  432. setup_lowcore(void)
  433. {
  434. struct _lowcore *lc;
  435. int lc_pages;
  436. /*
  437. * Setup lowcore for boot cpu
  438. */
  439. lc_pages = sizeof(void *) == 8 ? 2 : 1;
  440. lc = (struct _lowcore *)
  441. __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
  442. memset(lc, 0, lc_pages * PAGE_SIZE);
  443. lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
  444. lc->restart_psw.addr =
  445. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  446. if (switch_amode)
  447. lc->restart_psw.mask |= PSW_ASC_HOME;
  448. lc->external_new_psw.mask = psw_kernel_bits;
  449. lc->external_new_psw.addr =
  450. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  451. lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
  452. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  453. lc->program_new_psw.mask = psw_kernel_bits;
  454. lc->program_new_psw.addr =
  455. PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
  456. lc->mcck_new_psw.mask =
  457. psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
  458. lc->mcck_new_psw.addr =
  459. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  460. lc->io_new_psw.mask = psw_kernel_bits;
  461. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  462. lc->ipl_device = S390_lowcore.ipl_device;
  463. lc->jiffy_timer = -1LL;
  464. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  465. lc->async_stack = (unsigned long)
  466. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  467. lc->panic_stack = (unsigned long)
  468. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  469. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  470. lc->thread_info = (unsigned long) &init_thread_union;
  471. #ifndef CONFIG_64BIT
  472. if (MACHINE_HAS_IEEE) {
  473. lc->extended_save_area_addr = (__u32)
  474. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
  475. /* enable extended save area */
  476. __ctl_set_bit(14, 29);
  477. }
  478. #endif
  479. set_prefix((u32)(unsigned long) lc);
  480. }
  481. static void __init
  482. setup_resources(void)
  483. {
  484. struct resource *res, *sub_res;
  485. int i;
  486. code_resource.start = (unsigned long) &_text;
  487. code_resource.end = (unsigned long) &_etext - 1;
  488. data_resource.start = (unsigned long) &_etext;
  489. data_resource.end = (unsigned long) &_edata - 1;
  490. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  491. res = alloc_bootmem_low(sizeof(struct resource));
  492. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  493. switch (memory_chunk[i].type) {
  494. case CHUNK_READ_WRITE:
  495. res->name = "System RAM";
  496. break;
  497. case CHUNK_READ_ONLY:
  498. res->name = "System ROM";
  499. res->flags |= IORESOURCE_READONLY;
  500. break;
  501. default:
  502. res->name = "reserved";
  503. }
  504. res->start = memory_chunk[i].addr;
  505. res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
  506. request_resource(&iomem_resource, res);
  507. if (code_resource.start >= res->start &&
  508. code_resource.start <= res->end &&
  509. code_resource.end > res->end) {
  510. sub_res = alloc_bootmem_low(sizeof(struct resource));
  511. memcpy(sub_res, &code_resource,
  512. sizeof(struct resource));
  513. sub_res->end = res->end;
  514. code_resource.start = res->end + 1;
  515. request_resource(res, sub_res);
  516. }
  517. if (code_resource.start >= res->start &&
  518. code_resource.start <= res->end &&
  519. code_resource.end <= res->end)
  520. request_resource(res, &code_resource);
  521. if (data_resource.start >= res->start &&
  522. data_resource.start <= res->end &&
  523. data_resource.end > res->end) {
  524. sub_res = alloc_bootmem_low(sizeof(struct resource));
  525. memcpy(sub_res, &data_resource,
  526. sizeof(struct resource));
  527. sub_res->end = res->end;
  528. data_resource.start = res->end + 1;
  529. request_resource(res, sub_res);
  530. }
  531. if (data_resource.start >= res->start &&
  532. data_resource.start <= res->end &&
  533. data_resource.end <= res->end)
  534. request_resource(res, &data_resource);
  535. }
  536. }
  537. unsigned long real_memory_size;
  538. EXPORT_SYMBOL_GPL(real_memory_size);
  539. static void __init setup_memory_end(void)
  540. {
  541. unsigned long memory_size;
  542. unsigned long max_mem, max_phys;
  543. int i;
  544. #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
  545. if (ipl_info.type == IPL_TYPE_FCP_DUMP)
  546. memory_end = ZFCPDUMP_HSA_SIZE;
  547. #endif
  548. memory_size = 0;
  549. max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
  550. memory_end &= PAGE_MASK;
  551. max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
  552. for (i = 0; i < MEMORY_CHUNKS; i++) {
  553. struct mem_chunk *chunk = &memory_chunk[i];
  554. real_memory_size = max(real_memory_size,
  555. chunk->addr + chunk->size);
  556. if (chunk->addr >= max_mem) {
  557. memset(chunk, 0, sizeof(*chunk));
  558. continue;
  559. }
  560. if (chunk->addr + chunk->size > max_mem)
  561. chunk->size = max_mem - chunk->addr;
  562. memory_size = max(memory_size, chunk->addr + chunk->size);
  563. }
  564. if (!memory_end)
  565. memory_end = memory_size;
  566. }
  567. static void __init
  568. setup_memory(void)
  569. {
  570. unsigned long bootmap_size;
  571. unsigned long start_pfn, end_pfn;
  572. int i;
  573. /*
  574. * partially used pages are not usable - thus
  575. * we are rounding upwards:
  576. */
  577. start_pfn = PFN_UP(__pa(&_end));
  578. end_pfn = max_pfn = PFN_DOWN(memory_end);
  579. #ifdef CONFIG_BLK_DEV_INITRD
  580. /*
  581. * Move the initrd in case the bitmap of the bootmem allocater
  582. * would overwrite it.
  583. */
  584. if (INITRD_START && INITRD_SIZE) {
  585. unsigned long bmap_size;
  586. unsigned long start;
  587. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  588. bmap_size = PFN_PHYS(bmap_size);
  589. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  590. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  591. if (start + INITRD_SIZE > memory_end) {
  592. printk("initrd extends beyond end of memory "
  593. "(0x%08lx > 0x%08lx)\n"
  594. "disabling initrd\n",
  595. start + INITRD_SIZE, memory_end);
  596. INITRD_START = INITRD_SIZE = 0;
  597. } else {
  598. printk("Moving initrd (0x%08lx -> 0x%08lx, "
  599. "size: %ld)\n",
  600. INITRD_START, start, INITRD_SIZE);
  601. memmove((void *) start, (void *) INITRD_START,
  602. INITRD_SIZE);
  603. INITRD_START = start;
  604. }
  605. }
  606. }
  607. #endif
  608. /*
  609. * Initialize the boot-time allocator
  610. */
  611. bootmap_size = init_bootmem(start_pfn, end_pfn);
  612. /*
  613. * Register RAM areas with the bootmem allocator.
  614. */
  615. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  616. unsigned long start_chunk, end_chunk, pfn;
  617. if (memory_chunk[i].type != CHUNK_READ_WRITE)
  618. continue;
  619. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  620. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
  621. end_chunk = min(end_chunk, end_pfn);
  622. if (start_chunk >= end_chunk)
  623. continue;
  624. add_active_range(0, start_chunk, end_chunk);
  625. pfn = max(start_chunk, start_pfn);
  626. for (; pfn <= end_chunk; pfn++)
  627. page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
  628. }
  629. psw_set_key(PAGE_DEFAULT_KEY);
  630. free_bootmem_with_active_regions(0, max_pfn);
  631. /*
  632. * Reserve memory used for lowcore/command line/kernel image.
  633. */
  634. reserve_bootmem(0, (unsigned long)_ehead);
  635. reserve_bootmem((unsigned long)_stext,
  636. PFN_PHYS(start_pfn) - (unsigned long)_stext);
  637. /*
  638. * Reserve the bootmem bitmap itself as well. We do this in two
  639. * steps (first step was init_bootmem()) because this catches
  640. * the (very unlikely) case of us accidentally initializing the
  641. * bootmem allocator with an invalid RAM area.
  642. */
  643. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
  644. #ifdef CONFIG_BLK_DEV_INITRD
  645. if (INITRD_START && INITRD_SIZE) {
  646. if (INITRD_START + INITRD_SIZE <= memory_end) {
  647. reserve_bootmem(INITRD_START, INITRD_SIZE);
  648. initrd_start = INITRD_START;
  649. initrd_end = initrd_start + INITRD_SIZE;
  650. } else {
  651. printk("initrd extends beyond end of memory "
  652. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  653. initrd_start + INITRD_SIZE, memory_end);
  654. initrd_start = initrd_end = 0;
  655. }
  656. }
  657. #endif
  658. }
  659. /*
  660. * Setup function called from init/main.c just after the banner
  661. * was printed.
  662. */
  663. void __init
  664. setup_arch(char **cmdline_p)
  665. {
  666. /*
  667. * print what head.S has found out about the machine
  668. */
  669. #ifndef CONFIG_64BIT
  670. printk((MACHINE_IS_VM) ?
  671. "We are running under VM (31 bit mode)\n" :
  672. "We are running native (31 bit mode)\n");
  673. printk((MACHINE_HAS_IEEE) ?
  674. "This machine has an IEEE fpu\n" :
  675. "This machine has no IEEE fpu\n");
  676. #else /* CONFIG_64BIT */
  677. printk((MACHINE_IS_VM) ?
  678. "We are running under VM (64 bit mode)\n" :
  679. "We are running native (64 bit mode)\n");
  680. #endif /* CONFIG_64BIT */
  681. /* Save unparsed command line copy for /proc/cmdline */
  682. strlcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  683. *cmdline_p = COMMAND_LINE;
  684. *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
  685. ROOT_DEV = Root_RAM0;
  686. init_mm.start_code = PAGE_OFFSET;
  687. init_mm.end_code = (unsigned long) &_etext;
  688. init_mm.end_data = (unsigned long) &_edata;
  689. init_mm.brk = (unsigned long) &_end;
  690. if (MACHINE_HAS_MVCOS)
  691. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  692. else
  693. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  694. parse_early_param();
  695. setup_ipl_info();
  696. setup_memory_end();
  697. setup_addressing_mode();
  698. setup_memory();
  699. setup_resources();
  700. setup_lowcore();
  701. cpu_init();
  702. __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
  703. smp_setup_cpu_possible_map();
  704. /*
  705. * Create kernel page tables and switch to virtual addressing.
  706. */
  707. paging_init();
  708. /* Setup default console */
  709. conmode_default();
  710. /* Setup zfcpdump support */
  711. setup_zfcpdump(console_devno);
  712. }
  713. void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
  714. {
  715. printk("cpu %d "
  716. #ifdef CONFIG_SMP
  717. "phys_idx=%d "
  718. #endif
  719. "vers=%02X ident=%06X machine=%04X unused=%04X\n",
  720. cpuinfo->cpu_nr,
  721. #ifdef CONFIG_SMP
  722. cpuinfo->cpu_addr,
  723. #endif
  724. cpuinfo->cpu_id.version,
  725. cpuinfo->cpu_id.ident,
  726. cpuinfo->cpu_id.machine,
  727. cpuinfo->cpu_id.unused);
  728. }
  729. /*
  730. * show_cpuinfo - Get information on one CPU for use by procfs.
  731. */
  732. static int show_cpuinfo(struct seq_file *m, void *v)
  733. {
  734. struct cpuinfo_S390 *cpuinfo;
  735. unsigned long n = (unsigned long) v - 1;
  736. s390_adjust_jiffies();
  737. preempt_disable();
  738. if (!n) {
  739. seq_printf(m, "vendor_id : IBM/S390\n"
  740. "# processors : %i\n"
  741. "bogomips per cpu: %lu.%02lu\n",
  742. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  743. (loops_per_jiffy/(5000/HZ))%100);
  744. }
  745. if (cpu_online(n)) {
  746. #ifdef CONFIG_SMP
  747. if (smp_processor_id() == n)
  748. cpuinfo = &S390_lowcore.cpu_data;
  749. else
  750. cpuinfo = &lowcore_ptr[n]->cpu_data;
  751. #else
  752. cpuinfo = &S390_lowcore.cpu_data;
  753. #endif
  754. seq_printf(m, "processor %li: "
  755. "version = %02X, "
  756. "identification = %06X, "
  757. "machine = %04X\n",
  758. n, cpuinfo->cpu_id.version,
  759. cpuinfo->cpu_id.ident,
  760. cpuinfo->cpu_id.machine);
  761. }
  762. preempt_enable();
  763. return 0;
  764. }
  765. static void *c_start(struct seq_file *m, loff_t *pos)
  766. {
  767. return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
  768. }
  769. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  770. {
  771. ++*pos;
  772. return c_start(m, pos);
  773. }
  774. static void c_stop(struct seq_file *m, void *v)
  775. {
  776. }
  777. struct seq_operations cpuinfo_op = {
  778. .start = c_start,
  779. .next = c_next,
  780. .stop = c_stop,
  781. .show = show_cpuinfo,
  782. };