diff options
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r-- | drivers/pci/probe.c | 133 |
1 files changed, 43 insertions, 90 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d3db8b249729..aaaf0a1fed22 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -14,8 +14,6 @@ | |||
14 | 14 | ||
15 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ | 15 | #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ |
16 | #define CARDBUS_RESERVE_BUSNR 3 | 16 | #define CARDBUS_RESERVE_BUSNR 3 |
17 | #define PCI_CFG_SPACE_SIZE 256 | ||
18 | #define PCI_CFG_SPACE_EXP_SIZE 4096 | ||
19 | 17 | ||
20 | /* Ugh. Need to stop exporting this to modules. */ | 18 | /* Ugh. Need to stop exporting this to modules. */ |
21 | LIST_HEAD(pci_root_buses); | 19 | LIST_HEAD(pci_root_buses); |
@@ -44,72 +42,6 @@ int no_pci_devices(void) | |||
44 | } | 42 | } |
45 | EXPORT_SYMBOL(no_pci_devices); | 43 | EXPORT_SYMBOL(no_pci_devices); |
46 | 44 | ||
47 | #ifdef HAVE_PCI_LEGACY | ||
48 | /** | ||
49 | * pci_create_legacy_files - create legacy I/O port and memory files | ||
50 | * @b: bus to create files under | ||
51 | * | ||
52 | * Some platforms allow access to legacy I/O port and ISA memory space on | ||
53 | * a per-bus basis. This routine creates the files and ties them into | ||
54 | * their associated read, write and mmap files from pci-sysfs.c | ||
55 | * | ||
56 | * On error unwind, but don't propogate the error to the caller | ||
57 | * as it is ok to set up the PCI bus without these files. | ||
58 | */ | ||
59 | static void pci_create_legacy_files(struct pci_bus *b) | ||
60 | { | ||
61 | int error; | ||
62 | |||
63 | b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2, | ||
64 | GFP_ATOMIC); | ||
65 | if (!b->legacy_io) | ||
66 | goto kzalloc_err; | ||
67 | |||
68 | b->legacy_io->attr.name = "legacy_io"; | ||
69 | b->legacy_io->size = 0xffff; | ||
70 | b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; | ||
71 | b->legacy_io->read = pci_read_legacy_io; | ||
72 | b->legacy_io->write = pci_write_legacy_io; | ||
73 | error = device_create_bin_file(&b->dev, b->legacy_io); | ||
74 | if (error) | ||
75 | goto legacy_io_err; | ||
76 | |||
77 | /* Allocated above after the legacy_io struct */ | ||
78 | b->legacy_mem = b->legacy_io + 1; | ||
79 | b->legacy_mem->attr.name = "legacy_mem"; | ||
80 | b->legacy_mem->size = 1024*1024; | ||
81 | b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; | ||
82 | b->legacy_mem->mmap = pci_mmap_legacy_mem; | ||
83 | error = device_create_bin_file(&b->dev, b->legacy_mem); | ||
84 | if (error) | ||
85 | goto legacy_mem_err; | ||
86 | |||
87 | return; | ||
88 | |||
89 | legacy_mem_err: | ||
90 | device_remove_bin_file(&b->dev, b->legacy_io); | ||
91 | legacy_io_err: | ||
92 | kfree(b->legacy_io); | ||
93 | b->legacy_io = NULL; | ||
94 | kzalloc_err: | ||
95 | printk(KERN_WARNING "pci: warning: could not create legacy I/O port " | ||
96 | "and ISA memory resources to sysfs\n"); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | void pci_remove_legacy_files(struct pci_bus *b) | ||
101 | { | ||
102 | if (b->legacy_io) { | ||
103 | device_remove_bin_file(&b->dev, b->legacy_io); | ||
104 | device_remove_bin_file(&b->dev, b->legacy_mem); | ||
105 | kfree(b->legacy_io); /* both are allocated here */ | ||
106 | } | ||
107 | } | ||
108 | #else /* !HAVE_PCI_LEGACY */ | ||
109 | static inline void pci_create_legacy_files(struct pci_bus *bus) { return; } | ||
110 | void pci_remove_legacy_files(struct pci_bus *bus) { return; } | ||
111 | #endif /* HAVE_PCI_LEGACY */ | ||
112 | |||
113 | /* | 45 | /* |
114 | * PCI Bus Class Devices | 46 | * PCI Bus Class Devices |
115 | */ | 47 | */ |
@@ -219,7 +151,7 @@ static inline enum pci_bar_type decode_bar(struct resource *res, u32 bar) | |||
219 | 151 | ||
220 | res->flags = bar & ~PCI_BASE_ADDRESS_MEM_MASK; | 152 | res->flags = bar & ~PCI_BASE_ADDRESS_MEM_MASK; |
221 | 153 | ||
222 | if (res->flags == PCI_BASE_ADDRESS_MEM_TYPE_64) | 154 | if (res->flags & PCI_BASE_ADDRESS_MEM_TYPE_64) |
223 | return pci_bar_mem64; | 155 | return pci_bar_mem64; |
224 | return pci_bar_mem32; | 156 | return pci_bar_mem32; |
225 | } | 157 | } |
@@ -304,8 +236,8 @@ static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
304 | } else { | 236 | } else { |
305 | res->start = l64; | 237 | res->start = l64; |
306 | res->end = l64 + sz64; | 238 | res->end = l64 + sz64; |
307 | printk(KERN_DEBUG "PCI: %s reg %x 64bit mmio: %pR\n", | 239 | dev_printk(KERN_DEBUG, &dev->dev, |
308 | pci_name(dev), pos, res); | 240 | "reg %x 64bit mmio: %pR\n", pos, res); |
309 | } | 241 | } |
310 | } else { | 242 | } else { |
311 | sz = pci_size(l, sz, mask); | 243 | sz = pci_size(l, sz, mask); |
@@ -315,10 +247,10 @@ static int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |||
315 | 247 | ||
316 | res->start = l; | 248 | res->start = l; |
317 | res->end = l + sz; | 249 | res->end = l + sz; |
318 | printk(KERN_DEBUG "PCI: %s reg %x %s: %pR\n", | 250 | |
319 | pci_name(dev), pos, | 251 | dev_printk(KERN_DEBUG, &dev->dev, "reg %x %s: %pR\n", pos, |
320 | (res->flags & IORESOURCE_IO) ? "io port":"32bit mmio", | 252 | (res->flags & IORESOURCE_IO) ? "io port" : "32bit mmio", |
321 | res); | 253 | res); |
322 | } | 254 | } |
323 | 255 | ||
324 | out: | 256 | out: |
@@ -389,8 +321,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
389 | res->start = base; | 321 | res->start = base; |
390 | if (!res->end) | 322 | if (!res->end) |
391 | res->end = limit + 0xfff; | 323 | res->end = limit + 0xfff; |
392 | printk(KERN_DEBUG "PCI: bridge %s io port: %pR\n", | 324 | dev_printk(KERN_DEBUG, &dev->dev, "bridge io port: %pR\n", res); |
393 | pci_name(dev), res); | ||
394 | } | 325 | } |
395 | 326 | ||
396 | res = child->resource[1]; | 327 | res = child->resource[1]; |
@@ -402,8 +333,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
402 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; | 333 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; |
403 | res->start = base; | 334 | res->start = base; |
404 | res->end = limit + 0xfffff; | 335 | res->end = limit + 0xfffff; |
405 | printk(KERN_DEBUG "PCI: bridge %s 32bit mmio: %pR\n", | 336 | dev_printk(KERN_DEBUG, &dev->dev, "bridge 32bit mmio: %pR\n", |
406 | pci_name(dev), res); | 337 | res); |
407 | } | 338 | } |
408 | 339 | ||
409 | res = child->resource[2]; | 340 | res = child->resource[2]; |
@@ -439,9 +370,9 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
439 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH; | 370 | res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH; |
440 | res->start = base; | 371 | res->start = base; |
441 | res->end = limit + 0xfffff; | 372 | res->end = limit + 0xfffff; |
442 | printk(KERN_DEBUG "PCI: bridge %s %sbit mmio pref: %pR\n", | 373 | dev_printk(KERN_DEBUG, &dev->dev, "bridge %sbit mmio pref: %pR\n", |
443 | pci_name(dev), | 374 | (res->flags & PCI_PREF_RANGE_TYPE_64) ? "64" : "32", |
444 | (res->flags & PCI_PREF_RANGE_TYPE_64) ? "64":"32", res); | 375 | res); |
445 | } | 376 | } |
446 | } | 377 | } |
447 | 378 | ||
@@ -762,7 +693,7 @@ static int pci_setup_device(struct pci_dev * dev) | |||
762 | dev->class = class; | 693 | dev->class = class; |
763 | class >>= 8; | 694 | class >>= 8; |
764 | 695 | ||
765 | dev_dbg(&dev->dev, "found [%04x/%04x] class %06x header type %02x\n", | 696 | dev_dbg(&dev->dev, "found [%04x:%04x] class %06x header type %02x\n", |
766 | dev->vendor, dev->device, class, dev->hdr_type); | 697 | dev->vendor, dev->device, class, dev->hdr_type); |
767 | 698 | ||
768 | /* "Unknown power state" */ | 699 | /* "Unknown power state" */ |
@@ -844,6 +775,11 @@ static int pci_setup_device(struct pci_dev * dev) | |||
844 | return 0; | 775 | return 0; |
845 | } | 776 | } |
846 | 777 | ||
778 | static void pci_release_capabilities(struct pci_dev *dev) | ||
779 | { | ||
780 | pci_vpd_release(dev); | ||
781 | } | ||
782 | |||
847 | /** | 783 | /** |
848 | * pci_release_dev - free a pci device structure when all users of it are finished. | 784 | * pci_release_dev - free a pci device structure when all users of it are finished. |
849 | * @dev: device that's been disconnected | 785 | * @dev: device that's been disconnected |
@@ -856,7 +792,7 @@ static void pci_release_dev(struct device *dev) | |||
856 | struct pci_dev *pci_dev; | 792 | struct pci_dev *pci_dev; |
857 | 793 | ||
858 | pci_dev = to_pci_dev(dev); | 794 | pci_dev = to_pci_dev(dev); |
859 | pci_vpd_release(pci_dev); | 795 | pci_release_capabilities(pci_dev); |
860 | kfree(pci_dev); | 796 | kfree(pci_dev); |
861 | } | 797 | } |
862 | 798 | ||
@@ -887,8 +823,9 @@ static void set_pcie_port_type(struct pci_dev *pdev) | |||
887 | int pci_cfg_space_size_ext(struct pci_dev *dev) | 823 | int pci_cfg_space_size_ext(struct pci_dev *dev) |
888 | { | 824 | { |
889 | u32 status; | 825 | u32 status; |
826 | int pos = PCI_CFG_SPACE_SIZE; | ||
890 | 827 | ||
891 | if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL) | 828 | if (pci_read_config_dword(dev, pos, &status) != PCIBIOS_SUCCESSFUL) |
892 | goto fail; | 829 | goto fail; |
893 | if (status == 0xffffffff) | 830 | if (status == 0xffffffff) |
894 | goto fail; | 831 | goto fail; |
@@ -936,8 +873,6 @@ struct pci_dev *alloc_pci_dev(void) | |||
936 | 873 | ||
937 | INIT_LIST_HEAD(&dev->bus_list); | 874 | INIT_LIST_HEAD(&dev->bus_list); |
938 | 875 | ||
939 | pci_msi_init_pci_dev(dev); | ||
940 | |||
941 | return dev; | 876 | return dev; |
942 | } | 877 | } |
943 | EXPORT_SYMBOL(alloc_pci_dev); | 878 | EXPORT_SYMBOL(alloc_pci_dev); |
@@ -949,6 +884,7 @@ EXPORT_SYMBOL(alloc_pci_dev); | |||
949 | static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) | 884 | static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) |
950 | { | 885 | { |
951 | struct pci_dev *dev; | 886 | struct pci_dev *dev; |
887 | struct pci_slot *slot; | ||
952 | u32 l; | 888 | u32 l; |
953 | u8 hdr_type; | 889 | u8 hdr_type; |
954 | int delay = 1; | 890 | int delay = 1; |
@@ -997,6 +933,10 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) | |||
997 | dev->error_state = pci_channel_io_normal; | 933 | dev->error_state = pci_channel_io_normal; |
998 | set_pcie_port_type(dev); | 934 | set_pcie_port_type(dev); |
999 | 935 | ||
936 | list_for_each_entry(slot, &bus->slots, list) | ||
937 | if (PCI_SLOT(devfn) == slot->number) | ||
938 | dev->slot = slot; | ||
939 | |||
1000 | /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) | 940 | /* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer) |
1001 | set this higher, assuming the system even supports it. */ | 941 | set this higher, assuming the system even supports it. */ |
1002 | dev->dma_mask = 0xffffffff; | 942 | dev->dma_mask = 0xffffffff; |
@@ -1005,9 +945,22 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) | |||
1005 | return NULL; | 945 | return NULL; |
1006 | } | 946 | } |
1007 | 947 | ||
948 | return dev; | ||
949 | } | ||
950 | |||
951 | static void pci_init_capabilities(struct pci_dev *dev) | ||
952 | { | ||
953 | /* MSI/MSI-X list */ | ||
954 | pci_msi_init_pci_dev(dev); | ||
955 | |||
956 | /* Power Management */ | ||
957 | pci_pm_init(dev); | ||
958 | |||
959 | /* Vital Product Data */ | ||
1008 | pci_vpd_pci22_init(dev); | 960 | pci_vpd_pci22_init(dev); |
1009 | 961 | ||
1010 | return dev; | 962 | /* Alternative Routing-ID Forwarding */ |
963 | pci_enable_ari(dev); | ||
1011 | } | 964 | } |
1012 | 965 | ||
1013 | void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | 966 | void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) |
@@ -1026,8 +979,8 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | |||
1026 | /* Fix up broken headers */ | 979 | /* Fix up broken headers */ |
1027 | pci_fixup_device(pci_fixup_header, dev); | 980 | pci_fixup_device(pci_fixup_header, dev); |
1028 | 981 | ||
1029 | /* Initialize power management of the device */ | 982 | /* Initialize various capabilities */ |
1030 | pci_pm_init(dev); | 983 | pci_init_capabilities(dev); |
1031 | 984 | ||
1032 | /* | 985 | /* |
1033 | * Add the device to our list of discovered devices | 986 | * Add the device to our list of discovered devices |