History log of /openbsd-current/sys/dev/pci/virtio_pci.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.38 26-Jun-2024 jsg

return type on a dedicated line when declaring functions
ok mglocker@


# 1.37 17-May-2024 sf

vio: Fix signal handling and locking in sysctl path

Commits f0b002d01d5 "Release the netlock when sleeping for control
messages in in vioioctl()" and 126b881f71 "Insert a workaround for
per-ifp ioctl being called w/o NET_LOCK()." in vio(4) fixed a deadlock
but may cause a crash with a protection fault trap if addresses are
added/removed concurrently.

The actual issue is that signals are not handled correctly while
sleeping. After a signal, there is a race condition where sc_ctrl_inuse
is first set to FREE and then the interrupt handler sets it to DONE,
causing a hang in the next vio_wait_ctrl() call.

To fix it:

* Revert the NET_LOCK unlocking work-around.

* Remove PCATCH from the sleep call when we wait for control queue,
avoiding the race with vio_ctrleof(). To ensure that we don't hang
forever, use a 5 second timeout.

* If the timeout is hit, or if the hypervisor has set the
DEVICE_NEEDS_RESET status bit, do not try to use the control queue
until the next ifconfig down/up which resets the device.

* In order to allow reading the device status from device drivers, add a
new interface to the virtio transport drivers.

* Avoid a crash if there is outgoing traffic while doing ifconfig down.

OK bluhm@


Revision tags: OPENBSD_7_5_BASE
# 1.36 15-Jan-2024 dv

vio(4): poll device status after issuing device reset.

The virtio spec says a driver "should" wait for a device to report
a clear device status after performing a reset. In some hypervisors,
this doesn't matter as the vcpu's io instruction emulation and
virtio network device emulation happen serially in the same thread.
In hypervisors like vmd(8), device reset happens asynchronously and
the driver can't assume the device is ready.

This race condition results in mbuf pool corruption, causing panics.

Bug reported and reproduced by bluhm@. Root cause found and diff
from sf@. ok dv@ and committed on sf@'s behalf with his permission.


Revision tags: OPENBSD_7_4_BASE
# 1.35 07-Jul-2023 patrick

The per-VQ MSI-X interrupt handler needs to sync DMA mappings in the
same way that the shared interrupt handler does. This is one of the
requirements of virtio_dequeue(), as specified in its comment above.

Without the DMA sync, it will not see a new entry on the ring and
return. Since the interrupt is edge-triggered there won't be another
one and we'll get stuck.

ok dv@


# 1.34 05-Jul-2023 patrick

Fix off-by-one in the MSI-X interrupt establish loop that always tried to
establish one more interrupt than would be needed for per-VQ IRQs. This
meant even though there were enough MSI-X vectors available this path could
fail, roll back previously established interrupts and switch to shared IRQs
as a fallback.

ok dv@


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.37 17-May-2024 sf

vio: Fix signal handling and locking in sysctl path

Commits f0b002d01d5 "Release the netlock when sleeping for control
messages in in vioioctl()" and 126b881f71 "Insert a workaround for
per-ifp ioctl being called w/o NET_LOCK()." in vio(4) fixed a deadlock
but may cause a crash with a protection fault trap if addresses are
added/removed concurrently.

The actual issue is that signals are not handled correctly while
sleeping. After a signal, there is a race condition where sc_ctrl_inuse
is first set to FREE and then the interrupt handler sets it to DONE,
causing a hang in the next vio_wait_ctrl() call.

To fix it:

* Revert the NET_LOCK unlocking work-around.

* Remove PCATCH from the sleep call when we wait for control queue,
avoiding the race with vio_ctrleof(). To ensure that we don't hang
forever, use a 5 second timeout.

* If the timeout is hit, or if the hypervisor has set the
DEVICE_NEEDS_RESET status bit, do not try to use the control queue
until the next ifconfig down/up which resets the device.

* In order to allow reading the device status from device drivers, add a
new interface to the virtio transport drivers.

* Avoid a crash if there is outgoing traffic while doing ifconfig down.

OK bluhm@


Revision tags: OPENBSD_7_5_BASE
# 1.36 15-Jan-2024 dv

vio(4): poll device status after issuing device reset.

The virtio spec says a driver "should" wait for a device to report
a clear device status after performing a reset. In some hypervisors,
this doesn't matter as the vcpu's io instruction emulation and
virtio network device emulation happen serially in the same thread.
In hypervisors like vmd(8), device reset happens asynchronously and
the driver can't assume the device is ready.

This race condition results in mbuf pool corruption, causing panics.

Bug reported and reproduced by bluhm@. Root cause found and diff
from sf@. ok dv@ and committed on sf@'s behalf with his permission.


Revision tags: OPENBSD_7_4_BASE
# 1.35 07-Jul-2023 patrick

The per-VQ MSI-X interrupt handler needs to sync DMA mappings in the
same way that the shared interrupt handler does. This is one of the
requirements of virtio_dequeue(), as specified in its comment above.

