virtio: align virtio_config_ops::generation return type with Linux
Subsystems (5)
PATCH 3/9 hw_random: virtio: simplify code
In reply to Ahmad FatoumThe Linux code did a bit more than we do, but after deleting the unneeded parts virtrng_probe and virtrng_remove do nothing but call probe_common/remove_common. Drop the intermediate functions.
--- drivers/hw_random/virtio-rng.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/hw_random/virtio-rng.c +2 -12
@@ -61,7 +61,7 @@ static int virtio_rng_read(struct hwrng *hwrng, void *data, size_t len, bool waireturn len; } -static int probe_common (struct virtio_device *vdev) +static int virtrng_probe (struct virtio_device *vdev) {struct virtrng_info *vi;
@@ -76,22 +76,12 @@ static int probe_common(struct virtio_device *vdev)return virtio_find_vqs (vdev,1 , &vi->rng_vq); } -static void remove_common (struct virtio_device *vdev) +static void virtrng_remove (struct virtio_device *vdev) { vdev->config->reset (vdev); vdev->config->del_vqs (vdev); } -static int virtrng_probe (struct virtio_device *vdev) -{ -return probe_common (vdev); -} - -static void virtrng_remove (struct virtio_device *vdev) -{ -remove_common (vdev); -} -static void virtrng_scan (struct virtio_device *vdev) {struct virtrng_info *vi = vdev->priv;
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/9 virtio: remove unused, left-over, virtio_config_ops::set_features
In reply to Ahmad FatoumLinux finalize_features was renamed to set_features in the U-Boot port. We adhere to the Linux naming and set_features is unused anywhere. Drop it.
--- include/linux/virtio_config.h | 7 ------- 1 file changed, 7 deletions(-)
include/linux/virtio_config.h +0 -7
@@ -82,13 +82,6 @@ struct virtio_config_ops {* @return features */ u64 (*get_features)(struct virtio_device *vdev); -/** -* set_features() - confirm what device features we'll be using -* -* @vdev: the real virtio device -* @return 0 if OK, -ve on error -*/ -int (*set_features)(struct virtio_device *vdev);/** * find_vqs() - find virtqueues and instantiate them *
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/9 virtio: align virtio_config_ops::generation return type with Linux
The U-Boot return type for the function differs from Linux. We use the Linux API elsewhere, so use it here as well.
--- drivers/virtio/virtio_mmio.c | 8 +++----- include/linux/virtio_config.h | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-)
drivers/virtio/virtio_mmio.c +3 -5
@@ -141,16 +141,14 @@ static int virtio_mmio_set_config(struct virtio_device *vdev, unsigned int offsereturn 0 ; } -static int virtio_mmio_generation (struct virtio_device *vdev,u32 *counter) +static u32 virtio_mmio_generation (struct virtio_device *vdev) {struct virtio_mmio_device *priv =to_virtio_mmio_device (vdev);if (priv->version ==1 ) - *counter =0 ; -else - *counter =readl (priv->base +VIRTIO_MMIO_CONFIG_GENERATION ); +return 0 ; -return 0 ; +return readl (priv->base +VIRTIO_MMIO_CONFIG_GENERATION ); }static int virtio_mmio_get_status (struct virtio_device *vdev)
include/linux/virtio_config.h +4 -5
@@ -49,10 +49,9 @@ struct virtio_config_ops {* generation() - config generation counter * * @vdev: the real virtio device -* @counter: the returned config generation counter -* @return 0 if OK, -ve on error +* @return the config generation counter */ -int (*generation)(struct virtio_device *vdev,u32 *counter); +u32 (*generation)(struct virtio_device *vdev);/** * get_status() - read the status byte *
@@ -311,7 +310,7 @@ static inline void __virtio_cread_many(struct virtio_device *vdev,int i;/* no need to check return value as generation can be optional */ - vdev->config->generation (vdev, &gen); + gen = vdev->config->generation (vdev); do { old = gen;
@@ -319,7 +318,7 @@ static inline void __virtio_cread_many(struct virtio_device *vdev,virtio_get_config (vdev, offset + bytes * i, buf + i * bytes, bytes); - vdev->config->generation (vdev, &gen); + gen = vdev->config->generation (vdev); }while (gen != old); }
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/9 virtio: fix support for big-endian clients
With virtio 1.0 everything is little endian. Add back the Version 1.0 check that got lost during porting virtio to barebox.
--- include/linux/virtio_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/virtio_config.h +2 -1
@@ -203,7 +203,8 @@ static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)static inline bool virtio_is_little_endian (struct virtio_device *vdev) { -return virtio_legacy_is_little_endian (); +return virtio_has_feature (vdev,VIRTIO_F_VERSION_1 ) || +virtio_legacy_is_little_endian (); }
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 9/9 virtio: virtio-pci: restrict MIPS support to MMU configuration
In reply to Ahmad FatoumMMU-less MIPS doesn't play along nicely with VIRTIO_PCI. e.g. Reading from a virtio-rng, will return clearly bogus data. Document this in the Kconfig, so no one else trips over this.
Eventually, this should be fixed..
--- drivers/virtio/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/virtio/Kconfig +1 -0
@@ -28,6 +28,7 @@ config VIRTIO_MMIO config VIRTIO_PCI tristate "PCI driver for virtio devices" depends on PCI && HAS_DMA + depends on MMU && MIPS || !MIPS select VIRTIO help This driver provides support for virtio based paravirtual device
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/9 virtio: ring: fix erroneous behavior around caches and MMU
In reply to Ahmad FatoumThe U-Boot code assumes 1:1 phys2virt mapping and either disabled caches or a lot of luck. Use the DMA API to get appropriate addresses for DMA and use coherent/streaming DMA mappings where appropriate.
This is required for proper operation on MIPS.
--- drivers/virtio/virtio_ring.c | 98 +++++++++++++++++++++++++++++++----- include/linux/virtio_ring.h | 2 + 2 files changed, 87 insertions(+), 13 deletions(-)
drivers/virtio/virtio_ring.c +85 -13
@@ -22,12 +22,45 @@#define vq_info (vq, fmt, ...) \ dev_info(&vq->vdev->dev, fmt, ##__VA_ARGS__) +static inline struct device_d *vring_dma_dev (const struct virtqueue *vq) +{ +return vq->vdev->dev.parent; +} + +/* Map one sg entry. */ +static dma_addr_t vring_map_one_sg (struct virtqueue *vq, +struct virtio_sg *sg, +enum dma_data_direction direction) +{ +return dma_map_single (vring_dma_dev (vq), sg->addr, sg->length, direction); +} + +static int vring_mapping_error (struct virtqueue *vq, +dma_addr_t addr) +{ +return dma_mapping_error (vring_dma_dev (vq), addr); +} + +static void vring_unmap_one (struct virtqueue *vq, +struct vring_desc *desc) +{ +u16 flags; + + flags =virtio16_to_cpu (vq->vdev, desc->flags); + +dma_unmap_single (vring_dma_dev (vq), +virtio64_to_cpu (vq->vdev, desc->addr), +virtio32_to_cpu (vq->vdev, desc->len), + (flags &VRING_DESC_F_WRITE ) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +} +int virtqueue_add (struct virtqueue *vq,struct virtio_sg *sgs[],unsigned int out_sgs,unsigned int in_sgs) {struct vring_desc *desc;unsigned int total_sg = out_sgs + in_sgs; -unsigned int i, n, avail, descs_used,uninitialized_var (prev ); +unsigned int i, err_idx, n, avail, descs_used,uninitialized_var (prev );int head;WARN_ON (total_sg ==0 );
@@ -53,9 +86,13 @@ int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[],for (n =0 ; n < out_sgs; n++) {struct virtio_sg *sg = sgs[n]; +dma_addr_t addr =vring_map_one_sg (vq, sg,DMA_TO_DEVICE ); +if (vring_mapping_error (vq, addr)) + goto unmap_release; + desc[i].flags =cpu_to_virtio16 (vq->vdev,VRING_DESC_F_NEXT ); - desc[i].addr =cpu_to_virtio64 (vq->vdev, (u64 )(size_t )sg->addr); + desc[i].addr =cpu_to_virtio64 (vq->vdev, addr); desc[i].len =cpu_to_virtio32 (vq->vdev, sg->length); prev = i;
@@ -63,11 +100,13 @@ int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[], }for (; n < (out_sgs + in_sgs); n++) {struct virtio_sg *sg = sgs[n]; +dma_addr_t addr =vring_map_one_sg (vq, sg,DMA_FROM_DEVICE ); +if (vring_mapping_error (vq, addr)) + goto unmap_release; desc[i].flags =cpu_to_virtio16 (vq->vdev,VRING_DESC_F_NEXT |VRING_DESC_F_WRITE ); - desc[i].addr =cpu_to_virtio64 (vq->vdev, - (u64 )(uintptr_t )sg->addr); + desc[i].addr =cpu_to_virtio64 (vq->vdev, addr); desc[i].len =cpu_to_virtio32 (vq->vdev, sg->length); prev = i;
@@ -106,6 +145,19 @@ int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[],virtqueue_kick (vq);return 0 ; + +unmap_release: + err_idx = i; + +for (n =0 ; n < total_sg; n++) { +if (i == err_idx) +break ; +vring_unmap_one (vq, &desc[i]); + i =virtio16_to_cpu (vq->vdev, desc[i].next); + } + +return -ENOMEM ; + }static bool virtqueue_kick_prepare (struct virtqueue *vq)
@@ -149,10 +201,12 @@ static void detach_buf(struct virtqueue *vq, unsigned int head) i = head;while (vq->vring.desc[i].flags & nextflag) { +vring_unmap_one (vq, &vq->vring.desc[i]); i =virtio16_to_cpu (vq->vdev, vq->vring.desc[i].next); vq->num_free++; } +vring_unmap_one (vq, &vq->vring.desc[i]); vq->vring.desc[i].next =cpu_to_virtio16 (vq->vdev, vq->free_head); vq->free_head = head;
@@ -225,6 +279,8 @@ static struct virtqueue *__vring_new_virtqueue(unsigned int index, vq->avail_flags_shadow =0 ; vq->avail_idx_shadow =0 ; vq->num_added =0 ; + vq->queue_dma_addr =0 ; + vq->queue_size_in_bytes =0 ;list_add_tail (&vq->list, &vdev->vqs); vq->event =virtio_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX );
@@ -243,12 +299,24 @@ static struct virtqueue *__vring_new_virtqueue(unsigned int index,return vq; } +static void *vring_alloc_queue (size_t size,dma_addr_t *dma_handle) +{ +return dma_alloc_coherent (size, dma_handle); +} + +static void vring_free_queue (size_t size,void *queue,dma_addr_t dma_handle) +{ +dma_free_coherent (queue, dma_handle, size); +} +struct virtqueue *vring_create_virtqueue (unsigned int index,unsigned int num,unsigned int vring_align,struct virtio_device *vdev) {struct virtqueue *vq;void *queue =NULL ; +dma_addr_t dma_addr; +size_t queue_size_in_bytes;struct vring vring;/* We assume num is a power of 2 */
@@ -259,7 +327,7 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num,/* TODO: allocate each queue chunk individually */ for (; num &&vring_size (num, vring_align) >PAGE_SIZE ; num /=2 ) { - queue =memalign (PAGE_SIZE ,vring_size (num, vring_align)); + queue =vring_alloc_queue (vring_size (num, vring_align), &dma_addr);if (queue)break ; }
@@ -269,27 +337,31 @@ struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num,if (!queue) {/* Try to get a single page. You are my only hope! */ - queue =memalign (PAGE_SIZE ,vring_size (num, vring_align)); + queue =vring_alloc_queue (vring_size (num, vring_align), &dma_addr); }if (!queue)return NULL ; -memset (queue,0 ,vring_size (num, vring_align)); + queue_size_in_bytes =vring_size (num, vring_align);vring_init (&vring, num, queue, vring_align); vq =__vring_new_virtqueue (index, vring, vdev);if (!vq) { -free (queue); +vring_free_queue (queue_size_in_bytes, queue, dma_addr);return NULL ; } -vq_debug (vq,"created vring @ %p for vq with num %u\n" , queue, num); +vq_debug (vq,"created vring @ (virt=%p, phys=%pad) for vq with num %u\n" , + queue, &dma_addr, num); + + vq->queue_dma_addr = dma_addr; + vq->queue_size_in_bytes = queue_size_in_bytes;return vq; }void vring_del_virtqueue (struct virtqueue *vq) { -free (vq->vring.desc); +vring_free_queue (vq->queue_size_in_bytes, vq->vring.desc, vq->queue_dma_addr);list_del (&vq->list);free (vq); }
@@ -301,18 +373,18 @@ unsigned int virtqueue_get_vring_size(struct virtqueue *vq)dma_addr_t virtqueue_get_desc_addr (struct virtqueue *vq) { -return (dma_addr_t )vq->vring.desc; +return vq->queue_dma_addr; }dma_addr_t virtqueue_get_avail_addr (struct virtqueue *vq) { -return (dma_addr_t )vq->vring.desc + +return vq->queue_dma_addr + ((char *)vq->vring.avail - (char *)vq->vring.desc); }dma_addr_t virtqueue_get_used_addr (struct virtqueue *vq) { -return (dma_addr_t )vq->vring.desc + +return vq->queue_dma_addr + ((char *)vq->vring.used - (char *)vq->vring.desc); }
include/linux/virtio_ring.h +2 -0
@@ -108,6 +108,8 @@ struct virtqueue {u16 last_used_idx;u16 avail_flags_shadow;u16 avail_idx_shadow; +dma_addr_t queue_dma_addr; +size_t queue_size_in_bytes; };/*
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/9 dma: move dma_map/unmap_single from ARM to common code
In reply to Ahmad FatoumThere's nothing ARM specific about these functions. Move them to a common location, so other arches can use them as well.
--- arch/arm/cpu/mmu-common.c | 41 +------------------------------------- drivers/dma/Makefile | 1 + drivers/dma/map.c | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 drivers/dma/map.c
arch/arm/cpu/mmu-common.c +1 -40
@@ -10,27 +10,6 @@#include <memory.h> #include "mmu.h" - -static inline dma_addr_t cpu_to_dma (struct device_d *dev,unsigned long cpu_addr) -{ -dma_addr_t dma_addr = cpu_addr; - -if (dev) - dma_addr -= dev->dma_offset; - -return dma_addr; -} - -static inline unsigned long dma_to_cpu (struct device_d *dev,dma_addr_t addr) -{ -unsigned long cpu_addr = addr; - -if (dev) - cpu_addr += dev->dma_offset; - -return cpu_addr; -} -void dma_sync_single_for_cpu (dma_addr_t address,size_t size,enum dma_data_direction dir) {
@@ -41,24 +20,6 @@ void dma_sync_single_for_cpu(dma_addr_t address, size_t size,dma_inv_range ((void *)address, size); } -dma_addr_t dma_map_single (struct device_d *dev,void *ptr,size_t size, -enum dma_data_direction dir) -{ -unsigned long addr = (unsigned long )ptr; - -dma_sync_single_for_device (addr, size, dir); - -return cpu_to_dma (dev, addr); -} - -void dma_unmap_single (struct device_d *dev,dma_addr_t dma_addr,size_t size, -enum dma_data_direction dir) -{ -unsigned long addr =dma_to_cpu (dev, dma_addr); - -dma_sync_single_for_cpu (addr, size, dir); -} -void *dma_alloc_map (size_t size,dma_addr_t *dma_handle,unsigned flags) {void *ret;
@@ -108,4 +69,4 @@ static int mmu_init(void)return 0 ; } -mmu_initcall (mmu_init); +mmu_initcall (mmu_init);
drivers/dma/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_MXS_APBH_DMA) += apbh_dma.o +obj-$(CONFIG_HAS_DMA) += map.o
drivers/dma/map.c new file +42 -0
42 lines not on this page · raw message
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 7/9 PCI: port Linux pci_find_capability
In reply to Ahmad FatoumIncomding Linux virtio_pci code uses these functions, so port them over.
--- drivers/pci/pci.c | 90 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 5 +++ 2 files changed, 95 insertions(+)
drivers/pci/pci.c +90 -0
@@ -506,6 +506,96 @@ int pci_enable_device(struct pci_dev *dev) }EXPORT_SYMBOL (pci_enable_device); +static u8 __pci_find_next_cap_ttl (struct pci_bus *bus,unsigned int devfn, +u8 pos,int cap,int *ttl) +{ +u8 id; +u16 ent; + +pci_bus_read_config_byte (bus, devfn, pos, &pos); + +while ((*ttl)--) { +if (pos <0x40 ) +break ; + pos &= ~3 ; +pci_bus_read_config_word (bus, devfn, pos, &ent); + + id = ent &0xff ; +if (id ==0xff ) +break ; +if (id == cap) +return pos; + pos = (ent >>8 ); + } +return 0 ; +} + +static u8 __pci_find_next_cap (struct pci_bus *bus,unsigned int devfn, +u8 pos,int cap) +{ +int ttl =PCI_FIND_CAP_TTL ; + +return __pci_find_next_cap_ttl (bus, devfn, pos, cap, &ttl); +} + +u8 pci_find_next_capability (struct pci_dev *dev,u8 pos,int cap) +{ +return __pci_find_next_cap (dev->bus, dev->devfn, + pos +PCI_CAP_LIST_NEXT , cap); +} +EXPORT_SYMBOL_GPL (pci_find_next_capability); + +static u8 __pci_bus_find_cap_start (struct pci_bus *bus, +unsigned int devfn,u8 hdr_type) +{ +u16 status; + +pci_bus_read_config_word (bus, devfn,PCI_STATUS , &status); +if (!(status &PCI_STATUS_CAP_LIST )) +return 0 ; + +switch (hdr_type) { +case PCI_HEADER_TYPE_NORMAL : +case PCI_HEADER_TYPE_BRIDGE : +return PCI_CAPABILITY_LIST ; +case PCI_HEADER_TYPE_CARDBUS : +return PCI_CB_CAPABILITY_LIST ; + } + +return 0 ; +} + +/** +* pci_find_capability - query for devices' capabilities +* @dev: PCI device to query +* @cap: capability code +* +* Tell if a device supports a given PCI capability. +* Returns the address of the requested capability structure within the +* device's PCI configuration space or 0 in case the device does not +* support it. Possible values for @cap include: +* +* %PCI_CAP_ID_PM Power Management +* %PCI_CAP_ID_AGP Accelerated Graphics Port +* %PCI_CAP_ID_VPD Vital Product Data +* %PCI_CAP_ID_SLOTID Slot Identification +* %PCI_CAP_ID_MSI Message Signalled Interrupts +* %PCI_CAP_ID_CHSWP CompactPCI HotSwap +* %PCI_CAP_ID_PCIX PCI-X +* %PCI_CAP_ID_EXP PCI Express +*/ +u8 pci_find_capability (struct pci_dev *dev,int cap) +{ +u8 pos; + + pos =__pci_bus_find_cap_start (dev->bus, dev->devfn, dev->hdr_type); +if (pos) + pos =__pci_find_next_cap (dev->bus, dev->devfn, pos, cap); + +return pos; +} +EXPORT_SYMBOL (pci_find_capability); +static void pci_do_fixups (struct pci_dev *dev,struct pci_fixup *f,struct pci_fixup *end) {
include/linux/pci.h +5 -0
@@ -31,6 +31,8 @@#define PCI_ANY_ID (~0) +#define PCI_FIND_CAP_TTL 48 +/* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded
@@ -320,6 +322,9 @@ void pci_set_master(struct pci_dev *dev);void pci_clear_master (struct pci_dev *dev);int pci_enable_device (struct pci_dev *dev); +u8 pci_find_next_capability (struct pci_dev *dev,u8 pos,int cap); +u8 pci_find_capability (struct pci_dev *dev,int cap); +extern void __iomem *pci_iomap (struct pci_dev *dev,int bar);/*
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 8/9 virtio: support virtio-based device drivers over PCI
In reply to Ahmad FatoumThis driver provides support for virtio based paravirtual device drivers over PCI. This is useful with Qemu for boards that barebox has PCI support for, e.g. MIPS Malta.
--- Documentation/user/virtio.rst | 30 ++- drivers/virtio/Kconfig | 12 +- drivers/virtio/Makefile | 2 + drivers/virtio/virtio_pci_common.c | 88 ++++++ drivers/virtio/virtio_pci_common.h | 64 +++++ drivers/virtio/virtio_pci_modern.c | 417 +++++++++++++++++++++++++++++ include/uapi/linux/virtio_pci.h | 208 ++++++++++++++ 7 files changed, 807 insertions(+), 14 deletions(-) create mode 100644 drivers/virtio/virtio_pci_common.c create mode 100644 drivers/virtio/virtio_pci_common.h create mode 100644 drivers/virtio/virtio_pci_modern.c create mode 100644 include/uapi/linux/virtio_pci.h
Documentation/user/virtio.rst +17 -13
@@ -20,7 +20,7 @@ just the guest's device driver "knows" it is running in a virtual environment, and cooperates with the hypervisor. This enables guests to get high performance network and disk operations, and gives most of the performance benefits of paravirtualization. In the barebox case, the guest is barebox itself, while the -virtual environment will normally be QEMU_ targets like ARM, RISC-V and x86. +virtual environment will normally be QEMU_ targets like ARM, MIPS, RISC-V or x86. Status ------
@@ -31,8 +31,8 @@ embedded devices models like ARM/RISC-V, which does not normally come with PCI support might use simple memory mapped device (MMIO) instead of the PCI device. The memory mapped virtio device behaviour is based on the PCI device specification. Therefore most operations including device initialization, -queues configuration and buffer transfers are nearly identical. Only MMIO -is currently supported in barebox. +queues configuration and buffer transfers are nearly identical. Both MMIO +and non-legacy PCI are supported in barebox. The VirtIO spec defines a lots of VirtIO device types, however at present only block, console and RNG devices are supported.
@@ -67,16 +67,20 @@ to pass barebox a fixed-up device tree describing the ``virtio-mmio`` rings. Except for the console, multiple instances of a VirtIO device can be created -by appending more '-device' parameters. For example to create one HWRNG -and 2 block devices:: - - $ qemu-system-arm -m 256M -M virt -nographic \ - -kernel ./images/barebox-dt-2nd.img \ - -device virtio-rng-device \ - -drive if=none,file=/tmp/first.hdimg,format=raw,id=hd0 \ - -device virtio-blk-device,drive=hd0 \ - -drive if=none,file=/tmp/second.hdimg,format=raw,id=hd1 \ - -device virtio-blk-device,drive=hd1 +by appending more '-device' parameters. For example to extend a MIPS +malta VM with one HWRNG and 2 block VirtIO PCI devices:: + + $ qemu-system-mips -m 256M -M malta -serial stdio \ + -bios ./images/barebox-qemu-malta.img -monitor null \ + -device virtio-rng-pci,disable-legacy=on \ + -drive if=none,file=image1.hdimg,format=raw,id=hd0 \ + -device virtio-blk-pci,drive=hd0,disable-legacy=on \ + -drive if=none,file=image2.hdimg,format=raw,id=hd1 \ + -device virtio-blk-pci,drive=hd1,disable-legacy=on + +Note the use of ``disable-legacy=on``. barebox doesn't support legacy +or transitional VirtIO devices. Some versions of QEMU may need to +have ``,disable-modern=off`` specfied as well. .. _VirtIO: http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf .. _qemu: https://www.qemu.org
drivers/virtio/Kconfig +11 -1
@@ -3,7 +3,7 @@ config VIRTIO bool help This option is selected by any driver which implements the virtio - bus, such as CONFIG_VIRTIO_MMIO. + bus, such as CONFIG_VIRTIO_MMIO, CONFIG_VIRTIO_PCI. config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS bool
@@ -25,4 +25,14 @@ config VIRTIO_MMIO This drivers provides support for memory mapped virtio platform device driver. This is usually used with Qemu. +config VIRTIO_PCI + tristate "PCI driver for virtio devices" + depends on PCI && HAS_DMA + select VIRTIO + help + This driver provides support for virtio based paravirtual device + drivers over PCI. This requires that your VMM has appropriate PCI + virtio backends. Most QEMU based VMMs should support these devices + (like KVM or Xen). + endif # VIRTIO_MENU
drivers/virtio/Makefile +2 -0
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o +obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o +virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio_pci_common.c new file +88 -0
88 lines not on this page · raw message
drivers/virtio/virtio_pci_common.h new file +64 -0
64 lines not on this page · raw message
drivers/virtio/virtio_pci_modern.c new file +417 -0
417 lines not on this page · raw message
include/uapi/linux/virtio_pci.h new file +208 -0
208 lines not on this page · raw message
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 8 lines · Ahmad Fatoum
The U-Boot return type for the function differs from Linux. We use the Linux API elsewhere, so use it here as well.
Signed-off-by Ahmad Fatoum <[email protected]>--- drivers/virtio/virtio_mmio.c | 8 +++----- include/linux/virtio_config.h | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-)
Applied, thanks
Sascha
Quoted 69 lines
drivers/virtio/virtio_mmio.c +3
-5@@ -141,16 +141,14 @@ static int virtio_mmio_set_config(struct virtio_device *vdev, unsigned int offsereturn 0 ; } -static int virtio_mmio_generation (struct virtio_device *vdev,u32 *counter) +static u32 virtio_mmio_generation (struct virtio_device *vdev) {struct virtio_mmio_device *priv =to_virtio_mmio_device (vdev);if (priv->version ==1 ) - *counter =0 ; -else - *counter =readl (priv->base +VIRTIO_MMIO_CONFIG_GENERATION ); +return 0 ; -return 0 ; +return readl (priv->base +VIRTIO_MMIO_CONFIG_GENERATION ); }static int virtio_mmio_get_status (struct virtio_device *vdev)include/linux/virtio_config.h +4
-5@@ -49,10 +49,9 @@ struct virtio_config_ops {* generation() - config generation counter * * @vdev: the real virtio device -* @counter: the returned config generation counter -* @return 0 if OK, -ve on error +* @return the config generation counter */ -int (*generation)(struct virtio_device *vdev,u32 *counter); +u32 (*generation)(struct virtio_device *vdev);/** * get_status() - read the status byte * @@ -311,7 +310,7 @@ static inline void __virtio_cread_many(struct virtio_device *vdev,int i;/* no need to check return value as generation can be optional */ - vdev->config->generation (vdev, &gen); + gen = vdev->config->generation (vdev); do { old = gen;@@ -319,7 +318,7 @@ static inline void __virtio_cread_many(struct virtio_device *vdev,virtio_get_config (vdev, offset + bytes * i, buf + i * bytes, bytes); - vdev->config->generation (vdev, &gen); + gen = vdev->config->generation (vdev); }while (gen != old); }Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 4/9] dma: move dma_map/unmap_single from ARM to common code
In reply to Ahmad FatoumHi Ahmad,
Quoted 10 lines · Ahmad Fatoum
There's nothing ARM specific about these functions. Move them to a common location, so other arches can use them as well.
Signed-off-by Ahmad Fatoum <[email protected]>--- arch/arm/cpu/mmu-common.c | 41 +------------------------------------- drivers/dma/Makefile | 1 + drivers/dma/map.c | 42 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 drivers/dma/map.c
This breaks several arm configs:
drivers/dma/map.c:26:12: error: redefinition of 'dma_map_single'
26 | dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
| ^~~~~~~~~~~~~~
In file included from include/dma.h:13,
from drivers/dma/map.c:4:
/ptx/work/WORK_EIHEI/sha/backup/barebox/barebox-maintainer-utils/barebox/arch/arm/include/asm/dma.h:35:26: note: previous definition of 'dma_map_single' was here
35 | static inline dma_addr_t dma_map_single(struct device_d *dev, void *ptr, size_t size,
| ^~~~~~~~~~~~~~
drivers/dma/map.c:36:6: error: redefinition of 'dma_unmap_single'
36 | void dma_unmap_single(struct device_d *dev, dma_addr_t dma_addr, size_t size,
| ^~~~~~~~~~~~~~~~In file included from include/dma.h:13,
from drivers/dma/map.c:4:
/ptx/work/WORK_EIHEI/sha/backup/barebox/barebox-maintainer-utils/barebox/arch/arm/include/asm/dma.h:41:20: note: previous definition of 'dma_unmap_single' was here
41 | static inline void dma_unmap_single(struct device_d *dev, dma_addr_t addr, size_t size,
| ^~~~~~~~~~~~~~~~
This happens for example in dss11_defconfig, but several others as well.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 9/9] virtio: virtio-pci: restrict MIPS support to MMU configuration
In reply to Ahmad FatoumOn Sun, 28 Feb 2021 20:08:36 +0100
Ahmad Fatoum <[email protected]> wrote:
Hi!
Quoted 5 lines
MMU-less MIPS doesn't play along nicely with
VIRTIO_PCI. e.g. Reading from a virtio-rng, will return clearly bogus data. Document this in theKconfig, so no one else trips over this.Eventually, this should be fixed..
Please describe, how can I reproduce the problem.
Quoted 26 lines
Signed-off-by Ahmad Fatoum <[email protected]>--- drivers/virtio/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/virtio/Kconfig +1
-0@@ -28,6 +28,7 @@ config VIRTIO_MMIO config VIRTIO_PCI tristate "PCI driver for virtio devices" depends on PCI && HAS_DMA + depends on MMU && MIPS || !MIPS select VIRTIO help This driver provides support for virtio based paravirtual deviceSignature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 7 lines
Best regards, Antony Pavlov _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/1 dma: move dma_map/unmap_single from ARM to common code
In reply to Ahmad FatoumThere's nothing ARM specific about these functions. Move them to a common location, so other arches can use them as well.
This also fixes a bug on ARM MMU=n configurations:
Previously these two functions these functions only respected dma-ranges translation when compiled with MMU support. DMA address translation is applicable regardless of CPU use of MMU though. Now, dma-ranges should be respected unconditionally.
---
Sascha, please replace the original patch with this one.
--- arch/arm/cpu/mmu-common.c | 41 +-------------------------------- arch/arm/include/asm/dma.h | 11 --------- arch/sandbox/include/asm/dma.h | 11 --------- drivers/dma/Makefile | 1 + drivers/dma/map.c | 42 ++++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 62 deletions(-) create mode 100644 drivers/dma/map.c
arch/arm/cpu/mmu-common.c +1 -40
@@ -10,27 +10,6 @@#include <memory.h> #include "mmu.h" - -static inline dma_addr_t cpu_to_dma (struct device_d *dev,unsigned long cpu_addr) -{ -dma_addr_t dma_addr = cpu_addr; - -if (dev) - dma_addr -= dev->dma_offset; - -return dma_addr; -} - -static inline unsigned long dma_to_cpu (struct device_d *dev,dma_addr_t addr) -{ -unsigned long cpu_addr = addr; - -if (dev) - cpu_addr += dev->dma_offset; - -return cpu_addr; -} -void dma_sync_single_for_cpu (dma_addr_t address,size_t size,enum dma_data_direction dir) {
@@ -41,24 +20,6 @@ void dma_sync_single_for_cpu(dma_addr_t address, size_t size,dma_inv_range ((void *)address, size); } -dma_addr_t dma_map_single (struct device_d *dev,void *ptr,size_t size, -enum dma_data_direction dir) -{ -unsigned long addr = (unsigned long )ptr; - -dma_sync_single_for_device (addr, size, dir); - -return cpu_to_dma (dev, addr); -} - -void dma_unmap_single (struct device_d *dev,dma_addr_t dma_addr,size_t size, -enum dma_data_direction dir) -{ -unsigned long addr =dma_to_cpu (dev, dma_addr); - -dma_sync_single_for_cpu (addr, size, dir); -} -void *dma_alloc_map (size_t size,dma_addr_t *dma_handle,unsigned flags) {void *ret;
@@ -108,4 +69,4 @@ static int mmu_init(void)return 0 ; } -mmu_initcall (mmu_init); +mmu_initcall (mmu_init);
arch/arm/include/asm/dma.h +0 -11
@@ -32,17 +32,6 @@ static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle,free (mem); } -static inline dma_addr_t dma_map_single (struct device_d *dev,void *ptr,size_t size, -enum dma_data_direction dir) -{ -return (dma_addr_t )ptr; -} - -static inline void dma_unmap_single (struct device_d *dev,dma_addr_t addr,size_t size, -enum dma_data_direction dir) -{ -} -static inline void dma_sync_single_for_cpu (dma_addr_t address,size_t size,enum dma_data_direction dir) {
arch/sandbox/include/asm/dma.h +0 -11
@@ -40,17 +40,6 @@ static inline void dma_free_coherent(void *mem, dma_addr_t dma_handle,free (mem); } -static inline dma_addr_t dma_map_single (struct device_d *dev,void *ptr,size_t size, -enum dma_data_direction dir) -{ -return (dma_addr_t )ptr; -} - -static inline void dma_unmap_single (struct device_d *dev,dma_addr_t addr,size_t size, -enum dma_data_direction dir) -{ -} -static inline void dma_sync_single_for_cpu (dma_addr_t address,size_t size,enum dma_data_direction dir) {
drivers/dma/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_MXS_APBH_DMA) += apbh_dma.o +obj-$(CONFIG_HAS_DMA) += map.o
drivers/dma/map.c new file +42 -0
42 lines not on this page · raw message
Signature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 9/9] virtio: virtio-pci: restrict MIPS support to MMU configuration
In reply to Antony PavlovHello Antony,
Quoted 5 lines · Antony Pavlov
On Sun, 28 Feb 2021 20:08:36 +0100
Ahmad Fatoum <[email protected]> wrote:Hi!
Quoted 8 lines
Quoted 5 lines
MMU-less MIPS doesn't play along nicely with
VIRTIO_PCI. e.g. Reading from a virtio-rng, will return clearly bogus data. Document this in theKconfig, so no one else trips over this.Eventually, this should be fixed..
Please describe, how can I reproduce the problem.
- Apply this series on top of next, but revert this patch
- Use qemu-malta-defconfig
- Built with CONFIG_HW_RANDOM_VIRTIO=y and CONFIG_VIRTIO_PCI=y
- Run:
qemu-system-mips -m 256M -device VGA -M malta -serial stdio -monitor null \
-bios ./images/barebox-qemu-malta.img -device virtio-rng-pci,disable-legacy=on
- Execute md -s /dev/hwrng0 three times:
barebox@qemu malta:/ md -s /dev/hwrng0
00000000: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000010: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000020: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000030: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000040: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000050: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000060: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000070: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000080: 0000e632 0000000d 81ff8410 00000000 ...2............ 00000090: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000a0: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000b0: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000c0: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000d0: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000e0: 0000e632 0000000d 81ff8410 00000000 ...2............ 000000f0: 0000e632 0000000d 81ff8410 00000000 ...2............ barebox@qemu malta:/ md -s /dev/hwrng0 00000000: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000010: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000020: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000030: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000040: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000050: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000060: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000070: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000080: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 00000090: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000a0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000b0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000c0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000d0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000e0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 000000f0: 30303030 30306630 3a203030 30306536 000000f0: 0000e6 barebox@qemu malta:/ md -s /dev/hwrng0 00000000: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000010: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000020: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000030: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000040: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000050: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000060: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000070: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000080: 30303030 30306630 3a203330 33303330 000000f0: 303030 00000090: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000a0: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000b0: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000c0: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000d0: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000e0: 30303030 30306630 3a203330 33303330 000000f0: 303030 000000f0: 30303030 30306630 3a203330 33303330 000000f0: 303030
Something is clearly wrong here, but I didn't look further. If you repeat the same steps but with CONFIG_MMU=y, you will see random data as expected (You can cp /dev/hwrng0 /dev/fb0 to see for yourself that there is no obvious pattern, unlike with MMU=n).
Cheers,
Ahmad
Quoted 30 lines
Quoted 28 lines
Signed-off-by Ahmad Fatoum <[email protected]>--- drivers/virtio/Kconfig | 1 + 1 file changed, 1 insertion(+)drivers/virtio/Kconfig +1
-0@@ -28,6 +28,7 @@ config VIRTIO_MMIO config VIRTIO_PCI tristate "PCI driver for virtio devices" depends on PCI && HAS_DMA + depends on MMU && MIPS || !MIPS select VIRTIO help This driver provides support for virtio based paravirtual deviceSignature · 7 lines
2.30.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox