processor.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Initial setup-routines for HP 9000 based hardware.
  4. *
  5. * Copyright (C) 1991, 1992, 1995 Linus Torvalds
  6. * Modifications for PA-RISC (C) 1999-2008 Helge Deller <[email protected]>
  7. * Modifications copyright 1999 SuSE GmbH (Philipp Rumpf)
  8. * Modifications copyright 2000 Martin K. Petersen <[email protected]>
  9. * Modifications copyright 2000 Philipp Rumpf <[email protected]>
  10. * Modifications copyright 2001 Ryan Bradetich <[email protected]>
  11. *
  12. * Initial PA-RISC Version: 04-23-1999 by Helge Deller
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/mm.h>
  17. #include <linux/module.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/random.h>
  20. #include <linux/slab.h>
  21. #include <linux/cpu.h>
  22. #include <asm/topology.h>
  23. #include <asm/param.h>
  24. #include <asm/cache.h>
  25. #include <asm/hardware.h> /* for register_parisc_driver() stuff */
  26. #include <asm/processor.h>
  27. #include <asm/page.h>
  28. #include <asm/pdc.h>
  29. #include <asm/pdcpat.h>
  30. #include <asm/irq.h> /* for struct irq_region */
  31. #include <asm/parisc-device.h>
  32. struct system_cpuinfo_parisc boot_cpu_data __ro_after_init;
  33. EXPORT_SYMBOL(boot_cpu_data);
  34. #ifdef CONFIG_PA8X00
  35. int _parisc_requires_coherency __ro_after_init;
  36. EXPORT_SYMBOL(_parisc_requires_coherency);
  37. #endif
  38. DEFINE_PER_CPU(struct cpuinfo_parisc, cpu_data);
  39. /*
  40. ** PARISC CPU driver - claim "device" and initialize CPU data structures.
  41. **
  42. ** Consolidate per CPU initialization into (mostly) one module.
  43. ** Monarch CPU will initialize boot_cpu_data which shouldn't
  44. ** change once the system has booted.
  45. **
  46. ** The callback *should* do per-instance initialization of
  47. ** everything including the monarch. "Per CPU" init code in
  48. ** setup.c:start_parisc() has migrated here and start_parisc()
  49. ** will call register_parisc_driver(&cpu_driver) before calling do_inventory().
  50. **
  51. ** The goal of consolidating CPU initialization into one place is
  52. ** to make sure all CPUs get initialized the same way.
  53. ** The code path not shared is how PDC hands control of the CPU to the OS.
  54. ** The initialization of OS data structures is the same (done below).
  55. */
  56. /**
  57. * init_cpu_profiler - enable/setup per cpu profiling hooks.
  58. * @cpunum: The processor instance.
  59. *
  60. * FIXME: doesn't do much yet...
  61. */
  62. static void
  63. init_percpu_prof(unsigned long cpunum)
  64. {
  65. }
  66. /**
  67. * processor_probe - Determine if processor driver should claim this device.
  68. * @dev: The device which has been found.
  69. *
  70. * Determine if processor driver should claim this chip (return 0) or not
  71. * (return 1). If so, initialize the chip and tell other partners in crime
  72. * they have work to do.
  73. */
  74. static int __init processor_probe(struct parisc_device *dev)
  75. {
  76. unsigned long txn_addr;
  77. unsigned long cpuid;
  78. struct cpuinfo_parisc *p;
  79. struct pdc_pat_cpu_num cpu_info = { };
  80. #ifdef CONFIG_SMP
  81. if (num_online_cpus() >= nr_cpu_ids) {
  82. printk(KERN_INFO "num_online_cpus() >= nr_cpu_ids\n");
  83. return 1;
  84. }
  85. #else
  86. if (boot_cpu_data.cpu_count > 0) {
  87. printk(KERN_INFO "CONFIG_SMP=n ignoring additional CPUs\n");
  88. return 1;
  89. }
  90. #endif
  91. /* logical CPU ID and update global counter
  92. * May get overwritten by PAT code.
  93. */
  94. cpuid = boot_cpu_data.cpu_count;
  95. txn_addr = dev->hpa.start; /* for legacy PDC */
  96. cpu_info.cpu_num = cpu_info.cpu_loc = cpuid;
  97. #ifdef CONFIG_64BIT
  98. if (is_pdc_pat()) {
  99. ulong status;
  100. unsigned long bytecnt;
  101. pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;
  102. pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);
  103. if (!pa_pdc_cell)
  104. panic("couldn't allocate memory for PDC_PAT_CELL!");
  105. status = pdc_pat_cell_module(&bytecnt, dev->pcell_loc,
  106. dev->mod_index, PA_VIEW, pa_pdc_cell);
  107. BUG_ON(PDC_OK != status);
  108. /* verify it's the same as what do_pat_inventory() found */
  109. BUG_ON(dev->mod_info != pa_pdc_cell->mod_info);
  110. BUG_ON(dev->pmod_loc != pa_pdc_cell->mod_location);
  111. txn_addr = pa_pdc_cell->mod[0]; /* id_eid for IO sapic */
  112. kfree(pa_pdc_cell);
  113. /* get the cpu number */
  114. status = pdc_pat_cpu_get_number(&cpu_info, dev->hpa.start);
  115. BUG_ON(PDC_OK != status);
  116. pr_info("Logical CPU #%lu is physical cpu #%lu at location "
  117. "0x%lx with hpa %pa\n",
  118. cpuid, cpu_info.cpu_num, cpu_info.cpu_loc,
  119. &dev->hpa.start);
  120. #undef USE_PAT_CPUID
  121. #ifdef USE_PAT_CPUID
  122. /* We need contiguous numbers for cpuid. Firmware's notion
  123. * of cpuid is for physical CPUs and we just don't care yet.
  124. * We'll care when we need to query PAT PDC about a CPU *after*
  125. * boot time (ie shutdown a CPU from an OS perspective).
  126. */
  127. if (cpu_info.cpu_num >= NR_CPUS) {
  128. printk(KERN_WARNING "IGNORING CPU at %pa,"
  129. " cpu_slot_id > NR_CPUS"
  130. " (%ld > %d)\n",
  131. &dev->hpa.start, cpu_info.cpu_num, NR_CPUS);
  132. /* Ignore CPU since it will only crash */
  133. boot_cpu_data.cpu_count--;
  134. return 1;
  135. } else {
  136. cpuid = cpu_info.cpu_num;
  137. }
  138. #endif
  139. }
  140. #endif
  141. p = &per_cpu(cpu_data, cpuid);
  142. boot_cpu_data.cpu_count++;
  143. /* initialize counters - CPU 0 gets it_value set in time_init() */
  144. if (cpuid)
  145. memset(p, 0, sizeof(struct cpuinfo_parisc));
  146. p->dev = dev; /* Save IODC data in case we need it */
  147. p->hpa = dev->hpa.start; /* save CPU hpa */
  148. p->cpuid = cpuid; /* save CPU id */
  149. p->txn_addr = txn_addr; /* save CPU IRQ address */
  150. p->cpu_num = cpu_info.cpu_num;
  151. p->cpu_loc = cpu_info.cpu_loc;
  152. set_cpu_possible(cpuid, true);
  153. store_cpu_topology(cpuid);
  154. #ifdef CONFIG_SMP
  155. /*
  156. ** FIXME: review if any other initialization is clobbered
  157. ** for boot_cpu by the above memset().
  158. */
  159. init_percpu_prof(cpuid);
  160. #endif
  161. /*
  162. ** CONFIG_SMP: init_smp_config() will attempt to get CPUs into
  163. ** OS control. RENDEZVOUS is the default state - see mem_set above.
  164. ** p->state = STATE_RENDEZVOUS;
  165. */
  166. #if 0
  167. /* CPU 0 IRQ table is statically allocated/initialized */
  168. if (cpuid) {
  169. struct irqaction actions[];
  170. /*
  171. ** itimer and ipi IRQ handlers are statically initialized in
  172. ** arch/parisc/kernel/irq.c. ie Don't need to register them.
  173. */
  174. actions = kmalloc(sizeof(struct irqaction)*MAX_CPU_IRQ, GFP_ATOMIC);
  175. if (!actions) {
  176. /* not getting it's own table, share with monarch */
  177. actions = cpu_irq_actions[0];
  178. }
  179. cpu_irq_actions[cpuid] = actions;
  180. }
  181. #endif
  182. /*
  183. * Bring this CPU up now! (ignore bootstrap cpuid == 0)
  184. */
  185. #ifdef CONFIG_SMP
  186. if (cpuid) {
  187. set_cpu_present(cpuid, true);
  188. add_cpu(cpuid);
  189. }
  190. #endif
  191. return 0;
  192. }
  193. /**
  194. * collect_boot_cpu_data - Fill the boot_cpu_data structure.
  195. *
  196. * This function collects and stores the generic processor information
  197. * in the boot_cpu_data structure.
  198. */
  199. void __init collect_boot_cpu_data(void)
  200. {
  201. unsigned long cr16_seed;
  202. char orig_prod_num[64], current_prod_num[64], serial_no[64];
  203. memset(&boot_cpu_data, 0, sizeof(boot_cpu_data));
  204. cr16_seed = get_cycles();
  205. add_device_randomness(&cr16_seed, sizeof(cr16_seed));
  206. boot_cpu_data.cpu_hz = 100 * PAGE0->mem_10msec; /* Hz of this PARISC */
  207. /* get CPU-Model Information... */
  208. #define p ((unsigned long *)&boot_cpu_data.pdc.model)
  209. if (pdc_model_info(&boot_cpu_data.pdc.model) == PDC_OK) {
  210. printk(KERN_INFO
  211. "model %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  212. p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);
  213. add_device_randomness(&boot_cpu_data.pdc.model,
  214. sizeof(boot_cpu_data.pdc.model));
  215. }
  216. #undef p
  217. if (pdc_model_versions(&boot_cpu_data.pdc.versions, 0) == PDC_OK) {
  218. printk(KERN_INFO "vers %08lx\n",
  219. boot_cpu_data.pdc.versions);
  220. add_device_randomness(&boot_cpu_data.pdc.versions,
  221. sizeof(boot_cpu_data.pdc.versions));
  222. }
  223. if (pdc_model_cpuid(&boot_cpu_data.pdc.cpuid) == PDC_OK) {
  224. printk(KERN_INFO "CPUID vers %ld rev %ld (0x%08lx)\n",
  225. (boot_cpu_data.pdc.cpuid >> 5) & 127,
  226. boot_cpu_data.pdc.cpuid & 31,
  227. boot_cpu_data.pdc.cpuid);
  228. add_device_randomness(&boot_cpu_data.pdc.cpuid,
  229. sizeof(boot_cpu_data.pdc.cpuid));
  230. }
  231. if (pdc_model_capabilities(&boot_cpu_data.pdc.capabilities) == PDC_OK)
  232. printk(KERN_INFO "capabilities 0x%lx\n",
  233. boot_cpu_data.pdc.capabilities);
  234. if (pdc_model_sysmodel(boot_cpu_data.pdc.sys_model_name) == PDC_OK)
  235. printk(KERN_INFO "model %s\n",
  236. boot_cpu_data.pdc.sys_model_name);
  237. dump_stack_set_arch_desc("%s", boot_cpu_data.pdc.sys_model_name);
  238. boot_cpu_data.hversion = boot_cpu_data.pdc.model.hversion;
  239. boot_cpu_data.sversion = boot_cpu_data.pdc.model.sversion;
  240. boot_cpu_data.cpu_type = parisc_get_cpu_type(boot_cpu_data.hversion);
  241. boot_cpu_data.cpu_name = cpu_name_version[boot_cpu_data.cpu_type][0];
  242. boot_cpu_data.family_name = cpu_name_version[boot_cpu_data.cpu_type][1];
  243. #ifdef CONFIG_PA8X00
  244. _parisc_requires_coherency = (boot_cpu_data.cpu_type == mako) ||
  245. (boot_cpu_data.cpu_type == mako2);
  246. #endif
  247. if (pdc_model_platform_info(orig_prod_num, current_prod_num, serial_no) == PDC_OK) {
  248. printk(KERN_INFO "product %s, original product %s, S/N: %s\n",
  249. current_prod_num[0] ? current_prod_num : "n/a",
  250. orig_prod_num, serial_no);
  251. add_device_randomness(orig_prod_num, strlen(orig_prod_num));
  252. add_device_randomness(current_prod_num, strlen(current_prod_num));
  253. add_device_randomness(serial_no, strlen(serial_no));
  254. }
  255. }
  256. /**
  257. * init_per_cpu - Handle individual processor initializations.
  258. * @cpunum: logical processor number.
  259. *
  260. * This function handles initialization for *every* CPU
  261. * in the system:
  262. *
  263. * o Set "default" CPU width for trap handlers
  264. *
  265. * o Enable FP coprocessor
  266. * REVISIT: this could be done in the "code 22" trap handler.
  267. * (frowands idea - that way we know which processes need FP
  268. * registers saved on the interrupt stack.)
  269. * NEWS FLASH: wide kernels need FP coprocessor enabled to handle
  270. * formatted printing of %lx for example (double divides I think)
  271. *
  272. * o Enable CPU profiling hooks.
  273. */
  274. int init_per_cpu(int cpunum)
  275. {
  276. int ret;
  277. struct pdc_coproc_cfg coproc_cfg;
  278. set_firmware_width();
  279. ret = pdc_coproc_cfg(&coproc_cfg);
  280. if(ret >= 0 && coproc_cfg.ccr_functional) {
  281. mtctl(coproc_cfg.ccr_functional, 10); /* 10 == Coprocessor Control Reg */
  282. /* FWIW, FP rev/model is a more accurate way to determine
  283. ** CPU type. CPU rev/model has some ambiguous cases.
  284. */
  285. per_cpu(cpu_data, cpunum).fp_rev = coproc_cfg.revision;
  286. per_cpu(cpu_data, cpunum).fp_model = coproc_cfg.model;
  287. if (cpunum == 0)
  288. printk(KERN_INFO "FP[%d] enabled: Rev %ld Model %ld\n",
  289. cpunum, coproc_cfg.revision, coproc_cfg.model);
  290. /*
  291. ** store status register to stack (hopefully aligned)
  292. ** and clear the T-bit.
  293. */
  294. asm volatile ("fstd %fr0,8(%sp)");
  295. } else {
  296. printk(KERN_WARNING "WARNING: No FP CoProcessor?!"
  297. " (coproc_cfg.ccr_functional == 0x%lx, expected 0xc0)\n"
  298. #ifdef CONFIG_64BIT
  299. "Halting Machine - FP required\n"
  300. #endif
  301. , coproc_cfg.ccr_functional);
  302. #ifdef CONFIG_64BIT
  303. mdelay(100); /* previous chars get pushed to console */
  304. panic("FP CoProc not reported");
  305. #endif
  306. }
  307. /* FUTURE: Enable Performance Monitor : ccr bit 0x20 */
  308. init_percpu_prof(cpunum);
  309. return ret;
  310. }
  311. /*
  312. * Display CPU info for all CPUs.
  313. */
  314. int
  315. show_cpuinfo (struct seq_file *m, void *v)
  316. {
  317. unsigned long cpu;
  318. char cpu_name[60], *p;
  319. /* strip PA path from CPU name to not confuse lscpu */
  320. strlcpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name));
  321. p = strrchr(cpu_name, '[');
  322. if (p)
  323. *(--p) = 0;
  324. for_each_online_cpu(cpu) {
  325. #ifdef CONFIG_SMP
  326. const struct cpuinfo_parisc *cpuinfo = &per_cpu(cpu_data, cpu);
  327. if (0 == cpuinfo->hpa)
  328. continue;
  329. #endif
  330. seq_printf(m, "processor\t: %lu\n"
  331. "cpu family\t: PA-RISC %s\n",
  332. cpu, boot_cpu_data.family_name);
  333. seq_printf(m, "cpu\t\t: %s\n", boot_cpu_data.cpu_name );
  334. /* cpu MHz */
  335. seq_printf(m, "cpu MHz\t\t: %d.%06d\n",
  336. boot_cpu_data.cpu_hz / 1000000,
  337. boot_cpu_data.cpu_hz % 1000000 );
  338. #ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
  339. seq_printf(m, "physical id\t: %d\n",
  340. topology_physical_package_id(cpu));
  341. seq_printf(m, "siblings\t: %d\n",
  342. cpumask_weight(topology_core_cpumask(cpu)));
  343. seq_printf(m, "core id\t\t: %d\n", topology_core_id(cpu));
  344. #endif
  345. seq_printf(m, "capabilities\t:");
  346. if (boot_cpu_data.pdc.capabilities & PDC_MODEL_OS32)
  347. seq_puts(m, " os32");
  348. if (boot_cpu_data.pdc.capabilities & PDC_MODEL_OS64)
  349. seq_puts(m, " os64");
  350. if (boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC)
  351. seq_puts(m, " iopdir_fdc");
  352. switch (boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) {
  353. case PDC_MODEL_NVA_SUPPORTED:
  354. seq_puts(m, " nva_supported");
  355. break;
  356. case PDC_MODEL_NVA_SLOW:
  357. seq_puts(m, " nva_slow");
  358. break;
  359. case PDC_MODEL_NVA_UNSUPPORTED:
  360. seq_puts(m, " needs_equivalent_aliasing");
  361. break;
  362. }
  363. seq_printf(m, " (0x%02lx)\n", boot_cpu_data.pdc.capabilities);
  364. seq_printf(m, "model\t\t: %s - %s\n",
  365. boot_cpu_data.pdc.sys_model_name,
  366. cpu_name);
  367. seq_printf(m, "hversion\t: 0x%08x\n"
  368. "sversion\t: 0x%08x\n",
  369. boot_cpu_data.hversion,
  370. boot_cpu_data.sversion );
  371. /* print cachesize info */
  372. show_cache_info(m);
  373. seq_printf(m, "bogomips\t: %lu.%02lu\n",
  374. loops_per_jiffy / (500000 / HZ),
  375. loops_per_jiffy / (5000 / HZ) % 100);
  376. seq_printf(m, "software id\t: %ld\n\n",
  377. boot_cpu_data.pdc.model.sw_id);
  378. }
  379. return 0;
  380. }
  381. static const struct parisc_device_id processor_tbl[] __initconst = {
  382. { HPHW_NPROC, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, SVERSION_ANY_ID },
  383. { 0, }
  384. };
  385. static struct parisc_driver cpu_driver __refdata = {
  386. .name = "CPU",
  387. .id_table = processor_tbl,
  388. .probe = processor_probe
  389. };
  390. /**
  391. * processor_init - Processor initialization procedure.
  392. *
  393. * Register this driver.
  394. */
  395. void __init processor_init(void)
  396. {
  397. unsigned int cpu;
  398. reset_cpu_topology();
  399. /* reset possible mask. We will mark those which are possible. */
  400. for_each_possible_cpu(cpu)
  401. set_cpu_possible(cpu, false);
  402. register_parisc_driver(&cpu_driver);
  403. }