30 Commits

Author SHA1 Message Date
Simon Glass
9a4aa22a70 virtio: Increase the bootdev priority
The current priority of BOOTDEVP_4_SCAN_FAST means that virtio is
scanned after SCSI. But virtio-scsi provides higher performance.

It seems better to regard virtio has an internal device, since it is
paravirtualised and thus fast. Change its bootdev priority to
BOOTDEVP_2_INTERNAL_FAST

Disable the virtio-fs feature on sandbox, since the virtio queue is not
not yet supported by the emulator.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 23:33:26 +02:00
Simon Glass
bbd1cc14c1 virtio: Provide a command to list virtio devices
U-Boot only supports a subset of the devices supported by QEMU. For
example, U-Boot does not currently support the vsock device.

It is helpful to see what devices are provided by QEMU and whether there
is a driver for it in U-Boot.

Add a new 'virtio list' command to provide this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 23:33:26 +02:00
Simon Glass
7013d9f2f1 virtio: Fill in all the QEMU device types
Even if U-Boot doesn't have a driver for all of the virtio devices
provided by QEMU, it is still useful to see what they are. Fill out the
table of device types and names, so that 'virtio list' lists them all.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 23:33:26 +02:00
Simon Glass
33d80a2b25 virtio: Add debugging of driver features and device type
When a device type is not supported by U-Boot it is silently ignored.
Add some debugging for this.

Also show the driver features to provide a fuller picture of feature
negotiation.

Series-to: concept
Cover-letter:
virtio: Add support for virtio-scsi
It is often possible to use virtio-blk for block devices, but it is
less flexible than SCSI. SCSI provides a means to probe for multiple
disks through the same interface. It also supports hotplug and other
features.

This series adds a simple virtio-scsi driver for use with QEMU. The new
driver creates a SCSI bus when the virtio buses are scanned. That can be
scanned in turn, using 'scsi scan', to find the available virtio disks.

For this to work, quite a few minor updates are needed in the SCSI
implementation:

- Increase the buffer sizes for commands and sense buffer
- Fix off-by-one error when scanning for devices
- Use REPORT LUN to determine what LUNs are present for a target
- Clean up some open-coded constants
- Make use of a struct to decode the IDENTIFY response
- Clean up of the confusing and error-prone SCSI read/write functions
- Add support for using a scsi disk to the build-qemu/efi scripts

When a SCSI disk is inaccessible (e.g. the LUN is wrong), this is seldom
reported as an error. For example 'part list' does not say 'read error'
but 'unsupported partition type'. Probing the block device results in
each partition-type driver reading blocks, none of which reports the
error. So an attempt is made here to clean this up, so that bad LUNs
show an error.

Another clean-up is to show partition numbers in hex with 'part list',
since the current approach conflicts with the 'part' command.

Some additional x86 debugging is added for the jump from SPL to U-Boot
proper, since this can be confusing when it fails in QEMU.

With all of the above, virtio-scsi can be used on qemu-x86_64 for
loading an OS and associated files, including with standard boot.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
9a6d610a34 virtio: Add support for virtio-scsi
This feature can be useful where the host wants to provide more than one
block device, since it allows all of them to be under one virtio device.

Add an implementation of virtio-scsi

Series-to: concept
Cover-letter:
virtio: Support SCSI over virtio
U-Boot supports virtio-blk and in most cases this is sufficient for
providing access to a disk. However some larger users such as LXD prefer
virtio-scsi since it groups disks together and provides unified probing
of devices.

This series implements this protocol.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-02 13:43:28 -06:00
Simon Glass
f4b820f8ec virtio: Add top-level functions for virtio-fs
Provide access to the virtual queue and some functions for sending
various FUSE messages.

Add myself as a maintainer of virtio.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 08:35:17 -06:00
Simon Glass
0733605bb1 virtio: Acknowledge devices only when probed
At present virtio devices are acknowleged when bound. This results in a
call to virtio_set_status() which uses device-private data in several
cases, e.g. in virtio_pci_get_status()

This data is only allocated when the device is probed, so the access is
either ignored (on QEMU) or results in a crash (on sandbox).

Acknowledging the device so early does not seem to be necessary. Move it
to the pre-probe function instead. Update the test to match. We now have
no coverage to check that VIRTIO_CONFIG_S_ACKNOWLEDGE was actually set.

