axi_sandbox.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. */
  6. #include <common.h>
  7. #include <axi.h>
  8. #include <dm.h>
  9. #include <asm/axi.h>
  10. /*
  11. * This driver implements a AXI bus for the sandbox architecture for testing
  12. * purposes.
  13. *
  14. * The bus forwards every access to it to a special AXI emulation device (which
  15. * it gets via the axi_emul_get_ops function) that implements a simple
  16. * read/write storage.
  17. *
  18. * The emulator device must still be contained in the device tree in the usual
  19. * way, since configuration data for the storage is read from the DT.
  20. */
  21. static int axi_sandbox_read(struct udevice *bus, ulong address, void *data,
  22. enum axi_size_t size)
  23. {
  24. struct axi_emul_ops *ops;
  25. struct udevice *emul;
  26. int ret;
  27. /* Get emulator device */
  28. ret = axi_sandbox_get_emul(bus, address, size, &emul);
  29. if (ret)
  30. return ret == -ENODEV ? 0 : ret;
  31. /* Forward all reads to the AXI emulator */
  32. ops = axi_emul_get_ops(emul);
  33. if (!ops || !ops->read)
  34. return -ENOSYS;
  35. return ops->read(emul, address, data, size);
  36. }
  37. static int axi_sandbox_write(struct udevice *bus, ulong address, void *data,
  38. enum axi_size_t size)
  39. {
  40. struct axi_emul_ops *ops;
  41. struct udevice *emul;
  42. int ret;
  43. /* Get emulator device */
  44. ret = axi_sandbox_get_emul(bus, address, size, &emul);
  45. if (ret)
  46. return ret == -ENODEV ? 0 : ret;
  47. /* Forward all writes to the AXI emulator */
  48. ops = axi_emul_get_ops(emul);
  49. if (!ops || !ops->write)
  50. return -ENOSYS;
  51. return ops->write(emul, address, data, size);
  52. }
  53. static const struct udevice_id axi_sandbox_ids[] = {
  54. { .compatible = "sandbox,axi" },
  55. { /* sentinel */ }
  56. };
  57. static const struct axi_ops axi_sandbox_ops = {
  58. .read = axi_sandbox_read,
  59. .write = axi_sandbox_write,
  60. };
  61. U_BOOT_DRIVER(axi_sandbox_bus) = {
  62. .name = "axi_sandbox_bus",
  63. .id = UCLASS_AXI,
  64. .of_match = axi_sandbox_ids,
  65. .ops = &axi_sandbox_ops,
  66. };