setup.c 28 KB

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