Without the DMA sync, it will not see a new entry on the ring and
return. Since the interrupt is edge-triggered there won't be another
one and we'll get stuck.

ok dv@


# 1.34 05-Jul-2023 patrick

Fix off-by-one in the MSI-X interrupt establish loop that always tried to
establish one more interrupt than would be needed for per-VQ IRQs. This
meant even though there were enough MSI-X vectors available this path could
fail, roll back previously established interrupts and switch to shared IRQs
as a fallback.

ok dv@


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.36 15-Jan-2024 dv

vio(4): poll device status after issuing device reset.

The virtio spec says a driver "should" wait for a device to report
a clear device status after performing a reset. In some hypervisors,
this doesn't matter as the vcpu's io instruction emulation and
virtio network device emulation happen serially in the same thread.
In hypervisors like vmd(8), device reset happens asynchronously and
the driver can't assume the device is ready.

This race condition results in mbuf pool corruption, causing panics.

Bug reported and reproduced by bluhm@. Root cause found and diff
from sf@. ok dv@ and committed on sf@'s behalf with his permission.


Revision tags: OPENBSD_7_4_BASE
# 1.35 07-Jul-2023 patrick

The per-VQ MSI-X interrupt handler needs to sync DMA mappings in the
same way that the shared interrupt handler does. This is one of the
requirements of virtio_dequeue(), as specified in its comment above.

Without the DMA sync, it will not see a new entry on the ring and
return. Since the interrupt is edge-triggered there won't be another
one and we'll get stuck.

ok dv@


# 1.34 05-Jul-2023 patrick

Fix off-by-one in the MSI-X interrupt establish loop that always tried to
establish one more interrupt than would be needed for per-VQ IRQs. This
meant even though there were enough MSI-X vectors available this path could
fail, roll back previously established interrupts and switch to shared IRQs
as a fallback.

ok dv@


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.35 07-Jul-2023 patrick

The per-VQ MSI-X interrupt handler needs to sync DMA mappings in the
same way that the shared interrupt handler does. This is one of the
requirements of virtio_dequeue(), as specified in its comment above.

Without the DMA sync, it will not see a new entry on the ring and
return. Since the interrupt is edge-triggered there won't be another
one and we'll get stuck.

ok dv@


# 1.34 05-Jul-2023 patrick

Fix off-by-one in the MSI-X interrupt establish loop that always tried to
establish one more interrupt than would be needed for per-VQ IRQs. This
meant even though there were enough MSI-X vectors available this path could
fail, roll back previously established interrupts and switch to shared IRQs
as a fallback.

ok dv@


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.34 05-Jul-2023 patrick

Fix off-by-one in the MSI-X interrupt establish loop that always tried to
establish one more interrupt than would be needed for per-VQ IRQs. This
meant even though there were enough MSI-X vectors available this path could
fail, roll back previously established interrupts and switch to shared IRQs
as a fallback.

ok dv@


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.33 29-May-2023 sf

virtio: Set DRIVER_OK earlier

The DRIVER_OK bit must be set before using any virt-queues. To allow
virtio device drivers to use the virt-queues in their attach functions,
set the bit there and not in the virtio transport attach function. Only
vioscsi and viogpu really need this, but let's only have one standard
way to do this.

Noticed because of hangs with vioscsi on qemu/windows and in the Oracle
cloud. With much debugging help by Aaron Mason.

Also revert vioscsi.c 1.31 "Temporarily workaround double calls into
vioscsi_req_done()"

ok krw@


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.32 13-Apr-2023 jsg

remove duplicate includes
ok deraadt@ miod@ krw@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.31 11-Mar-2022 mpi

Constify struct cfattach.


Revision tags: OPENBSD_7_0_BASE
# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.30 03-Sep-2021 patrick

Make virtio(4) less restrictive on the type of BAR it supports for
legacy versions. The current version of Parallels on M1 seems to
not provide the I/O BAR that we expect, and reducing our expectations
seems to be help.

ok kettenis@


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.29 12-Jun-2021 kettenis

Restrict MSI override to i386 and amd64. On other architectures we can
trust the flag set by the PCI host bridge driver and there are cases
where it isn't set because MSIs aren't implemented (for example on riscv64).

ok patrick@, sf@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.28 27-May-2019 sf

fix virtio_pci on 32bit archs

bus_space_read/write_8 do not exist there, use two 32bit operations.


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.27 26-May-2019 sf

Support virtio 1.0 for virtio_pci

virtio 1.0 for virtio_mmio it not yet implemented, but 0.9 devices
continue to work.


# 1.26 26-May-2019 sf

Rework virtio_negotiate_features()

Add a sc_driver_features field that is automatically used by
virtio_negotiate_features() and during reinit.

Make virtio_negotiate_features() return an error code. Virtio 1.0 has a
special status bit for feature negotiation that means that negotiation
can fail. Make virtio_negotiate_features() return an error code instead
of the features.

Make virtio_reinit_start() automatically call
virtio_negotiate_features().

Add a convenience function virtio_has_feature() to make checking bits
easier.

