History

Merge branch 'pci/resource'

- Use ioremap(), not phys_to_virt() for platform ROM, to fix video ROM mapping with CONFIG_HIGHMEM (Mikel Rychliski) - Add support for root bus sizing so we don't have to assume host bridge windows are known a priori (Ivan Kokshaysky) - Fix alpha Nautilus PCI setup, which has been broken since we started enforcing window limits in resource allocation (Ivan Kokshaysky) * pci/resource: alpha: Fix nautilus PCI setup PCI: Add support for root bus sizing PCI: Use ioremap(), not phys_to_virt() for platform ROM

Bjorn Helgaas committed 6 years ago

Commit 86845e32 parents de71a00 5799dac7 files · +95 −88Browse files

Unified · Split

7 files
  1. arch/alpha/kernel/sys_nautilus.c +20 −32
  2. drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +18 −13
  3. drivers/gpu/drm/nouveau/nvkm/subdev/bios/shadowpci.c +15 −2
  4. drivers/gpu/drm/radeon/radeon_bios.c +19 −11
  5. drivers/pci/rom.c +0 −17
  6. drivers/pci/setup-bus.c +22 −12
  7. include/linux/pci.h +1 −1
arch/alpha/kernel/sys_nautilus.c+20−32
@@ -187,10 +187,6 @@ nautilus_machine_check(unsigned long vector, unsigned long la_ptr) · 186 unmodified lines
187187
188188 extern void pcibios_claim_one_bus(struct pci_bus *);
189189
190−static struct resource irongate_io = {
191− .name = "Irongate PCI IO",
192− .flags = IORESOURCE_IO,
193−};
194190 static struct resource irongate_mem = {
195191 .name = "Irongate PCI MEM",
196192 .flags = IORESOURCE_MEM,
@@ -208,17 +204,19 @@ nautilus_init_pci(void) · 11 unmodified lines
208204 struct pci_controller *hose = hose_head;
209205 struct pci_host_bridge *bridge;
210206 struct pci_bus *bus;
211− struct pci_dev *irongate;
212207 unsigned long bus_align, bus_size, pci_mem;
213208 unsigned long memtop = max_low_pfn << PAGE_SHIFT;
214− int ret;
215209
216210 bridge = pci_alloc_host_bridge(0);
217211 if (!bridge)
218212 return;
219213
214+ /* Use default IO. */
220215 pci_add_resource(&bridge->windows, &ioport_resource);
221− pci_add_resource(&bridge->windows, &iomem_resource);
216+ /* Irongate PCI memory aperture, calculate requred size before
217+ setting it up. */
218+ pci_add_resource(&bridge->windows, &irongate_mem);
219+
222220 pci_add_resource(&bridge->windows, &busn_resource);
223221 bridge->dev.parent = NULL;
224222 bridge->sysdata = hose;
@@ -226,59 +224,49 @@ nautilus_init_pci(void) · 1 unmodified line
226224 bridge->ops = alpha_mv.pci_ops;
227225 bridge->swizzle_irq = alpha_mv.pci_swizzle;
228226 bridge->map_irq = alpha_mv.pci_map_irq;
227+ bridge->size_windows = 1;
229228
230229 /* Scan our single hose. */
231− ret = pci_scan_root_bus_bridge(bridge);
232− if (ret) {
230+ if (pci_scan_root_bus_bridge(bridge)) {
233231 pci_free_host_bridge(bridge);
234232 return;
235233 }
236−
237234 bus = hose->bus = bridge->bus;
238235 pcibios_claim_one_bus(bus);
239236
240− irongate = pci_get_domain_bus_and_slot(pci_domain_nr(bus), 0, 0);
241− bus->self = irongate;
242− bus->resource[0] = &irongate_io;
243− bus->resource[1] = &irongate_mem;
244−
245237 pci_bus_size_bridges(bus);
246238
247− /* IO port range. */
248− bus->resource[0]->start = 0;
249− bus->resource[0]->end = 0xffff;
250−
251− /* Set up PCI memory range - limit is hardwired to 0xffffffff,
252− base must be at aligned to 16Mb. */
253− bus_align = bus->resource[1]->start;
254− bus_size = bus->resource[1]->end + 1 - bus_align;
239+ /* Now we've got the size and alignment of PCI memory resources
240+ stored in irongate_mem. Set up the PCI memory range: limit is
241+ hardwired to 0xffffffff, base must be aligned to 16Mb. */
242+ bus_align = irongate_mem.start;
243+ bus_size = irongate_mem.end + 1 - bus_align;
255244 if (bus_align < 0x1000000UL)
256245 bus_align = 0x1000000UL;
257246
258247 pci_mem = (0x100000000UL - bus_size) & -bus_align;
248+ irongate_mem.start = pci_mem;
249+ irongate_mem.end = 0xffffffffUL;
259250
260− bus->resource[1]->start = pci_mem;
261− bus->resource[1]->end = 0xffffffffUL;
262− if (request_resource(&iomem_resource, bus->resource[1]) < 0)
251+ /* Register our newly calculated PCI memory window in the resource
252+ tree. */
253+ if (request_resource(&iomem_resource, &irongate_mem) < 0)
263254 printk(KERN_ERR "Failed to request MEM on hose 0\n");
264255
256+ printk(KERN_INFO "Irongate pci_mem %pR\n", &irongate_mem);
257+
265258 if (pci_mem < memtop)
266259 memtop = pci_mem;
267260 if (memtop > alpha_mv.min_mem_address) {
268261 free_reserved_area(__va(alpha_mv.min_mem_address),
269262 __va(memtop), -1, NULL);
270− printk("nautilus_init_pci: %ldk freed\n",
263+ printk(KERN_INFO "nautilus_init_pci: %ldk freed\n",
271264 (memtop - alpha_mv.min_mem_address) >> 10);
272265 }
273−
274266 if ((IRONGATE0->dev_vendor >> 16) > 0x7006) /* Albacore? */
275267 IRONGATE0->pci_mem = pci_mem;
276268
277269 pci_bus_assign_resources(bus);
278−
279− /* pci_common_swizzle() relies on bus->self being NULL
280− for the root bus, so just clear it. */
281− bus->self = NULL;
282270 pci_bus_add_devices(bus);
283271 }
284272
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c+18−13
@@ -192,30 +192,35 @@ static bool amdgpu_read_bios_from_rom(struct amdgpu_device *adev) · 191 unmodified lines
192192
193193 static bool amdgpu_read_platform_bios(struct amdgpu_device *adev)
194194 {
195− uint8_t __iomem *bios;
196− size_t size;
195+ phys_addr_t rom = adev->pdev->rom;
196+ size_t romlen = adev->pdev->romlen;
197+ void __iomem *bios;
197198
198199 adev->bios = NULL;
199200
200− bios = pci_platform_rom(adev->pdev, &size);
201− if (!bios) {
201+ if (!rom || romlen == 0)
202202 return false;
203− }
204203
205− adev->bios = kzalloc(size, GFP_KERNEL);
206− if (adev->bios == NULL)
204+ adev->bios = kzalloc(romlen, GFP_KERNEL);
205+ if (!adev->bios)
207206 return false;
208207
209− memcpy_fromio(adev->bios, bios, size);
208+ bios = ioremap(rom, romlen);
209+ if (!bios)
210+ goto free_bios;
210211
211− if (!check_atom_bios(adev->bios, size)) {
212− kfree(adev->bios);
213− return false;
214− }
212+ memcpy_fromio(adev->bios, bios, romlen);
213+ iounmap(bios);
215214
216− adev->bios_size = size;
215+ if (!check_atom_bios(adev->bios, romlen))
216+ goto free_bios;
217+
218+ adev->bios_size = romlen;
217219
218220 return true;
221+free_bios:
222+ kfree(adev->bios);
223+ return false;
219224 }
220225
221226 #ifdef CONFIG_ACPI
drivers/gpu/drm/nouveau/nvkm/subdev/bios/shadowpci.c+15−2
@@ -101,9 +101,13 @@ platform_init(struct nvkm_bios *bios, const char *name) · 100 unmodified lines
101101 else
102102 return ERR_PTR(-ENODEV);
103103
104+ if (!pdev->rom || pdev->romlen == 0)
105+ return ERR_PTR(-ENODEV);
106+
104107 if ((priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {
108+ priv->size = pdev->romlen;
105109 if (ret = -ENODEV,
106− (priv->rom = pci_platform_rom(pdev, &priv->size)))
110+ (priv->rom = ioremap(pdev->rom, pdev->romlen)))
107111 return priv;
108112 kfree(priv);
109113 }
@@ -111,11 +115,20 @@ platform_init(struct nvkm_bios *bios, const char *name) · 1 unmodified line
111115 return ERR_PTR(ret);
112116 }
113117
118+static void
119+platform_fini(void *data)
120+{
121+ struct priv *priv = data;
122+
123+ iounmap(priv->rom);
124+ kfree(priv);
125+}
126+
114127 const struct nvbios_source
115128 nvbios_platform = {
116129 .name = "PLATFORM",
117130 .init = platform_init,
118− .fini = (void(*)(void *))kfree,
131+ .fini = platform_fini,
119132 .read = pcirom_read,
120133 .rw = true,
121134 };
drivers/gpu/drm/radeon/radeon_bios.c+19−11
@@ -108,25 +108,33 @@ static bool radeon_read_bios(struct radeon_device *rdev) · 107 unmodified lines
108108
109109 static bool radeon_read_platform_bios(struct radeon_device *rdev)
110110 {
111− uint8_t __iomem *bios;
112− size_t size;
111+ phys_addr_t rom = rdev->pdev->rom;
112+ size_t romlen = rdev->pdev->romlen;
113+ void __iomem *bios;
113114
114115 rdev->bios = NULL;
115116
116− bios = pci_platform_rom(rdev->pdev, &size);
117− if (!bios) {
117+ if (!rom || romlen == 0)
118118 return false;
119− }
120119
121− if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
120+ rdev->bios = kzalloc(romlen, GFP_KERNEL);
121+ if (!rdev->bios)
122122 return false;
123− }
124− rdev->bios = kmemdup(bios, size, GFP_KERNEL);
125− if (rdev->bios == NULL) {
126− return false;
127− }
123+
124+ bios = ioremap(rom, romlen);
125+ if (!bios)
126+ goto free_bios;
127+
128+ memcpy_fromio(rdev->bios, bios, romlen);
129+ iounmap(bios);
130+
131+ if (rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa)
132+ goto free_bios;
128133
129134 return true;
135+free_bios:
136+ kfree(rdev->bios);
137+ return false;
130138 }
131139
132140 #ifdef CONFIG_ACPI
drivers/pci/rom.c+0−17
@@ -195,20 +195,3 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom) · 194 unmodified lines
195195 pci_disable_rom(pdev);
196196 }
197197 EXPORT_SYMBOL(pci_unmap_rom);
198−
199−/**
200− * pci_platform_rom - provides a pointer to any ROM image provided by the
201− * platform
202− * @pdev: pointer to pci device struct
203− * @size: pointer to receive size of pci window over ROM
204− */
205−void __iomem *pci_platform_rom(struct pci_dev *pdev, size_t *size)
206−{
207− if (pdev->rom && pdev->romlen) {
208− *size = pdev->romlen;
209− return phys_to_virt((phys_addr_t)pdev->rom);
210− }
211−
212− return NULL;
213−}
214−EXPORT_SYMBOL(pci_platform_rom);
drivers/pci/setup-bus.c+22−12
@@ -846,7 +846,7 @@ static resource_size_t window_alignment(struct pci_bus *bus, unsigned long type) · 845 unmodified lines
846846 * Per spec, I/O windows are 4K-aligned, but some bridges have
847847 * an extension to support 1K alignment.
848848 */
849− if (bus->self->io_window_1k)
849+ if (bus->self && bus->self->io_window_1k)
850850 align = PCI_P2P_DEFAULT_IO_ALIGN_1K;
851851 else
852852 align = PCI_P2P_DEFAULT_IO_ALIGN;
@@ -920,7 +920,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, · 67 unmodified lines
920920 calculate_iosize(size, min_size, size1, add_size, children_add_size,
921921 resource_size(b_res), min_align);
922922 if (!size0 && !size1) {
923− if (b_res->start || b_res->end)
923+ if (bus->self && (b_res->start || b_res->end))
924924 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
925925 b_res, &bus->busn_res);
926926 b_res->flags = 0;
@@ -930,7 +930,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, · 3 unmodified lines
930930 b_res->start = min_align;
931931 b_res->end = b_res->start + size0 - 1;
932932 b_res->flags |= IORESOURCE_STARTALIGN;
933− if (size1 > size0 && realloc_head) {
933+ if (bus->self && size1 > size0 && realloc_head) {
934934 add_to_list(realloc_head, bus->self, b_res, size1-size0,
935935 min_align);
936936 pci_info(bus->self, "bridge window %pR to %pR add_size %llx\n",
@@ -1073,7 +1073,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, · 136 unmodified lines
10731073 calculate_memsize(size, min_size, add_size, children_add_size,
10741074 resource_size(b_res), add_align);
10751075 if (!size0 && !size1) {
1076− if (b_res->start || b_res->end)
1076+ if (bus->self && (b_res->start || b_res->end))
10771077 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
10781078 b_res, &bus->busn_res);
10791079 b_res->flags = 0;
@@ -1082,7 +1082,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, · 2 unmodified lines
10821082 b_res->start = min_align;
10831083 b_res->end = size0 + min_align - 1;
10841084 b_res->flags |= IORESOURCE_STARTALIGN;
1085− if (size1 > size0 && realloc_head) {
1085+ if (bus->self && size1 > size0 && realloc_head) {
10861086 add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align);
10871087 pci_info(bus->self, "bridge window %pR to %pR add_size %llx add_align %llx\n",
10881088 b_res, &bus->busn_res,
@@ -1196,8 +1196,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) · 107 unmodified lines
11961196 unsigned long mask, prefmask, type2 = 0, type3 = 0;
11971197 resource_size_t additional_io_size = 0, additional_mmio_size = 0,
11981198 additional_mmio_pref_size = 0;
1199− struct resource *b_res;
1200− int ret;
1199+ struct resource *pref;
1200+ struct pci_host_bridge *host;
1201+ int hdr_type, i, ret;
12011202
12021203 list_for_each_entry(dev, &bus->devices, bus_list) {
12031204 struct pci_bus *b = dev->subordinate;
@@ -1217,10 +1218,20 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) · 13 unmodified lines
12171218 }
12181219
12191220 /* The root bus? */
1220− if (pci_is_root_bus(bus))
1221− return;
1221+ if (pci_is_root_bus(bus)) {
1222+ host = to_pci_host_bridge(bus->bridge);
1223+ if (!host->size_windows)
1224+ return;
1225+ pci_bus_for_each_resource(bus, pref, i)
1226+ if (pref && (pref->flags & IORESOURCE_PREFETCH))
1227+ break;
1228+ hdr_type = -1; /* Intentionally invalid - not a PCI device. */
1229+ } else {
1230+ pref = &bus->self->resource[PCI_BRIDGE_RESOURCES + 2];
1231+ hdr_type = bus->self->hdr_type;
1232+ }
12221233
1223− switch (bus->self->hdr_type) {
1234+ switch (hdr_type) {
12241235 case PCI_HEADER_TYPE_CARDBUS:
12251236 /* Don't size CardBuses yet */
12261237 break;
@@ -1242,10 +1253,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) · 15 unmodified lines
12421253 * the size required to put all 64-bit prefetchable
12431254 * resources in it.
12441255 */
1245− b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES];
12461256 mask = IORESOURCE_MEM;
12471257 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
1248− if (b_res[2].flags & IORESOURCE_MEM_64) {
1258+ if (pref && (pref->flags & IORESOURCE_MEM_64)) {
12491259 prefmask |= IORESOURCE_MEM_64;
12501260 ret = pbus_size_mem(bus, prefmask, prefmask,
12511261 prefmask, prefmask,
include/linux/pci.h+1−1
@@ -517,6 +517,7 @@ struct pci_host_bridge { · 516 unmodified lines
517517 unsigned int native_ltr:1; /* OS may use PCIe LTR */
518518 unsigned int native_dpc:1; /* OS may use PCIe DPC */
519519 unsigned int preserve_config:1; /* Preserve FW resource setup */
520+ unsigned int size_windows:1; /* Enable root bus sizing */
520521
521522 /* Resource alignment requirements */
522523 resource_size_t (*align_resource)(struct pci_dev *dev,
@@ -1220,7 +1221,6 @@ int pci_enable_rom(struct pci_dev *pdev); · 697 unmodified lines
12201221 void pci_disable_rom(struct pci_dev *pdev);
12211222 void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
12221223 void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
1223−void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
12241224
12251225 /* Power management related routines */
12261226 int pci_save_state(struct pci_dev *dev);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t