From patchwork Mon Oct 15 09:20:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 983991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XzHR4KBW"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42YXrH4MM4z9s7W for ; Mon, 15 Oct 2018 20:16:47 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C9A00C21E08; Mon, 15 Oct 2018 09:16:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 51154C21CB1; Mon, 15 Oct 2018 09:16:36 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 539F9C21BE5; Mon, 15 Oct 2018 09:16:34 +0000 (UTC) Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by lists.denx.de (Postfix) with ESMTPS id 69970C21BE5 for ; Mon, 15 Oct 2018 09:16:33 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id y11-v6so8992285plt.3 for ; Mon, 15 Oct 2018 02:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3eXKUw9ts5dif1WrYlXWQJYtECPDQ4qizeUtXPBvIL8=; b=XzHR4KBWk80q4M8TnsT9a4FqBP0TpM2XAQOVOUkFSwZgwuzZnUAXInm/w5dqxQU0Xv cJpa1qIiDzvQzQhytoumx8Dwme1Q/bnTZJCNE9Koobb7Wmzny9L1xnDkd5rBknISzVG9 wAOymPUArmdntELH+HP5e9yPnMBfoNvUhrDULvk8NoZKFOrku7zssylVoD8hy54DKXei 6denPI6wglGDRW3ZSrvUCulNVSEUx8k5+VKSGz29z2KXhQmgNLSSld1VLT6RJGZ1qzxc b5ZHKI9pikRiaH7AaBmhTQTHdfNb6d1zGb1nu4AAIzpfeHTw+Rr3PmvKd+wZdr2HOdhi xyPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3eXKUw9ts5dif1WrYlXWQJYtECPDQ4qizeUtXPBvIL8=; b=GcNfleIeyrNrg2aPsE58IVbsodlsxtVRRl5hQ33ABk7b5rAIaYQXOzjR9zxNiW7eq8 xzsBuIJ/Z+qRCDVv248qIIVK+NuPnKTo9i6p2Ufc2AxYrNRnvILPU/hehDbWc7v/Fgar Yv2NoCch9Wu/VRBzMNkrqUiwN04qJ0wEIa9i06QaknIP2mANa3UFIppLrUMcUTV78O26 OcDz4VeqJRfRhu8zytSVtimLxDd0JzSY+qRLqTEPb60gEkSCoECnnNPaUqPvNb587cEO Om1iCUJ6WIrOBRi1uR4XJP784SkT9r/qQTCOhgRWokVs0iLuFZydzVrahXbQB3/UX9sZ VJTA== X-Gm-Message-State: ABuFfojJWGxCvi3FxIYei/a/XvCeSSK1hj02BBG4p7HN7h4u2+GKxpzd kDNRZeSc5G5UG78Re3kw+QI= X-Google-Smtp-Source: ACcGV62WQaQNhebZNtKa8MzmrIoxluZbpoL9Ly4sZclwWFbOrZIfNdDsVncqJPRca0J/pxshiKitDQ== X-Received: by 2002:a17:902:b198:: with SMTP id s24-v6mr15624914plr.70.1539594991722; Mon, 15 Oct 2018 02:16:31 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-156-139.windriver.com. [147.11.156.139]) by smtp.gmail.com with ESMTPSA id a11-v6sm10798256pgw.54.2018.10.15.02.16.30 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Oct 2018 02:16:30 -0700 (PDT) From: Bin Meng To: Simon Glass , U-Boot Mailing List Date: Mon, 15 Oct 2018 02:20:56 -0700 Message-Id: <1539595287-31378-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Subject: [U-Boot] [PATCH v3 00/31] virtio: Introduce VirtIO driver support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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