setup.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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 __devinit 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, str);
  265. console_loglevel = 2;
  266. }
  267. #else
  268. static inline void setup_zfcpdump(unsigned int console_devno) {}
  269. #endif /* CONFIG_ZFCPDUMP */
  270. #ifdef CONFIG_SMP
  271. void (*_machine_restart)(char *command) = machine_restart_smp;
  272. void (*_machine_halt)(void) = machine_halt_smp;
  273. void (*_machine_power_off)(void) = machine_power_off_smp;
  274. #else
  275. /*
  276. * Reboot, halt and power_off routines for non SMP.
  277. */
  278. static void do_machine_restart_nonsmp(char * __unused)
  279. {
  280. do_reipl();
  281. }
  282. static void do_machine_halt_nonsmp(void)
  283. {
  284. if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
  285. __cpcmd(vmhalt_cmd, NULL, 0, NULL);
  286. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  287. }
  288. static void do_machine_power_off_nonsmp(void)
  289. {
  290. if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
  291. __cpcmd(vmpoff_cmd, NULL, 0, NULL);
  292. signal_processor(smp_processor_id(), sigp_stop_and_store_status);
  293. }
  294. void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
  295. void (*_machine_halt)(void) = do_machine_halt_nonsmp;
  296. void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
  297. #endif
  298. /*
  299. * Reboot, halt and power_off stubs. They just call _machine_restart,
  300. * _machine_halt or _machine_power_off.
  301. */
  302. void machine_restart(char *command)
  303. {
  304. if (!in_interrupt() || oops_in_progress)
  305. /*
  306. * Only unblank the console if we are called in enabled
  307. * context or a bust_spinlocks cleared the way for us.
  308. */
  309. console_unblank();
  310. _machine_restart(command);
  311. }
  312. void machine_halt(void)
  313. {
  314. if (!in_interrupt() || oops_in_progress)
  315. /*
  316. * Only unblank the console if we are called in enabled
  317. * context or a bust_spinlocks cleared the way for us.
  318. */
  319. console_unblank();
  320. _machine_halt();
  321. }
  322. void machine_power_off(void)
  323. {
  324. if (!in_interrupt() || oops_in_progress)
  325. /*
  326. * Only unblank the console if we are called in enabled
  327. * context or a bust_spinlocks cleared the way for us.
  328. */
  329. console_unblank();
  330. _machine_power_off();
  331. }
  332. /*
  333. * Dummy power off function.
  334. */
  335. void (*pm_power_off)(void) = machine_power_off;
  336. static int __init early_parse_mem(char *p)
  337. {
  338. memory_end = memparse(p, &p);
  339. return 0;
  340. }
  341. early_param("mem", early_parse_mem);
  342. /*
  343. * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
  344. */
  345. static int __init early_parse_ipldelay(char *p)
  346. {
  347. unsigned long delay = 0;
  348. delay = simple_strtoul(p, &p, 0);
  349. switch (*p) {
  350. case 's':
  351. case 'S':
  352. delay *= 1000000;
  353. break;
  354. case 'm':
  355. case 'M':
  356. delay *= 60 * 1000000;
  357. }
  358. /* now wait for the requested amount of time */
  359. udelay(delay);
  360. return 0;
  361. }
  362. early_param("ipldelay", early_parse_ipldelay);
  363. #ifdef CONFIG_S390_SWITCH_AMODE
  364. unsigned int switch_amode = 0;
  365. EXPORT_SYMBOL_GPL(switch_amode);
  366. static void set_amode_and_uaccess(unsigned long user_amode,
  367. unsigned long user32_amode)
  368. {
  369. psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
  370. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  371. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  372. #ifdef CONFIG_COMPAT
  373. psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
  374. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  375. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  376. psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
  377. PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
  378. PSW32_MASK_PSTATE;
  379. #endif
  380. psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  381. PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
  382. if (MACHINE_HAS_MVCOS) {
  383. printk("mvcos available.\n");
  384. memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
  385. } else {
  386. printk("mvcos not available.\n");
  387. memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
  388. }
  389. }
  390. /*
  391. * Switch kernel/user addressing modes?
  392. */
  393. static int __init early_parse_switch_amode(char *p)
  394. {
  395. switch_amode = 1;
  396. return 0;
  397. }
  398. early_param("switch_amode", early_parse_switch_amode);
  399. #else /* CONFIG_S390_SWITCH_AMODE */
  400. static inline void set_amode_and_uaccess(unsigned long user_amode,
  401. unsigned long user32_amode)
  402. {
  403. }
  404. #endif /* CONFIG_S390_SWITCH_AMODE */
  405. #ifdef CONFIG_S390_EXEC_PROTECT
  406. unsigned int s390_noexec = 0;
  407. EXPORT_SYMBOL_GPL(s390_noexec);
  408. /*
  409. * Enable execute protection?
  410. */
  411. static int __init early_parse_noexec(char *p)
  412. {
  413. if (!strncmp(p, "off", 3))
  414. return 0;
  415. switch_amode = 1;
  416. s390_noexec = 1;
  417. return 0;
  418. }
  419. early_param("noexec", early_parse_noexec);
  420. #endif /* CONFIG_S390_EXEC_PROTECT */
  421. static void setup_addressing_mode(void)
  422. {
  423. if (s390_noexec) {
  424. printk("S390 execute protection active, ");
  425. set_amode_and_uaccess(PSW_ASC_SECONDARY, PSW32_ASC_SECONDARY);
  426. return;
  427. }
  428. if (switch_amode) {
  429. printk("S390 address spaces switched, ");
  430. set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY);
  431. }
  432. }
  433. static void __init
  434. setup_lowcore(void)
  435. {
  436. struct _lowcore *lc;
  437. int lc_pages;
  438. /*
  439. * Setup lowcore for boot cpu
  440. */
  441. lc_pages = sizeof(void *) == 8 ? 2 : 1;
  442. lc = (struct _lowcore *)
  443. __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
  444. memset(lc, 0, lc_pages * PAGE_SIZE);
  445. lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
  446. lc->restart_psw.addr =
  447. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  448. if (switch_amode)
  449. lc->restart_psw.mask |= PSW_ASC_HOME;
  450. lc->external_new_psw.mask = psw_kernel_bits;
  451. lc->external_new_psw.addr =
  452. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  453. lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
  454. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  455. lc->program_new_psw.mask = psw_kernel_bits;
  456. lc->program_new_psw.addr =
  457. PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
  458. lc->mcck_new_psw.mask =
  459. psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
  460. lc->mcck_new_psw.addr =
  461. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  462. lc->io_new_psw.mask = psw_kernel_bits;
  463. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  464. lc->ipl_device = S390_lowcore.ipl_device;
  465. lc->jiffy_timer = -1LL;
  466. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  467. lc->async_stack = (unsigned long)
  468. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  469. lc->panic_stack = (unsigned long)
  470. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  471. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  472. lc->thread_info = (unsigned long) &init_thread_union;
  473. #ifndef CONFIG_64BIT
  474. if (MACHINE_HAS_IEEE) {
  475. lc->extended_save_area_addr = (__u32)
  476. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
  477. /* enable extended save area */
  478. __ctl_set_bit(14, 29);
  479. }
  480. #endif
  481. set_prefix((u32)(unsigned long) lc);
  482. }
  483. static void __init
  484. setup_resources(void)
  485. {
  486. struct resource *res, *sub_res;
  487. int i;
  488. code_resource.start = (unsigned long) &_text;
  489. code_resource.end = (unsigned long) &_etext - 1;
  490. data_resource.start = (unsigned long) &_etext;
  491. data_resource.end = (unsigned long) &_edata - 1;
  492. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  493. res = alloc_bootmem_low(sizeof(struct resource));
  494. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  495. switch (memory_chunk[i].type) {
  496. case CHUNK_READ_WRITE:
  497. res->name = "System RAM";
  498. break;
  499. case CHUNK_READ_ONLY:
  500. res->name = "System ROM";
  501. res->flags |= IORESOURCE_READONLY;
  502. break;
  503. default:
  504. res->name = "reserved";
  505. }
  506. res->start = memory_chunk[i].addr;
  507. res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
  508. request_resource(&iomem_resource, res);
  509. if (code_resource.start >= res->start &&
  510. code_resource.start <= res->end &&
  511. code_resource.end > res->end) {
  512. sub_res = alloc_bootmem_low(sizeof(struct resource));
  513. memcpy(sub_res, &code_resource,
  514. sizeof(struct resource));
  515. sub_res->end = res->end;
  516. code_resource.start = res->end + 1;
  517. request_resource(res, sub_res);
  518. }
  519. if (code_resource.start >= res->start &&
  520. code_resource.start <= res->end &&
  521. code_resource.end <= res->end)
  522. request_resource(res, &code_resource);
  523. if (data_resource.start >= res->start &&
  524. data_resource.start <= res->end &&
  525. data_resource.end > res->end) {
  526. sub_res = alloc_bootmem_low(sizeof(struct resource));
  527. memcpy(sub_res, &data_resource,
  528. sizeof(struct resource));
  529. sub_res->end = res->end;
  530. data_resource.start = res->end + 1;
  531. request_resource(res, sub_res);
  532. }
  533. if (data_resource.start >= res->start &&
  534. data_resource.start <= res->end &&
  535. data_resource.end <= res->end)
  536. request_resource(res, &data_resource);
  537. }
  538. }
  539. unsigned long real_memory_size;
  540. EXPORT_SYMBOL_GPL(real_memory_size);
  541. static void __init setup_memory_end(void)
  542. {
  543. unsigned long memory_size;
  544. unsigned long max_mem, max_phys;
  545. int i;
  546. #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
  547. if (ipl_info.type == IPL_TYPE_FCP_DUMP)
  548. memory_end = ZFCPDUMP_HSA_SIZE;
  549. #endif
  550. memory_size = 0;
  551. max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
  552. memory_end &= PAGE_MASK;
  553. max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
  554. for (i = 0; i < MEMORY_CHUNKS; i++) {
  555. struct mem_chunk *chunk = &memory_chunk[i];
  556. real_memory_size = max(real_memory_size,
  557. chunk->addr + chunk->size);
  558. if (chunk->addr >= max_mem) {
  559. memset(chunk, 0, sizeof(*chunk));
  560. continue;
  561. }
  562. if (chunk->addr + chunk->size > max_mem)
  563. chunk->size = max_mem - chunk->addr;
  564. memory_size = max(memory_size, chunk->addr + chunk->size);
  565. }
  566. if (!memory_end)
  567. memory_end = memory_size;
  568. }
  569. static void __init
  570. setup_memory(void)
  571. {
  572. unsigned long bootmap_size;
  573. unsigned long start_pfn, end_pfn;
  574. int i;
  575. /*
  576. * partially used pages are not usable - thus
  577. * we are rounding upwards:
  578. */
  579. start_pfn = PFN_UP(__pa(&_end));
  580. end_pfn = max_pfn = PFN_DOWN(memory_end);
  581. #ifdef CONFIG_BLK_DEV_INITRD
  582. /*
  583. * Move the initrd in case the bitmap of the bootmem allocater
  584. * would overwrite it.
  585. */
  586. if (INITRD_START && INITRD_SIZE) {
  587. unsigned long bmap_size;
  588. unsigned long start;
  589. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  590. bmap_size = PFN_PHYS(bmap_size);
  591. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  592. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  593. if (start + INITRD_SIZE > memory_end) {
  594. printk("initrd extends beyond end of memory "
  595. "(0x%08lx > 0x%08lx)\n"
  596. "disabling initrd\n",
  597. start + INITRD_SIZE, memory_end);
  598. INITRD_START = INITRD_SIZE = 0;
  599. } else {
  600. printk("Moving initrd (0x%08lx -> 0x%08lx, "
  601. "size: %ld)\n",
  602. INITRD_START, start, INITRD_SIZE);
  603. memmove((void *) start, (void *) INITRD_START,
  604. INITRD_SIZE);
  605. INITRD_START = start;
  606. }
  607. }
  608. }
  609. #endif
  610. /*
  611. * Initialize the boot-time allocator
  612. */
  613. bootmap_size = init_bootmem(start_pfn, end_pfn);
  614. /*
  615. * Register RAM areas with the bootmem allocator.
  616. */
  617. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  618. unsigned long start_chunk, end_chunk, pfn;
  619. if (memory_chunk[i].type != CHUNK_READ_WRITE)
  620. continue;
  621. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  622. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
  623. end_chunk = min(end_chunk, end_pfn);
  624. if (start_chunk >= end_chunk)
  625. continue;
  626. add_active_range(0, start_chunk, end_chunk);
  627. pfn = max(start_chunk, start_pfn);
  628. for (; pfn <= end_chunk; pfn++)
  629. page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
  630. }
  631. psw_set_key(PAGE_DEFAULT_KEY);
  632. free_bootmem_with_active_regions(0, max_pfn);
  633. /*
  634. * Reserve memory used for lowcore/command line/kernel image.
  635. */
  636. reserve_bootmem(0, (unsigned long)_ehead);
  637. reserve_bootmem((unsigned long)_stext,
  638. PFN_PHYS(start_pfn) - (unsigned long)_stext);
  639. /*
  640. * Reserve the bootmem bitmap itself as well. We do this in two
  641. * steps (first step was init_bootmem()) because this catches
  642. * the (very unlikely) case of us accidentally initializing the
  643. * bootmem allocator with an invalid RAM area.
  644. */
  645. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
  646. #ifdef CONFIG_BLK_DEV_INITRD
  647. if (INITRD_START && INITRD_SIZE) {
  648. if (INITRD_START + INITRD_SIZE <= memory_end) {
  649. reserve_bootmem(INITRD_START, INITRD_SIZE);
  650. initrd_start = INITRD_START;
  651. initrd_end = initrd_start + INITRD_SIZE;
  652. } else {
  653. printk("initrd extends beyond end of memory "
  654. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  655. initrd_start + INITRD_SIZE, memory_end);
  656. initrd_start = initrd_end = 0;
  657. }
  658. }
  659. #endif
  660. }
  661. static __init unsigned int stfl(void)
  662. {
  663. asm volatile(
  664. " .insn s,0xb2b10000,0(0)\n" /* stfl */
  665. "0:\n"
  666. EX_TABLE(0b,0b));
  667. return S390_lowcore.stfl_fac_list;
  668. }
  669. static __init int stfle(unsigned long long *list, int doublewords)
  670. {
  671. typedef struct { unsigned long long _[doublewords]; } addrtype;
  672. register unsigned long __nr asm("0") = doublewords - 1;
  673. asm volatile(".insn s,0xb2b00000,%0" /* stfle */
  674. : "=m" (*(addrtype *) list), "+d" (__nr) : : "cc");
  675. return __nr + 1;
  676. }
  677. /*
  678. * Setup hardware capabilities.
  679. */
  680. static void __init setup_hwcaps(void)
  681. {
  682. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  683. struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
  684. unsigned long long facility_list_extended;
  685. unsigned int facility_list;
  686. int i;
  687. facility_list = stfl();
  688. /*
  689. * The store facility list bits numbers as found in the principles
  690. * of operation are numbered with bit 1UL<<31 as number 0 to
  691. * bit 1UL<<0 as number 31.
  692. * Bit 0: instructions named N3, "backported" to esa-mode
  693. * Bit 2: z/Architecture mode is active
  694. * Bit 7: the store-facility-list-extended facility is installed
  695. * Bit 17: the message-security assist is installed
  696. * Bit 19: the long-displacement facility is installed
  697. * Bit 21: the extended-immediate facility is installed
  698. * These get translated to:
  699. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  700. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  701. * HWCAP_S390_LDISP bit 4, and HWCAP_S390_EIMM bit 5.
  702. */
  703. for (i = 0; i < 6; i++)
  704. if (facility_list & (1UL << (31 - stfl_bits[i])))
  705. elf_hwcap |= 1UL << i;
  706. /*
  707. * Check for additional facilities with store-facility-list-extended.
  708. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  709. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  710. * as stored by stfl, bits 32-xxx contain additional facilities.
  711. * How many facility words are stored depends on the number of
  712. * doublewords passed to the instruction. The additional facilites
  713. * are:
  714. * Bit 43: decimal floating point facility is installed
  715. * translated to:
  716. * HWCAP_S390_DFP bit 6.
  717. */
  718. if ((elf_hwcap & (1UL << 2)) &&
  719. stfle(&facility_list_extended, 1) > 0) {
  720. if (facility_list_extended & (1ULL << (64 - 43)))
  721. elf_hwcap |= 1UL << 6;
  722. }
  723. switch (cpuinfo->cpu_id.machine) {
  724. case 0x9672:
  725. #if !defined(CONFIG_64BIT)
  726. default: /* Use "g5" as default for 31 bit kernels. */
  727. #endif
  728. strcpy(elf_platform, "g5");
  729. break;
  730. case 0x2064:
  731. case 0x2066:
  732. #if defined(CONFIG_64BIT)
  733. default: /* Use "z900" as default for 64 bit kernels. */
  734. #endif
  735. strcpy(elf_platform, "z900");
  736. break;
  737. case 0x2084:
  738. case 0x2086:
  739. strcpy(elf_platform, "z990");
  740. break;
  741. case 0x2094:
  742. strcpy(elf_platform, "z9-109");
  743. break;
  744. }
  745. }
  746. /*
  747. * Setup function called from init/main.c just after the banner
  748. * was printed.
  749. */
  750. void __init
  751. setup_arch(char **cmdline_p)
  752. {
  753. /*
  754. * print what head.S has found out about the machine
  755. */
  756. #ifndef CONFIG_64BIT
  757. printk((MACHINE_IS_VM) ?
  758. "We are running under VM (31 bit mode)\n" :
  759. "We are running native (31 bit mode)\n");
  760. printk((MACHINE_HAS_IEEE) ?
  761. "This machine has an IEEE fpu\n" :
  762. "This machine has no IEEE fpu\n");
  763. #else /* CONFIG_64BIT */
  764. printk((MACHINE_IS_VM) ?
  765. "We are running under VM (64 bit mode)\n" :
  766. "We are running native (64 bit mode)\n");
  767. #endif /* CONFIG_64BIT */
  768. /* Save unparsed command line copy for /proc/cmdline */
  769. strlcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  770. *cmdline_p = COMMAND_LINE;
  771. *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
  772. ROOT_DEV = Root_RAM0;
  773. init_mm.start_code = PAGE_OFFSET;
  774. init_mm.end_code = (unsigned long) &_etext;
  775. init_mm.end_data = (unsigned long) &_edata;
  776. init_mm.brk = (unsigned long) &_end;
  777. if (MACHINE_HAS_MVCOS)
  778. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  779. else
  780. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  781. parse_early_param();
  782. setup_ipl_info();
  783. setup_memory_end();
  784. setup_addressing_mode();
  785. setup_memory();
  786. setup_resources();
  787. setup_lowcore();
  788. cpu_init();
  789. __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
  790. smp_setup_cpu_possible_map();
  791. /*
  792. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  793. */
  794. setup_hwcaps();
  795. /*
  796. * Create kernel page tables and switch to virtual addressing.
  797. */
  798. paging_init();
  799. /* Setup default console */
  800. conmode_default();
  801. /* Setup zfcpdump support */
  802. setup_zfcpdump(console_devno);
  803. }
  804. void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
  805. {
  806. printk("cpu %d "
  807. #ifdef CONFIG_SMP
  808. "phys_idx=%d "
  809. #endif
  810. "vers=%02X ident=%06X machine=%04X unused=%04X\n",
  811. cpuinfo->cpu_nr,
  812. #ifdef CONFIG_SMP
  813. cpuinfo->cpu_addr,
  814. #endif
  815. cpuinfo->cpu_id.version,
  816. cpuinfo->cpu_id.ident,
  817. cpuinfo->cpu_id.machine,
  818. cpuinfo->cpu_id.unused);
  819. }
  820. /*
  821. * show_cpuinfo - Get information on one CPU for use by procfs.
  822. */
  823. static int show_cpuinfo(struct seq_file *m, void *v)
  824. {
  825. static const char *hwcap_str[7] = {
  826. "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp"
  827. };
  828. struct cpuinfo_S390 *cpuinfo;
  829. unsigned long n = (unsigned long) v - 1;
  830. int i;
  831. s390_adjust_jiffies();
  832. preempt_disable();
  833. if (!n) {
  834. seq_printf(m, "vendor_id : IBM/S390\n"
  835. "# processors : %i\n"
  836. "bogomips per cpu: %lu.%02lu\n",
  837. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  838. (loops_per_jiffy/(5000/HZ))%100);
  839. seq_puts(m, "features\t: ");
  840. for (i = 0; i < 7; i++)
  841. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  842. seq_printf(m, "%s ", hwcap_str[i]);
  843. seq_puts(m, "\n");
  844. }
  845. if (cpu_online(n)) {
  846. #ifdef CONFIG_SMP
  847. if (smp_processor_id() == n)
  848. cpuinfo = &S390_lowcore.cpu_data;
  849. else
  850. cpuinfo = &lowcore_ptr[n]->cpu_data;
  851. #else
  852. cpuinfo = &S390_lowcore.cpu_data;
  853. #endif
  854. seq_printf(m, "processor %li: "
  855. "version = %02X, "
  856. "identification = %06X, "
  857. "machine = %04X\n",
  858. n, cpuinfo->cpu_id.version,
  859. cpuinfo->cpu_id.ident,
  860. cpuinfo->cpu_id.machine);
  861. }
  862. preempt_enable();
  863. return 0;
  864. }
  865. static void *c_start(struct seq_file *m, loff_t *pos)
  866. {
  867. return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
  868. }
  869. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  870. {
  871. ++*pos;
  872. return c_start(m, pos);
  873. }
  874. static void c_stop(struct seq_file *m, void *v)
  875. {
  876. }
  877. struct seq_operations cpuinfo_op = {
  878. .start = c_start,
  879. .next = c_next,
  880. .stop = c_stop,
  881. .show = show_cpuinfo,
  882. };