Skip to content

Commit 73b4779

Browse files
committed
Merge branch 'pci/resource'
- Build zero-sized resources when a BAR is larger than 4G but pci_bus_addr_t or resource_size_t can't represent 64-bit addresses (Ilpo Järvinen) - Fix bridge window alignment with optional resources, where we previously lost the additional alignment requirement (Ilpo Järvinen) - Stop over-estimating bridge window size since we now assign them without any gaps between them (Ilpo Järvinen) - Increase resource MAX_IORES_LEVEL to avoid /proc/iomem flattening for nested bridges and endpoints (Ilpo Järvinen) - Remove old_size limit from bridge window sizing (Ilpo Järvinen) - Push realloc check into pbus_size_mem() to simplify callers (Ilpo Järvinen) - Pass bridge window resource to pbus_size_mem() to avoid looking it up again (Ilpo Järvinen) - Use res_to_dev_res() instead of open-coding the same search (Ilpo Järvinen) - Add pci_resource_is_bridge_win() helper (Ilpo Järvinen) - Add more logging of resource assignment (Ilpo Järvinen) - Add pbus_mem_size_optional() to handle sizes of optional resources (SR-IOV VF BARs, expansion ROMs, bridge windows) (Ilpo Järvinen) - Move CardBus code to setup-cardbus.c and only build it when CONFIG_CARDBUS is set (Ilpo Järvinen) - Use scnprintf() instead of sprintf() (Ilpo Järvinen) - Add pbus_validate_busn() for Bus Number validation (Ilpo Järvinen) - Don't claim disabled bridge windows to avoid spurious claim failures (Ilpo Järvinen) * pci/resource: PCI: Don't claim disabled bridge windows PCI: Move CardBus bridge scanning to setup-cardbus.c PCI: Add pbus_validate_busn() for Bus Number validation PCI: Add dword #defines for Bus Number + Secondary Latency Timer PCI: Use scnprintf() instead of sprintf() PCI: Handle CardBus-specific params in setup-cardbus.c PCI: Separate CardBus setup & build it only with CONFIG_CARDBUS PCI: Add 'pci' prefix to struct pci_dev_resource handling functions PCI: Use resource_assigned() in setup-bus.c algorithm resource: Mark res given to resource_assigned() as const PCI: Add pbus_mem_size_optional() to handle optional sizes PCI: Check invalid align earlier in pbus_size_mem() PCI: Log reset and restore of resources PCI: Add pci_resource_is_bridge_win() PCI: Fetch dev_res to local var in __assign_resources_sorted() PCI: Use res_to_dev_res() in reassign_resources_sorted() PCI: Pass bridge window resource to pbus_size_mem() PCI: Push realloc check into pbus_size_mem() PCI: Remove old_size limit from bridge window sizing resource: Increase MAX_IORES_LEVEL to 8 PCI: Stop over-estimating bridge window size PCI: Rewrite bridge window head alignment function PCI: Fix bridge window alignment with optional resources PCI: Use resource_set_range() that correctly sets ->end
2 parents bf37448 + 2ecc1bf commit 73b4779

13 files changed

Lines changed: 652 additions & 519 deletions

File tree

drivers/pci/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ obj-$(CONFIG_PCI_TSM) += tsm.o
3939
obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o
4040
obj-$(CONFIG_PCI_NPEM) += npem.o
4141
obj-$(CONFIG_PCIE_TPH) += tph.o
42+
obj-$(CONFIG_CARDBUS) += setup-cardbus.o
4243

4344
# Endpoint library must be initialized before its users
4445
obj-$(CONFIG_PCI_ENDPOINT) += endpoint/

drivers/pci/pci-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
181181
struct resource zerores = {};
182182

