setup.c 23 KB

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