setup.c 24 KB

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