setup.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. /*
  2. * arch/s390/kernel/setup.c
  3. *
  4. * S390 version
  5. * Copyright (C) IBM Corp. 1999,2010
  6. * Author(s): Hartmut Penner (hp@de.ibm.com),
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * Derived from "arch/i386/kernel/setup.c"
  10. * Copyright (C) 1995, Linus Torvalds
  11. */
  12. /*
  13. * This file handles the architecture-dependent parts of initialization
  14. */
  15. #define KMSG_COMPONENT "setup"
  16. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  17. #include <linux/errno.h>
  18. #include <linux/module.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel.h>
  21. #include <linux/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 <asm/ipl.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/system.h>
  49. #include <asm/smp.h>
  50. #include <asm/mmu_context.h>
  51. #include <asm/cpcmd.h>
  52. #include <asm/lowcore.h>
  53. #include <asm/irq.h>
  54. #include <asm/page.h>
  55. #include <asm/ptrace.h>
  56. #include <asm/sections.h>
  57. #include <asm/ebcdic.h>
  58. #include <asm/compat.h>
  59. #include <asm/kvm_virtio.h>
  60. #include <asm/diag.h>
  61. long psw_kernel_bits = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_ASC_PRIMARY |
  62. PSW_MASK_EA | PSW_MASK_BA;
  63. long psw_user_bits = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT |
  64. PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_MCHECK |
  65. PSW_MASK_PSTATE | PSW_ASC_HOME;
  66. /*
  67. * User copy operations.
  68. */
  69. struct uaccess_ops uaccess;
  70. EXPORT_SYMBOL(uaccess);
  71. /*
  72. * Machine setup..
  73. */
  74. unsigned int console_mode = 0;
  75. EXPORT_SYMBOL(console_mode);
  76. unsigned int console_devno = -1;
  77. EXPORT_SYMBOL(console_devno);
  78. unsigned int console_irq = -1;
  79. EXPORT_SYMBOL(console_irq);
  80. unsigned long elf_hwcap = 0;
  81. char elf_platform[ELF_PLATFORM_SIZE];
  82. struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
  83. int __initdata memory_end_set;
  84. unsigned long __initdata memory_end;
  85. unsigned long VMALLOC_START;
  86. EXPORT_SYMBOL(VMALLOC_START);
  87. unsigned long VMALLOC_END;
  88. EXPORT_SYMBOL(VMALLOC_END);
  89. struct page *vmemmap;
  90. EXPORT_SYMBOL(vmemmap);
  91. /* An array with a pointer to the lowcore of every CPU. */
  92. struct _lowcore *lowcore_ptr[NR_CPUS];
  93. EXPORT_SYMBOL(lowcore_ptr);
  94. /*
  95. * This is set up by the setup-routine at boot-time
  96. * for S390 need to find out, what we have to setup
  97. * using address 0x10400 ...
  98. */
  99. #include <asm/setup.h>
  100. /*
  101. * condev= and conmode= setup parameter.
  102. */
  103. static int __init condev_setup(char *str)
  104. {
  105. int vdev;
  106. vdev = simple_strtoul(str, &str, 0);
  107. if (vdev >= 0 && vdev < 65536) {
  108. console_devno = vdev;
  109. console_irq = -1;
  110. }
  111. return 1;
  112. }
  113. __setup("condev=", condev_setup);
  114. static void __init set_preferred_console(void)
  115. {
  116. if (MACHINE_IS_KVM)
  117. add_preferred_console("hvc", 0, NULL);
  118. else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  119. add_preferred_console("ttyS", 0, NULL);
  120. else if (CONSOLE_IS_3270)
  121. add_preferred_console("tty3270", 0, NULL);
  122. }
  123. static int __init conmode_setup(char *str)
  124. {
  125. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  126. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  127. SET_CONSOLE_SCLP;
  128. #endif
  129. #if defined(CONFIG_TN3215_CONSOLE)
  130. if (strncmp(str, "3215", 5) == 0)
  131. SET_CONSOLE_3215;
  132. #endif
  133. #if defined(CONFIG_TN3270_CONSOLE)
  134. if (strncmp(str, "3270", 5) == 0)
  135. SET_CONSOLE_3270;
  136. #endif
  137. set_preferred_console();
  138. return 1;
  139. }
  140. __setup("conmode=", conmode_setup);
  141. static void __init conmode_default(void)
  142. {
  143. char query_buffer[1024];
  144. char *ptr;
  145. if (MACHINE_IS_VM) {
  146. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  147. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  148. ptr = strstr(query_buffer, "SUBCHANNEL =");
  149. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  150. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  151. ptr = strstr(query_buffer, "CONMODE");
  152. /*
  153. * Set the conmode to 3215 so that the device recognition
  154. * will set the cu_type of the console to 3215. If the
  155. * conmode is 3270 and we don't set it back then both
  156. * 3215 and the 3270 driver will try to access the console
  157. * device (3215 as console and 3270 as normal tty).
  158. */
  159. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  160. if (ptr == NULL) {
  161. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  162. SET_CONSOLE_SCLP;
  163. #endif
  164. return;
  165. }
  166. if (strncmp(ptr + 8, "3270", 4) == 0) {
  167. #if defined(CONFIG_TN3270_CONSOLE)
  168. SET_CONSOLE_3270;
  169. #elif defined(CONFIG_TN3215_CONSOLE)
  170. SET_CONSOLE_3215;
  171. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  172. SET_CONSOLE_SCLP;
  173. #endif
  174. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  175. #if defined(CONFIG_TN3215_CONSOLE)
  176. SET_CONSOLE_3215;
  177. #elif defined(CONFIG_TN3270_CONSOLE)
  178. SET_CONSOLE_3270;
  179. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  180. SET_CONSOLE_SCLP;
  181. #endif
  182. }
  183. } else {
  184. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  185. SET_CONSOLE_SCLP;
  186. #endif
  187. }
  188. }
  189. #ifdef CONFIG_ZFCPDUMP
  190. static void __init setup_zfcpdump(unsigned int console_devno)
  191. {
  192. static char str[41];
  193. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  194. return;
  195. if (OLDMEM_BASE)
  196. return;
  197. if (console_devno != -1)
  198. sprintf(str, " cio_ignore=all,!0.0.%04x,!0.0.%04x",
  199. ipl_info.data.fcp.dev_id.devno, console_devno);
  200. else
  201. sprintf(str, " cio_ignore=all,!0.0.%04x",
  202. ipl_info.data.fcp.dev_id.devno);
  203. strcat(boot_command_line, str);
  204. console_loglevel = 2;
  205. }
  206. #else
  207. static inline void setup_zfcpdump(unsigned int console_devno) {}
  208. #endif /* CONFIG_ZFCPDUMP */
  209. /*
  210. * Reboot, halt and power_off stubs. They just call _machine_restart,
  211. * _machine_halt or _machine_power_off.
  212. */
  213. void machine_restart(char *command)
  214. {
  215. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  216. /*
  217. * Only unblank the console if we are called in enabled
  218. * context or a bust_spinlocks cleared the way for us.
  219. */
  220. console_unblank();
  221. _machine_restart(command);
  222. }
  223. void machine_halt(void)
  224. {
  225. if (!in_interrupt() || 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_halt();
  232. }
  233. void machine_power_off(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_power_off();
  242. }
  243. /*
  244. * Dummy power off function.
  245. */
  246. void (*pm_power_off)(void) = machine_power_off;
  247. static int __init early_parse_mem(char *p)
  248. {
  249. memory_end = memparse(p, &p);
  250. memory_end_set = 1;
  251. return 0;
  252. }
  253. early_param("mem", early_parse_mem);
  254. static int __init parse_vmalloc(char *arg)
  255. {
  256. if (!arg)
  257. return -EINVAL;
  258. VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
  259. return 0;
  260. }
  261. early_param("vmalloc", parse_vmalloc);
  262. unsigned int user_mode = HOME_SPACE_MODE;
  263. EXPORT_SYMBOL_GPL(user_mode);
  264. static int set_amode_primary(void)
  265. {
  266. psw_kernel_bits = (psw_kernel_bits & ~PSW_MASK_ASC) | PSW_ASC_HOME;
  267. psw_user_bits = (psw_user_bits & ~PSW_MASK_ASC) | PSW_ASC_PRIMARY;
  268. #ifdef CONFIG_COMPAT
  269. psw32_user_bits =
  270. (psw32_user_bits & ~PSW32_MASK_ASC) | PSW32_ASC_PRIMARY;
  271. #endif
  272. if (MACHINE_HAS_MVCOS) {
  273. memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
  274. return 1;
  275. } else {
  276. memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
  277. return 0;
  278. }
  279. }
  280. /*
  281. * Switch kernel/user addressing modes?
  282. */
  283. static int __init early_parse_switch_amode(char *p)
  284. {
  285. user_mode = PRIMARY_SPACE_MODE;
  286. return 0;
  287. }
  288. early_param("switch_amode", early_parse_switch_amode);
  289. static int __init early_parse_user_mode(char *p)
  290. {
  291. if (p && strcmp(p, "primary") == 0)
  292. user_mode = PRIMARY_SPACE_MODE;
  293. else if (!p || strcmp(p, "home") == 0)
  294. user_mode = HOME_SPACE_MODE;
  295. else
  296. return 1;
  297. return 0;
  298. }
  299. early_param("user_mode", early_parse_user_mode);
  300. static void setup_addressing_mode(void)
  301. {
  302. if (user_mode == PRIMARY_SPACE_MODE) {
  303. if (set_amode_primary())
  304. pr_info("Address spaces switched, "
  305. "mvcos available\n");
  306. else
  307. pr_info("Address spaces switched, "
  308. "mvcos not available\n");
  309. }
  310. }
  311. static void __init
  312. setup_lowcore(void)
  313. {
  314. struct _lowcore *lc;
  315. /*
  316. * Setup lowcore for boot cpu
  317. */
  318. BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
  319. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  320. lc->restart_psw.mask = psw_kernel_bits;
  321. lc->restart_psw.addr =
  322. PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
  323. lc->external_new_psw.mask = psw_kernel_bits |
  324. PSW_MASK_DAT | PSW_MASK_MCHECK;
  325. lc->external_new_psw.addr =
  326. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  327. lc->svc_new_psw.mask = psw_kernel_bits |
  328. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  329. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  330. lc->program_new_psw.mask = psw_kernel_bits |
  331. PSW_MASK_DAT | PSW_MASK_MCHECK;
  332. lc->program_new_psw.addr =
  333. PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
  334. lc->mcck_new_psw.mask = psw_kernel_bits;
  335. lc->mcck_new_psw.addr =
  336. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  337. lc->io_new_psw.mask = psw_kernel_bits |
  338. PSW_MASK_DAT | PSW_MASK_MCHECK;
  339. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  340. lc->clock_comparator = -1ULL;
  341. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  342. lc->async_stack = (unsigned long)
  343. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  344. lc->panic_stack = (unsigned long)
  345. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  346. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  347. lc->thread_info = (unsigned long) &init_thread_union;
  348. lc->machine_flags = S390_lowcore.machine_flags;
  349. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  350. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  351. MAX_FACILITY_BIT/8);
  352. #ifndef CONFIG_64BIT
  353. if (MACHINE_HAS_IEEE) {
  354. lc->extended_save_area_addr = (__u32)
  355. __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
  356. /* enable extended save area */
  357. __ctl_set_bit(14, 29);
  358. }
  359. #else
  360. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  361. #endif
  362. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  363. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  364. lc->exit_timer = S390_lowcore.exit_timer;
  365. lc->user_timer = S390_lowcore.user_timer;
  366. lc->system_timer = S390_lowcore.system_timer;
  367. lc->steal_timer = S390_lowcore.steal_timer;
  368. lc->last_update_timer = S390_lowcore.last_update_timer;
  369. lc->last_update_clock = S390_lowcore.last_update_clock;
  370. lc->ftrace_func = S390_lowcore.ftrace_func;
  371. set_prefix((u32)(unsigned long) lc);
  372. lowcore_ptr[0] = lc;
  373. }
  374. static struct resource code_resource = {
  375. .name = "Kernel code",
  376. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  377. };
  378. static struct resource data_resource = {
  379. .name = "Kernel data",
  380. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  381. };
  382. static struct resource bss_resource = {
  383. .name = "Kernel bss",
  384. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  385. };
  386. static struct resource __initdata *standard_resources[] = {
  387. &code_resource,
  388. &data_resource,
  389. &bss_resource,
  390. };
  391. static void __init setup_resources(void)
  392. {
  393. struct resource *res, *std_res, *sub_res;
  394. int i, j;
  395. code_resource.start = (unsigned long) &_text;
  396. code_resource.end = (unsigned long) &_etext - 1;
  397. data_resource.start = (unsigned long) &_etext;
  398. data_resource.end = (unsigned long) &_edata - 1;
  399. bss_resource.start = (unsigned long) &__bss_start;
  400. bss_resource.end = (unsigned long) &__bss_stop - 1;
  401. for (i = 0; i < MEMORY_CHUNKS; i++) {
  402. if (!memory_chunk[i].size)
  403. continue;
  404. if (memory_chunk[i].type == CHUNK_OLDMEM ||
  405. memory_chunk[i].type == CHUNK_CRASHK)
  406. continue;
  407. res = alloc_bootmem_low(sizeof(*res));
  408. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  409. switch (memory_chunk[i].type) {
  410. case CHUNK_READ_WRITE:
  411. case CHUNK_CRASHK:
  412. res->name = "System RAM";
  413. break;
  414. case CHUNK_READ_ONLY:
  415. res->name = "System ROM";
  416. res->flags |= IORESOURCE_READONLY;
  417. break;
  418. default:
  419. res->name = "reserved";
  420. }
  421. res->start = memory_chunk[i].addr;
  422. res->end = res->start + memory_chunk[i].size - 1;
  423. request_resource(&iomem_resource, res);
  424. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  425. std_res = standard_resources[j];
  426. if (std_res->start < res->start ||
  427. std_res->start > res->end)
  428. continue;
  429. if (std_res->end > res->end) {
  430. sub_res = alloc_bootmem_low(sizeof(*sub_res));
  431. *sub_res = *std_res;
  432. sub_res->end = res->end;
  433. std_res->start = res->end + 1;
  434. request_resource(res, sub_res);
  435. } else {
  436. request_resource(res, std_res);
  437. }
  438. }
  439. }
  440. }
  441. unsigned long real_memory_size;
  442. EXPORT_SYMBOL_GPL(real_memory_size);
  443. static void __init setup_memory_end(void)
  444. {
  445. unsigned long vmax, vmalloc_size, tmp;
  446. int i;
  447. #ifdef CONFIG_ZFCPDUMP
  448. if (ipl_info.type == IPL_TYPE_FCP_DUMP && !OLDMEM_BASE) {
  449. memory_end = ZFCPDUMP_HSA_SIZE;
  450. memory_end_set = 1;
  451. }
  452. #endif
  453. real_memory_size = 0;
  454. memory_end &= PAGE_MASK;
  455. /*
  456. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  457. * extra checks that HOLES_IN_ZONE would require.
  458. */
  459. for (i = 0; i < MEMORY_CHUNKS; i++) {
  460. unsigned long start, end;
  461. struct mem_chunk *chunk;
  462. unsigned long align;
  463. chunk = &memory_chunk[i];
  464. align = 1UL << (MAX_ORDER + PAGE_SHIFT - 1);
  465. start = (chunk->addr + align - 1) & ~(align - 1);
  466. end = (chunk->addr + chunk->size) & ~(align - 1);
  467. if (start >= end)
  468. memset(chunk, 0, sizeof(*chunk));
  469. else {
  470. chunk->addr = start;
  471. chunk->size = end - start;
  472. }
  473. real_memory_size = max(real_memory_size,
  474. chunk->addr + chunk->size);
  475. }
  476. /* Choose kernel address space layout: 2, 3, or 4 levels. */
  477. #ifdef CONFIG_64BIT
  478. vmalloc_size = VMALLOC_END ?: 128UL << 30;
  479. tmp = (memory_end ?: real_memory_size) / PAGE_SIZE;
  480. tmp = tmp * (sizeof(struct page) + PAGE_SIZE) + vmalloc_size;
  481. if (tmp <= (1UL << 42))
  482. vmax = 1UL << 42; /* 3-level kernel page table */
  483. else
  484. vmax = 1UL << 53; /* 4-level kernel page table */
  485. #else
  486. vmalloc_size = VMALLOC_END ?: 96UL << 20;
  487. vmax = 1UL << 31; /* 2-level kernel page table */
  488. #endif
  489. /* vmalloc area is at the end of the kernel address space. */
  490. VMALLOC_END = vmax;
  491. VMALLOC_START = vmax - vmalloc_size;
  492. /* Split remaining virtual space between 1:1 mapping & vmemmap array */
  493. tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
  494. tmp = VMALLOC_START - tmp * sizeof(struct page);
  495. tmp &= ~((vmax >> 11) - 1); /* align to page table level */
  496. tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
  497. vmemmap = (struct page *) tmp;
  498. /* Take care that memory_end is set and <= vmemmap */
  499. memory_end = min(memory_end ?: real_memory_size, tmp);
  500. /* Fixup memory chunk array to fit into 0..memory_end */
  501. for (i = 0; i < MEMORY_CHUNKS; i++) {
  502. struct mem_chunk *chunk = &memory_chunk[i];
  503. if (chunk->addr >= memory_end) {
  504. memset(chunk, 0, sizeof(*chunk));
  505. continue;
  506. }
  507. if (chunk->addr + chunk->size > memory_end)
  508. chunk->size = memory_end - chunk->addr;
  509. }
  510. }
  511. void *restart_stack __attribute__((__section__(".data")));
  512. /*
  513. * Setup new PSW and allocate stack for PSW restart interrupt
  514. */
  515. static void __init setup_restart_psw(void)
  516. {
  517. psw_t psw;
  518. restart_stack = __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0);
  519. restart_stack += ASYNC_SIZE;
  520. /*
  521. * Setup restart PSW for absolute zero lowcore. This is necesary
  522. * if PSW restart is done on an offline CPU that has lowcore zero
  523. */
  524. psw.mask = PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA | PSW_MASK_BA;
  525. psw.addr = PSW_ADDR_AMODE | (unsigned long) psw_restart_int_handler;
  526. copy_to_absolute_zero(&S390_lowcore.restart_psw, &psw, sizeof(psw));
  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;
  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. #endif
  698. }
  699. static void __init
  700. 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
  909. setup_arch(char **cmdline_p)
  910. {
  911. /*
  912. * print what head.S has found out about the machine
  913. */
  914. #ifndef CONFIG_64BIT
  915. if (MACHINE_IS_VM)
  916. pr_info("Linux is running as a z/VM "
  917. "guest operating system in 31-bit mode\n");
  918. else if (MACHINE_IS_LPAR)
  919. pr_info("Linux is running natively in 31-bit mode\n");
  920. if (MACHINE_HAS_IEEE)
  921. pr_info("The hardware system has IEEE compatible "
  922. "floating point units\n");
  923. else
  924. pr_info("The hardware system has no IEEE compatible "
  925. "floating point units\n");
  926. #else /* CONFIG_64BIT */
  927. if (MACHINE_IS_VM)
  928. pr_info("Linux is running as a z/VM "
  929. "guest operating system in 64-bit mode\n");
  930. else if (MACHINE_IS_KVM)
  931. pr_info("Linux is running under KVM in 64-bit mode\n");
  932. else if (MACHINE_IS_LPAR)
  933. pr_info("Linux is running natively in 64-bit mode\n");
  934. #endif /* CONFIG_64BIT */
  935. /* Have one command line that is parsed and saved in /proc/cmdline */
  936. /* boot_command_line has been already set up in early.c */
  937. *cmdline_p = boot_command_line;
  938. ROOT_DEV = Root_RAM0;
  939. init_mm.start_code = PAGE_OFFSET;
  940. init_mm.end_code = (unsigned long) &_etext;
  941. init_mm.end_data = (unsigned long) &_edata;
  942. init_mm.brk = (unsigned long) &_end;
  943. if (MACHINE_HAS_MVCOS)
  944. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  945. else
  946. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  947. parse_early_param();
  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_restart_psw();
  957. setup_lowcore();
  958. cpu_init();
  959. s390_init_cpu_topology();
  960. /*
  961. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  962. */
  963. setup_hwcaps();
  964. /*
  965. * Create kernel page tables and switch to virtual addressing.
  966. */
  967. paging_init();
  968. /* Setup default console */
  969. conmode_default();
  970. set_preferred_console();
  971. /* Setup zfcpdump support */
  972. setup_zfcpdump(console_devno);
  973. }