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

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6: (21 commits)
pciehp: fix error message about getting hotplug control
pci/irq: let pci_device_shutdown to call pci_msi_shutdown v2
pci/irq: restore mask_bits in msi shutdown -v3
doc: replace yet another dev with pdev for consistency in DMA-mapping.txt
PCI: don't expose struct pci_vpd to userspace
doc: fix an incorrect suggestion to pass NULL for PCI like buses
Consistently use pdev as the variable of type struct pci_dev *.
pciehp: Fix command write
shpchp: fix slot name
make pciehp_acpi_get_hp_hw_control_from_firmware()
pciehp: Clean up pcie_init()
pciehp: Mask hotplug interrupt at controller release
pciehp: Remove useless hotplug interrupt enabling
pciehp: Fix wrong slot capability check
pciehp: Fix wrong slot control register access
pciehp: Add missing memory barrier
pciehp: Fix interrupt event handlig
pciehp: fix slot name
Update MAINTAINERS with location of PCI tree
PCI: Add Intel SCH PCI IDs
...

+306 -472
+19 -19
Documentation/DMA-mapping.txt
··· 315 315 316 316 dma_addr_t dma_handle; 317 317 318 - cpu_addr = pci_alloc_consistent(dev, size, &dma_handle); 318 + cpu_addr = pci_alloc_consistent(pdev, size, &dma_handle); 319 319 320 - where dev is a struct pci_dev *. You should pass NULL for PCI like buses 321 - where devices don't have struct pci_dev (like ISA, EISA). This may be 322 - called in interrupt context. 320 + where pdev is a struct pci_dev *. This may be called in interrupt context. 321 + You should use dma_alloc_coherent (see DMA-API.txt) for buses 322 + where devices don't have struct pci_dev (like ISA, EISA). 323 323 324 324 This argument is needed because the DMA translations may be bus 325 325 specific (and often is private to the bus which the device is attached ··· 332 332 driver needs regions sized smaller than a page, you may prefer using 333 333 the pci_pool interface, described below. 334 334 335 - The consistent DMA mapping interfaces, for non-NULL dev, will by 335 + The consistent DMA mapping interfaces, for non-NULL pdev, will by 336 336 default return a DMA address which is SAC (Single Address Cycle) 337 337 addressable. Even if the device indicates (via PCI dma mask) that it 338 338 may address the upper 32-bits and thus perform DAC cycles, consistent ··· 354 354 355 355 To unmap and free such a DMA region, you call: 356 356 357 - pci_free_consistent(dev, size, cpu_addr, dma_handle); 357 + pci_free_consistent(pdev, size, cpu_addr, dma_handle); 358 358 359 - where dev, size are the same as in the above call and cpu_addr and 359 + where pdev, size are the same as in the above call and cpu_addr and 360 360 dma_handle are the values pci_alloc_consistent returned to you. 361 361 This function may not be called in interrupt context. 362 362 ··· 371 371 372 372 struct pci_pool *pool; 373 373 374 - pool = pci_pool_create(name, dev, size, align, alloc); 374 + pool = pci_pool_create(name, pdev, size, align, alloc); 375 375 376 - The "name" is for diagnostics (like a kmem_cache name); dev and size 376 + The "name" is for diagnostics (like a kmem_cache name); pdev and size 377 377 are as above. The device's hardware alignment requirement for this 378 378 type of data is "align" (which is expressed in bytes, and must be a 379 379 power of two). If your device has no boundary crossing restrictions, ··· 472 472 void *addr = buffer->ptr; 473 473 size_t size = buffer->len; 474 474 475 - dma_handle = pci_map_single(dev, addr, size, direction); 475 + dma_handle = pci_map_single(pdev, addr, size, direction); 476 476 477 477 and to unmap it: 478 478 479 - pci_unmap_single(dev, dma_handle, size, direction); 479 + pci_unmap_single(pdev, dma_handle, size, direction); 480 480 481 481 You should call pci_unmap_single when the DMA activity is finished, e.g. 482 482 from the interrupt which told you that the DMA transfer is done. ··· 493 493 unsigned long offset = buffer->offset; 494 494 size_t size = buffer->len; 495 495 496 - dma_handle = pci_map_page(dev, page, offset, size, direction); 496 + dma_handle = pci_map_page(pdev, page, offset, size, direction); 497 497 498 498 ... 499 499 500 - pci_unmap_page(dev, dma_handle, size, direction); 500 + pci_unmap_page(pdev, dma_handle, size, direction); 501 501 502 502 Here, "offset" means byte offset within the given page. 503 503 504 504 With scatterlists, you map a region gathered from several regions by: 505 505 506 - int i, count = pci_map_sg(dev, sglist, nents, direction); 506 + int i, count = pci_map_sg(pdev, sglist, nents, direction); 507 507 struct scatterlist *sg; 508 508 509 509 for_each_sg(sglist, sg, count, i) { ··· 527 527 528 528 To unmap a scatterlist, just call: 529 529 530 - pci_unmap_sg(dev, sglist, nents, direction); 530 + pci_unmap_sg(pdev, sglist, nents, direction); 531 531 532 532 Again, make sure DMA activity has already finished. 533 533 ··· 550 550 So, firstly, just map it with pci_map_{single,sg}, and after each DMA 551 551 transfer call either: 552 552 553 - pci_dma_sync_single_for_cpu(dev, dma_handle, size, direction); 553 + pci_dma_sync_single_for_cpu(pdev, dma_handle, size, direction); 554 554 555 555 or: 556 556 557 - pci_dma_sync_sg_for_cpu(dev, sglist, nents, direction); 557 + pci_dma_sync_sg_for_cpu(pdev, sglist, nents, direction); 558 558 559 559 as appropriate. 560 560 ··· 562 562 finish accessing the data with the cpu, and then before actually 563 563 giving the buffer to the hardware call either: 564 564 565 - pci_dma_sync_single_for_device(dev, dma_handle, size, direction); 565 + pci_dma_sync_single_for_device(pdev, dma_handle, size, direction); 566 566 567 567 or: 568 568 ··· 739 739 740 740 dma_addr_t dma_handle; 741 741 742 - dma_handle = pci_map_single(dev, addr, size, direction); 742 + dma_handle = pci_map_single(pdev, addr, size, direction); 743 743 if (pci_dma_mapping_error(dma_handle)) { 744 744 /* 745 745 * reduce current DMA mapping usage,
+1
MAINTAINERS
··· 3114 3114 M: jbarnes@virtuousgeek.org 3115 3115 L: linux-kernel@vger.kernel.org 3116 3116 L: linux-pci@atrey.karlin.mff.cuni.cz 3117 + T: git kernel.org:/pub/scm/linux/kernel/git/jbarnes/pci-2.6.git 3117 3118 S: Supported 3118 3119 3119 3120 PCI HOTPLUG CORE
+8 -9
drivers/pci/hotplug/pciehp.h
··· 93 93 u8 slot_device_offset; 94 94 u32 first_slot; /* First physical slot number */ /* PCIE only has 1 slot */ 95 95 u8 slot_bus; /* Bus where the slots handled by this controller sit */ 96 - u8 ctrlcap; 96 + u32 slot_cap; 97 97 u8 cap_base; 98 98 struct timer_list poll_timer; 99 99 volatile int cmd_busy; 100 - spinlock_t lock; 101 100 }; 102 101 103 102 #define INT_BUTTON_IGNORE 0 ··· 136 137 #define HP_SUPR_RM_SUP 0x00000020 137 138 #define EMI_PRSN 0x00020000 138 139 139 - #define ATTN_BUTTN(cap) (cap & ATTN_BUTTN_PRSN) 140 - #define POWER_CTRL(cap) (cap & PWR_CTRL_PRSN) 141 - #define MRL_SENS(cap) (cap & MRL_SENS_PRSN) 142 - #define ATTN_LED(cap) (cap & ATTN_LED_PRSN) 143 - #define PWR_LED(cap) (cap & PWR_LED_PRSN) 144 - #define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP) 145 - #define EMI(cap) (cap & EMI_PRSN) 140 + #define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & ATTN_BUTTN_PRSN) 141 + #define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PWR_CTRL_PRSN) 142 + #define MRL_SENS(ctrl) ((ctrl)->slot_cap & MRL_SENS_PRSN) 143 + #define ATTN_LED(ctrl) ((ctrl)->slot_cap & ATTN_LED_PRSN) 144 + #define PWR_LED(ctrl) ((ctrl)->slot_cap & PWR_LED_PRSN) 145 + #define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & HP_SUPR_RM_SUP) 146 + #define EMI(ctrl) ((ctrl)->slot_cap & EMI_PRSN) 146 147 147 148 extern int pciehp_sysfs_enable_slot(struct slot *slot); 148 149 extern int pciehp_sysfs_disable_slot(struct slot *slot);
+13 -6
drivers/pci/hotplug/pciehp_core.c
··· 41 41 int pciehp_poll_mode; 42 42 int pciehp_poll_time; 43 43 int pciehp_force; 44 + int pciehp_slot_with_bus; 44 45 struct workqueue_struct *pciehp_wq; 45 46 46 47 #define DRIVER_VERSION "0.4" ··· 56 55 module_param(pciehp_poll_mode, bool, 0644); 57 56 module_param(pciehp_poll_time, int, 0644); 58 57 module_param(pciehp_force, bool, 0644); 58 + module_param(pciehp_slot_with_bus, bool, 0644); 59 59 MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); 60 60 MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); 61 61 MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); 62 62 MODULE_PARM_DESC(pciehp_force, "Force pciehp, even if _OSC and OSHP are missing"); 63 + MODULE_PARM_DESC(pciehp_slot_with_bus, "Use bus number in the slot name"); 63 64 64 65 #define PCIE_MODULE_NAME "pciehp" 65 66 ··· 196 193 197 194 static void make_slot_name(struct slot *slot) 198 195 { 199 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 200 - slot->bus, slot->number); 196 + if (pciehp_slot_with_bus) 197 + snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 198 + slot->bus, slot->number); 199 + else 200 + snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", 201 + slot->number); 201 202 } 202 203 203 204 static int init_slots(struct controller *ctrl) ··· 258 251 goto error_info; 259 252 } 260 253 /* create additional sysfs entries */ 261 - if (EMI(ctrl->ctrlcap)) { 254 + if (EMI(ctrl)) { 262 255 retval = sysfs_create_file(&hotplug_slot->kobj, 263 256 &hotplug_slot_attr_lock.attr); 264 257 if (retval) { ··· 291 284 list_for_each_safe(tmp, next, &ctrl->slot_list) { 292 285 slot = list_entry(tmp, struct slot, slot_list); 293 286 list_del(&slot->slot_list); 294 - if (EMI(ctrl->ctrlcap)) 287 + if (EMI(ctrl)) 295 288 sysfs_remove_file(&slot->hotplug_slot->kobj, 296 289 &hotplug_slot_attr_lock.attr); 297 290 cancel_delayed_work(&slot->work); ··· 312 305 313 306 hotplug_slot->info->attention_status = status; 314 307 315 - if (ATTN_LED(slot->ctrl->ctrlcap)) 308 + if (ATTN_LED(slot->ctrl)) 316 309 slot->hpc_ops->set_attention_status(slot, status); 317 310 318 311 return 0; ··· 479 472 if (rc) /* -ENODEV: shouldn't happen, but deal with it */ 480 473 value = 0; 481 474 } 482 - if ((POWER_CTRL(ctrl->ctrlcap)) && !value) { 475 + if ((POWER_CTRL(ctrl)) && !value) { 483 476 rc = t_slot->hpc_ops->power_off_slot(t_slot); /* Power off slot if not occupied*/ 484 477 if (rc) 485 478 goto err_out_free_ctrl_slot;
+23 -23
drivers/pci/hotplug/pciehp_ctrl.c
··· 178 178 static void set_slot_off(struct controller *ctrl, struct slot * pslot) 179 179 { 180 180 /* turn off slot, turn on Amber LED, turn off Green LED if supported*/ 181 - if (POWER_CTRL(ctrl->ctrlcap)) { 181 + if (POWER_CTRL(ctrl)) { 182 182 if (pslot->hpc_ops->power_off_slot(pslot)) { 183 183 err("%s: Issue of Slot Power Off command failed\n", 184 184 __func__); ··· 186 186 } 187 187 } 188 188 189 - if (PWR_LED(ctrl->ctrlcap)) 189 + if (PWR_LED(ctrl)) 190 190 pslot->hpc_ops->green_led_off(pslot); 191 191 192 - if (ATTN_LED(ctrl->ctrlcap)) { 192 + if (ATTN_LED(ctrl)) { 193 193 if (pslot->hpc_ops->set_attention_status(pslot, 1)) { 194 194 err("%s: Issue of Set Attention Led command failed\n", 195 195 __func__); ··· 214 214 __func__, p_slot->device, 215 215 ctrl->slot_device_offset, p_slot->hp_slot); 216 216 217 - if (POWER_CTRL(ctrl->ctrlcap)) { 217 + if (POWER_CTRL(ctrl)) { 218 218 /* Power on slot */ 219 219 retval = p_slot->hpc_ops->power_on_slot(p_slot); 220 220 if (retval) 221 221 return retval; 222 222 } 223 223 224 - if (PWR_LED(ctrl->ctrlcap)) 224 + if (PWR_LED(ctrl)) 225 225 p_slot->hpc_ops->green_led_blink(p_slot); 226 226 227 227 /* Wait for ~1 second */ ··· 254 254 */ 255 255 if (pcie_mch_quirk) 256 256 pci_fixup_device(pci_fixup_final, ctrl->pci_dev); 257 - if (PWR_LED(ctrl->ctrlcap)) 257 + if (PWR_LED(ctrl)) 258 258 p_slot->hpc_ops->green_led_on(p_slot); 259 259 260 260 return 0; ··· 279 279 280 280 dbg("In %s, hp_slot = %d\n", __func__, p_slot->hp_slot); 281 281 282 - if (POWER_CTRL(ctrl->ctrlcap)) { 282 + if (POWER_CTRL(ctrl)) { 283 283 /* power off slot */ 284 284 retval = p_slot->hpc_ops->power_off_slot(p_slot); 285 285 if (retval) { ··· 289 289 } 290 290 } 291 291 292 - if (PWR_LED(ctrl->ctrlcap)) 292 + if (PWR_LED(ctrl)) 293 293 /* turn off Green LED */ 294 294 p_slot->hpc_ops->green_led_off(p_slot); 295 295 ··· 327 327 case POWERON_STATE: 328 328 mutex_unlock(&p_slot->lock); 329 329 if (pciehp_enable_slot(p_slot) && 330 - PWR_LED(p_slot->ctrl->ctrlcap)) 330 + PWR_LED(p_slot->ctrl)) 331 331 p_slot->hpc_ops->green_led_off(p_slot); 332 332 mutex_lock(&p_slot->lock); 333 333 p_slot->state = STATIC_STATE; ··· 409 409 "press.\n", p_slot->name); 410 410 } 411 411 /* blink green LED and turn off amber */ 412 - if (PWR_LED(ctrl->ctrlcap)) 412 + if (PWR_LED(ctrl)) 413 413 p_slot->hpc_ops->green_led_blink(p_slot); 414 - if (ATTN_LED(ctrl->ctrlcap)) 414 + if (ATTN_LED(ctrl)) 415 415 p_slot->hpc_ops->set_attention_status(p_slot, 0); 416 416 417 417 schedule_delayed_work(&p_slot->work, 5*HZ); ··· 427 427 dbg("%s: button cancel\n", __func__); 428 428 cancel_delayed_work(&p_slot->work); 429 429 if (p_slot->state == BLINKINGOFF_STATE) { 430 - if (PWR_LED(ctrl->ctrlcap)) 430 + if (PWR_LED(ctrl)) 431 431 p_slot->hpc_ops->green_led_on(p_slot); 432 432 } else { 433 - if (PWR_LED(ctrl->ctrlcap)) 433 + if (PWR_LED(ctrl)) 434 434 p_slot->hpc_ops->green_led_off(p_slot); 435 435 } 436 - if (ATTN_LED(ctrl->ctrlcap)) 436 + if (ATTN_LED(ctrl)) 437 437 p_slot->hpc_ops->set_attention_status(p_slot, 0); 438 438 info("PCI slot #%s - action canceled due to button press\n", 439 439 p_slot->name); ··· 492 492 handle_button_press_event(p_slot); 493 493 break; 494 494 case INT_POWER_FAULT: 495 - if (!POWER_CTRL(ctrl->ctrlcap)) 495 + if (!POWER_CTRL(ctrl)) 496 496 break; 497 - if (ATTN_LED(ctrl->ctrlcap)) 497 + if (ATTN_LED(ctrl)) 498 498 p_slot->hpc_ops->set_attention_status(p_slot, 1); 499 - if (PWR_LED(ctrl->ctrlcap)) 499 + if (PWR_LED(ctrl)) 500 500 p_slot->hpc_ops->green_led_off(p_slot); 501 501 break; 502 502 case INT_PRESENCE_ON: 503 503 case INT_PRESENCE_OFF: 504 - if (!HP_SUPR_RM(ctrl->ctrlcap)) 504 + if (!HP_SUPR_RM(ctrl)) 505 505 break; 506 506 dbg("Surprise Removal\n"); 507 507 update_slot_info(p_slot); ··· 531 531 mutex_unlock(&p_slot->ctrl->crit_sect); 532 532 return -ENODEV; 533 533 } 534 - if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 534 + if (MRL_SENS(p_slot->ctrl)) { 535 535 rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 536 536 if (rc || getstatus) { 537 537 info("%s: latch open on slot(%s)\n", __func__, ··· 541 541 } 542 542 } 543 543 544 - if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { 544 + if (POWER_CTRL(p_slot->ctrl)) { 545 545 rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 546 546 if (rc || getstatus) { 547 547 info("%s: already enabled on slot(%s)\n", __func__, ··· 576 576 /* Check to see if (latch closed, card present, power on) */ 577 577 mutex_lock(&p_slot->ctrl->crit_sect); 578 578 579 - if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) { 579 + if (!HP_SUPR_RM(p_slot->ctrl)) { 580 580 ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); 581 581 if (ret || !getstatus) { 582 582 info("%s: no adapter on slot(%s)\n", __func__, ··· 586 586 } 587 587 } 588 588 589 - if (MRL_SENS(p_slot->ctrl->ctrlcap)) { 589 + if (MRL_SENS(p_slot->ctrl)) { 590 590 ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); 591 591 if (ret || getstatus) { 592 592 info("%s: latch open on slot(%s)\n", __func__, ··· 596 596 } 597 597 } 598 598 599 - if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { 599 + if (POWER_CTRL(p_slot->ctrl)) { 600 600 ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 601 601 if (ret || !getstatus) { 602 602 info("%s: already disabled slot(%s)\n", __func__,
+179 -394
drivers/pci/hotplug/pciehp_hpc.c
··· 221 221 add_timer(&ctrl->poll_timer); 222 222 } 223 223 224 + static inline int pciehp_request_irq(struct controller *ctrl) 225 + { 226 + int retval, irq = ctrl->pci_dev->irq; 227 + 228 + /* Install interrupt polling timer. Start with 10 sec delay */ 229 + if (pciehp_poll_mode) { 230 + init_timer(&ctrl->poll_timer); 231 + start_int_poll_timer(ctrl, 10); 232 + return 0; 233 + } 234 + 235 + /* Installs the interrupt handler */ 236 + retval = request_irq(irq, pcie_isr, IRQF_SHARED, MY_NAME, ctrl); 237 + if (retval) 238 + err("Cannot get irq %d for the hotplug controller\n", irq); 239 + return retval; 240 + } 241 + 242 + static inline void pciehp_free_irq(struct controller *ctrl) 243 + { 244 + if (pciehp_poll_mode) 245 + del_timer_sync(&ctrl->poll_timer); 246 + else 247 + free_irq(ctrl->pci_dev->irq, ctrl); 248 + } 249 + 224 250 static inline int pcie_wait_cmd(struct controller *ctrl) 225 251 { 226 252 int retval = 0; ··· 268 242 269 243 /** 270 244 * pcie_write_cmd - Issue controller command 271 - * @slot: slot to which the command is issued 245 + * @ctrl: controller to which the command is issued 272 246 * @cmd: command value written to slot control register 273 247 * @mask: bitmask of slot control register to be modified 274 248 */ 275 - static int pcie_write_cmd(struct slot *slot, u16 cmd, u16 mask) 249 + static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask) 276 250 { 277 - struct controller *ctrl = slot->ctrl; 278 251 int retval = 0; 279 252 u16 slot_status; 280 253 u16 slot_ctrl; 281 - unsigned long flags; 282 254 283 255 mutex_lock(&ctrl->ctrl_lock); 284 256 ··· 294 270 __func__); 295 271 } 296 272 297 - spin_lock_irqsave(&ctrl->lock, flags); 298 273 retval = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 299 274 if (retval) { 300 275 err("%s: Cannot read SLOTCTRL register\n", __func__); 301 - goto out_spin_unlock; 276 + goto out; 302 277 } 303 278 304 279 slot_ctrl &= ~mask; 305 - slot_ctrl |= ((cmd & mask) | CMD_CMPL_INTR_ENABLE); 280 + slot_ctrl |= (cmd & mask); 281 + /* Don't enable command completed if caller is changing it. */ 282 + if (!(mask & CMD_CMPL_INTR_ENABLE)) 283 + slot_ctrl |= CMD_CMPL_INTR_ENABLE; 306 284 307 285 ctrl->cmd_busy = 1; 286 + smp_mb(); 308 287 retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl); 309 288 if (retval) 310 289 err("%s: Cannot write to SLOTCTRL register\n", __func__); 311 - 312 - out_spin_unlock: 313 - spin_unlock_irqrestore(&ctrl->lock, flags); 314 290 315 291 /* 316 292 * Wait for command completion. ··· 491 467 492 468 slot_cmd = EMI_CTRL; 493 469 cmd_mask = EMI_CTRL; 494 - if (!pciehp_poll_mode) { 495 - slot_cmd = slot_cmd | HP_INTR_ENABLE; 496 - cmd_mask = cmd_mask | HP_INTR_ENABLE; 497 - } 498 - 499 - rc = pcie_write_cmd(slot, slot_cmd, cmd_mask); 470 + rc = pcie_write_cmd(slot->ctrl, slot_cmd, cmd_mask); 500 471 slot->last_emi_toggle = get_seconds(); 501 472 502 473 return rc; ··· 518 499 default: 519 500 return -1; 520 501 } 521 - if (!pciehp_poll_mode) { 522 - slot_cmd = slot_cmd | HP_INTR_ENABLE; 523 - cmd_mask = cmd_mask | HP_INTR_ENABLE; 524 - } 525 - 526 - rc = pcie_write_cmd(slot, slot_cmd, cmd_mask); 502 + rc = pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 527 503 dbg("%s: SLOTCTRL %x write cmd %x\n", 528 504 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 529 505 ··· 533 519 534 520 slot_cmd = 0x0100; 535 521 cmd_mask = PWR_LED_CTRL; 536 - if (!pciehp_poll_mode) { 537 - slot_cmd = slot_cmd | HP_INTR_ENABLE; 538 - cmd_mask = cmd_mask | HP_INTR_ENABLE; 539 - } 540 - 541 - pcie_write_cmd(slot, slot_cmd, cmd_mask); 542 - 522 + pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 543 523 dbg("%s: SLOTCTRL %x write cmd %x\n", 544 524 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 545 525 } ··· 546 538 547 539 slot_cmd = 0x0300; 548 540 cmd_mask = PWR_LED_CTRL; 549 - if (!pciehp_poll_mode) { 550 - slot_cmd = slot_cmd | HP_INTR_ENABLE; 551 - cmd_mask = cmd_mask | HP_INTR_ENABLE; 552 - } 553 - 554 - pcie_write_cmd(slot, slot_cmd, cmd_mask); 541 + pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 555 542 dbg("%s: SLOTCTRL %x write cmd %x\n", 556 543 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 557 544 } ··· 559 556 560 557 slot_cmd = 0x0200; 561 558 cmd_mask = PWR_LED_CTRL; 562 - if (!pciehp_poll_mode) { 563 - slot_cmd = slot_cmd | HP_INTR_ENABLE; 564 - cmd_mask = cmd_mask | HP_INTR_ENABLE; 565 - } 566 - 567 - pcie_write_cmd(slot, slot_cmd, cmd_mask); 568 - 559 + pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 569 560 dbg("%s: SLOTCTRL %x write cmd %x\n", 570 561 __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); 571 562 } 572 563 573 564 static void hpc_release_ctlr(struct controller *ctrl) 574 565 { 575 - if (pciehp_poll_mode) 576 - del_timer(&ctrl->poll_timer); 577 - else 578 - free_irq(ctrl->pci_dev->irq, ctrl); 566 + /* Mask Hot-plug Interrupt Enable */ 567 + if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) 568 + err("%s: Cannot mask hotplut interrupt enable\n", __func__); 569 + 570 + /* Free interrupt handler or interrupt polling timer */ 571 + pciehp_free_irq(ctrl); 579 572 580 573 /* 581 574 * If this is the last controller to be released, destroy the ··· 611 612 cmd_mask = PWR_CTRL; 612 613 /* Enable detection that we turned off at slot power-off time */ 613 614 if (!pciehp_poll_mode) { 614 - slot_cmd = slot_cmd | 615 - PWR_FAULT_DETECT_ENABLE | 616 - MRL_DETECT_ENABLE | 617 - PRSN_DETECT_ENABLE | 618 - HP_INTR_ENABLE; 619 - cmd_mask = cmd_mask | 620 - PWR_FAULT_DETECT_ENABLE | 621 - MRL_DETECT_ENABLE | 622 - PRSN_DETECT_ENABLE | 623 - HP_INTR_ENABLE; 615 + slot_cmd |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | 616 + PRSN_DETECT_ENABLE); 617 + cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | 618 + PRSN_DETECT_ENABLE); 624 619 } 625 620 626 - retval = pcie_write_cmd(slot, slot_cmd, cmd_mask); 621 + retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 627 622 628 623 if (retval) { 629 624 err("%s: Write %x command failed!\n", __func__, slot_cmd); ··· 690 697 * till the slot is powered on again. 691 698 */ 692 699 if (!pciehp_poll_mode) { 693 - slot_cmd = (slot_cmd & 694 - ~PWR_FAULT_DETECT_ENABLE & 695 - ~MRL_DETECT_ENABLE & 696 - ~PRSN_DETECT_ENABLE) | HP_INTR_ENABLE; 697 - cmd_mask = cmd_mask | 698 - PWR_FAULT_DETECT_ENABLE | 699 - MRL_DETECT_ENABLE | 700 - PRSN_DETECT_ENABLE | 701 - HP_INTR_ENABLE; 700 + slot_cmd &= ~(PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | 701 + PRSN_DETECT_ENABLE); 702 + cmd_mask |= (PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | 703 + PRSN_DETECT_ENABLE); 702 704 } 703 705 704 - retval = pcie_write_cmd(slot, slot_cmd, cmd_mask); 706 + retval = pcie_write_cmd(ctrl, slot_cmd, cmd_mask); 705 707 if (retval) { 706 708 err("%s: Write command failed!\n", __func__); 707 709 retval = -1; ··· 721 733 static irqreturn_t pcie_isr(int irq, void *dev_id) 722 734 { 723 735 struct controller *ctrl = (struct controller *)dev_id; 724 - u16 slot_status, intr_detect, intr_loc; 725 - u16 temp_word; 726 - int hp_slot = 0; /* only 1 slot per PCI Express port */ 727 - int rc = 0; 728 - unsigned long flags; 736 + u16 detected, intr_loc; 729 737 730 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 731 - if (rc) { 732 - err("%s: Cannot read SLOTSTATUS register\n", __func__); 733 - return IRQ_NONE; 734 - } 735 - 736 - intr_detect = (ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | 737 - MRL_SENS_CHANGED | PRSN_DETECT_CHANGED | CMD_COMPLETED); 738 - 739 - intr_loc = slot_status & intr_detect; 740 - 741 - /* Check to see if it was our interrupt */ 742 - if ( !intr_loc ) 743 - return IRQ_NONE; 744 - 745 - dbg("%s: intr_loc %x\n", __func__, intr_loc); 746 - /* Mask Hot-plug Interrupt Enable */ 747 - if (!pciehp_poll_mode) { 748 - spin_lock_irqsave(&ctrl->lock, flags); 749 - rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 750 - if (rc) { 751 - err("%s: Cannot read SLOT_CTRL register\n", 752 - __func__); 753 - spin_unlock_irqrestore(&ctrl->lock, flags); 738 + /* 739 + * In order to guarantee that all interrupt events are 740 + * serviced, we need to re-inspect Slot Status register after 741 + * clearing what is presumed to be the last pending interrupt. 742 + */ 743 + intr_loc = 0; 744 + do { 745 + if (pciehp_readw(ctrl, SLOTSTATUS, &detected)) { 746 + err("%s: Cannot read SLOTSTATUS\n", __func__); 754 747 return IRQ_NONE; 755 748 } 756 749 757 - dbg("%s: pciehp_readw(SLOTCTRL) with value %x\n", 758 - __func__, temp_word); 759 - temp_word = (temp_word & ~HP_INTR_ENABLE & 760 - ~CMD_CMPL_INTR_ENABLE) | 0x00; 761 - rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 762 - if (rc) { 763 - err("%s: Cannot write to SLOTCTRL register\n", 764 - __func__); 765 - spin_unlock_irqrestore(&ctrl->lock, flags); 750 + detected &= (ATTN_BUTTN_PRESSED | PWR_FAULT_DETECTED | 751 + MRL_SENS_CHANGED | PRSN_DETECT_CHANGED | 752 + CMD_COMPLETED); 753 + intr_loc |= detected; 754 + if (!intr_loc) 755 + return IRQ_NONE; 756 + if (pciehp_writew(ctrl, SLOTSTATUS, detected)) { 757 + err("%s: Cannot write to SLOTSTATUS\n", __func__); 766 758 return IRQ_NONE; 767 759 } 768 - spin_unlock_irqrestore(&ctrl->lock, flags); 760 + } while (detected); 769 761 770 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 771 - if (rc) { 772 - err("%s: Cannot read SLOT_STATUS register\n", 773 - __func__); 774 - return IRQ_NONE; 775 - } 776 - dbg("%s: pciehp_readw(SLOTSTATUS) with value %x\n", 777 - __func__, slot_status); 762 + dbg("%s: intr_loc %x\n", __FUNCTION__, intr_loc); 778 763 779 - /* Clear command complete interrupt caused by this write */ 780 - temp_word = 0x1f; 781 - rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 782 - if (rc) { 783 - err("%s: Cannot write to SLOTSTATUS register\n", 784 - __func__); 785 - return IRQ_NONE; 786 - } 787 - } 788 - 764 + /* Check Command Complete Interrupt Pending */ 789 765 if (intr_loc & CMD_COMPLETED) { 790 - /* 791 - * Command Complete Interrupt Pending 792 - */ 793 766 ctrl->cmd_busy = 0; 767 + smp_mb(); 794 768 wake_up_interruptible(&ctrl->queue); 795 769 } 796 770 771 + /* Check MRL Sensor Changed */ 797 772 if (intr_loc & MRL_SENS_CHANGED) 798 - pciehp_handle_switch_change(hp_slot, ctrl); 773 + pciehp_handle_switch_change(0, ctrl); 799 774 775 + /* Check Attention Button Pressed */ 800 776 if (intr_loc & ATTN_BUTTN_PRESSED) 801 - pciehp_handle_attention_button(hp_slot, ctrl); 777 + pciehp_handle_attention_button(0, ctrl); 802 778 779 + /* Check Presence Detect Changed */ 803 780 if (intr_loc & PRSN_DETECT_CHANGED) 804 - pciehp_handle_presence_change(hp_slot, ctrl); 781 + pciehp_handle_presence_change(0, ctrl); 805 782 783 + /* Check Power Fault Detected */ 806 784 if (intr_loc & PWR_FAULT_DETECTED) 807 - pciehp_handle_power_fault(hp_slot, ctrl); 808 - 809 - /* Clear all events after serving them */ 810 - temp_word = 0x1F; 811 - rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 812 - if (rc) { 813 - err("%s: Cannot write to SLOTSTATUS register\n", __func__); 814 - return IRQ_NONE; 815 - } 816 - /* Unmask Hot-plug Interrupt Enable */ 817 - if (!pciehp_poll_mode) { 818 - spin_lock_irqsave(&ctrl->lock, flags); 819 - rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 820 - if (rc) { 821 - err("%s: Cannot read SLOTCTRL register\n", 822 - __func__); 823 - spin_unlock_irqrestore(&ctrl->lock, flags); 824 - return IRQ_NONE; 825 - } 826 - 827 - dbg("%s: Unmask Hot-plug Interrupt Enable\n", __func__); 828 - temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; 829 - 830 - rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 831 - if (rc) { 832 - err("%s: Cannot write to SLOTCTRL register\n", 833 - __func__); 834 - spin_unlock_irqrestore(&ctrl->lock, flags); 835 - return IRQ_NONE; 836 - } 837 - spin_unlock_irqrestore(&ctrl->lock, flags); 838 - 839 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 840 - if (rc) { 841 - err("%s: Cannot read SLOT_STATUS register\n", 842 - __func__); 843 - return IRQ_NONE; 844 - } 845 - 846 - /* Clear command complete interrupt caused by this write */ 847 - temp_word = 0x1F; 848 - rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 849 - if (rc) { 850 - err("%s: Cannot write to SLOTSTATUS failed\n", 851 - __func__); 852 - return IRQ_NONE; 853 - } 854 - dbg("%s: pciehp_writew(SLOTSTATUS) with value %x\n", 855 - __func__, temp_word); 856 - } 785 + pciehp_handle_power_fault(0, ctrl); 857 786 858 787 return IRQ_HANDLED; 859 788 } ··· 957 1052 }; 958 1053 959 1054 #ifdef CONFIG_ACPI 960 - int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) 1055 + static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) 961 1056 { 962 1057 acpi_status status; 963 1058 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); ··· 1017 1112 break; 1018 1113 } 1019 1114 1020 - err("Cannot get control of hotplug hardware for pci %s\n", 1115 + dbg("Cannot get control of hotplug hardware for pci %s\n", 1021 1116 pci_name(dev)); 1022 1117 1023 1118 kfree(string.pointer); ··· 1028 1123 static int pcie_init_hardware_part1(struct controller *ctrl, 1029 1124 struct pcie_device *dev) 1030 1125 { 1031 - int rc; 1032 - u16 temp_word; 1033 - u32 slot_cap; 1034 - u16 slot_status; 1035 - 1036 - rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); 1037 - if (rc) { 1038 - err("%s: Cannot read SLOTCAP register\n", __func__); 1039 - return -1; 1040 - } 1041 - 1042 1126 /* Mask Hot-plug Interrupt Enable */ 1043 - rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1044 - if (rc) { 1045 - err("%s: Cannot read SLOTCTRL register\n", __func__); 1046 - return -1; 1047 - } 1048 - 1049 - dbg("%s: SLOTCTRL %x value read %x\n", 1050 - __func__, ctrl->cap_base + SLOTCTRL, temp_word); 1051 - temp_word = (temp_word & ~HP_INTR_ENABLE & ~CMD_CMPL_INTR_ENABLE) | 1052 - 0x00; 1053 - 1054 - rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1055 - if (rc) { 1056 - err("%s: Cannot write to SLOTCTRL register\n", __func__); 1057 - return -1; 1058 - } 1059 - 1060 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1061 - if (rc) { 1062 - err("%s: Cannot read SLOTSTATUS register\n", __func__); 1063 - return -1; 1064 - } 1065 - 1066 - temp_word = 0x1F; /* Clear all events */ 1067 - rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 1068 - if (rc) { 1069 - err("%s: Cannot write to SLOTSTATUS register\n", __func__); 1127 + if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) { 1128 + err("%s: Cannot mask hotplug interrupt enable\n", __func__); 1070 1129 return -1; 1071 1130 } 1072 1131 return 0; ··· 1038 1169 1039 1170 int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev) 1040 1171 { 1041 - int rc; 1042 - u16 temp_word; 1043 - u16 intr_enable = 0; 1044 - u32 slot_cap; 1045 - u16 slot_status; 1046 - 1047 - rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1048 - if (rc) { 1049 - err("%s: Cannot read SLOTCTRL register\n", __func__); 1050 - goto abort; 1051 - } 1052 - 1053 - intr_enable = intr_enable | PRSN_DETECT_ENABLE; 1054 - 1055 - rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); 1056 - if (rc) { 1057 - err("%s: Cannot read SLOTCAP register\n", __func__); 1058 - goto abort; 1059 - } 1060 - 1061 - if (ATTN_BUTTN(slot_cap)) 1062 - intr_enable = intr_enable | ATTN_BUTTN_ENABLE; 1063 - 1064 - if (POWER_CTRL(slot_cap)) 1065 - intr_enable = intr_enable | PWR_FAULT_DETECT_ENABLE; 1066 - 1067 - if (MRL_SENS(slot_cap)) 1068 - intr_enable = intr_enable | MRL_DETECT_ENABLE; 1069 - 1070 - temp_word = (temp_word & ~intr_enable) | intr_enable; 1071 - 1072 - if (pciehp_poll_mode) { 1073 - temp_word = (temp_word & ~HP_INTR_ENABLE) | 0x0; 1074 - } else { 1075 - temp_word = (temp_word & ~HP_INTR_ENABLE) | HP_INTR_ENABLE; 1076 - } 1172 + u16 cmd, mask; 1077 1173 1078 1174 /* 1079 - * Unmask Hot-plug Interrupt Enable for the interrupt 1080 - * notification mechanism case. 1175 + * We need to clear all events before enabling hotplug interrupt 1176 + * notification mechanism in order for hotplug controler to 1177 + * generate interrupts. 1081 1178 */ 1082 - rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1083 - if (rc) { 1084 - err("%s: Cannot write to SLOTCTRL register\n", __func__); 1179 + if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) { 1180 + err("%s: Cannot write to SLOTSTATUS register\n", __FUNCTION__); 1181 + return -1; 1182 + } 1183 + 1184 + cmd = PRSN_DETECT_ENABLE; 1185 + if (ATTN_BUTTN(ctrl)) 1186 + cmd |= ATTN_BUTTN_ENABLE; 1187 + if (POWER_CTRL(ctrl)) 1188 + cmd |= PWR_FAULT_DETECT_ENABLE; 1189 + if (MRL_SENS(ctrl)) 1190 + cmd |= MRL_DETECT_ENABLE; 1191 + if (!pciehp_poll_mode) 1192 + cmd |= HP_INTR_ENABLE; 1193 + 1194 + mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | 1195 + PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE; 1196 + 1197 + if (pcie_write_cmd(ctrl, cmd, mask)) { 1198 + err("%s: Cannot enable software notification\n", __func__); 1085 1199 goto abort; 1086 1200 } 1087 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1088 - if (rc) { 1089 - err("%s: Cannot read SLOTSTATUS register\n", __func__); 1090 - goto abort_disable_intr; 1091 - } 1092 1201 1093 - temp_word = 0x1F; /* Clear all events */ 1094 - rc = pciehp_writew(ctrl, SLOTSTATUS, temp_word); 1095 - if (rc) { 1096 - err("%s: Cannot write to SLOTSTATUS register\n", __func__); 1097 - goto abort_disable_intr; 1098 - } 1099 - 1100 - if (pciehp_force) { 1202 + if (pciehp_force) 1101 1203 dbg("Bypassing BIOS check for pciehp use on %s\n", 1102 1204 pci_name(ctrl->pci_dev)); 1103 - } else { 1104 - rc = pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev); 1105 - if (rc) 1106 - goto abort_disable_intr; 1107 - } 1205 + else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev)) 1206 + goto abort_disable_intr; 1108 1207 1109 1208 return 0; 1110 1209 1111 1210 /* We end up here for the many possible ways to fail this API. */ 1112 1211 abort_disable_intr: 1113 - rc = pciehp_readw(ctrl, SLOTCTRL, &temp_word); 1114 - if (!rc) { 1115 - temp_word &= ~(intr_enable | HP_INTR_ENABLE); 1116 - rc = pciehp_writew(ctrl, SLOTCTRL, temp_word); 1117 - } 1118 - if (rc) 1212 + if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE)) 1119 1213 err("%s : disabling interrupts failed\n", __func__); 1120 1214 abort: 1121 1215 return -1; 1122 1216 } 1123 1217 1218 + static inline void dbg_ctrl(struct controller *ctrl) 1219 + { 1220 + int i; 1221 + u16 reg16; 1222 + struct pci_dev *pdev = ctrl->pci_dev; 1223 + 1224 + if (!pciehp_debug) 1225 + return; 1226 + 1227 + dbg("Hotplug Controller:\n"); 1228 + dbg(" Seg/Bus/Dev/Func/IRQ : %s IRQ %d\n", pci_name(pdev), pdev->irq); 1229 + dbg(" Vendor ID : 0x%04x\n", pdev->vendor); 1230 + dbg(" Device ID : 0x%04x\n", pdev->device); 1231 + dbg(" Subsystem ID : 0x%04x\n", pdev->subsystem_device); 1232 + dbg(" Subsystem Vendor ID : 0x%04x\n", pdev->subsystem_vendor); 1233 + dbg(" PCIe Cap offset : 0x%02x\n", ctrl->cap_base); 1234 + for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 1235 + if (!pci_resource_len(pdev, i)) 1236 + continue; 1237 + dbg(" PCI resource [%d] : 0x%llx@0x%llx\n", i, 1238 + (unsigned long long)pci_resource_len(pdev, i), 1239 + (unsigned long long)pci_resource_start(pdev, i)); 1240 + } 1241 + dbg("Slot Capabilities : 0x%08x\n", ctrl->slot_cap); 1242 + dbg(" Physical Slot Number : %d\n", ctrl->first_slot); 1243 + dbg(" Attention Button : %3s\n", ATTN_BUTTN(ctrl) ? "yes" : "no"); 1244 + dbg(" Power Controller : %3s\n", POWER_CTRL(ctrl) ? "yes" : "no"); 1245 + dbg(" MRL Sensor : %3s\n", MRL_SENS(ctrl) ? "yes" : "no"); 1246 + dbg(" Attention Indicator : %3s\n", ATTN_LED(ctrl) ? "yes" : "no"); 1247 + dbg(" Power Indicator : %3s\n", PWR_LED(ctrl) ? "yes" : "no"); 1248 + dbg(" Hot-Plug Surprise : %3s\n", HP_SUPR_RM(ctrl) ? "yes" : "no"); 1249 + dbg(" EMI Present : %3s\n", EMI(ctrl) ? "yes" : "no"); 1250 + pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1251 + dbg("Slot Status : 0x%04x\n", reg16); 1252 + pciehp_readw(ctrl, SLOTSTATUS, &reg16); 1253 + dbg("Slot Control : 0x%04x\n", reg16); 1254 + } 1255 + 1124 1256 int pcie_init(struct controller *ctrl, struct pcie_device *dev) 1125 1257 { 1126 - int rc; 1127 - u16 cap_reg; 1128 1258 u32 slot_cap; 1129 - int cap_base; 1130 - u16 slot_status, slot_ctrl; 1131 - struct pci_dev *pdev; 1259 + struct pci_dev *pdev = dev->port; 1132 1260 1133 - pdev = dev->port; 1134 - ctrl->pci_dev = pdev; /* save pci_dev in context */ 1135 - 1136 - dbg("%s: hotplug controller vendor id 0x%x device id 0x%x\n", 1137 - __func__, pdev->vendor, pdev->device); 1138 - 1139 - cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); 1140 - if (cap_base == 0) { 1141 - dbg("%s: Can't find PCI_CAP_ID_EXP (0x10)\n", __func__); 1261 + ctrl->pci_dev = pdev; 1262 + ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); 1263 + if (!ctrl->cap_base) { 1264 + err("%s: Cannot find PCI Express capability\n", __func__); 1142 1265 goto abort; 1143 1266 } 1144 - 1145 - ctrl->cap_base = cap_base; 1146 - 1147 - dbg("%s: pcie_cap_base %x\n", __func__, cap_base); 1148 - 1149 - rc = pciehp_readw(ctrl, CAPREG, &cap_reg); 1150 - if (rc) { 1151 - err("%s: Cannot read CAPREG register\n", __func__); 1152 - goto abort; 1153 - } 1154 - dbg("%s: CAPREG offset %x cap_reg %x\n", 1155 - __func__, ctrl->cap_base + CAPREG, cap_reg); 1156 - 1157 - if (((cap_reg & SLOT_IMPL) == 0) || 1158 - (((cap_reg & DEV_PORT_TYPE) != 0x0040) 1159 - && ((cap_reg & DEV_PORT_TYPE) != 0x0060))) { 1160 - dbg("%s : This is not a root port or the port is not " 1161 - "connected to a slot\n", __func__); 1162 - goto abort; 1163 - } 1164 - 1165 - rc = pciehp_readl(ctrl, SLOTCAP, &slot_cap); 1166 - if (rc) { 1267 + if (pciehp_readl(ctrl, SLOTCAP, &slot_cap)) { 1167 1268 err("%s: Cannot read SLOTCAP register\n", __func__); 1168 1269 goto abort; 1169 1270 } 1170 - dbg("%s: SLOTCAP offset %x slot_cap %x\n", 1171 - __func__, ctrl->cap_base + SLOTCAP, slot_cap); 1172 1271 1173 - if (!(slot_cap & HP_CAP)) { 1174 - dbg("%s : This slot is not hot-plug capable\n", __func__); 1175 - goto abort; 1176 - } 1177 - /* For debugging purpose */ 1178 - rc = pciehp_readw(ctrl, SLOTSTATUS, &slot_status); 1179 - if (rc) { 1180 - err("%s: Cannot read SLOTSTATUS register\n", __func__); 1181 - goto abort; 1182 - } 1183 - dbg("%s: SLOTSTATUS offset %x slot_status %x\n", 1184 - __func__, ctrl->cap_base + SLOTSTATUS, slot_status); 1185 - 1186 - rc = pciehp_readw(ctrl, SLOTCTRL, &slot_ctrl); 1187 - if (rc) { 1188 - err("%s: Cannot read SLOTCTRL register\n", __func__); 1189 - goto abort; 1190 - } 1191 - dbg("%s: SLOTCTRL offset %x slot_ctrl %x\n", 1192 - __func__, ctrl->cap_base + SLOTCTRL, slot_ctrl); 1193 - 1194 - for (rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++) 1195 - if (pci_resource_len(pdev, rc) > 0) 1196 - dbg("pci resource[%d] start=0x%llx(len=0x%llx)\n", rc, 1197 - (unsigned long long)pci_resource_start(pdev, rc), 1198 - (unsigned long long)pci_resource_len(pdev, rc)); 1272 + ctrl->slot_cap = slot_cap; 1273 + ctrl->first_slot = slot_cap >> 19; 1274 + ctrl->slot_device_offset = 0; 1275 + ctrl->num_slots = 1; 1276 + ctrl->hpc_ops = &pciehp_hpc_ops; 1277 + mutex_init(&ctrl->crit_sect); 1278 + mutex_init(&ctrl->ctrl_lock); 1279 + init_waitqueue_head(&ctrl->queue); 1280 + dbg_ctrl(ctrl); 1199 1281 1200 1282 info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", 1201 1283 pdev->vendor, pdev->device, 1202 1284 pdev->subsystem_vendor, pdev->subsystem_device); 1203 1285 1204 - mutex_init(&ctrl->crit_sect); 1205 - mutex_init(&ctrl->ctrl_lock); 1206 - spin_lock_init(&ctrl->lock); 1207 - 1208 - /* setup wait queue */ 1209 - init_waitqueue_head(&ctrl->queue); 1210 - 1211 - /* return PCI Controller Info */ 1212 - ctrl->slot_device_offset = 0; 1213 - ctrl->num_slots = 1; 1214 - ctrl->first_slot = slot_cap >> 19; 1215 - ctrl->ctrlcap = slot_cap & 0x0000007f; 1216 - 1217 - rc = pcie_init_hardware_part1(ctrl, dev); 1218 - if (rc) 1286 + if (pcie_init_hardware_part1(ctrl, dev)) 1219 1287 goto abort; 1220 1288 1221 - if (pciehp_poll_mode) { 1222 - /* Install interrupt polling timer. Start with 10 sec delay */ 1223 - init_timer(&ctrl->poll_timer); 1224 - start_int_poll_timer(ctrl, 10); 1225 - } else { 1226 - /* Installs the interrupt handler */ 1227 - rc = request_irq(ctrl->pci_dev->irq, pcie_isr, IRQF_SHARED, 1228 - MY_NAME, (void *)ctrl); 1229 - dbg("%s: request_irq %d for hpc%d (returns %d)\n", 1230 - __func__, ctrl->pci_dev->irq, 1231 - atomic_read(&pciehp_num_controllers), rc); 1232 - if (rc) { 1233 - err("Can't get irq %d for the hotplug controller\n", 1234 - ctrl->pci_dev->irq); 1235 - goto abort; 1236 - } 1237 - } 1238 - dbg("pciehp ctrl b:d:f:irq=0x%x:%x:%x:%x\n", pdev->bus->number, 1239 - PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), dev->irq); 1289 + if (pciehp_request_irq(ctrl)) 1290 + goto abort; 1240 1291 1241 1292 /* 1242 1293 * If this is the first controller to be initialized, ··· 1165 1376 if (atomic_add_return(1, &pciehp_num_controllers) == 1) { 1166 1377 pciehp_wq = create_singlethread_workqueue("pciehpd"); 1167 1378 if (!pciehp_wq) { 1168 - rc = -ENOMEM; 1169 1379 goto abort_free_irq; 1170 1380 } 1171 1381 } 1172 1382 1173 - rc = pcie_init_hardware_part2(ctrl, dev); 1174 - if (rc == 0) { 1175 - ctrl->hpc_ops = &pciehp_hpc_ops; 1176 - return 0; 1177 - } 1383 + if (pcie_init_hardware_part2(ctrl, dev)) 1384 + goto abort_free_irq; 1385 + 1386 + return 0; 1387 + 1178 1388 abort_free_irq: 1179 - if (pciehp_poll_mode) 1180 - del_timer_sync(&ctrl->poll_timer); 1181 - else 1182 - free_irq(ctrl->pci_dev->irq, ctrl); 1389 + pciehp_free_irq(ctrl); 1183 1390 abort: 1184 1391 return -1; 1185 1392 }
+9 -2
drivers/pci/hotplug/shpchp_core.c
··· 39 39 int shpchp_debug; 40 40 int shpchp_poll_mode; 41 41 int shpchp_poll_time; 42 + int shpchp_slot_with_bus; 42 43 struct workqueue_struct *shpchp_wq; 43 44 44 45 #define DRIVER_VERSION "0.4" ··· 53 52 module_param(shpchp_debug, bool, 0644); 54 53 module_param(shpchp_poll_mode, bool, 0644); 55 54 module_param(shpchp_poll_time, int, 0644); 55 + module_param(shpchp_slot_with_bus, bool, 0644); 56 56 MODULE_PARM_DESC(shpchp_debug, "Debugging mode enabled or not"); 57 57 MODULE_PARM_DESC(shpchp_poll_mode, "Using polling mechanism for hot-plug events or not"); 58 58 MODULE_PARM_DESC(shpchp_poll_time, "Polling mechanism frequency, in seconds"); 59 + MODULE_PARM_DESC(shpchp_slot_with_bus, "Use bus number in the slot name"); 59 60 60 61 #define SHPC_MODULE_NAME "shpchp" 61 62 ··· 103 100 104 101 static void make_slot_name(struct slot *slot) 105 102 { 106 - snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 107 - slot->bus, slot->number); 103 + if (shpchp_slot_with_bus) 104 + snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", 105 + slot->bus, slot->number); 106 + else 107 + snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", 108 + slot->number); 108 109 } 109 110 110 111 static int init_slots(struct controller *ctrl)
+40 -16
drivers/pci/msi.c
··· 123 123 } 124 124 } 125 125 126 - static void msi_set_mask_bit(unsigned int irq, int flag) 126 + static void msi_set_mask_bits(unsigned int irq, u32 mask, u32 flag) 127 127 { 128 128 struct msi_desc *entry; 129 129 ··· 137 137 138 138 pos = (long)entry->mask_base; 139 139 pci_read_config_dword(entry->dev, pos, &mask_bits); 140 - mask_bits &= ~(1); 141 - mask_bits |= flag; 140 + mask_bits &= ~(mask); 141 + mask_bits |= flag & mask; 142 142 pci_write_config_dword(entry->dev, pos, mask_bits); 143 143 } else { 144 144 msi_set_enable(entry->dev, !flag); ··· 241 241 242 242 void mask_msi_irq(unsigned int irq) 243 243 { 244 - msi_set_mask_bit(irq, 1); 244 + msi_set_mask_bits(irq, 1, 1); 245 245 msix_flush_writes(irq); 246 246 } 247 247 248 248 void unmask_msi_irq(unsigned int irq) 249 249 { 250 - msi_set_mask_bit(irq, 0); 250 + msi_set_mask_bits(irq, 1, 0); 251 251 msix_flush_writes(irq); 252 252 } 253 253 ··· 291 291 msi_set_enable(dev, 0); 292 292 write_msi_msg(dev->irq, &entry->msg); 293 293 if (entry->msi_attrib.maskbit) 294 - msi_set_mask_bit(dev->irq, entry->msi_attrib.masked); 294 + msi_set_mask_bits(dev->irq, entry->msi_attrib.maskbits_mask, 295 + entry->msi_attrib.masked); 295 296 296 297 pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); 297 298 control &= ~(PCI_MSI_FLAGS_QSIZE | PCI_MSI_FLAGS_ENABLE); ··· 316 315 317 316 list_for_each_entry(entry, &dev->msi_list, list) { 318 317 write_msi_msg(entry->irq, &entry->msg); 319 - msi_set_mask_bit(entry->irq, entry->msi_attrib.masked); 318 + msi_set_mask_bits(entry->irq, 1, entry->msi_attrib.masked); 320 319 } 321 320 322 321 BUG_ON(list_empty(&dev->msi_list)); ··· 383 382 pci_write_config_dword(dev, 384 383 msi_mask_bits_reg(pos, is_64bit_address(control)), 385 384 maskbits); 385 + entry->msi_attrib.maskbits_mask = temp; 386 386 } 387 387 list_add_tail(&entry->list, &dev->msi_list); 388 388 ··· 571 569 } 572 570 EXPORT_SYMBOL(pci_enable_msi); 573 571 574 - void pci_disable_msi(struct pci_dev* dev) 572 + void pci_msi_shutdown(struct pci_dev* dev) 575 573 { 576 574 struct msi_desc *entry; 577 - int default_irq; 578 575 579 576 if (!pci_msi_enable || !dev || !dev->msi_enabled) 580 577 return; ··· 584 583 585 584 BUG_ON(list_empty(&dev->msi_list)); 586 585 entry = list_entry(dev->msi_list.next, struct msi_desc, list); 587 - if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) { 588 - return; 586 + /* Return the the pci reset with msi irqs unmasked */ 587 + if (entry->msi_attrib.maskbit) { 588 + u32 mask = entry->msi_attrib.maskbits_mask; 589 + msi_set_mask_bits(dev->irq, mask, ~mask); 589 590 } 590 - 591 - default_irq = entry->msi_attrib.default_irq; 592 - msi_free_irqs(dev); 591 + if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) 592 + return; 593 593 594 594 /* Restore dev->irq to its default pin-assertion irq */ 595 - dev->irq = default_irq; 595 + dev->irq = entry->msi_attrib.default_irq; 596 + } 597 + void pci_disable_msi(struct pci_dev* dev) 598 + { 599 + struct msi_desc *entry; 600 + 601 + if (!pci_msi_enable || !dev || !dev->msi_enabled) 602 + return; 603 + 604 + pci_msi_shutdown(dev); 605 + 606 + entry = list_entry(dev->msi_list.next, struct msi_desc, list); 607 + if (!entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) 608 + return; 609 + 610 + msi_free_irqs(dev); 596 611 } 597 612 EXPORT_SYMBOL(pci_disable_msi); 598 613 ··· 701 684 msi_free_irqs(dev); 702 685 } 703 686 704 - void pci_disable_msix(struct pci_dev* dev) 687 + void pci_msix_shutdown(struct pci_dev* dev) 705 688 { 706 689 if (!pci_msi_enable || !dev || !dev->msix_enabled) 707 690 return; ··· 709 692 msix_set_enable(dev, 0); 710 693 pci_intx_for_msi(dev, 1); 711 694 dev->msix_enabled = 0; 695 + } 696 + void pci_disable_msix(struct pci_dev* dev) 697 + { 698 + if (!pci_msi_enable || !dev || !dev->msix_enabled) 699 + return; 700 + 701 + pci_msix_shutdown(dev); 712 702 713 703 msix_free_all_irqs(dev); 714 704 }
+2
drivers/pci/pci-driver.c
··· 360 360 361 361 if (drv && drv->shutdown) 362 362 drv->shutdown(pci_dev); 363 + pci_msi_shutdown(pci_dev); 364 + pci_msix_shutdown(pci_dev); 363 365 } 364 366 365 367 /**
+1 -1
drivers/pci/pcie/Kconfig
··· 33 33 config PCIEASPM 34 34 bool "PCI Express ASPM support(Experimental)" 35 35 depends on PCI && EXPERIMENTAL && PCIEPORTBUS 36 - default y 36 + default n 37 37 help 38 38 This enables PCI Express ASPM (Active State Power Management) and 39 39 Clock Power Management. ASPM supports state L0/L0s/L1.
+1
include/linux/msi.h
··· 22 22 __u8 masked : 1; 23 23 __u8 is_64 : 1; /* Address size: 0=32bit 1=64bit */ 24 24 __u8 pos; /* Location of the msi capability */ 25 + __u32 maskbits_mask; /* mask bits mask */ 25 26 __u16 entry_nr; /* specific enabled entry */ 26 27 unsigned default_irq; /* default pre-assigned irq */ 27 28 }msi_attrib;
+8 -2
include/linux/pci.h
··· 20 20 /* Include the pci register defines */ 21 21 #include <linux/pci_regs.h> 22 22 23 - struct pci_vpd; 24 - 25 23 /* 26 24 * The PCI interface treats multi-function devices as independent 27 25 * devices. The slot/function address of each device is encoded ··· 129 131 }; 130 132 131 133 struct pcie_link_state; 134 + struct pci_vpd; 135 + 132 136 /* 133 137 * The pci_dev structure is used to describe PCI devices. 134 138 */ ··· 702 702 return -1; 703 703 } 704 704 705 + static inline void pci_msi_shutdown(struct pci_dev *dev) 706 + { } 705 707 static inline void pci_disable_msi(struct pci_dev *dev) 706 708 { } 707 709 ··· 713 711 return -1; 714 712 } 715 713 714 + static inline void pci_msix_shutdown(struct pci_dev *dev) 715 + { } 716 716 static inline void pci_disable_msix(struct pci_dev *dev) 717 717 { } 718 718 ··· 725 721 { } 726 722 #else 727 723 extern int pci_enable_msi(struct pci_dev *dev); 724 + extern void pci_msi_shutdown(struct pci_dev *dev); 728 725 extern void pci_disable_msi(struct pci_dev *dev); 729 726 extern int pci_enable_msix(struct pci_dev *dev, 730 727 struct msix_entry *entries, int nvec); 728 + extern void pci_msix_shutdown(struct pci_dev *dev); 731 729 extern void pci_disable_msix(struct pci_dev *dev); 732 730 extern void msi_remove_pci_irq_vectors(struct pci_dev *dev); 733 731 extern void pci_restore_msi_state(struct pci_dev *dev);
+2
include/linux/pci_ids.h
··· 2413 2413 #define PCI_DEVICE_ID_INTEL_82443GX_0 0x71a0 2414 2414 #define PCI_DEVICE_ID_INTEL_82443GX_2 0x71a2 2415 2415 #define PCI_DEVICE_ID_INTEL_82372FB_1 0x7601 2416 + #define PCI_DEVICE_ID_INTEL_SCH_LPC 0x8119 2417 + #define PCI_DEVICE_ID_INTEL_SCH_IDE 0x811a 2416 2418 #define PCI_DEVICE_ID_INTEL_82454GX 0x84c4 2417 2419 #define PCI_DEVICE_ID_INTEL_82450GX 0x84c5 2418 2420 #define PCI_DEVICE_ID_INTEL_82451NX 0x84ca