1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
13 static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
14 uint offset, ulong value,
17 struct dm_pci_emul_ops *ops;
21 ret = sandbox_pci_get_emul(bus, devfn, &emul);
23 return ret == -ENODEV ? 0 : ret;
24 ops = pci_get_emul_ops(emul);
25 if (!ops || !ops->write_config)
28 return ops->write_config(emul, offset, value, size);
31 static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
32 uint offset, ulong *valuep,
35 struct dm_pci_emul_ops *ops;
39 /* Prepare the default response */
40 *valuep = pci_get_ff(size);
41 ret = sandbox_pci_get_emul(bus, devfn, &emul);
43 return ret == -ENODEV ? 0 : ret;
44 ops = pci_get_emul_ops(emul);
45 if (!ops || !ops->read_config)
48 return ops->read_config(emul, offset, valuep, size);
51 static const struct dm_pci_ops sandbox_pci_ops = {
52 .read_config = sandbox_pci_read_config,
53 .write_config = sandbox_pci_write_config,
56 static const struct udevice_id sandbox_pci_ids[] = {
57 { .compatible = "sandbox,pci" },
61 U_BOOT_DRIVER(pci_sandbox) = {
62 .name = "pci_sandbox",
64 .of_match = sandbox_pci_ids,
65 .ops = &sandbox_pci_ops,
67 /* Attach an emulator if we can */
68 .child_post_bind = dm_scan_fdt_dev,
69 .per_child_platdata_auto_alloc_size =
70 sizeof(struct pci_child_platdata),