Path: blob/master/arch/powerpc/platforms/pseries/setup.c
10818 views
/*1* 64-bit pSeries and RS/6000 setup code.2*3* Copyright (C) 1995 Linus Torvalds4* Adapted from 'alpha' version by Gary Thomas5* Modified by Cort Dougan ([email protected])6* Modified by PPC64 Team, IBM Corp7*8* This program is free software; you can redistribute it and/or9* modify it under the terms of the GNU General Public License10* as published by the Free Software Foundation; either version11* 2 of the License, or (at your option) any later version.12*/1314/*15* bootup setup stuff..16*/1718#include <linux/cpu.h>19#include <linux/errno.h>20#include <linux/sched.h>21#include <linux/kernel.h>22#include <linux/mm.h>23#include <linux/stddef.h>24#include <linux/unistd.h>25#include <linux/user.h>26#include <linux/tty.h>27#include <linux/major.h>28#include <linux/interrupt.h>29#include <linux/reboot.h>30#include <linux/init.h>31#include <linux/ioport.h>32#include <linux/console.h>33#include <linux/pci.h>34#include <linux/utsname.h>35#include <linux/adb.h>36#include <linux/module.h>37#include <linux/delay.h>38#include <linux/irq.h>39#include <linux/seq_file.h>40#include <linux/root_dev.h>4142#include <asm/mmu.h>43#include <asm/processor.h>44#include <asm/io.h>45#include <asm/pgtable.h>46#include <asm/prom.h>47#include <asm/rtas.h>48#include <asm/pci-bridge.h>49#include <asm/iommu.h>50#include <asm/dma.h>51#include <asm/machdep.h>52#include <asm/irq.h>53#include <asm/time.h>54#include <asm/nvram.h>55#include <asm/pmc.h>56#include <asm/mpic.h>57#include <asm/xics.h>58#include <asm/ppc-pci.h>59#include <asm/i8259.h>60#include <asm/udbg.h>61#include <asm/smp.h>62#include <asm/firmware.h>63#include <asm/eeh.h>64#include <asm/pSeries_reconfig.h>6566#include "plpar_wrappers.h"67#include "pseries.h"6869int CMO_PrPSP = -1;70int CMO_SecPSP = -1;71unsigned long CMO_PageSize = (ASM_CONST(1) << IOMMU_PAGE_SHIFT);72EXPORT_SYMBOL(CMO_PageSize);7374int fwnmi_active; /* TRUE if an FWNMI handler is present */7576static void pseries_shared_idle_sleep(void);77static void pseries_dedicated_idle_sleep(void);7879static struct device_node *pSeries_mpic_node;8081static void pSeries_show_cpuinfo(struct seq_file *m)82{83struct device_node *root;84const char *model = "";8586root = of_find_node_by_path("/");87if (root)88model = of_get_property(root, "model", NULL);89seq_printf(m, "machine\t\t: CHRP %s\n", model);90of_node_put(root);91}9293/* Initialize firmware assisted non-maskable interrupts if94* the firmware supports this feature.95*/96static void __init fwnmi_init(void)97{98unsigned long system_reset_addr, machine_check_addr;99100int ibm_nmi_register = rtas_token("ibm,nmi-register");101if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)102return;103104/* If the kernel's not linked at zero we point the firmware at low105* addresses anyway, and use a trampoline to get to the real code. */106system_reset_addr = __pa(system_reset_fwnmi) - PHYSICAL_START;107machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;108109if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,110machine_check_addr))111fwnmi_active = 1;112}113114static void pseries_8259_cascade(unsigned int irq, struct irq_desc *desc)115{116struct irq_chip *chip = irq_desc_get_chip(desc);117unsigned int cascade_irq = i8259_irq();118119if (cascade_irq != NO_IRQ)120generic_handle_irq(cascade_irq);121122chip->irq_eoi(&desc->irq_data);123}124125static void __init pseries_setup_i8259_cascade(void)126{127struct device_node *np, *old, *found = NULL;128unsigned int cascade;129const u32 *addrp;130unsigned long intack = 0;131int naddr;132133for_each_node_by_type(np, "interrupt-controller") {134if (of_device_is_compatible(np, "chrp,iic")) {135found = np;136break;137}138}139140if (found == NULL) {141printk(KERN_DEBUG "pic: no ISA interrupt controller\n");142return;143}144145cascade = irq_of_parse_and_map(found, 0);146if (cascade == NO_IRQ) {147printk(KERN_ERR "pic: failed to map cascade interrupt");148return;149}150pr_debug("pic: cascade mapped to irq %d\n", cascade);151152for (old = of_node_get(found); old != NULL ; old = np) {153np = of_get_parent(old);154of_node_put(old);155if (np == NULL)156break;157if (strcmp(np->name, "pci") != 0)158continue;159addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);160if (addrp == NULL)161continue;162naddr = of_n_addr_cells(np);163intack = addrp[naddr-1];164if (naddr > 1)165intack |= ((unsigned long)addrp[naddr-2]) << 32;166}167if (intack)168printk(KERN_DEBUG "pic: PCI 8259 intack at 0x%016lx\n", intack);169i8259_init(found, intack);170of_node_put(found);171irq_set_chained_handler(cascade, pseries_8259_cascade);172}173174static void __init pseries_mpic_init_IRQ(void)175{176struct device_node *np;177const unsigned int *opprop;178unsigned long openpic_addr = 0;179int naddr, n, i, opplen;180struct mpic *mpic;181182np = of_find_node_by_path("/");183naddr = of_n_addr_cells(np);184opprop = of_get_property(np, "platform-open-pic", &opplen);185if (opprop != 0) {186openpic_addr = of_read_number(opprop, naddr);187printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);188}189of_node_put(np);190191BUG_ON(openpic_addr == 0);192193/* Setup the openpic driver */194mpic = mpic_alloc(pSeries_mpic_node, openpic_addr,195MPIC_PRIMARY,19616, 250, /* isu size, irq count */197" MPIC ");198BUG_ON(mpic == NULL);199200/* Add ISUs */201opplen /= sizeof(u32);202for (n = 0, i = naddr; i < opplen; i += naddr, n++) {203unsigned long isuaddr = of_read_number(opprop + i, naddr);204mpic_assign_isu(mpic, n, isuaddr);205}206207/* Setup top-level get_irq */208ppc_md.get_irq = mpic_get_irq;209210/* All ISUs are setup, complete initialization */211mpic_init(mpic);212213/* Look for cascade */214pseries_setup_i8259_cascade();215}216217static void __init pseries_xics_init_IRQ(void)218{219xics_init();220pseries_setup_i8259_cascade();221}222223static void pseries_lpar_enable_pmcs(void)224{225unsigned long set, reset;226227set = 1UL << 63;228reset = 0;229plpar_hcall_norets(H_PERFMON, set, reset);230}231232static void __init pseries_discover_pic(void)233{234struct device_node *np;235const char *typep;236237for (np = NULL; (np = of_find_node_by_name(np,238"interrupt-controller"));) {239typep = of_get_property(np, "compatible", NULL);240if (strstr(typep, "open-pic")) {241pSeries_mpic_node = of_node_get(np);242ppc_md.init_IRQ = pseries_mpic_init_IRQ;243setup_kexec_cpu_down_mpic();244smp_init_pseries_mpic();245return;246} else if (strstr(typep, "ppc-xicp")) {247ppc_md.init_IRQ = pseries_xics_init_IRQ;248setup_kexec_cpu_down_xics();249smp_init_pseries_xics();250return;251}252}253printk(KERN_ERR "pSeries_discover_pic: failed to recognize"254" interrupt-controller\n");255}256257static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)258{259struct device_node *np = node;260struct pci_dn *pci = NULL;261int err = NOTIFY_OK;262263switch (action) {264case PSERIES_RECONFIG_ADD:265pci = np->parent->data;266if (pci)267update_dn_pci_info(np, pci->phb);268break;269default:270err = NOTIFY_DONE;271break;272}273return err;274}275276static struct notifier_block pci_dn_reconfig_nb = {277.notifier_call = pci_dn_reconfig_notifier,278};279280struct kmem_cache *dtl_cache;281282#ifdef CONFIG_VIRT_CPU_ACCOUNTING283/*284* Allocate space for the dispatch trace log for all possible cpus285* and register the buffers with the hypervisor. This is used for286* computing time stolen by the hypervisor.287*/288static int alloc_dispatch_logs(void)289{290int cpu, ret;291struct paca_struct *pp;292struct dtl_entry *dtl;293294if (!firmware_has_feature(FW_FEATURE_SPLPAR))295return 0;296297if (!dtl_cache)298return 0;299300for_each_possible_cpu(cpu) {301pp = &paca[cpu];302dtl = kmem_cache_alloc(dtl_cache, GFP_KERNEL);303if (!dtl) {304pr_warn("Failed to allocate dispatch trace log for cpu %d\n",305cpu);306pr_warn("Stolen time statistics will be unreliable\n");307break;308}309310pp->dtl_ridx = 0;311pp->dispatch_log = dtl;312pp->dispatch_log_end = dtl + N_DISPATCH_LOG;313pp->dtl_curr = dtl;314}315316/* Register the DTL for the current (boot) cpu */317dtl = get_paca()->dispatch_log;318get_paca()->dtl_ridx = 0;319get_paca()->dtl_curr = dtl;320get_paca()->lppaca_ptr->dtl_idx = 0;321322/* hypervisor reads buffer length from this field */323dtl->enqueue_to_dispatch_time = DISPATCH_LOG_BYTES;324ret = register_dtl(hard_smp_processor_id(), __pa(dtl));325if (ret)326pr_warn("DTL registration failed for boot cpu %d (%d)\n",327smp_processor_id(), ret);328get_paca()->lppaca_ptr->dtl_enable_mask = 2;329330return 0;331}332#else /* !CONFIG_VIRT_CPU_ACCOUNTING */333static inline int alloc_dispatch_logs(void)334{335return 0;336}337#endif /* CONFIG_VIRT_CPU_ACCOUNTING */338339static int alloc_dispatch_log_kmem_cache(void)340{341dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES,342DISPATCH_LOG_BYTES, 0, NULL);343if (!dtl_cache) {344pr_warn("Failed to create dispatch trace log buffer cache\n");345pr_warn("Stolen time statistics will be unreliable\n");346return 0;347}348349return alloc_dispatch_logs();350}351early_initcall(alloc_dispatch_log_kmem_cache);352353static void __init pSeries_setup_arch(void)354{355/* Discover PIC type and setup ppc_md accordingly */356pseries_discover_pic();357358/* openpic global configuration register (64-bit format). */359/* openpic Interrupt Source Unit pointer (64-bit format). */360/* python0 facility area (mmio) (64-bit format) REAL address. */361362/* init to some ~sane value until calibrate_delay() runs */363loops_per_jiffy = 50000000;364365fwnmi_init();366367/* Find and initialize PCI host bridges */368init_pci_config_tokens();369find_and_init_phbs();370pSeries_reconfig_notifier_register(&pci_dn_reconfig_nb);371eeh_init();372373pSeries_nvram_init();374375/* Choose an idle loop */376if (firmware_has_feature(FW_FEATURE_SPLPAR)) {377vpa_init(boot_cpuid);378if (get_lppaca()->shared_proc) {379printk(KERN_DEBUG "Using shared processor idle loop\n");380ppc_md.power_save = pseries_shared_idle_sleep;381} else {382printk(KERN_DEBUG "Using dedicated idle loop\n");383ppc_md.power_save = pseries_dedicated_idle_sleep;384}385} else {386printk(KERN_DEBUG "Using default idle loop\n");387}388389if (firmware_has_feature(FW_FEATURE_LPAR))390ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;391else392ppc_md.enable_pmcs = power4_enable_pmcs;393}394395static int __init pSeries_init_panel(void)396{397/* Manually leave the kernel version on the panel. */398ppc_md.progress("Linux ppc64\n", 0);399ppc_md.progress(init_utsname()->version, 0);400401return 0;402}403machine_arch_initcall(pseries, pSeries_init_panel);404405static int pseries_set_dabr(unsigned long dabr)406{407return plpar_hcall_norets(H_SET_DABR, dabr);408}409410static int pseries_set_xdabr(unsigned long dabr)411{412/* We want to catch accesses from kernel and userspace */413return plpar_hcall_norets(H_SET_XDABR, dabr,414H_DABRX_KERNEL | H_DABRX_USER);415}416417#define CMO_CHARACTERISTICS_TOKEN 44418#define CMO_MAXLENGTH 1026419420void pSeries_coalesce_init(void)421{422struct hvcall_mpp_x_data mpp_x_data;423424if (firmware_has_feature(FW_FEATURE_CMO) && !h_get_mpp_x(&mpp_x_data))425powerpc_firmware_features |= FW_FEATURE_XCMO;426else427powerpc_firmware_features &= ~FW_FEATURE_XCMO;428}429430/**431* fw_cmo_feature_init - FW_FEATURE_CMO is not stored in ibm,hypertas-functions,432* handle that here. (Stolen from parse_system_parameter_string)433*/434void pSeries_cmo_feature_init(void)435{436char *ptr, *key, *value, *end;437int call_status;438int page_order = IOMMU_PAGE_SHIFT;439440pr_debug(" -> fw_cmo_feature_init()\n");441spin_lock(&rtas_data_buf_lock);442memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE);443call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,444NULL,445CMO_CHARACTERISTICS_TOKEN,446__pa(rtas_data_buf),447RTAS_DATA_BUF_SIZE);448449if (call_status != 0) {450spin_unlock(&rtas_data_buf_lock);451pr_debug("CMO not available\n");452pr_debug(" <- fw_cmo_feature_init()\n");453return;454}455456end = rtas_data_buf + CMO_MAXLENGTH - 2;457ptr = rtas_data_buf + 2; /* step over strlen value */458key = value = ptr;459460while (*ptr && (ptr <= end)) {461/* Separate the key and value by replacing '=' with '\0' and462* point the value at the string after the '='463*/464if (ptr[0] == '=') {465ptr[0] = '\0';466value = ptr + 1;467} else if (ptr[0] == '\0' || ptr[0] == ',') {468/* Terminate the string containing the key/value pair */469ptr[0] = '\0';470471if (key == value) {472pr_debug("Malformed key/value pair\n");473/* Never found a '=', end processing */474break;475}476477if (0 == strcmp(key, "CMOPageSize"))478page_order = simple_strtol(value, NULL, 10);479else if (0 == strcmp(key, "PrPSP"))480CMO_PrPSP = simple_strtol(value, NULL, 10);481else if (0 == strcmp(key, "SecPSP"))482CMO_SecPSP = simple_strtol(value, NULL, 10);483value = key = ptr + 1;484}485ptr++;486}487488/* Page size is returned as the power of 2 of the page size,489* convert to the page size in bytes before returning490*/491CMO_PageSize = 1 << page_order;492pr_debug("CMO_PageSize = %lu\n", CMO_PageSize);493494if (CMO_PrPSP != -1 || CMO_SecPSP != -1) {495pr_info("CMO enabled\n");496pr_debug("CMO enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,497CMO_SecPSP);498powerpc_firmware_features |= FW_FEATURE_CMO;499pSeries_coalesce_init();500} else501pr_debug("CMO not enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,502CMO_SecPSP);503spin_unlock(&rtas_data_buf_lock);504pr_debug(" <- fw_cmo_feature_init()\n");505}506507/*508* Early initialization. Relocation is on but do not reference unbolted pages509*/510static void __init pSeries_init_early(void)511{512pr_debug(" -> pSeries_init_early()\n");513514if (firmware_has_feature(FW_FEATURE_LPAR))515find_udbg_vterm();516517if (firmware_has_feature(FW_FEATURE_DABR))518ppc_md.set_dabr = pseries_set_dabr;519else if (firmware_has_feature(FW_FEATURE_XDABR))520ppc_md.set_dabr = pseries_set_xdabr;521522pSeries_cmo_feature_init();523iommu_init_early_pSeries();524525pr_debug(" <- pSeries_init_early()\n");526}527528/*529* Called very early, MMU is off, device-tree isn't unflattened530*/531532static int __init pSeries_probe_hypertas(unsigned long node,533const char *uname, int depth,534void *data)535{536const char *hypertas;537unsigned long len;538539if (depth != 1 ||540(strcmp(uname, "rtas") != 0 && strcmp(uname, "rtas@0") != 0))541return 0;542543hypertas = of_get_flat_dt_prop(node, "ibm,hypertas-functions", &len);544if (!hypertas)545return 1;546547powerpc_firmware_features |= FW_FEATURE_LPAR;548fw_feature_init(hypertas, len);549550return 1;551}552553static int __init pSeries_probe(void)554{555unsigned long root = of_get_flat_dt_root();556char *dtype = of_get_flat_dt_prop(root, "device_type", NULL);557558if (dtype == NULL)559return 0;560if (strcmp(dtype, "chrp"))561return 0;562563/* Cell blades firmware claims to be chrp while it's not. Until this564* is fixed, we need to avoid those here.565*/566if (of_flat_dt_is_compatible(root, "IBM,CPBW-1.0") ||567of_flat_dt_is_compatible(root, "IBM,CBEA"))568return 0;569570pr_debug("pSeries detected, looking for LPAR capability...\n");571572/* Now try to figure out if we are running on LPAR */573of_scan_flat_dt(pSeries_probe_hypertas, NULL);574575if (firmware_has_feature(FW_FEATURE_LPAR))576hpte_init_lpar();577else578hpte_init_native();579580pr_debug("Machine is%s LPAR !\n",581(powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");582583return 1;584}585586587DECLARE_PER_CPU(long, smt_snooze_delay);588589static void pseries_dedicated_idle_sleep(void)590{591unsigned int cpu = smp_processor_id();592unsigned long start_snooze;593unsigned long in_purr, out_purr;594long snooze = __get_cpu_var(smt_snooze_delay);595596/*597* Indicate to the HV that we are idle. Now would be598* a good time to find other work to dispatch.599*/600get_lppaca()->idle = 1;601get_lppaca()->donate_dedicated_cpu = 1;602in_purr = mfspr(SPRN_PURR);603604/*605* We come in with interrupts disabled, and need_resched()606* has been checked recently. If we should poll for a little607* while, do so.608*/609if (snooze) {610start_snooze = get_tb() + snooze * tb_ticks_per_usec;611local_irq_enable();612set_thread_flag(TIF_POLLING_NRFLAG);613614while ((snooze < 0) || (get_tb() < start_snooze)) {615if (need_resched() || cpu_is_offline(cpu))616goto out;617ppc64_runlatch_off();618HMT_low();619HMT_very_low();620}621622HMT_medium();623clear_thread_flag(TIF_POLLING_NRFLAG);624smp_mb();625local_irq_disable();626if (need_resched() || cpu_is_offline(cpu))627goto out;628}629630cede_processor();631632out:633HMT_medium();634out_purr = mfspr(SPRN_PURR);635get_lppaca()->wait_state_cycles += out_purr - in_purr;636get_lppaca()->donate_dedicated_cpu = 0;637get_lppaca()->idle = 0;638}639640static void pseries_shared_idle_sleep(void)641{642/*643* Indicate to the HV that we are idle. Now would be644* a good time to find other work to dispatch.645*/646get_lppaca()->idle = 1;647648/*649* Yield the processor to the hypervisor. We return if650* an external interrupt occurs (which are driven prior651* to returning here) or if a prod occurs from another652* processor. When returning here, external interrupts653* are enabled.654*/655cede_processor();656657get_lppaca()->idle = 0;658}659660static int pSeries_pci_probe_mode(struct pci_bus *bus)661{662if (firmware_has_feature(FW_FEATURE_LPAR))663return PCI_PROBE_DEVTREE;664return PCI_PROBE_NORMAL;665}666667/**668* pSeries_power_off - tell firmware about how to power off the system.669*670* This function calls either the power-off rtas token in normal cases671* or the ibm,power-off-ups token (if present & requested) in case of672* a power failure. If power-off token is used, power on will only be673* possible with power button press. If ibm,power-off-ups token is used674* it will allow auto poweron after power is restored.675*/676static void pSeries_power_off(void)677{678int rc;679int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");680681if (rtas_flash_term_hook)682rtas_flash_term_hook(SYS_POWER_OFF);683684if (rtas_poweron_auto == 0 ||685rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {686rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);687printk(KERN_INFO "RTAS power-off returned %d\n", rc);688} else {689rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);690printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);691}692for (;;);693}694695#ifndef CONFIG_PCI696void pSeries_final_fixup(void) { }697#endif698699define_machine(pseries) {700.name = "pSeries",701.probe = pSeries_probe,702.setup_arch = pSeries_setup_arch,703.init_early = pSeries_init_early,704.show_cpuinfo = pSeries_show_cpuinfo,705.log_error = pSeries_log_error,706.pcibios_fixup = pSeries_final_fixup,707.pci_probe_mode = pSeries_pci_probe_mode,708.restart = rtas_restart,709.power_off = pSeries_power_off,710.halt = rtas_halt,711.panic = rtas_os_term,712.get_boot_time = rtas_get_boot_time,713.get_rtc_time = rtas_get_rtc_time,714.set_rtc_time = rtas_set_rtc_time,715.calibrate_decr = generic_calibrate_decr,716.progress = rtas_progress,717.system_reset_exception = pSeries_system_reset_exception,718.machine_check_exception = pSeries_machine_check_exception,719};720721722