Path: blob/master/arch/x86/kernel/apic/summit_32.c
17466 views
/*1* IBM Summit-Specific Code2*3* Written By: Matthew Dobson, IBM Corporation4*5* Copyright (c) 2003 IBM Corp.6*7* All rights reserved.8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or (at12* your option) any later version.13*14* This program is distributed in the hope that it will be useful, but15* WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or17* NON INFRINGEMENT. See the GNU General Public License for more18* details.19*20* You should have received a copy of the GNU General Public License21* along with this program; if not, write to the Free Software22* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.23*24* Send feedback to <[email protected]>25*26*/2728#include <linux/mm.h>29#include <linux/init.h>30#include <asm/io.h>31#include <asm/bios_ebda.h>3233/*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>4849static unsigned summit_get_apic_id(unsigned long x)50{51return (x >> 24) & 0xFF;52}5354static inline void summit_send_IPI_mask(const struct cpumask *mask, int vector)55{56default_send_IPI_mask_sequence_logical(mask, vector);57}5859static void summit_send_IPI_allbutself(int vector)60{61default_send_IPI_mask_allbutself_logical(cpu_online_mask, vector);62}6364static void summit_send_IPI_all(int vector)65{66summit_send_IPI_mask(cpu_online_mask, vector);67}6869#include <asm/tsc.h>7071extern int use_cyclone;7273#ifdef CONFIG_X86_SUMMIT_NUMA74static void setup_summit(void);75#else76static inline void setup_summit(void) {}77#endif7879static int summit_mps_oem_check(struct mpc_table *mpc, char *oem,80char *productid)81{82if (!strncmp(oem, "IBM ENSW", 8) &&83(!strncmp(productid, "VIGIL SMP", 9)84|| !strncmp(productid, "EXA", 3)85|| !strncmp(productid, "RUTHLESS SMP", 12))){86mark_tsc_unstable("Summit based system");87use_cyclone = 1; /*enable cyclone-timer*/88setup_summit();89return 1;90}91return 0;92}9394/* Hook from generic ACPI tables.c */95static int summit_acpi_madt_oem_check(char *oem_id, char *oem_table_id)96{97if (!strncmp(oem_id, "IBM", 3) &&98(!strncmp(oem_table_id, "SERVIGIL", 8)99|| !strncmp(oem_table_id, "EXA", 3))){100mark_tsc_unstable("Summit based system");101use_cyclone = 1; /*enable cyclone-timer*/102setup_summit();103return 1;104}105return 0;106}107108struct rio_table_hdr {109unsigned char version; /* Version number of this data structure */110/* Version 3 adds chassis_num & WP_index */111unsigned char num_scal_dev; /* # of Scalability devices (Twisters for Vigil) */112unsigned char num_rio_dev; /* # of RIO I/O devices (Cyclones and Winnipegs) */113} __attribute__((packed));114115struct scal_detail {116unsigned char node_id; /* Scalability Node ID */117unsigned long CBAR; /* Address of 1MB register space */118unsigned char port0node; /* Node ID port connected to: 0xFF=None */119unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */120unsigned char port1node; /* Node ID port connected to: 0xFF = None */121unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */122unsigned char port2node; /* Node ID port connected to: 0xFF = None */123unsigned char port2port; /* Port num port connected to: 0,1,2, or 0xFF=None */124unsigned char chassis_num; /* 1 based Chassis number (1 = boot node) */125} __attribute__((packed));126127struct rio_detail {128unsigned char node_id; /* RIO Node ID */129unsigned long BBAR; /* Address of 1MB register space */130unsigned char type; /* Type of device */131unsigned char owner_id; /* For WPEG: Node ID of Cyclone that owns this WPEG*/132/* For CYC: Node ID of Twister that owns this CYC */133unsigned char port0node; /* Node ID port connected to: 0xFF=None */134unsigned char port0port; /* Port num port connected to: 0,1,2, or 0xFF=None */135unsigned char port1node; /* Node ID port connected to: 0xFF=None */136unsigned char port1port; /* Port num port connected to: 0,1,2, or 0xFF=None */137unsigned char first_slot; /* For WPEG: Lowest slot number below this WPEG */138/* For CYC: 0 */139unsigned char status; /* For WPEG: Bit 0 = 1 : the XAPIC is used */140/* = 0 : the XAPIC is not used, ie:*/141/* ints fwded to another XAPIC */142/* Bits1:7 Reserved */143/* For CYC: Bits0:7 Reserved */144unsigned char WP_index; /* For WPEG: WPEG instance index - lower ones have */145/* lower slot numbers/PCI bus numbers */146/* For CYC: No meaning */147unsigned char chassis_num; /* 1 based Chassis number */148/* For LookOut WPEGs this field indicates the */149/* Expansion Chassis #, enumerated from Boot */150/* Node WPEG external port, then Boot Node CYC */151/* external port, then Next Vigil chassis WPEG */152/* external port, etc. */153/* Shared Lookouts have only 1 chassis number (the */154/* first one assigned) */155} __attribute__((packed));156157158typedef enum {159CompatTwister = 0, /* Compatibility Twister */160AltTwister = 1, /* Alternate Twister of internal 8-way */161CompatCyclone = 2, /* Compatibility Cyclone */162AltCyclone = 3, /* Alternate Cyclone of internal 8-way */163CompatWPEG = 4, /* Compatibility WPEG */164AltWPEG = 5, /* Second Planar WPEG */165LookOutAWPEG = 6, /* LookOut WPEG */166LookOutBWPEG = 7, /* LookOut WPEG */167} node_type;168169static inline int is_WPEG(struct rio_detail *rio){170return (rio->type == CompatWPEG || rio->type == AltWPEG ||171rio->type == LookOutAWPEG || rio->type == LookOutBWPEG);172}173174#define SUMMIT_APIC_DFR_VALUE (APIC_DFR_CLUSTER)175176static const struct cpumask *summit_target_cpus(void)177{178/* CPU_MASK_ALL (0xff) has undefined behaviour with179* dest_LowestPrio mode logical clustered apic interrupt routing180* Just start on cpu 0. IRQ balancing will spread load181*/182return cpumask_of(0);183}184185static unsigned long summit_check_apicid_used(physid_mask_t *map, int apicid)186{187return 0;188}189190/* we don't use the phys_cpu_present_map to indicate apicid presence */191static unsigned long summit_check_apicid_present(int bit)192{193return 1;194}195196static int summit_early_logical_apicid(int cpu)197{198int count = 0;199u8 my_id = early_per_cpu(x86_cpu_to_apicid, cpu);200u8 my_cluster = APIC_CLUSTER(my_id);201#ifdef CONFIG_SMP202u8 lid;203int i;204205/* Create logical APIC IDs by counting CPUs already in cluster. */206for (count = 0, i = nr_cpu_ids; --i >= 0; ) {207lid = early_per_cpu(x86_cpu_to_logical_apicid, i);208if (lid != BAD_APICID && APIC_CLUSTER(lid) == my_cluster)209++count;210}211#endif212/* We only have a 4 wide bitmap in cluster mode. If a deranged213* BIOS puts 5 CPUs in one APIC cluster, we're hosed. */214BUG_ON(count >= XAPIC_DEST_CPUS_SHIFT);215return my_cluster | (1UL << count);216}217218static void summit_init_apic_ldr(void)219{220int cpu = smp_processor_id();221unsigned long id = early_per_cpu(x86_cpu_to_logical_apicid, cpu);222unsigned long val;223224apic_write(APIC_DFR, SUMMIT_APIC_DFR_VALUE);225val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;226val |= SET_APIC_LOGICAL_ID(id);227apic_write(APIC_LDR, val);228}229230static int summit_apic_id_registered(void)231{232return 1;233}234235static void summit_setup_apic_routing(void)236{237printk("Enabling APIC mode: Summit. Using %d I/O APICs\n",238nr_ioapics);239}240241static int summit_cpu_present_to_apicid(int mps_cpu)242{243if (mps_cpu < nr_cpu_ids)244return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);245else246return BAD_APICID;247}248249static void summit_ioapic_phys_id_map(physid_mask_t *phys_id_map, physid_mask_t *retmap)250{251/* For clustered we don't have a good way to do this yet - hack */252physids_promote(0x0FL, retmap);253}254255static void summit_apicid_to_cpu_present(int apicid, physid_mask_t *retmap)256{257physid_set_mask_of_physid(0, retmap);258}259260static int summit_check_phys_apicid_present(int physical_apicid)261{262return 1;263}264265static unsigned int summit_cpu_mask_to_apicid(const struct cpumask *cpumask)266{267unsigned int round = 0;268int cpu, apicid = 0;269270/*271* The cpus in the mask must all be on the apic cluster.272*/273for_each_cpu(cpu, cpumask) {274int new_apicid = early_per_cpu(x86_cpu_to_logical_apicid, cpu);275276if (round && APIC_CLUSTER(apicid) != APIC_CLUSTER(new_apicid)) {277printk("%s: Not a valid mask!\n", __func__);278return BAD_APICID;279}280apicid |= new_apicid;281round++;282}283return apicid;284}285286static unsigned int summit_cpu_mask_to_apicid_and(const struct cpumask *inmask,287const struct cpumask *andmask)288{289int apicid = early_per_cpu(x86_cpu_to_logical_apicid, 0);290cpumask_var_t cpumask;291292if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))293return apicid;294295cpumask_and(cpumask, inmask, andmask);296cpumask_and(cpumask, cpumask, cpu_online_mask);297apicid = summit_cpu_mask_to_apicid(cpumask);298299free_cpumask_var(cpumask);300301return apicid;302}303304/*305* cpuid returns the value latched in the HW at reset, not the APIC ID306* register's value. For any box whose BIOS changes APIC IDs, like307* clustered APIC systems, we must use hard_smp_processor_id.308*309* See Intel's IA-32 SW Dev's Manual Vol2 under CPUID.310*/311static int summit_phys_pkg_id(int cpuid_apic, int index_msb)312{313return hard_smp_processor_id() >> index_msb;314}315316static int probe_summit(void)317{318/* probed later in mptable/ACPI hooks */319return 0;320}321322static void summit_vector_allocation_domain(int cpu, struct cpumask *retmask)323{324/* Careful. Some cpus do not strictly honor the set of cpus325* specified in the interrupt destination when using lowest326* priority interrupt delivery mode.327*328* In particular there was a hyperthreading cpu observed to329* deliver interrupts to the wrong hyperthread when only one330* hyperthread was specified in the interrupt desitination.331*/332cpumask_clear(retmask);333cpumask_bits(retmask)[0] = APIC_ALL_CPUS;334}335336#ifdef CONFIG_X86_SUMMIT_NUMA337static struct rio_table_hdr *rio_table_hdr;338static struct scal_detail *scal_devs[MAX_NUMNODES];339static struct rio_detail *rio_devs[MAX_NUMNODES*4];340341#ifndef CONFIG_X86_NUMAQ342static int mp_bus_id_to_node[MAX_MP_BUSSES];343#endif344345static int setup_pci_node_map_for_wpeg(int wpeg_num, int last_bus)346{347int twister = 0, node = 0;348int i, bus, num_buses;349350for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {351if (rio_devs[i]->node_id == rio_devs[wpeg_num]->owner_id) {352twister = rio_devs[i]->owner_id;353break;354}355}356if (i == rio_table_hdr->num_rio_dev) {357printk(KERN_ERR "%s: Couldn't find owner Cyclone for Winnipeg!\n", __func__);358return last_bus;359}360361for (i = 0; i < rio_table_hdr->num_scal_dev; i++) {362if (scal_devs[i]->node_id == twister) {363node = scal_devs[i]->node_id;364break;365}366}367if (i == rio_table_hdr->num_scal_dev) {368printk(KERN_ERR "%s: Couldn't find owner Twister for Cyclone!\n", __func__);369return last_bus;370}371372switch (rio_devs[wpeg_num]->type) {373case CompatWPEG:374/*375* The Compatibility Winnipeg controls the 2 legacy buses,376* the 66MHz PCI bus [2 slots] and the 2 "extra" buses in case377* a PCI-PCI bridge card is used in either slot: total 5 buses.378*/379num_buses = 5;380break;381case AltWPEG:382/*383* The Alternate Winnipeg controls the 2 133MHz buses [1 slot384* each], their 2 "extra" buses, the 100MHz bus [2 slots] and385* the "extra" buses for each of those slots: total 7 buses.386*/387num_buses = 7;388break;389case LookOutAWPEG:390case LookOutBWPEG:391/*392* A Lookout Winnipeg controls 3 100MHz buses [2 slots each]393* & the "extra" buses for each of those slots: total 9 buses.394*/395num_buses = 9;396break;397default:398printk(KERN_INFO "%s: Unsupported Winnipeg type!\n", __func__);399return last_bus;400}401402for (bus = last_bus; bus < last_bus + num_buses; bus++)403mp_bus_id_to_node[bus] = node;404return bus;405}406407static int build_detail_arrays(void)408{409unsigned long ptr;410int i, scal_detail_size, rio_detail_size;411412if (rio_table_hdr->num_scal_dev > MAX_NUMNODES) {413printk(KERN_WARNING "%s: MAX_NUMNODES too low! Defined as %d, but system has %d nodes.\n", __func__, MAX_NUMNODES, rio_table_hdr->num_scal_dev);414return 0;415}416417switch (rio_table_hdr->version) {418default:419printk(KERN_WARNING "%s: Invalid Rio Grande Table Version: %d\n", __func__, rio_table_hdr->version);420return 0;421case 2:422scal_detail_size = 11;423rio_detail_size = 13;424break;425case 3:426scal_detail_size = 12;427rio_detail_size = 15;428break;429}430431ptr = (unsigned long)rio_table_hdr + 3;432for (i = 0; i < rio_table_hdr->num_scal_dev; i++, ptr += scal_detail_size)433scal_devs[i] = (struct scal_detail *)ptr;434435for (i = 0; i < rio_table_hdr->num_rio_dev; i++, ptr += rio_detail_size)436rio_devs[i] = (struct rio_detail *)ptr;437438return 1;439}440441void setup_summit(void)442{443unsigned long ptr;444unsigned short offset;445int i, next_wpeg, next_bus = 0;446447/* The pointer to the EBDA is stored in the word @ phys 0x40E(40:0E) */448ptr = get_bios_ebda();449ptr = (unsigned long)phys_to_virt(ptr);450451rio_table_hdr = NULL;452offset = 0x180;453while (offset) {454/* The block id is stored in the 2nd word */455if (*((unsigned short *)(ptr + offset + 2)) == 0x4752) {456/* set the pointer past the offset & block id */457rio_table_hdr = (struct rio_table_hdr *)(ptr + offset + 4);458break;459}460/* The next offset is stored in the 1st word. 0 means no more */461offset = *((unsigned short *)(ptr + offset));462}463if (!rio_table_hdr) {464printk(KERN_ERR "%s: Unable to locate Rio Grande Table in EBDA - bailing!\n", __func__);465return;466}467468if (!build_detail_arrays())469return;470471/* The first Winnipeg we're looking for has an index of 0 */472next_wpeg = 0;473do {474for (i = 0; i < rio_table_hdr->num_rio_dev; i++) {475if (is_WPEG(rio_devs[i]) && rio_devs[i]->WP_index == next_wpeg) {476/* It's the Winnipeg we're looking for! */477next_bus = setup_pci_node_map_for_wpeg(i, next_bus);478next_wpeg++;479break;480}481}482/*483* If we go through all Rio devices and don't find one with484* the next index, it means we've found all the Winnipegs,485* and thus all the PCI buses.486*/487if (i == rio_table_hdr->num_rio_dev)488next_wpeg = 0;489} while (next_wpeg != 0);490}491#endif492493static struct apic apic_summit = {494495.name = "summit",496.probe = probe_summit,497.acpi_madt_oem_check = summit_acpi_madt_oem_check,498.apic_id_registered = summit_apic_id_registered,499500.irq_delivery_mode = dest_LowestPrio,501/* logical delivery broadcast to all CPUs: */502.irq_dest_mode = 1,503504.target_cpus = summit_target_cpus,505.disable_esr = 1,506.dest_logical = APIC_DEST_LOGICAL,507.check_apicid_used = summit_check_apicid_used,508.check_apicid_present = summit_check_apicid_present,509510.vector_allocation_domain = summit_vector_allocation_domain,511.init_apic_ldr = summit_init_apic_ldr,512513.ioapic_phys_id_map = summit_ioapic_phys_id_map,514.setup_apic_routing = summit_setup_apic_routing,515.multi_timer_check = NULL,516.cpu_present_to_apicid = summit_cpu_present_to_apicid,517.apicid_to_cpu_present = summit_apicid_to_cpu_present,518.setup_portio_remap = NULL,519.check_phys_apicid_present = summit_check_phys_apicid_present,520.enable_apic_mode = NULL,521.phys_pkg_id = summit_phys_pkg_id,522.mps_oem_check = summit_mps_oem_check,523524.get_apic_id = summit_get_apic_id,525.set_apic_id = NULL,526.apic_id_mask = 0xFF << 24,527528.cpu_mask_to_apicid = summit_cpu_mask_to_apicid,529.cpu_mask_to_apicid_and = summit_cpu_mask_to_apicid_and,530531.send_IPI_mask = summit_send_IPI_mask,532.send_IPI_mask_allbutself = NULL,533.send_IPI_allbutself = summit_send_IPI_allbutself,534.send_IPI_all = summit_send_IPI_all,535.send_IPI_self = default_send_IPI_self,536537.trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,538.trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,539540.wait_for_init_deassert = default_wait_for_init_deassert,541542.smp_callin_clear_local_apic = NULL,543.inquire_remote_apic = default_inquire_remote_apic,544545.read = native_apic_mem_read,546.write = native_apic_mem_write,547.icr_read = native_apic_icr_read,548.icr_write = native_apic_icr_write,549.wait_icr_idle = native_apic_wait_icr_idle,550.safe_wait_icr_idle = native_safe_apic_wait_icr_idle,551552.x86_32_early_logical_apicid = summit_early_logical_apicid,553};554555apic_driver(apic_summit);556557558