setup.c 29 KB

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