setup.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. /*
  2. * Architecture-specific setup.
  3. *
  4. * Copyright (C) 1998-2001, 2003-2004 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. * Stephane Eranian <eranian@hpl.hp.com>
  7. * Copyright (C) 2000, 2004 Intel Corp
  8. * Rohit Seth <rohit.seth@intel.com>
  9. * Suresh Siddha <suresh.b.siddha@intel.com>
  10. * Gordon Jin <gordon.jin@intel.com>
  11. * Copyright (C) 1999 VA Linux Systems
  12. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  13. *
  14. * 12/26/04 S.Siddha, G.Jin, R.Seth
  15. * Add multi-threading and multi-core detection
  16. * 11/12/01 D.Mosberger Convert get_cpuinfo() to seq_file based show_cpuinfo().
  17. * 04/04/00 D.Mosberger renamed cpu_initialized to cpu_online_map
  18. * 03/31/00 R.Seth cpu_initialized and current->processor fixes
  19. * 02/04/00 D.Mosberger some more get_cpuinfo fixes...
  20. * 02/01/00 R.Seth fixed get_cpuinfo for SMP
  21. * 01/07/99 S.Eranian added the support for command line argument
  22. * 06/24/99 W.Drummond added boot_cpu_data.
  23. * 05/28/05 Z. Menyhart Dynamic stride size for "flush_icache_range()"
  24. */
  25. #include <linux/config.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/acpi.h>
  29. #include <linux/bootmem.h>
  30. #include <linux/console.h>
  31. #include <linux/delay.h>
  32. #include <linux/kernel.h>
  33. #include <linux/reboot.h>
  34. #include <linux/sched.h>
  35. #include <linux/seq_file.h>
  36. #include <linux/string.h>
  37. #include <linux/threads.h>
  38. #include <linux/tty.h>
  39. #include <linux/serial.h>
  40. #include <linux/serial_core.h>
  41. #include <linux/efi.h>
  42. #include <linux/initrd.h>
  43. #include <linux/platform.h>
  44. #include <linux/pm.h>
  45. #include <linux/cpufreq.h>
  46. #include <asm/ia32.h>
  47. #include <asm/machvec.h>
  48. #include <asm/mca.h>
  49. #include <asm/meminit.h>
  50. #include <asm/page.h>
  51. #include <asm/patch.h>
  52. #include <asm/pgtable.h>
  53. #include <asm/processor.h>
  54. #include <asm/sal.h>
  55. #include <asm/sections.h>
  56. #include <asm/serial.h>
  57. #include <asm/setup.h>
  58. #include <asm/smp.h>
  59. #include <asm/system.h>
  60. #include <asm/unistd.h>
  61. #include <asm/system.h>
  62. #if defined(CONFIG_SMP) && (IA64_CPU_SIZE > PAGE_SIZE)
  63. # error "struct cpuinfo_ia64 too big!"
  64. #endif
  65. #ifdef CONFIG_SMP
  66. unsigned long __per_cpu_offset[NR_CPUS];
  67. EXPORT_SYMBOL(__per_cpu_offset);
  68. #endif
  69. DEFINE_PER_CPU(struct cpuinfo_ia64, cpu_info);
  70. DEFINE_PER_CPU(unsigned long, local_per_cpu_offset);
  71. DEFINE_PER_CPU(unsigned long, ia64_phys_stacked_size_p8);
  72. unsigned long ia64_cycles_per_usec;
  73. struct ia64_boot_param *ia64_boot_param;
  74. struct screen_info screen_info;
  75. unsigned long vga_console_iobase;
  76. unsigned long vga_console_membase;
  77. static struct resource data_resource = {
  78. .name = "Kernel data",
  79. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  80. };
  81. static struct resource code_resource = {
  82. .name = "Kernel code",
  83. .flags = IORESOURCE_BUSY | IORESOURCE_MEM
  84. };
  85. extern void efi_initialize_iomem_resources(struct resource *,
  86. struct resource *);
  87. extern char _text[], _end[], _etext[];
  88. unsigned long ia64_max_cacheline_size;
  89. int dma_get_cache_alignment(void)
  90. {
  91. return ia64_max_cacheline_size;
  92. }
  93. EXPORT_SYMBOL(dma_get_cache_alignment);
  94. unsigned long ia64_iobase; /* virtual address for I/O accesses */
  95. EXPORT_SYMBOL(ia64_iobase);
  96. struct io_space io_space[MAX_IO_SPACES];
  97. EXPORT_SYMBOL(io_space);
  98. unsigned int num_io_spaces;
  99. /*
  100. * "flush_icache_range()" needs to know what processor dependent stride size to use
  101. * when it makes i-cache(s) coherent with d-caches.
  102. */
  103. #define I_CACHE_STRIDE_SHIFT 5 /* Safest way to go: 32 bytes by 32 bytes */
  104. unsigned long ia64_i_cache_stride_shift = ~0;
  105. /*
  106. * The merge_mask variable needs to be set to (max(iommu_page_size(iommu)) - 1). This
  107. * mask specifies a mask of address bits that must be 0 in order for two buffers to be
  108. * mergeable by the I/O MMU (i.e., the end address of the first buffer and the start
  109. * address of the second buffer must be aligned to (merge_mask+1) in order to be
  110. * mergeable). By default, we assume there is no I/O MMU which can merge physically
  111. * discontiguous buffers, so we set the merge_mask to ~0UL, which corresponds to a iommu
  112. * page-size of 2^64.
  113. */
  114. unsigned long ia64_max_iommu_merge_mask = ~0UL;
  115. EXPORT_SYMBOL(ia64_max_iommu_merge_mask);
  116. /*
  117. * We use a special marker for the end of memory and it uses the extra (+1) slot
  118. */
  119. struct rsvd_region rsvd_region[IA64_MAX_RSVD_REGIONS + 1];
  120. int num_rsvd_regions;
  121. /*
  122. * Filter incoming memory segments based on the primitive map created from the boot
  123. * parameters. Segments contained in the map are removed from the memory ranges. A
  124. * caller-specified function is called with the memory ranges that remain after filtering.
  125. * This routine does not assume the incoming segments are sorted.
  126. */
  127. int
  128. filter_rsvd_memory (unsigned long start, unsigned long end, void *arg)
  129. {
  130. unsigned long range_start, range_end, prev_start;
  131. void (*func)(unsigned long, unsigned long, int);
  132. int i;
  133. #if IGNORE_PFN0
  134. if (start == PAGE_OFFSET) {
  135. printk(KERN_WARNING "warning: skipping physical page 0\n");
  136. start += PAGE_SIZE;
  137. if (start >= end) return 0;
  138. }
  139. #endif
  140. /*
  141. * lowest possible address(walker uses virtual)
  142. */
  143. prev_start = PAGE_OFFSET;
  144. func = arg;
  145. for (i = 0; i < num_rsvd_regions; ++i) {
  146. range_start = max(start, prev_start);
  147. range_end = min(end, rsvd_region[i].start);
  148. if (range_start < range_end)
  149. call_pernode_memory(__pa(range_start), range_end - range_start, func);
  150. /* nothing more available in this segment */
  151. if (range_end == end) return 0;
  152. prev_start = rsvd_region[i].end;
  153. }
  154. /* end of memory marker allows full processing inside loop body */
  155. return 0;
  156. }
  157. static void
  158. sort_regions (struct rsvd_region *rsvd_region, int max)
  159. {
  160. int j;
  161. /* simple bubble sorting */
  162. while (max--) {
  163. for (j = 0; j < max; ++j) {
  164. if (rsvd_region[j].start > rsvd_region[j+1].start) {
  165. struct rsvd_region tmp;
  166. tmp = rsvd_region[j];
  167. rsvd_region[j] = rsvd_region[j + 1];
  168. rsvd_region[j + 1] = tmp;
  169. }
  170. }
  171. }
  172. }
  173. /*
  174. * Request address space for all standard resources
  175. */
  176. static int __init register_memory(void)
  177. {
  178. code_resource.start = ia64_tpa(_text);
  179. code_resource.end = ia64_tpa(_etext) - 1;
  180. data_resource.start = ia64_tpa(_etext);
  181. data_resource.end = ia64_tpa(_end) - 1;
  182. efi_initialize_iomem_resources(&code_resource, &data_resource);
  183. return 0;
  184. }
  185. __initcall(register_memory);
  186. /**
  187. * reserve_memory - setup reserved memory areas
  188. *
  189. * Setup the reserved memory areas set aside for the boot parameters,
  190. * initrd, etc. There are currently %IA64_MAX_RSVD_REGIONS defined,
  191. * see include/asm-ia64/meminit.h if you need to define more.
  192. */
  193. void
  194. reserve_memory (void)
  195. {
  196. int n = 0;
  197. /*
  198. * none of the entries in this table overlap
  199. */
  200. rsvd_region[n].start = (unsigned long) ia64_boot_param;
  201. rsvd_region[n].end = rsvd_region[n].start + sizeof(*ia64_boot_param);
  202. n++;
  203. rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->efi_memmap);
  204. rsvd_region[n].end = rsvd_region[n].start + ia64_boot_param->efi_memmap_size;
  205. n++;
  206. rsvd_region[n].start = (unsigned long) __va(ia64_boot_param->command_line);
  207. rsvd_region[n].end = (rsvd_region[n].start
  208. + strlen(__va(ia64_boot_param->command_line)) + 1);
  209. n++;
  210. rsvd_region[n].start = (unsigned long) ia64_imva((void *)KERNEL_START);
  211. rsvd_region[n].end = (unsigned long) ia64_imva(_end);
  212. n++;
  213. #ifdef CONFIG_BLK_DEV_INITRD
  214. if (ia64_boot_param->initrd_start) {
  215. rsvd_region[n].start = (unsigned long)__va(ia64_boot_param->initrd_start);
  216. rsvd_region[n].end = rsvd_region[n].start + ia64_boot_param->initrd_size;
  217. n++;
  218. }
  219. #endif
  220. efi_memmap_init(&rsvd_region[n].start, &rsvd_region[n].end);
  221. n++;
  222. /* end of memory marker */
  223. rsvd_region[n].start = ~0UL;
  224. rsvd_region[n].end = ~0UL;
  225. n++;
  226. num_rsvd_regions = n;
  227. sort_regions(rsvd_region, num_rsvd_regions);
  228. }
  229. /**
  230. * find_initrd - get initrd parameters from the boot parameter structure
  231. *
  232. * Grab the initrd start and end from the boot parameter struct given us by
  233. * the boot loader.
  234. */
  235. void
  236. find_initrd (void)
  237. {
  238. #ifdef CONFIG_BLK_DEV_INITRD
  239. if (ia64_boot_param->initrd_start) {
  240. initrd_start = (unsigned long)__va(ia64_boot_param->initrd_start);
  241. initrd_end = initrd_start+ia64_boot_param->initrd_size;
  242. printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
  243. initrd_start, ia64_boot_param->initrd_size);
  244. }
  245. #endif
  246. }
  247. static void __init
  248. io_port_init (void)
  249. {
  250. unsigned long phys_iobase;
  251. /*
  252. * Set `iobase' based on the EFI memory map or, failing that, the
  253. * value firmware left in ar.k0.
  254. *
  255. * Note that in ia32 mode, IN/OUT instructions use ar.k0 to compute
  256. * the port's virtual address, so ia32_load_state() loads it with a
  257. * user virtual address. But in ia64 mode, glibc uses the
  258. * *physical* address in ar.k0 to mmap the appropriate area from
  259. * /dev/mem, and the inX()/outX() interfaces use MMIO. In both
  260. * cases, user-mode can only use the legacy 0-64K I/O port space.
  261. *
  262. * ar.k0 is not involved in kernel I/O port accesses, which can use
  263. * any of the I/O port spaces and are done via MMIO using the
  264. * virtual mmio_base from the appropriate io_space[].
  265. */
  266. phys_iobase = efi_get_iobase();
  267. if (!phys_iobase) {
  268. phys_iobase = ia64_get_kr(IA64_KR_IO_BASE);
  269. printk(KERN_INFO "No I/O port range found in EFI memory map, "
  270. "falling back to AR.KR0 (0x%lx)\n", phys_iobase);
  271. }
  272. ia64_iobase = (unsigned long) ioremap(phys_iobase, 0);
  273. ia64_set_kr(IA64_KR_IO_BASE, __pa(ia64_iobase));
  274. /* setup legacy IO port space */
  275. io_space[0].mmio_base = ia64_iobase;
  276. io_space[0].sparse = 1;
  277. num_io_spaces = 1;
  278. }
  279. /**
  280. * early_console_setup - setup debugging console
  281. *
  282. * Consoles started here require little enough setup that we can start using
  283. * them very early in the boot process, either right after the machine
  284. * vector initialization, or even before if the drivers can detect their hw.
  285. *
  286. * Returns non-zero if a console couldn't be setup.
  287. */
  288. static inline int __init
  289. early_console_setup (char *cmdline)
  290. {
  291. int earlycons = 0;
  292. #ifdef CONFIG_SERIAL_SGI_L1_CONSOLE
  293. {
  294. extern int sn_serial_console_early_setup(void);
  295. if (!sn_serial_console_early_setup())
  296. earlycons++;
  297. }
  298. #endif
  299. #ifdef CONFIG_EFI_PCDP
  300. if (!efi_setup_pcdp_console(cmdline))
  301. earlycons++;
  302. #endif
  303. #ifdef CONFIG_SERIAL_8250_CONSOLE
  304. if (!early_serial_console_init(cmdline))
  305. earlycons++;
  306. #endif
  307. return (earlycons) ? 0 : -1;
  308. }
  309. static inline void
  310. mark_bsp_online (void)
  311. {
  312. #ifdef CONFIG_SMP
  313. /* If we register an early console, allow CPU 0 to printk */
  314. cpu_set(smp_processor_id(), cpu_online_map);
  315. #endif
  316. }
  317. #ifdef CONFIG_SMP
  318. static void
  319. check_for_logical_procs (void)
  320. {
  321. pal_logical_to_physical_t info;
  322. s64 status;
  323. status = ia64_pal_logical_to_phys(0, &info);
  324. if (status == -1) {
  325. printk(KERN_INFO "No logical to physical processor mapping "
  326. "available\n");
  327. return;
  328. }
  329. if (status) {
  330. printk(KERN_ERR "ia64_pal_logical_to_phys failed with %ld\n",
  331. status);
  332. return;
  333. }
  334. /*
  335. * Total number of siblings that BSP has. Though not all of them
  336. * may have booted successfully. The correct number of siblings
  337. * booted is in info.overview_num_log.
  338. */
  339. smp_num_siblings = info.overview_tpc;
  340. smp_num_cpucores = info.overview_cpp;
  341. }
  342. #endif
  343. void __init
  344. setup_arch (char **cmdline_p)
  345. {
  346. unw_init();
  347. ia64_patch_vtop((u64) __start___vtop_patchlist, (u64) __end___vtop_patchlist);
  348. *cmdline_p = __va(ia64_boot_param->command_line);
  349. strlcpy(saved_command_line, *cmdline_p, COMMAND_LINE_SIZE);
  350. efi_init();
  351. io_port_init();
  352. #ifdef CONFIG_IA64_GENERIC
  353. {
  354. const char *mvec_name = strstr (*cmdline_p, "machvec=");
  355. char str[64];
  356. if (mvec_name) {
  357. const char *end;
  358. size_t len;
  359. mvec_name += 8;
  360. end = strchr (mvec_name, ' ');
  361. if (end)
  362. len = end - mvec_name;
  363. else
  364. len = strlen (mvec_name);
  365. len = min(len, sizeof (str) - 1);
  366. strncpy (str, mvec_name, len);
  367. str[len] = '\0';
  368. mvec_name = str;
  369. } else
  370. mvec_name = acpi_get_sysname();
  371. machvec_init(mvec_name);
  372. }
  373. #endif
  374. if (early_console_setup(*cmdline_p) == 0)
  375. mark_bsp_online();
  376. #ifdef CONFIG_ACPI
  377. /* Initialize the ACPI boot-time table parser */
  378. acpi_table_init();
  379. # ifdef CONFIG_ACPI_NUMA
  380. acpi_numa_init();
  381. # endif
  382. #else
  383. # ifdef CONFIG_SMP
  384. smp_build_cpu_map(); /* happens, e.g., with the Ski simulator */
  385. # endif
  386. #endif /* CONFIG_APCI_BOOT */
  387. find_memory();
  388. /* process SAL system table: */
  389. ia64_sal_init(efi.sal_systab);
  390. #ifdef CONFIG_SMP
  391. cpu_physical_id(0) = hard_smp_processor_id();
  392. cpu_set(0, cpu_sibling_map[0]);
  393. cpu_set(0, cpu_core_map[0]);
  394. check_for_logical_procs();
  395. if (smp_num_cpucores > 1)
  396. printk(KERN_INFO
  397. "cpu package is Multi-Core capable: number of cores=%d\n",
  398. smp_num_cpucores);
  399. if (smp_num_siblings > 1)
  400. printk(KERN_INFO
  401. "cpu package is Multi-Threading capable: number of siblings=%d\n",
  402. smp_num_siblings);
  403. #endif
  404. cpu_init(); /* initialize the bootstrap CPU */
  405. mmu_context_init(); /* initialize context_id bitmap */
  406. #ifdef CONFIG_ACPI
  407. acpi_boot_init();
  408. #endif
  409. #ifdef CONFIG_VT
  410. if (!conswitchp) {
  411. # if defined(CONFIG_DUMMY_CONSOLE)
  412. conswitchp = &dummy_con;
  413. # endif
  414. # if defined(CONFIG_VGA_CONSOLE)
  415. /*
  416. * Non-legacy systems may route legacy VGA MMIO range to system
  417. * memory. vga_con probes the MMIO hole, so memory looks like
  418. * a VGA device to it. The EFI memory map can tell us if it's
  419. * memory so we can avoid this problem.
  420. */
  421. if (efi_mem_type(0xA0000) != EFI_CONVENTIONAL_MEMORY)
  422. conswitchp = &vga_con;
  423. # endif
  424. }
  425. #endif
  426. /* enable IA-64 Machine Check Abort Handling unless disabled */
  427. if (!strstr(saved_command_line, "nomca"))
  428. ia64_mca_init();
  429. platform_setup(cmdline_p);
  430. paging_init();
  431. }
  432. /*
  433. * Display cpu info for all cpu's.
  434. */
  435. static int
  436. show_cpuinfo (struct seq_file *m, void *v)
  437. {
  438. #ifdef CONFIG_SMP
  439. # define lpj c->loops_per_jiffy
  440. # define cpunum c->cpu
  441. #else
  442. # define lpj loops_per_jiffy
  443. # define cpunum 0
  444. #endif
  445. static struct {
  446. unsigned long mask;
  447. const char *feature_name;
  448. } feature_bits[] = {
  449. { 1UL << 0, "branchlong" },
  450. { 1UL << 1, "spontaneous deferral"},
  451. { 1UL << 2, "16-byte atomic ops" }
  452. };
  453. char family[32], features[128], *cp, sep;
  454. struct cpuinfo_ia64 *c = v;
  455. unsigned long mask;
  456. unsigned long proc_freq;
  457. int i;
  458. mask = c->features;
  459. switch (c->family) {
  460. case 0x07: memcpy(family, "Itanium", 8); break;
  461. case 0x1f: memcpy(family, "Itanium 2", 10); break;
  462. default: sprintf(family, "%u", c->family); break;
  463. }
  464. /* build the feature string: */
  465. memcpy(features, " standard", 10);
  466. cp = features;
  467. sep = 0;
  468. for (i = 0; i < (int) ARRAY_SIZE(feature_bits); ++i) {
  469. if (mask & feature_bits[i].mask) {
  470. if (sep)
  471. *cp++ = sep;
  472. sep = ',';
  473. *cp++ = ' ';
  474. strcpy(cp, feature_bits[i].feature_name);
  475. cp += strlen(feature_bits[i].feature_name);
  476. mask &= ~feature_bits[i].mask;
  477. }
  478. }
  479. if (mask) {
  480. /* print unknown features as a hex value: */
  481. if (sep)
  482. *cp++ = sep;
  483. sprintf(cp, " 0x%lx", mask);
  484. }
  485. proc_freq = cpufreq_quick_get(cpunum);
  486. if (!proc_freq)
  487. proc_freq = c->proc_freq / 1000;
  488. seq_printf(m,
  489. "processor : %d\n"
  490. "vendor : %s\n"
  491. "arch : IA-64\n"
  492. "family : %s\n"
  493. "model : %u\n"
  494. "revision : %u\n"
  495. "archrev : %u\n"
  496. "features :%s\n" /* don't change this---it _is_ right! */
  497. "cpu number : %lu\n"
  498. "cpu regs : %u\n"
  499. "cpu MHz : %lu.%06lu\n"
  500. "itc MHz : %lu.%06lu\n"
  501. "BogoMIPS : %lu.%02lu\n",
  502. cpunum, c->vendor, family, c->model, c->revision, c->archrev,
  503. features, c->ppn, c->number,
  504. proc_freq / 1000, proc_freq % 1000,
  505. c->itc_freq / 1000000, c->itc_freq % 1000000,
  506. lpj*HZ/500000, (lpj*HZ/5000) % 100);
  507. #ifdef CONFIG_SMP
  508. seq_printf(m, "siblings : %u\n", cpus_weight(cpu_core_map[cpunum]));
  509. if (c->threads_per_core > 1 || c->cores_per_socket > 1)
  510. seq_printf(m,
  511. "physical id: %u\n"
  512. "core id : %u\n"
  513. "thread id : %u\n",
  514. c->socket_id, c->core_id, c->thread_id);
  515. #endif
  516. seq_printf(m,"\n");
  517. return 0;
  518. }
  519. static void *
  520. c_start (struct seq_file *m, loff_t *pos)
  521. {
  522. #ifdef CONFIG_SMP
  523. while (*pos < NR_CPUS && !cpu_isset(*pos, cpu_online_map))
  524. ++*pos;
  525. #endif
  526. return *pos < NR_CPUS ? cpu_data(*pos) : NULL;
  527. }
  528. static void *
  529. c_next (struct seq_file *m, void *v, loff_t *pos)
  530. {
  531. ++*pos;
  532. return c_start(m, pos);
  533. }
  534. static void
  535. c_stop (struct seq_file *m, void *v)
  536. {
  537. }
  538. struct seq_operations cpuinfo_op = {
  539. .start = c_start,
  540. .next = c_next,
  541. .stop = c_stop,
  542. .show = show_cpuinfo
  543. };
  544. void
  545. identify_cpu (struct cpuinfo_ia64 *c)
  546. {
  547. union {
  548. unsigned long bits[5];
  549. struct {
  550. /* id 0 & 1: */
  551. char vendor[16];
  552. /* id 2 */
  553. u64 ppn; /* processor serial number */
  554. /* id 3: */
  555. unsigned number : 8;
  556. unsigned revision : 8;
  557. unsigned model : 8;
  558. unsigned family : 8;
  559. unsigned archrev : 8;
  560. unsigned reserved : 24;
  561. /* id 4: */
  562. u64 features;
  563. } field;
  564. } cpuid;
  565. pal_vm_info_1_u_t vm1;
  566. pal_vm_info_2_u_t vm2;
  567. pal_status_t status;
  568. unsigned long impl_va_msb = 50, phys_addr_size = 44; /* Itanium defaults */
  569. int i;
  570. for (i = 0; i < 5; ++i)
  571. cpuid.bits[i] = ia64_get_cpuid(i);
  572. memcpy(c->vendor, cpuid.field.vendor, 16);
  573. #ifdef CONFIG_SMP
  574. c->cpu = smp_processor_id();
  575. /* below default values will be overwritten by identify_siblings()
  576. * for Multi-Threading/Multi-Core capable cpu's
  577. */
  578. c->threads_per_core = c->cores_per_socket = c->num_log = 1;
  579. c->socket_id = -1;
  580. identify_siblings(c);
  581. #endif
  582. c->ppn = cpuid.field.ppn;
  583. c->number = cpuid.field.number;
  584. c->revision = cpuid.field.revision;
  585. c->model = cpuid.field.model;
  586. c->family = cpuid.field.family;
  587. c->archrev = cpuid.field.archrev;
  588. c->features = cpuid.field.features;
  589. status = ia64_pal_vm_summary(&vm1, &vm2);
  590. if (status == PAL_STATUS_SUCCESS) {
  591. impl_va_msb = vm2.pal_vm_info_2_s.impl_va_msb;
  592. phys_addr_size = vm1.pal_vm_info_1_s.phys_add_size;
  593. }
  594. c->unimpl_va_mask = ~((7L<<61) | ((1L << (impl_va_msb + 1)) - 1));
  595. c->unimpl_pa_mask = ~((1L<<63) | ((1L << phys_addr_size) - 1));
  596. }
  597. void
  598. setup_per_cpu_areas (void)
  599. {
  600. /* start_kernel() requires this... */
  601. }
  602. /*
  603. * Calculate the max. cache line size.
  604. *
  605. * In addition, the minimum of the i-cache stride sizes is calculated for
  606. * "flush_icache_range()".
  607. */
  608. static void
  609. get_max_cacheline_size (void)
  610. {
  611. unsigned long line_size, max = 1;
  612. unsigned int cache_size = 0;
  613. u64 l, levels, unique_caches;
  614. pal_cache_config_info_t cci;
  615. s64 status;
  616. status = ia64_pal_cache_summary(&levels, &unique_caches);
  617. if (status != 0) {
  618. printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n",
  619. __FUNCTION__, status);
  620. max = SMP_CACHE_BYTES;
  621. /* Safest setup for "flush_icache_range()" */
  622. ia64_i_cache_stride_shift = I_CACHE_STRIDE_SHIFT;
  623. goto out;
  624. }
  625. for (l = 0; l < levels; ++l) {
  626. status = ia64_pal_cache_config_info(l, /* cache_type (data_or_unified)= */ 2,
  627. &cci);
  628. if (status != 0) {
  629. printk(KERN_ERR
  630. "%s: ia64_pal_cache_config_info(l=%lu, 2) failed (status=%ld)\n",
  631. __FUNCTION__, l, status);
  632. max = SMP_CACHE_BYTES;
  633. /* The safest setup for "flush_icache_range()" */
  634. cci.pcci_stride = I_CACHE_STRIDE_SHIFT;
  635. cci.pcci_unified = 1;
  636. }
  637. line_size = 1 << cci.pcci_line_size;
  638. if (line_size > max)
  639. max = line_size;
  640. if (cache_size < cci.pcci_cache_size)
  641. cache_size = cci.pcci_cache_size;
  642. if (!cci.pcci_unified) {
  643. status = ia64_pal_cache_config_info(l,
  644. /* cache_type (instruction)= */ 1,
  645. &cci);
  646. if (status != 0) {
  647. printk(KERN_ERR
  648. "%s: ia64_pal_cache_config_info(l=%lu, 1) failed (status=%ld)\n",
  649. __FUNCTION__, l, status);
  650. /* The safest setup for "flush_icache_range()" */
  651. cci.pcci_stride = I_CACHE_STRIDE_SHIFT;
  652. }
  653. }
  654. if (cci.pcci_stride < ia64_i_cache_stride_shift)
  655. ia64_i_cache_stride_shift = cci.pcci_stride;
  656. }
  657. out:
  658. #ifdef CONFIG_SMP
  659. max_cache_size = max(max_cache_size, cache_size);
  660. #endif
  661. if (max > ia64_max_cacheline_size)
  662. ia64_max_cacheline_size = max;
  663. }
  664. /*
  665. * cpu_init() initializes state that is per-CPU. This function acts
  666. * as a 'CPU state barrier', nothing should get across.
  667. */
  668. void
  669. cpu_init (void)
  670. {
  671. extern void __devinit ia64_mmu_init (void *);
  672. unsigned long num_phys_stacked;
  673. pal_vm_info_2_u_t vmi;
  674. unsigned int max_ctx;
  675. struct cpuinfo_ia64 *cpu_info;
  676. void *cpu_data;
  677. cpu_data = per_cpu_init();
  678. /*
  679. * We set ar.k3 so that assembly code in MCA handler can compute
  680. * physical addresses of per cpu variables with a simple:
  681. * phys = ar.k3 + &per_cpu_var
  682. */
  683. ia64_set_kr(IA64_KR_PER_CPU_DATA,
  684. ia64_tpa(cpu_data) - (long) __per_cpu_start);
  685. get_max_cacheline_size();
  686. /*
  687. * We can't pass "local_cpu_data" to identify_cpu() because we haven't called
  688. * ia64_mmu_init() yet. And we can't call ia64_mmu_init() first because it
  689. * depends on the data returned by identify_cpu(). We break the dependency by
  690. * accessing cpu_data() through the canonical per-CPU address.
  691. */
  692. cpu_info = cpu_data + ((char *) &__ia64_per_cpu_var(cpu_info) - __per_cpu_start);
  693. identify_cpu(cpu_info);
  694. #ifdef CONFIG_MCKINLEY
  695. {
  696. # define FEATURE_SET 16
  697. struct ia64_pal_retval iprv;
  698. if (cpu_info->family == 0x1f) {
  699. PAL_CALL_PHYS(iprv, PAL_PROC_GET_FEATURES, 0, FEATURE_SET, 0);
  700. if ((iprv.status == 0) && (iprv.v0 & 0x80) && (iprv.v2 & 0x80))
  701. PAL_CALL_PHYS(iprv, PAL_PROC_SET_FEATURES,
  702. (iprv.v1 | 0x80), FEATURE_SET, 0);
  703. }
  704. }
  705. #endif
  706. /* Clear the stack memory reserved for pt_regs: */
  707. memset(task_pt_regs(current), 0, sizeof(struct pt_regs));
  708. ia64_set_kr(IA64_KR_FPU_OWNER, 0);
  709. /*
  710. * Initialize the page-table base register to a global
  711. * directory with all zeroes. This ensure that we can handle
  712. * TLB-misses to user address-space even before we created the
  713. * first user address-space. This may happen, e.g., due to
  714. * aggressive use of lfetch.fault.
  715. */
  716. ia64_set_kr(IA64_KR_PT_BASE, __pa(ia64_imva(empty_zero_page)));
  717. /*
  718. * Initialize default control register to defer speculative faults except
  719. * for those arising from TLB misses, which are not deferred. The
  720. * kernel MUST NOT depend on a particular setting of these bits (in other words,
  721. * the kernel must have recovery code for all speculative accesses). Turn on
  722. * dcr.lc as per recommendation by the architecture team. Most IA-32 apps
  723. * shouldn't be affected by this (moral: keep your ia32 locks aligned and you'll
  724. * be fine).
  725. */
  726. ia64_setreg(_IA64_REG_CR_DCR, ( IA64_DCR_DP | IA64_DCR_DK | IA64_DCR_DX | IA64_DCR_DR
  727. | IA64_DCR_DA | IA64_DCR_DD | IA64_DCR_LC));
  728. atomic_inc(&init_mm.mm_count);
  729. current->active_mm = &init_mm;
  730. if (current->mm)
  731. BUG();
  732. ia64_mmu_init(ia64_imva(cpu_data));
  733. ia64_mca_cpu_init(ia64_imva(cpu_data));
  734. #ifdef CONFIG_IA32_SUPPORT
  735. ia32_cpu_init();
  736. #endif
  737. /* Clear ITC to eliminiate sched_clock() overflows in human time. */
  738. ia64_set_itc(0);
  739. /* disable all local interrupt sources: */
  740. ia64_set_itv(1 << 16);
  741. ia64_set_lrr0(1 << 16);
  742. ia64_set_lrr1(1 << 16);
  743. ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
  744. ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);
  745. /* clear TPR & XTP to enable all interrupt classes: */
  746. ia64_setreg(_IA64_REG_CR_TPR, 0);
  747. #ifdef CONFIG_SMP
  748. normal_xtp();
  749. #endif
  750. /* set ia64_ctx.max_rid to the maximum RID that is supported by all CPUs: */
  751. if (ia64_pal_vm_summary(NULL, &vmi) == 0)
  752. max_ctx = (1U << (vmi.pal_vm_info_2_s.rid_size - 3)) - 1;
  753. else {
  754. printk(KERN_WARNING "cpu_init: PAL VM summary failed, assuming 18 RID bits\n");
  755. max_ctx = (1U << 15) - 1; /* use architected minimum */
  756. }
  757. while (max_ctx < ia64_ctx.max_ctx) {
  758. unsigned int old = ia64_ctx.max_ctx;
  759. if (cmpxchg(&ia64_ctx.max_ctx, old, max_ctx) == old)
  760. break;
  761. }
  762. if (ia64_pal_rse_info(&num_phys_stacked, NULL) != 0) {
  763. printk(KERN_WARNING "cpu_init: PAL RSE info failed; assuming 96 physical "
  764. "stacked regs\n");
  765. num_phys_stacked = 96;
  766. }
  767. /* size of physical stacked register partition plus 8 bytes: */
  768. __get_cpu_var(ia64_phys_stacked_size_p8) = num_phys_stacked*8 + 8;
  769. platform_cpu_init();
  770. pm_idle = default_idle;
  771. }
  772. /*
  773. * On SMP systems, when the scheduler does migration-cost autodetection,
  774. * it needs a way to flush as much of the CPU's caches as possible.
  775. */
  776. void sched_cacheflush(void)
  777. {
  778. ia64_sal_cache_flush(3);
  779. }
  780. void
  781. check_bugs (void)
  782. {
  783. ia64_patch_mckinley_e9((unsigned long) __start___mckinley_e9_bundles,
  784. (unsigned long) __end___mckinley_e9_bundles);
  785. }