virtio: Introduce VirtIO driver support
Subsystems (10)
v3 cover virtio: Introduce VirtIO driver support
This series brings in VirtIO driver support in U-Boot. The work is based on Tuomas's virtio support on QEMU ARM targets.
VirtIO is a virtualization standard for network and disk device drivers where 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 U-Boot case, the guest is U-Boot itself, while the virtual environment are normally QEMU targets like ARM, RISC-V and x86.
Both VirtIO MMIO and PCI transport options are supported. Only VirtIO network and block device drivers are supported for now.
The following QEMU targets are supported.
- qemu_arm_defconfig
- qemu_arm64_defconfig
- qemu-riscv32_defconfig
- qemu-riscv64_defconfig
- qemu-x86_defconfig
- qemu-x86_64_defconfig
A new child_post_probe() uclass driver method is introduced to better support virtio device driver. This also changes BLK uclass driver to supply a post_probe() method which calls part_init(), so that we can avoid duplicating such call in every BLK driver.
Not every checkpatch warning reported was fixed, but I tried to fix as many as possible which makes sense. travis-ci build all pass.
This series is available at u-boot-x86/virtio-working for testing.
Changes in v3:
- Exclude VIRTIO_BLK in sandbox_noblk_defconfig build
Changes in v2:
- new patch to add test case for uclass driver's child_post_probe()
- new patch to add dm_remove_devices_flags() call to do_bootm_linux() for riscv bootm
- Added virtio spec link and a short statement of what virtio is in the header and source files
- Changed to use 'transport' over 'bus' in drivers/virtio/Kconfig
- Added UCLASS_VIRTIO ID in alphabetical order
- Moved the header file inclusion from virtio.h to C file
- Fixed code styling issue (blank line before return) in virtio_xxx() APIs
- Changed virtio_init() to return int if there is an error
- Added virtio_uclass_pre_probe() to check virtio transport driver ops here so that we don't need check these ops each time when the virtio_xxx APIs are called
- Implemented child_post_remove() method to reset the virtio device
- Changed virtio_driver_features_init() parameter 'feature' and 'feature_legacy' to const, and adjust member of
'struct virtio_dev_priv' accordingly
- Initialize uc_priv->vqs in virtio_uclass_post_probe()
- Changed virtio net driver feature table to const
- Correct desc->vendor for PCI transport
- imply VIRTIO_PCI for qemu-arm too
- use an internal function _dm_pci_find_next_capability() for dm_pci_find_capability() and dm_pci_find_next_capability()
- adjust swap_case driver to handle request from _dm_pci_find_next_capability()
- fix compiler warnings in 64-bit build
- adjust virtio_pci_find_capability() to avoid walking through capability list to find next one by ourselves
- new patch to add a Sandbox transport driver
- new patch to add test cases for virtio uclass
- Added driver remove and flags description in the documentation
Bin Meng (26):
dm: core: Allow uclass to set up a device's child after it is probed
test: dm: core: Add test case for uclass driver's child_post_probe()
riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()
dm: Add a new uclass driver for VirtIO transport devices
virtio: Add virtio over mmio transport driver
test: dm: blk: Correct blk_base test case
sandbox: blk: Switch to use platdata_auto_alloc_size for the driver
data
efi_driver: blk: Switch to use platdata_auto_alloc_size for the driver
data
blk: Call part_init() in the post_probe() method
blk: Drop blk_prepare_device()
blk: Make blk_next_free_devnum() public
riscv: qemu: Enumerate virtio bus during early boot
riscv: qemu: Include some useful commands
kconfig: Introduce HAVE_ARCH_IOMAP
x86: Implement arch-specific io accessor routines
virtio: Add virtio over pci transport driver
arm: qemu: Add a Kconfig in the board directory
arm: qemu: Enumerate virtio bus during early boot
x86: qemu: Imply virtio PCI transport and device drivers
dm: pci: Add APIs to find next capability and extended capability
test: dm: pci: Add cases for finding next PCI capability APIs
virtio: pci: Support non-legacy PCI transport device
virtio: net: Support non-legacy device
virtio: Add a Sandbox transport driver
test: dm: virtio: Add test cases for virtio uclass
doc: Document virtio support
Tuomas Tynkkynen (5):
virtio: Add codes for virtual queue/ring management
virtio: Add net driver support
blk: Introduce IF_TYPE_VIRTIO
virtio: Add block driver support
virtio: cmd: Add virtio command for virtio devices
arch/Kconfig | 6 + arch/arm/Kconfig | 1 + arch/riscv/lib/bootm.c | 11 +- arch/sandbox/dts/test.dts | 8 + arch/x86/include/asm/io.h | 66 +++ board/emulation/qemu-arm/Kconfig | 13 + board/emulation/qemu-arm/qemu-arm.c | 10 + board/emulation/qemu-riscv/Kconfig | 11 + board/emulation/qemu-riscv/qemu-riscv.c | 9 + board/emulation/qemu-x86/Kconfig | 3 + cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/sata.c | 9 - cmd/virtio.c | 38 ++ common/usb_storage.c | 4 +- configs/qemu_arm64_defconfig | 1 - configs/qemu_arm_defconfig | 1 - configs/sandbox_noblk_defconfig | 1 + disk/part.c | 6 + doc/README.virtio | 253 ++++++++++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/block/blk-uclass.c | 25 +- drivers/block/ide.c | 2 - drivers/block/sandbox.c | 17 +- drivers/core/uclass.c | 13 +- drivers/misc/swap_case.c | 9 + drivers/mmc/mmc.c | 3 - drivers/nvme/nvme.c | 1 - drivers/pci/pci-uclass.c | 51 ++- drivers/scsi/scsi.c | 1 - drivers/virtio/Kconfig | 62 +++ drivers/virtio/Makefile | 11 + drivers/virtio/virtio-uclass.c | 369 +++++++++++++++++ drivers/virtio/virtio_blk.c | 137 +++++++ drivers/virtio/virtio_blk.h | 129 ++++++ drivers/virtio/virtio_mmio.c | 413 +++++++++++++++++++ drivers/virtio/virtio_mmio.h | 129 ++++++ drivers/virtio/virtio_net.c | 239 +++++++++++ drivers/virtio/virtio_net.h | 268 ++++++++++++ drivers/virtio/virtio_pci.h | 173 ++++++++ drivers/virtio/virtio_pci_legacy.c | 421 +++++++++++++++++++ drivers/virtio/virtio_pci_modern.c | 609 +++++++++++++++++++++++++++ drivers/virtio/virtio_ring.c | 358 ++++++++++++++++ drivers/virtio/virtio_sandbox.c | 233 +++++++++++ include/blk.h | 22 +- include/dm/test.h | 1 + include/dm/uclass-id.h | 1 + include/dm/uclass.h | 4 +- include/linux/io.h | 4 + include/pci.h | 48 +++ include/virtio.h | 707 ++++++++++++++++++++++++++++++++ include/virtio_ring.h | 320 +++++++++++++++ include/virtio_types.h | 24 ++ lib/Kconfig | 6 + lib/efi_driver/efi_block_device.c | 26 +- test/dm/Makefile | 1 + test/dm/blk.c | 27 +- test/dm/bus.c | 45 ++ test/dm/pci.c | 20 + test/dm/test-fdt.c | 7 +- test/dm/virtio.c | 122 ++++++ 62 files changed, 5421 insertions(+), 99 deletions(-) create mode 100644 board/emulation/qemu-arm/Kconfig create mode 100644 cmd/virtio.c create mode 100644 doc/README.virtio create mode 100644 drivers/virtio/Kconfig create mode 100644 drivers/virtio/Makefile create mode 100644 drivers/virtio/virtio-uclass.c create mode 100644 drivers/virtio/virtio_blk.c create mode 100644 drivers/virtio/virtio_blk.h create mode 100644 drivers/virtio/virtio_mmio.c create mode 100644 drivers/virtio/virtio_mmio.h create mode 100644 drivers/virtio/virtio_net.c create mode 100644 drivers/virtio/virtio_net.h create mode 100644 drivers/virtio/virtio_pci.h create mode 100644 drivers/virtio/virtio_pci_legacy.c create mode 100644 drivers/virtio/virtio_pci_modern.c create mode 100644 drivers/virtio/virtio_ring.c create mode 100644 drivers/virtio/virtio_sandbox.c create mode 100644 include/virtio.h create mode 100644 include/virtio_ring.h create mode 100644 include/virtio_types.h create mode 100644 test/dm/virtio.c
Signature · 1 line
2.7.4
PATCH v3 1/31 dm: core: Allow uclass to set up a device's child after it is probed
Some buses need to set up their child devices after they are probed. Support a common child_post_probe() method for the uclass.
With this change, the two APIs uclass_pre_probe_device() and uclass_post_probe_device() become symmetric.
---
Changes in v3: None
Changes in v2: None
drivers/core/uclass.c | 13 ++++++++++++- include/dm/uclass.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/core/uclass.c +12 -1
@@ -687,8 +687,19 @@ int uclass_pre_probe_device(struct udevice *dev)int uclass_post_probe_device (struct udevice *dev) { -struct uclass_driver *uc_drv = dev->uclass->uc_drv; +struct uclass_driver *uc_drv; +int ret; + +if (dev->parent) { + uc_drv = dev->parent->uclass->uc_drv; +if (uc_drv->child_post_probe) { + ret = uc_drv->child_post_probe (dev); +if (ret) +return ret; + } + } + uc_drv = dev->uclass->uc_drv;if (uc_drv->post_probe)return uc_drv->post_probe (dev);
include/dm/uclass.h +3 -1
@@ -61,7 +61,8 @@ struct udevice;* @post_probe: Called after a new device is probed * @pre_remove: Called before a device is removed * @child_post_bind: Called after a child is bound to a device in this uclass -* @child_pre_probe: Called before a child is probed in this uclass +* @child_pre_probe: Called before a child in this uclass is probed +* @child_post_probe: Called after a child in this uclass is probed * @init: Called to set up the uclass * @destroy: Called to destroy the uclass * @priv_auto_alloc_size: If non-zero this is the size of the private data
@@ -94,6 +95,7 @@ struct uclass_driver {int (*pre_remove)(struct udevice *dev);int (*child_post_bind)(struct udevice *dev);int (*child_pre_probe)(struct udevice *dev); +int (*child_post_probe)(struct udevice *dev);int (*init)(struct uclass *class);int (*destroy)(struct uclass *class);int priv_auto_alloc_size;
Signature · 1 line
2.7.4
PATCH v3 1/31 dm: core: Allow uclass to set up a device's child after it is probed
Quoted 7 lines · Bin Meng
Some buses need to set up their child devices after they are probed. Support a common
child_post_probe()method for the uclass.With this change, the two APIs
uclass_pre_probe_device()anduclass_post_probe_device()become symmetric.Signed-off-by Bin Meng <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/core/uclass.c | 13 ++++++++++++- include/dm/uclass.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-)
PATCH v3 1/31 dm: core: Allow uclass to set up a device's child after it is probed
Quoted 7 lines · Bin Meng
Some buses need to set up their child devices after they are probed. Support a common
child_post_probe()method for the uclass.With this change, the two APIs
uclass_pre_probe_device()anduclass_post_probe_device()become symmetric.Signed-off-by Bin Meng <[email protected]>
Quoted 8 lines
---
Changes in v3: None
Changes in v2: Nonedrivers/core/uclass.c | 13 ++++++++++++- include/dm/uclass.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 2/31 test: dm: core: Add test case for uclass driver's child_post_probe()
In reply to Bin MengAdd test case to cover uclass driver's child_post_probe() method.
---
Changes in v3: None
Changes in v2:
- new patch to add test case for uclass driver's child_post_probe()
include/dm/test.h | 1 + test/dm/bus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 7 +++++-- 3 files changed, 51 insertions(+), 2 deletions(-)
include/dm/test.h +1 -0
@@ -69,6 +69,7 @@ struct dm_test_priv {int op_count[DM_TEST_OP_COUNT ];int uclass_flag;int uclass_total; +int uclass_postp; };/**
test/dm/bus.c +45 -0
60 lines not on this page · raw message
test/dm/test-fdt.c +5 -2
@@ -55,10 +55,13 @@ static int testfdt_drv_probe(struct udevice *dev)/* * If this device is on a bus, the uclass_flag will be set before -* calling this function. This is used by -* dm_test_bus_child_pre_probe_uclass(). +* calling this function. In the meantime the uclass_postp is +* initlized to a value -1. These are used respectively by +* dm_test_bus_child_pre_probe_uclass() and +* dm_test_bus_child_post_probe_uclass(). */ priv->uclass_total += priv->uclass_flag; + priv->uclass_postp =-1 ;return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 2/31 test: dm: core: Add test case for uclass driver's child_post_probe()
Quoted 6 lines · Bin Meng
Add test case to cover uclass driver's
child_post_probe()method.Signed-off-by Bin Meng <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2:
- new patch to add test case for uclass driver'schild_post_probe()include/dm/test.h | 1 + test/dm/bus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 7 +++++-- 3 files changed, 51 insertions(+), 2 deletions(-)
PATCH v3 2/31 test: dm: core: Add test case for uclass driver's child_post_probe()
Quoted 6 lines · Bin Meng
Add test case to cover uclass driver's
child_post_probe()method.Signed-off-by Bin Meng <[email protected]>---
Quoted 8 lines
Changes in v3: None
Changes in v2:
- new patch to add test case for uclass driver'schild_post_probe()include/dm/test.h | 1 + test/dm/bus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-fdt.c | 7 +++++-- 3 files changed, 51 insertions(+), 2 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 3/31 riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()
In reply to Bin MengThis adds a call to dm_remove_devices_flags() to do_bootm_linux() so that drivers that have one of the removal flags set (e.g. DM_FLAG_ACTIVE_DMA_REMOVE) in their driver struct, may do some last-stage cleanup before the OS is started.
arm and x86 already did such, and we should do the same for riscv.
---
Changes in v3: None
Changes in v2:
- new patch to add dm_remove_devices_flags() call to do_bootm_linux() for riscv bootm
arch/riscv/lib/bootm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/riscv/lib/bootm.c +10 -1
@@ -9,9 +9,11 @@#include <common.h> #include <command.h> #include <image.h> -#include <u-boot/zlib.h> #include <asm/byteorder.h> #include <asm/csr.h> +#include <dm/device.h> +#include <dm/root.h> +#include <u-boot/zlib.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -57,6 +59,13 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)/* we assume that the kernel is in place */ printf ("\nStarting kernel ...\n\n" ); +/* +* Call remove function of all devices with a removal flag set. +* This may be useful for last-stage operations, like cancelling +* of DMA operation or releasing device internal buffers. +*/ +dm_remove_devices_flags (DM_REMOVE_ACTIVE_ALL ); +cleanup_before_linux ();if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
Signature · 1 line
2.7.4
PATCH v3 3/31 riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()
Quoted 11 lines · Bin Meng
This adds a call to
dm_remove_devices_flags()todo_bootm_linux()so that drivers that have one of the removal flags set (e.g.DM_FLAG_ACTIVE_DMA_REMOVE) in their driver struct, may do some last-stage cleanup before the OS is started.arm and x86 already did such, and we should do the same for riscv.
Signed-off-by Bin Meng <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2:
- new patch to adddm_remove_devices_flags()call todo_bootm_linux()for riscv bootmarch/riscv/lib/bootm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
PATCH v3 3/31 riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()
Quoted 11 lines · Bin Meng
This adds a call to
dm_remove_devices_flags()todo_bootm_linux()so that drivers that have one of the removal flags set (e.g.DM_FLAG_ACTIVE_DMA_REMOVE) in their driver struct, may do some last-stage cleanup before the OS is started.arm and x86 already did such, and we should do the same for riscv.
Signed-off-by Bin Meng <[email protected]>---
Quoted 7 lines
Changes in v3: None
Changes in v2:
- new patch to adddm_remove_devices_flags()call todo_bootm_linux()for riscv bootmarch/riscv/lib/bootm.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 4/31 dm: Add a new uclass driver for VirtIO transport devices
In reply to Bin MengThis adds a new virtio uclass driver for “virtio” [1] family of devices that are are found in virtual environments like QEMU, yet by design they look like physical devices to the guest.
The uclass driver provides child_pre_probe() and child_post_probe() methods to do some common operations for virtio device drivers like device and driver supported feature negotiation, etc.
[1] http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf
---
Changes in v3: None
Changes in v2:
- Added virtio spec link and a short statement of what virtio is in the header and source files
- Changed to use 'transport' over 'bus' in drivers/virtio/Kconfig
- Added UCLASS_VIRTIO ID in alphabetical order
- Moved the header file inclusion from virtio.h to C file
- Fixed code styling issue (blank line before return) in virtio_xxx() APIs
- Changed virtio_init() to return int if there is an error
- Added virtio_uclass_pre_probe() to check virtio transport driver ops here so that we don't need check these ops each time when the virtio_xxx APIs are called
- Implemented child_post_remove() method to reset the virtio device
- Changed virtio_driver_features_init() parameter 'feature' and 'feature_legacy' to const, and adjust member of 'struct virtio_dev_priv' accordingly
- Initialize uc_priv->vqs in virtio_uclass_post_probe()
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/virtio/Kconfig | 25 ++ drivers/virtio/Makefile | 6 + drivers/virtio/virtio-uclass.c | 369 +++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/virtio.h | 707 +++++++++++++++++++++++++++++++++++++++++ include/virtio_types.h | 24 ++ 8 files changed, 1135 insertions(+) create mode 100644 drivers/virtio/Kconfig create mode 100644 drivers/virtio/Makefile create mode 100644 drivers/virtio/virtio-uclass.c create mode 100644 include/virtio.h create mode 100644 include/virtio_types.h
drivers/Kconfig +2 -0
@@ -112,6 +112,8 @@ source "drivers/usb/Kconfig" source "drivers/video/Kconfig" +source "drivers/virtio/Kconfig" + source "drivers/w1/Kconfig" source "drivers/w1-eeprom/Kconfig"
drivers/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_$(SPL_TPL_)SERIAL_SUPPORT) += serial/ obj-$(CONFIG_$(SPL_TPL_)SPI_FLASH_SUPPORT) += mtd/spi/ obj-$(CONFIG_$(SPL_TPL_)SPI_SUPPORT) += spi/ obj-$(CONFIG_$(SPL_TPL_)TIMER) += timer/ +obj-$(CONFIG_$(SPL_TPL_)VIRTIO) += virtio/ obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/ obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/
drivers/virtio/Kconfig new file +25 -0
@@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Tuomas Tynkkynen <[email protected]> +# Copyright (C) 2018, Bin Meng <[email protected]> +# +# VirtIO is a virtualization standard for network and disk device drivers +# where 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 U-Boot case, the guest +# is U-Boot itself, while the virtual environment are normally QEMU targets +# like ARM, RISC-V and x86. +# +# See http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf for +# the VirtIO specification v1.0. + +menu "VirtIO Drivers" + +config VIRTIO + bool + help + This option is selected by any driver which implements the virtio + transport, such as CONFIG_VIRTIO_MMIO or CONFIG_VIRTIO_PCI. + +endmenu
drivers/virtio/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Tuomas Tynkkynen <[email protected]> +# Copyright (C) 2018, Bin Meng <[email protected]> + +obj-y += virtio-uclass.o
drivers/virtio/virtio-uclass.c new file +369 -0
369 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -96,6 +96,7 @@ enum uclass_id {UCLASS_VIDEO_BRIDGE ,/* Video bridge, e.g. DisplayPort to LVDS */ UCLASS_VIDEO_CONSOLE ,/* Text console driver for video device */ UCLASS_VIDEO_OSD ,/* On-screen display */ +UCLASS_VIRTIO ,/* VirtIO transport device */ UCLASS_W1 ,/* Dallas 1-Wire bus */ UCLASS_W1_EEPROM ,/* one-wire EEPROMs */ UCLASS_WDT, /* Watchdot Timer driver */
include/virtio.h new file +707 -0
707 lines not on this page · raw message
include/virtio_types.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* +* Copyright (C) 2018, Tuomas Tynkkynen <[email protected]> +* Copyright (C) 2018, Bin Meng <[email protected]> +* +* From Linux kernel include/uapi/linux/virtio_types.h +*/ + +#ifndef _LINUX_VIRTIO_TYPES_H +#define _LINUX_VIRTIO_TYPES_H + +#include <linux/types.h> + +/* +* __virtio{16,32,64} have the following meaning: +* - __u{16,32,64} for virtio devices in legacy mode, accessed in native endian +* - __le{16,32,64} for standard-compliant virtio devices +*/ + +typedef __u16 __bitwise __virtio16 ; +typedef __u32 __bitwise __virtio32 ; +typedef __u64 __bitwise __virtio64 ; + +#endif /* _LINUX_VIRTIO_TYPES_H */
Signature · 1 line
2.7.4
PATCH v3 4/31 dm: Add a new uclass driver for VirtIO transport devices
Quoted 34 lines · Bin Meng
This adds a new virtio uclass driver for “virtio” [1] family of devices that are are found in virtual environments like QEMU, yet by design they look like physical devices to the guest.
The uclass driver provides
child_pre_probe()andchild_post_probe()methods to do some common operations for virtio device drivers like device and driver supported feature negotiation, etc.[1] http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf
Signed-off-by Tuomas Tynkkynen <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Changes in v3: None
Changes in v2:
- Added virtio spec link and a short statement of what virtio is in the header and source files
- Changed to use 'transport' over 'bus' indrivers/virtio/Kconfig
- AddedUCLASS_VIRTIOID in alphabetical order
- Moved the header file inclusion fromvirtio.hto C file
- Fixed code styling issue (blank line before return) invirtio_xxx()APIs
- Changedvirtio_init()to return int if there is an error
- Addedvirtio_uclass_pre_probe()to check virtio transport driver ops here so that we don't need check these ops each time when thevirtio_xxxAPIs are called
- Implementedchild_post_remove()method to reset the virtio device
- Changedvirtio_driver_features_init()parameter 'feature' and 'feature_legacy' to const, and adjust member of 'structvirtio_dev_priv' accordingly
- Initializeuc_priv->vqsinvirtio_uclass_post_probe()
Quoted 14 lines
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/virtio/Kconfig | 25 ++ drivers/virtio/Makefile | 6 + drivers/virtio/virtio-uclass.c | 369 +++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/virtio.h | 707 +++++++++++++++++++++++++++++++++++++++++ include/virtio_types.h | 24 ++ 8 files changed, 1135 insertions(+) create mode 100644 drivers/virtio/Kconfig create mode 100644 drivers/virtio/Makefile create mode 100644 drivers/virtio/virtio-uclass.c create mode 100644 include/virtio.h create mode 100644 include/virtio_types.h
PATCH v3 4/31 dm: Add a new uclass driver for VirtIO transport devices
Quoted 34 lines · Bin Meng
This adds a new virtio uclass driver for “virtio” [1] family of devices that are are found in virtual environments like QEMU, yet by design they look like physical devices to the guest.
The uclass driver provides
child_pre_probe()andchild_post_probe()methods to do some common operations for virtio device drivers like device and driver supported feature negotiation, etc.[1] http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf
Signed-off-by Tuomas Tynkkynen <[email protected]>Signed-off-by Bin Meng <[email protected]>---
Changes in v3: None
Changes in v2:
- Added virtio spec link and a short statement of what virtio is in the header and source files
- Changed to use 'transport' over 'bus' indrivers/virtio/Kconfig
- AddedUCLASS_VIRTIOID in alphabetical order
- Moved the header file inclusion fromvirtio.hto C file
- Fixed code styling issue (blank line before return) invirtio_xxx()APIs
- Changedvirtio_init()to return int if there is an error
- Addedvirtio_uclass_pre_probe()to check virtio transport driver ops here so that we don't need check these ops each time when thevirtio_xxxAPIs are called
- Implementedchild_post_remove()method to reset the virtio device
- Changedvirtio_driver_features_init()parameter 'feature' and 'feature_legacy' to const, and adjust member of 'structvirtio_dev_priv' accordingly
- Initializeuc_priv->vqsinvirtio_uclass_post_probe()
Quoted 14 lines
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/virtio/Kconfig | 25 ++ drivers/virtio/Makefile | 6 + drivers/virtio/virtio-uclass.c | 369 +++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/virtio.h | 707 +++++++++++++++++++++++++++++++++++++++++ include/virtio_types.h | 24 ++ 8 files changed, 1135 insertions(+) create mode 100644 drivers/virtio/Kconfig create mode 100644 drivers/virtio/Makefile create mode 100644 drivers/virtio/virtio-uclass.c create mode 100644 include/virtio.h create mode 100644 include/virtio_types.h
Applied to u-boot-dm/next, thanks!
PATCH v3 5/31 virtio: Add codes for virtual queue/ring management
In reply to Bin MengFrom: Tuomas Tynkkynen <[email protected]>
This adds support for managing virtual queue/ring, the channel for high performance I/O between host and guest.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Makefile | 2 +- drivers/virtio/virtio_ring.c | 358 +++++++++++++++++++++++++++++++++++++++++++ include/virtio_ring.h | 320 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 679 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_ring.c create mode 100644 include/virtio_ring.h
drivers/virtio/Makefile +1 -1
@@ -3,4 +3,4 @@ # Copyright (C) 2018, Tuomas Tynkkynen <[email protected]> # Copyright (C) 2018, Bin Meng <[email protected]> -obj-y += virtio-uclass.o +obj-y += virtio-uclass.o virtio_ring.o
drivers/virtio/virtio_ring.c new file +358 -0
358 lines not on this page · raw message
include/virtio_ring.h new file +320 -0
320 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 5/31 virtio: Add codes for virtual queue/ring management
From: Tuomas Tynkkynen <[email protected]>
This adds support for managing virtual queue/ring, the channel for high performance I/O between host and guest.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Makefile | 2 +- drivers/virtio/virtio_ring.c | 358 +++++++++++++++++++++++++++++++++++++++++++ include/virtio_ring.h | 320 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 679 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_ring.c create mode 100644 include/virtio_ring.h
Applied to u-boot-dm/next, thanks!
PATCH v3 6/31 virtio: Add virtio over mmio transport driver
In reply to Bin MengVirtIO can use various different buses and virtio devices are commonly implemented as PCI devices. But virtual environments without PCI support (a common situation in embedded devices models) might use simple memory mapped device (“virtio-mmio”) instead of the PCI device.
This adds a transport driver that implements UCLASS_VIRTIO for virtio over mmio.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mmio.c | 413 +++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_mmio.h | 129 ++++++++++++++ 4 files changed, 550 insertions(+) create mode 100644 drivers/virtio/virtio_mmio.c create mode 100644 drivers/virtio/virtio_mmio.h
drivers/virtio/Kconfig +7 -0
@@ -22,4 +22,11 @@ config VIRTIO This option is selected by any driver which implements the virtio transport, such as CONFIG_VIRTIO_MMIO or CONFIG_VIRTIO_PCI. +config VIRTIO_MMIO + bool "Platform bus driver for memory mapped virtio devices" + select VIRTIO + help + This driver provides support for memory mapped virtio + platform device driver. + endmenu
drivers/virtio/Makefile +1 -0
@@ -4,3 +4,4 @@ # Copyright (C) 2018, Bin Meng <[email protected]> obj-y += virtio-uclass.o virtio_ring.o +obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
drivers/virtio/virtio_mmio.c new file +413 -0
413 lines not on this page · raw message
drivers/virtio/virtio_mmio.h new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 6/31 virtio: Add virtio over mmio transport driver
VirtIO can use various different buses and virtio devices are commonly implemented as PCI devices. But virtual environments without PCI support (a common situation in embedded devices models) might use simple memory mapped device (“virtio-mmio”) instead of the PCI device.
This adds a transport driver that implements UCLASS_VIRTIO for virtio over mmio.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Kconfig | 7 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_mmio.c | 413 +++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_mmio.h | 129 ++++++++++++++ 4 files changed, 550 insertions(+) create mode 100644 drivers/virtio/virtio_mmio.c create mode 100644 drivers/virtio/virtio_mmio.h
Applied to u-boot-dm/next, thanks!
PATCH v3 7/31 virtio: Add net driver support
In reply to Bin MengFrom: Tuomas Tynkkynen <[email protected]>
This adds virtio net device driver support.
---
Changes in v3: None
Changes in v2:
- Changed virtio net driver feature table to const
drivers/virtio/Kconfig | 7 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_net.c | 218 +++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_net.h | 268 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 494 insertions(+) create mode 100644 drivers/virtio/virtio_net.c create mode 100644 drivers/virtio/virtio_net.h
drivers/virtio/Kconfig +7 -0
@@ -29,4 +29,11 @@ config VIRTIO_MMIO This driver provides support for memory mapped virtio platform device driver. +config VIRTIO_NET + bool "virtio net driver" + depends on VIRTIO + help + This is the virtual net driver for virtio. It can be used with + QEMU based targets. + endmenu
drivers/virtio/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-y += virtio-uclass.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o +obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
drivers/virtio/virtio_net.c new file +218 -0
218 lines not on this page · raw message
drivers/virtio/virtio_net.h new file +268 -0
268 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 7/31 virtio: Add net driver support
From: Tuomas Tynkkynen <[email protected]>
This adds virtio net device driver support.
---
Changes in v3: None
Changes in v2:
- Changed virtio net driver feature table to const
drivers/virtio/Kconfig | 7 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_net.c | 218 +++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_net.h | 268 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 494 insertions(+) create mode 100644 drivers/virtio/virtio_net.c create mode 100644 drivers/virtio/virtio_net.h
Applied to u-boot-dm/next, thanks!
PATCH v3 8/31 test: dm: blk: Correct blk_base test case
In reply to Bin MengThe blk_base test case creates a USB mass storage block device with the Sandbox host block device as its parent. This does not make any sense and causes potential issue, for example if the test case tries to read/write anything on the USB mass storage block device it will definitely fail as its parent is not on USB bus at all.
Correct the test case by creating another Sandbox host block device instead of the USB mass storage one and adjust the case accordingly.
---
Changes in v3: None
Changes in v2: None
test/dm/blk.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
test/dm/blk.c +11 -16
@@ -15,34 +15,29 @@ DECLARE_GLOBAL_DATA_PTR;/* Test that block devices can be created */ static int dm_test_blk_base (struct unit_test_state *uts) { -struct udevice *blk, *usb_blk, *dev; +struct udevice *blk1, *blk3, *dev;/* Make sure there are no block devices */ -ut_asserteq (-ENODEV ,uclass_get_device_by_seq (UCLASS_BLK ,0 , &blk)); +ut_asserteq (-ENODEV ,uclass_get_device_by_seq (UCLASS_BLK ,0 , &dev));/* Create two, one the parent of the other */ ut_assertok (blk_create_device (gd->dm_root,"sandbox_host_blk" ,"test" , -IF_TYPE_HOST ,1 ,512 ,2 , &blk)); -ut_assertok (blk_create_device (blk,"usb_storage_blk" ,"test" , -IF_TYPE_USB ,3 ,512 ,2 , &usb_blk)); +IF_TYPE_HOST ,1 ,512 ,2 , &blk1)); +ut_assertok (blk_create_device (blk1,"sandbox_host_blk" ,"test" , +IF_TYPE_HOST ,3 ,512 ,2 , &blk3));/* Check we can find them */ ut_asserteq (-ENODEV ,blk_get_device (IF_TYPE_HOST ,0 , &dev));ut_assertok (blk_get_device (IF_TYPE_HOST ,1 , &dev)); -ut_asserteq_ptr (blk, dev); - -ut_asserteq (-ENODEV ,blk_get_device (IF_TYPE_USB ,0 , &dev)); -ut_assertok (blk_get_device (IF_TYPE_USB ,3 , &dev)); -ut_asserteq_ptr (usb_blk, dev); +ut_asserteq_ptr (blk1, dev); +ut_assertok (blk_get_device (IF_TYPE_HOST ,3 , &dev)); +ut_asserteq_ptr (blk3, dev);/* Check we can iterate */ ut_assertok (blk_first_device (IF_TYPE_HOST , &dev)); -ut_asserteq_ptr (blk, dev); -ut_asserteq (-ENODEV ,blk_next_device (&dev)); - -ut_assertok (blk_first_device (IF_TYPE_USB , &dev)); -ut_asserteq_ptr (usb_blk, dev); -ut_asserteq (-ENODEV ,blk_next_device (&dev)); +ut_asserteq_ptr (blk1, dev); +ut_assertok (blk_next_device (&dev)); +ut_asserteq_ptr (blk3, dev);return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 8/31 test: dm: blk: Correct blk_base test case
The blk_base test case creates a USB mass storage block device with the Sandbox host block device as its parent. This does not make any sense and causes potential issue, for example if the test case tries to read/write anything on the USB mass storage block device it will definitely fail as its parent is not on USB bus at all.
Correct the test case by creating another Sandbox host block device instead of the USB mass storage one and adjust the case accordingly.
---
Changes in v3: None
Changes in v2: None
test/dm/blk.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 9/31 sandbox: blk: Switch to use platdata_auto_alloc_size for the driver data
In reply to Bin MengCurrently the sandbox block driver uses priv_auto_alloc_size for the driver data, however that's only available after the device probe phase. In order to make it accessible in an earlier phase, switch to use platdata_auto_alloc_size instead.
This patch is the prerequisite for the follow up patch of DM BLK driver changes to work with Sandbox.
---
Changes in v3: None
Changes in v2: None
drivers/block/sandbox.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/block/sandbox.c +8 -7
@@ -33,7 +33,7 @@ static unsigned long host_block_read(struct udevice *dev, unsigned long start, lbaint_t blkcnt, void *buffer) { - struct host_block_dev *host_dev = dev_get_priv(dev); + struct host_block_dev *host_dev = dev_get_platdata(dev);struct blk_desc *block_dev =dev_get_uclass_platdata (dev);#else
@@ -64,7 +64,7 @@ static unsigned long host_block_write(struct udevice *dev, unsigned long start, lbaint_t blkcnt, const void *buffer) { - struct host_block_dev *host_dev = dev_get_priv(dev); + struct host_block_dev *host_dev = dev_get_platdata(dev); struct blk_desc *block_dev = dev_get_uclass_platdata(dev); #else static unsigned long host_block_write(struct blk_desc *block_dev,
@@ -131,16 +131,17 @@ int host_dev_bind(int devnum, char *filename) os_lseek(fd, 0, OS_SEEK_END) / 512, &dev);if (ret) goto err_file; + + host_dev =dev_get_platdata (dev); + host_dev->fd = fd; + host_dev->filename = fname; + ret =device_probe (dev);if (ret) {device_unbind (dev); goto err_file; } - host_dev =dev_get_priv (dev); - host_dev->fd = fd; - host_dev->filename = fname; -return blk_prepare_device (dev); err_file:os_close (fd);
@@ -226,7 +227,7 @@ U_BOOT_DRIVER(sandbox_host_blk) = { .name = "sandbox_host_blk", .id = UCLASS_BLK, .ops = &sandbox_host_blk_ops, - .priv_auto_alloc_size = sizeof(struct host_block_dev), + .platdata_auto_alloc_size = sizeof(struct host_block_dev), };#else U_BOOT_LEGACY_BLK(sandbox_host) = {
Signature · 1 line
2.7.4
PATCH v3 9/31 sandbox: blk: Switch to use platdata_auto_alloc_size for the driver data
Currently the sandbox block driver uses priv_auto_alloc_size for the driver data, however that's only available after the device probe phase. In order to make it accessible in an earlier phase, switch to use platdata_auto_alloc_size instead.
This patch is the prerequisite for the follow up patch of DM BLK driver changes to work with Sandbox.
---
Changes in v3: None
Changes in v2: None
drivers/block/sandbox.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 10/31 efi_driver: blk: Switch to use platdata_auto_alloc_size for the driver data
In reply to Bin MengCurrently the efi block driver uses priv_auto_alloc_size for the driver data, however that's only available after the device probe phase. In order to make it accessible in an earlier phase, switch to use platdata_auto_alloc_size instead.
This patch is the prerequisite for the follow up patch of DM BLK driver changes to work with EFI loader.
---
Changes in v3: None
Changes in v2: None
lib/efi_driver/efi_block_device.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
lib/efi_driver/efi_block_device.c +12 -12
@@ -38,7 +38,7 @@* handle handle of the controller on which this driver is installed * io block io protocol proxied by this driver */ -struct efi_blk_priv { +struct efi_blk_platdata {efi_handle_t handle;struct efi_block_io *io; };
@@ -55,8 +55,8 @@ struct efi_blk_priv {static ulong efi_bl_read (struct udevice *dev,lbaint_t blknr,lbaint_t blkcnt,void *buffer) { -struct efi_blk_priv *priv = dev->priv; -struct efi_block_io *io = priv->io; +struct efi_blk_platdata *platdata =dev_get_platdata (dev); +struct efi_block_io *io = platdata->io;efi_status_t ret; EFI_PRINT("%s: read '%s', from block " LBAFU ", " LBAFU " blocks\n",
@@ -84,8 +84,8 @@ static ulong efi_bl_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,static ulong efi_bl_write (struct udevice *dev,lbaint_t blknr,lbaint_t blkcnt,const void *buffer) { -struct efi_blk_priv *priv = dev->priv; -struct efi_block_io *io = priv->io; +struct efi_blk_platdata *platdata =dev_get_platdata (dev); +struct efi_block_io *io = platdata->io;efi_status_t ret; EFI_PRINT("%s: write '%s', from block " LBAFU ", " LBAFU " blocks\n",
@@ -135,7 +135,7 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)struct efi_object *obj =efi_search_obj (handle);struct efi_block_io *io = interface;int disks; -struct efi_blk_priv *priv; +struct efi_blk_platdata *platdata;EFI_PRINT ("%s: handle %p, interface %p\n" , __func__, handle, io);
@@ -163,16 +163,16 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return -ENOENT ;/* Set the DM_FLAG_NAME_ALLOCED flag to avoid a memory leak */ device_set_name_alloced (bdev); -/* Allocate priv */ + + platdata =dev_get_platdata (bdev); + platdata->handle = handle; + platdata->io = interface; + ret =device_probe (bdev);if (ret)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name); - priv = bdev->priv; - priv->handle = handle; - priv->io = interface; - ret =blk_prepare_device (bdev);/* Create handles for the partions of the block device */
@@ -193,7 +193,7 @@ U_BOOT_DRIVER(efi_blk) = { .name = "efi_blk", .id = UCLASS_BLK, .ops = &efi_blk_ops, - .priv_auto_alloc_size = sizeof(struct efi_blk_priv), + .platdata_auto_alloc_size = sizeof(struct efi_blk_platdata), };/* EFI driver operators */
Signature · 1 line
2.7.4
PATCH v3 10/31 efi_driver: blk: Switch to use platdata_auto_alloc_size for the driver data
Currently the efi block driver uses priv_auto_alloc_size for the driver data, however that's only available after the device probe phase. In order to make it accessible in an earlier phase, switch to use platdata_auto_alloc_size instead.
This patch is the prerequisite for the follow up patch of DM BLK driver changes to work with EFI loader.
---
Changes in v3: None
Changes in v2: None
lib/efi_driver/efi_block_device.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
In reply to Bin Mengpart_init() is currently called in every DM BLK driver, either in its bind() or probe() method. However we can use the BLK uclass driver's post_probe() method to do it automatically.
Update all DM BLK drivers to adopt this change.
---
Changes in v3: None
Changes in v2: None
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)
cmd/sata.c +0 -9
@@ -51,7 +51,6 @@ int sata_probe(int devnum) {#ifdef CONFIG_AHCI struct udevice *dev; -struct udevice *blk;int rc; rc =uclass_get_device (UCLASS_AHCI , devnum, &dev);
@@ -67,14 +66,6 @@ int sata_probe(int devnum) return CMD_RET_FAILURE; } - rc =blk_get_from_parent (dev, &blk); -if (!rc) { -struct blk_desc *desc =dev_get_uclass_platdata (blk); - -if (desc->lba >0 && desc->blksz >0 ) -part_init (desc); - } -return 0 ;#else return sata_initialize () <0 ?CMD_RET_FAILURE :CMD_RET_SUCCESS ;
common/usb_storage.c +1 -3
@@ -226,9 +226,7 @@ static int usb_stor_probe_device(struct usb_device *udev) blkdev->lun = lun; ret =usb_stor_get_info (udev, data, blkdev); -if (ret ==1 ) - ret =blk_prepare_device (dev); -if (!ret) { +if (ret ==1 ) { usb_max_devs++;debug ("%s: Found device %p\n" , __func__, udev); }else {
drivers/block/blk-uclass.c +12 -0
@@ -644,8 +644,20 @@ int blk_unbind_all(int if_type)return 0 ; } +static int blk_post_probe (struct udevice *dev) +{ +#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) +struct blk_desc *desc =dev_get_uclass_platdata (dev); + +part_init (desc); +#endif + +return 0 ; +} +UCLASS_DRIVER (blk) = { .id =UCLASS_BLK , .name ="blk" , + .post_probe = blk_post_probe, .per_device_platdata_auto_alloc_size =sizeof (struct blk_desc ), };
drivers/block/ide.c +0 -2
@@ -1169,8 +1169,6 @@ static int ide_blk_probe(struct udevice *udev) BLK_REV_SIZE); desc->revision[BLK_REV_SIZE ] ='\0' ; -part_init (desc); -return 0 ; }
drivers/block/sandbox.c +1 -1
@@ -142,7 +142,7 @@ int host_dev_bind(int devnum, char *filename) goto err_file; } -return blk_prepare_device (dev); +return 0 ; err_file:os_close (fd); err:
drivers/mmc/mmc.c +0 -3
@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif return 0 ; }
drivers/nvme/nvme.c +0 -1
@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }
drivers/scsi/scsi.c +0 -1
@@ -592,7 +592,6 @@ static int do_scsi_scan_one(struct udevice *dev, int id, int lun, bool verbose)memcpy (&bdesc->vendor, &bd.vendor,sizeof (bd.vendor));memcpy (&bdesc->product, &bd.product,sizeof (bd.product));memcpy (&bdesc->revision, &bd.revision,sizeof (bd.revision)); -part_init (bdesc);if (verbose) {printf (" Device %d: " ,0 );
lib/efi_driver/efi_block_device.c +0 -2
@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name); - ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);
Signature · 1 line
2.7.4
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
part_init() is currently called in every DM BLK driver, either in its bind() or probe() method. However we can use the BLK uclass driver's post_probe() method to do it automatically.
Update all DM BLK drivers to adopt this change.
---
Changes in v3: None
Changes in v2: None
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
In reply to Bin MengQuoted 13 lines · Bin Meng
part_init()is currently called in every DM BLK driver, either in itsbind()orprobe()method. However we can use the BLK uclass driver'spost_probe()method to do it automatically.Update all DM BLK drivers to adopt this change.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: None
Quoted 10 lines
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)
Hi Bin,
sorry for this very late report on this.
I Just merged the 'v2019.01-rc1' tag into my branch and noticed that filesystem on my eMMC targets are not working anymore. Bisect showed up, that this commit breaks the stuff.
I reviewed the change a bit and i would say that all other block devices should work as known, except MMC, NVME and EFI (i do not have one, so i cannot test).
Quoted 5 lines
drivers/mmc/mmc.c +0
-0
drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 2449
Quoted 9 lines
drivers/mmc/mmc.c +0
-3@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif return 0 ; }
i changed this to:
#if (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)) && \
!defined(CONFIG_BLK)
part_init(bdesc);
#endif
Quoted 18 lines
drivers/nvme/nvme.c +0
-1@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }lib/efi_driver/efi_block_device.c +0
-0
lib/efi_driver/efi_block_device.c static int efi_bl_bind(efi_handle_t handle, void *interface) · line 178
Quoted 8 lines
lib/efi_driver/efi_block_device.c +0
-2@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name); - ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);
here i cannot see some alternative if CONFIG_BLK is enabled.
I know, everything shall be converted to DM since the deadline is quite close.
But i also think that upon this day everything should work as expected.
cheers,
Hannes
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
Hi Hannes,
Quoted 49 lines · Hannes Schmelzer
Quoted 13 lines · Bin Meng
part_init()is currently called in every DM BLK driver, either in itsbind()orprobe()method. However we can use the BLK uclass driver'spost_probe()method to do it automatically.Update all DM BLK drivers to adopt this change.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneQuoted 10 lines
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)Hi Bin,
sorry for this very late report on this.
I Just merged the 'v2019.01-rc1' tag into my branch and noticed that filesystem on my eMMC targets are not working anymore. Bisect showed up, that this commit breaks the stuff.I reviewed the change a bit and i would say that all other block devices should work as known, except MMC, NVME and EFI (i do not have one, so i cannot test).
Quoted 12 lines
drivers/mmc/mmc.c +0
-3@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif
Quoted 8 lines
drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 2449
Quoted 2 lines
drivers/mmc/mmc.c +0
-0return 0 ; }i changed this to:
#if (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)) && \ !defined(CONFIG_BLK) part_init(bdesc);#endif
I don't understand. The patch above removed 3 lines. Did you say that you added back these 3 lines with additional "!defined(CONFIG_BLK)"?
Quoted 23 lines
Quoted 23 lines
drivers/nvme/nvme.c +0
-1@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }lib/efi_driver/efi_block_device.c +0
-0@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name);
Quoted 7 lines
lib/efi_driver/efi_block_device.c static int efi_bl_bind(efi_handle_t handle, void *interface) · line 178
Quoted 5 lines
lib/efi_driver/efi_block_device.c +0
-2- ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);here i cannot see some alternative if
CONFIG_BLKis enabled.
I don't understand your comments here too...
Quoted 4 lines
I know, everything shall be converted to DM since the deadline is quite close.
But i also think that upon this day everything should work as expected.
Regards,
Bin
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
Quoted 1 line · Bin Meng
Hi Hannes,
Hi Bin,
Quoted 53 lines · Hannes Schmelzer
Quoted 52 lines · Bin Meng
Quoted 13 lines
part_init()is currently called in every DM BLK driver, either in itsbind()orprobe()method. However we can use the BLK uclass driver'spost_probe()method to do it automatically.Update all DM BLK drivers to adopt this change.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneQuoted 10 lines
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)Hi Bin,
sorry for this very late report on this.
I Just merged the 'v2019.01-rc1' tag into my branch and noticed that filesystem on my eMMC targets are not working anymore. Bisect showed up, that this commit breaks the stuff.I reviewed the change a bit and i would say that all other block devices should work as known, except MMC, NVME and EFI (i do not have one, so i cannot test).
Quoted 5 lines
drivers/mmc/mmc.c +0
-0drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 2449
Quoted 9 lines
drivers/mmc/mmc.c +0
-3@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif return 0 ; }i changed this to:
Quoted 6 lines
Quoted 4 lines
#if (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)) && \ !defined(CONFIG_BLK) part_init(bdesc);#endif
I don't understand. The patch above removed 3 lines. Did you say that you added back these 3 lines with additional "!defined(CONFIG_BLK)"?
Yes,
in case if CONFIG_BLK is disabled (meaning blk-uclass.c isn't compiled in and does therefore nothing),
the part_init(...) has to be done here.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/nvme/nvme.c +0
-1@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }lib/efi_driver/efi_block_device.c +0
-0@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name);
Quoted 8 lines
Quoted 8 lines
lib/efi_driver/efi_block_device.c static int efi_bl_bind(efi_handle_t handle, void *interface) · line 178
Quoted 5 lines
lib/efi_driver/efi_block_device.c +0
-2- ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);here i cannot see some alternative if
CONFIG_BLKis enabled.I don't understand your comments here too...
With alternative i mean, that:
If CONFIG_BLK is disabled within the code here some part_init has to be done.
Otherwise Partitions and following filesystems cannot work.
Quoted 7 lines
Quoted 5 lines
I know, everything shall be converted to DM since the deadline is quite close.
But i also think that upon this day everything should work as expected.Regards,
Bin
cheers,
Hannes
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
Hi Hannes,
Quoted 63 lines · Hannes Schmelzer
Quoted 1 line · Bin Meng
Hi Hannes,
Hi Bin,
Quoted 57 lines · Hannes Schmelzer
Quoted 56 lines · Bin Meng
Quoted 13 lines
part_init()is currently called in every DM BLK driver, either in itsbind()orprobe()method. However we can use the BLK uclass driver'spost_probe()method to do it automatically.Update all DM BLK drivers to adopt this change.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneQuoted 10 lines
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)Hi Bin,
sorry for this very late report on this.
I Just merged the 'v2019.01-rc1' tag into my branch and noticed that filesystem on my eMMC targets are not working anymore. Bisect showed up, that this commit breaks the stuff.I reviewed the change a bit and i would say that all other block devices should work as known, except MMC, NVME and EFI (i do not have one, so i cannot test).
Quoted 5 lines
drivers/mmc/mmc.c +0
-0drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 2449
Quoted 9 lines
drivers/mmc/mmc.c +0
-3@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif return 0 ; }i changed this to:
#if (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)) && \ !defined(CONFIG_BLK) part_init(bdesc);#endif
Quoted 6 lines
Quoted 2 lines
I don't understand. The patch above removed 3 lines. Did you say that you added back these 3 lines with additional "!defined(CONFIG_BLK)"?
Yes,
in case ifCONFIG_BLKis disabled (meaningblk-uclass.cisn't compiled in and does therefore nothing),
thepart_init(...)has to be done here.
OK, now I understand. But you should convert your board to use DM MMC instead. It's the right timing now.
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 19 lines
drivers/nvme/nvme.c +0
-1@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }lib/efi_driver/efi_block_device.c +0
-0lib/efi_driver/efi_block_device.c static int efi_bl_bind(efi_handle_t handle, void *interface) · line 178
Quoted 8 lines
lib/efi_driver/efi_block_device.c +0
-2@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name); - ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);here i cannot see some alternative if
CONFIG_BLKis enabled.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
I don't understand your comments here too...
With alternative i mean, that:
IfCONFIG_BLKis disabled within the code here somepart_inithas to be done.
No, this one I still don't understand. The EFI block device is a DM driver. It cannot work when CONFIG_BLK is disabled.
Quoted 6 lines
Otherwise Partitions and following filesystems cannot work.
Quoted 5 lines
Quoted 5 lines
I know, everything shall be converted to DM since the deadline is quite close.
But i also think that upon this day everything should work as expected.
Regards,
Bin
PATCH v3 11/31 blk: Call part_init() in the post_probe() method
Quoted 1 line · Bin Meng
Hi Hannes,
Hi Bin,
Quoted 56 lines
Quoted 56 lines
Quoted 56 lines · Hannes Schmelzer
Quoted 55 lines · Bin Meng
Quoted 13 lines
part_init()is currently called in every DM BLK driver, either in itsbind()orprobe()method. However we can use the BLK uclass driver'spost_probe()method to do it automatically.Update all DM BLK drivers to adopt this change.
Signed-off-by Bin Meng <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Changes in v3: None
Changes in v2: NoneQuoted 10 lines
cmd/sata.c | 9 --------- common/usb_storage.c | 4 +--- drivers/block/blk-uclass.c | 12 ++++++++++++ drivers/block/ide.c | 2 -- drivers/block/sandbox.c | 2 +- drivers/mmc/mmc.c | 3 --- drivers/nvme/nvme.c | 1 - drivers/scsi/scsi.c | 1 - lib/efi_driver/efi_block_device.c | 2 -- 9 files changed, 14 insertions(+), 22 deletions(-)Hi Bin,
sorry for this very late report on this.
I Just merged the 'v2019.01-rc1' tag into my branch and noticed that filesystem on my eMMC targets are not working anymore. Bisect showed up, that this commit breaks the stuff.I reviewed the change a bit and i would say that all other block devices should work as known, except MMC, NVME and EFI (i do not have one, so i cannot test).
Quoted 5 lines
drivers/mmc/mmc.c +0
-0drivers/mmc/mmc.c static int mmc_startup(struct mmc *mmc) · line 2449
Quoted 9 lines
drivers/mmc/mmc.c +0
-3@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc) bdesc->product[0 ] =0 ; bdesc->revision[0 ] =0 ;#endif -#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBDISK_SUPPORT ) -part_init (bdesc); -#endif return 0 ; }i changed this to:
#if (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)) && \ !defined(CONFIG_BLK) part_init(bdesc);#endif
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I don't understand. The patch above removed 3 lines. Did you say that you added back these 3 lines with additional "!defined(CONFIG_BLK)"?
Yes,
in case ifCONFIG_BLKis disabled (meaningblk-uclass.cisn't compiled in and does therefore nothing),
thepart_init(...)has to be done here.OK, now I understand. But you should convert your board to use DM MMC instead. It's the right timing now.
OK, thats already on my plan to do this since the deadline becomes closer. So we let the "bug" as it is and force people to convert more quickly ;-)
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 19 lines
drivers/nvme/nvme.c +0
-1@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)sprintf (desc->vendor,"0x%.4x" , pplat->vendor);memcpy (desc->product, ndev->serial,sizeof (ndev->serial));memcpy (desc->revision, ndev->firmware_rev,sizeof (ndev->firmware_rev)); -part_init (desc);return 0 ; }lib/efi_driver/efi_block_device.c +0
-0lib/efi_driver/efi_block_device.c static int efi_bl_bind(efi_handle_t handle, void *interface) · line 178
Quoted 8 lines
lib/efi_driver/efi_block_device.c +0
-2@@ -173,8 +173,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)return ret;EFI_PRINT ("%s: block device '%s' created\n" , __func__, bdev->name); - ret =blk_prepare_device (bdev); -/* Create handles for the partions of the block device */ disks =efi_bl_bind_partitions (handle, bdev);EFI_PRINT ("Found %d partitions\n" , disks);here i cannot see some alternative if
CONFIG_BLKis enabled.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
I don't understand your comments here too...
With alternative i mean, that:
IfCONFIG_BLKis disabled within the code here somepart_inithas to be done.No, this one I still don't understand. The EFI block device is a DM driver. It cannot work when
CONFIG_BLKis disabled.
OK. I don't catched that the EFI cannot work without DM, i just took notice that there is no "non-DM" alternative. So it is OK as it is.
PATCH v3 12/31 blk: Drop blk_prepare_device()
In reply to Bin MengWith the post_probe() changes, this API is no longer needed.
---
Changes in v3: None
Changes in v2: None
drivers/block/blk-uclass.c | 9 --------- include/blk.h | 10 ---------- 2 files changed, 19 deletions(-)
drivers/block/blk-uclass.c +0 -9
@@ -471,15 +471,6 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,return ops->erase (dev, start, blkcnt); } -int blk_prepare_device (struct udevice *dev) -{ -struct blk_desc *desc =dev_get_uclass_platdata (dev); - -part_init (desc); - -return 0 ; -} -int blk_get_from_parent (struct udevice *parent,struct udevice **devp) {struct udevice *dev;
include/blk.h +0 -10
@@ -357,16 +357,6 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name, lbaint_t lba, struct udevice **devp);/** -* blk_prepare_device() - Prepare a block device for use -* -* This reads partition information from the device if supported. -* -* @dev: Device to prepare -* @return 0 if ok, -ve on error -*/ -int blk_prepare_device (struct udevice *dev); - -/** * blk_unbind_all() - Unbind all device of the given interface type * * The devices are removed and then unbound.
Signature · 1 line
2.7.4
PATCH v3 12/31 blk: Drop blk_prepare_device()
With the post_probe() changes, this API is no longer needed.
---
Changes in v3: None
Changes in v2: None
drivers/block/blk-uclass.c | 9 --------- include/blk.h | 10 ---------- 2 files changed, 19 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 13/31 blk: Make blk_next_free_devnum() public
In reply to Bin Mengblk_next_free_devnum() can be helpful in some cases. Make it a public API.
---
Changes in v3: None
Changes in v2: None
drivers/block/blk-uclass.c | 2 +- include/blk.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
drivers/block/blk-uclass.c +1 -1
@@ -517,7 +517,7 @@ int blk_find_max_devnum(enum if_type if_type)return max_devnum; } -static int blk_next_free_devnum (enum if_type if_type) +int blk_next_free_devnum (enum if_type if_type) {int ret;
include/blk.h +11 -0
@@ -379,6 +379,17 @@ int blk_unbind_all(int if_type);int blk_find_max_devnum (enum if_type if_type);/** +* blk_next_free_devnum() - get the next device number for an interface type +* +* Finds the next number that is safe to use for a newly allocated device for +* an interface type @if_type. +* +* @if_type: Interface type to scan +* @return next device number safe to use, or -ve on error +*/ +int blk_next_free_devnum (enum if_type if_type); + +/** * blk_select_hwpart() - select a hardware partition * * Select a hardware partition if the device supports it (typically MMC does)
Signature · 1 line
2.7.4
PATCH v3 13/31 blk: Make blk_next_free_devnum() public
blk_next_free_devnum() can be helpful in some cases. Make it a public API.
---
Changes in v3: None
Changes in v2: None
drivers/block/blk-uclass.c | 2 +- include/blk.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 14/31 blk: Introduce IF_TYPE_VIRTIO
In reply to Bin MengFrom: Tuomas Tynkkynen <[email protected]>
This adds a new block interface type for VirtIO block devices.
---
Changes in v3: None
Changes in v2: None
disk/part.c | 6 ++++++ drivers/block/blk-uclass.c | 2 ++ include/blk.h | 1 + 3 files changed, 9 insertions(+)
disk/part.c +6 -0
@@ -150,6 +150,9 @@ void dev_print (struct blk_desc *dev_desc) dev_desc->revision, dev_desc->product);break ; +case IF_TYPE_VIRTIO : +printf ("%s VirtIO Block Device\n" , dev_desc->vendor); +break ;case IF_TYPE_DOC :puts ("device type DOC\n" );return ;
@@ -281,6 +284,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc)case IF_TYPE_NVME :puts ("NVMe" );break ; +case IF_TYPE_VIRTIO : +puts ("VirtIO" ); +break ;default :puts ("UNKNOWN" );break ;
drivers/block/blk-uclass.c +2 -0
@@ -23,6 +23,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = { [IF_TYPE_HOST] = "host", [IF_TYPE_NVME] = "nvme", [IF_TYPE_EFI] = "efi", + [IF_TYPE_VIRTIO] = "virtio", };static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT ] = {
@@ -37,6 +38,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = { [IF_TYPE_HOST] = UCLASS_ROOT, [IF_TYPE_NVME] = UCLASS_NVME, [IF_TYPE_EFI] = UCLASS_EFI, + [IF_TYPE_VIRTIO] = UCLASS_VIRTIO, };static enum if_type if_typename_to_iftype (const char *if_typename)
include/blk.h +1 -0
@@ -33,6 +33,7 @@ enum if_type {IF_TYPE_HOST ,IF_TYPE_NVME ,IF_TYPE_EFI , +IF_TYPE_VIRTIO , IF_TYPE_COUNT, /* Number of interface types */ };
Signature · 1 line
2.7.4
PATCH v3 14/31 blk: Introduce IF_TYPE_VIRTIO
From: Tuomas Tynkkynen <[email protected]>
This adds a new block interface type for VirtIO block devices.
---
Changes in v3: None
Changes in v2: None
disk/part.c | 6 ++++++ drivers/block/blk-uclass.c | 2 ++ include/blk.h | 1 + 3 files changed, 9 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 15/31 virtio: Add block driver support
In reply to Bin MengFrom: Tuomas Tynkkynen <[email protected]>
This adds virtio block device driver support.
---
Changes in v3: None
Changes in v2:
- Correct desc->vendor for PCI transport
drivers/virtio/Kconfig | 7 +++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_blk.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_blk.h | 129 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 drivers/virtio/virtio_blk.c create mode 100644 drivers/virtio/virtio_blk.h
drivers/virtio/Kconfig +7 -0
@@ -36,4 +36,11 @@ config VIRTIO_NET This is the virtual net driver for virtio. It can be used with QEMU based targets. +config VIRTIO_BLK + bool "virtio block driver" + depends on VIRTIO + help + This is the virtual block driver for virtio. It can be used with + QEMU based targets. + endmenu
drivers/virtio/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-y += virtio-uclass.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o +obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
drivers/virtio/virtio_blk.c new file +137 -0
137 lines not on this page · raw message
drivers/virtio/virtio_blk.h new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 15/31 virtio: Add block driver support
From: Tuomas Tynkkynen <[email protected]>
This adds virtio block device driver support.
---
Changes in v3: None
Changes in v2:
- Correct desc->vendor for PCI transport
drivers/virtio/Kconfig | 7 +++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_blk.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_blk.h | 129 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 drivers/virtio/virtio_blk.c create mode 100644 drivers/virtio/virtio_blk.h
Applied to u-boot-dm/next, thanks!
PATCH v3 16/31 virtio: cmd: Add virtio command for virtio devices
In reply to Bin MengFrom: Tuomas Tynkkynen <[email protected]>
Add 'virtio' command in U-Boot command line.
---
Changes in v3: None
Changes in v2: None
cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/virtio.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 cmd/virtio.c
cmd/Kconfig +7 -0
@@ -1065,6 +1065,13 @@ config CMD_USB_MASS_STORAGE help USB mass storage support +config CMD_VIRTIO + bool "virtio" + depends on VIRTIO + default y if VIRTIO + help + VirtIO block device support + config CMD_AXI bool "axi" depends on AXI
cmd/Makefile +1 -0
@@ -136,6 +136,7 @@ obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_UBIFS) += ubifs.o obj-$(CONFIG_CMD_UNIVERSE) += universe.o obj-$(CONFIG_CMD_UNZIP) += unzip.o +obj-$(CONFIG_CMD_VIRTIO) += virtio.o obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o obj-$(CONFIG_CMD_USB) += usb.o disk.o
cmd/virtio.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2018, Tuomas Tynkkynen <[email protected]> +* Copyright (C) 2018, Bin Meng <[email protected]> +*/ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <virtio_types.h> +#include <virtio.h> + +static int virtio_curr_dev; + +static int do_virtio (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +if (argc ==2 && !strcmp (argv[1 ],"scan" )) { +/* make sure all virtio devices are enumerated */ +virtio_init (); + +return CMD_RET_SUCCESS ; + } + +return blk_common_cmd (argc, argv,IF_TYPE_VIRTIO , &virtio_curr_dev); +} + +U_BOOT_CMD ( + virtio,8 ,1 , do_virtio, +"virtio block devices sub-system" , +"scan - initialize virtio bus\n" +"virtio info - show all available virtio block devices\n" +"virtio device [dev] - show or set current virtio block device\n" +"virtio part [dev] - print partition table of one or all virtio block devices\n" +"virtio read addr blk# cnt - read `cnt' blocks starting at block\n" +" `blk#' to memory address `addr'\n" +"virtio write addr blk# cnt - write `cnt' blocks starting at block\n" +" `blk#' from memory address `addr'" +);
Signature · 1 line
2.7.4
PATCH v3 16/31 virtio: cmd: Add virtio command for virtio devices
From: Tuomas Tynkkynen <[email protected]>
Add 'virtio' command in U-Boot command line.
---
Changes in v3: None
Changes in v2: None
cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/virtio.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 cmd/virtio.c
Applied to u-boot-dm/next, thanks!
PATCH v3 17/31 riscv: qemu: Enumerate virtio bus during early boot
In reply to Bin MengCurrently devices on the virtio bus is not automatically enumerated, which means peripherals on the virtio bus are not discovered by their drivers. This uses board_init() to do the virtio enumeration.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-riscv/Kconfig | 3 +++ board/emulation/qemu-riscv/qemu-riscv.c | 9 +++++++++ 2 files changed, 12 insertions(+)
board/emulation/qemu-riscv/Kconfig +3 -0
@@ -18,5 +18,8 @@ config SYS_TEXT_BASE config BOARD_SPECIFIC_OPTIONS # dummy def_bool y imply SYS_NS16550 + imply VIRTIO_MMIO + imply VIRTIO_NET + imply VIRTIO_BLK endif
board/emulation/qemu-riscv/qemu-riscv.c +9 -0
@@ -4,12 +4,21 @@*/ #include <common.h> +#include <dm.h> #include <fdtdec.h> +#include <virtio_types.h> +#include <virtio.h> #define MROM_FDT_ADDR 0x1020int board_init (void ) { +/* +* Make sure virtio bus is enumerated so that peripherals +* on the virtio bus can be discovered by their drivers +*/ +virtio_init (); +return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 17/31 riscv: qemu: Enumerate virtio bus during early boot
Currently devices on the virtio bus is not automatically enumerated, which means peripherals on the virtio bus are not discovered by their drivers. This uses board_init() to do the virtio enumeration.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-riscv/Kconfig | 3 +++ board/emulation/qemu-riscv/qemu-riscv.c | 9 +++++++++ 2 files changed, 12 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 18/31 riscv: qemu: Include some useful commands
In reply to Bin MengWith the virtio net and blk drivers, we can do more stuff with some useful commands. Imply those in the board Kconfig.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-riscv/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
board/emulation/qemu-riscv/Kconfig +8 -0
@@ -21,5 +21,13 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply VIRTIO_MMIO imply VIRTIO_NET imply VIRTIO_BLK + imply CMD_PING + imply CMD_FS_GENERIC + imply DOS_PARTITION + imply EFI_PARTITION + imply ISO_PARTITION + imply CMD_EXT2 + imply CMD_EXT4 + imply CMD_FAT endif
Signature · 1 line
2.7.4
PATCH v3 18/31 riscv: qemu: Include some useful commands
With the virtio net and blk drivers, we can do more stuff with some useful commands. Imply those in the board Kconfig.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-riscv/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 19/31 kconfig: Introduce HAVE_ARCH_IOMAP
In reply to Bin MengIntroduce a new Kconfig option for architecture codes to control whether it provides io{read,write}{8,16,32} I/O accessor functions.
---
Changes in v3: None
Changes in v2: None
include/linux/io.h | 4 ++++ lib/Kconfig | 6 ++++++ 2 files changed, 10 insertions(+)
include/linux/io.h +4 -0
@@ -7,6 +7,7 @@#include <linux/types.h> #include <asm/io.h> +#ifndef CONFIG_HAVE_ARCH_IOMAP static inline u8 ioread8 (const volatile void __iomem *addr) {return readb (addr);
@@ -21,6 +22,7 @@ static inline u32 ioread32(const volatile void __iomem *addr) {return readl (addr); } +#endif /* !CONFIG_HAVE_ARCH_IOMAP */ #ifdef CONFIG_64BIT static inline u64 ioread64 (const volatile void __iomem *addr)
@@ -29,6 +31,7 @@ static inline u64 ioread64(const volatile void __iomem *addr) }#endif /* CONFIG_64BIT */ +#ifndef CONFIG_HAVE_ARCH_IOMAP static inline void iowrite8 (u8 value,volatile void __iomem *addr) {writeb (value, addr);
@@ -43,6 +46,7 @@ static inline void iowrite32(u32 value, volatile void __iomem *addr) {writel (value, addr); } +#endif /* !CONFIG_HAVE_ARCH_IOMAP */ #ifdef CONFIG_64BIT static inline void iowrite64 (u64 value,volatile void __iomem *addr)
lib/Kconfig +6 -0
@@ -21,6 +21,12 @@ config DYNAMIC_CRC_TABLE Enable this option to calculate entries for CRC tables at runtime. This can be helpful when reducing the size of the build image +config HAVE_ARCH_IOMAP + bool + help + Enable this option if architecture provides io{read,write}{8,16,32} + I/O accessor functions. + config HAVE_PRIVATE_LIBGCC bool
Signature · 1 line
2.7.4
PATCH v3 19/31 kconfig: Introduce HAVE_ARCH_IOMAP
Introduce a new Kconfig option for architecture codes to control whether it provides io{read,write}{8,16,32} I/O accessor functions.
---
Changes in v3: None
Changes in v2: None
include/linux/io.h | 4 ++++ lib/Kconfig | 6 ++++++ 2 files changed, 10 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 20/31 x86: Implement arch-specific io accessor routines
In reply to Bin MengAt present the generic io{read,write}{8,16,32} routines only support MMIO access. With architecture like x86 that has a separate IO space, these routines cannot be used to access I/O ports.
Implement x86-specific version to support both PIO and MMIO access, so that drivers for multiple architectures can use these accessors without the need to know whether it's MMIO or PIO.
These are ported from Linux kernel lib/iomap.c, with slight changes.
---
Changes in v3: None
Changes in v2: None
arch/Kconfig | 1 + arch/x86/include/asm/io.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
arch/Kconfig +1 -0
@@ -120,6 +120,7 @@ config X86 select CREATE_ARCH_SYMLINK select DM select DM_PCI + select HAVE_ARCH_IOMAP select HAVE_PRIVATE_LIBGCC select OF_CONTROL select PCI
arch/x86/include/asm/io.h +66 -0
72 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 20/31 x86: Implement arch-specific io accessor routines
At present the generic io{read,write}{8,16,32} routines only support MMIO access. With architecture like x86 that has a separate IO space, these routines cannot be used to access I/O ports.
Implement x86-specific version to support both PIO and MMIO access, so that drivers for multiple architectures can use these accessors without the need to know whether it's MMIO or PIO.
These are ported from Linux kernel lib/iomap.c, with slight changes.
---
Changes in v3: None
Changes in v2: None
arch/Kconfig | 1 + arch/x86/include/asm/io.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 21/31 virtio: Add virtio over pci transport driver
In reply to Bin MengThis adds a transport driver that implements UCLASS_VIRTIO for virtio over pci, which is commonly used on x86.
It only supports the legacy interface of the pci transport, which is the default device that QEMU emulates.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Kconfig | 8 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_pci.c | 421 ++++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_pci.h | 173 ++++++++++++++++++ 4 files changed, 603 insertions(+) create mode 100644 drivers/virtio/virtio_pci.c create mode 100644 drivers/virtio/virtio_pci.h
drivers/virtio/Kconfig +8 -0
@@ -29,6 +29,14 @@ config VIRTIO_MMIO This driver provides support for memory mapped virtio platform device driver. +config VIRTIO_PCI + bool "PCI driver for virtio devices" + depends on DM_PCI + select VIRTIO + help + This driver provides support for virtio based paravirtual device + drivers over PCI. + config VIRTIO_NET bool "virtio net driver" depends on VIRTIO
drivers/virtio/Makefile +1 -0
@@ -5,5 +5,6 @@ obj-y += virtio-uclass.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o +obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
drivers/virtio/virtio_pci.c new file +421 -0
421 lines not on this page · raw message
drivers/virtio/virtio_pci.h new file +173 -0
173 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 21/31 virtio: Add virtio over pci transport driver
This adds a transport driver that implements UCLASS_VIRTIO for virtio over pci, which is commonly used on x86.
It only supports the legacy interface of the pci transport, which is the default device that QEMU emulates.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/Kconfig | 8 + drivers/virtio/Makefile | 1 + drivers/virtio/virtio_pci.c | 421 ++++++++++++++++++++++++++++++++++++++++++++ drivers/virtio/virtio_pci.h | 173 ++++++++++++++++++ 4 files changed, 603 insertions(+) create mode 100644 drivers/virtio/virtio_pci.c create mode 100644 drivers/virtio/virtio_pci.h
Applied to u-boot-dm/next, thanks!
PATCH v3 22/31 arm: qemu: Add a Kconfig in the board directory
In reply to Bin MengThis adds a Kconfig file in the board directory, so that some board-specific options can be specified there.
---
Changes in v3: None
Changes in v2: None
arch/arm/Kconfig | 1 + board/emulation/qemu-arm/Kconfig | 9 +++++++++ configs/qemu_arm64_defconfig | 1 - configs/qemu_arm_defconfig | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 board/emulation/qemu-arm/Kconfig
arch/arm/Kconfig +1 -0
@@ -1474,6 +1474,7 @@ source "board/broadcom/bcmns2/Kconfig" source "board/cavium/thunderx/Kconfig" source "board/cirrus/edb93xx/Kconfig" source "board/eets/pdu001/Kconfig" +source "board/emulation/qemu-arm/Kconfig" source "board/freescale/ls2080a/Kconfig" source "board/freescale/ls2080aqds/Kconfig" source "board/freescale/ls2080ardb/Kconfig"
board/emulation/qemu-arm/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT + +config SYS_TEXT_BASE + default 0x00000000 + +config BOARD_SPECIFIC_OPTIONS # dummy + def_bool y + +endif
configs/qemu_arm64_defconfig +0 -1
@@ -1,7 +1,6 @@ CONFIG_ARM=y CONFIG_ARM_SMCCC=y CONFIG_ARCH_QEMU=y -CONFIG_SYS_TEXT_BASE=0x00000000 CONFIG_TARGET_QEMU_ARM_64BIT=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y
configs/qemu_arm_defconfig +0 -1
@@ -1,7 +1,6 @@ CONFIG_ARM=y CONFIG_ARM_SMCCC=y CONFIG_ARCH_QEMU=y -CONFIG_SYS_TEXT_BASE=0x00000000 CONFIG_TARGET_QEMU_ARM_32BIT=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y
Signature · 1 line
2.7.4
PATCH v3 22/31 arm: qemu: Add a Kconfig in the board directory
This adds a Kconfig file in the board directory, so that some board-specific options can be specified there.
---
Changes in v3: None
Changes in v2: None
arch/arm/Kconfig | 1 + board/emulation/qemu-arm/Kconfig | 9 +++++++++ configs/qemu_arm64_defconfig | 1 - configs/qemu_arm_defconfig | 1 - 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 board/emulation/qemu-arm/Kconfig
Applied to u-boot-dm/next, thanks!
PATCH v3 23/31 arm: qemu: Enumerate virtio bus during early boot
In reply to Bin MengCurrently devices on the virtio bus is not automatically enumerated, which means peripherals on the virtio bus are not discovered by their drivers. This uses board_init() to do the virtio enumeration.
---
Changes in v3: None
Changes in v2:
- imply VIRTIO_PCI for qemu-arm too
board/emulation/qemu-arm/Kconfig | 4 ++++ board/emulation/qemu-arm/qemu-arm.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
board/emulation/qemu-arm/Kconfig +4 -0
@@ -5,5 +5,9 @@ config SYS_TEXT_BASE config BOARD_SPECIFIC_OPTIONS # dummy def_bool y + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK endif
board/emulation/qemu-arm/qemu-arm.c +10 -0
@@ -2,8 +2,12 @@/* * Copyright (c) 2017 Tuomas Tynkkynen */ +#include <common.h> +#include <dm.h> #include <fdtdec.h> +#include <virtio_types.h> +#include <virtio.h> #ifdef CONFIG_ARM64 #include <asm/armv8/mmu.h>
@@ -58,6 +62,12 @@ struct mm_region *mem_map = qemu_arm64_mem_map;int board_init (void ) { +/* +* Make sure virtio bus is enumerated so that peripherals +* on the virtio bus can be discovered by their drivers +*/ +virtio_init (); +return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 23/31 arm: qemu: Enumerate virtio bus during early boot
Currently devices on the virtio bus is not automatically enumerated, which means peripherals on the virtio bus are not discovered by their drivers. This uses board_init() to do the virtio enumeration.
---
Changes in v3: None
Changes in v2:
- imply VIRTIO_PCI for qemu-arm too
board/emulation/qemu-arm/Kconfig | 4 ++++ board/emulation/qemu-arm/qemu-arm.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 24/31 x86: qemu: Imply virtio PCI transport and device drivers
In reply to Bin MengAdd virtio drivers for QEMU x86 targets.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-x86/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
board/emulation/qemu-x86/Kconfig +3 -0
@@ -21,5 +21,8 @@ config BOARD_SPECIFIC_OPTIONS # dummy select X86_RESET_VECTOR select QEMU select BOARD_ROMSIZE_KB_1024 + imply VIRTIO_PCI + imply VIRTIO_NET + imply VIRTIO_BLK endif
Signature · 1 line
2.7.4
PATCH v3 24/31 x86: qemu: Imply virtio PCI transport and device drivers
Add virtio drivers for QEMU x86 targets.
---
Changes in v3: None
Changes in v2: None
board/emulation/qemu-x86/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 25/31 dm: pci: Add APIs to find next capability and extended capability
In reply to Bin MengThis introduces two new APIs dm_pci_find_next_capability() and dm_pci_find_next_ext_capability() to get PCI capability address and PCI express extended capability address for a given PCI device starting from a given offset.
---
Changes in v3: None
Changes in v2:
- use an internal function _dm_pci_find_next_capability() for dm_pci_find_capability() and dm_pci_find_next_capability()
drivers/pci/pci-uclass.c | 51 ++++++++++++++++++++++++++++++++++-------------- include/pci.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 15 deletions(-)
drivers/pci/pci-uclass.c +36 -15
@@ -1318,26 +1318,14 @@ void *dm_pci_map_bar(struct udevice *dev, int bar, int flags)return dm_pci_bus_to_virt (dev, pci_bus_addr, flags,0 ,MAP_NOCACHE ); } -int dm_pci_find_capability (struct udevice *dev,int cap) +static int _dm_pci_find_next_capability (struct udevice *dev,u8 pos,int cap) { -u16 status; -u8 header_type;int ttl =PCI_FIND_CAP_TTL ;u8 id;u16 ent; -u8 pos; - -dm_pci_read_config16 (dev,PCI_STATUS , &status); -if (!(status &PCI_STATUS_CAP_LIST )) -return 0 ; - -dm_pci_read_config8 (dev,PCI_HEADER_TYPE , &header_type); -if ((header_type &0x7f ) ==PCI_HEADER_TYPE_CARDBUS ) - pos =PCI_CB_CAPABILITY_LIST ; -else - pos =PCI_CAPABILITY_LIST ;dm_pci_read_config8 (dev, pos, &pos); +while (ttl--) {if (pos <PCI_STD_HEADER_SIZEOF )break ;
@@ -1355,7 +1343,32 @@ int dm_pci_find_capability(struct udevice *dev, int cap)return 0 ; } -int dm_pci_find_ext_capability (struct udevice *dev,int cap) +int dm_pci_find_next_capability (struct udevice *dev,u8 start,int cap) +{ +return _dm_pci_find_next_capability (dev, start +PCI_CAP_LIST_NEXT , + cap); +} + +int dm_pci_find_capability (struct udevice *dev,int cap) +{ +u16 status; +u8 header_type; +u8 pos; + +dm_pci_read_config16 (dev,PCI_STATUS , &status); +if (!(status &PCI_STATUS_CAP_LIST )) +return 0 ; + +dm_pci_read_config8 (dev,PCI_HEADER_TYPE , &header_type); +if ((header_type &0x7f ) ==PCI_HEADER_TYPE_CARDBUS ) + pos =PCI_CB_CAPABILITY_LIST ; +else + pos =PCI_CAPABILITY_LIST ; + +return _dm_pci_find_next_capability (dev, pos, cap); +} + +int dm_pci_find_next_ext_capability (struct udevice *dev,int start,int cap) {u32 header;int ttl;
@@ -1364,6 +1377,9 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)/* minimum 8 bytes per capability */ ttl = (PCI_CFG_SPACE_EXP_SIZE -PCI_CFG_SPACE_SIZE ) /8 ; +if (start) + pos = start; +dm_pci_read_config32 (dev, pos, &header);/* * If we have no capabilities, this is indicated by cap ID,
@@ -1386,6 +1402,11 @@ int dm_pci_find_ext_capability(struct udevice *dev, int cap)return 0 ; } +int dm_pci_find_ext_capability (struct udevice *dev,int cap) +{ +return dm_pci_find_next_ext_capability (dev,0 , cap); +} +UCLASS_DRIVER (pci) = { .id =UCLASS_PCI , .name ="pci" ,
include/pci.h +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 25/31 dm: pci: Add APIs to find next capability and extended capability
This introduces two new APIs dm_pci_find_next_capability() and dm_pci_find_next_ext_capability() to get PCI capability address and PCI express extended capability address for a given PCI device starting from a given offset.
---
Changes in v3: None
Changes in v2:
- use an internal function _dm_pci_find_next_capability() for dm_pci_find_capability() and dm_pci_find_next_capability()
drivers/pci/pci-uclass.c | 51 ++++++++++++++++++++++++++++++++++-------------- include/pci.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 15 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 26/31 test: dm: pci: Add cases for finding next PCI capability APIs
In reply to Bin MengAdd test cases to cover the two newly added PCI APIs:dm_pci_find_next_capability() & dm_pci_find_next_ext_capability().
---
Changes in v3: None
Changes in v2:
- adjust swap_case driver to handle request from
_dm_pci_find_next_capability()
drivers/misc/swap_case.c | 9 +++++++++ test/dm/pci.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+)
drivers/misc/swap_case.c +9 -0
@@ -124,12 +124,21 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset,case PCI_CAP_ID_PM_OFFSET : *valuep = (PCI_CAP_ID_EXP_OFFSET <<8 ) |PCI_CAP_ID_PM ;break ; +case PCI_CAP_ID_PM_OFFSET +PCI_CAP_LIST_NEXT : + *valuep =PCI_CAP_ID_EXP_OFFSET ; +break ;case PCI_CAP_ID_EXP_OFFSET : *valuep = (PCI_CAP_ID_MSIX_OFFSET <<8 ) |PCI_CAP_ID_EXP ;break ; +case PCI_CAP_ID_EXP_OFFSET +PCI_CAP_LIST_NEXT : + *valuep =PCI_CAP_ID_MSIX_OFFSET ; +break ;case PCI_CAP_ID_MSIX_OFFSET : *valuep =PCI_CAP_ID_MSIX ;break ; +case PCI_CAP_ID_MSIX_OFFSET +PCI_CAP_LIST_NEXT : + *valuep =0 ; +break ;case PCI_EXT_CAP_ID_ERR_OFFSET : *valuep = (PCI_EXT_CAP_ID_VC_OFFSET <<20 ) |PCI_EXT_CAP_ID_ERR ;break ;
test/dm/pci.c +20 -0
@@ -206,6 +206,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts) cap =dm_pci_find_capability (swap,PCI_CAP_ID_PCIX );ut_asserteq (0 , cap); +/* look up PCI_CAP_ID_MSIX starting from PCI_CAP_ID_PM_OFFSET */ + cap =dm_pci_find_next_capability (swap,PCI_CAP_ID_PM_OFFSET , +PCI_CAP_ID_MSIX ); +ut_asserteq (PCI_CAP_ID_MSIX_OFFSET , cap); + +/* look up PCI_CAP_ID_VNDR starting from PCI_CAP_ID_EXP_OFFSET */ + cap =dm_pci_find_next_capability (swap,PCI_CAP_ID_EXP_OFFSET , +PCI_CAP_ID_VNDR ); +ut_asserteq (0 , cap); +ut_assertok (uclass_get_device_by_seq (UCLASS_PCI ,1 , &bus));ut_assertok (dm_pci_bus_find_bdf (PCI_BDF (1 ,0x08 ,0 ), &swap));
@@ -217,6 +227,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts) cap =dm_pci_find_ext_capability (swap,PCI_EXT_CAP_ID_SRIOV );ut_asserteq (0 , cap); +/* look up PCI_EXT_CAP_ID_DSN starting from PCI_EXT_CAP_ID_ERR_OFFSET */ + cap =dm_pci_find_next_ext_capability (swap,PCI_EXT_CAP_ID_ERR_OFFSET , +PCI_EXT_CAP_ID_DSN ); +ut_asserteq (PCI_EXT_CAP_ID_DSN_OFFSET , cap); + +/* look up PCI_EXT_CAP_ID_RCRB starting from PCI_EXT_CAP_ID_VC_OFFSET */ + cap =dm_pci_find_next_ext_capability (swap,PCI_EXT_CAP_ID_VC_OFFSET , +PCI_EXT_CAP_ID_RCRB ); +ut_asserteq (0 , cap); +return 0 ; }DM_TEST (dm_test_pci_cap,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.7.4
PATCH v3 26/31 test: dm: pci: Add cases for finding next PCI capability APIs
Add test cases to cover the two newly added PCI APIs:dm_pci_find_next_capability() & dm_pci_find_next_ext_capability().
---
Changes in v3: None
Changes in v2:
- adjust swap_case driver to handle request from
_dm_pci_find_next_capability()
drivers/misc/swap_case.c | 9 +++++++++ test/dm/pci.c | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+)
Applied to u-boot-dm/next, thanks!
PATCH v3 27/31 virtio: pci: Support non-legacy PCI transport device
In reply to Bin MengBy default QEMU creates legacy PCI transport devices, but we can ask QEMU to create non-legacy one if we pass additional device property/value pairs in the command line:
-device virtio-blk-pci,disable-legacy=true,disable-modern=false
This adds a new driver driver to support non-legacy (modern) device mode. Previous driver/file name is changed accordingly.
---
Changes in v3: None
Changes in v2:
- fix compiler warnings in 64-bit build
- adjust virtio_pci_find_capability() to avoid walking through capability list to find next one by ourselves
drivers/virtio/Makefile | 2 +-
.../virtio/{virtio_pci.c => virtio_pci_legacy.c} | 6 +-
drivers/virtio/virtio_pci_modern.c | 609 +++++++++++++++++++++
3 files changed, 613 insertions(+), 4 deletions(-)
rename drivers/virtio/{virtio_pci.c => virtio_pci_legacy.c} (98%)
create mode 100644 drivers/virtio/virtio_pci_modern.cdrivers/virtio/Makefile +1 -1
@@ -5,6 +5,6 @@ obj-y += virtio-uclass.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o -obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o +obj-$(CONFIG_VIRTIO_PCI) += virtio_pci_legacy.o virtio_pci_modern.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
drivers/virtio/virtio_pci_legacy.c renamed from drivers/virtio/virtio_pci.c +3 -3
@@ -16,7 +16,7 @@#include <linux/io.h> #include "virtio_pci.h" -#define VIRTIO_PCI_DRV_NAME "virtio-pci" +#define VIRTIO_PCI_DRV_NAME "virtio-pci.l"/* PCI device ID in the range 0x1000 to 0x103f */ #define VIRTIO_PCI_VENDOR_ID 0x1af4
@@ -341,7 +341,7 @@ static const struct dm_virtio_ops virtio_pci_ops = { .notify = virtio_pci_notify, }; -U_BOOT_DRIVER (virtio_pci) = { +U_BOOT_DRIVER (virtio_pci_legacy) = { .name =VIRTIO_PCI_DRV_NAME , .id =UCLASS_VIRTIO , .ops = &virtio_pci_ops,
@@ -418,4 +418,4 @@ static struct pci_device_id virtio_pci_supported[] = { {}, }; -U_BOOT_PCI_DEVICE (virtio_pci, virtio_pci_supported); +U_BOOT_PCI_DEVICE (virtio_pci_legacy, virtio_pci_supported);
drivers/virtio/virtio_pci_modern.c new file +609 -0
609 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 27/31 virtio: pci: Support non-legacy PCI transport device
By default QEMU creates legacy PCI transport devices, but we can ask QEMU to create non-legacy one if we pass additional device property/value pairs in the command line:
-device virtio-blk-pci,disable-legacy=true,disable-modern=false
This adds a new driver driver to support non-legacy (modern) device mode. Previous driver/file name is changed accordingly.
---
Changes in v3: None
Changes in v2:
- fix compiler warnings in 64-bit build
- adjust virtio_pci_find_capability() to avoid walking through capability list to find next one by ourselves
drivers/virtio/Makefile | 2 +-
.../virtio/{virtio_pci.c => virtio_pci_legacy.c} | 6 +-
drivers/virtio/virtio_pci_modern.c | 609 +++++++++++++++++++++
3 files changed, 613 insertions(+), 4 deletions(-)
rename drivers/virtio/{virtio_pci.c => virtio_pci_legacy.c} (98%)
create mode 100644 drivers/virtio/virtio_pci_modern.cApplied to u-boot-dm/next, thanks!
PATCH v3 28/31 virtio: net: Support non-legacy device
In reply to Bin MengFor v1.0 compliant device, it always assumes the member 'num_buffers' exists in the struct virtio_net_hdr while the legacy driver only presented 'num_buffers' when VIRTIO_NET_F_MRG_RXBUF was negotiated. Without that feature the structure was 2 bytes shorter.
Update the driver to support the non-legacy device.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/virtio_net.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
drivers/virtio/virtio_net.c +26 -5
@@ -32,6 +32,7 @@ struct virtio_net_priv {char rx_buff[VIRTIO_NET_NUM_RX_BUFS ][VIRTIO_NET_RX_BUF_SIZE ];bool rx_running; +int net_hdr_len; };/*
@@ -77,12 +78,19 @@ static int virtio_net_send(struct udevice *dev, void *packet, int length) {struct virtio_net_priv *priv =dev_get_priv (dev);struct virtio_net_hdr hdr; -struct virtio_sg hdr_sg = { &hdr,sizeof (hdr) }; +struct virtio_net_hdr_v1 hdr_v1; +struct virtio_sg hdr_sg;struct virtio_sg data_sg = { packet, length };struct virtio_sg *sgs[] = { &hdr_sg, &data_sg };int ret; -memset (&hdr,0 ,sizeof (struct virtio_net_hdr )); +if (priv->net_hdr_len ==sizeof (struct virtio_net_hdr )) + hdr_sg.addr = &hdr; +else + hdr_sg.addr = &hdr_v1; + hdr_sg.length = priv->net_hdr_len; + +memset (hdr_sg.addr,0 , priv->net_hdr_len); ret =virtqueue_add (priv->tx_vq, sgs,2 ,0 );if (ret)
@@ -108,14 +116,14 @@ static int virtio_net_recv(struct udevice *dev, int flags, uchar **packetp)if (!buf)return -EAGAIN ; - *packetp = buf +sizeof (struct virtio_net_hdr ); -return len -sizeof (struct virtio_net_hdr ); + *packetp = buf + priv->net_hdr_len; +return len - priv->net_hdr_len; }static int virtio_net_free_pkt (struct udevice *dev,uchar *packet,int length) {struct virtio_net_priv *priv =dev_get_priv (dev); -void *buf = packet -sizeof (struct virtio_net_hdr ); +void *buf = packet - priv->net_hdr_len;struct virtio_sg sg = { buf,VIRTIO_NET_RX_BUF_SIZE };struct virtio_sg *sgs[] = { &sg };
@@ -186,12 +194,25 @@ static int virtio_net_bind(struct udevice *dev)static int virtio_net_probe (struct udevice *dev) {struct virtio_net_priv *priv =dev_get_priv (dev); +struct virtio_dev_priv *uc_priv =dev_get_uclass_priv (dev->parent);int ret; ret =virtio_find_vqs (dev,2 , priv->vqs);if (ret <0 )return ret; +/* +* For v1.0 compliant device, it always assumes the member +* 'num_buffers' exists in the struct virtio_net_hdr while +* the legacy driver only presented 'num_buffers' when +* VIRTIO_NET_F_MRG_RXBUF was negotiated. Without that feature +* the structure was 2 bytes shorter. +*/ +if (uc_priv->legacy) + priv->net_hdr_len =sizeof (struct virtio_net_hdr ); +else + priv->net_hdr_len =sizeof (struct virtio_net_hdr_v1 ); +return 0 ; }
Signature · 1 line
2.7.4
PATCH v3 28/31 virtio: net: Support non-legacy device
For v1.0 compliant device, it always assumes the member 'num_buffers' exists in the struct virtio_net_hdr while the legacy driver only presented 'num_buffers' when VIRTIO_NET_F_MRG_RXBUF was negotiated. Without that feature the structure was 2 bytes shorter.
Update the driver to support the non-legacy device.
---
Changes in v3: None
Changes in v2: None
drivers/virtio/virtio_net.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v3 29/31 virtio: Add a Sandbox transport driver
In reply to Bin MengThis driver provides support for Sandbox implementation of virtio transport driver which is used for testing purpose only.
Two drivers are provided. The 2nd one is a driver that lacks the 'notify' op.
---
Changes in v3: None
Changes in v2:
- new patch to add a Sandbox transport driver
drivers/virtio/Kconfig | 8 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_sandbox.c | 233 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 drivers/virtio/virtio_sandbox.c
drivers/virtio/Kconfig +8 -0
@@ -37,6 +37,14 @@ config VIRTIO_PCI This driver provides support for virtio based paravirtual device drivers over PCI. +config VIRTIO_SANDBOX + bool "Sandbox driver for virtio devices" + depends on SANDBOX + select VIRTIO + help + This driver provides support for Sandbox implementation of virtio + transport driver which is used for testing purpose only. + config VIRTIO_NET bool "virtio net driver" depends on VIRTIO
drivers/virtio/Makefile +1 -0
@@ -6,5 +6,6 @@ obj-y += virtio-uclass.o virtio_ring.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci_legacy.o virtio_pci_modern.o +obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o obj-$(CONFIG_VIRTIO_NET) += virtio_net.o obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
drivers/virtio/virtio_sandbox.c new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 29/31 virtio: Add a Sandbox transport driver
Quoted 14 lines · Bin Meng
This driver provides support for Sandbox implementation of virtio transport driver which is used for testing purpose only.
Two drivers are provided. The 2nd one is a driver that lacks the 'notify' op.
Signed-off-by Bin Meng <[email protected]>---
Changes in v3: None
Changes in v2:
- new patch to add a Sandbox transport driver
Quoted 5 lines
drivers/virtio/Kconfig | 8 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_sandbox.c | 233 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 drivers/virtio/virtio_sandbox.c
PATCH v3 29/31 virtio: Add a Sandbox transport driver
Quoted 14 lines · Bin Meng
This driver provides support for Sandbox implementation of virtio transport driver which is used for testing purpose only.
Two drivers are provided. The 2nd one is a driver that lacks the 'notify' op.
Signed-off-by Bin Meng <[email protected]>---
Changes in v3: None
Changes in v2:
- new patch to add a Sandbox transport driver
Quoted 5 lines
drivers/virtio/Kconfig | 8 ++ drivers/virtio/Makefile | 1 + drivers/virtio/virtio_sandbox.c | 233 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 insertions(+) create mode 100644 drivers/virtio/virtio_sandbox.c
Applied to u-boot-dm/next, thanks!
PATCH v3 30/31 test: dm: virtio: Add test cases for virtio uclass
In reply to Bin MengNow that we have a sandbox virtio transport driver, add some test cases to test virtio uclass driver.
---
Changes in v3:
- Exclude VIRTIO_BLK in sandbox_noblk_defconfig build
Changes in v2:
- new patch to add test cases for virtio uclass
arch/Kconfig | 5 ++ arch/sandbox/dts/test.dts | 8 +++ configs/sandbox_noblk_defconfig | 1 + test/dm/Makefile | 1 + test/dm/virtio.c | 122 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 test/dm/virtio.c
arch/Kconfig +5 -0
@@ -110,6 +110,11 @@ config SANDBOX imply LIBAVB imply CMD_AVB imply UDP_FUNCTION_FASTBOOT + imply VIRTIO_MMIO + imply VIRTIO_PCI + imply VIRTIO_SANDBOX + imply VIRTIO_BLK + imply VIRTIO_NET config SH bool "SuperH architecture"
arch/sandbox/dts/test.dts +8 -0
@@ -715,6 +715,14 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + sandbox_virtio1 { + compatible = "sandbox,virtio1"; + }; + + sandbox_virtio2 { + compatible = "sandbox,virtio2"; + }; }; #include "sandbox_pmic.dtsi"
configs/sandbox_noblk_defconfig +1 -0
@@ -171,6 +171,7 @@ CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y CONFIG_VIDEO_SANDBOX_SDL=y CONFIG_OSD=y CONFIG_SANDBOX_OSD=y +# CONFIG_VIRTIO_BLK is not set CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y CONFIG_CMD_DHRYSTONE=y
test/dm/Makefile +1 -0
@@ -53,4 +53,5 @@ obj-$(CONFIG_MISC) += misc.o obj-$(CONFIG_DM_SERIAL) += serial.o obj-$(CONFIG_CPU) += cpu.o obj-$(CONFIG_TEE) += tee.o +obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o endif
test/dm/virtio.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v3 30/31 test: dm: virtio: Add test cases for virtio uclass
Quoted 13 lines · Bin Meng
Now that we have a sandbox virtio transport driver, add some test cases to test virtio uclass driver.
Signed-off-by Bin Meng <[email protected]>---
Changes in v3:
- ExcludeVIRTIO_BLKinsandbox_noblk_defconfigbuildChanges in v2:
- new patch to add test cases for virtio uclass
Quoted 7 lines
arch/Kconfig | 5 ++ arch/sandbox/dts/test.dts | 8 +++ configs/sandbox_noblk_defconfig | 1 + test/dm/Makefile | 1 + test/dm/virtio.c | 122 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 test/dm/virtio.c
PATCH v3 30/31 test: dm: virtio: Add test cases for virtio uclass
Quoted 13 lines · Bin Meng
Now that we have a sandbox virtio transport driver, add some test cases to test virtio uclass driver.
Signed-off-by Bin Meng <[email protected]>---
Changes in v3:
- ExcludeVIRTIO_BLKinsandbox_noblk_defconfigbuildChanges in v2:
- new patch to add test cases for virtio uclass
Quoted 7 lines
arch/Kconfig | 5 ++ arch/sandbox/dts/test.dts | 8 +++ configs/sandbox_noblk_defconfig | 1 + test/dm/Makefile | 1 + test/dm/virtio.c | 122 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 test/dm/virtio.c
Applied to u-boot-dm/next, thanks!
PATCH v3 31/31 doc: Document virtio support
In reply to Bin MengAdd REAME.virtio to describe the information about U-Boot support for VirtIO devices, including supported boards, build instructions, driver details etc.
---
Changes in v3: None
Changes in v2:
- Added driver remove and flags description in the documentation
doc/README.virtio | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 doc/README.virtio
doc/README.virtio new file +253 -0
@@ -0,0 +1,253 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2018, Bin Meng <[email protected]> + +VirtIO Support +============== + +This document describes the information about U-Boot support for VirtIO [1] +devices, including supported boards, build instructions, driver details etc. + +What's VirtIO? +-------------- +VirtIO is a virtualization standard for network and disk device drivers where +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 U-Boot case, the guest is U-Boot itself, while the +virtual environment are normally QEMU [2] targets like ARM, RISC-V and x86. + +Status +------ +VirtIO can use various different buses, aka transports as described in the +spec. While VirtIO devices are commonly implemented as PCI devices on x86, +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. Both MMIO +and PCI transport options are supported in U-Boot. + +The VirtIO spec defines a lots of VirtIO device types, however at present only +network and block device, the most two commonly used devices, are supported. + +The following QEMU targets are supported. + + - qemu_arm_defconfig + - qemu_arm64_defconfig + - qemu-riscv32_defconfig + - qemu-riscv64_defconfig + - qemu-x86_defconfig + - qemu-x86_64_defconfig + +Note ARM and RISC-V targets are configured with VirtIO MMIO transport driver, +and on x86 it's the PCI transport driver. + +Build Instructions +------------------ +Building U-Boot for pre-configured QEMU targets is no different from others. +For example, we can do the following with the CROSS_COMPILE environment +variable being properly set to a working toolchain for ARM: + + $ make qemu_arm_defconfig + $ make + +You can even create a QEMU ARM target with VirtIO devices showing up on both +MMIO and PCI buses. In this case, you can enable the PCI transport driver +from 'make menuconfig': + +Device Drivers ---> + ... + VirtIO Drivers ---> + ... + [*] PCI driver for virtio devices + +Other drivers are at the same location and can be tuned to suit the needs. + +Requirements +------------ +It is required that QEMU v2.5.0+ should be used to test U-Boot VirtIO support +on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V. + +Testing +------- +The following QEMU command line is used to get U-Boot up and running with +VirtIO net and block devices on ARM. + + $ qemu-system-arm -nographic -machine virt -bios u-boot.bin \ + -netdev tap,ifname=tap0,id=net0 \ + -device virtio-net-device,netdev=net0 \ + -drive if=none,file=test.img,format=raw,id=hd0 \ + -device virtio-blk-device,drive=hd0 + +On x86, command is slightly different to create PCI VirtIO devices. + + $ qemu-system-i386 -nographic -bios u-boot.rom \ + -netdev tap,ifname=tap0,id=net0 \ + -device virtio-net-pci,netdev=net0 \ + -drive if=none,file=test.img,format=raw,id=hd0 \ + -device virtio-blk-pci,drive=hd0 + +Additional net and block devices can be created by appending more '-device' +parameters. It is also possible to specify both MMIO and PCI VirtIO devices. +For example, the following commnad creates 3 VirtIO devices, with 1 on MMIO +and 2 on PCI bus. + + $ qemu-system-arm -nographic -machine virt -bios u-boot.bin \ + -netdev tap,ifname=tap0,id=net0 \ + -device virtio-net-pci,netdev=net0 \ + -drive if=none,file=test0.img,format=raw,id=hd0 \ + -device virtio-blk-device,drive=hd0 \ + -drive if=none,file=test1.img,format=raw,id=hd1 \ + -device virtio-blk-pci,drive=hd1 + +By default QEMU creates VirtIO legacy devices by default. To create non-legacy +(aka modern) devices, pass additional device property/value pairs like below: + + $ qemu-system-i386 -nographic -bios u-boot.rom \ + -netdev tap,ifname=tap0,id=net0 \ + -device virtio-net-pci,netdev=net0,disable-legacy=true,disable-modern=false \ + -drive if=none,file=test.img,format=raw,id=hd0 \ + -device virtio-blk-pci,drive=hd0,disable-legacy=true,disable-modern=false + +A 'virtio' command is provided in U-Boot shell. + + => virtio + virtio - virtio block devices sub-system + + Usage: + virtio scan - initialize virtio bus + virtio info - show all available virtio block devices + virtio device [dev] - show or set current virtio block device + virtio part [dev] - print partition table of one or all virtio block devices + virtio read addr blk# cnt - read `cnt' blocks starting at block + `blk#' to memory address `addr' + virtio write addr blk# cnt - write `cnt' blocks starting at block + `blk#' from memory address `addr' + +To probe all the VirtIO devices, type: + + => virtio scan + +Then we can show the connected block device details by: + + => virtio info + Device 0: QEMU VirtIO Block Device + Type: Hard Disk + Capacity: 4096.0 MB = 4.0 GB (8388608 x 512) + +And list the directories and files on the disk by: + + => ls virtio 0 / + <DIR> 4096 . + <DIR> 4096 .. + <DIR> 16384 lost+found + <DIR> 4096 dev + <DIR> 4096 proc + <DIR> 4096 sys + <DIR> 4096 var + <DIR> 4096 etc + <DIR> 4096 usr + <SYM> 7 bin + <SYM> 8 sbin + <SYM> 7 lib + <SYM> 9 lib64 + <DIR> 4096 run + <DIR> 4096 boot + <DIR> 4096 home + <DIR> 4096 media + <DIR> 4096 mnt + <DIR> 4096 opt + <DIR> 4096 root + <DIR> 4096 srv + <DIR> 4096 tmp + 0 .autorelabel + +Driver Internals +---------------- +There are 3 level of drivers in the VirtIO driver family. + + +---------------------------------------+ + | virtio device drivers | + | +-------------+ +------------+ | + | | virtio-net | | virtio-blk | | + | +-------------+ +------------+ | + +---------------------------------------+ + +---------------------------------------+ + | virtio transport drivers | + | +-------------+ +------------+ | + | | virtio-mmio | | virtio-pci | | + | +-------------+ +------------+ | + +---------------------------------------+ + +----------------------+ + | virtio uclass driver | + +----------------------+ + +The root one is the virtio uclass driver (virtio-uclass.c), which does lots of +common stuff for the transport drivers (virtio_mmio.c, virtio_pci.c). The real +virtio device is discovered in the transport driver's probe() method, and its +device ID is saved in the virtio uclass's private data of the transport device. +Then in the virtio uclass's post_probe() method, the real virtio device driver +(virtio_net.c, virtio_blk.c) is bound if there is a match on the device ID. + +The child_post_bind(), child_pre_probe() and child_post_probe() methods of the +virtio uclass driver help bring the virtio device driver online. They do things +like acknowledging device, feature negotiation, etc, which are really common +for all virtio devices. + +The transport drivers provide a set of ops (struct dm_virtio_ops) for the real +virtio device driver to call. These ops APIs's parameter is designed to remind +the caller to pass the correct 'struct udevice' id of the virtio device, eg: + +int virtio_get_status(struct udevice *vdev, u8 *status) + +So the parameter 'vdev' indicates the device should be the real virtio device. +But we also have an API like: + +struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num, + unsigned int vring_align, + struct udevice *udev) + +Here the parameter 'udev' indicates the device should be the transport device. +Similar naming is applied in other functions that are even not APIs, eg: + +static int virtio_uclass_post_probe(struct udevice *udev) +static int virtio_uclass_child_pre_probe(struct udevice *vdev) + +So it's easy to tell which device these functions are operating on. + +Development Flow +---------------- +At present only VirtIO network card (device ID 1) and block device (device +ID 2) are supported. If you want to develop new driver for new devices, +please follow the guideline below. + +1. add new device ID in virtio.h +#define VIRTIO_ID_XXX X + +2. update VIRTIO_ID_MAX_NUM to be the largest device ID plus 1 + +3. add new driver name string in virtio.h +#define VIRTIO_XXX_DRV_NAME "virtio-xxx" + +4. create a new driver with name set to the name string above +U_BOOT_DRIVER(virtio_xxx) = { + .name = VIRTIO_XXX_DRV_NAME, + ... + .remove = virtio_reset, + .flags = DM_FLAG_ACTIVE_DMA, +} + +Note the driver needs to provide the remove method and normally this can be +hooked to virtio_reset(). The driver flags should contain DM_FLAG_ACTIVE_DMA +for the remove method to be called before jumping to OS. + +5. provide bind() method in the driver, where virtio_driver_features_init() + should be called for driver to negotiate feature support with the device. + +6. do funny stuff with the driver + +References +---------- +[1] http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf +[2] https://www.qemu.org
Signature · 1 line
2.7.4
PATCH v3 31/31 doc: Document virtio support
Add REAME.virtio to describe the information about U-Boot support for VirtIO devices, including supported boards, build instructions, driver details etc.
---
Changes in v3: None
Changes in v2:
- Added driver remove and flags description in the documentation
doc/README.virtio | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 doc/README.virtio
Applied to u-boot-dm/next, thanks!