[PATCH] tick-management: core functionality
[powerpc.git] / drivers / char / hw_random / intel-rng.c
index 8efbc9c..cc1046e 100644 (file)
  */
 static const struct pci_device_id pci_tbl[] = {
 /* AA
-       { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-       { 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */
+       { PCI_DEVICE(0x8086, 0x2418) }, */
+       { PCI_DEVICE(0x8086, 0x2410) }, /* AA */
 /* AB
-       { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-       { 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */
+       { PCI_DEVICE(0x8086, 0x2428) }, */
+       { PCI_DEVICE(0x8086, 0x2420) }, /* AB */
 /* ??
-       { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
+       { PCI_DEVICE(0x8086, 0x2430) }, */
 /* BAM, CAM, DBM, FBM, GxM
-       { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-       { 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */
-       { 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */
-       { 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */
-       { 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */
-       { 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */
-       { 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */
+       { PCI_DEVICE(0x8086, 0x2448) }, */
+       { PCI_DEVICE(0x8086, 0x244c) }, /* BAM */
+       { PCI_DEVICE(0x8086, 0x248c) }, /* CAM */
+       { PCI_DEVICE(0x8086, 0x24cc) }, /* DBM */
+       { PCI_DEVICE(0x8086, 0x2641) }, /* FBM */
+       { PCI_DEVICE(0x8086, 0x27b9) }, /* GxM */
+       { PCI_DEVICE(0x8086, 0x27bd) }, /* GxM DH */
 /* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
-       { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-       { 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */
-       { 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */
-       { 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */
-       { 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */
-       { 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */
-       { 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */
-       { 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */
-       { 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */
+       { PCI_DEVICE(0x8086, 0x244e) }, */
+       { PCI_DEVICE(0x8086, 0x2440) }, /* BA */
+       { PCI_DEVICE(0x8086, 0x2480) }, /* CA */
+       { PCI_DEVICE(0x8086, 0x24c0) }, /* DB */
+       { PCI_DEVICE(0x8086, 0x24d0) }, /* Ex */
+       { PCI_DEVICE(0x8086, 0x25a1) }, /* 6300 */
+       { PCI_DEVICE(0x8086, 0x2640) }, /* Fx */
+       { PCI_DEVICE(0x8086, 0x2670) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2671) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2672) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2673) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2674) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2675) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2676) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2677) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2678) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x2679) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267a) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267b) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267c) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267d) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267e) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x267f) }, /* 631x/632x */
+       { PCI_DEVICE(0x8086, 0x27b8) }, /* Gx */
 /* E
-       { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */
-       { 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E  */
+       { PCI_DEVICE(0x8086, 0x245e) }, */
+       { PCI_DEVICE(0x8086, 0x2450) }, /* E  */
        { 0, }, /* terminate list */
 };
 MODULE_DEVICE_TABLE(pci, pci_tbl);
 
+static __initdata int no_fwh_detect;
+module_param(no_fwh_detect, int, 0);
+MODULE_PARM_DESC(no_fwh_detect, "Skip FWH detection:\n"
+                                " positive value - skip if FWH space locked read-only\n"
+                                " negative value - skip always");
 
 static inline u8 hwstatus_get(void __iomem *mem)
 {
@@ -240,6 +245,11 @@ static int __init mod_init(void)
        if (!dev)
                goto out; /* Device not found. */
 
+       if (no_fwh_detect < 0) {
+               pci_dev_put(dev);
+               goto fwh_done;
+       }
+
        /* Check for Intel 82802 */
        if (dev->device < 0x2640) {
                fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
@@ -252,6 +262,23 @@ static int __init mod_init(void)
        pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val);
        pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val);
 
+       if ((bios_cntl_val &
+            (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK))
+           == BIOS_CNTL_LOCK_ENABLE_MASK) {
+               static __initdata /*const*/ char warning[] =
+                       KERN_WARNING PFX "Firmware space is locked read-only. If you can't or\n"
+                       KERN_WARNING PFX "don't want to disable this in firmware setup, and if\n"
+                       KERN_WARNING PFX "you are certain that your system has a functional\n"
+                       KERN_WARNING PFX "RNG, try using the 'no_fwh_detect' option.\n";
+
+               pci_dev_put(dev);
+               if (no_fwh_detect)
+                       goto fwh_done;
+               printk(warning);
+               err = -EBUSY;
+               goto out;
+       }
+
        mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN);
        if (mem == NULL) {
                pci_dev_put(dev);
@@ -280,8 +307,7 @@ static int __init mod_init(void)
                pci_write_config_byte(dev,
                                      fwh_dec_en1_off,
                                      fwh_dec_en1_val | FWH_F8_EN_MASK);
-       if (!(bios_cntl_val &
-             (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
+       if (!(bios_cntl_val & BIOS_CNTL_WRITE_ENABLE_MASK))
                pci_write_config_byte(dev,
                                      bios_cntl_off,
                                      bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK);
@@ -315,6 +341,8 @@ static int __init mod_init(void)
                goto out;
        }
 
+fwh_done:
+
        err = -ENOMEM;
        mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN);
        if (!mem)
@@ -350,7 +378,7 @@ static void __exit mod_exit(void)
        iounmap(mem);
 }
 
-subsys_initcall(mod_init);
+module_init(mod_init);
 module_exit(mod_exit);
 
 MODULE_DESCRIPTION("H/W RNG driver for Intel chipsets");