Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/pci-2.6: (41 commits)
Revert "PCI: remove duplicate device id from ata_piix"
msi: Make MSI useable more architectures
msi: Kill the msi_desc array.
msi: Remove attach_msi_entry.
msi: Fix msi_remove_pci_irq_vectors.
msi: Remove msi_lock.
msi: Kill msi_lookup_irq
MSI: Combine pci_(save|restore)_msi/msix_state
MSI: Remove pci_scan_msi_device()
MSI: Replace pci_msi_quirk with calls to pci_no_msi()
PCI: remove duplicate device id from ipr
PCI: remove duplicate device id from ata_piix
PCI: power management: remove noise on non-manageable hw
PCI: cleanup MSI code
PCI: make isa_bridge Alpha-only
PCI: remove quirk_sis_96x_compatible()
PCI: Speed up the Intel SMBus unhiding quirk
PCI Quirk: 1k I/O space IOBL_ADR fix on P64H2
shpchp: delete trailing whitespace
shpchp: remove DBG_XXX_ROUTINE
...

+1078 -1577
+4
arch/alpha/kernel/pci.c
··· 575 575 576 576 EXPORT_SYMBOL(pci_iomap); 577 577 EXPORT_SYMBOL(pci_iounmap); 578 + 579 + /* FIXME: Some boxes have multiple ISA bridges! */ 580 + struct pci_dev *isa_bridge; 581 + EXPORT_SYMBOL(isa_bridge);
+12 -5
arch/i386/kernel/io_apic.c
··· 2606 2606 .retrigger = ioapic_retrigger_irq, 2607 2607 }; 2608 2608 2609 - int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev) 2609 + int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) 2610 2610 { 2611 2611 struct msi_msg msg; 2612 - int ret; 2612 + int irq, ret; 2613 + irq = create_irq(); 2614 + if (irq < 0) 2615 + return irq; 2616 + 2617 + set_irq_msi(irq, desc); 2613 2618 ret = msi_compose_msg(dev, irq, &msg); 2614 - if (ret < 0) 2619 + if (ret < 0) { 2620 + destroy_irq(irq); 2615 2621 return ret; 2622 + } 2616 2623 2617 2624 write_msi_msg(irq, &msg); 2618 2625 2619 2626 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, 2620 2627 "edge"); 2621 2628 2622 - return 0; 2629 + return irq; 2623 2630 } 2624 2631 2625 2632 void arch_teardown_msi_irq(unsigned int irq) 2626 2633 { 2627 - return; 2634 + destroy_irq(irq); 2628 2635 } 2629 2636 2630 2637 #endif /* CONFIG_PCI_MSI */
+12 -7
arch/ia64/kernel/msi_ia64.c
··· 64 64 } 65 65 #endif /* CONFIG_SMP */ 66 66 67 - int ia64_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) 67 + int ia64_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc) 68 68 { 69 69 struct msi_msg msg; 70 70 unsigned long dest_phys_id; 71 - unsigned int vector; 71 + unsigned int irq, vector; 72 72 73 + irq = create_irq(); 74 + if (irq < 0) 75 + return irq; 76 + 77 + set_irq_msi(irq, desc); 73 78 dest_phys_id = cpu_physical_id(first_cpu(cpu_online_map)); 74 79 vector = irq; 75 80 ··· 94 89 write_msi_msg(irq, &msg); 95 90 set_irq_chip_and_handler(irq, &ia64_msi_chip, handle_edge_irq); 96 91 97 - return 0; 92 + return irq; 98 93 } 99 94 100 95 void ia64_teardown_msi_irq(unsigned int irq) 101 96 { 102 - return; /* no-op */ 97 + destroy_irq(irq); 103 98 } 104 99 105 100 static void ia64_ack_msi_irq(unsigned int irq) ··· 131 126 }; 132 127 133 128 134 - int arch_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) 129 + int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc) 135 130 { 136 131 if (platform_setup_msi_irq) 137 - return platform_setup_msi_irq(irq, pdev); 132 + return platform_setup_msi_irq(pdev, desc); 138 133 139 - return ia64_setup_msi_irq(irq, pdev); 134 + return ia64_setup_msi_irq(pdev, desc); 140 135 } 141 136 142 137 void arch_teardown_msi_irq(unsigned int irq)
+14 -6
arch/ia64/sn/kernel/msi_sn.c
··· 59 59 sn_intr_free(nasid, widget, sn_irq_info); 60 60 sn_msi_info[irq].sn_irq_info = NULL; 61 61 62 - return; 62 + destroy_irq(irq); 63 63 } 64 64 65 - int sn_setup_msi_irq(unsigned int irq, struct pci_dev *pdev) 65 + int sn_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *entry) 66 66 { 67 67 struct msi_msg msg; 68 - struct msi_desc *entry; 69 68 int widget; 70 69 int status; 71 70 nasid_t nasid; ··· 72 73 struct sn_irq_info *sn_irq_info; 73 74 struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev); 74 75 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev); 76 + int irq; 75 77 76 - entry = get_irq_data(irq); 77 78 if (!entry->msi_attrib.is_64) 78 79 return -EINVAL; 79 80 ··· 83 84 if (provider == NULL || provider->dma_map_consistent == NULL) 84 85 return -EINVAL; 85 86 87 + irq = create_irq(); 88 + if (irq < 0) 89 + return irq; 90 + 91 + set_irq_msi(irq, entry); 86 92 /* 87 93 * Set up the vector plumbing. Let the prom (via sn_intr_alloc) 88 94 * decide which cpu to direct this msi at by default. ··· 99 95 SWIN_WIDGETNUM(bussoft->bs_base); 100 96 101 97 sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL); 102 - if (! sn_irq_info) 98 + if (! sn_irq_info) { 99 + destroy_irq(irq); 103 100 return -ENOMEM; 101 + } 104 102 105 103 status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1); 106 104 if (status) { 107 105 kfree(sn_irq_info); 106 + destroy_irq(irq); 108 107 return -ENOMEM; 109 108 } 110 109 ··· 128 121 if (! bus_addr) { 129 122 sn_intr_free(nasid, widget, sn_irq_info); 130 123 kfree(sn_irq_info); 124 + destroy_irq(irq); 131 125 return -ENOMEM; 132 126 } 133 127 ··· 147 139 write_msi_msg(irq, &msg); 148 140 set_irq_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq); 149 141 150 - return 0; 142 + return irq; 151 143 } 152 144 153 145 #ifdef CONFIG_SMP
-2
arch/powerpc/kernel/pci_64.c
··· 381 381 382 382 pci_device_add(dev, bus); 383 383 384 - /* XXX pci_scan_msi_device(dev); */ 385 - 386 384 return dev; 387 385 } 388 386 EXPORT_SYMBOL(of_create_pci_dev);
+12 -5
arch/x86_64/kernel/io_apic.c
··· 1956 1956 .retrigger = ioapic_retrigger_irq, 1957 1957 }; 1958 1958 1959 - int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev) 1959 + int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) 1960 1960 { 1961 1961 struct msi_msg msg; 1962 - int ret; 1962 + int irq, ret; 1963 + irq = create_irq(); 1964 + if (irq < 0) 1965 + return irq; 1966 + 1967 + set_irq_msi(irq, desc); 1963 1968 ret = msi_compose_msg(dev, irq, &msg); 1964 - if (ret < 0) 1969 + if (ret < 0) { 1970 + destroy_irq(irq); 1965 1971 return ret; 1972 + } 1966 1973 1967 1974 write_msi_msg(irq, &msg); 1968 1975 1969 1976 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); 1970 1977 1971 - return 0; 1978 + return irq; 1972 1979 } 1973 1980 1974 1981 void arch_teardown_msi_irq(unsigned int irq) 1975 1982 { 1976 - return; 1983 + destroy_irq(irq); 1977 1984 } 1978 1985 1979 1986 #endif /* CONFIG_PCI_MSI */
+1 -2
drivers/net/bnx2.c
··· 5947 5947 * responding after a while. 5948 5948 * 5949 5949 * AMD believes this incompatibility is unique to the 5706, and 5950 - * prefers to locally disable MSI rather than globally disabling it 5951 - * using pci_msi_quirk. 5950 + * prefers to locally disable MSI rather than globally disabling it. 5952 5951 */ 5953 5952 if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) { 5954 5953 struct pci_dev *amd_8132 = NULL;
+1 -1
drivers/net/e1000/e1000_main.c
··· 3584 3584 */ 3585 3585 if (adapter->link_speed == 0) 3586 3586 return; 3587 - if (pdev->error_state && pdev->error_state != pci_channel_io_normal) 3587 + if (pci_channel_offline(pdev)) 3588 3588 return; 3589 3589 3590 3590 spin_lock_irqsave(&adapter->stats_lock, flags);
+1 -1
drivers/net/ixgb/ixgb_main.c
··· 1605 1605 struct pci_dev *pdev = adapter->pdev; 1606 1606 1607 1607 /* Prevent stats update while adapter is being reset */ 1608 - if (pdev->error_state && pdev->error_state != pci_channel_io_normal) 1608 + if (pci_channel_offline(pdev)) 1609 1609 return; 1610 1610 1611 1611 if((netdev->flags & IFF_PROMISC) || (netdev->flags & IFF_ALLMULTI) ||
-9
drivers/pci/hotplug/Kconfig
··· 145 145 146 146 When in doubt, say N. 147 147 148 - config HOTPLUG_PCI_SHPC_POLL_EVENT_MODE 149 - bool "Use polling mechanism for hot-plug events (for testing purpose)" 150 - depends on HOTPLUG_PCI_SHPC 151 - help 152 - Say Y here if you want to use the polling mechanism for hot-plug 153 - events for early platform testing. 154 - 155 - When in doubt, say N. 156 - 157 148 config HOTPLUG_PCI_RPA 158 149 tristate "RPA PCI Hotplug driver" 159 150 depends on HOTPLUG_PCI && PPC_PSERIES && PPC64 && !HOTPLUG_PCI_FAKE
+56 -136
drivers/pci/hotplug/pciehp.h
··· 44 44 extern int pciehp_debug; 45 45 extern int pciehp_force; 46 46 47 - /*#define dbg(format, arg...) do { if (pciehp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/ 48 - #define dbg(format, arg...) do { if (pciehp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0) 49 - #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) 50 - #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 51 - #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 47 + #define dbg(format, arg...) \ 48 + do { \ 49 + if (pciehp_debug) \ 50 + printk("%s: " format, MY_NAME , ## arg); \ 51 + } while (0) 52 + #define err(format, arg...) \ 53 + printk(KERN_ERR "%s: " format, MY_NAME , ## arg) 54 + #define info(format, arg...) \ 55 + printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 56 + #define warn(format, arg...) \ 57 + printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 52 58 53 - 59 + #define SLOT_NAME_SIZE 10 54 60 struct slot { 55 - struct slot *next; 56 61 u8 bus; 57 62 u8 device; 58 63 u32 number; ··· 68 63 struct hpc_ops *hpc_ops; 69 64 struct hotplug_slot *hotplug_slot; 70 65 struct list_head slot_list; 66 + char name[SLOT_NAME_SIZE]; 67 + unsigned long last_emi_toggle; 71 68 }; 72 69 73 70 struct event_info { ··· 77 70 u8 hp_slot; 78 71 }; 79 72 80 - typedef u8(*php_intr_callback_t) (u8 hp_slot, void *instance_id); 81 - 82 - struct php_ctlr_state_s { 83 - struct php_ctlr_state_s *pnext; 84 - struct pci_dev *pci_dev; 85 - unsigned int irq; 86 - unsigned long flags; /* spinlock's */ 87 - u32 slot_device_offset; 88 - u32 num_slots; 89 - struct timer_list int_poll_timer; /* Added for poll event */ 90 - php_intr_callback_t attention_button_callback; 91 - php_intr_callback_t switch_change_callback; 92 - php_intr_callback_t presence_change_callback; 93 - php_intr_callback_t power_fault_callback; 94 - void *callback_instance_id; 95 - struct ctrl_reg *creg; /* Ptr to controller register space */ 96 - }; 97 - 98 73 #define MAX_EVENTS 10 99 74 struct controller { 100 75 struct controller *next; 101 76 struct mutex crit_sect; /* critical section mutex */ 102 77 struct mutex ctrl_lock; /* controller lock */ 103 - struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ 104 78 int num_slots; /* Number of slots on ctlr */ 105 79 int slot_num_inc; /* 1 or -1 */ 106 80 struct pci_dev *pci_dev; 107 - struct pci_bus *pci_bus; 81 + struct list_head slot_list; 108 82 struct event_info event_queue[MAX_EVENTS]; 109 83 struct slot *slot; 110 84 struct hpc_ops *hpc_ops; ··· 100 112 u8 ctrlcap; 101 113 u16 vendor_id; 102 114 u8 cap_base; 115 + struct timer_list poll_timer; 116 + volatile int cmd_busy; 103 117 }; 104 118 105 119 #define INT_BUTTON_IGNORE 0 ··· 121 131 #define POWERON_STATE 3 122 132 #define POWEROFF_STATE 4 123 133 124 - #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400 125 - 126 134 /* Error messages */ 127 135 #define INTERLOCK_OPEN 0x00000002 128 136 #define ADD_NOT_SUPPORTED 0x00000003 ··· 132 144 #define WRONG_BUS_FREQUENCY 0x0000000D 133 145 #define POWER_FAILURE 0x0000000E 134 146 135 - #define REMOVE_NOT_SUPPORTED 0x00000003 136 - 137 - #define DISABLE_CARD 1 138 - 139 147 /* Field definitions in Slot Capabilities Register */ 140 148 #define ATTN_BUTTN_PRSN 0x00000001 141 149 #define PWR_CTRL_PRSN 0x00000002 ··· 139 155 #define ATTN_LED_PRSN 0x00000008 140 156 #define PWR_LED_PRSN 0x00000010 141 157 #define HP_SUPR_RM_SUP 0x00000020 158 + #define EMI_PRSN 0x00020000 142 159 143 160 #define ATTN_BUTTN(cap) (cap & ATTN_BUTTN_PRSN) 144 161 #define POWER_CTRL(cap) (cap & PWR_CTRL_PRSN) ··· 147 162 #define ATTN_LED(cap) (cap & ATTN_LED_PRSN) 148 163 #define PWR_LED(cap) (cap & PWR_LED_PRSN) 149 164 #define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP) 165 + #define EMI(cap) (cap & EMI_PRSN) 150 166 151 - /* 152 - * error Messages 153 - */ 154 - #define msg_initialization_err "Initialization failure, error=%d\n" 155 - #define msg_button_on "PCI slot #%s - powering on due to button press.\n" 156 - #define msg_button_off "PCI slot #%s - powering off due to button press.\n" 157 - #define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n" 158 - #define msg_button_ignore "PCI slot #%s - button press ignored. (action in progress...)\n" 159 - 160 - /* controller functions */ 161 - extern int pciehp_event_start_thread (void); 162 - extern void pciehp_event_stop_thread (void); 163 - extern int pciehp_enable_slot (struct slot *slot); 164 - extern int pciehp_disable_slot (struct slot *slot); 165 - 166 - extern u8 pciehp_handle_attention_button (u8 hp_slot, void *inst_id); 167 - extern u8 pciehp_handle_switch_change (u8 hp_slot, void *inst_id); 168 - extern u8 pciehp_handle_presence_change (u8 hp_slot, void *inst_id); 169 - extern u8 pciehp_handle_power_fault (u8 hp_slot, void *inst_id); 170 - /* extern void long_delay (int delay); */ 171 - 172 - /* pci functions */ 173 - extern int pciehp_configure_device (struct slot *p_slot); 174 - extern int pciehp_unconfigure_device (struct slot *p_slot); 175 - 176 - 167 + extern int pciehp_event_start_thread(void); 168 + extern void pciehp_event_stop_thread(void); 169 + extern int pciehp_enable_slot(struct slot *slot); 170 + extern int pciehp_disable_slot(struct slot *slot); 171 + extern u8 pciehp_handle_attention_button(u8 hp_slot, struct controller *ctrl); 172 + extern u8 pciehp_handle_switch_change(u8 hp_slot, struct controller *ctrl); 173 + extern u8 pciehp_handle_presence_change(u8 hp_slot, struct controller *ctrl); 174 + extern u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl); 175 + extern int pciehp_configure_device(struct slot *p_slot); 176 + extern int pciehp_unconfigure_device(struct slot *p_slot); 177 + int pcie_init(struct controller *ctrl, struct pcie_device *dev); 177 178 178 179 /* Global variables */ 179 180 extern struct controller *pciehp_ctrl_list; 180 181 181 - /* Inline functions */ 182 - 183 182 static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) 184 183 { 185 - struct slot *p_slot, *tmp_slot = NULL; 184 + struct slot *slot; 186 185 187 - p_slot = ctrl->slot; 188 - 189 - while (p_slot && (p_slot->device != device)) { 190 - tmp_slot = p_slot; 191 - p_slot = p_slot->next; 192 - } 193 - if (p_slot == NULL) { 194 - err("ERROR: pciehp_find_slot device=0x%x\n", device); 195 - p_slot = tmp_slot; 186 + list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 187 + if (slot->device == device) 188 + return slot; 196 189 } 197 190 198 - return p_slot; 191 + err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device); 192 + return NULL; 199 193 } 200 - 201 - static inline int wait_for_ctrl_irq(struct controller *ctrl) 202 - { 203 - int retval = 0; 204 - 205 - DECLARE_WAITQUEUE(wait, current); 206 - 207 - add_wait_queue(&ctrl->queue, &wait); 208 - if (!pciehp_poll_mode) 209 - /* Sleep for up to 1 second */ 210 - msleep_interruptible(1000); 211 - else 212 - msleep_interruptible(2500); 213 - 214 - remove_wait_queue(&ctrl->queue, &wait); 215 - if (signal_pending(current)) 216 - retval = -EINTR; 217 - 218 - return retval; 219 - } 220 - 221 - #define SLOT_NAME_SIZE 10 222 - 223 - static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot) 224 - { 225 - snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number); 226 - } 227 - 228 - enum php_ctlr_type { 229 - PCI, 230 - ISA, 231 - ACPI 232 - }; 233 - 234 - int pcie_init(struct controller *ctrl, struct pcie_device *dev); 235 - 236 - /* This has no meaning for PCI Express, as there is only 1 slot per port */ 237 - int pcie_get_ctlr_slot_config(struct controller *ctrl, 238 - int *num_ctlr_slots, 239 - int *first_device_num, 240 - int *physical_slot_num, 241 - u8 *ctrlcap); 242 194 243 195 struct hpc_ops { 244 - int (*power_on_slot) (struct slot *slot); 245 - int (*power_off_slot) (struct slot *slot); 246 - int (*get_power_status) (struct slot *slot, u8 *status); 247 - int (*get_attention_status) (struct slot *slot, u8 *status); 248 - int (*set_attention_status) (struct slot *slot, u8 status); 249 - int (*get_latch_status) (struct slot *slot, u8 *status); 250 - int (*get_adapter_status) (struct slot *slot, u8 *status); 251 - 252 - int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 253 - int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 254 - 255 - int (*get_max_lnk_width) (struct slot *slot, enum pcie_link_width *value); 256 - int (*get_cur_lnk_width) (struct slot *slot, enum pcie_link_width *value); 257 - 258 - int (*query_power_fault) (struct slot *slot); 259 - void (*green_led_on) (struct slot *slot); 260 - void (*green_led_off) (struct slot *slot); 261 - void (*green_led_blink) (struct slot *slot); 262 - void (*release_ctlr) (struct controller *ctrl); 263 - int (*check_lnk_status) (struct controller *ctrl); 196 + int (*power_on_slot)(struct slot *slot); 197 + int (*power_off_slot)(struct slot *slot); 198 + int (*get_power_status)(struct slot *slot, u8 *status); 199 + int (*get_attention_status)(struct slot *slot, u8 *status); 200 + int (*set_attention_status)(struct slot *slot, u8 status); 201 + int (*get_latch_status)(struct slot *slot, u8 *status); 202 + int (*get_adapter_status)(struct slot *slot, u8 *status); 203 + int (*get_emi_status)(struct slot *slot, u8 *status); 204 + int (*toggle_emi)(struct slot *slot); 205 + int (*get_max_bus_speed)(struct slot *slot, enum pci_bus_speed *speed); 206 + int (*get_cur_bus_speed)(struct slot *slot, enum pci_bus_speed *speed); 207 + int (*get_max_lnk_width)(struct slot *slot, enum pcie_link_width *val); 208 + int (*get_cur_lnk_width)(struct slot *slot, enum pcie_link_width *val); 209 + int (*query_power_fault)(struct slot *slot); 210 + void (*green_led_on)(struct slot *slot); 211 + void (*green_led_off)(struct slot *slot); 212 + void (*green_led_blink)(struct slot *slot); 213 + void (*release_ctlr)(struct controller *ctrl); 214 + int (*check_lnk_status)(struct controller *ctrl); 264 215 }; 265 - 266 216 267 217 #ifdef CONFIG_ACPI 268 218 #include <acpi/acpi.h> ··· 205 285 #include <acpi/actypes.h> 206 286 #include <linux/pci-acpi.h> 207 287 208 - #define pciehp_get_hp_hw_control_from_firmware(dev) \ 288 + #define pciehp_get_hp_hw_control_from_firmware(dev) \ 209 289 pciehp_acpi_get_hp_hw_control_from_firmware(dev) 210 290 static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, 211 291 struct hotplug_params *hpp)
+153 -139
drivers/pci/hotplug/pciehp_core.c
··· 34 34 #include <linux/pci.h> 35 35 #include "pciehp.h" 36 36 #include <linux/interrupt.h> 37 + #include <linux/time.h> 37 38 38 39 /* Global variables */ 39 40 int pciehp_debug; ··· 88 87 .get_cur_bus_speed = get_cur_bus_speed, 89 88 }; 90 89 90 + /* 91 + * Check the status of the Electro Mechanical Interlock (EMI) 92 + */ 93 + static int get_lock_status(struct hotplug_slot *hotplug_slot, u8 *value) 94 + { 95 + struct slot *slot = hotplug_slot->private; 96 + return (slot->hpc_ops->get_emi_status(slot, value)); 97 + } 98 + 99 + /* 100 + * sysfs interface for the Electro Mechanical Interlock (EMI) 101 + * 1 == locked, 0 == unlocked 102 + */ 103 + static ssize_t lock_read_file(struct hotplug_slot *slot, char *buf) 104 + { 105 + int retval; 106 + u8 value; 107 + 108 + retval = get_lock_status(slot, &value); 109 + if (retval) 110 + goto lock_read_exit; 111 + retval = sprintf (buf, "%d\n", value); 112 + 113 + lock_read_exit: 114 + return retval; 115 + } 116 + 117 + /* 118 + * Change the status of the Electro Mechanical Interlock (EMI) 119 + * This is a toggle - in addition there must be at least 1 second 120 + * in between toggles. 121 + */ 122 + static int set_lock_status(struct hotplug_slot *hotplug_slot, u8 status) 123 + { 124 + struct slot *slot = hotplug_slot->private; 125 + int retval; 126 + u8 value; 127 + 128 + mutex_lock(&slot->ctrl->crit_sect); 129 + 130 + /* has it been >1 sec since our last toggle? */ 131 + if ((get_seconds() - slot->last_emi_toggle) < 1) 132 + return -EINVAL; 133 + 134 + /* see what our current state is */ 135 + retval = get_lock_status(hotplug_slot, &value); 136 + if (retval || (value == status)) 137 + goto set_lock_exit; 138 + 139 + slot->hpc_ops->toggle_emi(slot); 140 + set_lock_exit: 141 + mutex_unlock(&slot->ctrl->crit_sect); 142 + return 0; 143 + } 144 + 145 + /* 146 + * sysfs interface which allows the user to toggle the Electro Mechanical 147 + * Interlock. Valid values are either 0 or 1. 0 == unlock, 1 == lock 148 + */ 149 + static ssize_t lock_write_file(struct hotplug_slot *slot, const char *buf, 150 + size_t count) 151 + { 152 + unsigned long llock; 153 + u8 lock; 154 + int retval = 0; 155 + 156 + llock = simple_strtoul(buf, NULL, 10); 157 + lock = (u8)(llock & 0xff); 158 + 159 + switch (lock) { 160 + case 0: 161 + case 1: 162 + retval = set_lock_status(slot, lock); 163 + break; 164 + default: 165 + err ("%d is an invalid lock value\n", lock); 166 + retval = -EINVAL; 167 + } 168 + if (retval) 169 + return retval; 170 + return count; 171 + } 172 + 173 + static struct hotplug_slot_attribute hotplug_slot_attr_lock = { 174 + .attr = {.name = "lock", .mode = S_IFREG | S_IRUGO | S_IWUSR}, 175 + .show = lock_read_file, 176 + .store = lock_write_file 177 + }; 178 + 91 179 /** 92 180 * release_slot - free up the memory used by a slot 93 181 * @hotplug_slot: slot to free ··· 188 98 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 189 99 190 100 kfree(slot->hotplug_slot->info); 191 - kfree(slot->hotplug_slot->name); 192 101 kfree(slot->hotplug_slot); 193 102 kfree(slot); 103 + } 104 + 105 + static void make_slot_name(struct slot *slot) 106 + { 107 + snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 108 + slot->bus, slot->number); 194 109 } 195 110 196 111 static int init_slots(struct controller *ctrl) 197 112 { 198 113 struct slot *slot; 199 - struct hpc_ops *hpc_ops; 200 114 struct hotplug_slot *hotplug_slot; 201 - struct hotplug_slot_info *hotplug_slot_info; 202 - u8 number_of_slots; 203 - u8 slot_device; 204 - u32 slot_number; 205 - int result = -ENOMEM; 115 + struct hotplug_slot_info *info; 116 + int retval = -ENOMEM; 117 + int i; 206 118 207 - number_of_slots = ctrl->num_slots; 208 - slot_device = ctrl->slot_device_offset; 209 - slot_number = ctrl->first_slot; 210 - 211 - while (number_of_slots) { 119 + for (i = 0; i < ctrl->num_slots; i++) { 212 120 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 213 121 if (!slot) 214 122 goto error; 215 123 216 - slot->hotplug_slot = 217 - kzalloc(sizeof(*(slot->hotplug_slot)), 218 - GFP_KERNEL); 219 - if (!slot->hotplug_slot) 124 + hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 125 + if (!hotplug_slot) 220 126 goto error_slot; 221 - hotplug_slot = slot->hotplug_slot; 127 + slot->hotplug_slot = hotplug_slot; 222 128 223 - hotplug_slot->info = 224 - kzalloc(sizeof(*(hotplug_slot->info)), 225 - GFP_KERNEL); 226 - if (!hotplug_slot->info) 129 + info = kzalloc(sizeof(*info), GFP_KERNEL); 130 + if (!info) 227 131 goto error_hpslot; 228 - hotplug_slot_info = hotplug_slot->info; 229 - hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 230 - if (!hotplug_slot->name) 231 - goto error_info; 132 + hotplug_slot->info = info; 232 133 134 + hotplug_slot->name = slot->name; 135 + 136 + slot->hp_slot = i; 233 137 slot->ctrl = ctrl; 234 - slot->bus = ctrl->slot_bus; 235 - slot->device = slot_device; 236 - slot->hpc_ops = hpc_ops = ctrl->hpc_ops; 237 - 138 + slot->bus = ctrl->pci_dev->subordinate->number; 139 + slot->device = ctrl->slot_device_offset + i; 140 + slot->hpc_ops = ctrl->hpc_ops; 238 141 slot->number = ctrl->first_slot; 239 - slot->hp_slot = slot_device - ctrl->slot_device_offset; 240 142 241 143 /* register this slot with the hotplug pci core */ 242 144 hotplug_slot->private = slot; 243 145 hotplug_slot->release = &release_slot; 244 - make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot); 146 + make_slot_name(slot); 245 147 hotplug_slot->ops = &pciehp_hotplug_slot_ops; 246 148 247 - hpc_ops->get_power_status(slot, 248 - &(hotplug_slot_info->power_status)); 249 - hpc_ops->get_attention_status(slot, 250 - &(hotplug_slot_info->attention_status)); 251 - hpc_ops->get_latch_status(slot, 252 - &(hotplug_slot_info->latch_status)); 253 - hpc_ops->get_adapter_status(slot, 254 - &(hotplug_slot_info->adapter_status)); 149 + get_power_status(hotplug_slot, &info->power_status); 150 + get_attention_status(hotplug_slot, &info->attention_status); 151 + get_latch_status(hotplug_slot, &info->latch_status); 152 + get_adapter_status(hotplug_slot, &info->adapter_status); 255 153 256 154 dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " 257 - "slot_device_offset=%x\n", 258 - slot->bus, slot->device, slot->hp_slot, slot->number, 259 - ctrl->slot_device_offset); 260 - result = pci_hp_register(hotplug_slot); 261 - if (result) { 262 - err ("pci_hp_register failed with error %d\n", result); 263 - goto error_name; 155 + "slot_device_offset=%x\n", slot->bus, slot->device, 156 + slot->hp_slot, slot->number, ctrl->slot_device_offset); 157 + retval = pci_hp_register(hotplug_slot); 158 + if (retval) { 159 + err ("pci_hp_register failed with error %d\n", retval); 160 + goto error_info; 161 + } 162 + /* create additional sysfs entries */ 163 + if (EMI(ctrl->ctrlcap)) { 164 + retval = sysfs_create_file(&hotplug_slot->kobj, 165 + &hotplug_slot_attr_lock.attr); 166 + if (retval) { 167 + pci_hp_deregister(hotplug_slot); 168 + err("cannot create additional sysfs entries\n"); 169 + goto error_info; 170 + } 264 171 } 265 172 266 - slot->next = ctrl->slot; 267 - ctrl->slot = slot; 268 - 269 - number_of_slots--; 270 - slot_device++; 271 - slot_number += ctrl->slot_num_inc; 173 + list_add(&slot->slot_list, &ctrl->slot_list); 272 174 } 273 175 274 176 return 0; 275 - 276 - error_name: 277 - kfree(hotplug_slot->name); 278 177 error_info: 279 - kfree(hotplug_slot_info); 178 + kfree(info); 280 179 error_hpslot: 281 180 kfree(hotplug_slot); 282 181 error_slot: 283 182 kfree(slot); 284 183 error: 285 - return result; 184 + return retval; 286 185 } 287 186 288 - 289 - static int cleanup_slots (struct controller * ctrl) 187 + static void cleanup_slots(struct controller *ctrl) 290 188 { 291 - struct slot *old_slot, *next_slot; 189 + struct list_head *tmp; 190 + struct list_head *next; 191 + struct slot *slot; 292 192 293 - old_slot = ctrl->slot; 294 - ctrl->slot = NULL; 295 - 296 - while (old_slot) { 297 - next_slot = old_slot->next; 298 - pci_hp_deregister (old_slot->hotplug_slot); 299 - old_slot = next_slot; 193 + list_for_each_safe(tmp, next, &ctrl->slot_list) { 194 + slot = list_entry(tmp, struct slot, slot_list); 195 + list_del(&slot->slot_list); 196 + if (EMI(ctrl->ctrlcap)) 197 + sysfs_remove_file(&slot->hotplug_slot->kobj, 198 + &hotplug_slot_attr_lock.attr); 199 + pci_hp_deregister(slot->hotplug_slot); 300 200 } 301 - 302 - 303 - return(0); 304 201 } 305 - 306 - static int get_ctlr_slot_config(struct controller *ctrl) 307 - { 308 - int num_ctlr_slots; /* Not needed; PCI Express has 1 slot per port*/ 309 - int first_device_num; /* Not needed */ 310 - int physical_slot_num; 311 - u8 ctrlcap; 312 - int rc; 313 - 314 - rc = pcie_get_ctlr_slot_config(ctrl, &num_ctlr_slots, &first_device_num, &physical_slot_num, &ctrlcap); 315 - if (rc) { 316 - err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n", __FUNCTION__, ctrl->bus, ctrl->device); 317 - return (-1); 318 - } 319 - 320 - ctrl->num_slots = num_ctlr_slots; /* PCI Express has 1 slot per port */ 321 - ctrl->slot_device_offset = first_device_num; 322 - ctrl->first_slot = physical_slot_num; 323 - ctrl->ctrlcap = ctrlcap; 324 - 325 - dbg("%s: bus(0x%x) num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) ctrlcap(%x) for b:d (%x:%x)\n", 326 - __FUNCTION__, ctrl->slot_bus, num_ctlr_slots, first_device_num, physical_slot_num, ctrlcap, 327 - ctrl->bus, ctrl->device); 328 - 329 - return (0); 330 - } 331 - 332 202 333 203 /* 334 204 * set_attention_status - Turns the Amber LED for a slot on, off or blink ··· 428 378 int rc; 429 379 struct controller *ctrl; 430 380 struct slot *t_slot; 431 - int first_device_num = 0 ; /* first PCI device number supported by this PCIE */ 432 - int num_ctlr_slots; /* number of slots supported by this HPC */ 433 381 u8 value; 434 382 struct pci_dev *pdev; 435 383 ··· 436 388 err("%s : out of memory\n", __FUNCTION__); 437 389 goto err_out_none; 438 390 } 391 + INIT_LIST_HEAD(&ctrl->slot_list); 439 392 440 393 pdev = dev->port; 441 394 ctrl->pci_dev = pdev; ··· 449 400 450 401 pci_set_drvdata(pdev, ctrl); 451 402 452 - ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL); 453 - if (!ctrl->pci_bus) { 454 - err("%s: out of memory\n", __FUNCTION__); 455 - rc = -ENOMEM; 456 - goto err_out_unmap_mmio_region; 457 - } 458 - memcpy (ctrl->pci_bus, pdev->bus, sizeof (*ctrl->pci_bus)); 459 403 ctrl->bus = pdev->bus->number; /* ctrl bus */ 460 404 ctrl->slot_bus = pdev->subordinate->number; /* bus controlled by this HPC */ 461 405 ··· 457 415 dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", __FUNCTION__, 458 416 ctrl->bus, ctrl->device, ctrl->function, pdev->irq); 459 417 460 - /* 461 - * Save configuration headers for this and subordinate PCI buses 462 - */ 463 - 464 - rc = get_ctlr_slot_config(ctrl); 465 - if (rc) { 466 - err(msg_initialization_err, rc); 467 - goto err_out_free_ctrl_bus; 468 - } 469 - first_device_num = ctrl->slot_device_offset; 470 - num_ctlr_slots = ctrl->num_slots; 471 - 472 418 /* Setup the slot information structures */ 473 419 rc = init_slots(ctrl); 474 420 if (rc) { 475 - err(msg_initialization_err, 6); 476 - goto err_out_free_ctrl_slot; 421 + err("%s: slot initialization failed\n", PCIE_MODULE_NAME); 422 + goto err_out_release_ctlr; 477 423 } 478 424 479 - t_slot = pciehp_find_slot(ctrl, first_device_num); 425 + t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); 480 426 481 427 /* Finish setting up the hot plug ctrl device */ 482 428 ctrl->next_event = 0; ··· 477 447 pciehp_ctrl_list = ctrl; 478 448 } 479 449 480 - /* Wait for exclusive access to hardware */ 481 - mutex_lock(&ctrl->ctrl_lock); 482 - 483 450 t_slot->hpc_ops->get_adapter_status(t_slot, &value); /* Check if slot is occupied */ 484 - 485 451 if ((POWER_CTRL(ctrl->ctrlcap)) && !value) { 486 452 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ 487 - if (rc) { 488 - /* Done with exclusive hardware access */ 489 - mutex_unlock(&ctrl->ctrl_lock); 453 + if (rc) 490 454 goto err_out_free_ctrl_slot; 491 - } else 492 - /* Wait for the command to complete */ 493 - wait_for_ctrl_irq (ctrl); 494 455 } 495 - 496 - /* Done with exclusive hardware access */ 497 - mutex_unlock(&ctrl->ctrl_lock); 498 456 499 457 return 0; 500 458 501 459 err_out_free_ctrl_slot: 502 460 cleanup_slots(ctrl); 503 - err_out_free_ctrl_bus: 504 - kfree(ctrl->pci_bus); 505 - err_out_unmap_mmio_region: 461 + err_out_release_ctlr: 506 462 ctrl->hpc_ops->release_ctlr(ctrl); 507 463 err_out_free_ctrl: 508 464 kfree(ctrl); ··· 521 505 522 506 while (ctrl) { 523 507 cleanup_slots(ctrl); 524 - 525 - kfree (ctrl->pci_bus); 526 508 527 509 ctrl->hpc_ops->release_ctlr(ctrl); 528 510
+55 -168
drivers/pci/hotplug/pciehp_ctrl.c
··· 48 48 return p_slot->hotplug_slot->name; 49 49 } 50 50 51 - u8 pciehp_handle_attention_button(u8 hp_slot, void *inst_id) 51 + u8 pciehp_handle_attention_button(u8 hp_slot, struct controller *ctrl) 52 52 { 53 - struct controller *ctrl = (struct controller *) inst_id; 54 53 struct slot *p_slot; 55 54 u8 rc = 0; 56 55 u8 getstatus; ··· 100 101 101 102 } 102 103 103 - u8 pciehp_handle_switch_change(u8 hp_slot, void *inst_id) 104 + u8 pciehp_handle_switch_change(u8 hp_slot, struct controller *ctrl) 104 105 { 105 - struct controller *ctrl = (struct controller *) inst_id; 106 106 struct slot *p_slot; 107 107 u8 rc = 0; 108 108 u8 getstatus; ··· 141 143 return rc; 142 144 } 143 145 144 - u8 pciehp_handle_presence_change(u8 hp_slot, void *inst_id) 146 + u8 pciehp_handle_presence_change(u8 hp_slot, struct controller *ctrl) 145 147 { 146 - struct controller *ctrl = (struct controller *) inst_id; 147 148 struct slot *p_slot; 148 149 u8 presence_save, rc = 0; 149 150 struct event_info *taskInfo; ··· 184 187 return rc; 185 188 } 186 189 187 - u8 pciehp_handle_power_fault(u8 hp_slot, void *inst_id) 190 + u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl) 188 191 { 189 - struct controller *ctrl = (struct controller *) inst_id; 190 192 struct slot *p_slot; 191 193 u8 rc = 0; 192 194 struct event_info *taskInfo; ··· 229 233 230 234 static void set_slot_off(struct controller *ctrl, struct slot * pslot) 231 235 { 232 - /* Wait for exclusive access to hardware */ 233 - mutex_lock(&ctrl->ctrl_lock); 234 - 235 236 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ 236 237 if (POWER_CTRL(ctrl->ctrlcap)) { 237 238 if (pslot->hpc_ops->power_off_slot(pslot)) { 238 - err("%s: Issue of Slot Power Off command failed\n", __FUNCTION__); 239 - mutex_unlock(&ctrl->ctrl_lock); 239 + err("%s: Issue of Slot Power Off command failed\n", 240 + __FUNCTION__); 240 241 return; 241 242 } 242 - wait_for_ctrl_irq (ctrl); 243 243 } 244 244 245 - if (PWR_LED(ctrl->ctrlcap)) { 245 + if (PWR_LED(ctrl->ctrlcap)) 246 246 pslot->hpc_ops->green_led_off(pslot); 247 - wait_for_ctrl_irq (ctrl); 248 - } 249 247 250 - if (ATTN_LED(ctrl->ctrlcap)) { 251 - if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 252 - err("%s: Issue of Set Attention Led command failed\n", __FUNCTION__); 253 - mutex_unlock(&ctrl->ctrl_lock); 248 + if (ATTN_LED(ctrl->ctrlcap)) { 249 + if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 250 + err("%s: Issue of Set Attention Led command failed\n", 251 + __FUNCTION__); 254 252 return; 255 253 } 256 - wait_for_ctrl_irq (ctrl); 257 254 } 258 - 259 - /* Done with exclusive hardware access */ 260 - mutex_unlock(&ctrl->ctrl_lock); 261 255 } 262 256 263 257 /** ··· 260 274 static int board_added(struct slot *p_slot) 261 275 { 262 276 u8 hp_slot; 263 - int rc = 0; 277 + int retval = 0; 264 278 struct controller *ctrl = p_slot->ctrl; 265 279 266 280 hp_slot = p_slot->device - ctrl->slot_device_offset; ··· 269 283 __FUNCTION__, p_slot->device, 270 284 ctrl->slot_device_offset, hp_slot); 271 285 272 - /* Wait for exclusive access to hardware */ 273 - mutex_lock(&ctrl->ctrl_lock); 274 - 275 286 if (POWER_CTRL(ctrl->ctrlcap)) { 276 287 /* Power on slot */ 277 - rc = p_slot->hpc_ops->power_on_slot(p_slot); 278 - if (rc) { 279 - mutex_unlock(&ctrl->ctrl_lock); 280 - return -1; 281 - } 282 - 283 - /* Wait for the command to complete */ 284 - wait_for_ctrl_irq (ctrl); 288 + retval = p_slot->hpc_ops->power_on_slot(p_slot); 289 + if (retval) 290 + return retval; 285 291 } 286 292 287 - if (PWR_LED(ctrl->ctrlcap)) { 293 + if (PWR_LED(ctrl->ctrlcap)) 288 294 p_slot->hpc_ops->green_led_blink(p_slot); 289 - 290 - /* Wait for the command to complete */ 291 - wait_for_ctrl_irq (ctrl); 292 - } 293 - 294 - /* Done with exclusive hardware access */ 295 - mutex_unlock(&ctrl->ctrl_lock); 296 295 297 296 /* Wait for ~1 second */ 298 - wait_for_ctrl_irq (ctrl); 297 + msleep(1000); 299 298 300 - /* Check link training status */ 301 - rc = p_slot->hpc_ops->check_lnk_status(ctrl); 302 - if (rc) { 299 + /* Check link training status */ 300 + retval = p_slot->hpc_ops->check_lnk_status(ctrl); 301 + if (retval) { 303 302 err("%s: Failed to check link status\n", __FUNCTION__); 304 303 set_slot_off(ctrl, p_slot); 305 - return rc; 304 + return retval; 306 305 } 307 306 308 307 /* Check for a power fault */ 309 308 if (p_slot->hpc_ops->query_power_fault(p_slot)) { 310 309 dbg("%s: power fault detected\n", __FUNCTION__); 311 - rc = POWER_FAILURE; 310 + retval = POWER_FAILURE; 312 311 goto err_exit; 313 312 } 314 313 315 - rc = pciehp_configure_device(p_slot); 316 - if (rc) { 314 + retval = pciehp_configure_device(p_slot); 315 + if (retval) { 317 316 err("Cannot add device 0x%x:%x\n", p_slot->bus, 318 - p_slot->device); 317 + p_slot->device); 319 318 goto err_exit; 320 319 } 321 320 ··· 309 338 */ 310 339 if (pcie_mch_quirk) 311 340 pci_fixup_device(pci_fixup_final, ctrl->pci_dev); 312 - if (PWR_LED(ctrl->ctrlcap)) { 313 - /* Wait for exclusive access to hardware */ 314 - mutex_lock(&ctrl->ctrl_lock); 315 - 341 + if (PWR_LED(ctrl->ctrlcap)) 316 342 p_slot->hpc_ops->green_led_on(p_slot); 317 - 318 - /* Wait for the command to complete */ 319 - wait_for_ctrl_irq (ctrl); 320 - 321 - /* Done with exclusive hardware access */ 322 - mutex_unlock(&ctrl->ctrl_lock); 323 - } 343 + 324 344 return 0; 325 345 326 346 err_exit: 327 347 set_slot_off(ctrl, p_slot); 328 - return -1; 348 + return retval; 329 349 } 330 - 331 350 332 351 /** 333 352 * remove_board - Turns off slot and LED's ··· 327 366 { 328 367 u8 device; 329 368 u8 hp_slot; 330 - int rc; 369 + int retval = 0; 331 370 struct controller *ctrl = p_slot->ctrl; 332 371 333 - if (pciehp_unconfigure_device(p_slot)) 334 - return 1; 372 + retval = pciehp_unconfigure_device(p_slot); 373 + if (retval) 374 + return retval; 335 375 336 376 device = p_slot->device; 337 - 338 377 hp_slot = p_slot->device - ctrl->slot_device_offset; 339 378 p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 340 379 341 380 dbg("In %s, hp_slot = %d\n", __FUNCTION__, hp_slot); 342 381 343 - /* Wait for exclusive access to hardware */ 344 - mutex_lock(&ctrl->ctrl_lock); 345 - 346 382 if (POWER_CTRL(ctrl->ctrlcap)) { 347 383 /* power off slot */ 348 - rc = p_slot->hpc_ops->power_off_slot(p_slot); 349 - if (rc) { 350 - err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 351 - mutex_unlock(&ctrl->ctrl_lock); 352 - return rc; 384 + retval = p_slot->hpc_ops->power_off_slot(p_slot); 385 + if (retval) { 386 + err("%s: Issue of Slot Disable command failed\n", 387 + __FUNCTION__); 388 + return retval; 353 389 } 354 - /* Wait for the command to complete */ 355 - wait_for_ctrl_irq (ctrl); 356 390 } 357 391 358 - if (PWR_LED(ctrl->ctrlcap)) { 392 + if (PWR_LED(ctrl->ctrlcap)) 359 393 /* turn off Green LED */ 360 394 p_slot->hpc_ops->green_led_off(p_slot); 361 - 362 - /* Wait for the command to complete */ 363 - wait_for_ctrl_irq (ctrl); 364 - } 365 - 366 - /* Done with exclusive hardware access */ 367 - mutex_unlock(&ctrl->ctrl_lock); 368 395 369 396 return 0; 370 397 } ··· 397 448 dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__, 398 449 p_slot->bus, p_slot->device); 399 450 400 - if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 401 - /* Wait for exclusive access to hardware */ 402 - mutex_lock(&p_slot->ctrl->ctrl_lock); 403 - 451 + if (pciehp_enable_slot(p_slot) && 452 + PWR_LED(p_slot->ctrl->ctrlcap)) 404 453 p_slot->hpc_ops->green_led_off(p_slot); 405 454 406 - /* Wait for the command to complete */ 407 - wait_for_ctrl_irq (p_slot->ctrl); 408 - 409 - /* Done with exclusive hardware access */ 410 - mutex_unlock(&p_slot->ctrl->ctrl_lock); 411 - } 412 455 p_slot->state = STATIC_STATE; 413 456 } 414 457 ··· 439 498 dbg("%s: adding bus:device(%x:%x)\n", 440 499 __FUNCTION__, p_slot->bus, p_slot->device); 441 500 442 - if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { 443 - /* Wait for exclusive access to hardware */ 444 - mutex_lock(&p_slot->ctrl->ctrl_lock); 445 - 501 + if (pciehp_enable_slot(p_slot) && 502 + PWR_LED(p_slot->ctrl->ctrlcap)) 446 503 p_slot->hpc_ops->green_led_off(p_slot); 447 504 448 - /* Wait for the command to complete */ 449 - wait_for_ctrl_irq (p_slot->ctrl); 450 - 451 - /* Done with exclusive hardware access */ 452 - mutex_unlock(&p_slot->ctrl->ctrl_lock); 453 - } 454 505 p_slot->state = STATIC_STATE; 455 506 } 456 507 ··· 553 620 554 621 switch (p_slot->state) { 555 622 case BLINKINGOFF_STATE: 556 - /* Wait for exclusive access to hardware */ 557 - mutex_lock(&ctrl->ctrl_lock); 558 - 559 - if (PWR_LED(ctrl->ctrlcap)) { 623 + if (PWR_LED(ctrl->ctrlcap)) 560 624 p_slot->hpc_ops->green_led_on(p_slot); 561 - /* Wait for the command to complete */ 562 - wait_for_ctrl_irq (ctrl); 563 - } 564 - if (ATTN_LED(ctrl->ctrlcap)) { 565 - p_slot->hpc_ops->set_attention_status(p_slot, 0); 566 625 567 - /* Wait for the command to complete */ 568 - wait_for_ctrl_irq (ctrl); 569 - } 570 - /* Done with exclusive hardware access */ 571 - mutex_unlock(&ctrl->ctrl_lock); 626 + if (ATTN_LED(ctrl->ctrlcap)) 627 + p_slot->hpc_ops->set_attention_status(p_slot, 0); 572 628 break; 573 629 case BLINKINGON_STATE: 574 - /* Wait for exclusive access to hardware */ 575 - mutex_lock(&ctrl->ctrl_lock); 576 - 577 - if (PWR_LED(ctrl->ctrlcap)) { 630 + if (PWR_LED(ctrl->ctrlcap)) 578 631 p_slot->hpc_ops->green_led_off(p_slot); 579 - /* Wait for the command to complete */ 580 - wait_for_ctrl_irq (ctrl); 581 - } 582 - if (ATTN_LED(ctrl->ctrlcap)){ 583 - p_slot->hpc_ops->set_attention_status(p_slot, 0); 584 - /* Wait for the command to complete */ 585 - wait_for_ctrl_irq (ctrl); 586 - } 587 - /* Done with exclusive hardware access */ 588 - mutex_unlock(&ctrl->ctrl_lock); 589 632 633 + if (ATTN_LED(ctrl->ctrlcap)) 634 + p_slot->hpc_ops->set_attention_status(p_slot, 0); 590 635 break; 591 636 default: 592 637 warn("Not a valid state\n"); 593 638 return; 594 639 } 595 - info(msg_button_cancel, slot_name(p_slot)); 640 + info("PCI slot #%s - action canceled due to button press.\n", slot_name(p_slot)); 596 641 p_slot->state = STATIC_STATE; 597 642 } 598 643 /* ***********Button Pressed (No action on 1st press...) */ ··· 583 672 /* slot is on */ 584 673 dbg("slot is on\n"); 585 674 p_slot->state = BLINKINGOFF_STATE; 586 - info(msg_button_off, slot_name(p_slot)); 675 + info("PCI slot #%s - powering off due to button press.\n", slot_name(p_slot)); 587 676 } else { 588 677 /* slot is off */ 589 678 dbg("slot is off\n"); 590 679 p_slot->state = BLINKINGON_STATE; 591 - info(msg_button_on, slot_name(p_slot)); 680 + info("PCI slot #%s - powering on due to button press.\n", slot_name(p_slot)); 592 681 } 593 - 594 - /* Wait for exclusive access to hardware */ 595 - mutex_lock(&ctrl->ctrl_lock); 596 682 597 683 /* blink green LED and turn off amber */ 598 - if (PWR_LED(ctrl->ctrlcap)) { 684 + if (PWR_LED(ctrl->ctrlcap)) 599 685 p_slot->hpc_ops->green_led_blink(p_slot); 600 - /* Wait for the command to complete */ 601 - wait_for_ctrl_irq (ctrl); 602 - } 603 686 604 - if (ATTN_LED(ctrl->ctrlcap)) { 687 + if (ATTN_LED(ctrl->ctrlcap)) 605 688 p_slot->hpc_ops->set_attention_status(p_slot, 0); 606 - 607 - /* Wait for the command to complete */ 608 - wait_for_ctrl_irq (ctrl); 609 - } 610 - 611 - /* Done with exclusive hardware access */ 612 - mutex_unlock(&ctrl->ctrl_lock); 613 689 614 690 init_timer(&p_slot->task_event); 615 691 p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ ··· 610 712 else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) { 611 713 if (POWER_CTRL(ctrl->ctrlcap)) { 612 714 dbg("power fault\n"); 613 - /* Wait for exclusive access to hardware */ 614 - mutex_lock(&ctrl->ctrl_lock); 615 - 616 - if (ATTN_LED(ctrl->ctrlcap)) { 715 + if (ATTN_LED(ctrl->ctrlcap)) 617 716 p_slot->hpc_ops->set_attention_status(p_slot, 1); 618 - wait_for_ctrl_irq (ctrl); 619 - } 620 717 621 - if (PWR_LED(ctrl->ctrlcap)) { 718 + if (PWR_LED(ctrl->ctrlcap)) 622 719 p_slot->hpc_ops->green_led_off(p_slot); 623 - wait_for_ctrl_irq (ctrl); 624 - } 625 - 626 - /* Done with exclusive hardware access */ 627 - mutex_unlock(&ctrl->ctrl_lock); 628 720 } 629 721 } 630 722 /***********SURPRISE REMOVAL********************/ ··· 641 753 } /* End of FOR loop */ 642 754 } 643 755 } 644 - 645 756 646 757 int pciehp_enable_slot(struct slot *p_slot) 647 758 {
+323 -512
drivers/pci/hotplug/pciehp_hpc.c
··· 35 35 #include <linux/timer.h> 36 36 #include <linux/pci.h> 37 37 #include <linux/interrupt.h> 38 + #include <linux/time.h> 38 39 39 40 #include "../pci.h" 40 41 #include "pciehp.h" ··· 106 105 ROOTCTRL = offsetof(struct ctrl_reg, root_ctrl), 107 106 ROOTSTATUS = offsetof(struct ctrl_reg, root_status), 108 107 }; 109 - static int pcie_cap_base = 0; /* Base of the PCI Express capability item structure */ 110 108 111 - #define PCIE_CAP_ID(cb) ( cb + PCIECAPID ) 112 - #define NXT_CAP_PTR(cb) ( cb + NXTCAPPTR ) 113 - #define CAP_REG(cb) ( cb + CAPREG ) 114 - #define DEV_CAP(cb) ( cb + DEVCAP ) 115 - #define DEV_CTRL(cb) ( cb + DEVCTRL ) 116 - #define DEV_STATUS(cb) ( cb + DEVSTATUS ) 117 - #define LNK_CAP(cb) ( cb + LNKCAP ) 118 - #define LNK_CTRL(cb) ( cb + LNKCTRL ) 119 - #define LNK_STATUS(cb) ( cb + LNKSTATUS ) 120 - #define SLOT_CAP(cb) ( cb + SLOTCAP ) 121 - #define SLOT_CTRL(cb) ( cb + SLOTCTRL ) 122 - #define SLOT_STATUS(cb) ( cb + SLOTSTATUS ) 123 - #define ROOT_CTRL(cb) ( cb + ROOTCTRL ) 124 - #define ROOT_STATUS(cb) ( cb + ROOTSTATUS ) 109 + static inline int pciehp_readw(struct controller *ctrl, int reg, u16 *value) 110 + { 111 + struct pci_dev *dev = ctrl->pci_dev; 112 + return pci_read_config_word(dev, ctrl->cap_base + reg, value); 113 + } 125 114 126 - #define hp_register_read_word(pdev, reg , value) \ 127 - pci_read_config_word(pdev, reg, &value) 115 + static inline int pciehp_readl(struct controller *ctrl, int reg, u32 *value) 116 + { 117 + struct pci_dev *dev = ctrl->pci_dev; 118 + return pci_read_config_dword(dev, ctrl->cap_base + reg, value); 119 + } 128 120 129 - #define hp_register_read_dword(pdev, reg , value) \ 130 - pci_read_config_dword(pdev, reg, &value) 131 - 132 - #define hp_register_write_word(pdev, reg , value) \ 133 - pci_write_config_word(pdev, reg, value) 121 + static inline int pciehp_writew(struct controller *ctrl, int reg, u16 value) 122 + { 123 + struct pci_dev *dev = ctrl->pci_dev; 124 + return pci_write_config_word(dev, ctrl->cap_base + reg, value); 125 + } 134 126 135 - #define hp_register_dwrite_word(pdev, reg , value) \ 136 - pci_write_config_dword(pdev, reg, value) 127 + static inline int pciehp_writel(struct controller *ctrl, int reg, u32 value) 128 + { 129 + struct pci_dev *dev = ctrl->pci_dev; 130 + return pci_write_config_dword(dev, ctrl->cap_base + reg, value); 131 + } 137 132 138 133 /* Field definitions in PCI Express Capabilities Register */ 139 134 #define CAP_VER 0x000F ··· 193 196 #define ATTN_LED_CTRL 0x00C0 194 197 #define PWR_LED_CTRL 0x0300 195 198 #define PWR_CTRL 0x0400 199 + #define EMI_CTRL 0x0800 196 200 197 201 /* Attention indicator and Power indicator states */ 198 202 #define LED_ON 0x01 ··· 204 206 #define POWER_ON 0 205 207 #define POWER_OFF 0x0400 206 208 209 + /* EMI Status defines */ 210 + #define EMI_DISENGAGED 0 211 + #define EMI_ENGAGED 1 212 + 207 213 /* Field definitions in Slot Status Register */ 208 214 #define ATTN_BUTTN_PRESSED 0x0001 209 215 #define PWR_FAULT_DETECTED 0x0002 ··· 216 214 #define CMD_COMPLETED 0x0010 217 215 #define MRL_STATE 0x0020 218 216 #define PRSN_STATE 0x0040 217 + #define EMI_STATE 0x0080 218 + #define EMI_STATUS_BIT 7 219 219 220 220 static spinlock_t hpc_event_lock; 221 221 222 222 DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ 223 - static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */ 224 223 static int ctlr_seq_num = 0; /* Controller sequence # */ 225 - static spinlock_t list_lock; 226 224 227 - static irqreturn_t pcie_isr(int IRQ, void *dev_id); 228 - 229 - static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds); 225 + static irqreturn_t pcie_isr(int irq, void *dev_id); 226 + static void start_int_poll_timer(struct controller *ctrl, int sec); 230 227 231 228 /* This is the interrupt polling timeout function. */ 232 - static void int_poll_timeout(unsigned long lphp_ctlr) 229 + static void int_poll_timeout(unsigned long data) 233 230 { 234 - struct php_ctlr_state_s *php_ctlr = (struct php_ctlr_state_s *)lphp_ctlr; 231 + struct controller *ctrl = (struct controller *)data; 235 232 236 233 DBG_ENTER_ROUTINE 237 234 238 - if ( !php_ctlr ) { 239 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 240 - return; 241 - } 242 - 243 235 /* Poll for interrupt events. regs == NULL => polling */ 244 - pcie_isr( 0, (void *)php_ctlr ); 236 + pcie_isr(0, ctrl); 245 237 246 - init_timer(&php_ctlr->int_poll_timer); 247 - 238 + init_timer(&ctrl->poll_timer); 248 239 if (!pciehp_poll_time) 249 240 pciehp_poll_time = 2; /* reset timer to poll in 2 secs if user doesn't specify at module installation*/ 250 241 251 - start_int_poll_timer(php_ctlr, pciehp_poll_time); 252 - 253 - return; 242 + start_int_poll_timer(ctrl, pciehp_poll_time); 254 243 } 255 244 256 245 /* This function starts the interrupt polling timer. */ 257 - static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int seconds) 246 + static void start_int_poll_timer(struct controller *ctrl, int sec) 258 247 { 259 - if (!php_ctlr) { 260 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 261 - return; 248 + /* Clamp to sane value */ 249 + if ((sec <= 0) || (sec > 60)) 250 + sec = 2; 251 + 252 + ctrl->poll_timer.function = &int_poll_timeout; 253 + ctrl->poll_timer.data = (unsigned long)ctrl; 254 + ctrl->poll_timer.expires = jiffies + sec * HZ; 255 + add_timer(&ctrl->poll_timer); 256 + } 257 + 258 + static inline int pcie_wait_cmd(struct controller *ctrl) 259 + { 260 + int retval = 0; 261 + unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; 262 + unsigned long timeout = msecs_to_jiffies(msecs); 263 + int rc; 264 + 265 + rc = wait_event_interruptible_timeout(ctrl->queue, 266 + !ctrl->cmd_busy, timeout); 267 + if (!rc) 268 + dbg("Command not completed in 1000 msec\n"); 269 + else if (rc < 0) { 270 + retval = -EINTR; 271 + info("Command was interrupted by a signal\n"); 262 272 } 263 273 264 - if ( ( seconds <= 0 ) || ( seconds > 60 ) ) 265 - seconds = 2; /* Clamp to sane value */ 266 - 267 - php_ctlr->int_poll_timer.function = &int_poll_timeout; 268 - php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; /* Instance data */ 269 - php_ctlr->int_poll_timer.expires = jiffies + seconds * HZ; 270 - add_timer(&php_ctlr->int_poll_timer); 271 - 272 - return; 274 + return retval; 273 275 } 274 276 275 277 static int pcie_write_cmd(struct slot *slot, u16 cmd) 276 278 { 277 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 279 + struct controller *ctrl = slot->ctrl; 278 280 int retval = 0; 279 281 u16 slot_status; 280 282 281 283 DBG_ENTER_ROUTINE 282 - 283 - if (!php_ctlr) { 284 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 285 - return -1; 284 + 285 + mutex_lock(&ctrl->ctrl_lock); 286 + 287 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 288 + if (retval) { 289 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 290 + goto out; 286 291 } 287 292 288 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); 289 - if (retval) { 290 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 291 - return retval; 292 - } 293 - 294 293 if ((slot_status & CMD_COMPLETED) == CMD_COMPLETED ) { 295 - /* After 1 sec and CMD_COMPLETED still not set, just proceed forward to issue 296 - the next command according to spec. Just print out the error message */ 297 - dbg("%s : CMD_COMPLETED not clear after 1 sec.\n", __FUNCTION__); 294 + /* After 1 sec and CMD_COMPLETED still not set, just 295 + proceed forward to issue the next command according 296 + to spec. Just print out the error message */ 297 + dbg("%s: CMD_COMPLETED not clear after 1 sec.\n", 298 + __FUNCTION__); 298 299 } 299 300 300 - retval = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), cmd | CMD_CMPL_INTR_ENABLE); 301 + ctrl->cmd_busy = 1; 302 + retval = pciehp_writew(ctrl, SLOTCTRL, (cmd | CMD_CMPL_INTR_ENABLE)); 301 303 if (retval) { 302 - err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); 303 - return retval; 304 + err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); 305 + goto out; 304 306 } 305 307 308 + /* 309 + * Wait for command completion. 310 + */ 311 + retval = pcie_wait_cmd(ctrl); 312 + out: 313 + mutex_unlock(&ctrl->ctrl_lock); 306 314 DBG_LEAVE_ROUTINE 307 315 return retval; 308 316 } 309 317 310 318 static int hpc_check_lnk_status(struct controller *ctrl) 311 319 { 312 - struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; 313 320 u16 lnk_status; 314 321 int retval = 0; 315 322 316 323 DBG_ENTER_ROUTINE 317 324 318 - if (!php_ctlr) { 319 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 320 - return -1; 321 - } 322 - 323 - retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(ctrl->cap_base), lnk_status); 324 - 325 + retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 325 326 if (retval) { 326 - err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); 327 + err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 327 328 return retval; 328 329 } 329 330 ··· 345 340 346 341 static int hpc_get_attention_status(struct slot *slot, u8 *status) 347 342 { 348 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 343 + struct controller *ctrl = slot->ctrl; 349 344 u16 slot_ctrl; 350 345 u8 atten_led_state; 351 346 int retval = 0; 352 347 353 348 DBG_ENTER_ROUTINE 354 349 355 - if (!php_ctlr) { 356 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 357 - return -1; 358 - } 359 - 360 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 361 - 350 + retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 362 351 if (retval) { 363 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 352 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 364 353 return retval; 365 354 } 366 355 367 - dbg("%s: SLOT_CTRL %x, value read %x\n", __FUNCTION__,SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 356 + dbg("%s: SLOTCTRL %x, value read %x\n", 357 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 368 358 369 359 atten_led_state = (slot_ctrl & ATTN_LED_CTRL) >> 6; 370 360 ··· 385 385 return 0; 386 386 } 387 387 388 - static int hpc_get_power_status(struct slot * slot, u8 *status) 388 + static int hpc_get_power_status(struct slot *slot, u8 *status) 389 389 { 390 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 390 + struct controller *ctrl = slot->ctrl; 391 391 u16 slot_ctrl; 392 392 u8 pwr_state; 393 393 int retval = 0; 394 394 395 395 DBG_ENTER_ROUTINE 396 396 397 - if (!php_ctlr) { 398 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 399 - return -1; 400 - } 401 - 402 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 403 - 397 + retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 404 398 if (retval) { 405 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 399 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 406 400 return retval; 407 401 } 408 - dbg("%s: SLOT_CTRL %x value read %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 402 + dbg("%s: SLOTCTRL %x value read %x\n", 403 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 409 404 410 405 pwr_state = (slot_ctrl & PWR_CTRL) >> 10; 411 406 ··· 423 428 424 429 static int hpc_get_latch_status(struct slot *slot, u8 *status) 425 430 { 426 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 431 + struct controller *ctrl = slot->ctrl; 427 432 u16 slot_status; 428 433 int retval = 0; 429 434 430 435 DBG_ENTER_ROUTINE 431 436 432 - if (!php_ctlr) { 433 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 434 - return -1; 435 - } 436 - 437 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); 438 - 437 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 439 438 if (retval) { 440 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 439 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 441 440 return retval; 442 441 } 443 442 ··· 443 454 444 455 static int hpc_get_adapter_status(struct slot *slot, u8 *status) 445 456 { 446 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 457 + struct controller *ctrl = slot->ctrl; 447 458 u16 slot_status; 448 459 u8 card_state; 449 460 int retval = 0; 450 461 451 462 DBG_ENTER_ROUTINE 452 463 453 - if (!php_ctlr) { 454 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 455 - return -1; 456 - } 457 - 458 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); 459 - 464 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 460 465 if (retval) { 461 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 466 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 462 467 return retval; 463 468 } 464 469 card_state = (u8)((slot_status & PRSN_STATE) >> 6); ··· 462 479 return 0; 463 480 } 464 481 465 - static int hpc_query_power_fault(struct slot * slot) 482 + static int hpc_query_power_fault(struct slot *slot) 466 483 { 467 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 484 + struct controller *ctrl = slot->ctrl; 468 485 u16 slot_status; 469 486 u8 pwr_fault; 470 487 int retval = 0; 471 488 472 489 DBG_ENTER_ROUTINE 473 490 474 - if (!php_ctlr) { 475 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 476 - return -1; 477 - } 478 - 479 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(slot->ctrl->cap_base), slot_status); 480 - 491 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 481 492 if (retval) { 482 - err("%s : Cannot check for power fault\n", __FUNCTION__); 493 + err("%s: Cannot check for power fault\n", __FUNCTION__); 483 494 return retval; 484 495 } 485 496 pwr_fault = (u8)((slot_status & PWR_FAULT_DETECTED) >> 1); ··· 482 505 return pwr_fault; 483 506 } 484 507 485 - static int hpc_set_attention_status(struct slot *slot, u8 value) 508 + static int hpc_get_emi_status(struct slot *slot, u8 *status) 486 509 { 487 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 510 + struct controller *ctrl = slot->ctrl; 511 + u16 slot_status; 512 + int retval = 0; 513 + 514 + DBG_ENTER_ROUTINE 515 + 516 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 517 + if (retval) { 518 + err("%s : Cannot check EMI status\n", __FUNCTION__); 519 + return retval; 520 + } 521 + *status = (slot_status & EMI_STATE) >> EMI_STATUS_BIT; 522 + 523 + DBG_LEAVE_ROUTINE 524 + return retval; 525 + } 526 + 527 + static int hpc_toggle_emi(struct slot *slot) 528 + { 529 + struct controller *ctrl = slot->ctrl; 488 530 u16 slot_cmd = 0; 489 531 u16 slot_ctrl; 490 532 int rc = 0; 491 533 492 534 DBG_ENTER_ROUTINE 493 535 494 - if (!php_ctlr) { 495 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 496 - return -1; 497 - } 498 - 499 - if (slot->hp_slot >= php_ctlr->num_slots) { 500 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 501 - return -1; 502 - } 503 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 504 - 536 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 505 537 if (rc) { 506 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 538 + err("%s : hp_register_read_word SLOT_CTRL failed\n", 539 + __FUNCTION__); 540 + return rc; 541 + } 542 + 543 + slot_cmd = (slot_ctrl | EMI_CTRL); 544 + if (!pciehp_poll_mode) 545 + slot_cmd = slot_cmd | HP_INTR_ENABLE; 546 + 547 + pcie_write_cmd(slot, slot_cmd); 548 + slot->last_emi_toggle = get_seconds(); 549 + DBG_LEAVE_ROUTINE 550 + return rc; 551 + } 552 + 553 + static int hpc_set_attention_status(struct slot *slot, u8 value) 554 + { 555 + struct controller *ctrl = slot->ctrl; 556 + u16 slot_cmd = 0; 557 + u16 slot_ctrl; 558 + int rc = 0; 559 + 560 + DBG_ENTER_ROUTINE 561 + 562 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 563 + if (rc) { 564 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 507 565 return rc; 508 566 } 509 567 ··· 559 547 slot_cmd = slot_cmd | HP_INTR_ENABLE; 560 548 561 549 pcie_write_cmd(slot, slot_cmd); 562 - dbg("%s: SLOT_CTRL %x write cmd %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 550 + dbg("%s: SLOTCTRL %x write cmd %x\n", 551 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 563 552 564 553 DBG_LEAVE_ROUTINE 565 554 return rc; ··· 569 556 570 557 static void hpc_set_green_led_on(struct slot *slot) 571 558 { 572 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 559 + struct controller *ctrl = slot->ctrl; 573 560 u16 slot_cmd; 574 561 u16 slot_ctrl; 575 562 int rc = 0; 576 563 577 564 DBG_ENTER_ROUTINE 578 565 579 - if (!php_ctlr) { 580 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 581 - return ; 582 - } 583 - 584 - if (slot->hp_slot >= php_ctlr->num_slots) { 585 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 586 - return ; 587 - } 588 - 589 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 590 - 566 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 591 567 if (rc) { 592 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 568 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 593 569 return; 594 570 } 595 571 slot_cmd = (slot_ctrl & ~PWR_LED_CTRL) | 0x0100; ··· 587 585 588 586 pcie_write_cmd(slot, slot_cmd); 589 587 590 - dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 588 + dbg("%s: SLOTCTRL %x write cmd %x\n", 589 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 591 590 DBG_LEAVE_ROUTINE 592 591 return; 593 592 } 594 593 595 594 static void hpc_set_green_led_off(struct slot *slot) 596 595 { 597 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 596 + struct controller *ctrl = slot->ctrl; 598 597 u16 slot_cmd; 599 598 u16 slot_ctrl; 600 599 int rc = 0; 601 600 602 601 DBG_ENTER_ROUTINE 603 602 604 - if (!php_ctlr) { 605 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 606 - return ; 607 - } 608 - 609 - if (slot->hp_slot >= php_ctlr->num_slots) { 610 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 611 - return ; 612 - } 613 - 614 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 615 - 603 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 616 604 if (rc) { 617 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 605 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 618 606 return; 619 607 } 620 608 ··· 613 621 if (!pciehp_poll_mode) 614 622 slot_cmd = slot_cmd | HP_INTR_ENABLE; 615 623 pcie_write_cmd(slot, slot_cmd); 616 - dbg("%s: SLOT_CTRL %x write cmd %x\n", __FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 624 + dbg("%s: SLOTCTRL %x write cmd %x\n", 625 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 617 626 618 627 DBG_LEAVE_ROUTINE 619 628 return; ··· 622 629 623 630 static void hpc_set_green_led_blink(struct slot *slot) 624 631 { 625 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 632 + struct controller *ctrl = slot->ctrl; 626 633 u16 slot_cmd; 627 634 u16 slot_ctrl; 628 635 int rc = 0; 629 636 630 637 DBG_ENTER_ROUTINE 631 638 632 - if (!php_ctlr) { 633 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 634 - return ; 635 - } 636 - 637 - if (slot->hp_slot >= php_ctlr->num_slots) { 638 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 639 - return ; 640 - } 641 - 642 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 643 - 639 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 644 640 if (rc) { 645 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 641 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 646 642 return; 647 643 } 648 644 ··· 641 659 slot_cmd = slot_cmd | HP_INTR_ENABLE; 642 660 pcie_write_cmd(slot, slot_cmd); 643 661 644 - dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 662 + dbg("%s: SLOTCTRL %x write cmd %x\n", 663 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 645 664 DBG_LEAVE_ROUTINE 646 665 return; 647 666 } 648 667 649 - int pcie_get_ctlr_slot_config(struct controller *ctrl, 650 - int *num_ctlr_slots, /* number of slots in this HPC; only 1 in PCIE */ 651 - int *first_device_num, /* PCI dev num of the first slot in this PCIE */ 652 - int *physical_slot_num, /* phy slot num of the first slot in this PCIE */ 653 - u8 *ctrlcap) 654 - { 655 - struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; 656 - u32 slot_cap; 657 - int rc = 0; 658 - 659 - DBG_ENTER_ROUTINE 660 - 661 - if (!php_ctlr) { 662 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 663 - return -1; 664 - } 665 - 666 - *first_device_num = 0; 667 - *num_ctlr_slots = 1; 668 - 669 - rc = hp_register_read_dword(php_ctlr->pci_dev, SLOT_CAP(ctrl->cap_base), slot_cap); 670 - 671 - if (rc) { 672 - err("%s : hp_register_read_dword SLOT_CAP failed\n", __FUNCTION__); 673 - return -1; 674 - } 675 - 676 - *physical_slot_num = slot_cap >> 19; 677 - dbg("%s: PSN %d \n", __FUNCTION__, *physical_slot_num); 678 - 679 - *ctrlcap = slot_cap & 0x0000007f; 680 - 681 - DBG_LEAVE_ROUTINE 682 - return 0; 683 - } 684 - 685 668 static void hpc_release_ctlr(struct controller *ctrl) 686 669 { 687 - struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle; 688 - struct php_ctlr_state_s *p, *p_prev; 689 - 690 670 DBG_ENTER_ROUTINE 691 671 692 - if (!php_ctlr) { 693 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 694 - return ; 695 - } 696 - 697 - if (pciehp_poll_mode) { 698 - del_timer(&php_ctlr->int_poll_timer); 699 - } else { 700 - if (php_ctlr->irq) { 701 - free_irq(php_ctlr->irq, ctrl); 702 - php_ctlr->irq = 0; 703 - } 704 - } 705 - if (php_ctlr->pci_dev) 706 - php_ctlr->pci_dev = NULL; 707 - 708 - spin_lock(&list_lock); 709 - p = php_ctlr_list_head; 710 - p_prev = NULL; 711 - while (p) { 712 - if (p == php_ctlr) { 713 - if (p_prev) 714 - p_prev->pnext = p->pnext; 715 - else 716 - php_ctlr_list_head = p->pnext; 717 - break; 718 - } else { 719 - p_prev = p; 720 - p = p->pnext; 721 - } 722 - } 723 - spin_unlock(&list_lock); 724 - 725 - kfree(php_ctlr); 672 + if (pciehp_poll_mode) 673 + del_timer(&ctrl->poll_timer); 674 + else 675 + free_irq(ctrl->pci_dev->irq, ctrl); 726 676 727 677 DBG_LEAVE_ROUTINE 728 - 729 678 } 730 679 731 680 static int hpc_power_on_slot(struct slot * slot) 732 681 { 733 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 682 + struct controller *ctrl = slot->ctrl; 734 683 u16 slot_cmd; 735 684 u16 slot_ctrl, slot_status; 736 - 737 685 int retval = 0; 738 686 739 687 DBG_ENTER_ROUTINE 740 688 741 - if (!php_ctlr) { 742 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 743 - return -1; 744 - } 745 - 746 689 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); 747 - if (slot->hp_slot >= php_ctlr->num_slots) { 748 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 749 - return -1; 750 - } 751 690 752 691 /* Clear sticky power-fault bit from previous power failures */ 753 - hp_register_read_word(php_ctlr->pci_dev, 754 - SLOT_STATUS(slot->ctrl->cap_base), slot_status); 755 - slot_status &= PWR_FAULT_DETECTED; 756 - if (slot_status) 757 - hp_register_write_word(php_ctlr->pci_dev, 758 - SLOT_STATUS(slot->ctrl->cap_base), slot_status); 759 - 760 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 761 - 692 + retval = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 762 693 if (retval) { 763 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 694 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 695 + return retval; 696 + } 697 + slot_status &= PWR_FAULT_DETECTED; 698 + if (slot_status) { 699 + retval = pciehp_writew(ctrl, SLOTSTATUS, slot_status); 700 + if (retval) { 701 + err("%s: Cannot write to SLOTSTATUS register\n", 702 + __FUNCTION__); 703 + return retval; 704 + } 705 + } 706 + 707 + retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 708 + if (retval) { 709 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 764 710 return retval; 765 711 } 766 712 ··· 708 798 err("%s: Write %x command failed!\n", __FUNCTION__, slot_cmd); 709 799 return -1; 710 800 } 711 - dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 801 + dbg("%s: SLOTCTRL %x write cmd %x\n", 802 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 712 803 713 804 DBG_LEAVE_ROUTINE 714 805 ··· 718 807 719 808 static int hpc_power_off_slot(struct slot * slot) 720 809 { 721 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 810 + struct controller *ctrl = slot->ctrl; 722 811 u16 slot_cmd; 723 812 u16 slot_ctrl; 724 - 725 813 int retval = 0; 726 814 727 815 DBG_ENTER_ROUTINE 728 816 729 - if (!php_ctlr) { 730 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 731 - return -1; 732 - } 733 - 734 817 dbg("%s: slot->hp_slot %x\n", __FUNCTION__, slot->hp_slot); 735 - slot->hp_slot = 0; 736 - if (slot->hp_slot >= php_ctlr->num_slots) { 737 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 738 - return -1; 739 - } 740 - retval = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(slot->ctrl->cap_base), slot_ctrl); 741 818 819 + retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 742 820 if (retval) { 743 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 821 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 744 822 return retval; 745 823 } 746 824 ··· 754 854 err("%s: Write command failed!\n", __FUNCTION__); 755 855 return -1; 756 856 } 757 - dbg("%s: SLOT_CTRL %x write cmd %x\n",__FUNCTION__, SLOT_CTRL(slot->ctrl->cap_base), slot_cmd); 857 + dbg("%s: SLOTCTRL %x write cmd %x\n", 858 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_cmd); 758 859 759 860 DBG_LEAVE_ROUTINE 760 861 761 862 return retval; 762 863 } 763 864 764 - static irqreturn_t pcie_isr(int IRQ, void *dev_id) 865 + static irqreturn_t pcie_isr(int irq, void *dev_id) 765 866 { 766 - struct controller *ctrl = NULL; 767 - struct php_ctlr_state_s *php_ctlr; 768 - u8 schedule_flag = 0; 867 + struct controller *ctrl = (struct controller *)dev_id; 769 868 u16 slot_status, intr_detect, intr_loc; 770 869 u16 temp_word; 771 870 int hp_slot = 0; /* only 1 slot per PCI Express port */ 772 871 int rc = 0; 773 872 774 - if (!dev_id) 775 - return IRQ_NONE; 776 - 777 - if (!pciehp_poll_mode) { 778 - ctrl = dev_id; 779 - php_ctlr = ctrl->hpc_ctlr_handle; 780 - } else { 781 - php_ctlr = dev_id; 782 - ctrl = (struct controller *)php_ctlr->callback_instance_id; 783 - } 784 - 785 - if (!ctrl) { 786 - dbg("%s: dev_id %p ctlr == NULL\n", __FUNCTION__, (void*) dev_id); 787 - return IRQ_NONE; 788 - } 789 - 790 - if (!php_ctlr) { 791 - dbg("%s: php_ctlr == NULL\n", __FUNCTION__); 792 - return IRQ_NONE; 793 - } 794 - 795 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 873 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 796 874 if (rc) { 797 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 875 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 798 876 return IRQ_NONE; 799 877 } 800 878 ··· 788 910 dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc); 789 911 /* Mask Hot-plug Interrupt Enable */ 790 912 if (!pciehp_poll_mode) { 791 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); 913 + rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 792 914 if (rc) { 793 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 915 + err("%s: Cannot read SLOT_CTRL register\n", 916 + __FUNCTION__); 794 917 return IRQ_NONE; 795 918 } 796 919 797 - dbg("%s: hp_register_read_word SLOT_CTRL with value %x\n", __FUNCTION__, temp_word); 920 + dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n", 921 + __FUNCTION__, temp_word); 798 922 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; 923 + rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 924 + if (rc) { 925 + err("%s: Cannot write to SLOTCTRL register\n", 926 + __FUNCTION__); 927 + return IRQ_NONE; 928 + } 799 929 800 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); 930 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 801 931 if (rc) { 802 - err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); 932 + err("%s: Cannot read SLOT_STATUS register\n", 933 + __FUNCTION__); 803 934 return IRQ_NONE; 804 935 } 805 - 806 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 807 - if (rc) { 808 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 809 - return IRQ_NONE; 810 - } 811 - dbg("%s: hp_register_read_word SLOT_STATUS with value %x\n", __FUNCTION__, slot_status); 936 + dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n", 937 + __FUNCTION__, slot_status); 812 938 813 939 /* Clear command complete interrupt caused by this write */ 814 940 temp_word = 0x1f; 815 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); 941 + rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 816 942 if (rc) { 817 - err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); 943 + err("%s: Cannot write to SLOTSTATUS register\n", 944 + __FUNCTION__); 818 945 return IRQ_NONE; 819 946 } 820 947 } ··· 828 945 /* 829 946 * Command Complete Interrupt Pending 830 947 */ 948 + ctrl->cmd_busy = 0; 831 949 wake_up_interruptible(&ctrl->queue); 832 950 } 833 951 834 - if ((php_ctlr->switch_change_callback) && (intr_loc & MRL_SENS_CHANGED)) 835 - schedule_flag += php_ctlr->switch_change_callback( 836 - hp_slot, php_ctlr->callback_instance_id); 837 - if ((php_ctlr->attention_button_callback) && (intr_loc & ATTN_BUTTN_PRESSED)) 838 - schedule_flag += php_ctlr->attention_button_callback( 839 - hp_slot, php_ctlr->callback_instance_id); 840 - if ((php_ctlr->presence_change_callback) && (intr_loc & PRSN_DETECT_CHANGED)) 841 - schedule_flag += php_ctlr->presence_change_callback( 842 - hp_slot , php_ctlr->callback_instance_id); 843 - if ((php_ctlr->power_fault_callback) && (intr_loc & PWR_FAULT_DETECTED)) 844 - schedule_flag += php_ctlr->power_fault_callback( 845 - hp_slot, php_ctlr->callback_instance_id); 952 + if (intr_loc & MRL_SENS_CHANGED) 953 + pciehp_handle_switch_change(hp_slot, ctrl); 954 + 955 + if (intr_loc & ATTN_BUTTN_PRESSED) 956 + pciehp_handle_attention_button(hp_slot, ctrl); 957 + 958 + if (intr_loc & PRSN_DETECT_CHANGED) 959 + pciehp_handle_presence_change(hp_slot, ctrl); 960 + 961 + if (intr_loc & PWR_FAULT_DETECTED) 962 + pciehp_handle_power_fault(hp_slot, ctrl); 846 963 847 964 /* Clear all events after serving them */ 848 965 temp_word = 0x1F; 849 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); 966 + rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 850 967 if (rc) { 851 - err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); 968 + err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); 852 969 return IRQ_NONE; 853 970 } 854 971 /* Unmask Hot-plug Interrupt Enable */ 855 972 if (!pciehp_poll_mode) { 856 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); 973 + rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 857 974 if (rc) { 858 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 975 + err("%s: Cannot read SLOTCTRL register\n", 976 + __FUNCTION__); 859 977 return IRQ_NONE; 860 978 } 861 979 862 980 dbg("%s: Unmask Hot-plug Interrupt Enable\n", __FUNCTION__); 863 981 temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; 864 982 865 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), temp_word); 983 + rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 866 984 if (rc) { 867 - err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); 985 + err("%s: Cannot write to SLOTCTRL register\n", 986 + __FUNCTION__); 868 987 return IRQ_NONE; 869 988 } 870 - 871 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 989 + 990 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 872 991 if (rc) { 873 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 992 + err("%s: Cannot read SLOT_STATUS register\n", 993 + __FUNCTION__); 874 994 return IRQ_NONE; 875 995 } 876 996 877 997 /* Clear command complete interrupt caused by this write */ 878 998 temp_word = 0x1F; 879 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); 999 + rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 880 1000 if (rc) { 881 - err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); 1001 + err("%s: Cannot write to SLOTSTATUS failed\n", 1002 + __FUNCTION__); 882 1003 return IRQ_NONE; 883 1004 } 884 - dbg("%s: hp_register_write_word SLOT_STATUS with value %x\n", __FUNCTION__, temp_word); 1005 + dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n", 1006 + __FUNCTION__, temp_word); 885 1007 } 886 1008 887 1009 return IRQ_HANDLED; ··· 894 1006 895 1007 static int hpc_get_max_lnk_speed (struct slot *slot, enum pci_bus_speed *value) 896 1008 { 897 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1009 + struct controller *ctrl = slot->ctrl; 898 1010 enum pcie_link_speed lnk_speed; 899 1011 u32 lnk_cap; 900 1012 int retval = 0; 901 1013 902 1014 DBG_ENTER_ROUTINE 903 1015 904 - if (!php_ctlr) { 905 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 906 - return -1; 907 - } 908 - 909 - if (slot->hp_slot >= php_ctlr->num_slots) { 910 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 911 - return -1; 912 - } 913 - 914 - retval = hp_register_read_dword(php_ctlr->pci_dev, LNK_CAP(slot->ctrl->cap_base), lnk_cap); 915 - 1016 + retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); 916 1017 if (retval) { 917 - err("%s : hp_register_read_dword LNK_CAP failed\n", __FUNCTION__); 1018 + err("%s: Cannot read LNKCAP register\n", __FUNCTION__); 918 1019 return retval; 919 1020 } 920 1021 ··· 924 1047 925 1048 static int hpc_get_max_lnk_width (struct slot *slot, enum pcie_link_width *value) 926 1049 { 927 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1050 + struct controller *ctrl = slot->ctrl; 928 1051 enum pcie_link_width lnk_wdth; 929 1052 u32 lnk_cap; 930 1053 int retval = 0; 931 1054 932 1055 DBG_ENTER_ROUTINE 933 1056 934 - if (!php_ctlr) { 935 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 936 - return -1; 937 - } 938 - 939 - if (slot->hp_slot >= php_ctlr->num_slots) { 940 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 941 - return -1; 942 - } 943 - 944 - retval = hp_register_read_dword(php_ctlr->pci_dev, LNK_CAP(slot->ctrl->cap_base), lnk_cap); 945 - 1057 + retval = pciehp_readl(ctrl, LNKCAP, &lnk_cap); 946 1058 if (retval) { 947 - err("%s : hp_register_read_dword LNK_CAP failed\n", __FUNCTION__); 1059 + err("%s: Cannot read LNKCAP register\n", __FUNCTION__); 948 1060 return retval; 949 1061 } 950 1062 ··· 975 1109 976 1110 static int hpc_get_cur_lnk_speed (struct slot *slot, enum pci_bus_speed *value) 977 1111 { 978 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1112 + struct controller *ctrl = slot->ctrl; 979 1113 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN; 980 1114 int retval = 0; 981 1115 u16 lnk_status; 982 1116 983 1117 DBG_ENTER_ROUTINE 984 1118 985 - if (!php_ctlr) { 986 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 987 - return -1; 988 - } 989 - 990 - if (slot->hp_slot >= php_ctlr->num_slots) { 991 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 992 - return -1; 993 - } 994 - 995 - retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(slot->ctrl->cap_base), lnk_status); 996 - 1119 + retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 997 1120 if (retval) { 998 - err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); 1121 + err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 999 1122 return retval; 1000 1123 } 1001 1124 ··· 1005 1150 1006 1151 static int hpc_get_cur_lnk_width (struct slot *slot, enum pcie_link_width *value) 1007 1152 { 1008 - struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle; 1153 + struct controller *ctrl = slot->ctrl; 1009 1154 enum pcie_link_width lnk_wdth = PCIE_LNK_WIDTH_UNKNOWN; 1010 1155 int retval = 0; 1011 1156 u16 lnk_status; 1012 1157 1013 1158 DBG_ENTER_ROUTINE 1014 1159 1015 - if (!php_ctlr) { 1016 - err("%s: Invalid HPC controller handle!\n", __FUNCTION__); 1017 - return -1; 1018 - } 1019 - 1020 - if (slot->hp_slot >= php_ctlr->num_slots) { 1021 - err("%s: Invalid HPC slot number!\n", __FUNCTION__); 1022 - return -1; 1023 - } 1024 - 1025 - retval = hp_register_read_word(php_ctlr->pci_dev, LNK_STATUS(slot->ctrl->cap_base), lnk_status); 1026 - 1160 + retval = pciehp_readw(ctrl, LNKSTATUS, &lnk_status); 1027 1161 if (retval) { 1028 - err("%s : hp_register_read_word LNK_STATUS failed\n", __FUNCTION__); 1162 + err("%s: Cannot read LNKSTATUS register\n", __FUNCTION__); 1029 1163 return retval; 1030 1164 } 1031 1165 ··· 1062 1218 .get_attention_status = hpc_get_attention_status, 1063 1219 .get_latch_status = hpc_get_latch_status, 1064 1220 .get_adapter_status = hpc_get_adapter_status, 1221 + .get_emi_status = hpc_get_emi_status, 1222 + .toggle_emi = hpc_toggle_emi, 1065 1223 1066 1224 .get_max_bus_speed = hpc_get_max_lnk_speed, 1067 1225 .get_cur_bus_speed = hpc_get_cur_lnk_speed, ··· 1151 1305 1152 1306 int pcie_init(struct controller * ctrl, struct pcie_device *dev) 1153 1307 { 1154 - struct php_ctlr_state_s *php_ctlr, *p; 1155 - void *instance_id = ctrl; 1156 1308 int rc; 1157 1309 static int first = 1; 1158 1310 u16 temp_word; 1159 1311 u16 cap_reg; 1160 1312 u16 intr_enable = 0; 1161 1313 u32 slot_cap; 1162 - int cap_base, saved_cap_base; 1314 + int cap_base; 1163 1315 u16 slot_status, slot_ctrl; 1164 1316 struct pci_dev *pdev; 1165 1317 1166 1318 DBG_ENTER_ROUTINE 1167 1319 1168 - spin_lock_init(&list_lock); 1169 - php_ctlr = kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL); 1170 - 1171 - if (!php_ctlr) { /* allocate controller state data */ 1172 - err("%s: HPC controller memory allocation error!\n", __FUNCTION__); 1173 - goto abort; 1174 - } 1175 - 1176 - memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s)); 1177 - 1178 1320 pdev = dev->port; 1179 - php_ctlr->pci_dev = pdev; /* save pci_dev in context */ 1321 + ctrl->pci_dev = pdev; /* save pci_dev in context */ 1180 1322 1181 1323 dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", 1182 1324 __FUNCTION__, pdev->vendor, pdev->device); 1183 - 1184 - saved_cap_base = pcie_cap_base; 1185 1325 1186 1326 if ((cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP)) == 0) { 1187 1327 dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __FUNCTION__); ··· 1176 1344 1177 1345 ctrl->cap_base = cap_base; 1178 1346 1179 - dbg("%s: pcie_cap_base %x\n", __FUNCTION__, pcie_cap_base); 1347 + dbg("%s: pcie_cap_base %x\n", __FUNCTION__, cap_base); 1180 1348 1181 - rc = hp_register_read_word(pdev, CAP_REG(ctrl->cap_base), cap_reg); 1349 + rc = pciehp_readw(ctrl, CAPREG, &cap_reg); 1182 1350 if (rc) { 1183 - err("%s : hp_register_read_word CAP_REG failed\n", __FUNCTION__); 1351 + err("%s: Cannot read CAPREG register\n", __FUNCTION__); 1184 1352 goto abort_free_ctlr; 1185 1353 } 1186 - dbg("%s: CAP_REG offset %x cap_reg %x\n", __FUNCTION__, CAP_REG(ctrl->cap_base), cap_reg); 1354 + dbg("%s: CAPREG offset %x cap_reg %x\n", 1355 + __FUNCTION__, ctrl->cap_base + CAPREG, cap_reg); 1187 1356 1188 1357 if (((cap_reg & SLOT_IMPL) == 0) || (((cap_reg & DEV_PORT_TYPE) != 0x0040) 1189 1358 && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { ··· 1192 1359 goto abort_free_ctlr; 1193 1360 } 1194 1361 1195 - rc = hp_register_read_dword(php_ctlr->pci_dev, SLOT_CAP(ctrl->cap_base), slot_cap); 1362 + rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); 1196 1363 if (rc) { 1197 - err("%s : hp_register_read_word CAP_REG failed\n", __FUNCTION__); 1364 + err("%s: Cannot read SLOTCAP register\n", __FUNCTION__); 1198 1365 goto abort_free_ctlr; 1199 1366 } 1200 - dbg("%s: SLOT_CAP offset %x slot_cap %x\n", __FUNCTION__, SLOT_CAP(ctrl->cap_base), slot_cap); 1367 + dbg("%s: SLOTCAP offset %x slot_cap %x\n", 1368 + __FUNCTION__, ctrl->cap_base + SLOTCAP, slot_cap); 1201 1369 1202 1370 if (!(slot_cap & HP_CAP)) { 1203 1371 dbg("%s : This slot is not hot-plug capable\n", __FUNCTION__); 1204 1372 goto abort_free_ctlr; 1205 1373 } 1206 1374 /* For debugging purpose */ 1207 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 1375 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1208 1376 if (rc) { 1209 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 1377 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 1210 1378 goto abort_free_ctlr; 1211 1379 } 1212 - dbg("%s: SLOT_STATUS offset %x slot_status %x\n", __FUNCTION__, SLOT_STATUS(ctrl->cap_base), slot_status); 1380 + dbg("%s: SLOTSTATUS offset %x slot_status %x\n", 1381 + __FUNCTION__, ctrl->cap_base + SLOTSTATUS, slot_status); 1213 1382 1214 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_CTRL(ctrl->cap_base), slot_ctrl); 1383 + rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 1215 1384 if (rc) { 1216 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 1385 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 1217 1386 goto abort_free_ctlr; 1218 1387 } 1219 - dbg("%s: SLOT_CTRL offset %x slot_ctrl %x\n", __FUNCTION__, SLOT_CTRL(ctrl->cap_base), slot_ctrl); 1388 + dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", 1389 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 1220 1390 1221 1391 if (first) { 1222 1392 spin_lock_init(&hpc_event_lock); ··· 1241 1405 /* setup wait queue */ 1242 1406 init_waitqueue_head(&ctrl->queue); 1243 1407 1244 - /* find the IRQ */ 1245 - php_ctlr->irq = dev->irq; 1246 - 1247 - /* Save interrupt callback info */ 1248 - php_ctlr->attention_button_callback = pciehp_handle_attention_button; 1249 - php_ctlr->switch_change_callback = pciehp_handle_switch_change; 1250 - php_ctlr->presence_change_callback = pciehp_handle_presence_change; 1251 - php_ctlr->power_fault_callback = pciehp_handle_power_fault; 1252 - php_ctlr->callback_instance_id = instance_id; 1253 - 1254 1408 /* return PCI Controller Info */ 1255 - php_ctlr->slot_device_offset = 0; 1256 - php_ctlr->num_slots = 1; 1409 + ctrl->slot_device_offset = 0; 1410 + ctrl->num_slots = 1; 1411 + ctrl->first_slot = slot_cap >> 19; 1412 + ctrl->ctrlcap = slot_cap & 0x0000007f; 1257 1413 1258 1414 /* Mask Hot-plug Interrupt Enable */ 1259 - rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1415 + rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1260 1416 if (rc) { 1261 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 1417 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 1262 1418 goto abort_free_ctlr; 1263 1419 } 1264 1420 1265 - dbg("%s: SLOT_CTRL %x value read %x\n", __FUNCTION__, SLOT_CTRL(ctrl->cap_base), temp_word); 1421 + dbg("%s: SLOTCTRL %x value read %x\n", 1422 + __FUNCTION__, ctrl->cap_base + SLOTCTRL, temp_word); 1266 1423 temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 0x00; 1267 1424 1268 - rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1425 + rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1269 1426 if (rc) { 1270 - err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); 1427 + err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); 1271 1428 goto abort_free_ctlr; 1272 1429 } 1273 1430 1274 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 1431 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1275 1432 if (rc) { 1276 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 1433 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 1277 1434 goto abort_free_ctlr; 1278 1435 } 1279 1436 1280 1437 temp_word = 0x1F; /* Clear all events */ 1281 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); 1438 + rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 1282 1439 if (rc) { 1283 - err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); 1440 + err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); 1284 1441 goto abort_free_ctlr; 1285 1442 } 1286 1443 1287 - if (pciehp_poll_mode) {/* Install interrupt polling code */ 1288 - /* Install and start the interrupt polling timer */ 1289 - init_timer(&php_ctlr->int_poll_timer); 1290 - start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ 1444 + if (pciehp_poll_mode) { 1445 + /* Install interrupt polling timer. Start with 10 sec delay */ 1446 + init_timer(&ctrl->poll_timer); 1447 + start_int_poll_timer(ctrl, 10); 1291 1448 } else { 1292 1449 /* Installs the interrupt handler */ 1293 - rc = request_irq(php_ctlr->irq, pcie_isr, IRQF_SHARED, MY_NAME, (void *) ctrl); 1294 - dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); 1450 + rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED, 1451 + MY_NAME, (void *)ctrl); 1452 + dbg("%s: request_irq %d for hpc%d (returns %d)\n", 1453 + __FUNCTION__, ctrl->pci_dev->irq, ctlr_seq_num, rc); 1295 1454 if (rc) { 1296 - err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); 1455 + err("Can't get irq %d for the hotplug controller\n", 1456 + ctrl->pci_dev->irq); 1297 1457 goto abort_free_ctlr; 1298 1458 } 1299 1459 } 1300 - 1301 1460 dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, 1302 1461 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); 1303 1462 1304 - rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1463 + rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1305 1464 if (rc) { 1306 - err("%s : hp_register_read_word SLOT_CTRL failed\n", __FUNCTION__); 1465 + err("%s: Cannot read SLOTCTRL register\n", __FUNCTION__); 1307 1466 goto abort_free_irq; 1308 1467 } 1309 1468 ··· 1322 1491 } 1323 1492 1324 1493 /* Unmask Hot-plug Interrupt Enable for the interrupt notification mechanism case */ 1325 - rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1494 + rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1326 1495 if (rc) { 1327 - err("%s : hp_register_write_word SLOT_CTRL failed\n", __FUNCTION__); 1496 + err("%s: Cannot write to SLOTCTRL register\n", __FUNCTION__); 1328 1497 goto abort_free_irq; 1329 1498 } 1330 - rc = hp_register_read_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), slot_status); 1499 + rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1331 1500 if (rc) { 1332 - err("%s : hp_register_read_word SLOT_STATUS failed\n", __FUNCTION__); 1501 + err("%s: Cannot read SLOTSTATUS register\n", __FUNCTION__); 1333 1502 goto abort_disable_intr; 1334 1503 } 1335 1504 1336 1505 temp_word = 0x1F; /* Clear all events */ 1337 - rc = hp_register_write_word(php_ctlr->pci_dev, SLOT_STATUS(ctrl->cap_base), temp_word); 1506 + rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 1338 1507 if (rc) { 1339 - err("%s : hp_register_write_word SLOT_STATUS failed\n", __FUNCTION__); 1508 + err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); 1340 1509 goto abort_disable_intr; 1341 1510 } 1342 1511 ··· 1349 1518 goto abort_disable_intr; 1350 1519 } 1351 1520 1352 - /* Add this HPC instance into the HPC list */ 1353 - spin_lock(&list_lock); 1354 - if (php_ctlr_list_head == 0) { 1355 - php_ctlr_list_head = php_ctlr; 1356 - p = php_ctlr_list_head; 1357 - p->pnext = NULL; 1358 - } else { 1359 - p = php_ctlr_list_head; 1360 - 1361 - while (p->pnext) 1362 - p = p->pnext; 1363 - 1364 - p->pnext = php_ctlr; 1365 - } 1366 - spin_unlock(&list_lock); 1367 - 1368 1521 ctlr_seq_num++; 1369 - ctrl->hpc_ctlr_handle = php_ctlr; 1370 1522 ctrl->hpc_ops = &pciehp_hpc_ops; 1371 1523 1372 1524 DBG_LEAVE_ROUTINE ··· 1357 1543 1358 1544 /* We end up here for the many possible ways to fail this API. */ 1359 1545 abort_disable_intr: 1360 - rc = hp_register_read_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1546 + rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1361 1547 if (!rc) { 1362 1548 temp_word &= ~(intr_enable | HP_INTR_ENABLE); 1363 - rc = hp_register_write_word(pdev, SLOT_CTRL(ctrl->cap_base), temp_word); 1549 + rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1364 1550 } 1365 1551 if (rc) 1366 1552 err("%s : disabling interrupts failed\n", __FUNCTION__); 1367 1553 1368 1554 abort_free_irq: 1369 1555 if (pciehp_poll_mode) 1370 - del_timer_sync(&php_ctlr->int_poll_timer); 1556 + del_timer_sync(&ctrl->poll_timer); 1371 1557 else 1372 - free_irq(php_ctlr->irq, ctrl); 1558 + free_irq(ctrl->pci_dev->irq, ctrl); 1373 1559 1374 1560 abort_free_ctlr: 1375 - pcie_cap_base = saved_cap_base; 1376 - kfree(php_ctlr); 1377 - abort: 1378 1561 DBG_LEAVE_ROUTINE 1379 1562 return -1; 1380 1563 }
+2 -2
drivers/pci/hotplug/shpchp.h
··· 106 106 }; 107 107 108 108 /* Define AMD SHPC ID */ 109 - #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 109 + #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 110 110 #define PCI_DEVICE_ID_AMD_POGO_7458 0x7458 111 111 112 112 /* AMD PCIX bridge registers */ ··· 221 221 }; 222 222 223 223 static inline struct slot *get_slot(struct hotplug_slot *hotplug_slot) 224 - { 224 + { 225 225 return hotplug_slot->private; 226 226 } 227 227
-4
drivers/pci/hotplug/shpchp_core.c
··· 401 401 { 402 402 int retval = 0; 403 403 404 - #ifdef CONFIG_HOTPLUG_PCI_SHPC_POLL_EVENT_MODE 405 - shpchp_poll_mode = 1; 406 - #endif 407 - 408 404 retval = pci_register_driver(&shpc_driver); 409 405 dbg("%s: pci_register_driver = %d\n", __FUNCTION__, retval); 410 406 info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
+10 -10
drivers/pci/hotplug/shpchp_ctrl.c
··· 64 64 65 65 /* Attention Button Change */ 66 66 dbg("shpchp: Attention button interrupt received.\n"); 67 - 67 + 68 68 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 69 69 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); 70 70 ··· 128 128 129 129 p_slot = shpchp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 130 130 131 - /* 131 + /* 132 132 * Save the presence state 133 133 */ 134 134 p_slot->hpc_ops->get_adapter_status(p_slot, &(p_slot->presence_save)); ··· 184 184 return 1; 185 185 } 186 186 187 - /* The following routines constitute the bulk of the 187 + /* The following routines constitute the bulk of the 188 188 hotplug controller logic 189 189 */ 190 190 static int change_bus_speed(struct controller *ctrl, struct slot *p_slot, 191 191 enum pci_bus_speed speed) 192 - { 192 + { 193 193 int rc = 0; 194 194 195 195 dbg("%s: change to speed %d\n", __FUNCTION__, speed); ··· 204 204 static int fix_bus_speed(struct controller *ctrl, struct slot *pslot, 205 205 u8 flag, enum pci_bus_speed asp, enum pci_bus_speed bsp, 206 206 enum pci_bus_speed msp) 207 - { 207 + { 208 208 int rc = 0; 209 209 210 210 /* ··· 257 257 err("%s: Failed to power on slot\n", __FUNCTION__); 258 258 return -1; 259 259 } 260 - 260 + 261 261 if ((ctrl->pci_dev->vendor == 0x8086) && (ctrl->pci_dev->device == 0x0332)) { 262 262 if (slots_not_empty) 263 263 return WRONG_BUS_FREQUENCY; 264 - 264 + 265 265 if ((rc = p_slot->hpc_ops->set_bus_speed_mode(p_slot, PCI_SPEED_33MHz))) { 266 266 err("%s: Issue of set bus speed mode command failed\n", __FUNCTION__); 267 267 return WRONG_BUS_FREQUENCY; 268 268 } 269 - 269 + 270 270 /* turn on board, blink green LED, turn off Amber LED */ 271 271 if ((rc = p_slot->hpc_ops->slot_enable(p_slot))) { 272 272 err("%s: Issue of Slot Enable command failed\n", __FUNCTION__); 273 273 return rc; 274 274 } 275 275 } 276 - 276 + 277 277 rc = p_slot->hpc_ops->get_adapter_speed(p_slot, &asp); 278 278 if (rc) { 279 279 err("%s: Can't get adapter speed or bus mode mismatch\n", ··· 378 378 err("%s: Issue of Slot Disable command failed\n", __FUNCTION__); 379 379 return rc; 380 380 } 381 - 381 + 382 382 rc = p_slot->hpc_ops->set_attention_status(p_slot, 0); 383 383 if (rc) { 384 384 err("%s: Issue of Set Attention command failed\n", __FUNCTION__);
+34 -151
drivers/pci/hotplug/shpchp_hpc.c
··· 35 35 36 36 #include "shpchp.h" 37 37 38 - #ifdef DEBUG 39 - #define DBG_K_TRACE_ENTRY ((unsigned int)0x00000001) /* On function entry */ 40 - #define DBG_K_TRACE_EXIT ((unsigned int)0x00000002) /* On function exit */ 41 - #define DBG_K_INFO ((unsigned int)0x00000004) /* Info messages */ 42 - #define DBG_K_ERROR ((unsigned int)0x00000008) /* Error messages */ 43 - #define DBG_K_TRACE (DBG_K_TRACE_ENTRY|DBG_K_TRACE_EXIT) 44 - #define DBG_K_STANDARD (DBG_K_INFO|DBG_K_ERROR|DBG_K_TRACE) 45 - /* Redefine this flagword to set debug level */ 46 - #define DEBUG_LEVEL DBG_K_STANDARD 47 - 48 - #define DEFINE_DBG_BUFFER char __dbg_str_buf[256]; 49 - 50 - #define DBG_PRINT( dbg_flags, args... ) \ 51 - do { \ 52 - if ( DEBUG_LEVEL & ( dbg_flags ) ) \ 53 - { \ 54 - int len; \ 55 - len = sprintf( __dbg_str_buf, "%s:%d: %s: ", \ 56 - __FILE__, __LINE__, __FUNCTION__ ); \ 57 - sprintf( __dbg_str_buf + len, args ); \ 58 - printk( KERN_NOTICE "%s\n", __dbg_str_buf ); \ 59 - } \ 60 - } while (0) 61 - 62 - #define DBG_ENTER_ROUTINE DBG_PRINT (DBG_K_TRACE_ENTRY, "%s", "[Entry]"); 63 - #define DBG_LEAVE_ROUTINE DBG_PRINT (DBG_K_TRACE_EXIT, "%s", "[Exit]"); 64 - #else 65 - #define DEFINE_DBG_BUFFER 66 - #define DBG_ENTER_ROUTINE 67 - #define DBG_LEAVE_ROUTINE 68 - #endif /* DEBUG */ 69 - 70 38 /* Slot Available Register I field definition */ 71 39 #define SLOT_33MHZ 0x0000001f 72 40 #define SLOT_66MHZ_PCIX 0x00001f00 ··· 179 211 #define SLOT_EVENT_LATCH 0x2 180 212 #define SLOT_SERR_INT_MASK 0x3 181 213 182 - DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ 183 214 static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); 184 215 185 216 static irqreturn_t shpc_isr(int irq, void *dev_id); ··· 235 268 { 236 269 struct controller *ctrl = (struct controller *)data; 237 270 238 - DBG_ENTER_ROUTINE 239 - 240 271 /* Poll for interrupt events. regs == NULL => polling */ 241 272 shpc_isr(0, ctrl); 242 273 ··· 243 278 shpchp_poll_time = 2; /* default polling interval is 2 sec */ 244 279 245 280 start_int_poll_timer(ctrl, shpchp_poll_time); 246 - 247 - DBG_LEAVE_ROUTINE 248 281 } 249 282 250 283 /* ··· 316 353 int retval = 0; 317 354 u16 temp_word; 318 355 319 - DBG_ENTER_ROUTINE 320 - 321 356 mutex_lock(&slot->ctrl->cmd_lock); 322 357 323 358 if (!shpc_poll_ctrl_busy(ctrl)) { ··· 329 368 ++t_slot; 330 369 temp_word = (t_slot << 8) | (cmd & 0xFF); 331 370 dbg("%s: t_slot %x cmd %x\n", __FUNCTION__, t_slot, cmd); 332 - 371 + 333 372 /* To make sure the Controller Busy bit is 0 before we send out the 334 - * command. 373 + * command. 335 374 */ 336 375 shpc_writew(ctrl, CMD, temp_word); 337 376 ··· 350 389 } 351 390 out: 352 391 mutex_unlock(&slot->ctrl->cmd_lock); 353 - 354 - DBG_LEAVE_ROUTINE 355 392 return retval; 356 393 } 357 394 358 395 static int hpc_check_cmd_status(struct controller *ctrl) 359 396 { 360 - u16 cmd_status; 361 397 int retval = 0; 398 + u16 cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; 362 399 363 - DBG_ENTER_ROUTINE 364 - 365 - cmd_status = shpc_readw(ctrl, CMD_STATUS) & 0x000F; 366 - 367 400 switch (cmd_status >> 1) { 368 401 case 0: 369 402 retval = 0; ··· 378 423 retval = cmd_status; 379 424 } 380 425 381 - DBG_LEAVE_ROUTINE 382 426 return retval; 383 427 } 384 428 ··· 385 431 static int hpc_get_attention_status(struct slot *slot, u8 *status) 386 432 { 387 433 struct controller *ctrl = slot->ctrl; 388 - u32 slot_reg; 389 - u8 state; 390 - 391 - DBG_ENTER_ROUTINE 392 - 393 - slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 394 - state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT; 434 + u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 435 + u8 state = (slot_reg & ATN_LED_STATE_MASK) >> ATN_LED_STATE_SHIFT; 395 436 396 437 switch (state) { 397 438 case ATN_LED_STATE_ON: ··· 403 454 break; 404 455 } 405 456 406 - DBG_LEAVE_ROUTINE 407 457 return 0; 408 458 } 409 459 410 460 static int hpc_get_power_status(struct slot * slot, u8 *status) 411 461 { 412 462 struct controller *ctrl = slot->ctrl; 413 - u32 slot_reg; 414 - u8 state; 415 - 416 - DBG_ENTER_ROUTINE 417 - 418 - slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 419 - state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT; 463 + u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 464 + u8 state = (slot_reg & SLOT_STATE_MASK) >> SLOT_STATE_SHIFT; 420 465 421 466 switch (state) { 422 467 case SLOT_STATE_PWRONLY: ··· 427 484 break; 428 485 } 429 486 430 - DBG_LEAVE_ROUTINE 431 487 return 0; 432 488 } 433 489 ··· 434 492 static int hpc_get_latch_status(struct slot *slot, u8 *status) 435 493 { 436 494 struct controller *ctrl = slot->ctrl; 437 - u32 slot_reg; 495 + u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 438 496 439 - DBG_ENTER_ROUTINE 440 - 441 - slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 442 497 *status = !!(slot_reg & MRL_SENSOR); /* 0 -> close; 1 -> open */ 443 498 444 - DBG_LEAVE_ROUTINE 445 499 return 0; 446 500 } 447 501 448 502 static int hpc_get_adapter_status(struct slot *slot, u8 *status) 449 503 { 450 504 struct controller *ctrl = slot->ctrl; 451 - u32 slot_reg; 452 - u8 state; 505 + u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 506 + u8 state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT; 453 507 454 - DBG_ENTER_ROUTINE 455 - 456 - slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 457 - state = (slot_reg & PRSNT_MASK) >> PRSNT_SHIFT; 458 508 *status = (state != 0x3) ? 1 : 0; 459 509 460 - DBG_LEAVE_ROUTINE 461 510 return 0; 462 511 } 463 512 ··· 456 523 { 457 524 struct controller *ctrl = slot->ctrl; 458 525 459 - DBG_ENTER_ROUTINE 460 - 461 526 *prog_int = shpc_readb(ctrl, PROG_INTERFACE); 462 527 463 - DBG_LEAVE_ROUTINE 464 528 return 0; 465 529 } 466 530 ··· 468 538 u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 469 539 u8 m66_cap = !!(slot_reg & MHZ66_CAP); 470 540 u8 pi, pcix_cap; 471 - 472 - DBG_ENTER_ROUTINE 473 541 474 542 if ((retval = hpc_get_prog_int(slot, &pi))) 475 543 return retval; ··· 510 582 } 511 583 512 584 dbg("Adapter speed = %d\n", *value); 513 - DBG_LEAVE_ROUTINE 514 585 return retval; 515 586 } 516 587 517 588 static int hpc_get_mode1_ECC_cap(struct slot *slot, u8 *mode) 518 589 { 519 - struct controller *ctrl = slot->ctrl; 520 - u16 sec_bus_status; 521 - u8 pi; 522 590 int retval = 0; 523 - 524 - DBG_ENTER_ROUTINE 525 - 526 - pi = shpc_readb(ctrl, PROG_INTERFACE); 527 - sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG); 591 + struct controller *ctrl = slot->ctrl; 592 + u16 sec_bus_status = shpc_readw(ctrl, SEC_BUS_CONFIG); 593 + u8 pi = shpc_readb(ctrl, PROG_INTERFACE); 528 594 529 595 if (pi == 2) { 530 596 *mode = (sec_bus_status & 0x0100) >> 8; ··· 527 605 } 528 606 529 607 dbg("Mode 1 ECC cap = %d\n", *mode); 530 - 531 - DBG_LEAVE_ROUTINE 532 608 return retval; 533 609 } 534 610 535 611 static int hpc_query_power_fault(struct slot * slot) 536 612 { 537 613 struct controller *ctrl = slot->ctrl; 538 - u32 slot_reg; 614 + u32 slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 539 615 540 - DBG_ENTER_ROUTINE 541 - 542 - slot_reg = shpc_readl(ctrl, SLOT_REG(slot->hp_slot)); 543 - 544 - DBG_LEAVE_ROUTINE 545 616 /* Note: Logic 0 => fault */ 546 617 return !(slot_reg & POWER_FAULT); 547 618 } ··· 544 629 u8 slot_cmd = 0; 545 630 546 631 switch (value) { 547 - case 0 : 632 + case 0 : 548 633 slot_cmd = SET_ATTN_OFF; /* OFF */ 549 634 break; 550 635 case 1: ··· 580 665 { 581 666 int i; 582 667 u32 slot_reg, serr_int; 583 - 584 - DBG_ENTER_ROUTINE 585 668 586 669 /* 587 670 * Mask event interrupts and SERRs of all slots ··· 621 708 */ 622 709 if (atomic_dec_and_test(&shpchp_num_controllers)) 623 710 destroy_workqueue(shpchp_wq); 624 - 625 - DBG_LEAVE_ROUTINE 626 711 } 627 712 628 713 static int hpc_power_on_slot(struct slot * slot) 629 714 { 630 715 int retval; 631 716 632 - DBG_ENTER_ROUTINE 633 - 634 717 retval = shpc_write_cmd(slot, slot->hp_slot, SET_SLOT_PWR); 635 - if (retval) { 718 + if (retval) 636 719 err("%s: Write command failed!\n", __FUNCTION__); 637 - return retval; 638 - } 639 720 640 - DBG_LEAVE_ROUTINE 641 - 642 - return 0; 721 + return retval; 643 722 } 644 723 645 724 static int hpc_slot_enable(struct slot * slot) 646 725 { 647 726 int retval; 648 727 649 - DBG_ENTER_ROUTINE 650 - 651 728 /* Slot - Enable, Power Indicator - Blink, Attention Indicator - Off */ 652 729 retval = shpc_write_cmd(slot, slot->hp_slot, 653 730 SET_SLOT_ENABLE | SET_PWR_BLINK | SET_ATTN_OFF); 654 - if (retval) { 731 + if (retval) 655 732 err("%s: Write command failed!\n", __FUNCTION__); 656 - return retval; 657 - } 658 733 659 - DBG_LEAVE_ROUTINE 660 - return 0; 734 + return retval; 661 735 } 662 736 663 737 static int hpc_slot_disable(struct slot * slot) 664 738 { 665 739 int retval; 666 740 667 - DBG_ENTER_ROUTINE 668 - 669 741 /* Slot - Disable, Power Indicator - Off, Attention Indicator - On */ 670 742 retval = shpc_write_cmd(slot, slot->hp_slot, 671 743 SET_SLOT_DISABLE | SET_PWR_OFF | SET_ATTN_ON); 672 - if (retval) { 744 + if (retval) 673 745 err("%s: Write command failed!\n", __FUNCTION__); 674 - return retval; 675 - } 676 746 677 - DBG_LEAVE_ROUTINE 678 - return 0; 747 + return retval; 679 748 } 680 749 681 750 static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) ··· 665 770 int retval; 666 771 struct controller *ctrl = slot->ctrl; 667 772 u8 pi, cmd; 668 - 669 - DBG_ENTER_ROUTINE 670 773 671 774 pi = shpc_readb(ctrl, PROG_INTERFACE); 672 775 if ((pi == 1) && (value > PCI_SPEED_133MHz_PCIX)) ··· 721 828 if (retval) 722 829 err("%s: Write command failed!\n", __FUNCTION__); 723 830 724 - DBG_LEAVE_ROUTINE 725 831 return retval; 726 832 } 727 833 ··· 735 843 if (!intr_loc) 736 844 return IRQ_NONE; 737 845 738 - dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); 846 + dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); 739 847 740 848 if(!shpchp_poll_mode) { 741 849 /* ··· 748 856 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); 749 857 750 858 intr_loc2 = shpc_readl(ctrl, INTR_LOC); 751 - dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); 859 + dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); 752 860 } 753 861 754 862 if (intr_loc & CMD_INTR_PENDING) { 755 - /* 756 - * Command Complete Interrupt Pending 863 + /* 864 + * Command Complete Interrupt Pending 757 865 * RO only - clear by writing 1 to the Command Completion 758 866 * Detect bit in Controller SERR-INT register 759 867 */ ··· 767 875 if (!(intr_loc & ~CMD_INTR_PENDING)) 768 876 goto out; 769 877 770 - for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { 878 + for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { 771 879 /* To find out which slot has interrupt pending */ 772 880 if (!(intr_loc & SLOT_INTR_PENDING(hp_slot))) 773 881 continue; ··· 799 907 serr_int &= ~(GLOBAL_INTR_MASK | SERR_INTR_RSVDZ_MASK); 800 908 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); 801 909 } 802 - 910 + 803 911 return IRQ_HANDLED; 804 912 } 805 913 ··· 811 919 u8 pi = shpc_readb(ctrl, PROG_INTERFACE); 812 920 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); 813 921 u32 slot_avail2 = shpc_readl(ctrl, SLOT_AVAIL2); 814 - 815 - DBG_ENTER_ROUTINE 816 922 817 923 if (pi == 2) { 818 924 if (slot_avail2 & SLOT_133MHZ_PCIX_533) ··· 844 954 845 955 *value = bus_speed; 846 956 dbg("Max bus speed = %d\n", bus_speed); 847 - DBG_LEAVE_ROUTINE 957 + 848 958 return retval; 849 959 } 850 960 ··· 856 966 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG); 857 967 u8 pi = shpc_readb(ctrl, PROG_INTERFACE); 858 968 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7); 859 - 860 - DBG_ENTER_ROUTINE 861 969 862 970 if ((pi == 1) && (speed_mode > 4)) { 863 971 *value = PCI_SPEED_UNKNOWN; ··· 912 1024 } 913 1025 914 1026 dbg("Current bus speed = %d\n", bus_speed); 915 - DBG_LEAVE_ROUTINE 916 1027 return retval; 917 1028 } 918 1029 ··· 919 1032 .power_on_slot = hpc_power_on_slot, 920 1033 .slot_enable = hpc_slot_enable, 921 1034 .slot_disable = hpc_slot_disable, 922 - .set_bus_speed_mode = hpc_set_bus_speed_mode, 1035 + .set_bus_speed_mode = hpc_set_bus_speed_mode, 923 1036 .set_attention_status = hpc_set_attention_status, 924 1037 .get_power_status = hpc_get_power_status, 925 1038 .get_attention_status = hpc_get_attention_status, ··· 936 1049 .green_led_on = hpc_set_green_led_on, 937 1050 .green_led_off = hpc_set_green_led_off, 938 1051 .green_led_blink = hpc_set_green_led_blink, 939 - 1052 + 940 1053 .release_ctlr = hpc_release_ctlr, 941 1054 }; 942 1055 ··· 947 1060 u32 shpc_base_offset; 948 1061 u32 tempdword, slot_reg, slot_config; 949 1062 u8 i; 950 - 951 - DBG_ENTER_ROUTINE 952 1063 953 1064 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 954 1065 ··· 993 1108 ctrl->mmio_size = 0x24 + 0x4 * num_slots; 994 1109 } 995 1110 996 - info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 1111 + info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 997 1112 pdev->subsystem_device); 998 - 1113 + 999 1114 rc = pci_enable_device(pdev); 1000 1115 if (rc) { 1001 1116 err("%s: pci_enable_device failed\n", __FUNCTION__); ··· 1057 1172 slot_reg &= ~SLOT_REG_RSVDZ_MASK; 1058 1173 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); 1059 1174 } 1060 - 1175 + 1061 1176 if (shpchp_poll_mode) { 1062 1177 /* Install interrupt polling timer. Start with 10 sec delay */ 1063 1178 init_timer(&ctrl->poll_timer); ··· 1069 1184 info("Can't get msi for the hotplug controller\n"); 1070 1185 info("Use INTx for the hotplug controller\n"); 1071 1186 } 1072 - 1187 + 1073 1188 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED, 1074 1189 MY_NAME, (void *)ctrl); 1075 1190 dbg("%s: request_irq %d for hpc%d (returns %d)\n", ··· 1120 1235 dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword); 1121 1236 } 1122 1237 1123 - DBG_LEAVE_ROUTINE 1124 1238 return 0; 1125 1239 1126 1240 /* We end up here for the many possible ways to fail this API. */ 1127 1241 abort_iounmap: 1128 1242 iounmap(ctrl->creg); 1129 1243 abort: 1130 - DBG_LEAVE_ROUTINE 1131 1244 return rc; 1132 1245 }
+117 -208
drivers/pci/msi.c
··· 24 24 #include "pci.h" 25 25 #include "msi.h" 26 26 27 - static DEFINE_SPINLOCK(msi_lock); 28 - static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL }; 29 27 static struct kmem_cache* msi_cachep; 30 28 31 29 static int pci_msi_enable = 1; ··· 42 44 { 43 45 struct msi_desc *entry; 44 46 45 - entry = msi_desc[irq]; 47 + entry = get_irq_msi(irq); 46 48 BUG_ON(!entry || !entry->dev); 47 49 switch (entry->msi_attrib.type) { 48 50 case PCI_CAP_ID_MSI: 49 51 if (entry->msi_attrib.maskbit) { 50 - int pos; 51 - u32 mask_bits; 52 + int pos; 53 + u32 mask_bits; 52 54 53 55 pos = (long)entry->mask_base; 54 56 pci_read_config_dword(entry->dev, pos, &mask_bits); ··· 72 74 73 75 void read_msi_msg(unsigned int irq, struct msi_msg *msg) 74 76 { 75 - struct msi_desc *entry = get_irq_data(irq); 77 + struct msi_desc *entry = get_irq_msi(irq); 76 78 switch(entry->msi_attrib.type) { 77 79 case PCI_CAP_ID_MSI: 78 80 { ··· 111 113 112 114 void write_msi_msg(unsigned int irq, struct msi_msg *msg) 113 115 { 114 - struct msi_desc *entry = get_irq_data(irq); 116 + struct msi_desc *entry = get_irq_msi(irq); 115 117 switch (entry->msi_attrib.type) { 116 118 case PCI_CAP_ID_MSI: 117 119 { ··· 160 162 } 161 163 162 164 static int msi_free_irq(struct pci_dev* dev, int irq); 165 + 163 166 static int msi_init(void) 164 167 { 165 168 static int status = -ENOMEM; 166 169 167 170 if (!status) 168 171 return status; 169 - 170 - if (pci_msi_quirk) { 171 - pci_msi_enable = 0; 172 - printk(KERN_WARNING "PCI: MSI quirk detected. MSI disabled.\n"); 173 - status = -EINVAL; 174 - return status; 175 - } 176 172 177 173 status = msi_cache_init(); 178 174 if (status < 0) { ··· 190 198 entry->dev = NULL; 191 199 192 200 return entry; 193 - } 194 - 195 - static void attach_msi_entry(struct msi_desc *entry, int irq) 196 - { 197 - unsigned long flags; 198 - 199 - spin_lock_irqsave(&msi_lock, flags); 200 - msi_desc[irq] = entry; 201 - spin_unlock_irqrestore(&msi_lock, flags); 202 - } 203 - 204 - static int create_msi_irq(void) 205 - { 206 - struct msi_desc *entry; 207 - int irq; 208 - 209 - entry = alloc_msi_entry(); 210 - if (!entry) 211 - return -ENOMEM; 212 - 213 - irq = create_irq(); 214 - if (irq < 0) { 215 - kmem_cache_free(msi_cachep, entry); 216 - return -EBUSY; 217 - } 218 - 219 - set_irq_data(irq, entry); 220 - 221 - return irq; 222 - } 223 - 224 - static void destroy_msi_irq(unsigned int irq) 225 - { 226 - struct msi_desc *entry; 227 - 228 - entry = get_irq_data(irq); 229 - set_irq_chip(irq, NULL); 230 - set_irq_data(irq, NULL); 231 - destroy_irq(irq); 232 - kmem_cache_free(msi_cachep, entry); 233 201 } 234 202 235 203 static void enable_msi_mode(struct pci_dev *dev, int pos, int type) ··· 230 278 pci_intx(dev, 1); /* enable intx */ 231 279 } 232 280 233 - static int msi_lookup_irq(struct pci_dev *dev, int type) 234 - { 235 - int irq; 236 - unsigned long flags; 237 - 238 - spin_lock_irqsave(&msi_lock, flags); 239 - for (irq = 0; irq < NR_IRQS; irq++) { 240 - if (!msi_desc[irq] || msi_desc[irq]->dev != dev || 241 - msi_desc[irq]->msi_attrib.type != type || 242 - msi_desc[irq]->msi_attrib.default_irq != dev->irq) 243 - continue; 244 - spin_unlock_irqrestore(&msi_lock, flags); 245 - /* This pre-assigned MSI irq for this device 246 - already exits. Override dev->irq with this irq */ 247 - dev->irq = irq; 248 - return 0; 249 - } 250 - spin_unlock_irqrestore(&msi_lock, flags); 251 - 252 - return -EACCES; 253 - } 254 - 255 - void pci_scan_msi_device(struct pci_dev *dev) 256 - { 257 - if (!dev) 258 - return; 259 - } 260 - 261 281 #ifdef CONFIG_PM 262 - int pci_save_msi_state(struct pci_dev *dev) 282 + static int __pci_save_msi_state(struct pci_dev *dev) 263 283 { 264 284 int pos, i = 0; 265 285 u16 control; ··· 269 345 return 0; 270 346 } 271 347 272 - void pci_restore_msi_state(struct pci_dev *dev) 348 + static void __pci_restore_msi_state(struct pci_dev *dev) 273 349 { 274 350 int i = 0, pos; 275 351 u16 control; ··· 297 373 kfree(save_state); 298 374 } 299 375 300 - int pci_save_msix_state(struct pci_dev *dev) 376 + static int __pci_save_msix_state(struct pci_dev *dev) 301 377 { 302 378 int pos; 303 - int temp; 304 379 int irq, head, tail = 0; 305 380 u16 control; 306 381 struct pci_cap_saved_state *save_state; 382 + 383 + if (!dev->msix_enabled) 384 + return 0; 307 385 308 386 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 309 387 if (pos <= 0 || dev->no_msi) ··· 324 398 *((u16 *)&save_state->data[0]) = control; 325 399 326 400 /* save the table */ 327 - temp = dev->irq; 328 - if (msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { 329 - kfree(save_state); 330 - return -EINVAL; 331 - } 332 - 333 - irq = head = dev->irq; 401 + irq = head = dev->first_msi_irq; 334 402 while (head != tail) { 335 403 struct msi_desc *entry; 336 404 337 - entry = msi_desc[irq]; 405 + entry = get_irq_msi(irq); 338 406 read_msi_msg(irq, &entry->msg_save); 339 407 340 - tail = msi_desc[irq]->link.tail; 408 + tail = entry->link.tail; 341 409 irq = tail; 342 410 } 343 - dev->irq = temp; 344 411 345 412 save_state->cap_nr = PCI_CAP_ID_MSIX; 346 413 pci_add_saved_cap(dev, save_state); 347 414 return 0; 348 415 } 349 416 350 - void pci_restore_msix_state(struct pci_dev *dev) 417 + int pci_save_msi_state(struct pci_dev *dev) 418 + { 419 + int rc; 420 + 421 + rc = __pci_save_msi_state(dev); 422 + if (rc) 423 + return rc; 424 + 425 + rc = __pci_save_msix_state(dev); 426 + 427 + return rc; 428 + } 429 + 430 + static void __pci_restore_msix_state(struct pci_dev *dev) 351 431 { 352 432 u16 save; 353 433 int pos; 354 434 int irq, head, tail = 0; 355 435 struct msi_desc *entry; 356 - int temp; 357 436 struct pci_cap_saved_state *save_state; 437 + 438 + if (!dev->msix_enabled) 439 + return; 358 440 359 441 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX); 360 442 if (!save_state) ··· 376 442 return; 377 443 378 444 /* route the table */ 379 - temp = dev->irq; 380 - if (msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) 381 - return; 382 - irq = head = dev->irq; 445 + irq = head = dev->first_msi_irq; 383 446 while (head != tail) { 384 - entry = msi_desc[irq]; 447 + entry = get_irq_msi(irq); 385 448 write_msi_msg(irq, &entry->msg_save); 386 449 387 - tail = msi_desc[irq]->link.tail; 450 + tail = entry->link.tail; 388 451 irq = tail; 389 452 } 390 - dev->irq = temp; 391 453 392 454 pci_write_config_word(dev, msi_control_reg(pos), save); 393 455 enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); 394 456 } 395 - #endif 457 + 458 + void pci_restore_msi_state(struct pci_dev *dev) 459 + { 460 + __pci_restore_msi_state(dev); 461 + __pci_restore_msix_state(dev); 462 + } 463 + #endif /* CONFIG_PM */ 396 464 397 465 /** 398 466 * msi_capability_init - configure device's MSI capability structure ··· 407 471 **/ 408 472 static int msi_capability_init(struct pci_dev *dev) 409 473 { 410 - int status; 411 474 struct msi_desc *entry; 412 475 int pos, irq; 413 476 u16 control; ··· 414 479 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 415 480 pci_read_config_word(dev, msi_control_reg(pos), &control); 416 481 /* MSI Entry Initialization */ 417 - irq = create_msi_irq(); 418 - if (irq < 0) 419 - return irq; 482 + entry = alloc_msi_entry(); 483 + if (!entry) 484 + return -ENOMEM; 420 485 421 - entry = get_irq_data(irq); 422 - entry->link.head = irq; 423 - entry->link.tail = irq; 424 486 entry->msi_attrib.type = PCI_CAP_ID_MSI; 425 487 entry->msi_attrib.is_64 = is_64bit_address(control); 426 488 entry->msi_attrib.entry_nr = 0; ··· 443 511 maskbits); 444 512 } 445 513 /* Configure MSI capability structure */ 446 - status = arch_setup_msi_irq(irq, dev); 447 - if (status < 0) { 448 - destroy_msi_irq(irq); 449 - return status; 514 + irq = arch_setup_msi_irq(dev, entry); 515 + if (irq < 0) { 516 + kmem_cache_free(msi_cachep, entry); 517 + return irq; 450 518 } 519 + entry->link.head = irq; 520 + entry->link.tail = irq; 521 + dev->first_msi_irq = irq; 522 + set_irq_msi(irq, entry); 451 523 452 - attach_msi_entry(entry, irq); 453 524 /* Set MSI enabled bits */ 454 525 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); 455 526 ··· 474 539 struct msix_entry *entries, int nvec) 475 540 { 476 541 struct msi_desc *head = NULL, *tail = NULL, *entry = NULL; 477 - int status; 478 542 int irq, pos, i, j, nr_entries, temp = 0; 479 543 unsigned long phys_addr; 480 544 u32 table_offset; ··· 496 562 497 563 /* MSI-X Table Initialization */ 498 564 for (i = 0; i < nvec; i++) { 499 - irq = create_msi_irq(); 500 - if (irq < 0) 565 + entry = alloc_msi_entry(); 566 + if (!entry) 501 567 break; 502 568 503 - entry = get_irq_data(irq); 504 569 j = entries[i].entry; 505 - entries[i].vector = irq; 506 570 entry->msi_attrib.type = PCI_CAP_ID_MSIX; 507 571 entry->msi_attrib.is_64 = 1; 508 572 entry->msi_attrib.entry_nr = j; ··· 509 577 entry->msi_attrib.pos = pos; 510 578 entry->dev = dev; 511 579 entry->mask_base = base; 580 + 581 + /* Configure MSI-X capability structure */ 582 + irq = arch_setup_msi_irq(dev, entry); 583 + if (irq < 0) { 584 + kmem_cache_free(msi_cachep, entry); 585 + break; 586 + } 587 + entries[i].vector = irq; 512 588 if (!head) { 513 589 entry->link.head = irq; 514 590 entry->link.tail = irq; ··· 529 589 } 530 590 temp = irq; 531 591 tail = entry; 532 - /* Configure MSI-X capability structure */ 533 - status = arch_setup_msi_irq(irq, dev); 534 - if (status < 0) { 535 - destroy_msi_irq(irq); 536 - break; 537 - } 538 592 539 - attach_msi_entry(entry, irq); 593 + set_irq_msi(irq, entry); 540 594 } 541 595 if (i != nvec) { 542 596 int avail = i - 1; ··· 547 613 avail = -EBUSY; 548 614 return avail; 549 615 } 616 + dev->first_msi_irq = entries[0].vector; 550 617 /* Set MSI-X enabled bits */ 551 618 enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); 552 619 ··· 595 660 **/ 596 661 int pci_enable_msi(struct pci_dev* dev) 597 662 { 598 - int pos, temp, status; 663 + int pos, status; 599 664 600 665 if (pci_msi_supported(dev) < 0) 601 666 return -EINVAL; 602 - 603 - temp = dev->irq; 604 667 605 668 status = msi_init(); 606 669 if (status < 0) ··· 608 675 if (!pos) 609 676 return -EINVAL; 610 677 611 - WARN_ON(!msi_lookup_irq(dev, PCI_CAP_ID_MSI)); 678 + WARN_ON(!!dev->msi_enabled); 612 679 613 680 /* Check whether driver already requested for MSI-X irqs */ 614 681 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 615 - if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { 682 + if (pos > 0 && dev->msix_enabled) { 616 683 printk(KERN_INFO "PCI: %s: Can't enable MSI. " 617 - "Device already has MSI-X irq assigned\n", 684 + "Device already has MSI-X enabled\n", 618 685 pci_name(dev)); 619 - dev->irq = temp; 620 686 return -EINVAL; 621 687 } 622 688 status = msi_capability_init(dev); ··· 627 695 struct msi_desc *entry; 628 696 int pos, default_irq; 629 697 u16 control; 630 - unsigned long flags; 631 698 632 699 if (!pci_msi_enable) 633 700 return; 634 701 if (!dev) 702 + return; 703 + 704 + if (!dev->msi_enabled) 635 705 return; 636 706 637 707 pos = pci_find_capability(dev, PCI_CAP_ID_MSI); ··· 644 710 if (!(control & PCI_MSI_FLAGS_ENABLE)) 645 711 return; 646 712 713 + 647 714 disable_msi_mode(dev, pos, PCI_CAP_ID_MSI); 648 715 649 - spin_lock_irqsave(&msi_lock, flags); 650 - entry = msi_desc[dev->irq]; 716 + entry = get_irq_msi(dev->first_msi_irq); 651 717 if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) { 652 - spin_unlock_irqrestore(&msi_lock, flags); 653 718 return; 654 719 } 655 - if (irq_has_action(dev->irq)) { 656 - spin_unlock_irqrestore(&msi_lock, flags); 720 + if (irq_has_action(dev->first_msi_irq)) { 657 721 printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without " 658 722 "free_irq() on MSI irq %d\n", 659 - pci_name(dev), dev->irq); 660 - BUG_ON(irq_has_action(dev->irq)); 723 + pci_name(dev), dev->first_msi_irq); 724 + BUG_ON(irq_has_action(dev->first_msi_irq)); 661 725 } else { 662 726 default_irq = entry->msi_attrib.default_irq; 663 - spin_unlock_irqrestore(&msi_lock, flags); 664 - msi_free_irq(dev, dev->irq); 727 + msi_free_irq(dev, dev->first_msi_irq); 665 728 666 729 /* Restore dev->irq to its default pin-assertion irq */ 667 730 dev->irq = default_irq; 668 731 } 732 + dev->first_msi_irq = 0; 669 733 } 670 734 671 735 static int msi_free_irq(struct pci_dev* dev, int irq) ··· 671 739 struct msi_desc *entry; 672 740 int head, entry_nr, type; 673 741 void __iomem *base; 674 - unsigned long flags; 675 742 676 - arch_teardown_msi_irq(irq); 677 - 678 - spin_lock_irqsave(&msi_lock, flags); 679 - entry = msi_desc[irq]; 743 + entry = get_irq_msi(irq); 680 744 if (!entry || entry->dev != dev) { 681 - spin_unlock_irqrestore(&msi_lock, flags); 682 745 return -EINVAL; 683 746 } 684 747 type = entry->msi_attrib.type; 685 748 entry_nr = entry->msi_attrib.entry_nr; 686 749 head = entry->link.head; 687 750 base = entry->mask_base; 688 - msi_desc[entry->link.head]->link.tail = entry->link.tail; 689 - msi_desc[entry->link.tail]->link.head = entry->link.head; 690 - entry->dev = NULL; 691 - msi_desc[irq] = NULL; 692 - spin_unlock_irqrestore(&msi_lock, flags); 751 + get_irq_msi(entry->link.head)->link.tail = entry->link.tail; 752 + get_irq_msi(entry->link.tail)->link.head = entry->link.head; 693 753 694 - destroy_msi_irq(irq); 754 + arch_teardown_msi_irq(irq); 755 + kmem_cache_free(msi_cachep, entry); 695 756 696 757 if (type == PCI_CAP_ID_MSIX) { 697 758 writel(1, base + entry_nr * PCI_MSIX_ENTRY_SIZE + ··· 715 790 int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) 716 791 { 717 792 int status, pos, nr_entries; 718 - int i, j, temp; 793 + int i, j; 719 794 u16 control; 720 795 721 796 if (!entries || pci_msi_supported(dev) < 0) ··· 743 818 return -EINVAL; /* duplicate entry */ 744 819 } 745 820 } 746 - temp = dev->irq; 747 - WARN_ON(!msi_lookup_irq(dev, PCI_CAP_ID_MSIX)); 821 + WARN_ON(!!dev->msix_enabled); 748 822 749 823 /* Check whether driver already requested for MSI irq */ 750 824 if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 && 751 - !msi_lookup_irq(dev, PCI_CAP_ID_MSI)) { 825 + dev->msi_enabled) { 752 826 printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " 753 827 "Device already has an MSI irq assigned\n", 754 828 pci_name(dev)); 755 - dev->irq = temp; 756 829 return -EINVAL; 757 830 } 758 831 status = msix_capability_init(dev, entries, nvec); ··· 759 836 760 837 void pci_disable_msix(struct pci_dev* dev) 761 838 { 762 - int pos, temp; 839 + int irq, head, tail = 0, warning = 0; 840 + int pos; 763 841 u16 control; 764 842 765 843 if (!pci_msi_enable) 766 844 return; 767 845 if (!dev) 846 + return; 847 + 848 + if (!dev->msix_enabled) 768 849 return; 769 850 770 851 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); ··· 781 854 782 855 disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX); 783 856 784 - temp = dev->irq; 785 - if (!msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { 786 - int irq, head, tail = 0, warning = 0; 787 - unsigned long flags; 788 - 789 - irq = head = dev->irq; 790 - dev->irq = temp; /* Restore pin IRQ */ 791 - while (head != tail) { 792 - spin_lock_irqsave(&msi_lock, flags); 793 - tail = msi_desc[irq]->link.tail; 794 - spin_unlock_irqrestore(&msi_lock, flags); 795 - if (irq_has_action(irq)) 796 - warning = 1; 797 - else if (irq != head) /* Release MSI-X irq */ 798 - msi_free_irq(dev, irq); 799 - irq = tail; 800 - } 801 - msi_free_irq(dev, irq); 802 - if (warning) { 803 - printk(KERN_WARNING "PCI: %s: pci_disable_msix() called without " 804 - "free_irq() on all MSI-X irqs\n", 805 - pci_name(dev)); 806 - BUG_ON(warning > 0); 807 - } 857 + irq = head = dev->first_msi_irq; 858 + while (head != tail) { 859 + tail = get_irq_msi(irq)->link.tail; 860 + if (irq_has_action(irq)) 861 + warning = 1; 862 + else if (irq != head) /* Release MSI-X irq */ 863 + msi_free_irq(dev, irq); 864 + irq = tail; 808 865 } 866 + msi_free_irq(dev, irq); 867 + if (warning) { 868 + printk(KERN_WARNING "PCI: %s: pci_disable_msix() called without " 869 + "free_irq() on all MSI-X irqs\n", 870 + pci_name(dev)); 871 + BUG_ON(warning > 0); 872 + } 873 + dev->first_msi_irq = 0; 809 874 } 810 875 811 876 /** ··· 811 892 **/ 812 893 void msi_remove_pci_irq_vectors(struct pci_dev* dev) 813 894 { 814 - int pos, temp; 815 - unsigned long flags; 816 - 817 895 if (!pci_msi_enable || !dev) 818 896 return; 819 897 820 - temp = dev->irq; /* Save IOAPIC IRQ */ 821 - pos = pci_find_capability(dev, PCI_CAP_ID_MSI); 822 - if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSI)) { 823 - if (irq_has_action(dev->irq)) { 898 + if (dev->msi_enabled) { 899 + if (irq_has_action(dev->first_msi_irq)) { 824 900 printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() " 825 901 "called without free_irq() on MSI irq %d\n", 826 - pci_name(dev), dev->irq); 827 - BUG_ON(irq_has_action(dev->irq)); 902 + pci_name(dev), dev->first_msi_irq); 903 + BUG_ON(irq_has_action(dev->first_msi_irq)); 828 904 } else /* Release MSI irq assigned to this device */ 829 - msi_free_irq(dev, dev->irq); 830 - dev->irq = temp; /* Restore IOAPIC IRQ */ 905 + msi_free_irq(dev, dev->first_msi_irq); 831 906 } 832 - pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); 833 - if (pos > 0 && !msi_lookup_irq(dev, PCI_CAP_ID_MSIX)) { 907 + if (dev->msix_enabled) { 834 908 int irq, head, tail = 0, warning = 0; 835 909 void __iomem *base = NULL; 836 910 837 - irq = head = dev->irq; 911 + irq = head = dev->first_msi_irq; 838 912 while (head != tail) { 839 - spin_lock_irqsave(&msi_lock, flags); 840 - tail = msi_desc[irq]->link.tail; 841 - base = msi_desc[irq]->mask_base; 842 - spin_unlock_irqrestore(&msi_lock, flags); 913 + tail = get_irq_msi(irq)->link.tail; 914 + base = get_irq_msi(irq)->mask_base; 843 915 if (irq_has_action(irq)) 844 916 warning = 1; 845 917 else if (irq != head) /* Release MSI-X irq */ ··· 845 935 pci_name(dev)); 846 936 BUG_ON(warning > 0); 847 937 } 848 - dev->irq = temp; /* Restore IOAPIC IRQ */ 849 938 } 850 939 } 851 940
+1 -2
drivers/pci/pci-driver.c
··· 324 324 /* restore the PCI config space */ 325 325 pci_restore_state(pci_dev); 326 326 /* if the device was enabled before suspend, reenable */ 327 - if (atomic_read(&pci_dev->enable_cnt)) 328 - retval = __pci_enable_device(pci_dev); 327 + retval = __pci_reenable_device(pci_dev); 329 328 /* if the device was busmaster before the suspend, make it busmaster again */ 330 329 if (pci_dev->is_busmaster) 331 330 pci_set_master(pci_dev);
+105 -70
drivers/pci/pci.c
··· 392 392 if (state > PCI_D3hot) 393 393 state = PCI_D3hot; 394 394 395 + /* 396 + * If the device or the parent bridge can't support PCI PM, ignore 397 + * the request if we're doing anything besides putting it into D0 398 + * (which would only happen on boot). 399 + */ 400 + if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) 401 + return 0; 402 + 395 403 /* Validate current state: 396 404 * Can enter D0 from any state, but if we can only go deeper 397 405 * to sleep if we're already in a low power state ··· 411 403 } else if (dev->current_state == state) 412 404 return 0; /* we're already there */ 413 405 414 - /* 415 - * If the device or the parent bridge can't support PCI PM, ignore 416 - * the request if we're doing anything besides putting it into D0 417 - * (which would only happen on boot). 418 - */ 419 - if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) 420 - return 0; 421 406 422 407 /* find PCI PM capability in list */ 423 408 pm = pci_find_capability(dev, PCI_CAP_ID_PM); ··· 634 633 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 635 634 if ((i = pci_save_msi_state(dev)) != 0) 636 635 return i; 637 - if ((i = pci_save_msix_state(dev)) != 0) 638 - return i; 639 636 if ((i = pci_save_pcie_state(dev)) != 0) 640 637 return i; 641 638 if ((i = pci_save_pcix_state(dev)) != 0) ··· 671 672 } 672 673 pci_restore_pcix_state(dev); 673 674 pci_restore_msi_state(dev); 674 - pci_restore_msix_state(dev); 675 + 675 676 return 0; 676 677 } 677 678 678 - /** 679 - * pci_enable_device_bars - Initialize some of a device for use 680 - * @dev: PCI device to be initialized 681 - * @bars: bitmask of BAR's that must be configured 682 - * 683 - * Initialize device before it's used by a driver. Ask low-level code 684 - * to enable selected I/O and memory resources. Wake up the device if it 685 - * was suspended. Beware, this function can fail. 686 - */ 687 - 688 - int 689 - pci_enable_device_bars(struct pci_dev *dev, int bars) 679 + static int do_pci_enable_device(struct pci_dev *dev, int bars) 690 680 { 691 681 int err; 692 682 ··· 685 697 err = pcibios_enable_device(dev, bars); 686 698 if (err < 0) 687 699 return err; 700 + pci_fixup_device(pci_fixup_enable, dev); 701 + 688 702 return 0; 689 703 } 690 704 691 705 /** 692 - * __pci_enable_device - Initialize device before it's used by a driver. 693 - * @dev: PCI device to be initialized 706 + * __pci_reenable_device - Resume abandoned device 707 + * @dev: PCI device to be resumed 694 708 * 695 - * Initialize device before it's used by a driver. Ask low-level code 696 - * to enable I/O and memory. Wake up the device if it was suspended. 697 - * Beware, this function can fail. 698 - * 699 - * Note this function is a backend and is not supposed to be called by 700 - * normal code, use pci_enable_device() instead. 709 + * Note this function is a backend of pci_default_resume and is not supposed 710 + * to be called by normal code, write proper resume handler and use it instead. 701 711 */ 702 712 int 703 - __pci_enable_device(struct pci_dev *dev) 713 + __pci_reenable_device(struct pci_dev *dev) 714 + { 715 + if (atomic_read(&dev->enable_cnt)) 716 + return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1); 717 + return 0; 718 + } 719 + 720 + /** 721 + * pci_enable_device_bars - Initialize some of a device for use 722 + * @dev: PCI device to be initialized 723 + * @bars: bitmask of BAR's that must be configured 724 + * 725 + * Initialize device before it's used by a driver. Ask low-level code 726 + * to enable selected I/O and memory resources. Wake up the device if it 727 + * was suspended. Beware, this function can fail. 728 + */ 729 + int 730 + pci_enable_device_bars(struct pci_dev *dev, int bars) 704 731 { 705 732 int err; 706 733 707 - err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1); 708 - if (err) 709 - return err; 710 - pci_fixup_device(pci_fixup_enable, dev); 711 - return 0; 734 + if (atomic_add_return(1, &dev->enable_cnt) > 1) 735 + return 0; /* already enabled */ 736 + 737 + err = do_pci_enable_device(dev, bars); 738 + if (err < 0) 739 + atomic_dec(&dev->enable_cnt); 740 + return err; 712 741 } 713 742 714 743 /** ··· 741 736 */ 742 737 int pci_enable_device(struct pci_dev *dev) 743 738 { 744 - int result; 745 - if (atomic_add_return(1, &dev->enable_cnt) > 1) 746 - return 0; /* already enabled */ 747 - result = __pci_enable_device(dev); 748 - if (result < 0) 749 - atomic_dec(&dev->enable_cnt); 750 - return result; 739 + return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1); 751 740 } 752 741 753 742 /** ··· 920 921 return -EBUSY; 921 922 } 922 923 924 + /** 925 + * pci_release_selected_regions - Release selected PCI I/O and memory resources 926 + * @pdev: PCI device whose resources were previously reserved 927 + * @bars: Bitmask of BARs to be released 928 + * 929 + * Release selected PCI I/O and memory resources previously reserved. 930 + * Call this function only after all use of the PCI regions has ceased. 931 + */ 932 + void pci_release_selected_regions(struct pci_dev *pdev, int bars) 933 + { 934 + int i; 935 + 936 + for (i = 0; i < 6; i++) 937 + if (bars & (1 << i)) 938 + pci_release_region(pdev, i); 939 + } 940 + 941 + /** 942 + * pci_request_selected_regions - Reserve selected PCI I/O and memory resources 943 + * @pdev: PCI device whose resources are to be reserved 944 + * @bars: Bitmask of BARs to be requested 945 + * @res_name: Name to be associated with resource 946 + */ 947 + int pci_request_selected_regions(struct pci_dev *pdev, int bars, 948 + const char *res_name) 949 + { 950 + int i; 951 + 952 + for (i = 0; i < 6; i++) 953 + if (bars & (1 << i)) 954 + if(pci_request_region(pdev, i, res_name)) 955 + goto err_out; 956 + return 0; 957 + 958 + err_out: 959 + while(--i >= 0) 960 + if (bars & (1 << i)) 961 + pci_release_region(pdev, i); 962 + 963 + return -EBUSY; 964 + } 923 965 924 966 /** 925 967 * pci_release_regions - Release reserved PCI I/O and memory resources ··· 973 933 974 934 void pci_release_regions(struct pci_dev *pdev) 975 935 { 976 - int i; 977 - 978 - for (i = 0; i < 6; i++) 979 - pci_release_region(pdev, i); 936 + pci_release_selected_regions(pdev, (1 << 6) - 1); 980 937 } 981 938 982 939 /** ··· 991 954 */ 992 955 int pci_request_regions(struct pci_dev *pdev, const char *res_name) 993 956 { 994 - int i; 995 - 996 - for (i = 0; i < 6; i++) 997 - if(pci_request_region(pdev, i, res_name)) 998 - goto err_out; 999 - return 0; 1000 - 1001 - err_out: 1002 - while(--i >= 0) 1003 - pci_release_region(pdev, i); 1004 - 1005 - return -EBUSY; 957 + return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name); 1006 958 } 1007 959 1008 960 /** ··· 1174 1148 return 0; 1175 1149 } 1176 1150 #endif 1177 - 1151 + 1152 + /** 1153 + * pci_select_bars - Make BAR mask from the type of resource 1154 + * @pdev: the PCI device for which BAR mask is made 1155 + * @flags: resource type mask to be selected 1156 + * 1157 + * This helper routine makes bar mask from the type of resource. 1158 + */ 1159 + int pci_select_bars(struct pci_dev *dev, unsigned long flags) 1160 + { 1161 + int i, bars = 0; 1162 + for (i = 0; i < PCI_NUM_RESOURCES; i++) 1163 + if (pci_resource_flags(dev, i) & flags) 1164 + bars |= (1 << i); 1165 + return bars; 1166 + } 1167 + 1178 1168 static int __devinit pci_init(void) 1179 1169 { 1180 1170 struct pci_dev *dev = NULL; ··· 1223 1181 1224 1182 device_initcall(pci_init); 1225 1183 1226 - #if defined(CONFIG_ISA) || defined(CONFIG_EISA) 1227 - /* FIXME: Some boxes have multiple ISA bridges! */ 1228 - struct pci_dev *isa_bridge; 1229 - EXPORT_SYMBOL(isa_bridge); 1230 - #endif 1231 - 1232 1184 EXPORT_SYMBOL_GPL(pci_restore_bars); 1233 1185 EXPORT_SYMBOL(pci_enable_device_bars); 1234 1186 EXPORT_SYMBOL(pci_enable_device); ··· 1233 1197 EXPORT_SYMBOL(pci_request_regions); 1234 1198 EXPORT_SYMBOL(pci_release_region); 1235 1199 EXPORT_SYMBOL(pci_request_region); 1200 + EXPORT_SYMBOL(pci_release_selected_regions); 1201 + EXPORT_SYMBOL(pci_request_selected_regions); 1236 1202 EXPORT_SYMBOL(pci_set_master); 1237 1203 EXPORT_SYMBOL(pci_set_mwi); 1238 1204 EXPORT_SYMBOL(pci_clear_mwi); ··· 1243 1205 EXPORT_SYMBOL(pci_set_consistent_dma_mask); 1244 1206 EXPORT_SYMBOL(pci_assign_resource); 1245 1207 EXPORT_SYMBOL(pci_find_parent_resource); 1208 + EXPORT_SYMBOL(pci_select_bars); 1246 1209 1247 1210 EXPORT_SYMBOL(pci_set_power_state); 1248 1211 EXPORT_SYMBOL(pci_save_state); 1249 1212 EXPORT_SYMBOL(pci_restore_state); 1250 1213 EXPORT_SYMBOL(pci_enable_wake); 1251 1214 1252 - /* Quirk info */ 1253 - 1254 - EXPORT_SYMBOL(isa_dma_bridge_buggy); 1255 - EXPORT_SYMBOL(pci_pci_problems);
+4 -10
drivers/pci/pci.h
··· 1 1 /* Functions internal to the PCI core code */ 2 2 3 - extern int __must_check __pci_enable_device(struct pci_dev *); 3 + extern int __must_check __pci_reenable_device(struct pci_dev *); 4 4 extern int pci_uevent(struct device *dev, char **envp, int num_envp, 5 5 char *buffer, int buffer_size); 6 6 extern int pci_create_sysfs_dev_files(struct pci_dev *pdev); ··· 43 43 /* Lock for read/write access to pci device and bus lists */ 44 44 extern struct rw_semaphore pci_bus_sem; 45 45 46 - #ifdef CONFIG_PCI_MSI 47 - extern int pci_msi_quirk; 48 - #else 49 - #define pci_msi_quirk 0 50 - #endif 51 46 extern unsigned int pci_pm_d3_delay; 47 + 52 48 #ifdef CONFIG_PCI_MSI 53 49 void disable_msi_mode(struct pci_dev *dev, int pos, int type); 54 50 void pci_no_msi(void); ··· 52 56 static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { } 53 57 static inline void pci_no_msi(void) { } 54 58 #endif 59 + 55 60 #if defined(CONFIG_PCI_MSI) && defined(CONFIG_PM) 56 61 int pci_save_msi_state(struct pci_dev *dev); 57 - int pci_save_msix_state(struct pci_dev *dev); 58 62 void pci_restore_msi_state(struct pci_dev *dev); 59 - void pci_restore_msix_state(struct pci_dev *dev); 60 63 #else 61 64 static inline int pci_save_msi_state(struct pci_dev *dev) { return 0; } 62 - static inline int pci_save_msix_state(struct pci_dev *dev) { return 0; } 63 65 static inline void pci_restore_msi_state(struct pci_dev *dev) {} 64 - static inline void pci_restore_msix_state(struct pci_dev *dev) {} 65 66 #endif 67 + 66 68 static inline int pci_no_d1d2(struct pci_dev *dev) 67 69 { 68 70 unsigned int parent_dstates = 0;
+56 -14
drivers/pci/probe.c
··· 144 144 return size; 145 145 } 146 146 147 + static u64 pci_size64(u64 base, u64 maxbase, u64 mask) 148 + { 149 + u64 size = mask & maxbase; /* Find the significant bits */ 150 + if (!size) 151 + return 0; 152 + 153 + /* Get the lowest of them to find the decode size, and 154 + from that the extent. */ 155 + size = (size & ~(size-1)) - 1; 156 + 157 + /* base == maxbase can be valid only if the BAR has 158 + already been programmed with all 1s. */ 159 + if (base == maxbase && ((base | size) & mask) != mask) 160 + return 0; 161 + 162 + return size; 163 + } 164 + 165 + static inline int is_64bit_memory(u32 mask) 166 + { 167 + if ((mask & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == 168 + (PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64)) 169 + return 1; 170 + return 0; 171 + } 172 + 147 173 static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) 148 174 { 149 175 unsigned int pos, reg, next; ··· 177 151 struct resource *res; 178 152 179 153 for(pos=0; pos<howmany; pos = next) { 154 + u64 l64; 155 + u64 sz64; 156 + u32 raw_sz; 157 + 180 158 next = pos+1; 181 159 res = &dev->resource[pos]; 182 160 res->name = pci_name(dev); ··· 193 163 continue; 194 164 if (l == 0xffffffff) 195 165 l = 0; 196 - if ((l & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) { 166 + raw_sz = sz; 167 + if ((l & PCI_BASE_ADDRESS_SPACE) == 168 + PCI_BASE_ADDRESS_SPACE_MEMORY) { 197 169 sz = pci_size(l, sz, (u32)PCI_BASE_ADDRESS_MEM_MASK); 198 - if (!sz) 170 + /* 171 + * For 64bit prefetchable memory sz could be 0, if the 172 + * real size is bigger than 4G, so we need to check 173 + * szhi for that. 174 + */ 175 + if (!is_64bit_memory(l) && !sz) 199 176 continue; 200 177 res->start = l & PCI_BASE_ADDRESS_MEM_MASK; 201 178 res->flags |= l & ~PCI_BASE_ADDRESS_MEM_MASK; ··· 215 178 } 216 179 res->end = res->start + (unsigned long) sz; 217 180 res->flags |= pci_calc_resource_flags(l); 218 - if ((l & (PCI_BASE_ADDRESS_SPACE | PCI_BASE_ADDRESS_MEM_TYPE_MASK)) 219 - == (PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64)) { 181 + if (is_64bit_memory(l)) { 220 182 u32 szhi, lhi; 183 + 221 184 pci_read_config_dword(dev, reg+4, &lhi); 222 185 pci_write_config_dword(dev, reg+4, ~0); 223 186 pci_read_config_dword(dev, reg+4, &szhi); 224 187 pci_write_config_dword(dev, reg+4, lhi); 225 - szhi = pci_size(lhi, szhi, 0xffffffff); 188 + sz64 = ((u64)szhi << 32) | raw_sz; 189 + l64 = ((u64)lhi << 32) | l; 190 + sz64 = pci_size64(l64, sz64, PCI_BASE_ADDRESS_MEM_MASK); 226 191 next++; 227 192 #if BITS_PER_LONG == 64 228 - res->start |= ((unsigned long) lhi) << 32; 229 - res->end = res->start + sz; 230 - if (szhi) { 231 - /* This BAR needs > 4GB? Wow. */ 232 - res->end |= (unsigned long)szhi<<32; 193 + if (!sz64) { 194 + res->start = 0; 195 + res->end = 0; 196 + res->flags = 0; 197 + continue; 233 198 } 199 + res->start = l64 & PCI_BASE_ADDRESS_MEM_MASK; 200 + res->end = res->start + sz64; 234 201 #else 235 - if (szhi) { 236 - printk(KERN_ERR "PCI: Unable to handle 64-bit BAR for device %s\n", pci_name(dev)); 202 + if (sz64 > 0x100000000ULL) { 203 + printk(KERN_ERR "PCI: Unable to handle 64-bit " 204 + "BAR for device %s\n", pci_name(dev)); 237 205 res->start = 0; 238 206 res->flags = 0; 239 207 } else if (lhi) { 240 208 /* 64-bit wide address, treat as disabled */ 241 - pci_write_config_dword(dev, reg, l & ~(u32)PCI_BASE_ADDRESS_MEM_MASK); 209 + pci_write_config_dword(dev, reg, 210 + l & ~(u32)PCI_BASE_ADDRESS_MEM_MASK); 242 211 pci_write_config_dword(dev, reg+4, 0); 243 212 res->start = 0; 244 213 res->end = sz; ··· 945 902 return NULL; 946 903 947 904 pci_device_add(dev, bus); 948 - pci_scan_msi_device(dev); 949 905 950 906 return dev; 951 907 }
+55 -58
drivers/pci/quirks.c
··· 61 61 62 62 This appears to be BIOS not version dependent. So presumably there is a 63 63 chipset level fix */ 64 - int isa_dma_bridge_buggy; /* Exported */ 64 + int isa_dma_bridge_buggy; 65 + EXPORT_SYMBOL(isa_dma_bridge_buggy); 65 66 66 67 static void __devinit quirk_isa_dma_hangs(struct pci_dev *dev) 67 68 { ··· 84 83 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_3, quirk_isa_dma_hangs ); 85 84 86 85 int pci_pci_problems; 86 + EXPORT_SYMBOL(pci_pci_problems); 87 87 88 88 /* 89 89 * Chipsets where PCI->PCI transfers vanish or hang ··· 96 94 pci_pci_problems |= PCIPCI_FAIL; 97 95 } 98 96 } 97 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci ); 98 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci ); 99 99 100 100 static void __devinit quirk_nopciamd(struct pci_dev *dev) 101 101 { ··· 109 105 pci_pci_problems |= PCIAGP_FAIL; 110 106 } 111 107 } 112 - 113 - DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci ); 114 - DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci ); 115 108 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8151_0, quirk_nopciamd ); 116 109 117 110 /* ··· 977 976 case 0x1626: /* L3C notebook */ 978 977 asus_hides_smbus = 1; 979 978 } 980 - if (dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) 979 + else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_HB) 981 980 switch(dev->subsystem_device) { 982 981 case 0x80b1: /* P4GE-V */ 983 982 case 0x80b2: /* P4PE */ 984 983 case 0x8093: /* P4B533-V */ 985 984 asus_hides_smbus = 1; 986 985 } 987 - if (dev->device == PCI_DEVICE_ID_INTEL_82850_HB) 986 + else if (dev->device == PCI_DEVICE_ID_INTEL_82850_HB) 988 987 switch(dev->subsystem_device) { 989 988 case 0x8030: /* P4T533 */ 990 989 asus_hides_smbus = 1; 991 990 } 992 - if (dev->device == PCI_DEVICE_ID_INTEL_7205_0) 991 + else if (dev->device == PCI_DEVICE_ID_INTEL_7205_0) 993 992 switch (dev->subsystem_device) { 994 993 case 0x8070: /* P4G8X Deluxe */ 995 994 asus_hides_smbus = 1; 996 995 } 997 - if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH) 996 + else if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH) 998 997 switch (dev->subsystem_device) { 999 998 case 0x80c9: /* PU-DLS */ 1000 999 asus_hides_smbus = 1; 1001 1000 } 1002 - if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB) 1001 + else if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB) 1003 1002 switch (dev->subsystem_device) { 1004 1003 case 0x1751: /* M2N notebook */ 1005 1004 case 0x1821: /* M5N notebook */ 1006 1005 asus_hides_smbus = 1; 1007 1006 } 1008 - if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 1007 + else if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 1009 1008 switch (dev->subsystem_device) { 1010 1009 case 0x184b: /* W1N notebook */ 1011 1010 case 0x186a: /* M6Ne notebook */ 1012 1011 asus_hides_smbus = 1; 1013 1012 } 1014 - if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB) 1013 + else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB) 1015 1014 switch (dev->subsystem_device) { 1016 1015 case 0x80f2: /* P4P800-X */ 1017 1016 asus_hides_smbus = 1; 1018 1017 } 1019 - if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) { 1018 + else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) 1020 1019 switch (dev->subsystem_device) { 1021 1020 case 0x1882: /* M6V notebook */ 1022 1021 case 0x1977: /* A6VA notebook */ 1023 1022 asus_hides_smbus = 1; 1024 1023 } 1025 - } 1026 1024 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) { 1027 1025 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 1028 1026 switch(dev->subsystem_device) { ··· 1029 1029 case 0x0890: /* HP Compaq nc6000 */ 1030 1030 asus_hides_smbus = 1; 1031 1031 } 1032 - if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB) 1032 + else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB) 1033 1033 switch (dev->subsystem_device) { 1034 1034 case 0x12bc: /* HP D330L */ 1035 1035 case 0x12bd: /* HP D530 */ 1036 1036 asus_hides_smbus = 1; 1037 1037 } 1038 - if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) { 1038 + else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) 1039 1039 switch (dev->subsystem_device) { 1040 1040 case 0x099c: /* HP Compaq nx6110 */ 1041 1041 asus_hides_smbus = 1; 1042 1042 } 1043 - } 1044 1043 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_TOSHIBA)) { 1045 1044 if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB) 1046 1045 switch(dev->subsystem_device) { 1047 1046 case 0x0001: /* Toshiba Satellite A40 */ 1048 1047 asus_hides_smbus = 1; 1049 1048 } 1050 - if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 1049 + else if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB) 1051 1050 switch(dev->subsystem_device) { 1052 1051 case 0x0001: /* Toshiba Tecra M2 */ 1053 1052 asus_hides_smbus = 1; ··· 1135 1136 pci_write_config_byte(dev, 0x77, val & ~0x10); 1136 1137 } 1137 1138 } 1139 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus ); 1140 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus ); 1141 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1142 + DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1143 + DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus ); 1144 + DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus ); 1145 + DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1146 + DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1138 1147 1139 1148 /* 1140 1149 * ... This is further complicated by the fact that some SiS96x south ··· 1152 1145 * 1153 1146 * We can also enable the sis96x bit in the discovery register.. 1154 1147 */ 1155 - static int __devinitdata sis_96x_compatible = 0; 1156 - 1157 1148 #define SIS_DETECT_REGISTER 0x40 1158 1149 1159 1150 static void quirk_sis_503(struct pci_dev *dev) ··· 1167 1162 return; 1168 1163 } 1169 1164 1170 - /* Make people aware that we changed the config.. */ 1171 - printk(KERN_WARNING "Uncovering SIS%x that hid as a SIS503 (compatible=%d)\n", devid, sis_96x_compatible); 1172 - 1173 1165 /* 1174 1166 * Ok, it now shows up as a 96x.. run the 96x quirk by 1175 1167 * hand in case it has already been processed. ··· 1175 1173 dev->device = devid; 1176 1174 quirk_sis_96x_smbus(dev); 1177 1175 } 1178 - 1179 - static void __init quirk_sis_96x_compatible(struct pci_dev *dev) 1180 - { 1181 - sis_96x_compatible = 1; 1182 - } 1183 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_645, quirk_sis_96x_compatible ); 1184 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_646, quirk_sis_96x_compatible ); 1185 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_648, quirk_sis_96x_compatible ); 1186 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_650, quirk_sis_96x_compatible ); 1187 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_651, quirk_sis_96x_compatible ); 1188 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible ); 1189 - 1190 1176 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 ); 1191 1177 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 ); 1178 + 1179 + 1192 1180 /* 1193 1181 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller 1194 1182 * and MC97 modem controller are disabled when a second PCI soundcard is ··· 1209 1217 } 1210 1218 } 1211 1219 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc ); 1212 - 1213 - 1214 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus ); 1215 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus ); 1216 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1217 - DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1218 - 1219 1220 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc ); 1220 - 1221 - 1222 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus ); 1223 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus ); 1224 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1225 - DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1226 1221 1227 1222 #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) 1228 1223 ··· 1255 1276 break; 1256 1277 } 1257 1278 } 1258 - 1259 1279 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1260 1280 DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1261 1281 ··· 1398 1420 1399 1421 1400 1422 int pcie_mch_quirk; 1423 + EXPORT_SYMBOL(pcie_mch_quirk); 1401 1424 1402 1425 static void __devinit quirk_pcie_mch(struct pci_dev *pdev) 1403 1426 { ··· 1625 1646 } 1626 1647 pci_do_fixups(dev, start, end); 1627 1648 } 1649 + EXPORT_SYMBOL(pci_fixup_device); 1628 1650 1629 1651 /* Enable 1k I/O space granularity on the Intel P64H2 */ 1630 1652 static void __devinit quirk_p64h2_1k_io(struct pci_dev *dev) ··· 1653 1673 } 1654 1674 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io); 1655 1675 1676 + /* Fix the IOBL_ADR for 1k I/O space granularity on the Intel P64H2 1677 + * The IOBL_ADR gets re-written to 4k boundaries in pci_setup_bridge() 1678 + * in drivers/pci/setup-bus.c 1679 + */ 1680 + static void __devinit quirk_p64h2_1k_io_fix_iobl(struct pci_dev *dev) 1681 + { 1682 + u16 en1k, iobl_adr, iobl_adr_1k; 1683 + struct resource *res = dev->resource + PCI_BRIDGE_RESOURCES; 1684 + 1685 + pci_read_config_word(dev, 0x40, &en1k); 1686 + 1687 + if (en1k & 0x200) { 1688 + pci_read_config_word(dev, PCI_IO_BASE, &iobl_adr); 1689 + 1690 + iobl_adr_1k = iobl_adr | (res->start >> 8) | (res->end & 0xfc00); 1691 + 1692 + if (iobl_adr != iobl_adr_1k) { 1693 + printk(KERN_INFO "PCI: Fixing P64H2 IOBL_ADR from 0x%x to 0x%x for 1 KB Granularity\n", 1694 + iobl_adr,iobl_adr_1k); 1695 + pci_write_config_word(dev, PCI_IO_BASE, iobl_adr_1k); 1696 + } 1697 + } 1698 + } 1699 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io_fix_iobl); 1700 + 1656 1701 /* Under some circumstances, AER is not linked with extended capabilities. 1657 1702 * Force it to be linked by setting the corresponding control bit in the 1658 1703 * config space. ··· 1700 1695 quirk_nvidia_ck804_pcie_aer_ext_cap); 1701 1696 1702 1697 #ifdef CONFIG_PCI_MSI 1703 - /* To disable MSI globally */ 1704 - int pci_msi_quirk; 1705 - 1706 1698 /* The Serverworks PCI-X chipset does not support MSI. We cannot easily rely 1707 1699 * on setting PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually 1708 1700 * some other busses controlled by the chipset even if Linux is not aware of it. ··· 1708 1706 */ 1709 1707 static void __init quirk_svw_msi(struct pci_dev *dev) 1710 1708 { 1711 - pci_msi_quirk = 1; 1712 - printk(KERN_WARNING "PCI: MSI quirk detected. pci_msi_quirk set.\n"); 1709 + pci_no_msi(); 1710 + printk(KERN_WARNING "PCI: MSI quirk detected. MSI deactivated.\n"); 1713 1711 } 1714 1712 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_svw_msi); 1715 1713 ··· 1790 1788 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1791 1789 quirk_nvidia_ck804_msi_ht_cap); 1792 1790 #endif /* CONFIG_PCI_MSI */ 1793 - 1794 - EXPORT_SYMBOL(pcie_mch_quirk); 1795 - #ifdef CONFIG_HOTPLUG 1796 - EXPORT_SYMBOL(pci_fixup_device); 1797 - #endif
-38
drivers/pci/search.c
··· 358 358 } 359 359 360 360 /** 361 - * pci_find_device_reverse - begin or continue searching for a PCI device by vendor/device id 362 - * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids 363 - * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids 364 - * @from: Previous PCI device found in search, or %NULL for new search. 365 - * 366 - * Iterates through the list of known PCI devices in the reverse order of 367 - * pci_find_device(). 368 - * If a PCI device is found with a matching @vendor and @device, a pointer to 369 - * its device structure is returned. Otherwise, %NULL is returned. 370 - * A new search is initiated by passing %NULL as the @from argument. 371 - * Otherwise if @from is not %NULL, searches continue from previous device 372 - * on the global list. 373 - */ 374 - struct pci_dev * 375 - pci_find_device_reverse(unsigned int vendor, unsigned int device, const struct pci_dev *from) 376 - { 377 - struct list_head *n; 378 - struct pci_dev *dev; 379 - 380 - WARN_ON(in_interrupt()); 381 - down_read(&pci_bus_sem); 382 - n = from ? from->global_list.prev : pci_devices.prev; 383 - 384 - while (n && (n != &pci_devices)) { 385 - dev = pci_dev_g(n); 386 - if ((vendor == PCI_ANY_ID || dev->vendor == vendor) && 387 - (device == PCI_ANY_ID || dev->device == device)) 388 - goto exit; 389 - n = n->prev; 390 - } 391 - dev = NULL; 392 - exit: 393 - up_read(&pci_bus_sem); 394 - return dev; 395 - } 396 - 397 - /** 398 361 * pci_get_class - begin or continue searching for a PCI device by class 399 362 * @class: search for a PCI device with this class designation 400 363 * @from: Previous PCI device found in search, or %NULL for new search. ··· 432 469 EXPORT_SYMBOL(pci_find_present); 433 470 434 471 EXPORT_SYMBOL(pci_find_device); 435 - EXPORT_SYMBOL(pci_find_device_reverse); 436 472 EXPORT_SYMBOL(pci_find_slot); 437 473 /* For boot time work */ 438 474 EXPORT_SYMBOL(pci_find_bus);
-3
drivers/scsi/ipr.c
··· 7558 7558 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7559 7559 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 7560 7560 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] }, 7561 - { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7562 - PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B8, 7563 - 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] }, 7564 7561 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, 7565 7562 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 7566 7563 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
+2
include/asm-alpha/pci.h
··· 293 293 #define IOBASE_ROOT_BUS 5 294 294 #define IOBASE_FROM_HOSE 0x10000 295 295 296 + extern struct pci_dev *isa_bridge; 297 + 296 298 #endif /* __ALPHA_PCI_H */
+2 -1
include/asm-ia64/machvec.h
··· 21 21 struct pci_bus; 22 22 struct task_struct; 23 23 struct pci_dev; 24 + struct msi_desc; 24 25 25 26 typedef void ia64_mv_setup_t (char **); 26 27 typedef void ia64_mv_cpu_init_t (void); ··· 80 79 typedef unsigned int ia64_mv_readl_relaxed_t (const volatile void __iomem *); 81 80 typedef unsigned long ia64_mv_readq_relaxed_t (const volatile void __iomem *); 82 81 83 - typedef int ia64_mv_setup_msi_irq_t (unsigned int irq, struct pci_dev *pdev); 82 + typedef int ia64_mv_setup_msi_irq_t (struct pci_dev *pdev, struct msi_desc *); 84 83 typedef void ia64_mv_teardown_msi_irq_t (unsigned int irq); 85 84 86 85 static inline void
+4
include/linux/irq.h
··· 68 68 #define IRQ_MOVE_PENDING 0x40000000 /* need to re-target IRQ destination */ 69 69 70 70 struct proc_dir_entry; 71 + struct msi_desc; 71 72 72 73 /** 73 74 * struct irq_chip - hardware interrupt chip descriptor ··· 149 148 struct irq_desc { 150 149 irq_flow_handler_t handle_irq; 151 150 struct irq_chip *chip; 151 + struct msi_desc *msi_desc; 152 152 void *handler_data; 153 153 void *chip_data; 154 154 struct irqaction *action; /* IRQ action list */ ··· 375 373 extern int set_irq_data(unsigned int irq, void *data); 376 374 extern int set_irq_chip_data(unsigned int irq, void *data); 377 375 extern int set_irq_type(unsigned int irq, unsigned int type); 376 + extern int set_irq_msi(unsigned int irq, struct msi_desc *entry); 378 377 379 378 #define get_irq_chip(irq) (irq_desc[irq].chip) 380 379 #define get_irq_chip_data(irq) (irq_desc[irq].chip_data) 381 380 #define get_irq_data(irq) (irq_desc[irq].handler_data) 381 + #define get_irq_msi(irq) (irq_desc[irq].msi_desc) 382 382 383 383 #endif /* CONFIG_GENERIC_HARDIRQS */ 384 384
+2 -3
include/linux/msi.h
··· 7 7 u32 data; /* 16 bits of msi message data */ 8 8 }; 9 9 10 - /* Heper functions */ 10 + /* Helper functions */ 11 11 extern void mask_msi_irq(unsigned int irq); 12 12 extern void unmask_msi_irq(unsigned int irq); 13 13 extern void read_msi_msg(unsigned int irq, struct msi_msg *msg); 14 - 15 14 extern void write_msi_msg(unsigned int irq, struct msi_msg *msg); 16 15 17 16 struct msi_desc { ··· 41 42 /* 42 43 * The arch hook for setup up msi irqs 43 44 */ 44 - int arch_setup_msi_irq(unsigned int irq, struct pci_dev *dev); 45 + int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc); 45 46 void arch_teardown_msi_irq(unsigned int irq); 46 47 47 48
+12 -10
include/linux/pci.h
··· 174 174 struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */ 175 175 int rom_attr_enabled; /* has display of the rom attribute been enabled? */ 176 176 struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */ 177 + #ifdef CONFIG_PCI_MSI 178 + unsigned int first_msi_irq; 179 + #endif 177 180 }; 178 181 179 182 #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list) 180 183 #define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list) 181 184 #define to_pci_dev(n) container_of(n, struct pci_dev, dev) 182 185 #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL) 186 + 187 + static inline int pci_channel_offline(struct pci_dev *pdev) 188 + { 189 + return (pdev->error_state != pci_channel_io_normal); 190 + } 183 191 184 192 static inline struct pci_cap_saved_state *pci_find_saved_cap( 185 193 struct pci_dev *pci_dev,char cap) ··· 471 463 472 464 /* Generic PCI functions exported to card drivers */ 473 465 474 - struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from); 475 - struct pci_dev *pci_find_device_reverse (unsigned int vendor, unsigned int device, const struct pci_dev *from); 466 + struct pci_dev __deprecated *pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from); 476 467 struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn); 477 468 int pci_find_capability (struct pci_dev *dev, int cap); 478 469 int pci_find_next_capability (struct pci_dev *dev, u8 pos, int cap); ··· 540 533 int __must_check pci_assign_resource(struct pci_dev *dev, int i); 541 534 int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i); 542 535 void pci_restore_bars(struct pci_dev *dev); 536 + int pci_select_bars(struct pci_dev *dev, unsigned long flags); 543 537 544 538 /* ROM control related routines */ 545 539 void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size); ··· 569 561 void pci_release_regions(struct pci_dev *); 570 562 int __must_check pci_request_region(struct pci_dev *, int, const char *); 571 563 void pci_release_region(struct pci_dev *, int); 564 + int pci_request_selected_regions(struct pci_dev *, int, const char *); 565 + void pci_release_selected_regions(struct pci_dev *, int); 572 566 573 567 /* drivers/pci/bus.c */ 574 568 int __must_check pci_bus_alloc_resource(struct pci_bus *bus, ··· 622 612 strategy_parameter byte boundaries */ 623 613 }; 624 614 625 - #if defined(CONFIG_ISA) || defined(CONFIG_EISA) 626 - extern struct pci_dev *isa_bridge; 627 - #endif 628 - 629 615 struct msix_entry { 630 616 u16 vector; /* kernel uses to write allocated vector */ 631 617 u16 entry; /* driver uses to specify entry, OS writes */ ··· 629 623 630 624 631 625 #ifndef CONFIG_PCI_MSI 632 - static inline void pci_scan_msi_device(struct pci_dev *dev) {} 633 626 static inline int pci_enable_msi(struct pci_dev *dev) {return -1;} 634 627 static inline void pci_disable_msi(struct pci_dev *dev) {} 635 628 static inline int pci_enable_msix(struct pci_dev* dev, ··· 636 631 static inline void pci_disable_msix(struct pci_dev *dev) {} 637 632 static inline void msi_remove_pci_irq_vectors(struct pci_dev *dev) {} 638 633 #else 639 - extern void pci_scan_msi_device(struct pci_dev *dev); 640 634 extern int pci_enable_msi(struct pci_dev *dev); 641 635 extern void pci_disable_msi(struct pci_dev *dev); 642 636 extern int pci_enable_msix(struct pci_dev* dev, ··· 726 722 static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; } 727 723 static inline pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) { return PCI_D0; } 728 724 static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; } 729 - 730 - #define isa_bridge ((struct pci_dev *)NULL) 731 725 732 726 #define pci_dma_burst_advice(pdev, strat, strategy_parameter) do { } while (0) 733 727
+28
kernel/irq/chip.c
··· 39 39 desc->chip = &no_irq_chip; 40 40 desc->handle_irq = handle_bad_irq; 41 41 desc->depth = 1; 42 + desc->msi_desc = NULL; 42 43 desc->handler_data = NULL; 43 44 desc->chip_data = NULL; 44 45 desc->action = NULL; ··· 75 74 WARN_ON(1); 76 75 return; 77 76 } 77 + desc->msi_desc = NULL; 78 + desc->handler_data = NULL; 79 + desc->chip_data = NULL; 78 80 desc->handle_irq = handle_bad_irq; 79 81 desc->chip = &no_irq_chip; 80 82 spin_unlock_irqrestore(&desc->lock, flags); ··· 164 160 return 0; 165 161 } 166 162 EXPORT_SYMBOL(set_irq_data); 163 + 164 + /** 165 + * set_irq_data - set irq type data for an irq 166 + * @irq: Interrupt number 167 + * @data: Pointer to interrupt specific data 168 + * 169 + * Set the hardware irq controller data for an irq 170 + */ 171 + int set_irq_msi(unsigned int irq, struct msi_desc *entry) 172 + { 173 + struct irq_desc *desc; 174 + unsigned long flags; 175 + 176 + if (irq >= NR_IRQS) { 177 + printk(KERN_ERR 178 + "Trying to install msi data for IRQ%d\n", irq); 179 + return -EINVAL; 180 + } 181 + desc = irq_desc + irq; 182 + spin_lock_irqsave(&desc->lock, flags); 183 + desc->msi_desc = entry; 184 + spin_unlock_irqrestore(&desc->lock, flags); 185 + return 0; 186 + } 167 187 168 188 /** 169 189 * set_irq_chip_data - set irq chip data for an irq