Skip to content

Commit afbac2a

Browse files
implement rproc_virtio_read_config/rproc_virtio_write_config
so the rpmsg could access the configuration space as needed Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent 078ba09 commit afbac2a

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

lib/include/openamp/rpmsg_virtio.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ rpmsg_virtio_get_features(struct rpmsg_virtio_device *rvdev)
8585
return rvdev->vdev->func->get_features(rvdev->vdev);
8686
}
8787

88+
static inline void
89+
rpmsg_virtio_read_config(struct rpmsg_virtio_device *rvdev,
90+
uint32_t offset, void *dst, int length)
91+
{
92+
rvdev->vdev->func->read_config(rvdev->vdev, offset, dst, length);
93+
}
94+
95+
static inline void
96+
rpmsg_virtio_write_config(struct rpmsg_virtio_device *rvdev,
97+
uint32_t offset, void *dst, int length)
98+
{
99+
rvdev->vdev->func->write_config(rvdev->vdev, offset, dst, length);
100+
}
101+
88102
static inline int
89103
rpmsg_virtio_create_virtqueues(struct rpmsg_virtio_device *rvdev,
90104
int flags, unsigned int nvqs,

lib/include/openamp/virtio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct virtio_device {
100100
virtio_dev_reset_cb reset_cb; /**< user registered device callback */
101101
const struct virtio_dispatch *func; /**< Virtio dispatch table */
102102
void *priv; /**< TODO: remove pointer to virtio_device private data */
103+
unsigned int config_len; /**< config space length */
103104
unsigned int vrings_num; /**< number of vrings */
104105
struct virtio_vring_info *vrings_info;
105106
};

lib/remoteproc/remoteproc_virtio.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,43 @@ static uint32_t rproc_virtio_negotiate_features(struct virtio_device *vdev,
128128
static void rproc_virtio_read_config(struct virtio_device *vdev,
129129
uint32_t offset, void *dst, int length)
130130
{
131-
(void)vdev;
132-
(void)offset;
133-
(void)dst;
134-
(void)length;
131+
struct remoteproc_virtio *rpvdev;
132+
struct fw_rsc_vdev *vdev_rsc;
133+
struct metal_io_region *io;
134+
char *config;
135+
136+
if (offset + length > vdev->config_len || offset + length < length)
137+
return;
138+
139+
rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
140+
vdev_rsc = rpvdev->vdev_rsc;
141+
config = (char *)(&vdev_rsc->vring[vdev->vrings_num]);
142+
io = rpvdev->vdev_rsc_io;
143+
metal_io_block_read(io,
144+
metal_io_virt_to_offset(io, config + offset),
145+
dst, length);
135146
}
136147

137148
#ifndef VIRTIO_SLAVE_ONLY
138149
static void rproc_virtio_write_config(struct virtio_device *vdev,
139150
uint32_t offset, void *src, int length)
140151
{
141-
(void)vdev;
142-
(void)offset;
143-
(void)src;
144-
(void)length;
152+
struct remoteproc_virtio *rpvdev;
153+
struct fw_rsc_vdev *vdev_rsc;
154+
struct metal_io_region *io;
155+
char *config;
156+
157+
if (offset + length > vdev->config_len || offset + length < length)
158+
return;
159+
160+
rpvdev = metal_container_of(vdev, struct remoteproc_virtio, vdev);
161+
vdev_rsc = rpvdev->vdev_rsc;
162+
config = (char *)(&vdev_rsc->vring[vdev->vrings_num]);
163+
io = rpvdev->vdev_rsc_io;
164+
metal_io_block_write(io,
165+
metal_io_virt_to_offset(io, config + offset),
166+
src, length);
167+
rpvdev->notify(rpvdev->priv, vdev->notifyid);
145168
}
146169

147170
static void rproc_virtio_reset_device(struct virtio_device *vdev)
@@ -222,6 +245,7 @@ rproc_virtio_create_vdev(unsigned int role, unsigned int notifyid,
222245
vdev->notifyid = notifyid;
223246
vdev->role = role;
224247
vdev->reset_cb = rst_cb;
248+
vdev->config_len = vdev_rsc->config_len;
225249
vdev->vrings_num = num_vrings;
226250
vdev->func = &remoteproc_virtio_dispatch_funcs;
227251

0 commit comments

Comments
 (0)