setup.c 24 KB

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