Skip to content

Commit 903a3b1

Browse files
committed
Merge branch 'pci/enumeration'
- Move the PRESERVE_BOOT_CONFIG ACPI _DSM evaluation from drivers/acpi to drivers/pci so we can unify with similar DT functionality (Vidya Sagar) - Add of_pci_preserve_config() to check for a DT "linux,pci-probe-only" property on a per-host bridge basis in addition to a global basis (Vidya Sagar) - Unify ACPI PRESERVE_BOOT_CONFIG _DSM and DT "linux,pci-probe-only" in a generic pci_preserve_config() path (Vidya Sagar) * pci/enumeration: PCI: Use preserve_config in place of pci_flags PCI: Unify ACPI and DT 'preserve config' support PCI: of: Add of_pci_preserve_config() for per-host bridge support PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge()
2 parents 147ea50 + 7246a45 commit 903a3b1

File tree

6 files changed

+100
-37
lines changed

6 files changed

+100
-37
lines changed

drivers/acpi/pci_root.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,6 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
10081008
int node = acpi_get_node(device->handle);
10091009
struct pci_bus *bus;
10101010
struct pci_host_bridge *host_bridge;
1011-
union acpi_object *obj;
10121011

10131012
info->root = root;
10141013
info->bridge = device;
@@ -1050,17 +1049,6 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
10501049
if (!(root->osc_ext_control_set & OSC_CXL_ERROR_REPORTING_CONTROL))
10511050
host_bridge->native_cxl_error = 0;
10521051

1053-
/*
1054-
* Evaluate the "PCI Boot Configuration" _DSM Function. If it
1055-
* exists and returns 0, we must preserve any PCI resource
1056-
* assignments made by firmware for this host bridge.
1057-
*/
1058-
obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(bus->bridge), &pci_acpi_dsm_guid, 1,
1059-
DSM_PCI_PRESERVE_BOOT_CONFIG, NULL, ACPI_TYPE_INTEGER);
1060-
if (obj && obj->integer.value == 0)
1061-
host_bridge->preserve_config = 1;
1062-
ACPI_FREE(obj);
1063-
10641052
acpi_dev_power_up_children_with_adr(device);
10651053

10661054
pci_scan_child_bus(bus);

drivers/pci/controller/pci-host-common.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ int pci_host_common_probe(struct platform_device *pdev)
7373
if (IS_ERR(cfg))
7474
return PTR_ERR(cfg);
7575

76-
/* Do not reassign resources if probe only */
77-
if (!pci_has_flag(PCI_PROBE_ONLY))
78-
pci_add_flags(PCI_REASSIGN_ALL_BUS);
79-
8076
bridge->sysdata = cfg;
8177
bridge->ops = (struct pci_ops *)&ops->pci_ops;
8278
bridge->msi_domain = true;

drivers/pci/of.c

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,61 @@ int of_get_pci_domain_nr(struct device_node *node)
234234
EXPORT_SYMBOL_GPL(of_get_pci_domain_nr);
235235

236236
/**
237-
* of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
238-
* is present and valid
237+
* of_pci_preserve_config - Return true if the boot configuration needs to
238+
* be preserved
239+
* @node: Device tree node.
240+
*
241+
* Look for "linux,pci-probe-only" property for a given PCI controller's
242+
* node and return true if found. Also look in the chosen node if the
243+
* property is not found in the given controller's node. Having this
244+
* property ensures that the kernel doesn't reconfigure the BARs and bridge
245+
* windows that are already done by the platform firmware.
246+
*
247+
* Return: true if the property exists; false otherwise.
239248
*/
240-
void of_pci_check_probe_only(void)
249+
bool of_pci_preserve_config(struct device_node *node)
241250
{
242-
u32 val;
251+
u32 val = 0;
243252
int ret;
244253

245-
ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val);
254+
if (!node) {
255+
pr_warn("device node is NULL, trying with of_chosen\n");
256+
node = of_chosen;
257+
}
258+
259+
retry:
260+
ret = of_property_read_u32(node, "linux,pci-probe-only", &val);
246261
if (ret) {
247-
if (ret == -ENODATA || ret == -EOVERFLOW)
248-
pr_warn("linux,pci-probe-only without valid value, ignoring\n");
249-
return;
262+
if (ret == -ENODATA || ret == -EOVERFLOW) {
263+
pr_warn("Incorrect value for linux,pci-probe-only in %pOF, ignoring\n",
264+
node);
265+
return false;
266+
}
267+
if (ret == -EINVAL) {
268+
if (node == of_chosen)
269+
return false;
270+
271+
node = of_chosen;
272+
goto retry;
273+
}
250274
}
251275

252276
if (val)
277+
return true;
278+
else
279+
return false;
280+
}
281+
282+
/**
283+
* of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
284+
* is present and valid
285+
*/
286+
void of_pci_check_probe_only(void)
287+
{
288+
if (of_pci_preserve_config(of_chosen))
253289
pci_add_flags(PCI_PROBE_ONLY);
254290
else
255291
pci_clear_flags(PCI_PROBE_ONLY);
256-
257-
pr_info("PROBE_ONLY %s\n", val ? "enabled" : "disabled");
258292
}
259293
EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
260294

drivers/pci/pci-acpi.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
119119
return (phys_addr_t)mcfg_addr;
120120
}
121121

