Merge branch 'hwmon-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
[safe/jmp/linux-2.6] / drivers / watchdog / hpwdt.c
index b1cd0ac..763c1ea 100644 (file)
@@ -39,9 +39,8 @@
 #include <linux/string.h>
 #include <linux/bootmem.h>
 #include <linux/slab.h>
-#include <asm/dmi.h>
 #include <asm/desc.h>
-#include <asm/kdebug.h>
+#include <asm/cacheflush.h>
 
 #define PCI_BIOS32_SD_VALUE            0x5F32335F      /* "_32_" */
 #define CRU_BIOS_SIGNATURE_VALUE       0x55524324
@@ -58,41 +57,6 @@ struct bios32_service_dir {
        u8 reserved[5];
 };
 
-/*
- * smbios_entry_point     - defines SMBIOS entry point structure
- *
- * anchor[4]              - anchor string (_SM_)
- * checksum               - checksum of the entry point structure
- * length                 - length of the entry point structure
- * major_ver              - major version (02h for revision 2.1)
- * minor_ver              - minor version (01h for revision 2.1)
- * max_struct_size        - size of the largest SMBIOS structure
- * revision               - entry point structure revision implemented
- * formatted_area[5]      - reserved
- * intermediate_anchor[5] - intermediate anchor string (_DMI_)
- * intermediate_checksum  - intermediate checksum
- * table_length           - structure table length
- * table_address          - structure table address
- * table_num_structs      - number of SMBIOS structures present
- * bcd_revision           - BCD revision
- */
-struct smbios_entry_point {
-       u8 anchor[4];
-       u8 checksum;
-       u8 length;
-       u8 major_ver;
-       u8 minor_ver;
-       u16 max_struct_size;
-       u8 revision;
-       u8 formatted_area[5];
-       u8 intermediate_anchor[5];
-       u8 intermediate_checksum;
-       u16 table_length;
-       u32 table_address;
-       u16 table_num_structs;
-       u8 bcd_revision;
-};
-
 /* type 212 */
 struct smbios_cru64_info {
        u8 type;
@@ -153,6 +117,7 @@ static unsigned int reload;                 /* the computed soft_margin */
 static int nowayout = WATCHDOG_NOWAYOUT;
 static char expect_release;
 static unsigned long hpwdt_is_open;
+static unsigned int allow_kdump;
 
 static void __iomem *pci_mem_addr;             /* the PCI-memory address */
 static unsigned long __iomem *hpwdt_timer_reg;
@@ -175,67 +140,53 @@ static struct pci_device_id hpwdt_devices[] = {
 };
 MODULE_DEVICE_TABLE(pci, hpwdt_devices);
 
-/*
- *     bios_checksum
- */
-static int __devinit bios_checksum(const char __iomem *ptr, int len)
-{
-       char sum = 0;
-       int i;
-
-       /*
-        * calculate checksum of size bytes. This should add up
-        * to zero if we have a valid header.
-        */
-       for (i = 0; i < len; i++)
-               sum += ptr[i];
-
-       return ((sum == 0) && (len > 0));
-}
+extern asmlinkage void asminline_call(struct cmn_registers *pi86Regs, unsigned long *pRomEntry);
 
 #ifndef CONFIG_X86_64
 /* --32 Bit Bios------------------------------------------------------------ */
 
 #define HPWDT_ARCH     32
 
-asmlinkage void asminline_call(struct cmn_registers *pi86Regs,
-                              unsigned long *pRomEntry)
-{
-       asm("pushl       %ebp               \n\t"
-           "movl        %esp, %ebp         \n\t"
-           "pusha                          \n\t"
-           "pushf                          \n\t"
-           "push        %es                \n\t"
-           "push        %ds                \n\t"
-           "pop         %es                \n\t"
-           "movl        8(%ebp),%eax       \n\t"
-           "movl        4(%eax),%ebx       \n\t"
-           "movl        8(%eax),%ecx       \n\t"
-           "movl        12(%eax),%edx      \n\t"
-           "movl        16(%eax),%esi      \n\t"
-           "movl        20(%eax),%edi      \n\t"
-           "movl        (%eax),%eax        \n\t"
-           "push        %cs                \n\t"
-           "call        *12(%ebp)          \n\t"
-           "pushf                          \n\t"
-           "pushl       %eax               \n\t"
-           "movl        8(%ebp),%eax       \n\t"
-           "movl        %ebx,4(%eax)       \n\t"
-           "movl        %ecx,8(%eax)       \n\t"
-           "movl        %edx,12(%eax)      \n\t"
-           "movl        %esi,16(%eax)      \n\t"
-           "movl        %edi,20(%eax)      \n\t"
-           "movw        %ds,24(%eax)       \n\t"
-           "movw        %es,26(%eax)       \n\t"
-           "popl        %ebx               \n\t"
-           "movl        %ebx,(%eax)        \n\t"
-           "popl        %ebx               \n\t"
-           "movl        %ebx,28(%eax)      \n\t"
-           "pop         %es                \n\t"
-           "popf                           \n\t"
-           "popa                           \n\t"
-           "leave                          \n\t" "ret");
-}
+asm(".text                          \n\t"
+    ".align 4                       \n"
+    "asminline_call:                \n\t"
+    "pushl       %ebp               \n\t"
+    "movl        %esp, %ebp         \n\t"
+    "pusha                          \n\t"
+    "pushf                          \n\t"
+    "push        %es                \n\t"
+    "push        %ds                \n\t"
+    "pop         %es                \n\t"
+    "movl        8(%ebp),%eax       \n\t"
+    "movl        4(%eax),%ebx       \n\t"
+    "movl        8(%eax),%ecx       \n\t"
+    "movl        12(%eax),%edx      \n\t"
+    "movl        16(%eax),%esi      \n\t"
+    "movl        20(%eax),%edi      \n\t"
+    "movl        (%eax),%eax        \n\t"
+    "push        %cs                \n\t"
+    "call        *12(%ebp)          \n\t"
+    "pushf                          \n\t"
+    "pushl       %eax               \n\t"
+    "movl        8(%ebp),%eax       \n\t"
+    "movl        %ebx,4(%eax)       \n\t"
+    "movl        %ecx,8(%eax)       \n\t"
+    "movl        %edx,12(%eax)      \n\t"
+    "movl        %esi,16(%eax)      \n\t"
+    "movl        %edi,20(%eax)      \n\t"
+    "movw        %ds,24(%eax)       \n\t"
+    "movw        %es,26(%eax)       \n\t"
+    "popl        %ebx               \n\t"
+    "movl        %ebx,(%eax)        \n\t"
+    "popl        %ebx               \n\t"
+    "movl        %ebx,28(%eax)      \n\t"
+    "pop         %es                \n\t"
+    "popf                           \n\t"
+    "popa                           \n\t"
+    "leave                          \n\t"
+    "ret                            \n\t"
+    ".previous");
+
 
 /*
  *     cru_detect
@@ -272,19 +223,19 @@ static int __devinit cru_detect(unsigned long map_entry,
 
        if (cmn_regs.u1.ral != 0) {
                printk(KERN_WARNING
-                      "hpwdt: Call succeeded but with an error: 0x%x\n",
-                      cmn_regs.u1.ral);
+                       "hpwdt: Call succeeded but with an error: 0x%x\n",
+                       cmn_regs.u1.ral);
        } else {
                physical_bios_base = cmn_regs.u2.rebx;
                physical_bios_offset = cmn_regs.u4.redx;
                cru_length = cmn_regs.u3.recx;
                cru_physical_address =
-                   physical_bios_base + physical_bios_offset;
+                       physical_bios_base + physical_bios_offset;
 
                /* If the values look OK, then map it in. */
                if ((physical_bios_base + physical_bios_offset)) {
                        cru_rom_addr =
-                           ioremap(cru_physical_address, cru_length);
+                               ioremap(cru_physical_address, cru_length);
                        if (cru_rom_addr)
                                retval = 0;
                }
@@ -303,6 +254,24 @@ static int __devinit cru_detect(unsigned long map_entry,
 }
 
 /*
+ *     bios_checksum
+ */
+static int __devinit bios_checksum(const char __iomem *ptr, int len)
+{
+       char sum = 0;
+       int i;
+
+       /*
+        * calculate checksum of size bytes. This should add up
+        * to zero if we have a valid header.
+        */
+       for (i = 0; i < len; i++)
+               sum += ptr[i];
+
+       return ((sum == 0) && (len > 0));
+}
+
+/*
  *     bios32_present
  *
  *     Routine Description:
@@ -368,54 +337,50 @@ static int __devinit detect_cru_service(void)
 
 #define HPWDT_ARCH     64
 
-asmlinkage void asminline_call(struct cmn_registers *pi86Regs,
-                              unsigned long *pRomEntry)
-{
-       asm("pushq      %rbp            \n\t"
-           "movq       %rsp, %rbp      \n\t"
-           "pushq      %rax            \n\t"
-           "pushq      %rbx            \n\t"
-           "pushq      %rdx            \n\t"
-           "pushq      %r12            \n\t"
-           "pushq      %r9             \n\t"
-           "movq       %rsi, %r12      \n\t"
-           "movq       %rdi, %r9       \n\t"
-           "movl       4(%r9),%ebx     \n\t"
-           "movl       8(%r9),%ecx     \n\t"
-           "movl       12(%r9),%edx    \n\t"
-           "movl       16(%r9),%esi    \n\t"
-           "movl       20(%r9),%edi    \n\t"
-           "movl       (%r9),%eax      \n\t"
-           "call       *%r12           \n\t"
-           "pushfq                     \n\t"
-           "popq        %r12           \n\t"
-           "popfq                      \n\t"
-           "movl       %eax, (%r9)     \n\t"
-           "movl       %ebx, 4(%r9)    \n\t"
-           "movl       %ecx, 8(%r9)    \n\t"
-           "movl       %edx, 12(%r9)   \n\t"
-           "movl       %esi, 16(%r9)   \n\t"
-           "movl       %edi, 20(%r9)   \n\t"
-           "movq       %r12, %rax      \n\t"
-           "movl       %eax, 28(%r9)   \n\t"
-           "popq       %r9             \n\t"
-           "popq       %r12            \n\t"
-           "popq       %rdx            \n\t"
-           "popq       %rbx            \n\t"
-           "popq       %rax            \n\t"
-           "leave                      \n\t" "ret");
-}
+asm(".text                      \n\t"
+    ".align 4                   \n"
+    "asminline_call:            \n\t"
+    "pushq      %rbp            \n\t"
+    "movq       %rsp, %rbp      \n\t"
+    "pushq      %rax            \n\t"
+    "pushq      %rbx            \n\t"
+    "pushq      %rdx            \n\t"
+    "pushq      %r12            \n\t"
+    "pushq      %r9             \n\t"
+    "movq       %rsi, %r12      \n\t"
+    "movq       %rdi, %r9       \n\t"
+    "movl       4(%r9),%ebx     \n\t"
+    "movl       8(%r9),%ecx     \n\t"
+    "movl       12(%r9),%edx    \n\t"
+    "movl       16(%r9),%esi    \n\t"
+    "movl       20(%r9),%edi    \n\t"
+    "movl       (%r9),%eax      \n\t"
+    "call       *%r12           \n\t"
+    "pushfq                     \n\t"
+    "popq        %r12           \n\t"
+    "movl       %eax, (%r9)     \n\t"
+    "movl       %ebx, 4(%r9)    \n\t"
+    "movl       %ecx, 8(%r9)    \n\t"
+    "movl       %edx, 12(%r9)   \n\t"
+    "movl       %esi, 16(%r9)   \n\t"
+    "movl       %edi, 20(%r9)   \n\t"
+    "movq       %r12, %rax      \n\t"
+    "movl       %eax, 28(%r9)   \n\t"
+    "popq       %r9             \n\t"
+    "popq       %r12            \n\t"
+    "popq       %rdx            \n\t"
+    "popq       %rbx            \n\t"
+    "popq       %rax            \n\t"
+    "leave                      \n\t"
+    "ret                        \n\t"
+    ".previous");
 
 /*
  *     dmi_find_cru
  *
  *     Routine Description:
- *     This function checks wether or not a SMBIOS/DMI record is
+ *     This function checks whether or not a SMBIOS/DMI record is
  *     the 64bit CRU info or not
- *
- *     Return Value:
- *     0        :  SUCCESS - if record found
- *     <0       :  FAILURE - if record not found
  */
 static void __devinit dmi_find_cru(const struct dmi_header *dm)
 {
@@ -426,146 +391,24 @@ static void __devinit dmi_find_cru(const struct dmi_header *dm)
                smbios_cru64_ptr = (struct smbios_cru64_info *) dm;
                if (smbios_cru64_ptr->signature == CRU_BIOS_SIGNATURE_VALUE) {
                        cru_physical_address =
-                           smbios_cru64_ptr->physical_address +
-                           smbios_cru64_ptr->double_offset;
+                               smbios_cru64_ptr->physical_address +
+                               smbios_cru64_ptr->double_offset;
                        cru_rom_addr = ioremap(cru_physical_address,
-                                   smbios_cru64_ptr->double_length);
-               }
-       }
-}
-
-/*
- *     dmi_table
- *
- *     Routine Description:
- *     Decode the SMBIOS/DMI table and check if we have a 64bit CRU record
- *     or not.
- *
- *     We have to be cautious here. We have seen BIOSes with DMI pointers
- *     pointing to completely the wrong place for example
- */
-static void __devinit dmi_table(u8 *buf, int len, int num,
-                     void (*decode)(const struct dmi_header *))
-{
-       u8 *data = buf;
-       int i = 0;
-
-       /*
-        *      Stop when we see all the items the table claimed to have
-        *      OR we run off the end of the table (also happens)
-        */
-       while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
-               const struct dmi_header *dm = (const struct dmi_header *)data;
-
-               /*
-                *  We want to know the total length (formated area and strings)
-                *  before decoding to make sure we won't run off the table in
-                *  dmi_decode or dmi_string
-                */
-               data += dm->length;
-               while ((data - buf < len - 1) && (data[0] || data[1]))
-                       data++;
-               if (data - buf < len - 1)
-                       decode(dm);
-               data += 2;
-               i++;
-       }
-}
-
-/*
- *     smbios_present
- *
- *     Routine Description:
- *     This function parses the SMBIOS entry point table to retrieve
- *     the 64 bit CRU Service.
- *
- *     Return Value:
- *     0        :  SUCCESS
- *     <0       :  FAILURE
- */
-static int __devinit smbios_present(const char __iomem *p)
-{
-       struct smbios_entry_point *eps =
-               (struct smbios_entry_point *) p;
-       int length;
-       u8 *buf;
-
-       /* check if we have indeed the SMBIOS table entry point */
-       if ((strncmp((char *)eps->anchor, "_SM_",
-                            sizeof(eps->anchor))) == 0) {
-               length = eps->length;
-
-               /* SMBIOS v2.1 implementation might use 0x1e */
-               if ((length == 0x1e) &&
-                   (eps->major_ver == 2) &&
-                   (eps->minor_ver == 1))
-                       length = 0x1f;
-
-               /*
-                * Now we will check:
-                * - SMBIOS checksum must be 0
-                * - intermediate anchor should be _DMI_
-                * - intermediate checksum should be 0
-                */
-               if ((bios_checksum(p, length)) &&
-                   (strncmp((char *)eps->intermediate_anchor, "_DMI_",
-                            sizeof(eps->intermediate_anchor)) == 0) &&
-                   (bios_checksum(p+0x10, 15))) {
-                       buf = ioremap(eps->table_address, eps->table_length);
-                       if (buf == NULL)
-                               return -ENODEV;
-
-
-                       /* Scan the DMI table for the 64 bit CRU service */
-                       dmi_table(buf, eps->table_length,
-                                 eps->table_num_structs, dmi_find_cru);
-
-                       iounmap(buf);
-                       return 0;
+                               smbios_cru64_ptr->double_length);
+                       set_memory_x((unsigned long)cru_rom_addr & PAGE_MASK,
+                               smbios_cru64_ptr->double_length >> PAGE_SHIFT);
                }
        }
