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 const struct dm_pci_ops sandbox_pci_ops = {
55 .read_config = sandbox_pci_read_config,
56 .write_config = sandbox_pci_write_config,
59 static const struct udevice_id sandbox_pci_ids[] = {
60 { .compatible = "sandbox,pci" },
64 U_BOOT_DRIVER(pci_sandbox) = {
65 .name = "pci_sandbox",
67 .of_match = sandbox_pci_ids,
68 .ops = &sandbox_pci_ops,
70 /* Attach an emulator if we can */
71 .child_post_bind = dm_scan_fdt_dev,
72 .per_child_platdata_auto_alloc_size =
73 sizeof(struct pci_child_platdata),