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
187 187
188extern void pcibios_claim_one_bus(struct pci_bus *);188extern void pcibios_claim_one_bus(struct pci_bus *);
189 189
190static struct resource irongate_io = {
191 .name = "Irongate PCI IO",
192 .flags = IORESOURCE_IO,
193};
194static struct resource irongate_mem = {190static struct resource irongate_mem = {
195 .name = "Irongate PCI MEM",191 .name = "Irongate PCI MEM",
196 .flags = IORESOURCE_MEM,192 .flags = IORESOURCE_MEM,
@@ -208,17 +204,19 @@ nautilus_init_pci(void) · 11 unmodified lines
208 struct pci_controller *hose = hose_head;204 struct pci_controller *hose = hose_head;
209 struct pci_host_bridge *bridge;205 struct pci_host_bridge *bridge;
210 struct pci_bus *bus;206 struct pci_bus *bus;
211 struct pci_dev *irongate;
212 unsigned long bus_align, bus_size, pci_mem;207 unsigned long bus_align, bus_size, pci_mem;
213 unsigned long memtop = max_low_pfn << PAGE_SHIFT;208 unsigned long memtop = max_low_pfn << PAGE_SHIFT;
214 int ret;
215 209
216 bridge = pci_alloc_host_bridge(0);210 bridge = pci_alloc_host_bridge(0);
217 if (!bridge)211 if (!bridge)
218 return;212 return;
219 213
214 /* Use default IO. */
220 pci_add_resource(&bridge->windows, &ioport_resource);215 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
222 pci_add_resource(&bridge->windows, &busn_resource);220 pci_add_resource(&bridge->windows, &busn_resource);
223 bridge->dev.parent = NULL;221 bridge->dev.parent = NULL;
224 bridge->sysdata = hose;222 bridge->sysdata = hose;
@@ -226,59 +224,49 @@ nautilus_init_pci(void) · 1 unmodified line
226 bridge->ops = alpha_mv.pci_ops;224 bridge->ops = alpha_mv.pci_ops;
227 bridge->swizzle_irq = alpha_mv.pci_swizzle;225 bridge->swizzle_irq = alpha_mv.pci_swizzle;
228 bridge->map_irq = alpha_mv.pci_map_irq;226 bridge->map_irq = alpha_mv.pci_map_irq;
227 bridge->size_windows = 1;
229 228
230 /* Scan our single hose. */229 /* Scan our single hose. */
231 ret = pci_scan_root_bus_bridge(bridge);230 if (pci_scan_root_bus_bridge(bridge)) {
232 if (ret) {
233 pci_free_host_bridge(bridge);231 pci_free_host_bridge(bridge);
234 return;232 return;
235 }233 }
236
237 bus = hose->bus = bridge->bus;234 bus = hose->bus = bridge->bus;
238 pcibios_claim_one_bus(bus);235 pcibios_claim_one_bus(bus);
239 236
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
245 pci_bus_size_bridges(bus);237 pci_bus_size_bridges(bus);
246 238
247 /* IO port range. */239 /* Now we've got the size and alignment of PCI memory resources
248 bus->resource[0]->start = 0;240 stored in irongate_mem. Set up the PCI memory range: limit is
249 bus->resource[0]->end = 0xffff;241 hardwired to 0xffffffff, base must be aligned to 16Mb. */
250 242 bus_align = irongate_mem.start;
251 /* Set up PCI memory range - limit is hardwired to 0xffffffff,243 bus_size = irongate_mem.end + 1 - bus_align;
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;
255 if (bus_align < 0x1000000UL)244 if (bus_align < 0x1000000UL)
256 bus_align = 0x1000000UL;245 bus_align = 0x1000000UL;
257 246
258 pci_mem = (0x100000000UL - bus_size) & -bus_align;247 pci_mem = (0x100000000UL - bus_size) & -bus_align;
248 irongate_mem.start = pci_mem;
249 irongate_mem.end = 0xffffffffUL;
259 250
260 bus->resource[1]->start = pci_mem;251 /* Register our newly calculated PCI memory window in the resource
261 bus->resource[1]->end = 0xffffffffUL;252 tree. */
262 if (request_resource(&iomem_resource, bus->resource[1]) < 0)253 if (request_resource(&iomem_resource, &irongate_mem) < 0)
263 printk(KERN_ERR "Failed to request MEM on hose 0\n");254 printk(KERN_ERR "Failed to request MEM on hose 0\n");
264 255
256 printk(KERN_INFO "Irongate pci_mem %pR\n", &irongate_mem);
257
265 if (pci_mem < memtop)258 if (pci_mem < memtop)
266 memtop = pci_mem;259 memtop = pci_mem;
267 if (memtop > alpha_mv.min_mem_address) {260 if (memtop > alpha_mv.min_mem_address) {
268 free_reserved_area(__va(alpha_mv.min_mem_address),261 free_reserved_area(__va(alpha_mv.min_mem_address),
269 __va(memtop), -1, NULL);262 __va(memtop), -1, NULL);
270 printk("nautilus_init_pci: %ldk freed\n",263 printk(KERN_INFO "nautilus_init_pci: %ldk freed\n",
271 (memtop - alpha_mv.min_mem_address) >> 10);264 (memtop - alpha_mv.min_mem_address) >> 10);
272 }265 }
273
274 if ((IRONGATE0->dev_vendor >> 16) > 0x7006) /* Albacore? */266 if ((IRONGATE0->dev_vendor >> 16) > 0x7006) /* Albacore? */
275 IRONGATE0->pci_mem = pci_mem;267 IRONGATE0->pci_mem = pci_mem;
276 268
277 pci_bus_assign_resources(bus);269 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;
282 pci_bus_add_devices(bus);270 pci_bus_add_devices(bus);
283}271}
284 272
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
192 192
193static bool amdgpu_read_platform_bios(struct amdgpu_device *adev)193static bool amdgpu_read_platform_bios(struct amdgpu_device *adev)
194{194{
195 uint8_t __iomem *bios;195 phys_addr_t rom = adev->pdev->rom;
196 size_t size;196 size_t romlen = adev->pdev->romlen;
197 void __iomem *bios;
197 198
198 adev->bios = NULL;199 adev->bios = NULL;
199 200
200 bios = pci_platform_rom(adev->pdev, &size);201 if (!rom || romlen == 0)
201 if (!bios) {
202 return false;202 return false;
203 }
204 203
205 adev->bios = kzalloc(size, GFP_KERNEL);204 adev->bios = kzalloc(romlen, GFP_KERNEL);
206 if (adev->bios == NULL)205 if (!adev->bios)
207 return false;206 return false;
208 207
209 memcpy_fromio(adev->bios, bios, size);208 bios = ioremap(rom, romlen);
209 if (!bios)
210 goto free_bios;
210 211
211 if (!check_atom_bios(adev->bios, size)) {212 memcpy_fromio(adev->bios, bios, romlen);
212 kfree(adev->bios);213 iounmap(bios);
213 return false;
214 }
215 214
216 adev->bios_size = size;215 if (!check_atom_bios(adev->bios, romlen))
216 goto free_bios;
217
218 adev->bios_size = romlen;
217 219
218 return true;220 return true;
221free_bios:
222 kfree(adev->bios);
223 return false;
219}224}
220 225
221#ifdef CONFIG_ACPI226#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
101 else101 else
102 return ERR_PTR(-ENODEV);102 return ERR_PTR(-ENODEV);
103 103
104 if (!pdev->rom || pdev->romlen == 0)
105 return ERR_PTR(-ENODEV);
106
104 if ((priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {107 if ((priv = kmalloc(sizeof(*priv), GFP_KERNEL))) {
108 priv->size = pdev->romlen;
105 if (ret = -ENODEV,109 if (ret = -ENODEV,
106 (priv->rom = pci_platform_rom(pdev, &priv->size)))110 (priv->rom = ioremap(pdev->rom, pdev->romlen)))
107 return priv;111 return priv;
108 kfree(priv);112 kfree(priv);
109 }113 }
@@ -111,11 +115,20 @@ platform_init(struct nvkm_bios *bios, const char *name) · 1 unmodified line
111 return ERR_PTR(ret);115 return ERR_PTR(ret);
112}116}
113 117
118static void
119platform_fini(void *data)
120{
121 struct priv *priv = data;
122
123 iounmap(priv->rom);
124 kfree(priv);
125}
126
114const struct nvbios_source127const struct nvbios_source
115nvbios_platform = {128nvbios_platform = {
116 .name = "PLATFORM",129 .name = "PLATFORM",
117 .init = platform_init,130 .init = platform_init,
118 .fini = (void(*)(void *))kfree,131 .fini = platform_fini,
119 .read = pcirom_read,132 .read = pcirom_read,
120 .rw = true,133 .rw = true,
121};134};
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
108 108
109static bool radeon_read_platform_bios(struct radeon_device *rdev)109static bool radeon_read_platform_bios(struct radeon_device *rdev)
110{110{
111 uint8_t __iomem *bios;111 phys_addr_t rom = rdev->pdev->rom;
112 size_t size;112 size_t romlen = rdev->pdev->romlen;
113 void __iomem *bios;
113 114
114 rdev->bios = NULL;115 rdev->bios = NULL;
115 116
116 bios = pci_platform_rom(rdev->pdev, &size);117 if (!rom || romlen == 0)
117 if (!bios) {
118 return false;118 return false;
119 }
120 119
121 if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {120 rdev->bios = kzalloc(romlen, GFP_KERNEL);
121 if (!rdev->bios)
122 return false;122 return false;
123 }123
124 rdev->bios = kmemdup(bios, size, GFP_KERNEL);124 bios = ioremap(rom, romlen);
125 if (rdev->bios == NULL) {125 if (!bios)
126 return false;126 goto free_bios;
127 }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;
128 133
129 return true;134 return true;
135free_bios:
136 kfree(rdev->bios);
137 return false;
130}138}
131 139
132#ifdef CONFIG_ACPI140#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
195 pci_disable_rom(pdev);195 pci_disable_rom(pdev);
196}196}
197EXPORT_SYMBOL(pci_unmap_rom);197EXPORT_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 */
205void __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}
214EXPORT_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
846 * Per spec, I/O windows are 4K-aligned, but some bridges have846 * Per spec, I/O windows are 4K-aligned, but some bridges have
847 * an extension to support 1K alignment.847 * an extension to support 1K alignment.
848 */848 */
849 if (bus->self->io_window_1k)849 if (bus->self && bus->self->io_window_1k)
850 align = PCI_P2P_DEFAULT_IO_ALIGN_1K;850 align = PCI_P2P_DEFAULT_IO_ALIGN_1K;
851 else851 else
852 align = PCI_P2P_DEFAULT_IO_ALIGN;852 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
920 calculate_iosize(size, min_size, size1, add_size, children_add_size,920 calculate_iosize(size, min_size, size1, add_size, children_add_size,
921 resource_size(b_res), min_align);921 resource_size(b_res), min_align);
922 if (!size0 && !size1) {922 if (!size0 && !size1) {
923 if (b_res->start || b_res->end)923 if (bus->self && (b_res->start || b_res->end))
924 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",924 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
925 b_res, &bus->busn_res);925 b_res, &bus->busn_res);
926 b_res->flags = 0;926 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
930 b_res->start = min_align;930 b_res->start = min_align;
931 b_res->end = b_res->start + size0 - 1;931 b_res->end = b_res->start + size0 - 1;
932 b_res->flags |= IORESOURCE_STARTALIGN;932 b_res->flags |= IORESOURCE_STARTALIGN;
933 if (size1 > size0 && realloc_head) {933 if (bus->self && size1 > size0 && realloc_head) {
934 add_to_list(realloc_head, bus->self, b_res, size1-size0,934 add_to_list(realloc_head, bus->self, b_res, size1-size0,
935 min_align);935 min_align);
936 pci_info(bus->self, "bridge window %pR to %pR add_size %llx\n",936 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
1073 calculate_memsize(size, min_size, add_size, children_add_size,1073 calculate_memsize(size, min_size, add_size, children_add_size,
1074 resource_size(b_res), add_align);1074 resource_size(b_res), add_align);
1075 if (!size0 && !size1) {1075 if (!size0 && !size1) {
1076 if (b_res->start || b_res->end)1076 if (bus->self && (b_res->start || b_res->end))
1077 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",1077 pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
1078 b_res, &bus->busn_res);1078 b_res, &bus->busn_res);
1079 b_res->flags = 0;1079 b_res->flags = 0;
@@ -1082,7 +1082,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, · 2 unmodified lines
1082 b_res->start = min_align;1082 b_res->start = min_align;
1083 b_res->end = size0 + min_align - 1;1083 b_res->end = size0 + min_align - 1;
1084 b_res->flags |= IORESOURCE_STARTALIGN;1084 b_res->flags |= IORESOURCE_STARTALIGN;
1085 if (size1 > size0 && realloc_head) {1085 if (bus->self && size1 > size0 && realloc_head) {
1086 add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align);1086 add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align);
1087 pci_info(bus->self, "bridge window %pR to %pR add_size %llx add_align %llx\n",1087 pci_info(bus->self, "bridge window %pR to %pR add_size %llx add_align %llx\n",
1088 b_res, &bus->busn_res,1088 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
1196 unsigned long mask, prefmask, type2 = 0, type3 = 0;1196 unsigned long mask, prefmask, type2 = 0, type3 = 0;
1197 resource_size_t additional_io_size = 0, additional_mmio_size = 0,1197 resource_size_t additional_io_size = 0, additional_mmio_size = 0,
1198 additional_mmio_pref_size = 0;1198 additional_mmio_pref_size = 0;
1199 struct resource *b_res;1199 struct resource *pref;
1200 int ret;1200 struct pci_host_bridge *host;
1201 int hdr_type, i, ret;
1201 1202
1202 list_for_each_entry(dev, &bus->devices, bus_list) {1203 list_for_each_entry(dev, &bus->devices, bus_list) {
1203 struct pci_bus *b = dev->subordinate;1204 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
1217 }1218 }
1218 1219
1219 /* The root bus? */1220 /* The root bus? */
1220 if (pci_is_root_bus(bus))1221 if (pci_is_root_bus(bus)) {
1221 return;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 }
1222 1233
1223 switch (bus->self->hdr_type) {1234 switch (hdr_type) {
1224 case PCI_HEADER_TYPE_CARDBUS:1235 case PCI_HEADER_TYPE_CARDBUS:
1225 /* Don't size CardBuses yet */1236 /* Don't size CardBuses yet */
1226 break;1237 break;
@@ -1242,10 +1253,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) · 15 unmodified lines
1242 * the size required to put all 64-bit prefetchable1253 * the size required to put all 64-bit prefetchable
1243 * resources in it.1254 * resources in it.
1244 */1255 */
1245 b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES];
1246 mask = IORESOURCE_MEM;1256 mask = IORESOURCE_MEM;
1247 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;1257 prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
1248 if (b_res[2].flags & IORESOURCE_MEM_64) {1258 if (pref && (pref->flags & IORESOURCE_MEM_64)) {
1249 prefmask |= IORESOURCE_MEM_64;1259 prefmask |= IORESOURCE_MEM_64;
1250 ret = pbus_size_mem(bus, prefmask, prefmask,1260 ret = pbus_size_mem(bus, prefmask, prefmask,
1251 prefmask, prefmask,1261 prefmask, prefmask,
include/linux/pci.h+1−1
@@ -517,6 +517,7 @@ struct pci_host_bridge { · 516 unmodified lines
517 unsigned int native_ltr:1; /* OS may use PCIe LTR */517 unsigned int native_ltr:1; /* OS may use PCIe LTR */
518 unsigned int native_dpc:1; /* OS may use PCIe DPC */518 unsigned int native_dpc:1; /* OS may use PCIe DPC */
519 unsigned int preserve_config:1; /* Preserve FW resource setup */519 unsigned int preserve_config:1; /* Preserve FW resource setup */
520 unsigned int size_windows:1; /* Enable root bus sizing */
520 521
521 /* Resource alignment requirements */522 /* Resource alignment requirements */
522 resource_size_t (*align_resource)(struct pci_dev *dev,523 resource_size_t (*align_resource)(struct pci_dev *dev,
@@ -1220,7 +1221,6 @@ int pci_enable_rom(struct pci_dev *pdev); · 697 unmodified lines
1220void pci_disable_rom(struct pci_dev *pdev);1221void pci_disable_rom(struct pci_dev *pdev);
1221void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);1222void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
1222void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);1223void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
1223void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
1224 1224
1225/* Power management related routines */1225/* Power management related routines */
1226int pci_save_state(struct pci_dev *dev);1226int 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