setup.c 29 KB

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