[POWERPC] Convert from DBG() to pr_debug() in platforms/pseries/
[safe/jmp/linux-2.6] / arch / powerpc / platforms / pseries / setup.c
index 54a5243..65e8795 100644 (file)
@@ -55,7 +55,6 @@
 #include <asm/dma.h>
 #include <asm/machdep.h>
 #include <asm/irq.h>
-#include <asm/kexec.h>
 #include <asm/time.h>
 #include <asm/nvram.h>
 #include "xics.h"
 #include <asm/i8259.h>
 #include <asm/udbg.h>
 #include <asm/smp.h>
+#include <asm/firmware.h>
+#include <asm/eeh.h>
 
 #include "plpar_wrappers.h"
-#include "ras.h"
-#include "firmware.h"
+#include "pseries.h"
 
-#ifdef DEBUG
-#define DBG(fmt...) udbg_printf(fmt)
-#else
-#define DBG(fmt...)
-#endif
-
-/* move those away to a .h */
-extern void smp_init_pseries_mpic(void);
-extern void smp_init_pseries_xics(void);
-extern void find_udbg_vterm(void);
 
 int fwnmi_active;  /* TRUE if an FWNMI handler is present */
 
@@ -95,7 +85,7 @@ static void pSeries_show_cpuinfo(struct seq_file *m)
 
        root = of_find_node_by_path("/");
        if (root)
-               model = get_property(root, "model", NULL);
+               model = of_get_property(root, "model", NULL);
        seq_printf(m, "machine\t\t: CHRP %s\n", model);
        of_node_put(root);
 }
@@ -121,29 +111,74 @@ static void __init fwnmi_init(void)
                fwnmi_active = 1;
 }
 
-void pseries_8259_cascade(unsigned int irq, struct irq_desc *desc,
-                         struct pt_regs *regs)
+void pseries_8259_cascade(unsigned int irq, struct irq_desc *desc)
 {
-       unsigned int cascade_irq = i8259_irq(regs);
+       unsigned int cascade_irq = i8259_irq();
        if (cascade_irq != NO_IRQ)
-               generic_handle_irq(cascade_irq, regs);
+               generic_handle_irq(cascade_irq);
        desc->chip->eoi(irq);
 }
 
