blob: 67cd733e617bcf977333eb19683eb513500b2a39 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass537849a2015-03-05 12:25:27 -07002/*
3 * Copyright (c) 2014 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass537849a2015-03-05 12:25:27 -07005 */
6
7#include <common.h>
8#include <dm.h>
9#include <fdtdec.h>
10#include <inttypes.h>
11#include <pci.h>
Simon Glass537849a2015-03-05 12:25:27 -070012
Simon Glass537849a2015-03-05 12:25:27 -070013static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
14 uint offset, ulong value,
15 enum pci_size_t size)
16{
17 struct dm_pci_emul_ops *ops;
18 struct udevice *emul;
19 int ret;
20
21 ret = sandbox_pci_get_emul(bus, devfn, &emul);
22 if (ret)
23 return ret == -ENODEV ? 0 : ret;
24 ops = pci_get_emul_ops(emul);
25 if (!ops || !ops->write_config)
26 return -ENOSYS;
27
28 return ops->write_config(emul, offset, value, size);
29}
30
31static int sandbox_pci_read_config(struct udevice *bus, pci_dev_t devfn,
32 uint offset, ulong *valuep,
33 enum pci_size_t size)
34{
35 struct dm_pci_emul_ops *ops;
36 struct udevice *emul;
37 int ret;
38
39 /* Prepare the default response */
40 *valuep = pci_get_ff(size);
41 ret = sandbox_pci_get_emul(bus, devfn, &emul);
42 if (ret)
43 return ret == -ENODEV ? 0 : ret;
44 ops = pci_get_emul_ops(emul);
45 if (!ops || !ops->read_config)
46 return -ENOSYS;
47
48 return ops->read_config(emul, offset, valuep, size);
49}
50
Simon Glass537849a2015-03-05 12:25:27 -070051static const struct dm_pci_ops sandbox_pci_ops = {
52 .read_config = sandbox_pci_read_config,
53 .write_config = sandbox_pci_write_config,
54};
55
56static const struct udevice_id sandbox_pci_ids[] = {
57 { .compatible = "sandbox,pci" },
58 { }
59};
60
61U_BOOT_DRIVER(pci_sandbox) = {
62 .name = "pci_sandbox",
63 .id = UCLASS_PCI,
64 .of_match = sandbox_pci_ids,
65 .ops = &sandbox_pci_ops,
Simon Glass91195482016-07-05 17:10:10 -060066
67 /* Attach an emulator if we can */
68 .child_post_bind = dm_scan_fdt_dev,
Simon Glass537849a2015-03-05 12:25:27 -070069 .per_child_platdata_auto_alloc_size =
70 sizeof(struct pci_child_platdata),
71};