2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
15 DECLARE_GLOBAL_DATA_PTR;
17 struct sandbox_pci_priv {
21 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
22 struct udevice **emulp)
27 ret = pci_bus_find_devfn(bus, find_devfn, &dev);
29 debug("%s: Could not find emulator for dev %x\n", __func__,
34 ret = device_find_first_child(dev, emulp);
38 return *emulp ? 0 : -ENODEV;
41 static int sandbox_pci_emul_post_probe(struct udevice *dev)
43 struct sandbox_pci_priv *priv = dev->uclass->priv;
46 sandbox_set_enable_pci_map(true);
51 static int sandbox_pci_emul_pre_remove(struct udevice *dev)
53 struct sandbox_pci_priv *priv = dev->uclass->priv;
56 sandbox_set_enable_pci_map(priv->dev_count > 0);
61 UCLASS_DRIVER(pci_emul) = {
62 .id = UCLASS_PCI_EMUL,
64 .post_probe = sandbox_pci_emul_post_probe,
65 .pre_remove = sandbox_pci_emul_pre_remove,
66 .priv_auto_alloc_size = sizeof(struct sandbox_pci_priv),