···30083008 int ret = 0;3009300930103010 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {30113011- id = pci_match_device (parport_pc_pci_tbl, pdev);30113011+ id = pci_match_id(parport_pc_pci_tbl, pdev);30123012 if (id == NULL || id->driver_data >= last_sio)30133013 continue;30143014
+1
drivers/pci/Makefile
···1919#2020# Some architectures use the generic PCI setup functions2121#2222+obj-$(CONFIG_X86) += setup-bus.o2223obj-$(CONFIG_ALPHA) += setup-bus.o setup-irq.o2324obj-$(CONFIG_ARM) += setup-bus.o setup-irq.o2425obj-$(CONFIG_PARISC) += setup-bus.o
···77#include <linux/module.h>88#include <linux/init.h>99#include <linux/device.h>1010-#include <linux/pci-dynids.h>1110#include "pci.h"12111312/*···1819 */19202021#ifdef CONFIG_HOTPLUG2121-/**2222- * pci_device_probe_dynamic()2323- *2424- * Walk the dynamic ID list looking for a match.2525- * returns 0 and sets pci_dev->driver when drv claims pci_dev, else error.2626- */2727-static int2828-pci_device_probe_dynamic(struct pci_driver *drv, struct pci_dev *pci_dev)2929-{3030- int error = -ENODEV;3131- struct list_head *pos;3232- struct dynid *dynid;33223434- spin_lock(&drv->dynids.lock);3535- list_for_each(pos, &drv->dynids.list) {3636- dynid = list_entry(pos, struct dynid, node);3737- if (pci_match_one_device(&dynid->id, pci_dev)) {3838- spin_unlock(&drv->dynids.lock);3939- error = drv->probe(pci_dev, &dynid->id);4040- if (error >= 0) {4141- pci_dev->driver = drv;4242- return 0;4343- }4444- return error;4545- }4646- }4747- spin_unlock(&drv->dynids.lock);4848- return error;4949-}2323+struct pci_dynid {2424+ struct list_head node;2525+ struct pci_device_id id;2626+};50275128/**5229 * store_new_id···3358static inline ssize_t3459store_new_id(struct device_driver *driver, const char *buf, size_t count)3560{3636- struct dynid *dynid;3737- struct bus_type * bus;6161+ struct pci_dynid *dynid;3862 struct pci_driver *pdrv = to_pci_driver(driver);3963 __u32 vendor=PCI_ANY_ID, device=PCI_ANY_ID, subvendor=PCI_ANY_ID,4064 subdevice=PCI_ANY_ID, class=0, class_mask=0;···6591 list_add_tail(&pdrv->dynids.list, &dynid->node);6692 spin_unlock(&pdrv->dynids.lock);67936868- bus = get_bus(pdrv->driver.bus);6969- if (bus) {7070- if (get_driver(&pdrv->driver)) {7171- down_write(&bus->subsys.rwsem);7272- driver_attach(&pdrv->driver);7373- up_write(&bus->subsys.rwsem);7474- put_driver(&pdrv->driver);7575- }7676- put_bus(bus);9494+ if (get_driver(&pdrv->driver)) {9595+ driver_attach(&pdrv->driver);9696+ put_driver(&pdrv->driver);7797 }78987999 return count;80100}8181-82101static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);8383-static inline void8484-pci_init_dynids(struct pci_dynids *dynids)8585-{8686- spin_lock_init(&dynids->lock);8787- INIT_LIST_HEAD(&dynids->list);8888-}8910290103static void91104pci_free_dynids(struct pci_driver *drv)92105{9393- struct list_head *pos, *n;9494- struct dynid *dynid;106106+ struct pci_dynid *dynid, *n;9510796108 spin_lock(&drv->dynids.lock);9797- list_for_each_safe(pos, n, &drv->dynids.list) {9898- dynid = list_entry(pos, struct dynid, node);109109+ list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {99110 list_del(&dynid->node);100111 kfree(dynid);101112 }···97138 return error;98139}99140100100-static int101101-pci_bus_match_dynids(const struct pci_dev *pci_dev, struct pci_driver *pci_drv)102102-{103103- struct list_head *pos;104104- struct dynid *dynid;105105-106106- spin_lock(&pci_drv->dynids.lock);107107- list_for_each(pos, &pci_drv->dynids.list) {108108- dynid = list_entry(pos, struct dynid, node);109109- if (pci_match_one_device(&dynid->id, pci_dev)) {110110- spin_unlock(&pci_drv->dynids.lock);111111- return 1;112112- }113113- }114114- spin_unlock(&pci_drv->dynids.lock);115115- return 0;116116-}117117-118141#else /* !CONFIG_HOTPLUG */119119-static inline int pci_device_probe_dynamic(struct pci_driver *drv, struct pci_dev *pci_dev)120120-{121121- return -ENODEV;122122-}123123-static inline void pci_init_dynids(struct pci_dynids *dynids) {}124142static inline void pci_free_dynids(struct pci_driver *drv) {}125143static inline int pci_create_newid_file(struct pci_driver *drv)126126-{127127- return 0;128128-}129129-static inline int pci_bus_match_dynids(const struct pci_dev *pci_dev, struct pci_driver *pci_drv)130144{131145 return 0;132146}133147#endif134148135149/**136136- * pci_match_device - Tell if a PCI device structure has a matching137137- * PCI device id structure150150+ * pci_match_id - See if a pci device matches a given pci_id table138151 * @ids: array of PCI device id structures to search in139139- * @dev: the PCI device structure to match against140140- * 152152+ * @dev: the PCI device structure to match against.153153+ *141154 * Used by a driver to check whether a PCI device present in the142142- * system is in its list of supported devices.Returns the matching155155+ * system is in its list of supported devices. Returns the matching143156 * pci_device_id structure or %NULL if there is no match.157157+ *158158+ * Depreciated, don't use this as it will not catch any dynamic ids159159+ * that a driver might want to check for.144160 */145145-const struct pci_device_id *146146-pci_match_device(const struct pci_device_id *ids, const struct pci_dev *dev)161161+const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,162162+ struct pci_dev *dev)147163{148148- while (ids->vendor || ids->subvendor || ids->class_mask) {149149- if (pci_match_one_device(ids, dev))150150- return ids;151151- ids++;164164+ if (ids) {165165+ while (ids->vendor || ids->subvendor || ids->class_mask) {166166+ if (pci_match_one_device(ids, dev))167167+ return ids;168168+ ids++;169169+ }152170 }153171 return NULL;154172}155173156174/**157157- * pci_device_probe_static()158158- * 159159- * returns 0 and sets pci_dev->driver when drv claims pci_dev, else error.175175+ * pci_match_device - Tell if a PCI device structure has a matching176176+ * PCI device id structure177177+ * @ids: array of PCI device id structures to search in178178+ * @dev: the PCI device structure to match against179179+ * @drv: the PCI driver to match against180180+ *181181+ * Used by a driver to check whether a PCI device present in the182182+ * system is in its list of supported devices. Returns the matching183183+ * pci_device_id structure or %NULL if there is no match.160184 */161161-static int162162-pci_device_probe_static(struct pci_driver *drv, struct pci_dev *pci_dev)163163-{ 164164- int error = -ENODEV;185185+const struct pci_device_id *pci_match_device(struct pci_driver *drv,186186+ struct pci_dev *dev)187187+{165188 const struct pci_device_id *id;189189+ struct pci_dynid *dynid;166190167167- if (!drv->id_table)168168- return error;169169- id = pci_match_device(drv->id_table, pci_dev);191191+ id = pci_match_id(drv->id_table, dev);170192 if (id)171171- error = drv->probe(pci_dev, id);172172- if (error >= 0) {173173- pci_dev->driver = drv;174174- error = 0;193193+ return id;194194+195195+ /* static ids didn't match, lets look at the dynamic ones */196196+ spin_lock(&drv->dynids.lock);197197+ list_for_each_entry(dynid, &drv->dynids.list, node) {198198+ if (pci_match_one_device(&dynid->id, dev)) {199199+ spin_unlock(&drv->dynids.lock);200200+ return &dynid->id;201201+ }175202 }176176- return error;203203+ spin_unlock(&drv->dynids.lock);204204+ return NULL;177205}178206179207/**···171225 */172226static int173227__pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)174174-{ 228228+{229229+ const struct pci_device_id *id;175230 int error = 0;176231177232 if (!pci_dev->driver && drv->probe) {178178- error = pci_device_probe_static(drv, pci_dev);179179- if (error == -ENODEV)180180- error = pci_device_probe_dynamic(drv, pci_dev);233233+ error = -ENODEV;234234+235235+ id = pci_match_device(drv, pci_dev);236236+ if (id)237237+ error = drv->probe(pci_dev, id);238238+ if (error >= 0) {239239+ pci_dev->driver = drv;240240+ error = 0;241241+ }181242 }182243 return error;183244}···324371 .sysfs_ops = &pci_driver_sysfs_ops,325372};326373327327-static int328328-pci_populate_driver_dir(struct pci_driver *drv)329329-{330330- return pci_create_newid_file(drv);331331-}332332-333374/**334375 * pci_register_driver - register a new pci driver335376 * @drv: the driver structure to register···348401 drv->driver.shutdown = pci_device_shutdown;349402 drv->driver.owner = drv->owner;350403 drv->driver.kobj.ktype = &pci_driver_kobj_type;351351- pci_init_dynids(&drv->dynids);404404+405405+ spin_lock_init(&drv->dynids.lock);406406+ INIT_LIST_HEAD(&drv->dynids.list);352407353408 /* register with core */354409 error = driver_register(&drv->driver);355410356411 if (!error)357357- pci_populate_driver_dir(drv);412412+ error = pci_create_newid_file(drv);358413359414 return error;360415}···412463 * system is in its list of supported devices.Returns the matching413464 * pci_device_id structure or %NULL if there is no match.414465 */415415-static int pci_bus_match(struct device * dev, struct device_driver * drv) 466466+static int pci_bus_match(struct device *dev, struct device_driver *drv)416467{417417- const struct pci_dev * pci_dev = to_pci_dev(dev);418418- struct pci_driver * pci_drv = to_pci_driver(drv);419419- const struct pci_device_id * ids = pci_drv->id_table;468468+ struct pci_dev *pci_dev = to_pci_dev(dev);469469+ struct pci_driver *pci_drv = to_pci_driver(drv);420470 const struct pci_device_id *found_id;421471422422- if (!ids)423423- return 0;424424-425425- found_id = pci_match_device(ids, pci_dev);472472+ found_id = pci_match_device(pci_drv, pci_dev);426473 if (found_id)427474 return 1;428475429429- return pci_bus_match_dynids(pci_dev, pci_drv);476476+ return 0;430477}431478432479/**···481536482537postcore_initcall(pci_driver_init);483538539539+EXPORT_SYMBOL(pci_match_id);484540EXPORT_SYMBOL(pci_match_device);485541EXPORT_SYMBOL(pci_register_driver);486542EXPORT_SYMBOL(pci_unregister_driver);
-6
drivers/pci/pci.c
···334334/**335335 * pci_save_state - save the PCI configuration space of a device before suspending336336 * @dev: - PCI device that we're dealing with337337- * @buffer: - buffer to hold config space context338338- *339339- * @buffer must be large enough to hold the entire PCI 2.2 config space 340340- * (>= 64 bytes).341337 */342338int343339pci_save_state(struct pci_dev *dev)···348352/** 349353 * pci_restore_state - Restore the saved state of a PCI device350354 * @dev: - PCI device that we're dealing with351351- * @buffer: - saved PCI config space352352- *353355 */354356int 355357pci_restore_state(struct pci_dev *dev)
+5
drivers/pci/pcie/portdrv.h
···27272828#define get_descriptor_id(type, service) (((type - 4) << 4) | service)29293030+struct pcie_port_device_ext {3131+ int interrupt_mode; /* [0:INTx | 1:MSI | 2:MSI-X] */3232+ unsigned int saved_msi_config_space[5];3333+};3434+3035extern struct bus_type pcie_port_bus_type;3136extern int pcie_port_device_probe(struct pci_dev *dev);3237extern int pcie_port_device_register(struct pci_dev *dev);
+8
drivers/pci/pcie/portdrv_core.c
···275275276276int pcie_port_device_register(struct pci_dev *dev)277277{278278+ struct pcie_port_device_ext *p_ext;278279 int status, type, capabilities, irq_mode, i;279280 int vectors[PCIE_PORT_DEVICE_MAXSERVICES];280281 u16 reg16;282282+283283+ /* Allocate port device extension */284284+ if (!(p_ext = kmalloc(sizeof(struct pcie_port_device_ext), GFP_KERNEL)))285285+ return -ENOMEM;286286+287287+ pci_set_drvdata(dev, p_ext);281288282289 /* Get port type */283290 pci_read_config_word(dev,···295288 /* Now get port services */296289 capabilities = get_port_device_capability(dev);297290 irq_mode = assign_interrupt_mode(dev, vectors, capabilities);291291+ p_ext->interrupt_mode = irq_mode;298292299293 /* Allocate child services if any */300294 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) {
+78-1
drivers/pci/pcie/portdrv_pci.c
···2929/* global data */3030static const char device_name[] = "pcieport-driver";31313232+static void pci_save_msi_state(struct pci_dev *dev)3333+{3434+ struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);3535+ int i = 0, pos;3636+ u16 control;3737+3838+ if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)3939+ return;4040+4141+ pci_read_config_dword(dev, pos, &p_ext->saved_msi_config_space[i++]);4242+ control = p_ext->saved_msi_config_space[0] >> 16;4343+ pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,4444+ &p_ext->saved_msi_config_space[i++]);4545+ if (control & PCI_MSI_FLAGS_64BIT) {4646+ pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,4747+ &p_ext->saved_msi_config_space[i++]);4848+ pci_read_config_dword(dev, pos + PCI_MSI_DATA_64,4949+ &p_ext->saved_msi_config_space[i++]);5050+ } else5151+ pci_read_config_dword(dev, pos + PCI_MSI_DATA_32,5252+ &p_ext->saved_msi_config_space[i++]);5353+ if (control & PCI_MSI_FLAGS_MASKBIT)5454+ pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT,5555+ &p_ext->saved_msi_config_space[i++]);5656+}5757+5858+static void pci_restore_msi_state(struct pci_dev *dev)5959+{6060+ struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);6161+ int i = 0, pos;6262+ u16 control;6363+6464+ if ((pos = pci_find_capability(dev, PCI_CAP_ID_MSI)) <= 0)6565+ return;6666+6767+ control = p_ext->saved_msi_config_space[i++] >> 16;6868+ pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);6969+ pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,7070+ p_ext->saved_msi_config_space[i++]);7171+ if (control & PCI_MSI_FLAGS_64BIT) {7272+ pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,7373+ p_ext->saved_msi_config_space[i++]);7474+ pci_write_config_dword(dev, pos + PCI_MSI_DATA_64,7575+ p_ext->saved_msi_config_space[i++]);7676+ } else7777+ pci_write_config_dword(dev, pos + PCI_MSI_DATA_32,7878+ p_ext->saved_msi_config_space[i++]);7979+ if (control & PCI_MSI_FLAGS_MASKBIT)8080+ pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT,8181+ p_ext->saved_msi_config_space[i++]);8282+}8383+8484+static void pcie_portdrv_save_config(struct pci_dev *dev)8585+{8686+ struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);8787+8888+ pci_save_state(dev);8989+ if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)9090+ pci_save_msi_state(dev);9191+}9292+9393+static void pcie_portdrv_restore_config(struct pci_dev *dev)9494+{9595+ struct pcie_port_device_ext *p_ext = pci_get_drvdata(dev);9696+9797+ pci_restore_state(dev);9898+ if (p_ext->interrupt_mode == PCIE_PORT_MSI_MODE)9999+ pci_restore_msi_state(dev);100100+ pci_enable_device(dev);101101+ pci_set_master(dev);102102+}103103+32104/*33105 * pcie_portdrv_probe - Probe PCI-Express port devices34106 * @dev: PCI-Express port device being probed···13664static void pcie_portdrv_remove (struct pci_dev *dev)13765{13866 pcie_port_device_remove(dev);6767+ kfree(pci_get_drvdata(dev));13968}1406914170#ifdef CONFIG_PM14271static int pcie_portdrv_suspend (struct pci_dev *dev, pm_message_t state)14372{144144- return pcie_port_device_suspend(dev, state);7373+ int ret = pcie_port_device_suspend(dev, state);7474+7575+ pcie_portdrv_save_config(dev);7676+ return ret;14577}1467814779static int pcie_portdrv_resume (struct pci_dev *dev)14880{8181+ pcie_portdrv_restore_config(dev);14982 return pcie_port_device_resume(dev);15083}15184#endif
+20-4
drivers/pci/probe.c
···239239240240 if (dev->transparent) {241241 printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev));242242- for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++)243243- child->resource[i] = child->parent->resource[i];244244- return;242242+ for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)243243+ child->resource[i] = child->parent->resource[i - 3];245244 }246245247246 for(i=0; i<3; i++)···397398 pci_write_config_word(dev, rpcap + PCI_EXP_RTCTL, rpctl);398399}399400401401+static void __devinit pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max)402402+{403403+ struct pci_bus *parent = child->parent;404404+ while (parent->parent && parent->subordinate < max) {405405+ parent->subordinate = max;406406+ pci_write_config_byte(parent->self, PCI_SUBORDINATE_BUS, max);407407+ parent = parent->parent;408408+ }409409+}410410+400411unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus);401412402413/*···508499509500 if (!is_cardbus) {510501 child->bridge_ctl = PCI_BRIDGE_CTL_NO_ISA;511511-502502+ /*503503+ * Adjust subordinate busnr in parent buses.504504+ * We do this before scanning for children because505505+ * some devices may not be detected if the bios506506+ * was lazy.507507+ */508508+ pci_fixup_parent_subordinate_busnr(child, max);512509 /* Now we can scan all subordinate buses... */513510 max = pci_scan_child_bus(child);514511 } else {···528513 max+i+1))529514 break;530515 max += i;516516+ pci_fixup_parent_subordinate_busnr(child, max);531517 }532518 /*533519 * Set the subordinate bus number to its real value.
+1
drivers/pci/quirks.c
···767767 if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {768768 if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB)769769 switch(dev->subsystem_device) {770770+ case 0x8025: /* P4B-LX */770771 case 0x8070: /* P4B */771772 case 0x8088: /* P4B533 */772773 case 0x1626: /* L3C notebook */
+2
drivers/pci/setup-bus.c
···273273274274 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {275275 r = bus->resource[i];276276+ if (r == &ioport_resource || r == &iomem_resource)277277+ continue;276278 if (r && (r->flags & type_mask) == type && !r->parent)277279 return r;278280 }
-18
include/linux/pci-dynids.h
···11-/*22- * PCI defines and function prototypes33- * Copyright 2003 Dell Inc.44- * by Matt Domsch <Matt_Domsch@dell.com>55- */66-77-#ifndef LINUX_PCI_DYNIDS_H88-#define LINUX_PCI_DYNIDS_H99-1010-#include <linux/list.h>1111-#include <linux/mod_devicetable.h>1212-1313-struct dynid {1414- struct list_head node;1515- struct pci_device_id id;1616-};1717-1818-#endif
+3-2
include/linux/pci.h
···586586#define PCI_NUM_RESOURCES 11587587588588#ifndef PCI_BUS_NUM_RESOURCES589589-#define PCI_BUS_NUM_RESOURCES 4589589+#define PCI_BUS_NUM_RESOURCES 8590590#endif591591592592#define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */···860860void pci_unregister_driver(struct pci_driver *);861861void pci_remove_behind_bridge(struct pci_dev *);862862struct pci_driver *pci_dev_driver(const struct pci_dev *);863863-const struct pci_device_id *pci_match_device(const struct pci_device_id *ids, const struct pci_dev *dev);863863+const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev);864864+const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, struct pci_dev *dev);864865int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass);865866866867/* kmem_cache style wrapper around pci_alloc_consistent() */
+1-1
sound/pci/bt87x.c
···804804 int i;805805 const struct pci_device_id *supported;806806807807- supported = pci_match_device(snd_bt87x_ids, pci);807807+ supported = pci_match_device(driver, pci);808808 if (supported)809809 return supported->driver_data;810810