Skip to content

Commit 92f0083

Browse files
committed
drivers: virtio: Separate macros into a common header
Move macros derived from the virtio specification to a shared include. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent dc62a25 commit 92f0083

File tree

4 files changed

+82
-61
lines changed

4 files changed

+82
-61
lines changed

drivers/virtio/virtio_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <zephyr/logging/log.h>
88
#include <zephyr/sys/byteorder.h>
99
#include <zephyr/drivers/virtio.h>
10+
#include <zephyr/drivers/virtio/virtio_config.h>
1011
#include <zephyr/drivers/virtio/virtqueue.h>
1112
#include "virtio_common.h"
1213

drivers/virtio/virtio_common.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,6 @@
77
#ifndef ZEPHYR_VIRTIO_VIRTIO_COMMON_H_
88
#define ZEPHYR_VIRTIO_VIRTIO_COMMON_H_
99

10-
#define DEVICE_STATUS_ACKNOWLEDGE 0
11-
#define DEVICE_STATUS_DRIVER 1
12-
#define DEVICE_STATUS_DRIVER_OK 2
13-
#define DEVICE_STATUS_FEATURES_OK 3
14-
#define DEVICE_STATUS_NEEDS_RESET 6
15-
#define DEVICE_STATUS_FAILED 7
16-
17-
#define VIRTIO_F_VERSION_1 32
18-
19-
/* Ranges of feature bits for specific device types (see spec 2.2)*/
20-
#define DEV_TYPE_FEAT_RANGE_0_BEGIN 0
21-
#define DEV_TYPE_FEAT_RANGE_0_END 23
22-
#define DEV_TYPE_FEAT_RANGE_1_BEGIN 50
23-
#define DEV_TYPE_FEAT_RANGE_1_END 127
24-
25-
/*
26-
* While defined separately in 4.1.4.5 for PCI and in 4.2.2 for MMIO
27-
* the same bits are responsible for the same interrupts, so defines
28-
* with them can be unified
29-
*/
30-
#define VIRTIO_QUEUE_INTERRUPT 1
31-
#define VIRTIO_DEVICE_CONFIGURATION_INTERRUPT 2
32-
33-
/*
34-
* VIRTIO-MMIO register definitions.
35-
*
36-
* Based on Virtual I/O Device (VIRTIO) Version 1.3 specification:
37-
* https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf
38-
*/
39-
40-
#define VIRTIO_MMIO_MAGIC_VALUE 0x000
41-
#define VIRTIO_MMIO_VERSION 0x004
42-
#define VIRTIO_MMIO_DEVICE_ID 0x008
43-
#define VIRTIO_MMIO_VENDOR_ID 0x00c
44-
#define VIRTIO_MMIO_DEVICE_FEATURES 0x010
45-
#define VIRTIO_MMIO_DEVICE_FEATURES_SEL 0x014
46-
#define VIRTIO_MMIO_DRIVER_FEATURES 0x020
47-
#define VIRTIO_MMIO_DRIVER_FEATURES_SEL 0x024
48-
#define VIRTIO_MMIO_QUEUE_SEL 0x030
49-
#define VIRTIO_MMIO_QUEUE_SIZE_MAX 0x034
50-
#define VIRTIO_MMIO_QUEUE_SIZE 0x038
51-
#define VIRTIO_MMIO_QUEUE_READY 0x044
52-
#define VIRTIO_MMIO_QUEUE_NOTIFY 0x050
53-
#define VIRTIO_MMIO_INTERRUPT_STATUS 0x060
54-
#define VIRTIO_MMIO_INTERRUPT_ACK 0x064
55-
#define VIRTIO_MMIO_STATUS 0x070
56-
#define VIRTIO_MMIO_QUEUE_DESC_LOW 0x080
57-
#define VIRTIO_MMIO_QUEUE_DESC_HIGH 0x084
58-
#define VIRTIO_MMIO_QUEUE_AVAIL_LOW 0x090
59-
#define VIRTIO_MMIO_QUEUE_AVAIL_HIGH 0x094
60-
#define VIRTIO_MMIO_QUEUE_USED_LOW 0x0a0
61-
#define VIRTIO_MMIO_QUEUE_USED_HIGH 0x0a4
62-
#define VIRTIO_MMIO_SHM_SEL 0x0ac
63-
#define VIRTIO_MMIO_SHM_LEN_LOW 0x0b0
64-
#define VIRTIO_MMIO_SHM_LEN_HIGH 0x0b4
65-
#define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8
66-
#define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc
67-
#define VIRTIO_MMIO_QUEUE_RESET 0x0c0
68-
#define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc
69-
#define VIRTIO_MMIO_CONFIG 0x100
70-
7110
/**
7211
* Common virtio isr
7312
*

drivers/virtio/virtio_mmio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/sys/barrier.h>
1212
#include <zephyr/sys/byteorder.h>
1313
#include <zephyr/drivers/virtio.h>
14+
#include <zephyr/drivers/virtio/virtio_config.h>
1415
#include <zephyr/drivers/virtio/virtqueue.h>
1516
#include "virtio_common.h"
1617

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2025 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_VIRTIO_VIRTIO_DEFINES_H_
8+
#define ZEPHYR_DRIVERS_VIRTIO_VIRTIO_DEFINES_H_
9+
10+
#define DEVICE_STATUS_ACKNOWLEDGE 0
11+
#define DEVICE_STATUS_DRIVER 1
12+
#define DEVICE_STATUS_DRIVER_OK 2
13+
#define DEVICE_STATUS_FEATURES_OK 3
14+
#define DEVICE_STATUS_NEEDS_RESET 6
15+
#define DEVICE_STATUS_FAILED 7
16+
17+
#define VIRTIO_F_ANY_LAYOUT 27
18+
#define VIRTIO_F_VERSION_1 32
19+
#define VIRTIO_F_ACCESS_PLATFORM 33
20+
21+
#define VIRTIO_RING_F_INDIRECT_DESC 28
22+
#define VIRTIO_RING_F_EVENT_IDX 29
23+
24+
#define VIRTQ_AVAIL_F_NO_INTERRUPT 1
25+
26+
#define VIRTQ_USED_F_NO_NOTIFY 1
27+
28+
/* Ranges of feature bits for specific device types (see spec 2.2)*/
29+
#define DEV_TYPE_FEAT_RANGE_0_BEGIN 0
30+
#define DEV_TYPE_FEAT_RANGE_0_END 23
31+
#define DEV_TYPE_FEAT_RANGE_1_BEGIN 50
32+
#define DEV_TYPE_FEAT_RANGE_1_END 127
33+
34+
/*
35+
* While defined separately in 4.1.4.5 for PCI and in 4.2.2 for MMIO
36+
* the same bits are responsible for the same interrupts, so defines
37+
* with them can be unified
38+
*/
39+
#define VIRTIO_QUEUE_INTERRUPT 1
40+
#define VIRTIO_DEVICE_CONFIGURATION_INTERRUPT 2
41+
42+
/*
43+
* VIRTIO-MMIO register definitions.
44+
*
45+
* Based on Virtual I/O Device (VIRTIO) Version 1.3 specification:
46+
* https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/virtio-v1.3-csd01.pdf
47+
*/
48+
49+
#define VIRTIO_MMIO_MAGIC_VALUE 0x000
50+
#define VIRTIO_MMIO_VERSION 0x004
51+
#define VIRTIO_MMIO_DEVICE_ID 0x008
52+
#define VIRTIO_MMIO_VENDOR_ID 0x00c
53+
#define VIRTIO_MMIO_DEVICE_FEATURES 0x010
54+
#define VIRTIO_MMIO_DEVICE_FEATURES_SEL 0x014
55+
#define VIRTIO_MMIO_DRIVER_FEATURES 0x020
56+
#define VIRTIO_MMIO_DRIVER_FEATURES_SEL 0x024
57+
#define VIRTIO_MMIO_QUEUE_SEL 0x030
58+
#define VIRTIO_MMIO_QUEUE_SIZE_MAX 0x034
59+
#define VIRTIO_MMIO_QUEUE_SIZE 0x038
60+
#define VIRTIO_MMIO_QUEUE_READY 0x044
61+
#define VIRTIO_MMIO_QUEUE_NOTIFY 0x050
62+
#define VIRTIO_MMIO_INTERRUPT_STATUS 0x060
63+
#define VIRTIO_MMIO_INTERRUPT_ACK 0x064
64+
#define VIRTIO_MMIO_STATUS 0x070
65+
#define VIRTIO_MMIO_QUEUE_DESC_LOW 0x080
66+
#define VIRTIO_MMIO_QUEUE_DESC_HIGH 0x084
67+
#define VIRTIO_MMIO_QUEUE_AVAIL_LOW 0x090
68+
#define VIRTIO_MMIO_QUEUE_AVAIL_HIGH 0x094
69+
#define VIRTIO_MMIO_QUEUE_USED_LOW 0x0a0
70+
#define VIRTIO_MMIO_QUEUE_USED_HIGH 0x0a4
71+
#define VIRTIO_MMIO_SHM_SEL 0x0ac
72+
#define VIRTIO_MMIO_SHM_LEN_LOW 0x0b0
73+
#define VIRTIO_MMIO_SHM_LEN_HIGH 0x0b4
74+
#define VIRTIO_MMIO_SHM_BASE_LOW 0x0b8
75+
#define VIRTIO_MMIO_SHM_BASE_HIGH 0x0bc
76+
#define VIRTIO_MMIO_QUEUE_RESET 0x0c0
77+
#define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc
78+
#define VIRTIO_MMIO_CONFIG 0x100
79+
80+
#endif /* ZEPHYR_DRIVERS_VIRTIO_VIRTIO_DEFINES_H_ */

0 commit comments

Comments
 (0)