2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
15 uint offset, ulong value,
18 struct dm_pci_emul_ops *ops;
22 ret = sandbox_pci_get_emul(bus, devfn, &emul);
24 return ret == -ENODEV ? 0 : ret;
25 ops = pci_get_emul_ops(emul);
26 if (!ops || !ops->write_config)
29 return ops->write_config(emul, offset, value, size);
32 static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
33 uint offset, ulong *valuep,
36 struct dm_pci_emul_ops *ops;
40 /* Prepare the default response */
41 *valuep = pci_get_ff(size);
42 ret = sandbox_pci_get_emul(bus, devfn, &emul);
44 return ret == -ENODEV ? 0 : ret;
45 ops = pci_get_emul_ops(emul);
46 if (!ops || !ops->read_config)
49 return ops->read_config(emul, offset, valuep, size);
52 static const struct dm_pci_ops sandbox_pci_ops = {
53 .read_config = sandbox_pci_read_config,
54 .write_config = sandbox_pci_write_config,
57 static const struct udevice_id sandbox_pci_ids[] = {
58 { .compatible = "sandbox,pci" },
62 U_BOOT_DRIVER(pci_sandbox) = {
63 .name = "pci_sandbox",
65 .of_match = sandbox_pci_ids,
66 .ops = &sandbox_pci_ops,
68 /* Attach an emulator if we can */
69 .child_post_bind = dm_scan_fdt_dev,
70 .per_child_platdata_auto_alloc_size =
71 sizeof(struct pci_child_platdata),