setup.c 27 KB

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