setup.c 22 KB

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