Pull sem2mutex-ioc4 into release branch
[powerpc.git] / drivers / pci / hotplug / shpchp_hpc.c
index 8d98410..b4226ff 100644 (file)
  *
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/types.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/interrupt.h>
-#include <linux/spinlock.h>
-#include <linux/delay.h>
 #include <linux/pci.h>
-#include <asm/system.h>
+#include <linux/interrupt.h>
+
 #include "shpchp.h"
 
 #ifdef DEBUG
@@ -280,9 +275,28 @@ static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds)
        return;
 }
 
+static inline int shpc_wait_cmd(struct controller *ctrl)
+{
+       int retval = 0;
+       unsigned int timeout_msec = shpchp_poll_mode ? 2000 : 1000;
+       unsigned long timeout = msecs_to_jiffies(timeout_msec);
+       int rc = wait_event_interruptible_timeout(ctrl->queue,
+                                                 !ctrl->cmd_busy, timeout);
+       if (!rc) {
+               retval = -EIO;
+               err("Command not completed in %d msec\n", timeout_msec);
+       } else if (rc < 0) {
+               retval = -EINTR;
+               info("Command was interrupted by a signal\n");
+       }
+       ctrl->cmd_busy = 0;
+
+       return retval;
+}
+
 static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u16 cmd_status;
        int retval = 0;
        u16 temp_word;
@@ -319,8 +333,13 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
        /* To make sure the Controller Busy bit is 0 before we send out the
         * command. 
         */
+       slot->ctrl->cmd_busy = 1;
        writew(temp_word, php_ctlr->creg + CMD);
-       dbg("%s: temp_word written %x\n", __FUNCTION__, temp_word);
+
+       /*
+        * Wait for command completion.
+        */
+       retval = shpc_wait_cmd(slot->ctrl);
 
        DBG_LEAVE_ROUTINE 
        return retval;
@@ -328,7 +347,7 @@ static int shpc_write_cmd(struct slot *slot, u8 t_slot, u8 cmd)
 
 static int hpc_check_cmd_status(struct controller *ctrl)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
        u16 cmd_status;
        int retval = 0;
 
@@ -368,7 +387,7 @@ static int hpc_check_cmd_status(struct controller *ctrl)
 
 static int hpc_get_attention_status(struct slot *slot, u8 *status)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status;
        u8 atten_led_state;
@@ -408,7 +427,7 @@ static int hpc_get_attention_status(struct slot *slot, u8 *status)
 
 static int hpc_get_power_status(struct slot * slot, u8 *status)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status;
        u8 slot_state;
@@ -450,7 +469,7 @@ static int hpc_get_power_status(struct slot * slot, u8 *status)
 
 static int hpc_get_latch_status(struct slot *slot, u8 *status)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status;
 
@@ -473,7 +492,7 @@ static int hpc_get_latch_status(struct slot *slot, u8 *status)
 
 static int hpc_get_adapter_status(struct slot *slot, u8 *status)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status;
        u8 card_state;
@@ -496,7 +515,7 @@ static int hpc_get_adapter_status(struct slot *slot, u8 *status)
 
 static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
 
        DBG_ENTER_ROUTINE 
        
@@ -513,7 +532,7 @@ static int hpc_get_prog_int(struct slot *slot, u8 *prog_int)
 
 static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status, sec_bus_status;
        u8 m66_cap, pcix_cap, pi;
@@ -594,7 +613,7 @@ static int hpc_get_adapter_speed(struct slot *slot, enum pci_bus_speed *value)
 
 static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u16 sec_bus_status;
        u8 pi;
        int retval = 0;
@@ -610,7 +629,7 @@ static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
        sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);
 
        if (pi == 2) {
-               *mode = (sec_bus_status & 0x0100) >> 7;
+               *mode = (sec_bus_status & 0x0100) >> 8;
        } else {
                retval = -1;
        }
@@ -623,7 +642,7 @@ static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode)
 
 static int hpc_query_power_fault(struct slot * slot)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u32 slot_reg;
        u16 slot_status;
        u8 pwr_fault_state, status;
