setup.c 28 KB

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