setup.c 29 KB

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