setup.c 29 KB

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