summit_32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * IBM Summit-Specific Code
  3. *
  4. * Written By: Matthew Dobson, IBM Corporation
  5. *
  6. * Copyright (c) 2003 IBM Corp.
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <colpatch@us.ibm.com>
  26. *
  27. */
  28. #define pr_fmt(fmt) "summit: %s: " fmt, __func__
  29. #include <linux/mm.h>
  30. #include <linux/init.h>
  31. #include <asm/io.h>
  32. #include <asm/bios_ebda.h>
  33. /*
  34. * APIC driver for the IBM "Summit" chipset.
  35. */
  36. #include <linux/threads.h>
  37. #include <linux/cpumask.h>
  38. #include <asm/mpspec.h>
  39. #include <asm/apic.h>
  40. #include <asm/smp.h>
  41. #include <asm/fixmap.h>
  42. #include <asm/apicdef.h>
  43. #include <asm/ipi.h>
  44. #include <linux/kernel.h>
  45. #include <linux/string.h>
  46. #include <linux/gfp.h>
  47. #include <linux/smp.h>
  48. static unsigned summit_get_apic_id(unsigned long x)
  49. {
  50. return (x >> 24) & 0xFF;
  51. }
  52. static inline void summit_send_IPI_mask(const struct cpumask *mask, int vector)
  53. {
  54. default_send_IPI_mask_sequence_logical(mask, vector);
  55. }
  56. static void summit_send_IPI_allbutself(int vector)
  57. {
  58. default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);
  59. }
  60. static void summit_send_IPI_all(int vector)
  61. {
  62. summit_send_IPI_mask(cpu_online_mask, vector);
  63. }
  64. #include <asm/tsc.h>
  65. extern int use_cyclone;
  66. #ifdef CONFIG_X86_SUMMIT_NUMA
  67. static void setup_summit(void);
  68. #else
  69. static inline void setup_summit(void) {}
  70. #endif
  71. static int summit_mps_oem_check(struct mpc_table *mpc, char *oem,
  72. char *productid)
  73. {
  74. if (!strncmp(oem, "IBM ENSW", 8) &&
  75. (!strncmp(productid, "VIGIL SMP", 9)
  76. || !strncmp(productid, "EXA", 3)
  77. || !strncmp(productid, "RUTHLESS SMP", 12))){
  78. mark_tsc_unstable("Summit based system");
  79. use_cyclone = 1; /*enable cyclone-timer*/
  80. setup_summit();
  81. return 1;
  82. }
  83. return 0;
  84. }
  85. /* Hook from generic ACPI tables.c */
  86. static int summit_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  87. {
  88. if (!strncmp(oem_id, "IBM", 3) &&
  89. (!strncmp(oem_table_id, "SERVIGIL", 8)
  90. || !strncmp(oem_table_id, "EXA", 3))){
  91. mark_tsc_unstable("Summit based system");
  92. use_cyclone = 1; /*enable cyclone-timer*/
  93. setup_summit();
  94. return 1;
  95. }
  96. return 0;
  97. }
  98. struct rio_table_hdr {
  99. unsigned char version; /* Version number of this data structure */
  100. /* Version 3 adds chassis_num & WP_index */
  101. unsigned char num_scal_dev; /* # of Scalability devices (Twisters for Vigil) */
  102. unsigned char num_rio_dev; /* # of RIO I/O devices (Cyclones and Winnipegs) */
  103. } __attribute__((packed));
  104. struct scal_detail {
  105. unsigned char node_id; /* Scalability Node ID */
  106. unsigned long CBAR; /* Address of 1MB register space */
  107. unsigned char port0node; /* Node ID port connected to: 0xFF=None */
  108. unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */
  109. unsigned char port1node; /* Node ID port connected to: 0xFF = None */
  110. unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */
  111. unsigned char port2node; /* Node ID port connected to: 0xFF = None */
  112. unsigned char port2port; /* Port num port connected to: 0,1,2, or 0xFF=None */
  113. unsigned char chassis_num; /* 1 based Chassis number (1 = boot node) */
  114. } __attribute__((packed));
  115. struct rio_detail {
  116. unsigned char node_id; /* RIO Node ID */
  117. unsigned long BBAR; /* Address of 1MB register space */
  118. unsigned char type; /* Type of device */
  119. unsigned char owner_id; /* For WPEG: Node ID of Cyclone that owns this WPEG*/
  120. /* For CYC: Node ID of Twister that owns this CYC */
  121. unsigned char port0node; /* Node ID port connected to: 0xFF=None */
  122. unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */
  123. unsigned char port1node; /* Node ID port connected to: 0xFF=None */
  124. unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */
  125. unsigned char first_slot; /* For WPEG: Lowest slot number below this WPEG */
  126. /* For CYC: 0 */
  127. unsigned char status; /* For WPEG: Bit 0 = 1 : the XAPIC is used */
  128. /* = 0 : the XAPIC is not used, ie:*/
  129. /* ints fwded to another XAPIC */
  130. /* Bits1:7 Reserved */
  131. /* For CYC: Bits0:7 Reserved */
  132. unsigned char WP_index; /* For WPEG: WPEG instance index - lower ones have */
  133. /* lower slot numbers/PCI bus numbers */
  134. /* For CYC: No meaning */
  135. unsigned char chassis_num; /* 1 based Chassis number */
  136. /* For LookOut WPEGs this field indicates the */
  137. /* Expansion Chassis #, enumerated from Boot */
  138. /* Node WPEG external port, then Boot Node CYC */
  139. /* external port, then Next Vigil chassis WPEG */
  140. /* external port, etc. */
  141. /* Shared Lookouts have only 1 chassis number (the */
  142. /* first one assigned) */
  143. } __attribute__((packed));
  144. typedef enum {
  145. CompatTwister = 0, /* Compatibility Twister */
  146. AltTwister = 1, /* Alternate Twister of internal 8-way */
  147. CompatCyclone = 2, /* Compatibility Cyclone */
  148. AltCyclone = 3, /* Alternate Cyclone of internal 8-way */
  149. CompatWPEG = 4, /* Compatibility WPEG */
  150. AltWPEG = 5, /* Second Planar WPEG */
  151. LookOutAWPEG = 6, /* LookOut WPEG */
  152. LookOutBWPEG = 7, /* LookOut WPEG */
  153. } node_type;
  154. static inline int is_WPEG(struct rio_detail *rio){
  155. return (rio->type == CompatWPEG || rio->type == AltWPEG ||
  156. rio->type == LookOutAWPEG || rio->type == LookOutBWPEG);
  157. }
  158. #define SUMMIT_APIC_DFR_VALUE (APIC_DFR_CLUSTER)
  159. static const struct cpumask *summit_target_cpus(void)
  160. {
  161. /* CPU_MASK_ALL (0xff) has undefined behaviour with
  162. * dest_LowestPrio mode logical clustered apic interrupt routing
  163. * Just start on cpu 0. IRQ balancing will spread load
  164. */
  165. return cpumask_of(0);
  166. }
  167. static unsigned long summit_check_apicid_used(physid_mask_t *map, int apicid)
  168. {
  169. return 0;
  170. }
  171. /* we don't use the phys_cpu_present_map to indicate apicid presence */
  172. static unsigned long summit_check_apicid_present(int bit)
  173. {
  174. return 1;
  175. }
  176. static int summit_early_logical_apicid(int cpu)
  177. {
  178. int count = 0;
  179. u8 my_id = early_per_cpu(x86_cpu_to_apicid, cpu);
  180. u8 my_cluster = APIC_CLUSTER(my_id);
  181. #ifdef CONFIG_SMP
  182. u8 lid;
  183. int i;
  184. /* Create logical APIC IDs by counting CPUs already in cluster. */
  185. for (count = 0, i = nr_cpu_ids; --i >= 0; ) {
  186. lid = early_per_cpu(x86_cpu_to_logical_apicid, i);
  187. if (lid != BAD_APICID && APIC_CLUSTER(lid) == my_cluster)
  188. ++count;
  189. }
  190. #endif
  191. /* We only have a 4 wide bitmap in cluster mode. If a deranged
  192. * BIOS puts 5 CPUs in one APIC cluster, we're hosed. */
  193. BUG_ON(count >= XAPIC_DEST_CPUS_SHIFT);
  194. return my_cluster | (1UL << count);
  195. }
  196. static void summit_init_apic_ldr(void)
  197. {
  198. int cpu = smp_processor_id();
  199. unsigned long id = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
  200. unsigned long val;
  201. apic_write(APIC_DFR, SUMMIT_APIC_DFR_VALUE);
  202. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  203. val |= SET_APIC_LOGICAL_ID(id);
  204. apic_write(APIC_LDR, val);
  205. }
  206. static int summit_apic_id_registered(void)
  207. {
  208. return 1;
  209. }
  210. static void summit_setup_apic_routing(void)
  211. {
  212. pr_info("Enabling APIC mode: Summit. Using %d I/O APICs\n",
  213. nr_ioapics);
  214. }
  215. static int summit_cpu_present_to_apicid(int mps_cpu)
  216. {
  217. if (mps_cpu < nr_cpu_ids)
  218. return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
  219. else
  220. return BAD_APICID;
  221. }
  222. static void summit_ioapic_phys_id_map(physid_mask_t *phys_id_map, physid_mask_t *retmap)
  223. {
  224. /* For clustered we don't have a good way to do this yet - hack */
  225. physids_promote(0x0FL, retmap);
  226. }
  227. static void summit_apicid_to_cpu_present(int apicid, physid_mask_t *retmap)
  228. {
  229. physid_set_mask_of_physid(0, retmap);
  230. }
  231. static int summit_check_phys_apicid_present(int physical_apicid)
  232. {
  233. return 1;
  234. }
  235. static inline int
  236. summit_cpu_mask_to_apicid(const struct cpumask *cpumask, unsigned int *dest_id)
  237. {
  238. unsigned int round = 0;
  239. unsigned int cpu, apicid = 0;
  240. /*
  241. * The cpus in the mask must all be on the apic cluster.
  242. */
  243. for_each_cpu_and(cpu, cpumask, cpu_online_mask) {
  244. int new_apicid = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
  245. if (round && APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {
  246. pr_err("Not a valid mask!\n");
  247. return -EINVAL;
  248. }
  249. apicid |= new_apicid;
  250. round++;
  251. }
  252. if (!round)
  253. return -EINVAL;
  254. *dest_id = apicid;
  255. return 0;
  256. }
  257. static int
  258. summit_cpu_mask_to_apicid_and(const struct cpumask *inmask,
  259. const struct cpumask *andmask,
  260. unsigned int *apicid)
  261. {
  262. cpumask_var_t cpumask;
  263. *apicid = early_per_cpu(x86_cpu_to_logical_apicid, 0);
  264. if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
  265. return 0;
  266. cpumask_and(cpumask, inmask, andmask);
  267. summit_cpu_mask_to_apicid(cpumask, apicid);
  268. free_cpumask_var(cpumask);
  269. return 0;
  270. }
  271. /*
  272. * cpuid returns the value latched in the HW at reset, not the APIC ID
  273. * register's value. For any box whose BIOS changes APIC IDs, like
  274. * clustered APIC systems, we must use hard_smp_processor_id.
  275. *
  276. * See Intel's IA-32 SW Dev's Manual Vol2 under CPUID.
  277. */
  278. static int summit_phys_pkg_id(int cpuid_apic, int index_msb)
  279. {
  280. return hard_smp_processor_id() >> index_msb;
  281. }
  282. static int probe_summit(void)
  283. {
  284. /* probed later in mptable/ACPI hooks */
  285. return 0;
  286. }
  287. #ifdef CONFIG_X86_SUMMIT_NUMA
  288. static struct rio_table_hdr *rio_table_hdr;
  289. static struct scal_detail *scal_devs[MAX_NUMNODES];
  290. static struct rio_detail *rio_devs[MAX_NUMNODES*4];
  291. #ifndef CONFIG_X86_NUMAQ
  292. static int mp_bus_id_to_node[MAX_MP_BUSSES];
  293. #endif
  294. static int setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)
  295. {
  296. int twister = 0, node = 0;
  297. int i, bus, num_buses;
  298. for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
  299. if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {
  300. twister = rio_devs[i]->owner_id;
  301. break;
  302. }
  303. }
  304. if (i == rio_table_hdr->num_rio_dev) {
  305. pr_err("Couldn't find owner Cyclone for Winnipeg!\n");
  306. return last_bus;
  307. }
  308. for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {
  309. if (scal_devs[i]->node_id == twister) {
  310. node = scal_devs[i]->node_id;
  311. break;
  312. }
  313. }
  314. if (i == rio_table_hdr->num_scal_dev) {
  315. pr_err("Couldn't find owner Twister for Cyclone!\n");
  316. return last_bus;
  317. }
  318. switch (rio_devs[wpeg_num]->type) {
  319. case CompatWPEG:
  320. /*
  321. * The Compatibility Winnipeg controls the 2 legacy buses,
  322. * the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case
  323. * a PCI-PCI bridge card is used in either slot: total 5 buses.
  324. */
  325. num_buses = 5;
  326. break;
  327. case AltWPEG:
  328. /*
  329. * The Alternate Winnipeg controls the 2 133MHz buses [1 slot
  330. * each], their 2 "extra" buses, the 100MHz bus [2 slots] and
  331. * the "extra" buses for each of those slots: total 7 buses.
  332. */
  333. num_buses = 7;
  334. break;
  335. case LookOutAWPEG:
  336. case LookOutBWPEG:
  337. /*
  338. * A Lookout Winnipeg controls 3 100MHz buses [2 slots each]
  339. * & the "extra" buses for each of those slots: total 9 buses.
  340. */
  341. num_buses = 9;
  342. break;
  343. default:
  344. pr_info("Unsupported Winnipeg type!\n");
  345. return last_bus;
  346. }
  347. for (bus = last_bus; bus < last_bus + num_buses; bus++)
  348. mp_bus_id_to_node[bus] = node;
  349. return bus;
  350. }
  351. static int build_detail_arrays(void)
  352. {
  353. unsigned long ptr;
  354. int i, scal_detail_size, rio_detail_size;
  355. if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {
  356. pr_warn("MAX_NUMNODES too low! Defined as %d, but system has %d nodes\n",
  357. MAX_NUMNODES, rio_table_hdr->num_scal_dev);
  358. return 0;
  359. }
  360. switch (rio_table_hdr->version) {
  361. default:
  362. pr_warn("Invalid Rio Grande Table Version: %d\n",
  363. rio_table_hdr->version);
  364. return 0;
  365. case 2:
  366. scal_detail_size = 11;
  367. rio_detail_size = 13;
  368. break;
  369. case 3:
  370. scal_detail_size = 12;
  371. rio_detail_size = 15;
  372. break;
  373. }
  374. ptr = (unsigned long)rio_table_hdr + 3;
  375. for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)
  376. scal_devs[i] = (struct scal_detail *)ptr;
  377. for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)
  378. rio_devs[i] = (struct rio_detail *)ptr;
  379. return 1;
  380. }
  381. void setup_summit(void)
  382. {
  383. unsigned long ptr;
  384. unsigned short offset;
  385. int i, next_wpeg, next_bus = 0;
  386. /* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */
  387. ptr = get_bios_ebda();
  388. ptr = (unsigned long)phys_to_virt(ptr);
  389. rio_table_hdr = NULL;
  390. offset = 0x180;
  391. while (offset) {
  392. /* The block id is stored in the 2nd word */
  393. if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {
  394. /* set the pointer past the offset & block id */
  395. rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);
  396. break;
  397. }
  398. /* The next offset is stored in the 1st word. 0 means no more */
  399. offset = *((unsigned short *)(ptr + offset));
  400. }
  401. if (!rio_table_hdr) {
  402. pr_err("Unable to locate Rio Grande Table in EBDA - bailing!\n");
  403. return;
  404. }
  405. if (!build_detail_arrays())
  406. return;
  407. /* The first Winnipeg we're looking for has an index of 0 */
  408. next_wpeg = 0;
  409. do {
  410. for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {
  411. if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {
  412. /* It's the Winnipeg we're looking for! */
  413. next_bus = setup_pci_node_map_for_wpeg(i, next_bus);
  414. next_wpeg++;
  415. break;
  416. }
  417. }
  418. /*
  419. * If we go through all Rio devices and don't find one with
  420. * the next index, it means we've found all the Winnipegs,
  421. * and thus all the PCI buses.
  422. */
  423. if (i == rio_table_hdr->num_rio_dev)
  424. next_wpeg = 0;
  425. } while (next_wpeg != 0);
  426. }
  427. #endif
  428. static struct apic apic_summit = {
  429. .name = "summit",
  430. .probe = probe_summit,
  431. .acpi_madt_oem_check = summit_acpi_madt_oem_check,
  432. .apic_id_valid = default_apic_id_valid,
  433. .apic_id_registered = summit_apic_id_registered,
  434. .irq_delivery_mode = dest_LowestPrio,
  435. /* logical delivery broadcast to all CPUs: */
  436. .irq_dest_mode = 1,
  437. .target_cpus = summit_target_cpus,
  438. .disable_esr = 1,
  439. .dest_logical = APIC_DEST_LOGICAL,
  440. .check_apicid_used = summit_check_apicid_used,
  441. .check_apicid_present = summit_check_apicid_present,
  442. .vector_allocation_domain = flat_vector_allocation_domain,
  443. .init_apic_ldr = summit_init_apic_ldr,
  444. .ioapic_phys_id_map = summit_ioapic_phys_id_map,
  445. .setup_apic_routing = summit_setup_apic_routing,
  446. .multi_timer_check = NULL,
  447. .cpu_present_to_apicid = summit_cpu_present_to_apicid,
  448. .apicid_to_cpu_present = summit_apicid_to_cpu_present,
  449. .setup_portio_remap = NULL,
  450. .check_phys_apicid_present = summit_check_phys_apicid_present,
  451. .enable_apic_mode = NULL,
  452. .phys_pkg_id = summit_phys_pkg_id,
  453. .mps_oem_check = summit_mps_oem_check,
  454. .get_apic_id = summit_get_apic_id,
  455. .set_apic_id = NULL,
  456. .apic_id_mask = 0xFF << 24,
  457. .cpu_mask_to_apicid_and = summit_cpu_mask_to_apicid_and,
  458. .send_IPI_mask = summit_send_IPI_mask,
  459. .send_IPI_mask_allbutself = NULL,
  460. .send_IPI_allbutself = summit_send_IPI_allbutself,
  461. .send_IPI_all = summit_send_IPI_all,
  462. .send_IPI_self = default_send_IPI_self,
  463. .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
  464. .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
  465. .wait_for_init_deassert = default_wait_for_init_deassert,
  466. .smp_callin_clear_local_apic = NULL,
  467. .inquire_remote_apic = default_inquire_remote_apic,
  468. .read = native_apic_mem_read,
  469. .write = native_apic_mem_write,
  470. .eoi_write = native_apic_mem_write,
  471. .icr_read = native_apic_icr_read,
  472. .icr_write = native_apic_icr_write,
  473. .wait_icr_idle = native_apic_wait_icr_idle,
  474. .safe_wait_icr_idle = native_safe_apic_wait_icr_idle,
  475. .x86_32_early_logical_apicid = summit_early_logical_apicid,
  476. };
  477. apic_driver(apic_summit);