setup.c 26 KB

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