setup.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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() || 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. return;
  428. }
  429. if (switch_amode) {
  430. printk("S390 address spaces switched, ");
  431. set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY);
  432. }
  433. }
  434. static void __init
  435. setup_lowcore(void)
  436. {
  437. struct _lowcore *lc;
  438. int lc_pages;
  439. /*
  440. * Setup lowcore for boot cpu
  441. */
  442. lc_pages = sizeof(void *) == 8 ? 2 : 1;
  443. lc = (struct _lowcore *)
  444. __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
  445. memset(lc, 0, lc_pages * PAGE_SIZE);
  446. lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
  447. lc->restart_psw.addr =
  448. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  449. if (switch_amode)
  450. lc->restart_psw.mask |= PSW_ASC_HOME;
  451. lc->external_new_psw.mask = psw_kernel_bits;
  452. lc->external_new_psw.addr =
  453. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  454. lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
  455. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  456. lc->program_new_psw.mask = psw_kernel_bits;
  457. lc->program_new_psw.addr =
  458. PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
  459. lc->mcck_new_psw.mask =
  460. psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
  461. lc->mcck_new_psw.addr =
  462. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  463. lc->io_new_psw.mask = psw_kernel_bits;
  464. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  465. lc->ipl_device = S390_lowcore.ipl_device;
  466. lc->jiffy_timer = -1LL;
  467. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  468. lc->async_stack = (unsigned long)
  469. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  470. lc->panic_stack = (unsigned long)
  471. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  472. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  473. lc->thread_info = (unsigned long) &init_thread_union;
  474. #ifndef CONFIG_64BIT
  475. if (MACHINE_HAS_IEEE) {
  476. lc->extended_save_area_addr = (__u32)
  477. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
  478. /* enable extended save area */
  479. __ctl_set_bit(14, 29);
  480. }
  481. #endif
  482. set_prefix((u32)(unsigned long) lc);
  483. }
  484. static void __init
  485. setup_resources(void)
  486. {
  487. struct resource *res, *sub_res;
  488. int i;
  489. code_resource.start = (unsigned long) &_text;
  490. code_resource.end = (unsigned long) &_etext - 1;
  491. data_resource.start = (unsigned long) &_etext;
  492. data_resource.end = (unsigned long) &_edata - 1;
  493. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  494. res = alloc_bootmem_low(sizeof(struct resource));
  495. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  496. switch (memory_chunk[i].type) {
  497. case CHUNK_READ_WRITE:
  498. res->name = "System RAM";
  499. break;
  500. case CHUNK_READ_ONLY:
  501. res->name = "System ROM";
  502. res->flags |= IORESOURCE_READONLY;
  503. break;
  504. default:
  505. res->name = "reserved";
  506. }
  507. res->start = memory_chunk[i].addr;
  508. res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
  509. request_resource(&iomem_resource, res);
  510. if (code_resource.start >= res->start &&
  511. code_resource.start <= res->end &&
  512. code_resource.end > res->end) {
  513. sub_res = alloc_bootmem_low(sizeof(struct resource));
  514. memcpy(sub_res, &code_resource,
  515. sizeof(struct resource));
  516. sub_res->end = res->end;
  517. code_resource.start = res->end + 1;
  518. request_resource(res, sub_res);
  519. }
  520. if (code_resource.start >= res->start &&
  521. code_resource.start <= res->end &&
  522. code_resource.end <= res->end)
  523. request_resource(res, &code_resource);
  524. if (data_resource.start >= res->start &&
  525. data_resource.start <= res->end &&
  526. data_resource.end > res->end) {
  527. sub_res = alloc_bootmem_low(sizeof(struct resource));
  528. memcpy(sub_res, &data_resource,
  529. sizeof(struct resource));
  530. sub_res->end = res->end;
  531. data_resource.start = res->end + 1;
  532. request_resource(res, sub_res);
  533. }
  534. if (data_resource.start >= res->start &&
  535. data_resource.start <= res->end &&
  536. data_resource.end <= res->end)
  537. request_resource(res, &data_resource);
  538. }
  539. }
  540. unsigned long real_memory_size;
  541. EXPORT_SYMBOL_GPL(real_memory_size);
  542. static void __init setup_memory_end(void)
  543. {
  544. unsigned long memory_size;
  545. unsigned long max_mem, max_phys;
  546. int i;
  547. #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
  548. if (ipl_info.type == IPL_TYPE_FCP_DUMP)
  549. memory_end = ZFCPDUMP_HSA_SIZE;
  550. #endif
  551. memory_size = 0;
  552. max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
  553. memory_end &= PAGE_MASK;
  554. max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
  555. for (i = 0; i < MEMORY_CHUNKS; i++) {
  556. struct mem_chunk *chunk = &memory_chunk[i];
  557. real_memory_size = max(real_memory_size,
  558. chunk->addr + chunk->size);
  559. if (chunk->addr >= max_mem) {
  560. memset(chunk, 0, sizeof(*chunk));
  561. continue;
  562. }
  563. if (chunk->addr + chunk->size > max_mem)
  564. chunk->size = max_mem - chunk->addr;
  565. memory_size = max(memory_size, chunk->addr + chunk->size);
  566. }
  567. if (!memory_end)
  568. memory_end = memory_size;
  569. }
  570. static void __init
  571. setup_memory(void)
  572. {
  573. unsigned long bootmap_size;
  574. unsigned long start_pfn, end_pfn;
  575. int i;
  576. /*
  577. * partially used pages are not usable - thus
  578. * we are rounding upwards:
  579. */
  580. start_pfn = PFN_UP(__pa(&_end));
  581. end_pfn = max_pfn = PFN_DOWN(memory_end);
  582. #ifdef CONFIG_BLK_DEV_INITRD
  583. /*
  584. * Move the initrd in case the bitmap of the bootmem allocater
  585. * would overwrite it.
  586. */
  587. if (INITRD_START && INITRD_SIZE) {
  588. unsigned long bmap_size;
  589. unsigned long start;
  590. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  591. bmap_size = PFN_PHYS(bmap_size);
  592. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  593. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  594. if (start + INITRD_SIZE > memory_end) {
  595. printk("initrd extends beyond end of memory "
  596. "(0x%08lx > 0x%08lx)\n"
  597. "disabling initrd\n",
  598. start + INITRD_SIZE, memory_end);
  599. INITRD_START = INITRD_SIZE = 0;
  600. } else {
  601. printk("Moving initrd (0x%08lx -> 0x%08lx, "
  602. "size: %ld)\n",
  603. INITRD_START, start, INITRD_SIZE);
  604. memmove((void *) start, (void *) INITRD_START,
  605. INITRD_SIZE);
  606. INITRD_START = start;
  607. }
  608. }
  609. }
  610. #endif
  611. /*
  612. * Initialize the boot-time allocator
  613. */
  614. bootmap_size = init_bootmem(start_pfn, end_pfn);
  615. /*
  616. * Register RAM areas with the bootmem allocator.
  617. */
  618. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  619. unsigned long start_chunk, end_chunk, pfn;
  620. if (memory_chunk[i].type != CHUNK_READ_WRITE)
  621. continue;
  622. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  623. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
  624. end_chunk = min(end_chunk, end_pfn);
  625. if (start_chunk >= end_chunk)
  626. continue;
  627. add_active_range(0, start_chunk, end_chunk);
  628. pfn = max(start_chunk, start_pfn);
  629. for (; pfn <= end_chunk; pfn++)
  630. page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
  631. }
  632. psw_set_key(PAGE_DEFAULT_KEY);
  633. free_bootmem_with_active_regions(0, max_pfn);
  634. /*
  635. * Reserve memory used for lowcore/command line/kernel image.
  636. */
  637. reserve_bootmem(0, (unsigned long)_ehead);
  638. reserve_bootmem((unsigned long)_stext,
  639. PFN_PHYS(start_pfn) - (unsigned long)_stext);
  640. /*
  641. * Reserve the bootmem bitmap itself as well. We do this in two
  642. * steps (first step was init_bootmem()) because this catches
  643. * the (very unlikely) case of us accidentally initializing the
  644. * bootmem allocator with an invalid RAM area.
  645. */
  646. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
  647. #ifdef CONFIG_BLK_DEV_INITRD
  648. if (INITRD_START && INITRD_SIZE) {
  649. if (INITRD_START + INITRD_SIZE <= memory_end) {
  650. reserve_bootmem(INITRD_START, INITRD_SIZE);
  651. initrd_start = INITRD_START;
  652. initrd_end = initrd_start + INITRD_SIZE;
  653. } else {
  654. printk("initrd extends beyond end of memory "
  655. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  656. initrd_start + INITRD_SIZE, memory_end);
  657. initrd_start = initrd_end = 0;
  658. }
  659. }
  660. #endif
  661. }
  662. static __init unsigned int stfl(void)
  663. {
  664. asm volatile(
  665. " .insn s,0xb2b10000,0(0)\n" /* stfl */
  666. "0:\n"
  667. EX_TABLE(0b,0b));
  668. return S390_lowcore.stfl_fac_list;
  669. }
  670. static __init int stfle(unsigned long long *list, int doublewords)
  671. {
  672. typedef struct { unsigned long long _[doublewords]; } addrtype;
  673. register unsigned long __nr asm("0") = doublewords - 1;
  674. asm volatile(".insn s,0xb2b00000,%0" /* stfle */
  675. : "=m" (*(addrtype *) list), "+d" (__nr) : : "cc");
  676. return __nr + 1;
  677. }
  678. /*
  679. * Setup hardware capabilities.
  680. */
  681. static void __init setup_hwcaps(void)
  682. {
  683. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  684. struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
  685. unsigned long long facility_list_extended;
  686. unsigned int facility_list;
  687. int i;
  688. facility_list = stfl();
  689. /*
  690. * The store facility list bits numbers as found in the principles
  691. * of operation are numbered with bit 1UL<<31 as number 0 to
  692. * bit 1UL<<0 as number 31.
  693. * Bit 0: instructions named N3, "backported" to esa-mode
  694. * Bit 2: z/Architecture mode is active
  695. * Bit 7: the store-facility-list-extended facility is installed
  696. * Bit 17: the message-security assist is installed
  697. * Bit 19: the long-displacement facility is installed
  698. * Bit 21: the extended-immediate facility is installed
  699. * These get translated to:
  700. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  701. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  702. * HWCAP_S390_LDISP bit 4, and HWCAP_S390_EIMM bit 5.
  703. */
  704. for (i = 0; i < 6; i++)
  705. if (facility_list & (1UL << (31 - stfl_bits[i])))
  706. elf_hwcap |= 1UL << i;
  707. /*
  708. * Check for additional facilities with store-facility-list-extended.
  709. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  710. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  711. * as stored by stfl, bits 32-xxx contain additional facilities.
  712. * How many facility words are stored depends on the number of
  713. * doublewords passed to the instruction. The additional facilites
  714. * are:
  715. * Bit 43: decimal floating point facility is installed
  716. * translated to:
  717. * HWCAP_S390_DFP bit 6.
  718. */
  719. if ((elf_hwcap & (1UL << 2)) &&
  720. stfle(&facility_list_extended, 1) > 0) {
  721. if (facility_list_extended & (1ULL << (64 - 43)))
  722. elf_hwcap |= 1UL << 6;
  723. }
  724. switch (cpuinfo->cpu_id.machine) {
  725. case 0x9672:
  726. #if !defined(CONFIG_64BIT)
  727. default: /* Use "g5" as default for 31 bit kernels. */
  728. #endif
  729. strcpy(elf_platform, "g5");
  730. break;
  731. case 0x2064:
  732. case 0x2066:
  733. #if defined(CONFIG_64BIT)
  734. default: /* Use "z900" as default for 64 bit kernels. */
  735. #endif
  736. strcpy(elf_platform, "z900");
  737. break;
  738. case 0x2084:
  739. case 0x2086:
  740. strcpy(elf_platform, "z990");
  741. break;
  742. case 0x2094:
  743. strcpy(elf_platform, "z9-109");
  744. break;
  745. }
  746. }
  747. /*
  748. * Setup function called from init/main.c just after the banner
  749. * was printed.
  750. */
  751. void __init
  752. setup_arch(char **cmdline_p)
  753. {
  754. /*
  755. * print what head.S has found out about the machine
  756. */
  757. #ifndef CONFIG_64BIT
  758. printk((MACHINE_IS_VM) ?
  759. "We are running under VM (31 bit mode)\n" :
  760. "We are running native (31 bit mode)\n");
  761. printk((MACHINE_HAS_IEEE) ?
  762. "This machine has an IEEE fpu\n" :
  763. "This machine has no IEEE fpu\n");
  764. #else /* CONFIG_64BIT */
  765. printk((MACHINE_IS_VM) ?
  766. "We are running under VM (64 bit mode)\n" :
  767. "We are running native (64 bit mode)\n");
  768. #endif /* CONFIG_64BIT */
  769. /* Save unparsed command line copy for /proc/cmdline */
  770. strlcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
  771. *cmdline_p = COMMAND_LINE;
  772. *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
  773. ROOT_DEV = Root_RAM0;
  774. init_mm.start_code = PAGE_OFFSET;
  775. init_mm.end_code = (unsigned long) &_etext;
  776. init_mm.end_data = (unsigned long) &_edata;
  777. init_mm.brk = (unsigned long) &_end;
  778. if (MACHINE_HAS_MVCOS)
  779. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  780. else
  781. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  782. parse_early_param();
  783. setup_ipl_info();
  784. setup_memory_end();
  785. setup_addressing_mode();
  786. setup_memory();
  787. setup_resources();
  788. setup_lowcore();
  789. cpu_init();
  790. __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
  791. smp_setup_cpu_possible_map();
  792. /*
  793. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  794. */
  795. setup_hwcaps();
  796. /*
  797. * Create kernel page tables and switch to virtual addressing.
  798. */
  799. paging_init();
  800. /* Setup default console */
  801. conmode_default();
  802. /* Setup zfcpdump support */
  803. setup_zfcpdump(console_devno);
  804. }
  805. void __cpuinit print_cpu_info(struct cpuinfo_S390 *cpuinfo)
  806. {
  807. printk("cpu %d "
  808. #ifdef CONFIG_SMP
  809. "phys_idx=%d "
  810. #endif
  811. "vers=%02X ident=%06X machine=%04X unused=%04X\n",
  812. cpuinfo->cpu_nr,
  813. #ifdef CONFIG_SMP
  814. cpuinfo->cpu_addr,
  815. #endif
  816. cpuinfo->cpu_id.version,
  817. cpuinfo->cpu_id.ident,
  818. cpuinfo->cpu_id.machine,
  819. cpuinfo->cpu_id.unused);
  820. }
  821. /*
  822. * show_cpuinfo - Get information on one CPU for use by procfs.
  823. */
  824. static int show_cpuinfo(struct seq_file *m, void *v)
  825. {
  826. static const char *hwcap_str[7] = {
  827. "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp"
  828. };
  829. struct cpuinfo_S390 *cpuinfo;
  830. unsigned long n = (unsigned long) v - 1;
  831. int i;
  832. s390_adjust_jiffies();
  833. preempt_disable();
  834. if (!n) {
  835. seq_printf(m, "vendor_id : IBM/S390\n"
  836. "# processors : %i\n"
  837. "bogomips per cpu: %lu.%02lu\n",
  838. num_online_cpus(), loops_per_jiffy/(500000/HZ),
  839. (loops_per_jiffy/(5000/HZ))%100);
  840. seq_puts(m, "features\t: ");
  841. for (i = 0; i < 7; i++)
  842. if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
  843. seq_printf(m, "%s ", hwcap_str[i]);
  844. seq_puts(m, "\n");
  845. }
  846. if (cpu_online(n)) {
  847. #ifdef CONFIG_SMP
  848. if (smp_processor_id() == n)
  849. cpuinfo = &S390_lowcore.cpu_data;
  850. else
  851. cpuinfo = &lowcore_ptr[n]->cpu_data;
  852. #else
  853. cpuinfo = &S390_lowcore.cpu_data;
  854. #endif
  855. seq_printf(m, "processor %li: "
  856. "version = %02X, "
  857. "identification = %06X, "
  858. "machine = %04X\n",
  859. n, cpuinfo->cpu_id.version,
  860. cpuinfo->cpu_id.ident,
  861. cpuinfo->cpu_id.machine);
  862. }
  863. preempt_enable();
  864. return 0;
  865. }
  866. static void *c_start(struct seq_file *m, loff_t *pos)
  867. {
  868. return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
  869. }
  870. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  871. {
  872. ++*pos;
  873. return c_start(m, pos);
  874. }
  875. static void c_stop(struct seq_file *m, void *v)
  876. {
  877. }
  878. struct seq_operations cpuinfo_op = {
  879. .start = c_start,
  880. .next = c_next,
  881. .stop = c_stop,
  882. .show = show_cpuinfo,
  883. };