@@ -647,7 +666,7 @@ static int hpc_query_power_fault(struct slot * slot)
 
 static int hpc_set_attention_status(struct slot *slot, u8 value)
 {
-       struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd = 0;
        int rc = 0;
 
@@ -683,7 +702,7 @@ static int hpc_set_attention_status(struct slot *slot, u8 value)
 
 static void hpc_set_green_led_on(struct slot *slot)
 {
-       struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
 
        if (!slot->ctrl->hpc_ctlr_handle) {
@@ -705,7 +724,7 @@ static void hpc_set_green_led_on(struct slot *slot)
 
 static void hpc_set_green_led_off(struct slot *slot)
 {
-       struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
 
        if (!slot->ctrl->hpc_ctlr_handle) {
@@ -727,7 +746,7 @@ static void hpc_set_green_led_off(struct slot *slot)
 
 static void hpc_set_green_led_blink(struct slot *slot)
 {
-       struct php_ctlr_state_s *php_ctlr =(struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
 
        if (!slot->ctrl->hpc_ctlr_handle) {
@@ -754,7 +773,7 @@ int shpc_get_ctlr_slot_config(struct controller *ctrl,
        int *updown,            /* physical_slot_num increament: 1 or -1        */
        int *flags)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
 
        DBG_ENTER_ROUTINE 
 
@@ -776,7 +795,7 @@ int shpc_get_ctlr_slot_config(struct controller *ctrl,
 
 static void hpc_release_ctlr(struct controller *ctrl)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
        struct php_ctlr_state_s *p, *p_prev;
 
        DBG_ENTER_ROUTINE 
@@ -796,10 +815,8 @@ static void hpc_release_ctlr(struct controller *ctrl)
                }
        }
        if (php_ctlr->pci_dev) {
-               dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
                iounmap(php_ctlr->creg);
-               release_mem_region(pci_resource_start(php_ctlr->pci_dev, 0), pci_resource_len(php_ctlr->pci_dev, 0));
-               dbg("%s: before calling iounmap & release_mem_region\n", __FUNCTION__);
+               release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
                php_ctlr->pci_dev = NULL;
        }
 
@@ -828,7 +845,7 @@ DBG_LEAVE_ROUTINE
 
 static int hpc_power_on_slot(struct slot * slot)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
        int retval = 0;
 
@@ -859,7 +876,7 @@ static int hpc_power_on_slot(struct slot * slot)
 
 static int hpc_slot_enable(struct slot * slot)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
        int retval = 0;
 
@@ -890,7 +907,7 @@ static int hpc_slot_enable(struct slot * slot)
 
 static int hpc_slot_disable(struct slot * slot)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        u8 slot_cmd;
        int retval = 0;
 
@@ -920,51 +937,12 @@ static int hpc_slot_disable(struct slot * slot)
        return retval;
 }
 
-static int hpc_enable_all_slots( struct slot *slot )
-{
-       int retval = 0;
-
-       DBG_ENTER_ROUTINE 
-       
-       if (!slot->ctrl->hpc_ctlr_handle) {
-               err("%s: Invalid HPC controller handle!\n", __FUNCTION__);
-               return -1;
-       }
-
-       retval = shpc_write_cmd(slot, 0, SET_ENABLE_ALL);
-       if (retval) {
-               err("%s: Write command failed!\n", __FUNCTION__);
-               return -1;
-       }
-
-       DBG_LEAVE_ROUTINE
-
-       return retval;
-}
-
-static int hpc_pwr_on_all_slots(struct slot *slot)
-{
-       int retval = 0;
-
-       DBG_ENTER_ROUTINE 
-
-       retval = shpc_write_cmd(slot, 0, SET_PWR_ON_ALL);
-
-       if (retval) {
-               err("%s: Write command failed!\n", __FUNCTION__);
-               return -1;
-       }
-
-       DBG_LEAVE_ROUTINE
-       return retval;
-}
-
 static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
 {
        u8 slot_cmd;
        u8 pi;
        int retval = 0;
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
 
        DBG_ENTER_ROUTINE 
        
@@ -1089,18 +1067,13 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
 
        if (!intr_loc)
                return IRQ_NONE;
-       dbg("%s: shpc_isr proceeds\n", __FUNCTION__);
        dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); 
 
        if(!shpchp_poll_mode) {
                /* Mask Global Interrupt Mask - see implementation note on p. 139 */
                /* of SHPC spec rev 1.0*/
                temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
-               dbg("%s: Before masking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                temp_dword |= 0x00000001;
-               dbg("%s: After masking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
 
                intr_loc2 = readl(php_ctlr->creg + INTR_LOC);  
@@ -1110,27 +1083,20 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
        if (intr_loc & 0x0001) {
                /* 
                 * Command Complete Interrupt Pending 
-                * RO only - clear by writing 0 to the Command Completion
+                * RO only - clear by writing 1 to the Command Completion
                 * Detect bit in Controller SERR-INT register
                 */
                temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
-               dbg("%s: Before clearing CCIP, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
-               temp_dword &= 0xfffeffff;
-               dbg("%s: After clearing CCIP, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
+               temp_dword &= 0xfffdffff;
                writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
+               ctrl->cmd_busy = 0;
                wake_up_interruptible(&ctrl->queue);
        }
 
        if ((intr_loc = (intr_loc >> 1)) == 0) {
                /* Unmask Global Interrupt Mask */
                temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
-               dbg("%s: 1-Before unmasking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                temp_dword &= 0xfffffffe;
-               dbg("%s: 1-After unmasking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
 
                return IRQ_NONE;
@@ -1140,11 +1106,9 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
        /* To find out which slot has interrupt pending */
                if ((intr_loc >> hp_slot) & 0x01) {
                        temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));
-                       dbg("%s: Slot %x with intr, temp_dword = %x\n",
-                               __FUNCTION__, hp_slot, temp_dword); 
+                       dbg("%s: Slot %x with intr, slot register = %x\n",
+                               __FUNCTION__, hp_slot, temp_dword);
                        temp_byte = (temp_dword >> 16) & 0xFF;
-                       dbg("%s: Slot with intr, temp_byte = %x\n",
-                               __FUNCTION__, temp_byte); 
                        if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))
                                schedule_flag += php_ctlr->switch_change_callback(
                                        hp_slot, php_ctlr->callback_instance_id);
@@ -1160,8 +1124,6 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
                        
                        /* Clear all slot events */
                        temp_dword = 0xe01f3fff;
-                       dbg("%s: Clearing slot events, temp_dword = %x\n",
-                               __FUNCTION__, temp_dword); 
                        writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));
 
                        intr_loc2 = readl(php_ctlr->creg + INTR_LOC);  
@@ -1171,11 +1133,7 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
        if (!shpchp_poll_mode) {
                /* Unmask Global Interrupt Mask */
                temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);
-               dbg("%s: 2-Before unmasking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                temp_dword &= 0xfffffffe;
-               dbg("%s: 2-After unmasking global interrupt, temp_dword = %x\n",
-                       __FUNCTION__, temp_dword); 
                writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);
        }
        
@@ -1184,12 +1142,11 @@ static irqreturn_t shpc_isr(int IRQ, void *dev_id, struct pt_regs *regs)
 
 static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
        int retval = 0;
        u8 pi;
        u32 slot_avail1, slot_avail2;
-       int slot_num;
 
        DBG_ENTER_ROUTINE 
 
@@ -1208,39 +1165,39 @@ static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
        slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);
 
        if (pi == 2) {
-               if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_533) >> 27)  ) != 0 )
+               if (slot_avail2 & SLOT_133MHZ_PCIX_533)
                        bus_speed = PCIX_133MHZ_533;
-               else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_533) >> 23)  ) != 0 )
+               else if (slot_avail2 & SLOT_100MHZ_PCIX_533)
                        bus_speed = PCIX_100MHZ_533;
