setup.c 23 KB

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