aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/bus.c')
-rw-r--r--drivers/pci/bus.c133
1 files changed, 103 insertions, 30 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index fc1b74013743..00660cc502c5 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -98,41 +98,54 @@ void pci_bus_remove_resources(struct pci_bus *bus)
98 } 98 }
99} 99}
100 100
101/** 101static struct pci_bus_region pci_32_bit = {0, 0xffffffffULL};
102 * pci_bus_alloc_resource - allocate a resource from a parent bus 102#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
103 * @bus: PCI bus 103static struct pci_bus_region pci_64_bit = {0,
104 * @res: resource to allocate 104 (dma_addr_t) 0xffffffffffffffffULL};
105 * @size: size of resource to allocate 105static struct pci_bus_region pci_high = {(dma_addr_t) 0x100000000ULL,
106 * @align: alignment of resource to allocate 106 (dma_addr_t) 0xffffffffffffffffULL};
107 * @min: minimum /proc/iomem address to allocate 107#endif
108 * @type_mask: IORESOURCE_* type flags 108
109 * @alignf: resource alignment function 109/*
110 * @alignf_data: data argument for resource alignment function 110 * @res contains CPU addresses. Clip it so the corresponding bus addresses
111 * 111 * on @bus are entirely within @region. This is used to control the bus
112 * Given the PCI bus a device resides on, the size, minimum address, 112 * addresses of resources we allocate, e.g., we may need a resource that
113 * alignment and type, try to find an acceptable resource allocation 113 * can be mapped by a 32-bit BAR.
114 * for a specific device resource.
115 */ 114 */
116int 115static void pci_clip_resource_to_region(struct pci_bus *bus,
117pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, 116 struct resource *res,
117 struct pci_bus_region *region)
118{
119 struct pci_bus_region r;
120
121 pcibios_resource_to_bus(bus, &r, res);
122 if (r.start < region->start)
123 r.start = region->start;
124 if (r.end > region->end)
125 r.end = region->end;
126
127 if (r.end < r.start)
128 res->end = res->start - 1;
129 else
130 pcibios_bus_to_resource(bus, res, &r);
131}
132
133static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,
118 resource_size_t size, resource_size_t align, 134 resource_size_t size, resource_size_t align,
119 resource_size_t min, unsigned int type_mask, 135 resource_size_t min, unsigned int type_mask,
120 resource_size_t (*alignf)(void *, 136 resource_size_t (*alignf)(void *,
121 const struct resource *, 137 const struct resource *,
122 resource_size_t, 138 resource_size_t,
123 resource_size_t), 139 resource_size_t),
124 void *alignf_data) 140 void *alignf_data,
141 struct pci_bus_region *region)
125{ 142{
126 int i, ret = -ENOMEM; 143 int i, ret;
127 struct resource *r; 144 struct resource *r, avail;
128 resource_size_t max = -1; 145 resource_size_t max;
129 146
130 type_mask |= IORESOURCE_IO | IORESOURCE_MEM; 147 type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
131 148
132 /* don't allocate too high if the pref mem doesn't support 64bit*/
133 if (!(res->flags & IORESOURCE_MEM_64))
134 max = PCIBIOS_MAX_MEM_32;
135
136 pci_bus_for_each_resource(bus, r, i) { 149 pci_bus_for_each_resource(bus, r, i) {
137 if (!r) 150 if (!r)
138 continue; 151 continue;
@@ -147,15 +160,74 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
147 !(res->flags & IORESOURCE_PREFETCH)) 160 !(res->flags & IORESOURCE_PREFETCH))
148 continue; 161 continue;
149 162
163 avail = *r;
164 pci_clip_resource_to_region(bus, &avail, region);
165 if (!resource_size(&avail))
166 continue;
167
168 /*
169 * "min" is typically PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM to
170 * protect badly documented motherboard resources, but if
171 * this is an already-configured bridge window, its start
172 * overrides "min".
173 */
174 if (avail.start)
175 min = avail.start;
176
177 max = avail.end;
178
150 /* Ok, try it out.. */ 179 /* Ok, try it out.. */
151 ret = allocate_resource(r, res, size, 180 ret = allocate_resource(r, res, size, min, max,
152 r->start ? : min, 181 align, alignf, alignf_data);
153 max, align,
154 alignf, alignf_data);
155 if (ret == 0) 182 if (ret == 0)
156 break; 183 return 0;
157 } 184 }
158 return ret; 185 return -ENOMEM;
186}
187
188/**
189 * pci_bus_alloc_resource - allocate a resource from a parent bus
190 * @bus: PCI bus
191 * @res: resource to allocate
192 * @size: size of resource to allocate
193 * @align: alignment of resource to allocate
194 * @min: minimum /proc/iomem address to allocate
195 * @type_mask: IORESOURCE_* type flags
196 * @alignf: resource alignment function
197 * @alignf_data: data argument for resource alignment function
198 *
199 * Given the PCI bus a device resides on, the size, minimum address,
200 * alignment and type, try to find an acceptable resource allocation
201 * for a specific device resource.
202 */
203int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
204 resource_size_t size, resource_size_t align,
205 resource_size_t min, unsigned int type_mask,
206 resource_size_t (*alignf)(void *,
207 const struct resource *,
208 resource_size_t,
209 resource_size_t),
210 void *alignf_data)
211{
212#ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
213 int rc;
214
215 if (res->flags & IORESOURCE_MEM_64) {
216 rc = pci_bus_alloc_from_region(bus, res, size, align, min,
217 type_mask, alignf, alignf_data,
218 &pci_high);
219 if (rc == 0)
220 return 0;
221
222 return pci_bus_alloc_from_region(bus, res, size, align, min,
223 type_mask, alignf, alignf_data,
224 &pci_64_bit);
225 }
226#endif
227
228 return pci_bus_alloc_from_region(bus, res, size, align, min,
229 type_mask, alignf, alignf_data,
230 &pci_32_bit);
159} 231}
160 232
161void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } 233void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
@@ -176,6 +248,7 @@ int pci_bus_add_device(struct pci_dev *dev)
176 */ 248 */
177 pci_fixup_device(pci_fixup_final, dev); 249 pci_fixup_device(pci_fixup_final, dev);
178 pci_create_sysfs_dev_files(dev); 250 pci_create_sysfs_dev_files(dev);
251 pci_proc_attach_device(dev);
179 252
180 dev->match_driver = true; 253 dev->match_driver = true;
181 retval = device_attach(&dev->dev); 254 retval = device_attach(&dev->dev);