-               else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_533) >> 19)  ) != 0 )
+               else if (slot_avail2 & SLOT_66MHZ_PCIX_533)
                        bus_speed = PCIX_66MHZ_533;
-               else if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_266) >> 15)  ) != 0 )
+               else if (slot_avail2 & SLOT_133MHZ_PCIX_266)
                        bus_speed = PCIX_133MHZ_266;
-               else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_266) >> 11)  ) != 0 )
+               else if (slot_avail2 & SLOT_100MHZ_PCIX_266)
                        bus_speed = PCIX_100MHZ_266;
-               else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_266) >> 7)  ) != 0 )
+               else if (slot_avail2 & SLOT_66MHZ_PCIX_266)
                        bus_speed = PCIX_66MHZ_266;
-               else if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23)  ) != 0 )
+               else if (slot_avail1 & SLOT_133MHZ_PCIX)
                        bus_speed = PCIX_133MHZ;
-               else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15)  ) != 0 )
+               else if (slot_avail1 & SLOT_100MHZ_PCIX)
                        bus_speed = PCIX_100MHZ;
-               else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7)  ) != 0 )
+               else if (slot_avail1 & SLOT_66MHZ_PCIX)
                        bus_speed = PCIX_66MHZ;
-               else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )
+               else if (slot_avail2 & SLOT_66MHZ)
                        bus_speed = PCI_66MHZ;