122+
bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
123+
{
124+
if (ACPI_HANDLE(&host_bridge->dev)) {
125+
union acpi_object *obj;
126+
127+
/*
128+
* Evaluate the "PCI Boot Configuration" _DSM Function. If it
129+
* exists and returns 0, we must preserve any PCI resource
130+
* assignments made by firmware for this host bridge.
131+
*/
132+
obj = acpi_evaluate_dsm_typed(ACPI_HANDLE(&host_bridge->dev),
133+
&pci_acpi_dsm_guid,
134+
1, DSM_PCI_PRESERVE_BOOT_CONFIG,
135+
NULL, ACPI_TYPE_INTEGER);
136+
if (obj && obj->integer.value == 0)
137+
return true;
138+
ACPI_FREE(obj);
139+
}
140+
141+
return false;
142+
}
143+
122144
/* _HPX PCI Setting Record (Type 0); same as _HPP */
123145
struct hpx_type0 {
124146
u32 revision; /* Not present in _HPP */

drivers/pci/pci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ int of_pci_get_max_link_speed(struct device_node *node);
648648
u32 of_pci_get_slot_power_limit(struct device_node *node,
649649
u8 *slot_power_limit_value,
650650
u8 *slot_power_limit_scale);
651+
bool of_pci_preserve_config(struct device_node *node);
651652
int pci_set_of_node(struct pci_dev *dev);
652653
void pci_release_of_node(struct pci_dev *dev);
653654
void pci_set_bus_of_node(struct pci_bus *bus);
@@ -686,6 +687,11 @@ of_pci_get_slot_power_limit(struct device_node *node,
686687
return 0;
687688
}
688689

690+
static inline bool of_pci_preserve_config(struct device_node *node)
691+
{
692+
return false;
693+
}
694+
689695
static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
690696
static inline void pci_release_of_node(struct pci_dev *dev) { }
691697
static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
@@ -732,6 +738,7 @@ static inline void pci_restore_aer_state(struct pci_dev *dev) { }
732738
#endif
733739

734740
#ifdef CONFIG_ACPI
741+
bool pci_acpi_preserve_config(struct pci_host_bridge *bridge);
735742
int pci_acpi_program_hp_params(struct pci_dev *dev);
736743
extern const struct attribute_group pci_dev_acpi_attr_group;
737744
void pci_set_acpi_fwnode(struct pci_dev *dev);
@@ -745,6 +752,10 @@ int acpi_pci_wakeup(struct pci_dev *dev, bool enable);
745752
bool acpi_pci_need_resume(struct pci_dev *dev);
746753
pci_power_t acpi_pci_choose_state(struct pci_dev *pdev);
747754
#else
755+
static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge)
756+
{
757+
return false;
758+
}
748759
static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
749760
{
750761
return -ENOTTY;

drivers/pci/probe.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,17 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus)
889889
dev_set_msi_domain(&bus->dev, d);
890890
}
891891

892+
static bool pci_preserve_config(struct pci_host_bridge *host_bridge)
893+
{
894+
if (pci_acpi_preserve_config(host_bridge))
895+
return true;
896+
897+
if (host_bridge->dev.parent && host_bridge->dev.parent->of_node)
898+
return of_pci_preserve_config(host_bridge->dev.parent->of_node);
899+
900+
return false;
901+
}
902+
892903
static int pci_register_host_bridge(struct pci_host_bridge *bridge)
893904
{
894905
struct device *parent = bridge->dev.parent;
@@ -983,6 +994,9 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
983994
if (nr_node_ids > 1 && pcibus_to_node(bus) == NUMA_NO_NODE)
984995
dev_warn(&bus->dev, "Unknown NUMA node; performance will be reduced\n");
985996

997+
/* Check if the boot configuration by FW needs to be preserved */
998+
bridge->preserve_config = pci_preserve_config(bridge);
999+
9861000
/* Coalesce contiguous windows */
9871001
resource_list_for_each_entry_safe(window, n, &resources) {
9881002
if (list_is_last(&window->node, &resources))
@@ -3080,20 +3094,18 @@ int pci_host_probe(struct pci_host_bridge *bridge)
30803094

30813095
bus = bridge->bus;
30823096

3097+
/* If we must preserve the resource configuration, claim now */
3098+
if (bridge->preserve_config)
3099+
pci_bus_claim_resources(bus);
3100+
30833101
/*
3084-
* We insert PCI resources into the iomem_resource and
3085-
* ioport_resource trees in either pci_bus_claim_resources()
3086-
* or pci_bus_assign_resources().
3102+
* Assign whatever was left unassigned. If we didn't claim above,
3103+
* this will reassign everything.
30873104
*/
3088-
if (pci_has_flag(PCI_PROBE_ONLY)) {
3089-
pci_bus_claim_resources(bus);
3090-
} else {
3091-
pci_bus_size_bridges(bus);
3092-
pci_bus_assign_resources(bus);
3105+
pci_assign_unassigned_root_bus_resources(bus);
30933106

3094-
list_for_each_entry(child, &bus->children, node)
3095-
pcie_bus_configure_settings(child);
3096-
}
3107+
list_for_each_entry(child, &bus->children, node)
3108+
pcie_bus_configure_settings(child);
30973109

30983110
pci_bus_add_devices(bus);
30993111
return 0;

0 commit comments

Comments
 (0)