Skip to content

Commit

Permalink
virtio_mmio: Statically allocate metal_io_regions
Browse files Browse the repository at this point in the history
Make the metal_io_region for cfg_io and shm_io into full member structs
instead of just pointers. This means they will be allocated along with
the parent virtio_mmio_device struct and not need dynamically allocated
later.

Signed-off-by: Andrew Davis <afd@ti.com>
  • Loading branch information
glneo authored and arnopo committed Jul 5, 2024
1 parent 6780dd2 commit fdb8bf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/include/openamp/virtio_mmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ struct virtio_mmio_device {
struct virtio_device vdev;

/** Device configuration space metal_io_region */
struct metal_io_region *cfg_io;
struct metal_io_region cfg_io;

/** Pre-shared memory space metal_io_region */
struct metal_io_region *shm_io;
struct metal_io_region shm_io;

/** VIRTIO device configuration space */
struct virtio_mmio_dev_mem cfg_mem;
Expand Down
18 changes: 8 additions & 10 deletions lib/virtio_mmio/virtio_mmio_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ static inline void virtio_mmio_write32(struct virtio_device *vdev, int offset, u
struct virtio_mmio_device *vmdev = metal_container_of(vdev,
struct virtio_mmio_device, vdev);

metal_io_write32(vmdev->cfg_io, offset, value);
metal_io_write32(&vmdev->cfg_io, offset, value);
}

static inline uint32_t virtio_mmio_read32(struct virtio_device *vdev, int offset)
{
struct virtio_mmio_device *vmdev = metal_container_of(vdev,
struct virtio_mmio_device, vdev);

return metal_io_read32(vmdev->cfg_io, offset);
return metal_io_read32(&vmdev->cfg_io, offset);
}

static inline uint8_t virtio_mmio_read8(struct virtio_device *vdev, int offset)
{
struct virtio_mmio_device *vmdev = metal_container_of(vdev,
struct virtio_mmio_device, vdev);

return metal_io_read8(vmdev->cfg_io, offset);
return metal_io_read8(&vmdev->cfg_io, offset);
}

static inline void virtio_mmio_set_status(struct virtio_device *vdev, uint8_t status)
Expand Down Expand Up @@ -145,14 +145,12 @@ static int virtio_mmio_get_metal_io(struct virtio_device *vdev, uintptr_t virt_m
struct virtio_mmio_device, vdev);

/* Setup shared memory region */
vmdev->shm_io = metal_allocate_memory(sizeof(*vmdev->shm_io));
metal_io_init(vmdev->shm_io, (void *)virt_mem_ptr,
metal_io_init(&vmdev->shm_io, (void *)virt_mem_ptr,
(metal_phys_addr_t *)&vmdev->shm_mem.base,
vmdev->shm_mem.size, -1, 0, NULL);

/* Setup configuration region */
vmdev->cfg_io = metal_allocate_memory(sizeof(*vmdev->cfg_io));
metal_io_init(vmdev->cfg_io, (void *)cfg_mem_ptr,
metal_io_init(&vmdev->cfg_io, (void *)cfg_mem_ptr,
(metal_phys_addr_t *)&vmdev->cfg_mem.base,
vmdev->cfg_mem.size, -1, 0, NULL);

Expand Down Expand Up @@ -258,7 +256,7 @@ struct virtqueue *virtio_mmio_setup_virtqueue(struct virtio_device *vdev,
return NULL;
}

vring_info->io = vmdev->shm_io;
vring_info->io = &vmdev->shm_io;
vring_info->info.num_descs = virtio_mmio_get_max_elem(vdev, idx);
vring_info->info.align = VIRTIO_MMIO_VRING_ALIGNMENT;

Expand All @@ -284,7 +282,7 @@ struct virtqueue *virtio_mmio_setup_virtqueue(struct virtio_device *vdev,
}
vdev->role = role_bk;
vq->priv = cb_arg;
virtqueue_set_shmem_io(vq, vmdev->shm_io);
virtqueue_set_shmem_io(vq, &vmdev->shm_io);

/* Writing selection register VIRTIO_MMIO_QUEUE_SEL. In pure AMP
* mode this needs to be followed by a synchronization w/ the device
Expand All @@ -299,7 +297,7 @@ struct virtqueue *virtio_mmio_setup_virtqueue(struct virtio_device *vdev,
virtio_mmio_write32(vdev, VIRTIO_MMIO_QUEUE_NUM, vq->vq_nentries);
virtio_mmio_write32(vdev, VIRTIO_MMIO_QUEUE_ALIGN, 4096);
virtio_mmio_write32(vdev, VIRTIO_MMIO_QUEUE_PFN,
((uintptr_t)metal_io_virt_to_phys(vmdev->shm_io,
((uintptr_t)metal_io_virt_to_phys(&vmdev->shm_io,
(char *)vq->vq_ring.desc)) / 4096);

vdev->vrings_info[vdev->vrings_num].vq = vq;
Expand Down

0 comments on commit fdb8bf3

Please sign in to comment.