-               else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )
+               else if (slot_avail1 & SLOT_33MHZ)
                        bus_speed = PCI_33MHZ;
                else bus_speed = PCI_SPEED_UNKNOWN;
        } else {
-               if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23)  ) != 0 )
+               if (slot_avail1 & SLOT_133MHZ_PCIX)
                        bus_speed = PCIX_133MHZ;
-               else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15)  ) != 0 )
+               else if (slot_avail1 & SLOT_100MHZ_PCIX)
                        bus_speed = PCIX_100MHZ;
-               else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7)  ) != 0 )
+               else if (slot_avail1 & SLOT_66MHZ_PCIX)
                        bus_speed = PCIX_66MHZ;
-               else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )
+               else if (slot_avail2 & SLOT_66MHZ)
                        bus_speed = PCI_66MHZ;
-               else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )
+               else if (slot_avail1 & SLOT_33MHZ)
                        bus_speed = PCI_33MHZ;
                else bus_speed = PCI_SPEED_UNKNOWN;
        }
@@ -1253,7 +1210,7 @@ static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
 
 static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
 {
-       struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *) slot->ctrl->hpc_ctlr_handle;
+       struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;
        enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
        u16 sec_bus_status;
        int retval = 0;
@@ -1367,8 +1324,6 @@ static struct hpc_ops shpchp_hpc_ops = {
        .power_on_slot                  = hpc_power_on_slot,
        .slot_enable                    = hpc_slot_enable,
        .slot_disable                   = hpc_slot_disable,
-       .enable_all_slots               = hpc_enable_all_slots,
-       .pwr_on_all_slots               = hpc_pwr_on_all_slots,
        .set_bus_speed_mode             = hpc_set_bus_speed_mode,         
        .set_attention_status   = hpc_set_attention_status,
        .get_power_status               = hpc_get_power_status,
@@ -1391,25 +1346,34 @@ static struct hpc_ops shpchp_hpc_ops = {
        .check_cmd_status               = hpc_check_cmd_status,
 };
 
-int shpc_init(struct controller * ctrl,
-               struct pci_dev * pdev,
-               php_intr_callback_t attention_button_callback,
-               php_intr_callback_t switch_change_callback,
-               php_intr_callback_t presence_change_callback,
-               php_intr_callback_t power_fault_callback)
+inline static int shpc_indirect_creg_read(struct controller *ctrl, int index,
+                                         u32 *value)
+{
+       int rc;
+       u32 cap_offset = ctrl->cap_offset;
+       struct pci_dev *pdev = ctrl->pci_dev;
+
+       rc = pci_write_config_byte(pdev, cap_offset + DWORD_SELECT, index);
+       if (rc)
+               return rc;
+       return pci_read_config_dword(pdev, cap_offset + DWORD_DATA, value);
+}
+
+int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
 {
        struct php_ctlr_state_s *php_ctlr, *p;
        void *instance_id = ctrl;
-       int rc;
+       int rc, num_slots = 0;
        u8 hp_slot;
        static int first = 1;
-       u32 shpc_cap_offset, shpc_base_offset;
+       u32 shpc_base_offset;
        u32 tempdword, slot_reg;
-       u16 vendor_id, device_id;
        u8 i;
 
        DBG_ENTER_ROUTINE
 
+       ctrl->pci_dev = pdev;  /* pci_dev of the P2P bridge */
+
        spin_lock_init(&list_lock);
        php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL);
 
@@ -1422,55 +1386,47 @@ int shpc_init(struct controller * ctrl,
 
        php_ctlr->pci_dev = pdev;       /* save pci_dev in context */
 
-       rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
-       dbg("%s: Vendor ID: %x\n",__FUNCTION__, vendor_id);
-       if (rc) {
-               err("%s: unable to read PCI configuration data\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
-
-       rc = pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
-       dbg("%s: Device ID: %x\n",__FUNCTION__, device_id);
-       if (rc) {
-               err("%s: unable to read PCI configuration data\n", __FUNCTION__);
-               goto abort_free_ctlr;
-       }
-
-       if ((vendor_id == PCI_VENDOR_ID_AMD) || (device_id == PCI_DEVICE_ID_AMD_GOLAM_7450)) {
-               shpc_base_offset = 0;  /* amd shpc driver doesn't use this; assume 0 */
+       if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
+                               PCI_DEVICE_ID_AMD_GOLAM_7450)) {
+               /* amd shpc driver doesn't use Base Offset; assume 0 */
+               ctrl->mmio_base = pci_resource_start(pdev, 0);
+               ctrl->mmio_size = pci_resource_len(pdev, 0);
        } else {
-               if ((shpc_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC)) == 0) {
-                       err("%s : shpc_cap_offset == 0\n", __FUNCTION__);
+               ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
+               if (!ctrl->cap_offset) {
+                       err("%s : cap_offset == 0\n", __FUNCTION__);
                        goto abort_free_ctlr;
                }
-               dbg("%s: shpc_cap_offset = %x\n", __FUNCTION__, shpc_cap_offset);       
-       
-               rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset + DWORD_SELECT , BASE_OFFSET);
+               dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
+
+               rc = shpc_indirect_creg_read(ctrl, 0, &shpc_base_offset);
                if (rc) {
-                       err("%s : pci_word_config_byte failed\n", __FUNCTION__);
+                       err("%s: cannot read base_offset\n", __FUNCTION__);
                        goto abort_free_ctlr;
                }
-       
-               rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &shpc_base_offset);
+
+               rc = shpc_indirect_creg_read(ctrl, 3, &tempdword);
                if (rc) {
-                       err("%s : pci_read_config_dword failed\n", __FUNCTION__);
+                       err("%s: cannot read slot config\n", __FUNCTION__);
                        goto abort_free_ctlr;
                }
+               num_slots = tempdword & SLOT_NUM;
+               dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
 
-               for (i = 0; i <= 14; i++) {
-                       rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset +  DWORD_SELECT , i);
-                       if (rc) {
-                               err("%s : pci_word_config_byte failed\n", __FUNCTION__);
-                               goto abort_free_ctlr;
-                       }
-       
-                       rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &tempdword);
+               for (i = 0; i < 9 + num_slots; i++) {
+                       rc = shpc_indirect_creg_read(ctrl, i, &tempdword);
                        if (rc) {
-                               err("%s : pci_read_config_dword failed\n", __FUNCTION__);
+                               err("%s: cannot read creg (index = %d)\n",
+                                   __FUNCTION__, i);
                                goto abort_free_ctlr;
                        }
-                       dbg("%s: offset %d: tempdword %x\n", __FUNCTION__,i, tempdword);
+                       dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
+                                       tempdword);
                }
