setup.c 22 KB

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