Add an error check in viomb for virtio_negotiate_features because it has
some feature bits that may cause negotiation to fail. More error
checking in the child drivers is still missing.

ok mlarkin@


# 1.25 26-May-2019 sf

virtio_pci: Move msix vector config into functions

ok mlarkin@


# 1.24 26-May-2019 sf

virtio_pci: Split bus space handles

In virtio_pci 1.0, different parts of the register set may be located in
different BARs. Use subregions to make the access independent of the
virtio version.


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


Revision tags: OPENBSD_6_5_BASE
# 1.23 24-Mar-2019 sf

virtio: Prepare for 64 feature bits

virtio 1.0 supports an arbitrary number of feature bits. However, so far
no more than 64 are used (compared to 32 in virtio 0.9). Adjust data
types to support 64 feature bits.

Later, we may want to use bitmaps and setbit(), ... to support even more
feature bits.

ok mlarkin@


# 1.22 24-Mar-2019 sf

virtio: adjust virtio_setup_queue prototype for 1.0

Make it take an address instead of a PFN.
Pass the virtqueue pointer. In virtio 1.0, more information has to be
configured in the device. Also call virtio_setup_queue() after the
information has been filled in.

ok mlarkin@


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.21 19-Jan-2019 sf

virtio: Introduce defines for config(8) flags


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


# 1.20 10-Jan-2019 sf

Move some PCI-specific defines to a new virtio_pcireg.h file

Also add some virtio 1.0 status and feature bits


# 1.19 10-Jan-2019 sf

Move some common defines to virtiovar.h

And fix some comments


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt


Revision tags: OPENBSD_6_2_BASE
# 1.18 31-May-2017 sf

virtio_pci: Support IPL_MPSAFE interrupt handlers


Revision tags: OPENBSD_6_1_BASE
# 1.17 21-Jan-2017 reyk

Switch include of virtio header from dev/pci/to dev/pv/


# 1.16 13-Jan-2017 reyk

Add vmmci(4) (VMM control interface), a simple guest-side driver for vmm(4) VMs

While we don't have ACPI in vmm(4), we need a simple way to shutdown
and reboot VMs gracefully but the device also allows to add more
direct communications between host and guest later.

OK mlarkin@


Revision tags: OPENBSD_6_0_BASE
# 1.15 19-Jul-2016 sf

virtio_pci: Always allow MSI/MSI-X

For virtio devices, ignore the black/white-listing depending on the PCI
bridge. This enables MSI-X with qemu's old "82441FX" pci-bridge.

Suggested by kettenis@


# 1.14 16-Jul-2016 sf

Support MSI-X in virtio

This increases performance for interrupt heavy loads.

While suspend/resume support for MSI-X is missing, this is also missing for
virtio. So no new issue there.

Currently, qemu's old "82441FX" pci-bridge is still blacklisted for MSI. But
MSI-X is used if qemu is started with "-M q35".


# 1.13 14-Jul-2016 sf

virtio: Move interrupt handler into transport specific code

For MSI-X (and also possibly for other transports), the interrupt
handler must do different things. Move it out of virtio.c and into
virtio_pci.

ARM part tested by patrick@


Revision tags: OPENBSD_5_9_BASE
# 1.12 15-Nov-2015 deraadt

virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
becomes simply
virtio2 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00


Revision tags: OPENBSD_5_8_BASE
# 1.11 18-Jul-2015 sf

virtio_pci: Do the ISR read without kernel lock

The ISR read is relatively expensive because it causes a vmexit. Grab the
kernel lock only after it is done.


# 1.10 18-Jul-2015 sf

KNF fixes

No object file changes besides line numbers in KASSERTs


# 1.9 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.8 15-Dec-2014 brad

Consistency with the pci_intr_map bits.

ok sf@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.7 22-Sep-2013 sf

Support MSI for virtio. This is useful for bhyve.


Revision tags: OPENBSD_5_4_BASE
# 1.6 10-Mar-2013 sf

Rename write_queue_address -> setup_queue

For transports supporting several interrupts, this function needs to
setup per-queue interrupts in addition of setting the queue address.

No logic change.

OK jasper@


# 1.5 10-Mar-2013 sf

Move sc_ih to virtio_pci_softc, it is not used outside of virtio_pci
and is really a transport-specific thing.

OK jasper@


Revision tags: OPENBSD_5_3_BASE
# 1.4 05-Dec-2012 deraadt

Remove excessive sys/cdefs.h inclusion
ok guenther millert kettenis


# 1.3 12-Oct-2012 reyk

Add $OpenBSD$ CVS Ids.

ok sf@


# 1.2 20-Sep-2012 jasper

make the lines printed during attach more consistent with other drivers

ok mikeb@ sf@


# 1.1 19-Sep-2012 sf

Add new drivers for virtio network (vio) and block devices (vioblk, the disks
attach as scsi disks). These are paravirtualized devices offered by some
hypervisors like kvm and virtualbox.

The virtio transport driver has the pci specific parts separated out. This
will make it easier to add support for mmio (e.g. for ARM) later.

OK mikeb
OK jasper
"commit what you have" deraadt