-static void __init pseries_mpic_init_IRQ(void)
+static void __init pseries_setup_i8259_cascade(void)
 {
-       struct device_node *np, *old, *cascade = NULL;
-        unsigned int *addrp;
+       struct device_node *np, *old, *found = NULL;
+       unsigned int cascade;
+       const u32 *addrp;
        unsigned long intack = 0;
-       unsigned int *opprop;
+       int naddr;
+
+       for_each_node_by_type(np, "interrupt-controller") {
+               if (of_device_is_compatible(np, "chrp,iic")) {
+                       found = np;
+                       break;
+               }
+       }
+
+       if (found == NULL) {
+               printk(KERN_DEBUG "pic: no ISA interrupt controller\n");
+               return;
+       }
+
+       cascade = irq_of_parse_and_map(found, 0);
+       if (cascade == NO_IRQ) {
+               printk(KERN_ERR "pic: failed to map cascade interrupt");
+               return;
+       }
+       pr_debug("pic: cascade mapped to irq %d\n", cascade);
+
+       for (old = of_node_get(found); old != NULL ; old = np) {
+               np = of_get_parent(old);
+               of_node_put(old);
+               if (np == NULL)
+                       break;
+               if (strcmp(np->name, "pci") != 0)
+                       continue;
+               addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
+               if (addrp == NULL)
+                       continue;
+               naddr = of_n_addr_cells(np);
+               intack = addrp[naddr-1];
+               if (naddr > 1)
+                       intack |= ((unsigned long)addrp[naddr-2]) << 32;
+       }
+       if (intack)
+               printk(KERN_DEBUG "pic: PCI 8259 intack at 0x%016lx\n", intack);
+       i8259_init(found, intack);
+       of_node_put(found);
+       set_irq_chained_handler(cascade, pseries_8259_cascade);
+}
+
+static void __init pseries_mpic_init_IRQ(void)
+{
+       struct device_node *np;
+       const unsigned int *opprop;
        unsigned long openpic_addr = 0;
-       unsigned int cascade_irq;
        int naddr, n, i, opplen;
        struct mpic *mpic;
 
        np = of_find_node_by_path("/");
-       naddr = prom_n_addr_cells(np);
-       opprop = (unsigned int *) get_property(np, "platform-open-pic", &opplen);
+       naddr = of_n_addr_cells(np);
+       opprop = of_get_property(np, "platform-open-pic", &opplen);
        if (opprop != 0) {
                openpic_addr = of_read_number(opprop, naddr);
                printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
@@ -170,51 +205,19 @@ static void __init pseries_mpic_init_IRQ(void)
        mpic_init(mpic);
 
        /* Look for cascade */
-       for_each_node_by_type(np, "interrupt-controller")
-               if (device_is_compatible(np, "chrp,iic")) {
-                       cascade = np;
-                       break;
-               }
-       if (cascade == NULL)
-               return;
-
-       cascade_irq = irq_of_parse_and_map(cascade, 0);
-       if (cascade == NO_IRQ) {
-               printk(KERN_ERR "xics: failed to map cascade interrupt");
-               return;
-       }
+       pseries_setup_i8259_cascade();
+}
 
-       /* Check ACK type */
-       for (old = of_node_get(cascade); old != NULL ; old = np) {
-               np = of_get_parent(old);
-               of_node_put(old);
-               if (np == NULL)
-                       break;
-               if (strcmp(np->name, "pci") != 0)
-                       continue;
-               addrp = (u32 *)get_property(np, "8259-interrupt-acknowledge",
-                                           NULL);
-               if (addrp == NULL)
-                       continue;
-               naddr = prom_n_addr_cells(np);
-               intack = addrp[naddr-1];
-               if (naddr > 1)
-                       intack |= ((unsigned long)addrp[naddr-2]) << 32;
-       }
-       if (intack)
-               printk(KERN_DEBUG "mpic: PCI 8259 intack at 0x%016lx\n",
-                      intack);
-       i8259_init(cascade, intack);
-       of_node_put(cascade);
-       set_irq_chained_handler(cascade_irq, pseries_8259_cascade);
+static void __init pseries_xics_init_IRQ(void)
+{
+       xics_init_IRQ();
+       pseries_setup_i8259_cascade();
 }
 
 static void pseries_lpar_enable_pmcs(void)
 {
        unsigned long set, reset;
 
-       power4_enable_pmcs();
-
        set = 1UL << 63;
        reset = 0;
        plpar_hcall_norets(H_PERFMON, set, reset);
@@ -224,55 +227,25 @@ static void pseries_lpar_enable_pmcs(void)
                get_lppaca()->pmcregs_in_use = 1;
 }
 
-#ifdef CONFIG_KEXEC
-static void pseries_kexec_cpu_down_mpic(int crash_shutdown, int secondary)
-{
-       mpic_teardown_this_cpu(secondary);
-}
-
-static void pseries_kexec_cpu_down_xics(int crash_shutdown, int secondary)
-{
-       /* Don't risk a hypervisor call if we're crashing */
-       if (firmware_has_feature(FW_FEATURE_SPLPAR) && !crash_shutdown) {
-               unsigned long vpa = __pa(get_lppaca());
-
-               if (unregister_vpa(hard_smp_processor_id(), vpa)) {
-                       printk("VPA deregistration of cpu %u (hw_cpu_id %d) "
-                                       "failed\n", smp_processor_id(),
-                                       hard_smp_processor_id());
-               }
-       }
-       xics_teardown_cpu(secondary);
-}
-#endif /* CONFIG_KEXEC */
-
 static void __init pseries_discover_pic(void)
 {
        struct device_node *np;
-       char *typep;
+       const char *typep;
 
        for (np = NULL; (np = of_find_node_by_name(np,
                                                   "interrupt-controller"));) {
-               typep = (char *)get_property(np, "compatible", NULL);
+               typep = of_get_property(np, "compatible", NULL);
                if (strstr(typep, "open-pic")) {
                        pSeries_mpic_node = of_node_get(np);
                        ppc_md.init_IRQ       = pseries_mpic_init_IRQ;
                        ppc_md.get_irq        = mpic_get_irq;
-#ifdef CONFIG_KEXEC
-                       ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_mpic;
-#endif
-#ifdef CONFIG_SMP
+                       setup_kexec_cpu_down_mpic();
                        smp_init_pseries_mpic();
-#endif
                        return;
                } else if (strstr(typep, "ppc-xicp")) {
-                       ppc_md.init_IRQ       = xics_init_IRQ;
-#ifdef CONFIG_KEXEC
-                       ppc_md.kexec_cpu_down = pseries_kexec_cpu_down_xics;
-#endif
-#ifdef CONFIG_SMP
+                       ppc_md.init_IRQ       = pseries_xics_init_IRQ;
+                       setup_kexec_cpu_down_xics();
                        smp_init_pseries_xics();
-#endif
                        return;
                }
        }
@@ -292,11 +265,6 @@ static void __init pSeries_setup_arch(void)
        /* init to some ~sane value until calibrate_delay() runs */
        loops_per_jiffy = 50000000;
 
-       if (ROOT_DEV == 0) {
-               printk("No ramdisk, default root is /dev/sda2\n");
-               ROOT_DEV = Root_SDA2;
-       }
-
        fwnmi_init();
 
        /* Find and initialize PCI host bridges */
@@ -330,23 +298,12 @@ static int __init pSeries_init_panel(void)
 {
        /* Manually leave the kernel version on the panel. */
        ppc_md.progress("Linux ppc64\n", 0);
-       ppc_md.progress(system_utsname.release, 0);
+       ppc_md.progress(init_utsname()->version, 0);
 
        return 0;
 }
 arch_initcall(pSeries_init_panel);
 
-static void pSeries_mach_cpu_die(void)
-{
-       local_irq_disable();
-       idle_task_exit();
-       xics_teardown_cpu(0);
-       rtas_stop_self();
-       /* Should never get here... */
-       BUG();
-       for(;;);
-}
-
 static int pseries_set_dabr(unsigned long dabr)
 {
        return plpar_hcall_norets(H_SET_DABR, dabr);
@@ -364,9 +321,7 @@ static int pseries_set_xdabr(unsigned long dabr)
  */
 static void __init pSeries_init_early(void)
 {
-       DBG(" -> pSeries_init_early()\n");
-
-       fw_feature_init();
+       pr_debug(" -> pSeries_init_early()\n");
 
        if (firmware_has_feature(FW_FEATURE_LPAR))
                find_udbg_vterm();
@@ -378,33 +333,7 @@ static void __init pSeries_init_early(void)
 
        iommu_init_early_pSeries();
 
-       DBG(" <- pSeries_init_early()\n");
-}
-
-
-static int pSeries_check_legacy_ioport(unsigned int baseport)
-{
-       struct device_node *np;
-
-#define I8042_DATA_REG 0x60
-#define FDC_BASE       0x3f0
-
-
-       switch(baseport) {
-       case I8042_DATA_REG:
-               np = of_find_node_by_type(NULL, "8042");
-               if (np == NULL)
-                       return -ENODEV;
-               of_node_put(np);
-               break;
-       case FDC_BASE:
-               np = of_find_node_by_type(NULL, "fdc");
-               if (np == NULL)
-                       return -ENODEV;
-               of_node_put(np);
-               break;
-       }
-       return 0;
+       pr_debug(" <- pSeries_init_early()\n");
 }
 
 /*
@@ -415,26 +344,28 @@ static int __init pSeries_probe_hypertas(unsigned long node,
                                         const char *uname, int depth,
                                         void *data)
 {
+       const char *hypertas;
+       unsigned long len;
+
        if (depth != 1 ||
            (strcmp(uname, "rtas") != 0 && strcmp(uname, "rtas@0") != 0))
-               return 0;
+               return 0;
 
-       if (of_get_flat_dt_prop(node, "ibm,hypertas-functions", NULL) != NULL)
-               powerpc_firmware_features |= FW_FEATURE_LPAR;
+       hypertas = of_get_flat_dt_prop(node, "ibm,hypertas-functions", &len);
+       if (!hypertas)
+               return 1;
 
-       if (firmware_has_feature(FW_FEATURE_LPAR))
-               hpte_init_lpar();
-       else
-               hpte_init_native();
+       powerpc_firmware_features |= FW_FEATURE_LPAR;
+       fw_feature_init(hypertas, len);
 
-       return 1;
+       return 1;
 }
 
 static int __init pSeries_probe(void)
 {
        unsigned long root = of_get_flat_dt_root();
-       char *dtype = of_get_flat_dt_prop(of_get_flat_dt_root(),
-                                         "device_type", NULL);
+       char *dtype = of_get_flat_dt_prop(root, "device_type", NULL);
+
        if (dtype == NULL)
                return 0;
        if (strcmp(dtype, "chrp"))
@@ -447,13 +378,18 @@ static int __init pSeries_probe(void)
            of_flat_dt_is_compatible(root, "IBM,CBEA"))
                return 0;
 
-       DBG("pSeries detected, looking for LPAR capability...\n");
+       pr_debug("pSeries detected, looking for LPAR capability...\n");
 
        /* Now try to figure out if we are running on LPAR */
        of_scan_flat_dt(pSeries_probe_hypertas, NULL);
 
-       DBG("Machine is%s LPAR !\n",
-           (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
+       if (firmware_has_feature(FW_FEATURE_LPAR))
+               hpte_init_lpar();
+       else
+               hpte_init_native();
+
+       pr_debug("Machine is%s LPAR !\n",
+                (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
 
        return 1;
 }
@@ -465,22 +401,24 @@ static void pseries_dedicated_idle_sleep(void)
 { 
        unsigned int cpu = smp_processor_id();
        unsigned long start_snooze;
-       unsigned long *smt_snooze_delay = &__get_cpu_var(smt_snooze_delay);
+       unsigned long in_purr, out_purr;
 
        /*
         * Indicate to the HV that we are idle. Now would be
         * a good time to find other work to dispatch.
         */
        get_lppaca()->idle = 1;
+       get_lppaca()->donate_dedicated_cpu = 1;
+       in_purr = mfspr(SPRN_PURR);
 
        /*
         * We come in with interrupts disabled, and need_resched()
         * has been checked recently.  If we should poll for a little
         * while, do so.
         */
-       if (*smt_snooze_delay) {
+       if (__get_cpu_var(smt_snooze_delay)) {
                start_snooze = get_tb() +
-                       *smt_snooze_delay * tb_ticks_per_usec;
+                       __get_cpu_var(smt_snooze_delay) * tb_ticks_per_usec;
                local_irq_enable();
                set_thread_flag(TIF_POLLING_NRFLAG);
 
@@ -500,25 +438,13 @@ static void pseries_dedicated_idle_sleep(void)
                        goto out;
        }
 
-       /*
-        * Cede if the other thread is not idle, so that it can
-        * go single-threaded.  If the other thread is idle,
-        * we ask the hypervisor if it has pending work it
-        * wants to do and cede if it does.  Otherwise we keep
-        * polling in order to reduce interrupt latency.
-        *
-        * Doing the cede when the other thread is active will
-        * result in this thread going dormant, meaning the other
-        * thread gets to run in single-threaded (ST) mode, which
-        * is slightly faster than SMT mode with this thread at
-        * very low priority.  The cede enables interrupts, which
-        * doesn't matter here.
-        */
-       if (!lppaca[cpu ^ 1].idle || poll_pending() == H_PENDING)
-               cede_processor();
+       cede_processor();
 
 out:
        HMT_medium();
+       out_purr = mfspr(SPRN_PURR);
+       get_lppaca()->wait_state_cycles += out_purr - in_purr;
+       get_lppaca()->donate_dedicated_cpu = 0;
        get_lppaca()->idle = 0;
 }
 
@@ -549,6 +475,38 @@ static int pSeries_pci_probe_mode(struct pci_bus *bus)
        return PCI_PROBE_NORMAL;
 }
 
+/**
+ * pSeries_power_off - tell firmware about how to power off the system.
+ *
+ * This function calls either the power-off rtas token in normal cases
+ * or the ibm,power-off-ups token (if present & requested) in case of
+ * a power failure. If power-off token is used, power on will only be
+ * possible with power button press. If ibm,power-off-ups token is used
+ * it will allow auto poweron after power is restored.
+ */
+void pSeries_power_off(void)
+{
+       int rc;
+       int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");
+
+       if (rtas_flash_term_hook)
+               rtas_flash_term_hook(SYS_POWER_OFF);
+
+       if (rtas_poweron_auto == 0 ||
+               rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {
+               rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
+               printk(KERN_INFO "RTAS power-off returned %d\n", rc);
+       } else {
+               rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
+               printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
+       }
+       for (;;);
+}
+
+#ifndef CONFIG_PCI
+void pSeries_final_fixup(void) { }
+#endif
+
 define_machine(pseries) {
        .name                   = "pSeries",
        .probe                  = pSeries_probe,
@@ -558,23 +516,15 @@ define_machine(pseries) {
        .log_error              = pSeries_log_error,
        .pcibios_fixup          = pSeries_final_fixup,
        .pci_probe_mode         = pSeries_pci_probe_mode,
-       .irq_bus_setup          = pSeries_irq_bus_setup,
        .restart                = rtas_restart,
-       .power_off              = rtas_power_off,
+       .power_off              = pSeries_power_off,
        .halt                   = rtas_halt,
        .panic                  = rtas_os_term,
-       .cpu_die                = pSeries_mach_cpu_die,
        .get_boot_time          = rtas_get_boot_time,
        .get_rtc_time           = rtas_get_rtc_time,
        .set_rtc_time           = rtas_set_rtc_time,
        .calibrate_decr         = generic_calibrate_decr,
        .progress               = rtas_progress,
-       .check_legacy_ioport    = pSeries_check_legacy_ioport,
        .system_reset_exception = pSeries_system_reset_exception,
        .machine_check_exception = pSeries_machine_check_exception,
-#ifdef CONFIG_KEXEC
-       .machine_kexec          = default_machine_kexec,
-       .machine_kexec_prepare  = default_machine_kexec_prepare,
-       .machine_crash_shutdown = default_machine_crash_shutdown,
-#endif
 };