summaryrefslogtreecommitdiff
path: root/drivers/pci/pci-emul-uclass.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci-emul-uclass.c')
-rw-r--r--drivers/pci/pci-emul-uclass.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c
index 79e2c1420e..3822758354 100644
--- a/drivers/pci/pci-emul-uclass.c
+++ b/drivers/pci/pci-emul-uclass.c
@@ -11,33 +11,39 @@
#include <pci.h>
#include <dm/lists.h>
-struct sandbox_pci_priv {
+struct sandbox_pci_emul_priv {
int dev_count;
};
int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
- struct udevice **emulp)
+ struct udevice **containerp, struct udevice **emulp)
{
struct udevice *dev;
int ret;
- ret = pci_bus_find_devfn(bus, find_devfn, &dev);
+ *containerp = NULL;
+ ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(find_devfn), &dev);
if (ret) {
debug("%s: Could not find emulator for dev %x\n", __func__,
find_devfn);
return ret;
}
+ *containerp = dev;
- ret = device_find_first_child(dev, emulp);
- if (ret)
- return ret;
+ if (device_get_uclass_id(dev) == UCLASS_PCI_GENERIC) {
+ ret = device_find_first_child(dev, emulp);
+ if (ret)
+ return ret;
+ } else {
+ *emulp = dev;
+ }
return *emulp ? 0 : -ENODEV;
}
static int sandbox_pci_emul_post_probe(struct udevice *dev)
{
- struct sandbox_pci_priv *priv = dev->uclass->priv;
+ struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
priv->dev_count++;
sandbox_set_enable_pci_map(true);
@@ -47,7 +53,7 @@ static int sandbox_pci_emul_post_probe(struct udevice *dev)
static int sandbox_pci_emul_pre_remove(struct udevice *dev)
{
- struct sandbox_pci_priv *priv = dev->uclass->priv;
+ struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
priv->dev_count--;
sandbox_set_enable_pci_map(priv->dev_count > 0);
@@ -60,5 +66,5 @@ UCLASS_DRIVER(pci_emul) = {
.name = "pci_emul",
.post_probe = sandbox_pci_emul_post_probe,
.pre_remove = sandbox_pci_emul_pre_remove,
- .priv_auto_alloc_size = sizeof(struct sandbox_pci_priv),
+ .priv_auto_alloc_size = sizeof(struct sandbox_pci_emul_priv),
};