setup.c 29 KB

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