-
-       return -ENODEV;
-}
-
-static void __devinit smbios_scan_machine(void)
-{
-       char __iomem *p, *q;
-
-       if (efi_enabled) {
-               if (efi.smbios == EFI_INVALID_TABLE_ADDR)
-                       return;
-
-               p = ioremap(efi.smbios, 32);
-               if (p == NULL)
-                       return;
-
-               smbios_present(p);
-               iounmap(p);
-       } else {
-               /*
-                * Search from 0x0f0000 through 0x0fffff, inclusive.
-                */
-               p = ioremap(PCI_ROM_BASE1, ROM_SIZE);
-               if (p == NULL)
-                       return;
-
-               for (q = p; q < p + ROM_SIZE; q += 16)
-                       if (!smbios_present(q))
-                               break;
-
-               iounmap(p);
-       }
 }
 
 static int __devinit detect_cru_service(void)
 {
        cru_rom_addr = NULL;
 
-       smbios_scan_machine();  /* will become dmi_walk(dmi_find_cru); */
+       dmi_walk(dmi_find_cru);
 
        /* if cru_rom_addr has been set then we found a CRU service */
-       return ((cru_rom_addr != NULL)? 0: -ENODEV);
+       return ((cru_rom_addr != NULL) ? 0 : -ENODEV);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -573,34 +416,6 @@ static int __devinit detect_cru_service(void)
 #endif
 
 /*
- *     NMI Handler
- */
-static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
-                           void *data)
-{
-       static unsigned long rom_pl;
-       static int die_nmi_called;
-
-       if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI)
-               return NOTIFY_OK;
-
-       spin_lock_irqsave(&rom_lock, rom_pl);
-       if (!die_nmi_called)
-               asminline_call(&cmn_regs, cru_rom_addr);
-       die_nmi_called = 1;
-       spin_unlock_irqrestore(&rom_lock, rom_pl);
-       if (cmn_regs.u1.ral == 0) {
-               printk(KERN_WARNING "hpwdt: An NMI occurred, "
-                      "but unable to determine source.\n");
-       } else {
-               panic("An NMI occurred, please see the Integrated "
-                       "Management Log for details.\n");
-       }
-
-       return NOTIFY_STOP;
-}
-
-/*
  *     Watchdog operations
  */
 static void hpwdt_start(void)