If we later find it necessary to acknowledge the device while binding,
we can update the uclass and drivers to use plat data instead of priv.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-30 08:34:03 -06:00
Simon Glass
d40e88a868 blk: Use hex indices for the device name
It is confusing to use decimal values in device names. For example, with
virtio:

  => dm tree
  ...
  pci           5  [ + ]   pci_bridge_drv        |   |-- pci_0:1.5
    virtio        5  [ + ]   virtio-pci.m          |   |   `-- virtio-pci.m#5
   blk           0  [ + ]   virtio-blk            |   |       |-- virtio-blk#5
   partition     0  [ + ]   blk_partition         |   |       |   |-- virtio-blk#5:1
   partition     1  [ + ]   blk_partition         |   |       |   |-- virtio-blk#5:14
   partition     2  [ + ]   blk_partition         |   |       |   |-- virtio-blk#5:15
   partition     3  [ + ]   blk_partition         |   |       |   `-- virtio-blk#5:16
   bootdev       2  [ + ]   virtio_bootdev        |   |       `-- virtio-blk#5.bootdev
   pci           6  [ + ]   pci_bridge_drv        |   |-- pci_0:1.6
   ...
  => ls virtio 0:14
  ** Invalid partition 20 **
  Couldn't find partition virtio 0:14

Fix this by using hex for both the block-device number and the partition.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 07:53:25 -06:00
Tom Rini
03de305ec4 Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
As part of bringing the master branch back in to next, we need to allow
for all of these changes to exist here.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-20 13:35:03 -06:00
Tom Rini
d678a59d2d Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d, reversing
changes made to 2ee6f3a5f7.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-19 08:16:36 -06:00
Tom Rini
3ba56d6b23 virtio: Remove <common.h> and add needed includes
Remove <common.h> from this driver directory and when needed
add missing include files directly.

Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-07 08:00:57 -06:00
Simon Glass
d7d78576bb bootstd: Rename bootdev_setup_sibling_blk()
This name is a little confusing since it suggests that it sets up the
sibling block device. In fact it sets up a bootdev for it. Rename the
function to make this clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2023-08-09 23:31:11 +08:00
Heinrich Schuchardt
63baa84129 virtio: provide driver name in debug message
If a driver cannot be bound, provide the driver name in the debug
message. Now the debug message may look like this:

    (virtio-pci.l#0): virtio-rng driver not configured

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-03 15:30:53 -04:00
Simon Glass
27ff7806c1 virtio: Ensure PCI is set up first
Sometimes virtio may rely on PCI, or at least that is what the
distro_bootcmd script suggests. Add this in.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-04-26 08:43:04 -04:00
Will Deacon
7804306c80 virtio: Expose VIRTIO_F_IOMMU_PLATFORM in device features
If we detect the VIRTIO_F_IOMMU_PLATFORM transport feature for a device,
then expose it in the device features.

Signed-off-by: Will Deacon <willdeacon@google.com>
[ Paul: pick from the Android tree. Rebase to the upstream ]
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Link: 9693bd26bf
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-04-25 11:53:15 -04:00
Simon Glass
a710f5b2eb bootstd: Correct virtio block-device handling
At present virtio tries to attach QEMU services to a bootdev device, which
cannot work. Add a check for this.

Also use bootdev_setup_sibling_blk() to create the bootdev device, since
it allows the correct name to be used and bootdev_get_sibling_blk() to
work as expected.

The bootdev is not created on sandbox since it does have a real virtio
device and it is not possible to read blocks.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: a60f7a3e35 ("bootstd: Add a virtio bootdev")
Reported-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-02-06 13:04:53 -05:00
Simon Glass
eacc261178 bootstd: Add a new pre-scan priority for bootdevs
We need extensions to be set up before we start trying to boot any of the
bootdevs. Add a new priority before all the others for tht sort of thing.
Also add a 'none' option, so that the first one is not 0.

While we are here, comment enum bootdev_prio_t fully and expand the test
for the 'bootdev hunt' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:41 -05:00
Simon Glass
a60f7a3e35 bootstd: Add a virtio bootdev
Add a bootdev for virtio so that these devices can be used with standard
boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Simon Glass
811c81e889 virtio: Fix returning -ENODEV
This has a special meaning in driver model. There is clearly a device, so
it does not make sense to return this error code. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Simon Glass
59a6be9b11 virtio: Avoid repeating a long expression
Use a local variable to hold this name, to reduce the amount of code that
needs to be read.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23 18:11:40 -05:00
Michal Suchanek
c0648b7b9d dm: treewide: Do not opencode uclass_probe_all()
We already have a function for probing all devices of a specific class,
use it.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
2022-10-17 21:17:12 -06:00
Patrick Delaunay
b953ec2bca dm: define LOG_CATEGORY for all uclass
Define LOG_CATEGORY for all uclass to allow filtering with
log command.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2021-07-06 10:38:03 -06:00
Vincent Stehlé
25d34b936c virtio: fix off by one device id comparison
VIRTIO_ID_MAX_NUM is the largest device ID plus 1. Therefore a device id
cannot be greater or equal to VIRTIO_ID_MAX_NUM. Fix the comparison
accordingly.

Fixes: 8fb49b4c7a ("dm: Add a new uclass driver for VirtIO transport devices")
Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
2021-02-24 16:51:48 -05:00
Simon Glass
8b85dfc675 dm: Avoid accessing seq directly
At present various drivers etc. access the device's 'seq' member directly.
This makes it harder to change the meaning of that member. Change access
to go through a function instead.

The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-18 20:32:21 -07:00
Simon Glass
41575d8e4c dm: treewide: Rename auto_alloc_size members to be shorter
This construct is quite long-winded. In earlier days it made some sense
since auto-allocation was a strange concept. But with driver model now
used pretty universally, we can shorten this to 'auto'. This reduces
verbosity and makes it easier to read.

Coincidentally it also ensures that every declaration is on one line,
thus making dtoc's job easier.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-13 08:00:25 -07:00
Simon Glass
eb41d8a1be common: Drop linux/bug.h from common header
Move this uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18 21:19:23 -04:00
Simon Glass
f7ae49fc4f common: Drop log.h from common header
Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-18 21:19:18 -04:00
Simon Glass
336d4615f8 dm: core: Create a new header file for 'compat' features
At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-02-05 19:33:46 -07:00
Sughosh Ganu
03018ea8fd virtio: rng: Add a random number generator(rng) driver
Add a driver for the virtio-rng device on the qemu platform. The
device uses pci as a transport medium. The driver can be enabled with
the following configs

CONFIG_VIRTIO
CONFIG_DM_RNG
CONFIG_VIRTIO_PCI
CONFIG_VIRTIO_RNG

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
2020-01-07 18:08:21 +01:00
Bin Meng
8fb49b4c7a dm: Add a new uclass driver for VirtIO transport devices
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() 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

Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2018-11-14 09:16:27 -08:00