0009-implement-rproc_virtio_read_config-rproc_virtio_writ.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. From 9bbc2dcd43f6107a7e0b1eec16bab10e533329f2 Mon Sep 17 00:00:00 2001
  2. From: Xiang Xiao <xiaoxiang@xiaomi.com>
  3. Date: Thu, 3 Jan 2019 14:20:48 +0800
  4. Subject: [PATCH 09/10] implement
  5. rproc_virtio_read_config/rproc_virtio_write_config
  6. so the rpmsg could access the configuration space as needed
  7. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
  8. ---
  9. lib/include/openamp/rpmsg_virtio.h | 14 +++++++++++
  10. lib/include/openamp/virtio.h | 1 +
  11. lib/remoteproc/remoteproc_virtio.c | 40 ++++++++++++++++++++++++------
  12. 3 files changed, 47 insertions(+), 8 deletions(-)
  13. diff --git a/lib/include/openamp/rpmsg_virtio.h open-amp/lib/include/openamp/rpmsg_virtio.h
  14. index e6e5fa2..4d3093b 100644
  15. --- a/lib/include/openamp/rpmsg_virtio.h
  16. +++ open-amp/lib/include/openamp/rpmsg_virtio.h
  17. @@ -86,6 +86,20 @@ rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev)
  18. return rvdev->vdev->func->get_features(rvdev->vdev);
  19. }
  20. +static inline void
  21. +rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev,
  22. + uint32_t offset, void *dst, int length)
  23. +{
  24. + rvdev->vdev->func->read_config(rvdev->vdev, offset, dst, length);
  25. +}
  26. +
  27. +static inline void
  28. +rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev,
  29. + uint32_t offset, void *dst, int length)
  30. +{
  31. + rvdev->vdev->func->write_config(rvdev->vdev, offset, dst, length);
  32. +}
  33. +
  34. static inline int
  35. rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
  36. int flags, unsigned int nvqs,
  37. diff --git a/lib/include/openamp/virtio.h open-amp/lib/include/openamp/virtio.h
  38. index 55c8ea5..9c8376e 100644
  39. --- a/lib/include/openamp/virtio.h
  40. +++ open-amp/lib/include/openamp/virtio.h
  41. @@ -100,6 +100,7 @@ struct virtio_device {
  42. virtio_dev_reset_cb reset_cb; /**< user registered device callback */
  43. const struct virtio_dispatch *func; /**< Virtio dispatch table */
  44. void *priv; /**< TODO: remove pointer to virtio_device private data */
  45. + unsigned int config_len; /**< config space length */
  46. unsigned int vrings_num; /**< number of vrings */
  47. struct virtio_vring_info *vrings_info;
  48. };
  49. diff --git a/lib/remoteproc/remoteproc_virtio.c open-amp/lib/remoteproc/remoteproc_virtio.c
  50. index aafc48c..7505f64 100644
  51. --- a/lib/remoteproc/remoteproc_virtio.c
  52. +++ open-amp/lib/remoteproc/remoteproc_virtio.c
  53. @@ -128,20 +128,43 @@ static uint32_t rproc_virtio_negotiate_features(struct virtio_device *vdev,
  54. static void rproc_virtio_read_config(struct virtio_device *vdev,
  55. uint32_t offset, void *dst, int length)
  56. {
  57. - (void)vdev;
  58. - (void)offset;
  59. - (void)dst;
  60. - (void)length;
  61. + struct remoteproc_virtio *rpvdev;
  62. + struct fw_rsc_vdev *vdev_rsc;
  63. + struct metal_io_region *io;
  64. + char *config;
  65. +
  66. + if (offset + length > vdev->config_len || offset + length < length)
  67. + return;
  68. +
  69. + rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
  70. + vdev_rsc = rpvdev->vdev_rsc;
  71. + config = (char *)(&vdev_rsc->vring[vdev->vrings_num]);
  72. + io = rpvdev->vdev_rsc_io;
  73. + metal_io_block_read(io,
  74. + metal_io_virt_to_offset(io, config + offset),
  75. + dst, length);
  76. }
  77. #ifndef VIRTIO_SLAVE_ONLY
  78. static void rproc_virtio_write_config(struct virtio_device *vdev,
  79. uint32_t offset, void *src, int length)
  80. {
  81. - (void)vdev;
  82. - (void)offset;
  83. - (void)src;
  84. - (void)length;
  85. + struct remoteproc_virtio *rpvdev;
  86. + struct fw_rsc_vdev *vdev_rsc;
  87. + struct metal_io_region *io;
  88. + char *config;
  89. +
  90. + if (offset + length > vdev->config_len || offset + length < length)
  91. + return;
  92. +
  93. + rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
  94. + vdev_rsc = rpvdev->vdev_rsc;
  95. + config = (char *)(&vdev_rsc->vring[vdev->vrings_num]);
  96. + io = rpvdev->vdev_rsc_io;
  97. + metal_io_block_write(io,
  98. + metal_io_virt_to_offset(io, config + offset),
  99. + src, length);
  100. + rpvdev->notify(rpvdev->priv, vdev->notifyid);
  101. }
  102. static void rproc_virtio_reset_device(struct virtio_device *vdev)
  103. @@ -222,6 +245,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
  104. vdev->notifyid = notifyid;
  105. vdev->role = role;
  106. vdev->reset_cb = rst_cb;
  107. + vdev->config_len = vdev_rsc->config_len;
  108. vdev->vrings_num = num_vrings;
  109. vdev->func = &remoteproc_virtio_dispatch_funcs;
  110. --
  111. 2.17.1