include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / idle / i7300_idle.c
index 59d1bbc..15341fc 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/gfp.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
 #include <linux/cpumask.h>
 #include <linux/delay.h>
 #include <linux/debugfs.h>
 #include <linux/stop_machine.h>
+#include <linux/i7300_idle.h>
 
 #include <asm/idle.h>
 
-#include "../dma/ioatdma_hw.h"
-#include "../dma/ioatdma_registers.h"
+#include "../dma/ioat/hw.h"
+#include "../dma/ioat/registers.h"
 
 #define I7300_IDLE_DRIVER_VERSION      "1.55"
 #define I7300_PRINT                    "i7300_idle:"
 
+#define MAX_STOP_RETRIES       10
+
 static int debug;
 module_param_named(debug, debug, uint, 0644);
 MODULE_PARM_DESC(debug, "Enable debug printks in this driver");
 
+static int forceload;
+module_param_named(forceload, forceload, uint, 0644);
+MODULE_PARM_DESC(debug, "Enable driver testing on unvalidated i5000");
+
 #define dprintk(fmt, arg...) \
        do { if (debug) printk(KERN_INFO I7300_PRINT fmt, ##arg); } while (0)
 
@@ -46,12 +54,12 @@ MODULE_PARM_DESC(debug, "Enable debug printks in this driver");
  *  0 = No throttling
  *  1 = Throttle when > 4 activations per eval window (Maximum throttling)
  *  2 = Throttle when > 8 activations
- *  168 = Throttle when > 168 activations (Minimum throttling)
+ *  168 = Throttle when > 672 activations (Minimum throttling)
  */
-#define MAX_THRTLWLIMIT                168
-static uint i7300_idle_thrtlowlm = 1;
-module_param_named(thrtlwlimit, i7300_idle_thrtlowlm, uint, 0644);
-MODULE_PARM_DESC(thrtlwlimit,
+#define MAX_THROTTLE_LOW_LIMIT         168
+static uint throttle_low_limit = 1;
+module_param_named(throttle_low_limit, throttle_low_limit, uint, 0644);
+MODULE_PARM_DESC(throttle_low_limit,
                "Value for THRTLOWLM activation field "
                "(0 = disable throttle, 1 = Max throttle, 168 = Min throttle)");
 
@@ -74,7 +82,7 @@ static u8 i7300_idle_thrtctl_saved;
 static u8 i7300_idle_thrtlow_saved;
 static u32 i7300_idle_mc_saved;
 
-static cpumask_t idle_cpumask;
+static cpumask_var_t idle_cpumask;
 static ktime_t start_ktime;
 static unsigned long avg_idle_us;
 
@@ -110,25 +118,26 @@ static int i7300_idle_ioat_start(void)
 static void i7300_idle_ioat_stop(void)
 {
        int i;
-       u8 sts;
+       u64 sts;
 
-       for (i = 0; i < 5; i++) {
+       for (i = 0; i < MAX_STOP_RETRIES; i++) {
                writeb(IOAT_CHANCMD_RESET,
                        ioat_chanbase + IOAT1_CHANCMD_OFFSET);
 
                udelay(10);
 
                sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
-                       IOAT_CHANSTS_DMA_TRANSFER_STATUS;
+                       IOAT_CHANSTS_STATUS;
 
-               if (sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE)
+               if (sts != IOAT_CHANSTS_ACTIVE)
                        break;
 
        }
 
-       if (i == 5)
-               dprintk("failed to suspend+reset I/O AT after 5 retries\n");
-
+       if (i == MAX_STOP_RETRIES) {
+               dprintk("failed to stop I/O AT after %d retries\n",
+                       MAX_STOP_RETRIES);
+       }
 }
 
 /* Test I/O AT by copying 1024 byte from 2k to 1k */
@@ -152,9 +161,9 @@ static int __init i7300_idle_ioat_selftest(u8 *ctl,
        udelay(1000);
 
        chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
-                       IOAT_CHANSTS_DMA_TRANSFER_STATUS;
+                       IOAT_CHANSTS_STATUS;
 
-       if (chan_sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_DONE) {
+       if (chan_sts != IOAT_CHANSTS_DONE) {
                /* Not complete, reset the channel */
                writeb(IOAT_CHANCMD_RESET,
                       ioat_chanbase + IOAT1_CHANCMD_OFFSET);
@@ -173,8 +182,8 @@ static int __init i7300_idle_ioat_selftest(u8 *ctl,
 }
 
 static struct device dummy_dma_dev = {
-       .bus_id = "fallback device",
-       .coherent_dma_mask = DMA_64BIT_MASK,
+       .init_name = "fallback device",
+       .coherent_dma_mask = DMA_BIT_MASK(64),
        .dma_mask = &dummy_dma_dev.coherent_dma_mask,
 };
 
@@ -275,14 +284,14 @@ static void __exit i7300_idle_ioat_exit(void)
        i7300_idle_ioat_stop();
 
        /* Wait for a while for the channel to halt before releasing */
-       for (i = 0; i < 10; i++) {
+       for (i = 0; i < MAX_STOP_RETRIES; i++) {
                writeb(IOAT_CHANCMD_RESET,
                       ioat_chanbase + IOAT1_CHANCMD_OFFSET);
 
                chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
-                       IOAT_CHANSTS_DMA_TRANSFER_STATUS;
+                       IOAT_CHANSTS_STATUS;
 
-               if (chan_sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE) {
+               if (chan_sts != IOAT_CHANSTS_ACTIVE) {
                        writew(0, ioat_chanbase + IOAT_CHANCTRL_OFFSET);
                        break;
                }
@@ -290,14 +299,14 @@ static void __exit i7300_idle_ioat_exit(void)
        }
 
        chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
-                       IOAT_CHANSTS_DMA_TRANSFER_STATUS;
+                       IOAT_CHANSTS_STATUS;
 
        /*
         * We tried to reset multiple times. If IO A/T channel is still active
         * flag an error and return without cleanup. Memory leak is better
         * than random corruption in that extreme error situation.
         */
-       if (chan_sts == IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE) {
+       if (chan_sts == IOAT_CHANSTS_ACTIVE) {
                printk(KERN_ERR I7300_PRINT "Unable to stop IO A/T channels."
                        " Not freeing resources\n");
                return;
@@ -389,9 +398,9 @@ static void i7300_idle_start(void)
        new_ctl = i7300_idle_thrtctl_saved & ~DIMM_THRTCTL_THRMHUNT;
        pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
 
-       limit = i7300_idle_thrtlowlm;
-       if (unlikely(limit > MAX_THRTLWLIMIT))
-               limit = MAX_THRTLWLIMIT;
+       limit = throttle_low_limit;
+       if (unlikely(limit > MAX_THROTTLE_LOW_LIMIT))
+               limit = MAX_THROTTLE_LOW_LIMIT;
 
        pci_write_config_byte(fbd_dev, DIMM_THRTLOW, limit);
 
@@ -440,7 +449,7 @@ static int i7300_idle_notifier(struct notifier_block *nb, unsigned long val,
        static ktime_t idle_begin_time;
        static int time_init = 1;
 
-       if (!i7300_idle_thrtlowlm)
+       if (!throttle_low_limit)
                return 0;
 
        if (unlikely(time_init)) {
@@ -451,9 +460,9 @@ static int i7300_idle_notifier(struct notifier_block *nb, unsigned long val,
        spin_lock_irqsave(&i7300_idle_lock, flags);
        if (val == IDLE_START) {
 
-               cpu_set(smp_processor_id(), idle_cpumask);
+               cpumask_set_cpu(smp_processor_id(), idle_cpumask);
 
-               if (cpus_weight(idle_cpumask) != num_online_cpus())
+               if (cpumask_weight(idle_cpumask) != num_online_cpus())
                        goto end;
 
                now_ktime = ktime_get();
@@ -470,8 +479,8 @@ static int i7300_idle_notifier(struct notifier_block *nb, unsigned long val,
                i7300_idle_ioat_start();
 
        } else if (val == IDLE_END) {
-               cpu_clear(smp_processor_id(), idle_cpumask);
-               if (cpus_weight(idle_cpumask) == (num_online_cpus() - 1)) {
+               cpumask_clear_cpu(smp_processor_id(), idle_cpumask);
+               if (cpumask_weight(idle_cpumask) == (num_online_cpus() - 1)) {
                        /* First CPU coming out of idle */
                        u64 idle_duration_us;
 
@@ -505,77 +514,8 @@ static struct notifier_block i7300_idle_nb = {
        .notifier_call = i7300_idle_notifier,
 };
 
-/*
- * I/O AT controls (PCI bus 0 device 8 function 0)
- * DIMM controls (PCI bus 0 device 16 function 1)
- */
-#define IOAT_BUS 0
-#define IOAT_DEVFN PCI_DEVFN(8, 0)
-#define MEMCTL_BUS 0
-#define MEMCTL_DEVFN PCI_DEVFN(16, 1)
-
-struct fbd_ioat {
-       unsigned int vendor;
-       unsigned int ioat_dev;
-};
-
-/*
- * The i5000 chip-set has the same hooks as the i7300
- * but support is disabled by default because this driver
- * has not been validated on that platform.
- */
-#define SUPPORT_I5000 0
-
-static const struct fbd_ioat fbd_ioat_list[] = {
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB},
-#if SUPPORT_I5000
-       {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT},
-#endif
-       {0, 0}
-};
-
-/* table of devices that work with this driver */
-static const struct pci_device_id pci_tbl[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_FBD_CNB) },
-#if SUPPORT_I5000
-       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
-#endif
-       { } /* Terminating entry */
-};
-
 MODULE_DEVICE_TABLE(pci, pci_tbl);
 
-/* Check for known platforms with I/O-AT */
-static int __init i7300_idle_platform_probe(void)
-{
-       int i;
-
-       fbd_dev = pci_get_bus_and_slot(MEMCTL_BUS, MEMCTL_DEVFN);
-       if (!fbd_dev)
-               return -ENODEV;
-
-       for (i = 0; pci_tbl[i].vendor != 0; i++) {
-               if (fbd_dev->vendor == pci_tbl[i].vendor &&
-                   fbd_dev->device == pci_tbl[i].device) {
-                       break;
-               }
-       }
-       if (pci_tbl[i].vendor == 0)
-               return -ENODEV;
-
-       ioat_dev = pci_get_bus_and_slot(IOAT_BUS, IOAT_DEVFN);
-       if (!ioat_dev)
-               return -ENODEV;
-
-       for (i = 0; fbd_ioat_list[i].vendor != 0; i++) {
-               if (ioat_dev->vendor == fbd_ioat_list[i].vendor &&
-                   ioat_dev->device == fbd_ioat_list[i].ioat_dev) {
-                       return 0;
-               }
-       }
-       return -ENODEV;
-}
-
 int stats_open_generic(struct inode *inode, struct file *fp)
 {
        fp->private_data = inode->i_private;
@@ -614,10 +554,9 @@ struct debugfs_file_info {
 static int __init i7300_idle_init(void)
 {
        spin_lock_init(&i7300_idle_lock);
-       cpus_clear(idle_cpumask);
        total_us = 0;
 
-       if (i7300_idle_platform_probe())
+       if (i7300_idle_platform_probe(&fbd_dev, &ioat_dev, forceload))
                return -ENODEV;
 
        if (i7300_idle_thrt_save())
@@ -626,6 +565,9 @@ static int __init i7300_idle_init(void)
        if (i7300_idle_ioat_init())
                return -ENODEV;
 
+       if (!zalloc_cpumask_var(&idle_cpumask, GFP_KERNEL))
+               return -ENOMEM;
+
        debugfs_dir = debugfs_create_dir("i7300_idle", NULL);
        if (debugfs_dir) {
                int i = 0;
@@ -650,6 +592,7 @@ static int __init i7300_idle_init(void)
 static void __exit i7300_idle_exit(void)
 {
        idle_notifier_unregister(&i7300_idle_nb);
+       free_cpumask_var(idle_cpumask);
 
        if (debugfs_dir) {
                int i = 0;