183183
/* For backwards compatibility */
184-
if (i >= PCI_BRIDGE_RESOURCES && i <= PCI_BRIDGE_RESOURCE_END &&
184+
if (pci_resource_is_bridge_win(i) &&
185185
res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
186186
res = &zerores;
187187

drivers/pci/pci.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ bool pci_reset_supported(struct pci_dev *dev)
9999
int pci_domains_supported = 1;
100100
#endif
101101

102-
#define DEFAULT_CARDBUS_IO_SIZE (256)
103-
#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
104-
/* pci=cbmemsize=nnM,cbiosize=nn can override this */
105-
unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE;
106-
unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
107-
108102
#define DEFAULT_HOTPLUG_IO_SIZE (256)
109103
#define DEFAULT_HOTPLUG_MMIO_SIZE (2*1024*1024)
110104
#define DEFAULT_HOTPLUG_MMIO_PREF_SIZE (2*1024*1024)
@@ -6639,7 +6633,9 @@ static int __init pci_setup(char *str)
66396633
if (k)
66406634
*k++ = 0;
66416635
if (*str && (str = pcibios_setup(str)) && *str) {
6642-
if (!strcmp(str, "nomsi")) {
6636+
if (!pci_setup_cardbus(str)) {
6637+
/* Function handled the parameters */
6638+
} else if (!strcmp(str, "nomsi")) {
66436639
pci_no_msi();
66446640
} else if (!strncmp(str, "noats", 5)) {
66456641
pr_info("PCIe: ATS is disabled\n");
@@ -6658,10 +6654,6 @@ static int __init pci_setup(char *str)
66586654
pcie_ari_disabled = true;
66596655
} else if (!strncmp(str, "notph", 5)) {
66606656
pci_no_tph();
6661-
} else if (!strncmp(str, "cbiosize=", 9)) {
6662-
pci_cardbus_io_size = memparse(str + 9, &str);
6663-
} else if (!strncmp(str, "cbmemsize=", 10)) {
6664-
pci_cardbus_mem_size = memparse(str + 10, &str);
66656657
} else if (!strncmp(str, "resource_alignment=", 19)) {
66666658
resource_alignment_param = str + 19;
66676659
} else if (!strncmp(str, "ecrc=", 5)) {

drivers/pci/pci.h

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ void pci_config_pm_runtime_put(struct pci_dev *dev);
245245
void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev);
246246
void pci_pm_init(struct pci_dev *dev);
247247
void pci_ea_init(struct pci_dev *dev);
248+
bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub);
248249
void pci_msi_init(struct pci_dev *dev);
249250
void pci_msix_init(struct pci_dev *dev);
250251
bool pci_bridge_d3_possible(struct pci_dev *dev);
@@ -379,8 +380,40 @@ extern unsigned long pci_hotplug_io_size;
379380
extern unsigned long pci_hotplug_mmio_size;
380381
extern unsigned long pci_hotplug_mmio_pref_size;
381382
extern unsigned long pci_hotplug_bus_size;
382-
extern unsigned long pci_cardbus_io_size;
383-
extern unsigned long pci_cardbus_mem_size;
383+
384+
static inline bool pci_is_cardbus_bridge(struct pci_dev *dev)
385+
{
386+
return dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
387+
}
388+
#ifdef CONFIG_CARDBUS
389+
unsigned long pci_cardbus_resource_alignment(struct resource *res);
390+
int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
391+
struct list_head *realloc_head);
392+
int pci_cardbus_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
393+
u32 buses, int max,
394+
unsigned int available_buses, int pass);
395+
int pci_setup_cardbus(char *str);
396+
397+
#else
398+
static inline unsigned long pci_cardbus_resource_alignment(struct resource *res)
399+
{
400+
return 0;
401+
}
402+
static inline int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
403+
struct list_head *realloc_head)
404+
{
405+
return -EOPNOTSUPP;
406+
}
407+
static inline int pci_cardbus_scan_bridge_extend(struct pci_bus *bus,
408+
struct pci_dev *dev,
409+
u32 buses, int max,
410+
unsigned int available_buses,
411+
int pass)
412+
{
413+
return max;
414+
}
415+
static inline int pci_setup_cardbus(char *str) { return -ENOENT; }
416+
#endif /* CONFIG_CARDBUS */
384417

