setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /*
  2. * arch/s390/kernel/setup.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  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 <asm/ipl.h>
  43. #include <asm/uaccess.h>
  44. #include <asm/system.h>
  45. #include <asm/smp.h>
  46. #include <asm/mmu_context.h>
  47. #include <asm/cpcmd.h>
  48. #include <asm/lowcore.h>
  49. #include <asm/irq.h>
  50. #include <asm/page.h>
  51. #include <asm/ptrace.h>
  52. #include <asm/sections.h>
  53. #include <asm/ebcdic.h>
  54. #include <asm/compat.h>
  55. #include <asm/kvm_virtio.h>
  56. long psw_kernel_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY |
  57. PSW_MASK_MCHECK | PSW_DEFAULT_KEY);
  58. long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  59. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  60. PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
  61. /*
  62. * User copy operations.
  63. */
  64. struct uaccess_ops uaccess;
  65. EXPORT_SYMBOL(uaccess);
  66. /*
  67. * Machine setup..
  68. */
  69. unsigned int console_mode = 0;
  70. EXPORT_SYMBOL(console_mode);
  71. unsigned int console_devno = -1;
  72. EXPORT_SYMBOL(console_devno);
  73. unsigned int console_irq = -1;
  74. EXPORT_SYMBOL(console_irq);
  75. unsigned long elf_hwcap = 0;
  76. char elf_platform[ELF_PLATFORM_SIZE];
  77. struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
  78. int __initdata memory_end_set;
  79. unsigned long __initdata memory_end;
  80. /* An array with a pointer to the lowcore of every CPU. */
  81. struct _lowcore *lowcore_ptr[NR_CPUS];
  82. EXPORT_SYMBOL(lowcore_ptr);
  83. /*
  84. * This is set up by the setup-routine at boot-time
  85. * for S390 need to find out, what we have to setup
  86. * using address 0x10400 ...
  87. */
  88. #include <asm/setup.h>
  89. static struct resource code_resource = {
  90. .name = "Kernel code",
  91. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  92. };
  93. static struct resource data_resource = {
  94. .name = "Kernel data",
  95. .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
  96. };
  97. /*
  98. * cpu_init() initializes state that is per-CPU.
  99. */
  100. void __cpuinit cpu_init(void)
  101. {
  102. /*
  103. * Store processor id in lowcore (used e.g. in timer_interrupt)
  104. */
  105. get_cpu_id(&S390_lowcore.cpu_id);
  106. atomic_inc(&init_mm.mm_count);
  107. current->active_mm = &init_mm;
  108. BUG_ON(current->mm);
  109. enter_lazy_tlb(&init_mm, current);
  110. }
  111. /*
  112. * condev= and conmode= setup parameter.
  113. */
  114. static int __init condev_setup(char *str)
  115. {
  116. int vdev;
  117. vdev = simple_strtoul(str, &str, 0);
  118. if (vdev >= 0 && vdev < 65536) {
  119. console_devno = vdev;
  120. console_irq = -1;
  121. }
  122. return 1;
  123. }
  124. __setup("condev=", condev_setup);
  125. static void __init set_preferred_console(void)
  126. {
  127. if (MACHINE_IS_KVM)
  128. add_preferred_console("hvc", 0, NULL);
  129. else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
  130. add_preferred_console("ttyS", 0, NULL);
  131. else if (CONSOLE_IS_3270)
  132. add_preferred_console("tty3270", 0, NULL);
  133. }
  134. static int __init conmode_setup(char *str)
  135. {
  136. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  137. if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
  138. SET_CONSOLE_SCLP;
  139. #endif
  140. #if defined(CONFIG_TN3215_CONSOLE)
  141. if (strncmp(str, "3215", 5) == 0)
  142. SET_CONSOLE_3215;
  143. #endif
  144. #if defined(CONFIG_TN3270_CONSOLE)
  145. if (strncmp(str, "3270", 5) == 0)
  146. SET_CONSOLE_3270;
  147. #endif
  148. set_preferred_console();
  149. return 1;
  150. }
  151. __setup("conmode=", conmode_setup);
  152. static void __init conmode_default(void)
  153. {
  154. char query_buffer[1024];
  155. char *ptr;
  156. if (MACHINE_IS_VM) {
  157. cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
  158. console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
  159. ptr = strstr(query_buffer, "SUBCHANNEL =");
  160. console_irq = simple_strtoul(ptr + 13, NULL, 16);
  161. cpcmd("QUERY TERM", query_buffer, 1024, NULL);
  162. ptr = strstr(query_buffer, "CONMODE");
  163. /*
  164. * Set the conmode to 3215 so that the device recognition
  165. * will set the cu_type of the console to 3215. If the
  166. * conmode is 3270 and we don't set it back then both
  167. * 3215 and the 3270 driver will try to access the console
  168. * device (3215 as console and 3270 as normal tty).
  169. */
  170. cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
  171. if (ptr == NULL) {
  172. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  173. SET_CONSOLE_SCLP;
  174. #endif
  175. return;
  176. }
  177. if (strncmp(ptr + 8, "3270", 4) == 0) {
  178. #if defined(CONFIG_TN3270_CONSOLE)
  179. SET_CONSOLE_3270;
  180. #elif defined(CONFIG_TN3215_CONSOLE)
  181. SET_CONSOLE_3215;
  182. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  183. SET_CONSOLE_SCLP;
  184. #endif
  185. } else if (strncmp(ptr + 8, "3215", 4) == 0) {
  186. #if defined(CONFIG_TN3215_CONSOLE)
  187. SET_CONSOLE_3215;
  188. #elif defined(CONFIG_TN3270_CONSOLE)
  189. SET_CONSOLE_3270;
  190. #elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  191. SET_CONSOLE_SCLP;
  192. #endif
  193. }
  194. } else {
  195. #if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
  196. SET_CONSOLE_SCLP;
  197. #endif
  198. }
  199. }
  200. #ifdef CONFIG_ZFCPDUMP
  201. static void __init setup_zfcpdump(unsigned int console_devno)
  202. {
  203. static char str[41];
  204. if (ipl_info.type != IPL_TYPE_FCP_DUMP)
  205. return;
  206. if (console_devno != -1)
  207. sprintf(str, " cio_ignore=all,!0.0.%04x,!0.0.%04x",
  208. ipl_info.data.fcp.dev_id.devno, console_devno);
  209. else
  210. sprintf(str, " cio_ignore=all,!0.0.%04x",
  211. ipl_info.data.fcp.dev_id.devno);
  212. strcat(boot_command_line, str);
  213. console_loglevel = 2;
  214. }
  215. #else
  216. static inline void setup_zfcpdump(unsigned int console_devno) {}
  217. #endif /* CONFIG_ZFCPDUMP */
  218. /*
  219. * Reboot, halt and power_off stubs. They just call _machine_restart,
  220. * _machine_halt or _machine_power_off.
  221. */
  222. void machine_restart(char *command)
  223. {
  224. if ((!in_interrupt() && !in_atomic()) || 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_restart(command);
  231. }
  232. void machine_halt(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_halt();
  241. }
  242. void machine_power_off(void)
  243. {
  244. if (!in_interrupt() || oops_in_progress)
  245. /*
  246. * Only unblank the console if we are called in enabled
  247. * context or a bust_spinlocks cleared the way for us.
  248. */
  249. console_unblank();
  250. _machine_power_off();
  251. }
  252. /*
  253. * Dummy power off function.
  254. */
  255. void (*pm_power_off)(void) = machine_power_off;
  256. static int __init early_parse_mem(char *p)
  257. {
  258. memory_end = memparse(p, &p);
  259. memory_end_set = 1;
  260. return 0;
  261. }
  262. early_param("mem", early_parse_mem);
  263. unsigned int user_mode = HOME_SPACE_MODE;
  264. EXPORT_SYMBOL_GPL(user_mode);
  265. static int set_amode_and_uaccess(unsigned long user_amode,
  266. unsigned long user32_amode)
  267. {
  268. psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
  269. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  270. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  271. #ifdef CONFIG_COMPAT
  272. psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
  273. PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
  274. PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
  275. psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
  276. PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
  277. PSW32_MASK_PSTATE;
  278. #endif
  279. psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
  280. PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
  281. if (MACHINE_HAS_MVCOS) {
  282. memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
  283. return 1;
  284. } else {
  285. memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
  286. return 0;
  287. }
  288. }
  289. /*
  290. * Switch kernel/user addressing modes?
  291. */
  292. static int __init early_parse_switch_amode(char *p)
  293. {
  294. if (user_mode != SECONDARY_SPACE_MODE)
  295. user_mode = PRIMARY_SPACE_MODE;
  296. return 0;
  297. }
  298. early_param("switch_amode", early_parse_switch_amode);
  299. static int __init early_parse_user_mode(char *p)
  300. {
  301. if (p && strcmp(p, "primary") == 0)
  302. user_mode = PRIMARY_SPACE_MODE;
  303. #ifdef CONFIG_S390_EXEC_PROTECT
  304. else if (p && strcmp(p, "secondary") == 0)
  305. user_mode = SECONDARY_SPACE_MODE;
  306. #endif
  307. else if (!p || strcmp(p, "home") == 0)
  308. user_mode = HOME_SPACE_MODE;
  309. else
  310. return 1;
  311. return 0;
  312. }
  313. early_param("user_mode", early_parse_user_mode);
  314. #ifdef CONFIG_S390_EXEC_PROTECT
  315. /*
  316. * Enable execute protection?
  317. */
  318. static int __init early_parse_noexec(char *p)
  319. {
  320. if (!strncmp(p, "off", 3))
  321. return 0;
  322. user_mode = SECONDARY_SPACE_MODE;
  323. return 0;
  324. }
  325. early_param("noexec", early_parse_noexec);
  326. #endif /* CONFIG_S390_EXEC_PROTECT */
  327. static void setup_addressing_mode(void)
  328. {
  329. if (user_mode == SECONDARY_SPACE_MODE) {
  330. if (set_amode_and_uaccess(PSW_ASC_SECONDARY,
  331. PSW32_ASC_SECONDARY))
  332. pr_info("Execute protection active, "
  333. "mvcos available\n");
  334. else
  335. pr_info("Execute protection active, "
  336. "mvcos not available\n");
  337. } else if (user_mode == PRIMARY_SPACE_MODE) {
  338. if (set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY))
  339. pr_info("Address spaces switched, "
  340. "mvcos available\n");
  341. else
  342. pr_info("Address spaces switched, "
  343. "mvcos not available\n");
  344. }
  345. #ifdef CONFIG_TRACE_IRQFLAGS
  346. sysc_restore_trace_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  347. io_restore_trace_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
  348. #endif
  349. }
  350. static void __init
  351. setup_lowcore(void)
  352. {
  353. struct _lowcore *lc;
  354. /*
  355. * Setup lowcore for boot cpu
  356. */
  357. BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
  358. lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
  359. lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
  360. lc->restart_psw.addr =
  361. PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
  362. if (user_mode != HOME_SPACE_MODE)
  363. lc->restart_psw.mask |= PSW_ASC_HOME;
  364. lc->external_new_psw.mask = psw_kernel_bits;
  365. lc->external_new_psw.addr =
  366. PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
  367. lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
  368. lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
  369. lc->program_new_psw.mask = psw_kernel_bits;
  370. lc->program_new_psw.addr =
  371. PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
  372. lc->mcck_new_psw.mask =
  373. psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
  374. lc->mcck_new_psw.addr =
  375. PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
  376. lc->io_new_psw.mask = psw_kernel_bits;
  377. lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
  378. lc->clock_comparator = -1ULL;
  379. lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
  380. lc->async_stack = (unsigned long)
  381. __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
  382. lc->panic_stack = (unsigned long)
  383. __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
  384. lc->current_task = (unsigned long) init_thread_union.thread_info.task;
  385. lc->thread_info = (unsigned long) &init_thread_union;
  386. lc->machine_flags = S390_lowcore.machine_flags;
  387. #ifndef CONFIG_64BIT
  388. if (MACHINE_HAS_IEEE) {
  389. lc->extended_save_area_addr = (__u32)
  390. __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
  391. /* enable extended save area */
  392. __ctl_set_bit(14, 29);
  393. }
  394. #else
  395. lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
  396. #endif
  397. lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
  398. lc->async_enter_timer = S390_lowcore.async_enter_timer;
  399. lc->exit_timer = S390_lowcore.exit_timer;
  400. lc->user_timer = S390_lowcore.user_timer;
  401. lc->system_timer = S390_lowcore.system_timer;
  402. lc->steal_timer = S390_lowcore.steal_timer;
  403. lc->last_update_timer = S390_lowcore.last_update_timer;
  404. lc->last_update_clock = S390_lowcore.last_update_clock;
  405. lc->ftrace_func = S390_lowcore.ftrace_func;
  406. set_prefix((u32)(unsigned long) lc);
  407. lowcore_ptr[0] = lc;
  408. }
  409. static void __init
  410. setup_resources(void)
  411. {
  412. struct resource *res, *sub_res;
  413. int i;
  414. code_resource.start = (unsigned long) &_text;
  415. code_resource.end = (unsigned long) &_etext - 1;
  416. data_resource.start = (unsigned long) &_etext;
  417. data_resource.end = (unsigned long) &_edata - 1;
  418. for (i = 0; i < MEMORY_CHUNKS; i++) {
  419. if (!memory_chunk[i].size)
  420. continue;
  421. res = alloc_bootmem_low(sizeof(struct resource));
  422. res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
  423. switch (memory_chunk[i].type) {
  424. case CHUNK_READ_WRITE:
  425. res->name = "System RAM";
  426. break;
  427. case CHUNK_READ_ONLY:
  428. res->name = "System ROM";
  429. res->flags |= IORESOURCE_READONLY;
  430. break;
  431. default:
  432. res->name = "reserved";
  433. }
  434. res->start = memory_chunk[i].addr;
  435. res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
  436. request_resource(&iomem_resource, res);
  437. if (code_resource.start >= res->start &&
  438. code_resource.start <= res->end &&
  439. code_resource.end > res->end) {
  440. sub_res = alloc_bootmem_low(sizeof(struct resource));
  441. memcpy(sub_res, &code_resource,
  442. sizeof(struct resource));
  443. sub_res->end = res->end;
  444. code_resource.start = res->end + 1;
  445. request_resource(res, sub_res);
  446. }
  447. if (code_resource.start >= res->start &&
  448. code_resource.start <= res->end &&
  449. code_resource.end <= res->end)
  450. request_resource(res, &code_resource);
  451. if (data_resource.start >= res->start &&
  452. data_resource.start <= res->end &&
  453. data_resource.end > res->end) {
  454. sub_res = alloc_bootmem_low(sizeof(struct resource));
  455. memcpy(sub_res, &data_resource,
  456. sizeof(struct resource));
  457. sub_res->end = res->end;
  458. data_resource.start = res->end + 1;
  459. request_resource(res, sub_res);
  460. }
  461. if (data_resource.start >= res->start &&
  462. data_resource.start <= res->end &&
  463. data_resource.end <= res->end)
  464. request_resource(res, &data_resource);
  465. }
  466. }
  467. unsigned long real_memory_size;
  468. EXPORT_SYMBOL_GPL(real_memory_size);
  469. static void __init setup_memory_end(void)
  470. {
  471. unsigned long memory_size;
  472. unsigned long max_mem;
  473. int i;
  474. #ifdef CONFIG_ZFCPDUMP
  475. if (ipl_info.type == IPL_TYPE_FCP_DUMP) {
  476. memory_end = ZFCPDUMP_HSA_SIZE;
  477. memory_end_set = 1;
  478. }
  479. #endif
  480. memory_size = 0;
  481. memory_end &= PAGE_MASK;
  482. max_mem = memory_end ? min(VMEM_MAX_PHYS, memory_end) : VMEM_MAX_PHYS;
  483. memory_end = min(max_mem, memory_end);
  484. /*
  485. * Make sure all chunks are MAX_ORDER aligned so we don't need the
  486. * extra checks that HOLES_IN_ZONE would require.
  487. */
  488. for (i = 0; i < MEMORY_CHUNKS; i++) {
  489. unsigned long start, end;
  490. struct mem_chunk *chunk;
  491. unsigned long align;
  492. chunk = &memory_chunk[i];
  493. align = 1UL << (MAX_ORDER + PAGE_SHIFT - 1);
  494. start = (chunk->addr + align - 1) & ~(align - 1);
  495. end = (chunk->addr + chunk->size) & ~(align - 1);
  496. if (start >= end)
  497. memset(chunk, 0, sizeof(*chunk));
  498. else {
  499. chunk->addr = start;
  500. chunk->size = end - start;
  501. }
  502. }
  503. for (i = 0; i < MEMORY_CHUNKS; i++) {
  504. struct mem_chunk *chunk = &memory_chunk[i];
  505. real_memory_size = max(real_memory_size,
  506. chunk->addr + chunk->size);
  507. if (chunk->addr >= max_mem) {
  508. memset(chunk, 0, sizeof(*chunk));
  509. continue;
  510. }
  511. if (chunk->addr + chunk->size > max_mem)
  512. chunk->size = max_mem - chunk->addr;
  513. memory_size = max(memory_size, chunk->addr + chunk->size);
  514. }
  515. if (!memory_end)
  516. memory_end = memory_size;
  517. }
  518. static void __init
  519. setup_memory(void)
  520. {
  521. unsigned long bootmap_size;
  522. unsigned long start_pfn, end_pfn;
  523. int i;
  524. /*
  525. * partially used pages are not usable - thus
  526. * we are rounding upwards:
  527. */
  528. start_pfn = PFN_UP(__pa(&_end));
  529. end_pfn = max_pfn = PFN_DOWN(memory_end);
  530. #ifdef CONFIG_BLK_DEV_INITRD
  531. /*
  532. * Move the initrd in case the bitmap of the bootmem allocater
  533. * would overwrite it.
  534. */
  535. if (INITRD_START && INITRD_SIZE) {
  536. unsigned long bmap_size;
  537. unsigned long start;
  538. bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
  539. bmap_size = PFN_PHYS(bmap_size);
  540. if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
  541. start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
  542. if (start + INITRD_SIZE > memory_end) {
  543. pr_err("initrd extends beyond end of "
  544. "memory (0x%08lx > 0x%08lx) "
  545. "disabling initrd\n",
  546. start + INITRD_SIZE, memory_end);
  547. INITRD_START = INITRD_SIZE = 0;
  548. } else {
  549. pr_info("Moving initrd (0x%08lx -> "
  550. "0x%08lx, size: %ld)\n",
  551. INITRD_START, start, INITRD_SIZE);
  552. memmove((void *) start, (void *) INITRD_START,
  553. INITRD_SIZE);
  554. INITRD_START = start;
  555. }
  556. }
  557. }
  558. #endif
  559. /*
  560. * Initialize the boot-time allocator
  561. */
  562. bootmap_size = init_bootmem(start_pfn, end_pfn);
  563. /*
  564. * Register RAM areas with the bootmem allocator.
  565. */
  566. for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
  567. unsigned long start_chunk, end_chunk, pfn;
  568. if (memory_chunk[i].type != CHUNK_READ_WRITE)
  569. continue;
  570. start_chunk = PFN_DOWN(memory_chunk[i].addr);
  571. end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
  572. end_chunk = min(end_chunk, end_pfn);
  573. if (start_chunk >= end_chunk)
  574. continue;
  575. add_active_range(0, start_chunk, end_chunk);
  576. pfn = max(start_chunk, start_pfn);
  577. for (; pfn < end_chunk; pfn++)
  578. page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
  579. }
  580. psw_set_key(PAGE_DEFAULT_KEY);
  581. free_bootmem_with_active_regions(0, max_pfn);
  582. /*
  583. * Reserve memory used for lowcore/command line/kernel image.
  584. */
  585. reserve_bootmem(0, (unsigned long)_ehead, BOOTMEM_DEFAULT);
  586. reserve_bootmem((unsigned long)_stext,
  587. PFN_PHYS(start_pfn) - (unsigned long)_stext,
  588. BOOTMEM_DEFAULT);
  589. /*
  590. * Reserve the bootmem bitmap itself as well. We do this in two
  591. * steps (first step was init_bootmem()) because this catches
  592. * the (very unlikely) case of us accidentally initializing the
  593. * bootmem allocator with an invalid RAM area.
  594. */
  595. reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size,
  596. BOOTMEM_DEFAULT);
  597. #ifdef CONFIG_BLK_DEV_INITRD
  598. if (INITRD_START && INITRD_SIZE) {
  599. if (INITRD_START + INITRD_SIZE <= memory_end) {
  600. reserve_bootmem(INITRD_START, INITRD_SIZE,
  601. BOOTMEM_DEFAULT);
  602. initrd_start = INITRD_START;
  603. initrd_end = initrd_start + INITRD_SIZE;
  604. } else {
  605. pr_err("initrd extends beyond end of "
  606. "memory (0x%08lx > 0x%08lx) "
  607. "disabling initrd\n",
  608. initrd_start + INITRD_SIZE, memory_end);
  609. initrd_start = initrd_end = 0;
  610. }
  611. }
  612. #endif
  613. }
  614. /*
  615. * Setup hardware capabilities.
  616. */
  617. static void __init setup_hwcaps(void)
  618. {
  619. static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
  620. unsigned long long facility_list_extended;
  621. unsigned int facility_list;
  622. int i;
  623. facility_list = stfl();
  624. /*
  625. * The store facility list bits numbers as found in the principles
  626. * of operation are numbered with bit 1UL<<31 as number 0 to
  627. * bit 1UL<<0 as number 31.
  628. * Bit 0: instructions named N3, "backported" to esa-mode
  629. * Bit 2: z/Architecture mode is active
  630. * Bit 7: the store-facility-list-extended facility is installed
  631. * Bit 17: the message-security assist is installed
  632. * Bit 19: the long-displacement facility is installed
  633. * Bit 21: the extended-immediate facility is installed
  634. * Bit 22: extended-translation facility 3 is installed
  635. * Bit 30: extended-translation facility 3 enhancement facility
  636. * These get translated to:
  637. * HWCAP_S390_ESAN3 bit 0, HWCAP_S390_ZARCH bit 1,
  638. * HWCAP_S390_STFLE bit 2, HWCAP_S390_MSA bit 3,
  639. * HWCAP_S390_LDISP bit 4, HWCAP_S390_EIMM bit 5 and
  640. * HWCAP_S390_ETF3EH bit 8 (22 && 30).
  641. */
  642. for (i = 0; i < 6; i++)
  643. if (facility_list & (1UL << (31 - stfl_bits[i])))
  644. elf_hwcap |= 1UL << i;
  645. if ((facility_list & (1UL << (31 - 22)))
  646. && (facility_list & (1UL << (31 - 30))))
  647. elf_hwcap |= HWCAP_S390_ETF3EH;
  648. /*
  649. * Check for additional facilities with store-facility-list-extended.
  650. * stfle stores doublewords (8 byte) with bit 1ULL<<63 as bit 0
  651. * and 1ULL<<0 as bit 63. Bits 0-31 contain the same information
  652. * as stored by stfl, bits 32-xxx contain additional facilities.
  653. * How many facility words are stored depends on the number of
  654. * doublewords passed to the instruction. The additional facilites
  655. * are:
  656. * Bit 42: decimal floating point facility is installed
  657. * Bit 44: perform floating point operation facility is installed
  658. * translated to:
  659. * HWCAP_S390_DFP bit 6 (42 && 44).
  660. */
  661. if ((elf_hwcap & (1UL << 2)) &&
  662. __stfle(&facility_list_extended, 1) > 0) {
  663. if ((facility_list_extended & (1ULL << (63 - 42)))
  664. && (facility_list_extended & (1ULL << (63 - 44))))
  665. elf_hwcap |= HWCAP_S390_DFP;
  666. }
  667. /*
  668. * Huge page support HWCAP_S390_HPAGE is bit 7.
  669. */
  670. if (MACHINE_HAS_HPAGE)
  671. elf_hwcap |= HWCAP_S390_HPAGE;
  672. /*
  673. * 64-bit register support for 31-bit processes
  674. * HWCAP_S390_HIGH_GPRS is bit 9.
  675. */
  676. elf_hwcap |= HWCAP_S390_HIGH_GPRS;
  677. switch (S390_lowcore.cpu_id.machine) {
  678. case 0x9672:
  679. #if !defined(CONFIG_64BIT)
  680. default: /* Use "g5" as default for 31 bit kernels. */
  681. #endif
  682. strcpy(elf_platform, "g5");
  683. break;
  684. case 0x2064:
  685. case 0x2066:
  686. #if defined(CONFIG_64BIT)
  687. default: /* Use "z900" as default for 64 bit kernels. */
  688. #endif
  689. strcpy(elf_platform, "z900");
  690. break;
  691. case 0x2084:
  692. case 0x2086:
  693. strcpy(elf_platform, "z990");
  694. break;
  695. case 0x2094:
  696. case 0x2096:
  697. strcpy(elf_platform, "z9-109");
  698. break;
  699. case 0x2097:
  700. case 0x2098:
  701. strcpy(elf_platform, "z10");
  702. break;
  703. }
  704. }
  705. /*
  706. * Setup function called from init/main.c just after the banner
  707. * was printed.
  708. */
  709. void __init
  710. setup_arch(char **cmdline_p)
  711. {
  712. /*
  713. * print what head.S has found out about the machine
  714. */
  715. #ifndef CONFIG_64BIT
  716. if (MACHINE_IS_VM)
  717. pr_info("Linux is running as a z/VM "
  718. "guest operating system in 31-bit mode\n");
  719. else if (MACHINE_IS_LPAR)
  720. pr_info("Linux is running natively in 31-bit mode\n");
  721. if (MACHINE_HAS_IEEE)
  722. pr_info("The hardware system has IEEE compatible "
  723. "floating point units\n");
  724. else
  725. pr_info("The hardware system has no IEEE compatible "
  726. "floating point units\n");
  727. #else /* CONFIG_64BIT */
  728. if (MACHINE_IS_VM)
  729. pr_info("Linux is running as a z/VM "
  730. "guest operating system in 64-bit mode\n");
  731. else if (MACHINE_IS_KVM)
  732. pr_info("Linux is running under KVM in 64-bit mode\n");
  733. else if (MACHINE_IS_LPAR)
  734. pr_info("Linux is running natively in 64-bit mode\n");
  735. #endif /* CONFIG_64BIT */
  736. /* Have one command line that is parsed and saved in /proc/cmdline */
  737. /* boot_command_line has been already set up in early.c */
  738. *cmdline_p = boot_command_line;
  739. ROOT_DEV = Root_RAM0;
  740. init_mm.start_code = PAGE_OFFSET;
  741. init_mm.end_code = (unsigned long) &_etext;
  742. init_mm.end_data = (unsigned long) &_edata;
  743. init_mm.brk = (unsigned long) &_end;
  744. if (MACHINE_HAS_MVCOS)
  745. memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
  746. else
  747. memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
  748. parse_early_param();
  749. setup_ipl();
  750. setup_memory_end();
  751. setup_addressing_mode();
  752. setup_memory();
  753. setup_resources();
  754. setup_lowcore();
  755. cpu_init();
  756. s390_init_cpu_topology();
  757. /*
  758. * Setup capabilities (ELF_HWCAP & ELF_PLATFORM).
  759. */
  760. setup_hwcaps();
  761. /*
  762. * Create kernel page tables and switch to virtual addressing.
  763. */
  764. paging_init();
  765. /* Setup default console */
  766. conmode_default();
  767. set_preferred_console();
  768. /* Setup zfcpdump support */
  769. setup_zfcpdump(console_devno);
  770. }