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 static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
18 uint offset, ulong value,
21 struct dm_pci_emul_ops *ops;
25 ret = sandbox_pci_get_emul(bus, devfn, &emul);
27 return ret == -ENODEV ? 0 : ret;
28 ops = pci_get_emul_ops(emul);
29 if (!ops || !ops->write_config)
32 return ops->write_config(emul, offset, value, size);
35 static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
36 uint offset, ulong *valuep,
39 struct dm_pci_emul_ops *ops;
43 /* Prepare the default response */
44 *valuep = pci_get_ff(size);
45 ret = sandbox_pci_get_emul(bus, devfn, &emul);
47 return ret == -ENODEV ? 0 : ret;
48 ops = pci_get_emul_ops(emul);
49 if (!ops || !ops->read_config)
52 return ops->read_config(emul, offset, valuep, size);
55 static int sandbox_pci_child_post_bind(struct udevice *dev)
57 /* Attach an emulator if we can */
58 return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
61 static const struct dm_pci_ops sandbox_pci_ops = {
62 .read_config = sandbox_pci_read_config,
63 .write_config = sandbox_pci_write_config,
66 static const struct udevice_id sandbox_pci_ids[] = {
67 { .compatible = "sandbox,pci" },
71 U_BOOT_DRIVER(pci_sandbox) = {
72 .name = "pci_sandbox",
74 .of_match = sandbox_pci_ids,
75 .ops = &sandbox_pci_ops,
76 .child_post_bind = sandbox_pci_child_post_bind,
77 .per_child_platdata_auto_alloc_size =
78 sizeof(struct pci_child_platdata),