Skip to content

Commit 9b70771

Browse files
committed
Merge tag 'pci-v7.0-fixes-4' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
Pull pci fixes from Bjorn Helgaas: - Create pwrctrl devices only for DT nodes below a PCI controller that describe PCI devices and are related to a power supply; this prevents waiting indefinitely for pwrctrl drivers that will never probe (Manivannan Sadhasivam) - Restore endpoint BAR mapping on subrange setup failure to make selftest reliable (Koichiro Den) * tag 'pci-v7.0-fixes-4' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci: PCI: endpoint: pci-epf-test: Roll back BAR mapping when subrange setup fails PCI/pwrctrl: Create pwrctrl devices only for PCI device nodes PCI/pwrctrl: Ensure that remote endpoint node parent has supply requirement
2 parents a1d9d8e + 2164767 commit 9b70771

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,11 @@ static void pci_epf_test_bar_subrange_setup(struct pci_epf_test *epf_test,
894894
dev_err(&epf->dev, "pci_epc_set_bar() failed: %d\n", ret);
895895
bar->submap = old_submap;
896896
bar->num_submap = old_nsub;
897+
ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no, bar);
898+
if (ret)
899+
dev_warn(&epf->dev, "Failed to restore the original BAR mapping: %d\n",
900+
ret);
901+
897902
kfree(submap);
898903
goto err;
899904
}

drivers/pci/pwrctrl/core.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,46 @@ int pci_pwrctrl_power_on_devices(struct device *parent)
268268
}
269269
EXPORT_SYMBOL_GPL(pci_pwrctrl_power_on_devices);
270270

271+
/*
272+
* Check whether the pwrctrl device really needs to be created or not. The
273+
* pwrctrl device will only be created if the node satisfies below requirements:
274+
*
275+
* 1. Presence of compatible property with "pci" prefix to match against the
276+
* pwrctrl driver (AND)
277+
* 2. At least one of the power supplies defined in the devicetree node of the
278+
* device (OR) in the remote endpoint parent node to indicate pwrctrl
279+
* requirement.
280+
*/
281+
static bool pci_pwrctrl_is_required(struct device_node *np)
282+
{
283+
struct device_node *endpoint;
284+
const char *compat;
285+
int ret;
286+
287+
ret = of_property_read_string(np, "compatible", &compat);
288+
if (ret < 0)
289+
return false;
290+
291+
if (!strstarts(compat, "pci"))
292+
return false;
293+
294+
if (of_pci_supply_present(np))
295+
return true;
296+
297+
if (of_graph_is_present(np)) {
298+
for_each_endpoint_of_node(np, endpoint) {
299+
struct device_node *remote __free(device_node) =
300+
of_graph_get_remote_port_parent(endpoint);
301+
if (remote) {
302+
if (of_pci_supply_present(remote))
303+
return true;
304+
}
305+
}
306+
}
307+
308+
return false;
309+
}
310+
271311
static int pci_pwrctrl_create_device(struct device_node *np,
272312
struct device *parent)
273313
{
@@ -287,19 +327,7 @@ static int pci_pwrctrl_create_device(struct device_node *np,
287327
return 0;
288328
}
289329

290-
/*
291-
* Sanity check to make sure that the node has the compatible property
292-
* to allow driver binding.
293-
*/
294-
if (!of_property_present(np, "compatible"))
295-
return 0;
296-
297-
/*
298-
* Check whether the pwrctrl device really needs to be created or not.
299-
* This is decided based on at least one of the power supplies defined
300-
* in the devicetree node of the device or the graph property.
301-
*/
302-
if (!of_pci_supply_present(np) && !of_graph_is_present(np)) {
330+
if (!pci_pwrctrl_is_required(np)) {
303331
dev_dbg(parent, "Skipping OF node: %s\n", np->name);
304332
return 0;
305333
}

0 commit comments

Comments
 (0)