LCOV - code coverage report
Current view: top level - zephyr/drivers/virtio - virtio_config.h Coverage Total Hit
Test: new.info Lines: 100.0 % 49 49
Test Date: 2025-10-20 12:20:01

            Line data    Source code
       1            1 : /*
       2              :  * Copyright (c) 2025 Antmicro <www.antmicro.com>
       3              :  * Copyright (c) 2025 TOKITA Hiroshi
       4              :  *
       5              :  * SPDX-License-Identifier: Apache-2.0
       6              :  */
       7              : 
       8              : /**
       9              :  * @file
      10              :  *
      11              :  * VIRTIO common definitions based on the specification.
      12              :  *
      13              :  * Based on Virtual I/O Device (VIRTIO) Version 1.3 specification:
      14              :  * https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf
      15              :  */
      16              : 
      17              : #ifndef ZEPHYR_DRIVERS_VIRTIO_VIRTIO_CONFIG_H_
      18              : #define ZEPHYR_DRIVERS_VIRTIO_VIRTIO_CONFIG_H_
      19              : 
      20              : /**
      21              :  * @name Virtio device status bits
      22              :  *
      23              :  * Bit positions of the device status field.
      24              :  * These are described in
      25              :  * <a href="https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#section.2.1">
      26              :  * 2.1 Device Status Field </a>
      27              :  *
      28              :  * @{
      29              :  */
      30              : 
      31              : /** Indicates the guest has found and recognized the device presence. */
      32            1 : #define DEVICE_STATUS_ACKNOWLEDGE 0
      33              : /** Indicates the guest driver is ready to drive the device. */
      34            1 : #define DEVICE_STATUS_DRIVER      1
      35              : /** Indicates the driver has successfully set up the device and is ready. */
      36            1 : #define DEVICE_STATUS_DRIVER_OK   2
      37              : /** Indicates the driver and device agreed on the negotiated feature set. */
      38            1 : #define DEVICE_STATUS_FEATURES_OK 3
      39              : /** Indicates the device requests a reset to recover from an error. */
      40            1 : #define DEVICE_STATUS_NEEDS_RESET 6
      41              : /** Indicates the device has experienced a non-recoverable error. */
      42            1 : #define DEVICE_STATUS_FAILED      7
      43              : 
      44              : /** @} */
      45              : 
      46              : /**
      47              :  * @name Feature Bits
      48              :  *
      49              :  * Negotiable device-independent feature bit positions.
      50              :  * These are described in
      51              :  * <a href=
      52              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#chapter.6">
      53              :  * 6 Reserved Feature Bits
      54              :  * </a>
      55              :  *
      56              :  * @{
      57              :  */
      58              : 
      59              : /** Indicates descriptors can reference descriptor tables. */
      60            1 : #define VIRTIO_RING_F_INDIRECT_DESC 28
      61              : /** Indicates driver/device use event index for notifications. */
      62            1 : #define VIRTIO_RING_F_EVENT_IDX     29
      63              : /** Indicates device complies with Virtio 1.0+ semantics. */
      64            1 : #define VIRTIO_F_VERSION_1          32
      65              : /** Indicates device needs platform-specific handling. */
      66            1 : #define VIRTIO_F_ACCESS_PLATFORM    33
      67              : 
      68              : /** @} */
      69              : 
      70              : /**
      71              :  * @name Ring Flag Bits
      72              :  *
      73              :  * Available and used ring flag bit positions as described in
      74              :  *
      75              :  * <a href=
      76              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#subsection.2.7.6">
      77              :  * 2.7.6 The Virtqueue Available Ring
      78              :  * </a>
      79              :  * and
      80              :  * <a href=
      81              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#subsection.2.7.8">
      82              :  * 2.7.8 The Virtqueue Used Ring
      83              :  * </a>
      84              :  *
      85              :  * @{
      86              :  */
      87              : 
      88              : /**
      89              :  * Driver requests the device to skip interrupts.
      90              :  * This is valid if @ref VIRTIO_RING_F_EVENT_IDX negotiated.
      91              :  */
      92            1 : #define VIRTQ_AVAIL_F_NO_INTERRUPT 1
      93              : 
      94              : /**
      95              :  * Device requests the driver to suppress notifications.
      96              :  * This is valid if @ref VIRTIO_RING_F_EVENT_IDX negotiated.
      97              :  */
      98            1 : #define VIRTQ_USED_F_NO_NOTIFY 1
      99              : 
     100              : /** @} */
     101              : 
     102              : /**
     103              :  * @name Ranges of feature bits
     104              :  *
     105              :  * These described in
     106              :  * <a href=
     107              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#section.2.2">
     108              :  * 2.2 Feature Bits
     109              :  * </a>
     110              :  *
     111              :  * @{
     112              :  */
     113              : 
     114              : /** Start of the first device-specific feature range. */
     115            1 : #define DEV_TYPE_FEAT_RANGE_0_BEGIN 0
     116              : /** End of the first device-specific feature range. */
     117            1 : #define DEV_TYPE_FEAT_RANGE_0_END   23
     118              : /** Start of the second device-specific feature range. */
     119            1 : #define DEV_TYPE_FEAT_RANGE_1_BEGIN 50
     120              : /** End of the second device-specific feature range. */
     121            1 : #define DEV_TYPE_FEAT_RANGE_1_END   127
     122              : 
     123              : /** @} */
     124              : 
     125              : /**
     126              :  * @name Transport interrupt bits
     127              :  *
     128              :  * While defined separately in
     129              :  *
     130              :  * <a href=
     131              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#subsubsection.4.1.4.5">
     132              :  * 4.1.4.5 ISR status capabilit </a> for PCI and
     133              :  * <a href=
     134              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#subsection.4.2.2">
     135              :  * 4.2.2 MMIO Device Register Layout </a> for MMIO
     136              :  *
     137              :  * the same bits are responsible for the same interrupts, so defines
     138              :  * with them can be unified
     139              :  *
     140              :  * @{
     141              :  */
     142              : 
     143              : /** A virtqueue has pending used buffers. */
     144            1 : #define VIRTIO_QUEUE_INTERRUPT                1
     145              : /** Device configuration space has changed. */
     146            1 : #define VIRTIO_DEVICE_CONFIGURATION_INTERRUPT 2
     147              : 
     148              : /** @} */
     149              : 
     150              : /**
     151              :  * @name VIRTIO-MMIO registers
     152              :  *
     153              :  * The details are described in
     154              :  * <a href=
     155              :  * "https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf#subsection.4.2.2">
     156              :  * 4.2.2 MMIO Device Register Layout </a>
     157              :  *
     158              :  * @{
     159              :  */
     160              : 
     161              : /** Magic value identifying the virtio MMIO device. */
     162            1 : #define VIRTIO_MMIO_MAGIC_VALUE         0x000
     163              : /** Virtio specification version exposed by the device. */
     164            1 : #define VIRTIO_MMIO_VERSION             0x004
     165              : /** Device type identifier register. */
     166            1 : #define VIRTIO_MMIO_DEVICE_ID           0x008
     167              : /** Vendor-specific identifier register. */
     168            1 : #define VIRTIO_MMIO_VENDOR_ID           0x00c
     169              : /** Lower 32 bits of the device feature bitmap. */
     170            1 : #define VIRTIO_MMIO_DEVICE_FEATURES     0x010
     171              : /** Selector choosing the device feature word. */
     172            1 : #define VIRTIO_MMIO_DEVICE_FEATURES_SEL 0x014
     173              : /** Lower 32 bits of the negotiated driver feature bitmap. */
     174            1 : #define VIRTIO_MMIO_DRIVER_FEATURES     0x020
     175              : /** Selector choosing the driver feature word. */
     176            1 : #define VIRTIO_MMIO_DRIVER_FEATURES_SEL 0x024
     177              : /** Virtqueue index selected for subsequent accesses. */
     178            1 : #define VIRTIO_MMIO_QUEUE_SEL           0x030
     179              : /** Maximum queue size supported by the selected virtqueue. */
     180            1 : #define VIRTIO_MMIO_QUEUE_SIZE_MAX      0x034
     181              : /** Queue size chosen by the driver for the selected virtqueue. */
     182            1 : #define VIRTIO_MMIO_QUEUE_SIZE          0x038
     183              : /** Ready flag indicating driver ownership of the queue. */
     184            1 : #define VIRTIO_MMIO_QUEUE_READY         0x044
     185              : /** Doorbell register for queue notifications. */
     186            1 : #define VIRTIO_MMIO_QUEUE_NOTIFY        0x050
     187              : /** Pending interrupt summary bits. */
     188            1 : #define VIRTIO_MMIO_INTERRUPT_STATUS    0x060
     189              : /** Interrupt acknowledgment register. */
     190            1 : #define VIRTIO_MMIO_INTERRUPT_ACK       0x064
     191              : /** Device status. */
     192            1 : #define VIRTIO_MMIO_STATUS              0x070
     193              : /** Lower 32 bits of the descriptor table address. */
     194            1 : #define VIRTIO_MMIO_QUEUE_DESC_LOW      0x080
     195              : /** Upper 32 bits of the descriptor table address. */
     196            1 : #define VIRTIO_MMIO_QUEUE_DESC_HIGH     0x084
     197              : /** Lower 32 bits of the available ring address. */
     198            1 : #define VIRTIO_MMIO_QUEUE_AVAIL_LOW     0x090
     199              : /** Upper 32 bits of the available ring address. */
     200            1 : #define VIRTIO_MMIO_QUEUE_AVAIL_HIGH    0x094
     201              : /** Lower 32 bits of the used ring address. */
     202            1 : #define VIRTIO_MMIO_QUEUE_USED_LOW      0x0a0
     203              : /** Upper 32 bits of the used ring address. */
     204            1 : #define VIRTIO_MMIO_QUEUE_USED_HIGH     0x0a4
     205              : /** Shared memory region selector. */
     206            1 : #define VIRTIO_MMIO_SHM_SEL             0x0ac
     207              : /** Lower 32 bits of the shared memory length. */
     208            1 : #define VIRTIO_MMIO_SHM_LEN_LOW         0x0b0
     209              : /** Upper 32 bits of the shared memory length. */
     210            1 : #define VIRTIO_MMIO_SHM_LEN_HIGH        0x0b4
     211              : /** Lower 32 bits of the shared memory base address. */
     212            1 : #define VIRTIO_MMIO_SHM_BASE_LOW        0x0b8
     213              : /** Upper 32 bits of the shared memory base address. */
     214            1 : #define VIRTIO_MMIO_SHM_BASE_HIGH       0x0bc
     215              : /** Queue reset control register. */
     216            1 : #define VIRTIO_MMIO_QUEUE_RESET         0x0c0
     217              : /** Generation counter for configuration space. */
     218            1 : #define VIRTIO_MMIO_CONFIG_GENERATION   0x0fc
     219              : /** Base offset of the device configuration structure. */
     220            1 : #define VIRTIO_MMIO_CONFIG              0x100
     221              : 
     222              : /** @} */
     223              : 
     224              : #endif /* ZEPHYR_DRIVERS_VIRTIO_VIRTIO_CONFIG_H_ */
        

Generated by: LCOV version 2.0-1