2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/libfdt.h>
15 struct sandbox_pci_priv {
19 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
20 struct udevice **emulp)
25 ret = pci_bus_find_devfn(bus, find_devfn, &dev);
27 debug("%s: Could not find emulator for dev %x\n", __func__,
32 ret = device_find_first_child(dev, emulp);
36 return *emulp ? 0 : -ENODEV;
39 static int sandbox_pci_emul_post_probe(struct udevice *dev)
41 struct sandbox_pci_priv *priv = dev->uclass->priv;
44 sandbox_set_enable_pci_map(true);
49 static int sandbox_pci_emul_pre_remove(struct udevice *dev)
51 struct sandbox_pci_priv *priv = dev->uclass->priv;
54 sandbox_set_enable_pci_map(priv->dev_count > 0);
59 UCLASS_DRIVER(pci_emul) = {
60 .id = UCLASS_PCI_EMUL,
62 .post_probe = sandbox_pci_emul_post_probe,
63 .pre_remove = sandbox_pci_emul_pre_remove,
64 .priv_auto_alloc_size = sizeof(struct sandbox_pci_priv),