pci_sandbox.c 1.6 KB

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