setup.c 29 KB

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