@@ -644,6 +459,36 @@ static int hpwdt_change_timer(int new_margin)
 }
 
 /*
+ *     NMI Handler
+ */
+static int hpwdt_pretimeout(struct notifier_block *nb, unsigned long ulReason,
+                               void *data)
+{
+       unsigned long rom_pl;
+       static int die_nmi_called;
+
+       if (ulReason != DIE_NMI && ulReason != DIE_NMI_IPI)
+               return NOTIFY_OK;
+
+       spin_lock_irqsave(&rom_lock, rom_pl);
+       if (!die_nmi_called)
+               asminline_call(&cmn_regs, cru_rom_addr);
+       die_nmi_called = 1;
+       spin_unlock_irqrestore(&rom_lock, rom_pl);
+       if (cmn_regs.u1.ral == 0) {
+               printk(KERN_WARNING "hpwdt: An NMI occurred, "
+                       "but unable to determine source.\n");
+       } else {
+               if (allow_kdump)
+                       hpwdt_stop();
+               panic("An NMI occurred, please see the Integrated "
+                       "Management Log for details.\n");
+       }
+
+       return NOTIFY_OK;
+}
+
+/*
  *     /dev/watchdog handling
  */
 static int hpwdt_open(struct inode *inode, struct file *file)
@@ -693,7 +538,7 @@ static ssize_t hpwdt_write(struct file *file, const char __user *data,
                        /* scan to see whether or not we got the magic char. */
                        for (i = 0; i != len; i++) {
                                char c;
-                               if (get_user(c, data+i))
+                               if (get_user(c, data + i))
                                        return -EFAULT;
                                if (c == 'V')
                                        expect_release = 42;
@@ -785,17 +630,18 @@ static struct notifier_block die_notifier = {
  */
 
 static int __devinit hpwdt_init_one(struct pci_dev *dev,
-                                   const struct pci_device_id *ent)
+                                       const struct pci_device_id *ent)
 {
        int retval;
 
        /*
         * First let's find out if we are on an iLO2 server. We will
         * not run on a legacy ASM box.
+        * So we only support the G5 ProLiant servers and higher.
         */
        if (dev->subsystem_vendor != PCI_VENDOR_ID_HP) {
                dev_warn(&dev->dev,
-                      "This server does not have an iLO2 ASIC.\n");
+                       "This server does not have an iLO2 ASIC.\n");
                return -ENODEV;
        }
 
@@ -829,7 +675,7 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
        retval = detect_cru_service();
        if (retval < 0) {
                dev_warn(&dev->dev,
-                      "Unable to detect the %d Bit CRU Service.\n",
+                       "Unable to detect the %d Bit CRU Service.\n",
                        HPWDT_ARCH);
                goto error_get_cru;
        }
@@ -844,7 +690,7 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
        retval = register_die_notifier(&die_notifier);
        if (retval != 0) {
                dev_warn(&dev->dev,
-                      "Unable to register a die notifier (err=%d).\n",
+                       "Unable to register a die notifier (err=%d).\n",
                        retval);
                goto error_die_notifier;
        }
@@ -859,8 +705,9 @@ static int __devinit hpwdt_init_one(struct pci_dev *dev,
 
        printk(KERN_INFO
                "hp Watchdog Timer Driver: 1.00"
-               ", timer margin: %d seconds( nowayout=%d).\n",
-               soft_margin, nowayout);
+               ", timer margin: %d seconds (nowayout=%d)"
+               ", allow kernel dump: %s (default = 0/OFF).\n",
+               soft_margin, nowayout, (allow_kdump == 0) ? "OFF" : "ON");
 
        return 0;
 
@@ -915,6 +762,9 @@ MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
 module_param(soft_margin, int, 0);
 MODULE_PARM_DESC(soft_margin, "Watchdog timeout in seconds");
 
+module_param(allow_kdump, int, 0);
+MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
+
 module_param(nowayout, int, 0);
 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
                __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");