+
+               ctrl->mmio_base =
+                       pci_resource_start(pdev, 0) + shpc_base_offset;
+               ctrl->mmio_size = 0x24 + 0x4 * num_slots;
        }
 
        if (first) {
@@ -1478,33 +1434,25 @@ int shpc_init(struct controller * ctrl,
                first = 0;
        }
 
-       dbg("pdev = %p: b:d:f:irq=0x%x:%x:%x:%x\n", pdev, pdev->bus->number, PCI_SLOT(pdev->devfn), 
-               PCI_FUNC(pdev->devfn), pdev->irq);
-       for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)
-               if (pci_resource_len(pdev, rc) > 0)
-                       dbg("pci resource[%d] start=0x%lx(len=0x%lx), shpc_base_offset %x\n", rc,
-                               pci_resource_start(pdev, rc), pci_resource_len(pdev, rc), shpc_base_offset);
-
        info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 
                pdev->subsystem_device);
        
        if (pci_enable_device(pdev))
                goto abort_free_ctlr;
 
-       if (!request_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0), MY_NAME)) {
+       if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
                err("%s: cannot reserve MMIO region\n", __FUNCTION__);
                goto abort_free_ctlr;
        }
 
-       php_ctlr->creg = ioremap(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));
+       php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
        if (!php_ctlr->creg) {
-               err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, pci_resource_len(pdev, 0), 
-                       pci_resource_start(pdev, 0) + shpc_base_offset);
-               release_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));
+               err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
+                   ctrl->mmio_size, ctrl->mmio_base);
+               release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
                goto abort_free_ctlr;
        }
        dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);
