setup.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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/sched/task.h>
  19. #include <linux/cpu.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/random.h>
  27. #include <linux/user.h>
  28. #include <linux/tty.h>
  29. #include <linux/ioport.h>
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/initrd.h>
  33. #include <linux/bootmem.h>
  34. #include <linux/root_dev.h>
  35. #include <linux/console.h>
  36. #include <linux/kernel_stat.h>
  37. #include <linux/dma-contiguous.h>
  38. #include <linux/device.h>
  39. #include <linux/notifier.h>
  40. #include <linux/pfn.h>
  41. #include <linux/ctype.h>
  42. #include <linux/reboot.h>
  43. #include <linux/topology.h>
  44. #include <linux/kexec.h>
  45. #include <linux/crash_dump.h>
  46. #include <linux/memory.h>
  47. #include <linux/compat.h>
  48. #include <asm/ipl.h>
  49. #include <asm/facility.h>
  50. #include <asm/smp.h>
  51. #include <asm/mmu_context.h>
  52. #include <asm/cpcmd.h>
  53. #include <asm/lowcore.h>
  54. #include <asm/irq.h>
  55. #include <asm/page.h>
  56. #include <asm/ptrace.h>
  57. #include <asm/sections.h>
  58. #include <asm/ebcdic.h>
  59. #include <asm/kvm_virtio.h>
  60. #include <asm/diag.h>
  61. #include <asm/os_info.h>
  62. #include <asm/sclp.h>
  63. #include <asm/sysinfo.h>
  64. #include <asm/numa.h>
  65. #include <asm/alternative.h>
  66. #include "entry.h"
  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 __read_mostly = 0;
  77. char elf_platform[ELF_PLATFORM_SIZE];
  78. unsigned long int_hwcap = 0;
  79. int __initdata memory_end_set;
  80. unsigned long __initdata memory_end;
  81. unsigned long __initdata max_physmem_end;
  82. unsigned long VMALLOC_START;
  83. EXPORT_SYMBOL(VMALLOC_START);
  84. unsigned long VMALLOC_END;
  85. EXPORT_SYMBOL(VMALLOC_END);
  86. struct page *vmemmap;
  87. EXPORT_SYMBOL(vmemmap);
  88. unsigned long MODULES_VADDR;
  89. unsigned long MODULES_END;
  90. /* An array with a pointer to the lowcore of every CPU. */
  91. struct lowcore *lowcore_ptr[NR_CPUS];
  92. EXPORT_SYMBOL(lowcore_ptr);
  93. /*
  94. * This is set up by the setup-routine at boot-time
  95. * for S390 need to find out, what we have to setup
  96. * using address 0x10400 ...
  97. */
  98. #include <asm/setup.h>
  99. /*
  100. * condev= and conmode= setup parameter.
  101. */
  102. static int __init condev_setup(char *str)
  103. {
  104. int vdev;
  105. vdev = simple_strtoul(str, &str, 0);
  106. if (vdev >= 0 && vdev < 65536) {
  107. console_devno = vdev;
  108. console_irq = -1;
  109. }
  110. return 1;
  111. }
  112. __setup("condev=", condev_setup);
  113. static void __init set_preferred_console(void)
  114. {
  115. if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  116. add_preferred_console("ttyS", 0, NULL);
  117. else if (CONSOLE_IS_3270)
  118. add_preferred_console("tty3270", 0, NULL);
  119. else if (CONSOLE_IS_VT220)
  120. add_preferred_console("ttyS", 1, NULL);
  121. else if (CONSOLE_IS_HVC)
  122. add_preferred_console("hvc", 0, NULL);
  123. }
  124. static int __init conmode_setup(char *str)
  125. {
  126. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  127. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  128. SET_CONSOLE_SCLP;
  129. #endif
  130. #if defined(CONFIG_TN3215_CONSOLE)
  131. if (strncmp(str, "3215", 5) == 0)
  132. SET_CONSOLE_3215;
  133. #endif
  134. #if defined(CONFIG_TN3270_CONSOLE)
  135. if (strncmp(str, "3270", 5) == 0)
  136. SET_CONSOLE_3270;
  137. #endif
  138. set_preferred_console();
  139. return 1;
  140. }
  141. __setup("conmode=", conmode_setup);
  142. static void __init conmode_default(void)
  143. {
  144. char query_buffer[1024];
  145. char *ptr;
  146. if (MACHINE_IS_VM) {
  147. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  148. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  149. ptr = strstr(query_buffer, "SUBCHANNEL =");
  150. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  151. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  152. ptr = strstr(query_buffer, "CONMODE");
  153. /*
  154. * Set the conmode to 3215 so that the device recognition
  155. * will set the cu_type of the console to 3215. If the
  156. * conmode is 3270 and we don't set it back then both
  157. * 3215 and the 3270 driver will try to access the console
  158. * device (3215 as console and 3270 as normal tty).
  159. */
  160. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  161. if (ptr == NULL) {
  162. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  163. SET_CONSOLE_SCLP;
  164. #endif
  165. return;
  166. }
  167. if (strncmp(ptr + 8, "3270", 4) == 0) {
  168. #if defined(CONFIG_TN3270_CONSOLE)
  169. SET_CONSOLE_3270;
  170. #elif defined(CONFIG_TN3215_CONSOLE)
  171. SET_CONSOLE_3215;
  172. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  173. SET_CONSOLE_SCLP;
  174. #endif
  175. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  176. #if defined(CONFIG_TN3215_CONSOLE)
  177. SET_CONSOLE_3215;
  178. #elif defined(CONFIG_TN3270_CONSOLE)
  179. SET_CONSOLE_3270;
  180. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  181. SET_CONSOLE_SCLP;
  182. #endif
  183. }
  184. } else if (MACHINE_IS_KVM) {
  185. if (sclp.has_vt220 && IS_ENABLED(CONFIG_SCLP_VT220_CONSOLE))
  186. SET_CONSOLE_VT220;
  187. else if (sclp.has_linemode && IS_ENABLED(CONFIG_SCLP_CONSOLE))
  188. SET_CONSOLE_SCLP;
  189. else
  190. SET_CONSOLE_HVC;
  191. } else {
  192. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  193. SET_CONSOLE_SCLP;
  194. #endif
  195. }
  196. }
  197. #ifdef CONFIG_CRASH_DUMP
  198. static void __init setup_zfcpdump(void)
  199. {
  200. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  201. return;
  202. if (OLDMEM_BASE)
  203. return;
  204. strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
  205. console_loglevel = 2;
  206. }
  207. #else
  208. static inline void setup_zfcpdump(void) {}
  209. #endif /* CONFIG_CRASH_DUMP */
  210. /*
  211. * Reboot, halt and power_off stubs. They just call _machine_restart,
  212. * _machine_halt or _machine_power_off.
  213. */
  214. void machine_restart(char *command)
  215. {
  216. if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
  217. /*
  218. * Only unblank the console if we are called in enabled
  219. * context or a bust_spinlocks cleared the way for us.
  220. */
  221. console_unblank();
  222. _machine_restart(command);
  223. }
  224. void machine_halt(void)
  225. {
  226. if (!in_interrupt() || oops_in_progress)
  227. /*
  228. * Only unblank the console if we are called in enabled
  229. * context or a bust_spinlocks cleared the way for us.
  230. */
  231. console_unblank();
  232. _machine_halt();
  233. }
  234. void machine_power_off(void)
  235. {
  236. if (!in_interrupt() || oops_in_progress)
  237. /*
  238. * Only unblank the console if we are called in enabled
  239. * context or a bust_spinlocks cleared the way for us.
  240. */
  241. console_unblank();
  242. _machine_power_off();
  243. }
  244. /*
  245. * Dummy power off function.
  246. */
  247. void (*pm_power_off)(void) = machine_power_off;
  248. EXPORT_SYMBOL_GPL(pm_power_off);
  249. static int __init early_parse_mem(char *p)
  250. {
  251. memory_end = memparse(p, &p);
  252. memory_end &= PAGE_MASK;
  253. memory_end_set = 1;
  254. return 0;
  255. }
  256. early_param("mem", early_parse_mem);
  257. static int __init parse_vmalloc(char *arg)
  258. {
  259. if (!arg)
  260. return -EINVAL;
  261. VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
  262. return 0;
  263. }
  264. early_param("vmalloc", parse_vmalloc);
  265. void *restart_stack __section(.data);
  266. static void __init setup_lowcore(void)
  267. {
  268. struct lowcore *lc;
  269. /*
  270. * Setup lowcore for boot cpu
  271. */
  272. BUILD_BUG_ON(sizeof(struct lowcore) != LC_PAGES * PAGE_SIZE);
  273. lc = memblock_virt_alloc_low(sizeof(*lc), sizeof(*lc));
  274. lc->restart_psw.mask = PSW_KERNEL_BITS;
  275. lc->restart_psw.addr = (unsigned long) restart_int_handler;
  276. lc->external_new_psw.mask = PSW_KERNEL_BITS |
  277. PSW_MASK_DAT | PSW_MASK_MCHECK;
  278. lc->external_new_psw.addr = (unsigned long) ext_int_handler;
  279. lc->svc_new_psw.mask = PSW_KERNEL_BITS |
  280. PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
  281. lc->svc_new_psw.addr = (unsigned long) system_call;
  282. lc->program_new_psw.mask = PSW_KERNEL_BITS |
  283. PSW_MASK_DAT | PSW_MASK_MCHECK;
  284. lc->program_new_psw.addr = (unsigned long) pgm_check_handler;
  285. lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
  286. lc->mcck_new_psw.addr = (unsigned long) mcck_int_handler;
  287. lc->io_new_psw.mask = PSW_KERNEL_BITS |
  288. PSW_MASK_DAT | PSW_MASK_MCHECK;
  289. lc->io_new_psw.addr = (unsigned long) io_int_handler;
  290. lc->clock_comparator = clock_comparator_max;
  291. lc->kernel_stack = ((unsigned long) &init_thread_union)
  292. + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  293. lc->async_stack = (unsigned long)
  294. memblock_virt_alloc(ASYNC_SIZE, ASYNC_SIZE)
  295. + ASYNC_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  296. lc->panic_stack = (unsigned long)
  297. memblock_virt_alloc(PAGE_SIZE, PAGE_SIZE)
  298. + PAGE_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
  299. lc->current_task = (unsigned long)&init_task;
  300. lc->lpp = LPP_MAGIC;
  301. lc->machine_flags = S390_lowcore.machine_flags;
  302. lc->preempt_count = S390_lowcore.preempt_count;
  303. lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
  304. memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
  305. MAX_FACILITY_BIT/8);
  306. if (MACHINE_HAS_VX || MACHINE_HAS_GS) {
  307. unsigned long bits, size;
  308. bits = MACHINE_HAS_GS ? 11 : 10;
  309. size = 1UL << bits;
  310. lc->mcesad = (__u64) memblock_virt_alloc(size, size);
  311. if (MACHINE_HAS_GS)
  312. lc->mcesad |= bits;
  313. }
  314. vdso_alloc_boot_cpu(lc);
  315. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  316. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  317. lc->exit_timer = S390_lowcore.exit_timer;
  318. lc->user_timer = S390_lowcore.user_timer;
  319. lc->system_timer = S390_lowcore.system_timer;
  320. lc->steal_timer = S390_lowcore.steal_timer;
  321. lc->last_update_timer = S390_lowcore.last_update_timer;
  322. lc->last_update_clock = S390_lowcore.last_update_clock;
  323. restart_stack = memblock_virt_alloc(ASYNC_SIZE, ASYNC_SIZE);
  324. restart_stack += ASYNC_SIZE;
  325. /*
  326. * Set up PSW restart to call ipl.c:do_restart(). Copy the relevant
  327. * restart data to the absolute zero lowcore. This is necessary if
  328. * PSW restart is done on an offline CPU that has lowcore zero.
  329. */
  330. lc->restart_stack = (unsigned long) restart_stack;
  331. lc->restart_fn = (unsigned long) do_restart;
  332. lc->restart_data = 0;
  333. lc->restart_source = -1UL;
  334. /* Setup absolute zero lowcore */
  335. mem_assign_absolute(S390_lowcore.restart_stack, lc->restart_stack);
  336. mem_assign_absolute(S390_lowcore.restart_fn, lc->restart_fn);
  337. mem_assign_absolute(S390_lowcore.restart_data, lc->restart_data);
  338. mem_assign_absolute(S390_lowcore.restart_source, lc->restart_source);
  339. mem_assign_absolute(S390_lowcore.restart_psw, lc->restart_psw);
  340. #ifdef CONFIG_SMP
  341. lc->spinlock_lockval = arch_spin_lockval(0);
  342. lc->spinlock_index = 0;
  343. arch_spin_lock_setup(0);
  344. #endif
  345. set_prefix((u32)(unsigned long) lc);
  346. lowcore_ptr[0] = lc;
  347. }
  348. static struct resource code_resource = {
  349. .name = "Kernel code",
  350. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  351. };
  352. static struct resource data_resource = {
  353. .name = "Kernel data",
  354. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  355. };
  356. static struct resource bss_resource = {
  357. .name = "Kernel bss",
  358. .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
  359. };
  360. static struct resource __initdata *standard_resources[] = {
  361. &code_resource,
  362. &data_resource,
  363. &bss_resource,
  364. };
  365. static void __init setup_resources(void)
  366. {
  367. struct resource *res, *std_res, *sub_res;
  368. struct memblock_region *reg;
  369. int j;
  370. code_resource.start = (unsigned long) &_text;
  371. code_resource.end = (unsigned long) &_etext - 1;
  372. data_resource.start = (unsigned long) &_etext;
  373. data_resource.end = (unsigned long) &_edata - 1;
  374. bss_resource.start = (unsigned long) &__bss_start;
  375. bss_resource.end = (unsigned long) &__bss_stop - 1;
  376. for_each_memblock(memory, reg) {
  377. res = memblock_virt_alloc(sizeof(*res), 8);
  378. res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM;
  379. res->name = "System RAM";
  380. res->start = reg->base;
  381. res->end = reg->base + reg->size - 1;
  382. request_resource(&iomem_resource, res);
  383. for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
  384. std_res = standard_resources[j];
  385. if (std_res->start < res->start ||
  386. std_res->start > res->end)
  387. continue;
  388. if (std_res->end > res->end) {
  389. sub_res = memblock_virt_alloc(sizeof(*sub_res), 8);
  390. *sub_res = *std_res;
  391. sub_res->end = res->end;
  392. std_res->start = res->end + 1;
  393. request_resource(res, sub_res);
  394. } else {
  395. request_resource(res, std_res);
  396. }
  397. }
  398. }
  399. #ifdef CONFIG_CRASH_DUMP
  400. /*
  401. * Re-add removed crash kernel memory as reserved memory. This makes
  402. * sure it will be mapped with the identity mapping and struct pages
  403. * will be created, so it can be resized later on.
  404. * However add it later since the crash kernel resource should not be
  405. * part of the System RAM resource.
  406. */
  407. if (crashk_res.end) {
  408. memblock_add_node(crashk_res.start, resource_size(&crashk_res), 0);
  409. memblock_reserve(crashk_res.start, resource_size(&crashk_res));
  410. insert_resource(&iomem_resource, &crashk_res);
  411. }
  412. #endif
  413. }
  414. static void __init setup_memory_end(void)
  415. {
  416. unsigned long vmax, vmalloc_size, tmp;
  417. /* Choose kernel address space layout: 2, 3, or 4 levels. */
  418. vmalloc_size = VMALLOC_END ?: (128UL << 30) - MODULES_LEN;
  419. tmp = (memory_end ?: max_physmem_end) / PAGE_SIZE;
  420. tmp = tmp * (sizeof(struct page) + PAGE_SIZE);
  421. if (tmp + vmalloc_size + MODULES_LEN <= _REGION2_SIZE)
  422. vmax = _REGION2_SIZE; /* 3-level kernel page table */
  423. else
  424. vmax = _REGION1_SIZE; /* 4-level kernel page table */
  425. /* module area is at the end of the kernel address space. */
  426. MODULES_END = vmax;
  427. MODULES_VADDR = MODULES_END - MODULES_LEN;
  428. VMALLOC_END = MODULES_VADDR;
  429. VMALLOC_START = vmax - vmalloc_size;
  430. /* Split remaining virtual space between 1:1 mapping & vmemmap array */
  431. tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
  432. /* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
  433. tmp = SECTION_ALIGN_UP(tmp);
  434. tmp = VMALLOC_START - tmp * sizeof(struct page);
  435. tmp &= ~((vmax >> 11) - 1); /* align to page table level */
  436. tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
  437. vmemmap = (struct page *) tmp;
  438. /* Take care that memory_end is set and <= vmemmap */
  439. memory_end = min(memory_end ?: max_physmem_end, tmp);
  440. max_pfn = max_low_pfn = PFN_DOWN(memory_end);
  441. memblock_remove(memory_end, ULONG_MAX);
  442. pr_notice("The maximum memory size is %luMB\n", memory_end >> 20);
  443. }
  444. #ifdef CONFIG_CRASH_DUMP
  445. /*
  446. * When kdump is enabled, we have to ensure that no memory from
  447. * the area [0 - crashkernel memory size] and
  448. * [crashk_res.start - crashk_res.end] is set offline.
  449. */
  450. static int kdump_mem_notifier(struct notifier_block *nb,
  451. unsigned long action, void *data)
  452. {
  453. struct memory_notify *arg = data;
  454. if (action != MEM_GOING_OFFLINE)
  455. return NOTIFY_OK;
  456. if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
  457. return NOTIFY_BAD;
  458. if (arg->start_pfn > PFN_DOWN(crashk_res.end))
  459. return NOTIFY_OK;
  460. if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
  461. return NOTIFY_OK;
  462. return NOTIFY_BAD;
  463. }
  464. static struct notifier_block kdump_mem_nb = {
  465. .notifier_call = kdump_mem_notifier,
  466. };
  467. #endif
  468. /*
  469. * Make sure that the area behind memory_end is protected
  470. */
  471. static void reserve_memory_end(void)
  472. {
  473. #ifdef CONFIG_CRASH_DUMP
  474. if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
  475. !OLDMEM_BASE && sclp.hsa_size) {
  476. memory_end = sclp.hsa_size;
  477. memory_end &= PAGE_MASK;
  478. memory_end_set = 1;
  479. }
  480. #endif
  481. if (!memory_end_set)
  482. return;
  483. memblock_reserve(memory_end, ULONG_MAX);
  484. }
  485. /*
  486. * Make sure that oldmem, where the dump is stored, is protected
  487. */
  488. static void reserve_oldmem(void)
  489. {
  490. #ifdef CONFIG_CRASH_DUMP
  491. if (OLDMEM_BASE)
  492. /* Forget all memory above the running kdump system */
  493. memblock_reserve(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  494. #endif
  495. }
  496. /*
  497. * Make sure that oldmem, where the dump is stored, is protected
  498. */
  499. static void remove_oldmem(void)
  500. {
  501. #ifdef CONFIG_CRASH_DUMP
  502. if (OLDMEM_BASE)
  503. /* Forget all memory above the running kdump system */
  504. memblock_remove(OLDMEM_SIZE, (phys_addr_t)ULONG_MAX);
  505. #endif
  506. }
  507. /*
  508. * Reserve memory for kdump kernel to be loaded with kexec
  509. */
  510. static void __init reserve_crashkernel(void)
  511. {
  512. #ifdef CONFIG_CRASH_DUMP
  513. unsigned long long crash_base, crash_size;
  514. phys_addr_t low, high;
  515. int rc;
  516. rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
  517. &crash_base);
  518. crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
  519. crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
  520. if (rc || crash_size == 0)
  521. return;
  522. if (memblock.memory.regions[0].size < crash_size) {
  523. pr_info("crashkernel reservation failed: %s\n",
  524. "first memory chunk must be at least crashkernel size");
  525. return;
  526. }
  527. low = crash_base ?: OLDMEM_BASE;
  528. high = low + crash_size;
  529. if (low >= OLDMEM_BASE && high <= OLDMEM_BASE + OLDMEM_SIZE) {
  530. /* The crashkernel fits into OLDMEM, reuse OLDMEM */
  531. crash_base = low;
  532. } else {
  533. /* Find suitable area in free memory */
  534. low = max_t(unsigned long, crash_size, sclp.hsa_size);
  535. high = crash_base ? crash_base + crash_size : ULONG_MAX;
  536. if (crash_base && crash_base < low) {
  537. pr_info("crashkernel reservation failed: %s\n",
  538. "crash_base too low");
  539. return;
  540. }
  541. low = crash_base ?: low;
  542. crash_base = memblock_find_in_range(low, high, crash_size,
  543. KEXEC_CRASH_MEM_ALIGN);
  544. }
  545. if (!crash_base) {
  546. pr_info("crashkernel reservation failed: %s\n",
  547. "no suitable area found");
  548. return;
  549. }
  550. if (register_memory_notifier(&kdump_mem_nb))
  551. return;
  552. if (!OLDMEM_BASE && MACHINE_IS_VM)
  553. diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
  554. crashk_res.start = crash_base;
  555. crashk_res.end = crash_base + crash_size - 1;
  556. memblock_remove(crash_base, crash_size);
  557. pr_info("Reserving %lluMB of memory at %lluMB "
  558. "for crashkernel (System RAM: %luMB)\n",
  559. crash_size >> 20, crash_base >> 20,
  560. (unsigned long)memblock.memory.total_size >> 20);
  561. os_info_crashkernel_add(crash_base, crash_size);
  562. #endif
  563. }
  564. /*
  565. * Reserve the initrd from being used by memblock
  566. */
  567. static void __init reserve_initrd(void)
  568. {
  569. #ifdef CONFIG_BLK_DEV_INITRD
  570. if (!INITRD_START || !INITRD_SIZE)
  571. return;
  572. initrd_start = INITRD_START;
  573. initrd_end = initrd_start + INITRD_SIZE;
  574. memblock_reserve(INITRD_START, INITRD_SIZE);
  575. #endif
  576. }
  577. /*
  578. * Check for initrd being in usable memory
  579. */
  580. static void __init check_initrd(void)
  581. {
  582. #ifdef CONFIG_BLK_DEV_INITRD
  583. if (INITRD_START && INITRD_SIZE &&
  584. !memblock_is_region_memory(INITRD_START, INITRD_SIZE)) {
  585. pr_err("The initial RAM disk does not fit into the memory\n");
  586. memblock_free(INITRD_START, INITRD_SIZE);
  587. initrd_start = initrd_end = 0;
  588. }
  589. #endif
  590. }
  591. /*
  592. * Reserve memory used for lowcore/command line/kernel image.
  593. */
  594. static void __init reserve_kernel(void)
  595. {
  596. unsigned long start_pfn = PFN_UP(__pa(&_end));
  597. #ifdef CONFIG_DMA_API_DEBUG
  598. /*
  599. * DMA_API_DEBUG code stumbles over addresses from the
  600. * range [_ehead, _stext]. Mark the memory as reserved
  601. * so it is not used for CONFIG_DMA_API_DEBUG=y.
  602. */
  603. memblock_reserve(0, PFN_PHYS(start_pfn));
  604. #else
  605. memblock_reserve(0, (unsigned long)_ehead);
  606. memblock_reserve((unsigned long)_stext, PFN_PHYS(start_pfn)
  607. - (unsigned long)_stext);
  608. #endif
  609. }
  610. static void __init setup_memory(void)
  611. {
  612. struct memblock_region *reg;
  613. /*
  614. * Init storage key for present memory
  615. */
  616. for_each_memblock(memory, reg) {
  617. storage_key_init_range(reg->base, reg->base + reg->size);
  618. }
  619. psw_set_key(PAGE_DEFAULT_KEY);
  620. /* Only cosmetics */
  621. memblock_enforce_memory_limit(memblock_end_of_DRAM());
  622. }
  623. /*
  624. * Setup hardware capabilities.
  625. */
  626. static int __init setup_hwcaps(void)
  627. {
  628. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  629. struct cpuid cpu_id;
  630. int i;
  631. /*
  632. * The store facility list bits numbers as found in the principles
  633. * of operation are numbered with bit 1UL<<31 as number 0 to
  634. * bit 1UL<<0 as number 31.
  635. * Bit 0: instructions named N3, "backported" to esa-mode
  636. * Bit 2: z/Architecture mode is active
  637. * Bit 7: the store-facility-list-extended facility is installed
  638. * Bit 17: the message-security assist is installed
  639. * Bit 19: the long-displacement facility is installed
  640. * Bit 21: the extended-immediate facility is installed
  641. * Bit 22: extended-translation facility 3 is installed
  642. * Bit 30: extended-translation facility 3 enhancement facility
  643. * These get translated to:
  644. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  645. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  646. * HWCAP_S390_LDISP bit 4, HWCAP_S390_EIMM bit 5 and
  647. * HWCAP_S390_ETF3EH bit 8 (22 && 30).
  648. */
  649. for (i = 0; i < 6; i++)
  650. if (test_facility(stfl_bits[i]))
  651. elf_hwcap |= 1UL << i;
  652. if (test_facility(22) && test_facility(30))
  653. elf_hwcap |= HWCAP_S390_ETF3EH;
  654. /*
  655. * Check for additional facilities with store-facility-list-extended.
  656. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  657. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  658. * as stored by stfl, bits 32-xxx contain additional facilities.
  659. * How many facility words are stored depends on the number of
  660. * doublewords passed to the instruction. The additional facilities
  661. * are:
  662. * Bit 42: decimal floating point facility is installed
  663. * Bit 44: perform floating point operation facility is installed
  664. * translated to:
  665. * HWCAP_S390_DFP bit 6 (42 && 44).
  666. */
  667. if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
  668. elf_hwcap |= HWCAP_S390_DFP;
  669. /*
  670. * Huge page support HWCAP_S390_HPAGE is bit 7.
  671. */
  672. if (MACHINE_HAS_EDAT1)
  673. elf_hwcap |= HWCAP_S390_HPAGE;
  674. /*
  675. * 64-bit register support for 31-bit processes
  676. * HWCAP_S390_HIGH_GPRS is bit 9.
  677. */
  678. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  679. /*
  680. * Transactional execution support HWCAP_S390_TE is bit 10.
  681. */
  682. if (test_facility(50) && test_facility(73))
  683. elf_hwcap |= HWCAP_S390_TE;
  684. /*
  685. * Vector extension HWCAP_S390_VXRS is bit 11. The Vector extension
  686. * can be disabled with the "novx" parameter. Use MACHINE_HAS_VX
  687. * instead of facility bit 129.
  688. */
  689. if (MACHINE_HAS_VX) {
  690. elf_hwcap |= HWCAP_S390_VXRS;
  691. if (test_facility(134))
  692. elf_hwcap |= HWCAP_S390_VXRS_EXT;
  693. if (test_facility(135))
  694. elf_hwcap |= HWCAP_S390_VXRS_BCD;
  695. }
  696. /*
  697. * Guarded storage support HWCAP_S390_GS is bit 12.
  698. */
  699. if (MACHINE_HAS_GS)
  700. elf_hwcap |= HWCAP_S390_GS;
  701. get_cpu_id(&cpu_id);
  702. add_device_randomness(&cpu_id, sizeof(cpu_id));
  703. switch (cpu_id.machine) {
  704. case 0x2064:
  705. case 0x2066:
  706. default: /* Use "z900" as default for 64 bit kernels. */
  707. strcpy(elf_platform, "z900");
  708. break;
  709. case 0x2084:
  710. case 0x2086:
  711. strcpy(elf_platform, "z990");
  712. break;
  713. case 0x2094:
  714. case 0x2096:
  715. strcpy(elf_platform, "z9-109");
  716. break;
  717. case 0x2097:
  718. case 0x2098:
  719. strcpy(elf_platform, "z10");
  720. break;
  721. case 0x2817:
  722. case 0x2818:
  723. strcpy(elf_platform, "z196");
  724. break;
  725. case 0x2827:
  726. case 0x2828:
  727. strcpy(elf_platform, "zEC12");
  728. break;
  729. case 0x2964:
  730. case 0x2965:
  731. strcpy(elf_platform, "z13");
  732. break;
  733. case 0x3906:
  734. strcpy(elf_platform, "z14");
  735. break;
  736. }
  737. /*
  738. * Virtualization support HWCAP_INT_SIE is bit 0.
  739. */
  740. if (sclp.has_sief2)
  741. int_hwcap |= HWCAP_INT_SIE;
  742. return 0;
  743. }
  744. arch_initcall(setup_hwcaps);
  745. /*
  746. * Add system information as device randomness
  747. */
  748. static void __init setup_randomness(void)
  749. {
  750. struct sysinfo_3_2_2 *vmms;
  751. vmms = (struct sysinfo_3_2_2 *) memblock_alloc(PAGE_SIZE, PAGE_SIZE);
  752. if (stsi(vmms, 3, 2, 2) == 0 && vmms->count)
  753. add_device_randomness(&vmms->vm, sizeof(vmms->vm[0]) * vmms->count);
  754. memblock_free((unsigned long) vmms, PAGE_SIZE);
  755. }
  756. /*
  757. * Find the correct size for the task_struct. This depends on
  758. * the size of the struct fpu at the end of the thread_struct
  759. * which is embedded in the task_struct.
  760. */
  761. static void __init setup_task_size(void)
  762. {
  763. int task_size = sizeof(struct task_struct);
  764. if (!MACHINE_HAS_VX) {
  765. task_size -= sizeof(__vector128) * __NUM_VXRS;
  766. task_size += sizeof(freg_t) * __NUM_FPRS;
  767. }
  768. arch_task_struct_size = task_size;
  769. }
  770. /*
  771. * Setup function called from init/main.c just after the banner
  772. * was printed.
  773. */
  774. void __init setup_arch(char **cmdline_p)
  775. {
  776. /*
  777. * print what head.S has found out about the machine
  778. */
  779. if (MACHINE_IS_VM)
  780. pr_info("Linux is running as a z/VM "
  781. "guest operating system in 64-bit mode\n");
  782. else if (MACHINE_IS_KVM)
  783. pr_info("Linux is running under KVM in 64-bit mode\n");
  784. else if (MACHINE_IS_LPAR)
  785. pr_info("Linux is running natively in 64-bit mode\n");
  786. /* Have one command line that is parsed and saved in /proc/cmdline */
  787. /* boot_command_line has been already set up in early.c */
  788. *cmdline_p = boot_command_line;
  789. ROOT_DEV = Root_RAM0;
  790. /* Is init_mm really needed? */
  791. init_mm.start_code = PAGE_OFFSET;
  792. init_mm.end_code = (unsigned long) &_etext;
  793. init_mm.end_data = (unsigned long) &_edata;
  794. init_mm.brk = (unsigned long) &_end;
  795. parse_early_param();
  796. #ifdef CONFIG_CRASH_DUMP
  797. /* Deactivate elfcorehdr= kernel parameter */
  798. elfcorehdr_addr = ELFCORE_ADDR_MAX;
  799. #endif
  800. os_info_init();
  801. setup_ipl();
  802. setup_task_size();
  803. /* Do some memory reservations *before* memory is added to memblock */
  804. reserve_memory_end();
  805. reserve_oldmem();
  806. reserve_kernel();
  807. reserve_initrd();
  808. memblock_allow_resize();
  809. /* Get information about *all* installed memory */
  810. detect_memory_memblock();
  811. remove_oldmem();
  812. /*
  813. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  814. * extra checks that HOLES_IN_ZONE would require.
  815. *
  816. * Is this still required?
  817. */
  818. memblock_trim_memory(1UL << (MAX_ORDER - 1 + PAGE_SHIFT));
  819. setup_memory_end();
  820. setup_memory();
  821. dma_contiguous_reserve(memory_end);
  822. vmcp_cma_reserve();
  823. check_initrd();
  824. reserve_crashkernel();
  825. #ifdef CONFIG_CRASH_DUMP
  826. /*
  827. * Be aware that smp_save_dump_cpus() triggers a system reset.
  828. * Therefore CPU and device initialization should be done afterwards.
  829. */
  830. smp_save_dump_cpus();
  831. #endif
  832. setup_resources();
  833. setup_lowcore();
  834. smp_fill_possible_mask();
  835. cpu_detect_mhz_feature();
  836. cpu_init();
  837. numa_setup();
  838. smp_detect_cpus();
  839. topology_init_early();
  840. /*
  841. * Create kernel page tables and switch to virtual addressing.
  842. */
  843. paging_init();
  844. /* Setup default console */
  845. conmode_default();
  846. set_preferred_console();
  847. apply_alternative_instructions();
  848. /* Setup zfcpdump support */
  849. setup_zfcpdump();
  850. /* Add system specific data to the random pool */
  851. setup_randomness();
  852. }