setup.c 29 KB

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