2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 DECLARE_GLOBAL_DATA_PTR;
16 static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
17 uint offset, ulong value,
20 struct dm_pci_emul_ops *ops;
24 ret = sandbox_pci_get_emul(bus, devfn, &emul);
26 return ret == -ENODEV ? 0 : ret;
27 ops = pci_get_emul_ops(emul);
28 if (!ops || !ops->write_config)
31 return ops->write_config(emul, offset, value, size);
34 static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
35 uint offset, ulong *valuep,
38 struct dm_pci_emul_ops *ops;
42 /* Prepare the default response */
43 *valuep = pci_get_ff(size);
44 ret = sandbox_pci_get_emul(bus, devfn, &emul);
46 return ret == -ENODEV ? 0 : ret;
47 ops = pci_get_emul_ops(emul);
48 if (!ops || !ops->read_config)
51 return ops->read_config(emul, offset, valuep, size);
54 static int sandbox_pci_child_post_bind(struct udevice *dev)
56 /* Attach an emulator if we can */
57 return dm_scan_fdt_dev(dev);
60 static const struct dm_pci_ops sandbox_pci_ops = {
61 .read_config = sandbox_pci_read_config,
62 .write_config = sandbox_pci_write_config,
65 static const struct udevice_id sandbox_pci_ids[] = {
66 { .compatible = "sandbox,pci" },
70 U_BOOT_DRIVER(pci_sandbox) = {
71 .name = "pci_sandbox",
73 .of_match = sandbox_pci_ids,
74 .ops = &sandbox_pci_ops,
75 .child_post_bind = sandbox_pci_child_post_bind,
76 .per_child_platdata_auto_alloc_size =
77 sizeof(struct pci_child_platdata),