-       dbg("%s: physical addr %p\n", __FUNCTION__, (void*)pci_resource_start(pdev, 0));
 
        init_MUTEX(&ctrl->crit_sect);
        /* Setup wait queue */
@@ -1512,13 +1460,10 @@ int shpc_init(struct controller * ctrl,
 
        /* Find the IRQ */
        php_ctlr->irq = pdev->irq;
-       dbg("HPC interrupt = %d\n", php_ctlr->irq);
-
-       /* Save interrupt callback info */
-       php_ctlr->attention_button_callback = attention_button_callback;
-       php_ctlr->switch_change_callback = switch_change_callback;
-       php_ctlr->presence_change_callback = presence_change_callback;
-       php_ctlr->power_fault_callback = power_fault_callback;
+       php_ctlr->attention_button_callback = shpchp_handle_attention_button,
+       php_ctlr->switch_change_callback = shpchp_handle_switch_change;
+       php_ctlr->presence_change_callback = shpchp_handle_presence_change;
+       php_ctlr->power_fault_callback = shpchp_handle_power_fault;
        php_ctlr->callback_instance_id = instance_id;
 
        /* Return PCI Controller Info */
@@ -1556,7 +1501,6 @@ int shpc_init(struct controller * ctrl,
                if (rc) {
                        info("Can't get msi for the hotplug controller\n");
                        info("Use INTx for the hotplug controller\n");
-                       dbg("%s: rc = %x\n", __FUNCTION__, rc);
                } else
                        php_ctlr->irq = pdev->irq;
                
@@ -1566,9 +1510,11 @@ int shpc_init(struct controller * ctrl,
                        err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);
                        goto abort_free_ctlr;
                }
-               /* Execute OSHP method here */
        }
-       dbg("%s: Before adding HPC to HPC list\n", __FUNCTION__);
+       dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
+                       pdev->bus->number, PCI_SLOT(pdev->devfn),
+                       PCI_FUNC(pdev->devfn), pdev->irq);
+       get_hp_hw_control_from_firmware(pdev);
 
        /*  Add this HPC instance into the HPC list */
        spin_lock(&list_lock);
@@ -1607,7 +1553,6 @@ int shpc_init(struct controller * ctrl,
                dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);
        }
 
-       dbg("%s: Leaving shpc_init\n", __FUNCTION__);
        DBG_LEAVE_ROUTINE
        return 0;