385418
/**
386419
* pci_match_one_device - Tell if a PCI device structure has a matching
@@ -443,6 +476,10 @@ void __pci_size_stdbars(struct pci_dev *dev, int count,
443476
int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
444477
struct resource *res, unsigned int reg, u32 *sizes);
445478
void pci_configure_ari(struct pci_dev *dev);
479+
480+
int pci_dev_res_add_to_list(struct list_head *head, struct pci_dev *dev,
481+
struct resource *res, resource_size_t add_size,
482+
resource_size_t min_align);
446483
void __pci_bus_size_bridges(struct pci_bus *bus,
447484
struct list_head *realloc_head);
448485
void __pci_bus_assign_resources(const struct pci_bus *bus,
@@ -455,6 +492,11 @@ void pci_walk_bus_locked(struct pci_bus *top,
455492

456493
const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
457494
bool pci_resource_is_optional(const struct pci_dev *dev, int resno);
495+
static inline bool pci_resource_is_bridge_win(int resno)
496+
{
497+
return resno >= PCI_BRIDGE_RESOURCES &&
498+
resno <= PCI_BRIDGE_RESOURCE_END;
499+
}
458500

459501
/**
460502
* pci_resource_num - Reverse lookup resource number from device resources
@@ -478,6 +520,7 @@ static inline int pci_resource_num(const struct pci_dev *dev,
478520
return resno;
479521
}
480522

523+
void pbus_validate_busn(struct pci_bus *bus);
481524
struct resource *pbus_select_window(struct pci_bus *bus,
482525
const struct resource *res);
483526
void pci_reassigndev_resource_alignment(struct pci_dev *dev);
@@ -927,8 +970,6 @@ static inline void pci_suspend_ptm(struct pci_dev *dev) { }
927970
static inline void pci_resume_ptm(struct pci_dev *dev) { }
928971
#endif
929972

930-
unsigned long pci_cardbus_resource_alignment(struct resource *);
931-
932973
static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
933974
struct resource *res)
934975
{

drivers/pci/probe.c

Lines changed: 50 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/platform_device.h>
1515
#include <linux/pci_hotplug.h>
1616
#include <linux/slab.h>
17+
#include <linux/sprintf.h>
1718
#include <linux/module.h>
1819
#include <linux/cpumask.h>
1920
#include <linux/aer.h>
@@ -24,9 +25,6 @@
2425
#include <linux/bitfield.h>
2526
#include "pci.h"
2627

27-
#define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */
28-
#define CARDBUS_RESERVE_BUSNR 3
29-
3028
static struct resource busn_resource = {
3129
.name = "PCI busn",
3230
.start = 0,
@@ -287,8 +285,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
287285
if ((sizeof(pci_bus_addr_t) < 8 || sizeof(resource_size_t) < 8)
288286
&& sz64 > 0x100000000ULL) {
289287
res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
290-
res->start = 0;
291-
res->end = 0;
288+
resource_set_range(res, 0, 0);
292289
pci_err(dev, "%s: can't handle BAR larger than 4GB (size %#010llx)\n",
293290
res_name, (unsigned long long)sz64);
294291
goto out;
@@ -297,8 +294,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
297294
if ((sizeof(pci_bus_addr_t) < 8) && l) {
298295
/* Above 32-bit boundary; try to reallocate */
299296
res->flags |= IORESOURCE_UNSET;
300-
res->start = 0;
301-
res->end = sz64 - 1;
297+
resource_set_range(res, 0, sz64);
302298
pci_info(dev, "%s: can't handle BAR above 4GB (bus address %#010llx)\n",
303299
res_name, (unsigned long long)l64);
304300
goto out;
@@ -525,8 +521,8 @@ static void pci_read_bridge_windows(struct pci_dev *bridge)
525521

526522
pci_read_config_dword(bridge, PCI_PRIMARY_BUS, &buses);
527523
res.flags = IORESOURCE_BUS;
528-
res.start = (buses >> 8) & 0xff;
529-
res.end = (buses >> 16) & 0xff;
524+
res.start = FIELD_GET(PCI_SECONDARY_BUS_MASK, buses);
525+
res.end = FIELD_GET(PCI_SUBORDINATE_BUS_MASK, buses);
530526
pci_info(bridge, "PCI bridge to %pR%s\n", &res,
531527
bridge->transparent ? " (subtractive decode)" : "");
532528

@@ -1313,6 +1309,26 @@ static void pci_enable_rrs_sv(struct pci_dev *pdev)
13131309

13141310
static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
13151311
unsigned int available_buses);
1312+
1313+
void pbus_validate_busn(struct pci_bus *bus)
1314+
{
1315+
struct pci_bus *upstream = bus->parent;
1316+
struct pci_dev *bridge = bus->self;
1317+
1318+
/* Check that all devices are accessible */
1319+
while (upstream->parent) {
1320+
if ((bus->busn_res.end > upstream->busn_res.end) ||
1321+
(bus->number > upstream->busn_res.end) ||
1322+
(bus->number < upstream->number) ||
1323+
(bus->busn_res.end < upstream->number)) {
1324+
pci_info(bridge, "devices behind bridge are unusable because %pR cannot be assigned for them\n",
1325+
&bus->busn_res);
1326+
break;
1327+
}
1328+
upstream = upstream->parent;
1329+
}
1330+
}
1331+
13161332
/**
13171333
* pci_ea_fixed_busnrs() - Read fixed Secondary and Subordinate bus
13181334
* numbers from EA capability.
@@ -1324,7 +1340,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
13241340
* and subordinate bus numbers, return true with the bus numbers in @sec
13251341
* and @sub. Otherwise return false.
13261342
*/
1327-
static bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub)
1343+
bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub)
13281344
{
13291345
int ea, offset;
13301346
u32 dw;
@@ -1378,8 +1394,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
13781394
int pass)
13791395
{
13801396
struct pci_bus *child;
1381-
int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
1382-
u32 buses, i, j = 0;
1397+
u32 buses;
13831398
u16 bctl;
13841399
u8 primary, secondary, subordinate;
13851400
int broken = 0;
@@ -1394,9 +1409,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
13941409
pm_runtime_get_sync(&dev->dev);
13951410

13961411
pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
1397-
primary = buses & 0xFF;
1398-
secondary = (buses >> 8) & 0xFF;
1399-
subordinate = (buses >> 16) & 0xFF;
1412+
primary = FIELD_GET(PCI_PRIMARY_BUS_MASK, buses);
1413+
secondary = FIELD_GET(PCI_SECONDARY_BUS_MASK, buses);
1414+
subordinate = FIELD_GET(PCI_SUBORDINATE_BUS_MASK, buses);
14001415

14011416
pci_dbg(dev, "scanning [bus %02x-%02x] behind bridge, pass %d\n",
14021417
secondary, subordinate, pass);
@@ -1423,8 +1438,15 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
14231438
pci_write_config_word(dev, PCI_BRIDGE_CONTROL,
14241439
bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT);
14251440

1426-
if ((secondary || subordinate) && !pcibios_assign_all_busses() &&
1427-
!is_cardbus && !broken) {
1441+
if (pci_is_cardbus_bridge(dev)) {
1442+
max = pci_cardbus_scan_bridge_extend(bus, dev, buses, max,
1443+
available_buses,
1444+
pass);
1445+
goto out;
1446+
}
1447+
1448+
if ((secondary || subordinate) &&
1449+
!pcibios_assign_all_busses() && !broken) {
14281450
unsigned int cmax, buses;
14291451

14301452
/*
@@ -1466,7 +1488,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
14661488
* do in the second pass.
14671489
*/
14681490
if (!pass) {
1469-
if (pcibios_assign_all_busses() || broken || is_cardbus)
1491+
if (pcibios_assign_all_busses() || broken)
14701492

14711493
/*
14721494
* Temporarily disable forwarding of the
@@ -1477,7 +1499,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
14771499
* ranges.
14781500
*/
14791501
pci_write_config_dword(dev, PCI_PRIMARY_BUS,
1480-
buses & ~0xffffff);
1502+
buses & PCI_SEC_LATENCY_TIMER_MASK);
14811503
goto out;
14821504
}
14831505

@@ -1508,59 +1530,16 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
15081530
if (available_buses)
15091531
available_buses--;
15101532

1511-
buses = (buses & 0xff000000)
1512-
| ((unsigned int)(child->primary) << 0)
1513-
| ((unsigned int)(child->busn_res.start) << 8)
1514-
| ((unsigned int)(child->busn_res.end) << 16);
1515-
1516-
/*
1517-
* yenta.c forces a secondary latency timer of 176.
1518-
* Copy that behaviour here.
1519-
*/
1520-
if (is_cardbus) {
1521-
buses &= ~0xff000000;
1522-
buses |= CARDBUS_LATENCY_TIMER << 24;
1523-
}
1533+
buses = (buses & PCI_SEC_LATENCY_TIMER_MASK) |
1534+
FIELD_PREP(PCI_PRIMARY_BUS_MASK, child->primary) |
1535+
FIELD_PREP(PCI_SECONDARY_BUS_MASK, child->busn_res.start) |
1536+
FIELD_PREP(PCI_SUBORDINATE_BUS_MASK, child->busn_res.end);
15241537

15251538
/* We need to blast all three values with a single write */
15261539
pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses);
15271540

1528-
if (!is_cardbus) {
1529-
child->bridge_ctl = bctl;
1530-
max = pci_scan_child_bus_extend(child, available_buses);
1531-
} else {
1532-
1533-
/*
1534-
* For CardBus bridges, we leave 4 bus numbers as
1535-
* cards with a PCI-to-PCI bridge can be inserted
1536-
* later.
1537-
*/
1538-
for (i = 0; i < CARDBUS_RESERVE_BUSNR; i++) {
1539-
struct pci_bus *parent = bus;
1540-
if (pci_find_bus(pci_domain_nr(bus),
1541-
max+i+1))
1542-
break;
1543-
while (parent->parent) {
1544-
if ((!pcibios_assign_all_busses()) &&
1545-
(parent->busn_res.end > max) &&
1546-
(parent->busn_res.end <= max+i)) {
1547-
j = 1;
1548-
}
1549-
parent = parent->parent;
1550-
}
1551-
if (j) {
1552-
1553-
/*
1554-
* Often, there are two CardBus
1555-
* bridges -- try to leave one
1556-
* valid bus number for each one.
1557-
*/
1558-
i /= 2;
1559-
break;
1560-
}
1561-
}
1562-
max += i;
1563-
}
1541+
child->bridge_ctl = bctl;
1542+
max = pci_scan_child_bus_extend(child, available_buses);
15641543

15651544
/*
15661545
* Set subordinate bus number to its real value.
@@ -1572,23 +1551,10 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
15721551
pci_bus_update_busn_res_end(child, max);
15731552
pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max);
15741553
}
1554+
scnprintf(child->name, sizeof(child->name), "PCI Bus %04x:%02x",
1555+
pci_domain_nr(bus), child->number);
15751556

1576-
sprintf(child->name,
1577-
(is_cardbus ? "PCI CardBus %04x:%02x" : "PCI Bus %04x:%02x"),
1578-
pci_domain_nr(bus), child->number);
1579-
1580-
/* Check that all devices are accessible */
1581-
while (bus->parent) {
1582-
if ((child->busn_res.end > bus->busn_res.end) ||
1583-
(child->number > bus->busn_res.end) ||
1584-
(child->number < bus->number) ||
1585-
(child->busn_res.end < bus->number)) {
1586-
dev_info(&dev->dev, "devices behind bridge are unusable because %pR cannot be assigned for them\n",
1587-
&child->busn_res);
1588-
break;
1589-
}
1590-
bus = bus->parent;
1591-
}
1557+
pbus_validate_busn(child);
15921558

15931559
out:
15941560
/* Clear errors in the Secondary Status Register */

0 commit comments

Comments
 (0)