pci_sandbox.c 1.7 KB

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