setup.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * arch/s390/kernel/setup.c
  3. *
  4. * S390 version
  5. * Copyright (C) IBM Corp. 1999,2010
  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. #define KMSG_COMPONENT "setup"
  16. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  17. #include <linux/errno.h>
  18. #include <linux/module.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/stddef.h>
  23. #include <linux/unistd.h>
  24. #include <linux/ptrace.h>
  25. #include <linux/user.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/kernel_stat.h>
  35. #include <linux/device.h>
  36. #include <linux/notifier.h>
  37. #include <linux/pfn.h>
  38. #include <linux/ctype.h>
  39. #include <linux/reboot.h>
  40. #include <linux/topology.h>
  41. #include <linux/ftrace.h>
  42. #include <linux/kexec.h>
  43. #include <linux/crash_dump.h>
  44. #include <linux/memory.h>
  45. #include <asm/ipl.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/system.h>
  48. #include <asm/smp.h>
  49. #include <asm/mmu_context.h>
  50. #include <asm/cpcmd.h>
  51. #include <asm/lowcore.h>
  52. #include <asm/irq.h>
  53. #include <asm/page.h>
  54. #include <asm/ptrace.h>
  55. #include <asm/sections.h>
  56. #include <asm/ebcdic.h>
  57. #include <asm/compat.h>
  58. #include <asm/kvm_virtio.h>
  59. #include <asm/diag.h>
  60. long psw_kernel_bits = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_ASC_PRIMARY |
  61. PSW_MASK_EA | PSW_MASK_BA;
  62. long psw_user_bits = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT |
  63. PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_MCHECK |
  64. PSW_MASK_PSTATE | PSW_ASC_HOME;
  65. /*
  66. * User copy operations.
  67. */
  68. struct uaccess_ops uaccess;
  69. EXPORT_SYMBOL(uaccess);
  70. /*
  71. * Machine setup..
  72. */
  73. unsigned int console_mode = 0;
  74. EXPORT_SYMBOL(console_mode);
  75. unsigned int console_devno = -1;
  76. EXPORT_SYMBOL(console_devno);
  77. unsigned int console_irq = -1;
  78. EXPORT_SYMBOL(console_irq);
  79. unsigned long elf_hwcap = 0;
  80. char elf_platform[ELF_PLATFORM_SIZE];
  81. struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
  82. int __initdata memory_end_set;
  83. unsigned long __initdata memory_end;
  84. /* An array with a pointer to the lowcore of every CPU. */
  85. struct _lowcore *lowcore_ptr[NR_CPUS];
  86. EXPORT_SYMBOL(lowcore_ptr);
  87. /*
  88. * This is set up by the setup-routine at boot-time
  89. * for S390 need to find out, what we have to setup
  90. * using address 0x10400 ...
  91. */
  92. #include <asm/setup.h>
  93. /*
  94. * condev= and conmode= setup parameter.
  95. */
  96. static int __init condev_setup(char *str)
  97. {
  98. int vdev;
  99. vdev = simple_strtoul(str, &str, 0);
  100. if (vdev >= 0 && vdev < 65536) {
  101. console_devno = vdev;
  102. console_irq = -1;
  103. }
  104. return 1;
  105. }
  106. __setup("condev=", condev_setup);
  107. static void __init set_preferred_console(void)
  108. {
  109. if (MACHINE_IS_KVM)
  110. add_preferred_console("hvc", 0, NULL);
  111. else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  112. add_preferred_console("ttyS", 0, NULL);
  113. else if (CONSOLE_IS_3270)
  114. add_preferred_console("tty3270", 0, NULL);
  115. }
  116. static int __init conmode_setup(char *str)
  117. {
  118. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  119. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  120. SET_CONSOLE_SCLP;
  121. #endif
  122. #if defined(CONFIG_TN3215_CONSOLE)
  123. if (strncmp(str, "3215", 5) == 0)
  124. SET_CONSOLE_3215;
  125. #endif
  126. #if defined(CONFIG_TN3270_CONSOLE)
  127. if (strncmp(str, "3270", 5) == 0)
  128. SET_CONSOLE_3270;
  129. #endif
  130. set_preferred_console();
  131. return 1;
  132. }
  133. __setup("conmode=", conmode_setup);
  134. static void __init conmode_default(void)
  135. {
  136. char query_buffer[1024];
  137. char *ptr;
  138. if (MACHINE_IS_VM) {
  139. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  140. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  141. ptr = strstr(query_buffer, "SUBCHANNEL =");
  142. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  143. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  144. ptr = strstr(query_buffer, "CONMODE");
  145. /*
  146. * Set the conmode to 3215 so that the device recognition
  147. * will set the cu_type of the console to 3215. If the
  148. * conmode is 3270 and we don't set it back then both
  149. * 3215 and the 3270 driver will try to access the console
  150. * device (3215 as console and 3270 as normal tty).
  151. */
  152. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  153. if (ptr == NULL) {
  154. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  155. SET_CONSOLE_SCLP;
  156. #endif
  157. return;
  158. }
  159. if (strncmp(ptr + 8, "3270", 4) == 0) {
  160. #if defined(CONFIG_TN3270_CONSOLE)
  161. SET_CONSOLE_3270;
  162. #elif defined(CONFIG_TN3215_CONSOLE)
  163. SET_CONSOLE_3215;
  164. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  165. SET_CONSOLE_SCLP;
  166. #endif
  167. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  168. #if defined(CONFIG_TN3215_CONSOLE)
  169. SET_CONSOLE_3215;
  170. #elif defined(CONFIG_TN3270_CONSOLE)
  171. SET_CONSOLE_3270;
  172. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  173. SET_CONSOLE_SCLP;
  174. #endif
  175. }
  176. } else {
  177. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  178. SET_CONSOLE_SCLP;
  179. #endif
  180. }
  181. }
  182. #ifdef CONFIG_ZFCPDUMP
  183. static void __init setup_zfcpdump(unsigned int console_devno)
  184. {
  185. static char str[41];
  186. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  187. return;
  188. if (OLDMEM_BASE)
  189. return;
  190. if (console_devno != -1)
  191. sprintf(str, " cio_ignore=all,!0.0.%04x,!0.0.%04x",
  192. ipl_info.data.fcp.dev_id.devno, console_devno);
  193. else
  194. sprintf(str, " cio_ignore=all,!0.0.%04x",
  195. ipl_info.data.fcp.dev_id.devno);
  196. strcat(boot_command_line, str);
  197. console_loglevel = 2;
  198. }
  199. #else
  200. static inline void setup_zfcpdump(unsigned int console_devno) {}
  201. #endif /* CONFIG_ZFCPDUMP */
  202. /*
  203. * Reboot, halt and power_off stubs. They just call _machine_restart,
  204. * _machine_halt or _machine_power_off.
  205. */
  206. void machine_restart(char *command)
  207. {
  208. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  209. /*
  210. * Only unblank the console if we are called in enabled
  211. * context or a bust_spinlocks cleared the way for us.
  212. */
  213. console_unblank();
  214. _machine_restart(command);
  215. }
  216. void machine_halt(void)
  217. {
  218. if (!in_interrupt() || oops_in_progress)
  219. /*
  220. * Only unblank the console if we are called in enabled
  221. * context or a bust_spinlocks cleared the way for us.
  222. */
  223. console_unblank();
  224. _machine_halt();
  225. }
  226. void machine_power_off(void)
  227. {
  228. if (!in_interrupt() || oops_in_progress)
  229. /*
  230. * Only unblank the console if we are called in enabled
  231. * context or a bust_spinlocks cleared the way for us.
  232. */
  233. console_unblank();
  234. _machine_power_off();
  235. }
  236. /*
  237. * Dummy power off function.
  238. */
  239. void (*pm_power_off)(void) = machine_power_off;
  240. static int __init early_parse_mem(char *p)
  241. {
  242. memory_end = memparse(p, &p);
  243. memory_end_set = 1;
  244. return 0;
  245. }
  246. early_param("mem", early_parse_mem);
  247. unsigned int user_mode = HOME_SPACE_MODE;
  248. EXPORT_SYMBOL_GPL(user_mode);
  249. static int set_amode_primary(void)
  250. {
  251. psw_kernel_bits = (psw_kernel_bits & ~PSW_MASK_ASC) | PSW_ASC_HOME;
  252. psw_user_bits = (psw_user_bits & ~PSW_MASK_ASC) | PSW_ASC_PRIMARY;
  253. #ifdef CONFIG_COMPAT
  254. psw32_user_bits =
  255. (psw32_user_bits & ~PSW32_MASK_ASC) | PSW32_ASC_PRIMARY;
  256. #endif
  257. if (MACHINE_HAS_MVCOS) {
  258. memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
  259. return 1;
  260. } else {
  261. memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
  262. return 0;
  263. }
  264. }
  265. /*
  266. * Switch kernel/user addressing modes?
  267. */
  268. static int __init early_parse_switch_amode(char *p)
  269. {
  270. user_mode = PRIMARY_SPACE_MODE;
  271. return 0;
  272. }
  273. early_param("switch_amode", early_parse_switch_amode);
  274. static int __init early_parse_user_mode(char *p)
  275. {
  276. if (p && strcmp(p, "primary") == 0)
  277. user_mode = PRIMARY_SPACE_MODE;
  278. else if (!p || strcmp(p, "home") == 0)
  279. user_mode = HOME_SPACE_MODE;
  280. else
  281. return 1;
  282. return 0;
  283. }
  284. early_param("user_mode", early_parse_user_mode);
  285. static void setup_addressing_mode(void)
  286. {
  287. if (user_mode == PRIMARY_SPACE_MODE) {
  288. if (set_amode_primary())
  289. pr_info("Address spaces switched, "
  290. "mvcos available\n");
  291. else
  292. pr_info("Address spaces switched, "
  293. "mvcos not available\n");
  294. }
  295. }
  296. static void __init
  297. setup_lowcore(void)
  298. {
  299. struct _lowcore *lc;
  300. /*
  301. * Setup lowcore for boot cpu
  302. */
  303. BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
  304. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  305. lc->restart_psw.mask = psw_kernel_bits;
  306. lc->restart_psw.addr =
  307. PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
  308. lc->external_new_psw.mask = psw_kernel_bits |
  309. PSW_MASK_DAT | PSW_MASK_MCHECK;
  310. lc->external_new_psw.addr =
  311. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  312. lc->svc_new_psw.mask = psw_kernel_bits |
  313. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  314. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  315. lc->program_new_psw.mask = psw_kernel_bits |
  316. PSW_MASK_DAT | PSW_MASK_MCHECK;
  317. lc->program_new_psw.addr =
  318. PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
  319. lc->mcck_new_psw.mask = psw_kernel_bits;
  320. lc->mcck_new_psw.addr =
  321. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  322. lc->io_new_psw.mask = psw_kernel_bits |
  323. PSW_MASK_DAT | PSW_MASK_MCHECK;
  324. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  325. lc->clock_comparator = -1ULL;
  326. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  327. lc->async_stack = (unsigned long)
  328. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  329. lc->panic_stack = (unsigned long)
  330. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  331. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  332. lc->thread_info = (unsigned long) &init_thread_union;
  333. lc->machine_flags = S390_lowcore.machine_flags;
  334. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  335. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  336. MAX_FACILITY_BIT/8);
  337. #ifndef CONFIG_64BIT
  338. if (MACHINE_HAS_IEEE) {
  339. lc->extended_save_area_addr = (__u32)
  340. __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
  341. /* enable extended save area */
  342. __ctl_set_bit(14, 29);
  343. }
  344. #else
  345. lc->cmf_hpp = -1ULL;
  346. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  347. #endif
  348. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  349. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  350. lc->exit_timer = S390_lowcore.exit_timer;
  351. lc->user_timer = S390_lowcore.user_timer;
  352. lc->system_timer = S390_lowcore.system_timer;
  353. lc->steal_timer = S390_lowcore.steal_timer;
  354. lc->last_update_timer = S390_lowcore.last_update_timer;
  355. lc->last_update_clock = S390_lowcore.last_update_clock;
  356. lc->ftrace_func = S390_lowcore.ftrace_func;
  357. set_prefix((u32)(unsigned long) lc);
  358. lowcore_ptr[0] = lc;
  359. }
  360. static struct resource code_resource = {
  361. .name = "Kernel code",
  362. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  363. };
  364. static struct resource data_resource = {
  365. .name = "Kernel data",
  366. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  367. };
  368. static struct resource bss_resource = {
  369. .name = "Kernel bss",
  370. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  371. };
  372. static struct resource __initdata *standard_resources[] = {
  373. &code_resource,
  374. &data_resource,
  375. &bss_resource,
  376. };
  377. static void __init setup_resources(void)
  378. {
  379. struct resource *res, *std_res, *sub_res;
  380. int i, j;
  381. code_resource.start = (unsigned long) &_text;
  382. code_resource.end = (unsigned long) &_etext - 1;
  383. data_resource.start = (unsigned long) &_etext;
  384. data_resource.end = (unsigned long) &_edata - 1;
  385. bss_resource.start = (unsigned long) &__bss_start;
  386. bss_resource.end = (unsigned long) &__bss_stop - 1;
  387. for (i = 0; i < MEMORY_CHUNKS; i++) {
  388. if (!memory_chunk[i].size)
  389. continue;
  390. if (memory_chunk[i].type == CHUNK_OLDMEM ||
  391. memory_chunk[i].type == CHUNK_CRASHK)
  392. continue;
  393. res = alloc_bootmem_low(sizeof(*res));
  394. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  395. switch (memory_chunk[i].type) {
  396. case CHUNK_READ_WRITE:
  397. case CHUNK_CRASHK:
  398. res->name = "System RAM";
  399. break;
  400. case CHUNK_READ_ONLY:
  401. res->name = "System ROM";
  402. res->flags |= IORESOURCE_READONLY;
  403. break;
  404. default:
  405. res->name = "reserved";
  406. }
  407. res->start = memory_chunk[i].addr;
  408. res->end = res->start + memory_chunk[i].size - 1;
  409. request_resource(&iomem_resource, res);
  410. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  411. std_res = standard_resources[j];
  412. if (std_res->start < res->start ||
  413. std_res->start > res->end)
  414. continue;
  415. if (std_res->end > res->end) {
  416. sub_res = alloc_bootmem_low(sizeof(*sub_res));
  417. *sub_res = *std_res;
  418. sub_res->end = res->end;
  419. std_res->start = res->end + 1;
  420. request_resource(res, sub_res);
  421. } else {
  422. request_resource(res, std_res);
  423. }
  424. }
  425. }
  426. }
  427. unsigned long real_memory_size;
  428. EXPORT_SYMBOL_GPL(real_memory_size);
  429. static void __init setup_memory_end(void)
  430. {
  431. unsigned long memory_size;
  432. unsigned long max_mem;
  433. int i;
  434. #ifdef CONFIG_ZFCPDUMP
  435. if (ipl_info.type == IPL_TYPE_FCP_DUMP && !OLDMEM_BASE) {
  436. memory_end = ZFCPDUMP_HSA_SIZE;
  437. memory_end_set = 1;
  438. }
  439. #endif
  440. memory_size = 0;
  441. memory_end &= PAGE_MASK;
  442. max_mem = memory_end ? min(VMEM_MAX_PHYS, memory_end) : VMEM_MAX_PHYS;
  443. memory_end = min(max_mem, memory_end);
  444. /*
  445. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  446. * extra checks that HOLES_IN_ZONE would require.
  447. */
  448. for (i = 0; i < MEMORY_CHUNKS; i++) {
  449. unsigned long start, end;
  450. struct mem_chunk *chunk;
  451. unsigned long align;
  452. chunk = &memory_chunk[i];
  453. align = 1UL << (MAX_ORDER + PAGE_SHIFT - 1);
  454. start = (chunk->addr + align - 1) & ~(align - 1);
  455. end = (chunk->addr + chunk->size) & ~(align - 1);
  456. if (start >= end)
  457. memset(chunk, 0, sizeof(*chunk));
  458. else {
  459. chunk->addr = start;
  460. chunk->size = end - start;
  461. }
  462. }
  463. for (i = 0; i < MEMORY_CHUNKS; i++) {
  464. struct mem_chunk *chunk = &memory_chunk[i];
  465. real_memory_size = max(real_memory_size,
  466. chunk->addr + chunk->size);
  467. if (chunk->addr >= max_mem) {
  468. memset(chunk, 0, sizeof(*chunk));
  469. continue;
  470. }
  471. if (chunk->addr + chunk->size > max_mem)
  472. chunk->size = max_mem - chunk->addr;
  473. memory_size = max(memory_size, chunk->addr + chunk->size);
  474. }
  475. if (!memory_end)
  476. memory_end = memory_size;
  477. }
  478. void *restart_stack __attribute__((__section__(".data")));
  479. /*
  480. * Setup new PSW and allocate stack for PSW restart interrupt
  481. */
  482. static void __init setup_restart_psw(void)
  483. {
  484. psw_t psw;
  485. restart_stack = __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0);
  486. restart_stack += ASYNC_SIZE;
  487. /*
  488. * Setup restart PSW for absolute zero lowcore. This is necesary
  489. * if PSW restart is done on an offline CPU that has lowcore zero
  490. */
  491. psw.mask = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
  492. psw.addr = PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
  493. copy_to_absolute_zero(&S390_lowcore.restart_psw, &psw, sizeof(psw));
  494. }
  495. static void __init setup_vmcoreinfo(void)
  496. {
  497. #ifdef CONFIG_KEXEC
  498. unsigned long ptr = paddr_vmcoreinfo_note();
  499. copy_to_absolute_zero(&S390_lowcore.vmcore_info, &ptr, sizeof(ptr));
  500. #endif
  501. }
  502. #ifdef CONFIG_CRASH_DUMP
  503. /*
  504. * Find suitable location for crashkernel memory
  505. */
  506. static unsigned long __init find_crash_base(unsigned long crash_size,
  507. char **msg)
  508. {
  509. unsigned long crash_base;
  510. struct mem_chunk *chunk;
  511. int i;
  512. if (memory_chunk[0].size < crash_size) {
  513. *msg = "first memory chunk must be at least crashkernel size";
  514. return 0;
  515. }
  516. if (OLDMEM_BASE && crash_size == OLDMEM_SIZE)
  517. return OLDMEM_BASE;
  518. for (i = MEMORY_CHUNKS - 1; i >= 0; i--) {
  519. chunk = &memory_chunk[i];
  520. if (chunk->size == 0)
  521. continue;
  522. if (chunk->type != CHUNK_READ_WRITE)
  523. continue;
  524. if (chunk->size < crash_size)
  525. continue;
  526. crash_base = (chunk->addr + chunk->size) - crash_size;
  527. if (crash_base < crash_size)
  528. continue;
  529. if (crash_base < ZFCPDUMP_HSA_SIZE_MAX)
  530. continue;
  531. if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
  532. continue;
  533. return crash_base;
  534. }
  535. *msg = "no suitable area found";
  536. return 0;
  537. }
  538. /*
  539. * Check if crash_base and crash_size is valid
  540. */
  541. static int __init verify_crash_base(unsigned long crash_base,
  542. unsigned long crash_size,
  543. char **msg)
  544. {
  545. struct mem_chunk *chunk;
  546. int i;
  547. /*
  548. * Because we do the swap to zero, we must have at least 'crash_size'
  549. * bytes free space before crash_base
  550. */
  551. if (crash_size > crash_base) {
  552. *msg = "crashkernel offset must be greater than size";
  553. return -EINVAL;
  554. }
  555. /* First memory chunk must be at least crash_size */
  556. if (memory_chunk[0].size < crash_size) {
  557. *msg = "first memory chunk must be at least crashkernel size";
  558. return -EINVAL;
  559. }
  560. /* Check if we fit into the respective memory chunk */
  561. for (i = 0; i < MEMORY_CHUNKS; i++) {
  562. chunk = &memory_chunk[i];
  563. if (chunk->size == 0)
  564. continue;
  565. if (crash_base < chunk->addr)
  566. continue;
  567. if (crash_base >= chunk->addr + chunk->size)
  568. continue;
  569. /* we have found the memory chunk */
  570. if (crash_base + crash_size > chunk->addr + chunk->size) {
  571. *msg = "selected memory chunk is too small for "
  572. "crashkernel memory";
  573. return -EINVAL;
  574. }
  575. return 0;
  576. }
  577. *msg = "invalid memory range specified";
  578. return -EINVAL;
  579. }
  580. /*
  581. * Reserve kdump memory by creating a memory hole in the mem_chunk array
  582. */
  583. static void __init reserve_kdump_bootmem(unsigned long addr, unsigned long size,
  584. int type)
  585. {
  586. create_mem_hole(memory_chunk, addr, size, type);
  587. }
  588. /*
  589. * When kdump is enabled, we have to ensure that no memory from
  590. * the area [0 - crashkernel memory size] and
  591. * [crashk_res.start - crashk_res.end] is set offline.
  592. */
  593. static int kdump_mem_notifier(struct notifier_block *nb,
  594. unsigned long action, void *data)
  595. {
  596. struct memory_notify *arg = data;
  597. if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
  598. return NOTIFY_BAD;
  599. if (arg->start_pfn > PFN_DOWN(crashk_res.end))
  600. return NOTIFY_OK;
  601. if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
  602. return NOTIFY_OK;
  603. return NOTIFY_BAD;
  604. }
  605. static struct notifier_block kdump_mem_nb = {
  606. .notifier_call = kdump_mem_notifier,
  607. };
  608. #endif
  609. /*
  610. * Make sure that oldmem, where the dump is stored, is protected
  611. */
  612. static void reserve_oldmem(void)
  613. {
  614. #ifdef CONFIG_CRASH_DUMP
  615. if (!OLDMEM_BASE)
  616. return;
  617. reserve_kdump_bootmem(OLDMEM_BASE, OLDMEM_SIZE, CHUNK_OLDMEM);
  618. reserve_kdump_bootmem(OLDMEM_SIZE, memory_end - OLDMEM_SIZE,
  619. CHUNK_OLDMEM);
  620. if (OLDMEM_BASE + OLDMEM_SIZE == real_memory_size)
  621. saved_max_pfn = PFN_DOWN(OLDMEM_BASE) - 1;
  622. else
  623. saved_max_pfn = PFN_DOWN(real_memory_size) - 1;
  624. #endif
  625. }
  626. /*
  627. * Reserve memory for kdump kernel to be loaded with kexec
  628. */
  629. static void __init reserve_crashkernel(void)
  630. {
  631. #ifdef CONFIG_CRASH_DUMP
  632. unsigned long long crash_base, crash_size;
  633. char *msg;
  634. int rc;
  635. rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
  636. &crash_base);
  637. if (rc || crash_size == 0)
  638. return;
  639. crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
  640. crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
  641. if (register_memory_notifier(&kdump_mem_nb))
  642. return;
  643. if (!crash_base)
  644. crash_base = find_crash_base(crash_size, &msg);
  645. if (!crash_base) {
  646. pr_info("crashkernel reservation failed: %s\n", msg);
  647. unregister_memory_notifier(&kdump_mem_nb);
  648. return;
  649. }
  650. if (verify_crash_base(crash_base, crash_size, &msg)) {
  651. pr_info("crashkernel reservation failed: %s\n", msg);
  652. unregister_memory_notifier(&kdump_mem_nb);
  653. return;
  654. }
  655. if (!OLDMEM_BASE && MACHINE_IS_VM)
  656. diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
  657. crashk_res.start = crash_base;
  658. crashk_res.end = crash_base + crash_size - 1;
  659. insert_resource(&iomem_resource, &crashk_res);
  660. reserve_kdump_bootmem(crash_base, crash_size, CHUNK_CRASHK);
  661. pr_info("Reserving %lluMB of memory at %lluMB "
  662. "for crashkernel (System RAM: %luMB)\n",
  663. crash_size >> 20, crash_base >> 20, memory_end >> 20);
  664. #endif
  665. }
  666. static void __init
  667. setup_memory(void)
  668. {
  669. unsigned long bootmap_size;
  670. unsigned long start_pfn, end_pfn;
  671. int i;
  672. /*
  673. * partially used pages are not usable - thus
  674. * we are rounding upwards:
  675. */
  676. start_pfn = PFN_UP(__pa(&_end));
  677. end_pfn = max_pfn = PFN_DOWN(memory_end);
  678. #ifdef CONFIG_BLK_DEV_INITRD
  679. /*
  680. * Move the initrd in case the bitmap of the bootmem allocater
  681. * would overwrite it.
  682. */
  683. if (INITRD_START && INITRD_SIZE) {
  684. unsigned long bmap_size;
  685. unsigned long start;
  686. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  687. bmap_size = PFN_PHYS(bmap_size);
  688. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  689. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  690. #ifdef CONFIG_CRASH_DUMP
  691. if (OLDMEM_BASE) {
  692. /* Move initrd behind kdump oldmem */
  693. if (start + INITRD_SIZE > OLDMEM_BASE &&
  694. start < OLDMEM_BASE + OLDMEM_SIZE)
  695. start = OLDMEM_BASE + OLDMEM_SIZE;
  696. }
  697. #endif
  698. if (start + INITRD_SIZE > memory_end) {
  699. pr_err("initrd extends beyond end of "
  700. "memory (0x%08lx > 0x%08lx) "
  701. "disabling initrd\n",
  702. start + INITRD_SIZE, memory_end);
  703. INITRD_START = INITRD_SIZE = 0;
  704. } else {
  705. pr_info("Moving initrd (0x%08lx -> "
  706. "0x%08lx, size: %ld)\n",
  707. INITRD_START, start, INITRD_SIZE);
  708. memmove((void *) start, (void *) INITRD_START,
  709. INITRD_SIZE);
  710. INITRD_START = start;
  711. }
  712. }
  713. }
  714. #endif
  715. /*
  716. * Initialize the boot-time allocator
  717. */
  718. bootmap_size = init_bootmem(start_pfn, end_pfn);
  719. /*
  720. * Register RAM areas with the bootmem allocator.
  721. */
  722. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  723. unsigned long start_chunk, end_chunk, pfn;
  724. if (memory_chunk[i].type != CHUNK_READ_WRITE &&
  725. memory_chunk[i].type != CHUNK_CRASHK)
  726. continue;
  727. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  728. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
  729. end_chunk = min(end_chunk, end_pfn);
  730. if (start_chunk >= end_chunk)
  731. continue;
  732. add_active_range(0, start_chunk, end_chunk);
  733. pfn = max(start_chunk, start_pfn);
  734. for (; pfn < end_chunk; pfn++)
  735. page_set_storage_key(PFN_PHYS(pfn),
  736. PAGE_DEFAULT_KEY, 0);
  737. }
  738. psw_set_key(PAGE_DEFAULT_KEY);
  739. free_bootmem_with_active_regions(0, max_pfn);
  740. /*
  741. * Reserve memory used for lowcore/command line/kernel image.
  742. */
  743. reserve_bootmem(0, (unsigned long)_ehead, BOOTMEM_DEFAULT);
  744. reserve_bootmem((unsigned long)_stext,
  745. PFN_PHYS(start_pfn) - (unsigned long)_stext,
  746. BOOTMEM_DEFAULT);
  747. /*
  748. * Reserve the bootmem bitmap itself as well. We do this in two
  749. * steps (first step was init_bootmem()) because this catches
  750. * the (very unlikely) case of us accidentally initializing the
  751. * bootmem allocator with an invalid RAM area.
  752. */
  753. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size,
  754. BOOTMEM_DEFAULT);
  755. #ifdef CONFIG_CRASH_DUMP
  756. if (crashk_res.start)
  757. reserve_bootmem(crashk_res.start,
  758. crashk_res.end - crashk_res.start + 1,
  759. BOOTMEM_DEFAULT);
  760. if (is_kdump_kernel())
  761. reserve_bootmem(elfcorehdr_addr - OLDMEM_BASE,
  762. PAGE_ALIGN(elfcorehdr_size), BOOTMEM_DEFAULT);
  763. #endif
  764. #ifdef CONFIG_BLK_DEV_INITRD
  765. if (INITRD_START && INITRD_SIZE) {
  766. if (INITRD_START + INITRD_SIZE <= memory_end) {
  767. reserve_bootmem(INITRD_START, INITRD_SIZE,
  768. BOOTMEM_DEFAULT);
  769. initrd_start = INITRD_START;
  770. initrd_end = initrd_start + INITRD_SIZE;
  771. } else {
  772. pr_err("initrd extends beyond end of "
  773. "memory (0x%08lx > 0x%08lx) "
  774. "disabling initrd\n",
  775. initrd_start + INITRD_SIZE, memory_end);
  776. initrd_start = initrd_end = 0;
  777. }
  778. }
  779. #endif
  780. }
  781. /*
  782. * Setup hardware capabilities.
  783. */
  784. static void __init setup_hwcaps(void)
  785. {
  786. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  787. struct cpuid cpu_id;
  788. int i;
  789. /*
  790. * The store facility list bits numbers as found in the principles
  791. * of operation are numbered with bit 1UL<<31 as number 0 to
  792. * bit 1UL<<0 as number 31.
  793. * Bit 0: instructions named N3, "backported" to esa-mode
  794. * Bit 2: z/Architecture mode is active
  795. * Bit 7: the store-facility-list-extended facility is installed
  796. * Bit 17: the message-security assist is installed
  797. * Bit 19: the long-displacement facility is installed
  798. * Bit 21: the extended-immediate facility is installed
  799. * Bit 22: extended-translation facility 3 is installed
  800. * Bit 30: extended-translation facility 3 enhancement facility
  801. * These get translated to:
  802. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  803. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  804. * HWCAP_S390_LDISP bit 4, HWCAP_S390_EIMM bit 5 and
  805. * HWCAP_S390_ETF3EH bit 8 (22 && 30).
  806. */
  807. for (i = 0; i < 6; i++)
  808. if (test_facility(stfl_bits[i]))
  809. elf_hwcap |= 1UL << i;
  810. if (test_facility(22) && test_facility(30))
  811. elf_hwcap |= HWCAP_S390_ETF3EH;
  812. /*
  813. * Check for additional facilities with store-facility-list-extended.
  814. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  815. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  816. * as stored by stfl, bits 32-xxx contain additional facilities.
  817. * How many facility words are stored depends on the number of
  818. * doublewords passed to the instruction. The additional facilities
  819. * are:
  820. * Bit 42: decimal floating point facility is installed
  821. * Bit 44: perform floating point operation facility is installed
  822. * translated to:
  823. * HWCAP_S390_DFP bit 6 (42 && 44).
  824. */
  825. if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
  826. elf_hwcap |= HWCAP_S390_DFP;
  827. /*
  828. * Huge page support HWCAP_S390_HPAGE is bit 7.
  829. */
  830. if (MACHINE_HAS_HPAGE)
  831. elf_hwcap |= HWCAP_S390_HPAGE;
  832. /*
  833. * 64-bit register support for 31-bit processes
  834. * HWCAP_S390_HIGH_GPRS is bit 9.
  835. */
  836. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  837. get_cpu_id(&cpu_id);
  838. switch (cpu_id.machine) {
  839. case 0x9672:
  840. #if !defined(CONFIG_64BIT)
  841. default: /* Use "g5" as default for 31 bit kernels. */
  842. #endif
  843. strcpy(elf_platform, "g5");
  844. break;
  845. case 0x2064:
  846. case 0x2066:
  847. #if defined(CONFIG_64BIT)
  848. default: /* Use "z900" as default for 64 bit kernels. */
  849. #endif
  850. strcpy(elf_platform, "z900");
  851. break;
  852. case 0x2084:
  853. case 0x2086:
  854. strcpy(elf_platform, "z990");
  855. break;
  856. case 0x2094:
  857. case 0x2096:
  858. strcpy(elf_platform, "z9-109");
  859. break;
  860. case 0x2097:
  861. case 0x2098:
  862. strcpy(elf_platform, "z10");
  863. break;
  864. case 0x2817:
  865. case 0x2818:
  866. strcpy(elf_platform, "z196");
  867. break;
  868. }
  869. }
  870. /*
  871. * Setup function called from init/main.c just after the banner
  872. * was printed.
  873. */
  874. void __init
  875. setup_arch(char **cmdline_p)
  876. {
  877. /*
  878. * print what head.S has found out about the machine
  879. */
  880. #ifndef CONFIG_64BIT
  881. if (MACHINE_IS_VM)
  882. pr_info("Linux is running as a z/VM "
  883. "guest operating system in 31-bit mode\n");
  884. else if (MACHINE_IS_LPAR)
  885. pr_info("Linux is running natively in 31-bit mode\n");
  886. if (MACHINE_HAS_IEEE)
  887. pr_info("The hardware system has IEEE compatible "
  888. "floating point units\n");
  889. else
  890. pr_info("The hardware system has no IEEE compatible "
  891. "floating point units\n");
  892. #else /* CONFIG_64BIT */
  893. if (MACHINE_IS_VM)
  894. pr_info("Linux is running as a z/VM "
  895. "guest operating system in 64-bit mode\n");
  896. else if (MACHINE_IS_KVM)
  897. pr_info("Linux is running under KVM in 64-bit mode\n");
  898. else if (MACHINE_IS_LPAR)
  899. pr_info("Linux is running natively in 64-bit mode\n");
  900. #endif /* CONFIG_64BIT */
  901. /* Have one command line that is parsed and saved in /proc/cmdline */
  902. /* boot_command_line has been already set up in early.c */
  903. *cmdline_p = boot_command_line;
  904. ROOT_DEV = Root_RAM0;
  905. init_mm.start_code = PAGE_OFFSET;
  906. init_mm.end_code = (unsigned long) &_etext;
  907. init_mm.end_data = (unsigned long) &_edata;
  908. init_mm.brk = (unsigned long) &_end;
  909. if (MACHINE_HAS_MVCOS)
  910. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  911. else
  912. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  913. parse_early_param();
  914. setup_ipl();
  915. setup_memory_end();
  916. setup_addressing_mode();
  917. reserve_oldmem();
  918. reserve_crashkernel();
  919. setup_memory();
  920. setup_resources();
  921. setup_vmcoreinfo();
  922. setup_restart_psw();
  923. setup_lowcore();
  924. cpu_init();
  925. s390_init_cpu_topology();
  926. /*
  927. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  928. */
  929. setup_hwcaps();
  930. /*
  931. * Create kernel page tables and switch to virtual addressing.
  932. */
  933. paging_init();
  934. /* Setup default console */
  935. conmode_default();
  936. set_preferred_console();
  937. /* Setup zfcpdump support */
  938. setup_zfcpdump(console_devno);
  939. }