45
45
*/
46
46
#define DEV_STRUCT (vs ) ((void *)(vs))
47
47
48
- /*
49
- * Link a virtio_base to its constants, the virtio device, and
50
- * the PCI emulation.
48
+ /**
49
+ * @brief Link a virtio_base to its constants, the virtio device,
50
+ * and the PCI emulation.
51
+ *
52
+ * @param base Pointer to struct virtio_base.
53
+ * @param vops Pointer to struct virtio_ops.
54
+ * @param pci_virtio_dev Pointer to instance of certain virtio device.
55
+ * @param dev Pointer to struct pci_vdev which emulates a PCI device.
56
+ * @param queues Pointer to struct virtio_vq_info, normally an array.
57
+ *
58
+ * @return NULL
51
59
*/
52
60
void
53
61
virtio_linkup (struct virtio_base * base , struct virtio_ops * vops ,
@@ -69,14 +77,19 @@ virtio_linkup(struct virtio_base *base, struct virtio_ops *vops,
69
77
}
70
78
}
71
79
72
- /*
73
- * Reset device (device-wide). This erases all queues, i.e.,
74
- * all the queues become invalid (though we don't wipe out the
75
- * internal pointers, we just clear the VQ_ALLOC flag).
80
+ /**
81
+ * @brief Reset device (device-wide).
76
82
*
77
- * It resets negotiated features to "none".
83
+ * This erases all queues, i.e., all the queues become invalid.
84
+ * But we don't wipe out the internal pointers, by just clearing
85
+ * the VQ_ALLOC flag.
78
86
*
87
+ * It resets negotiated features to "none".
79
88
* If MSI-X is enabled, this also resets all the vectors to NO_VECTOR.
89
+ *
90
+ * @param base Pointer to struct virtio_base.
91
+ *
92
+ * @return N/A
80
93
*/
81
94
void
82
95
virtio_reset_dev (struct virtio_base * base )
@@ -114,8 +127,13 @@ virtio_reset_dev(struct virtio_base *base)
114
127
base -> config_generation = 0 ;
115
128
}
116
129
117
- /*
118
- * Set I/O BAR (usually 0) to map PCI config registers.
130
+ /**
131
+ * @brief Set I/O BAR (usually 0) to map PCI config registers.
132
+ *
133
+ * @param base Pointer to struct virtio_base.
134
+ * @param barnum Which BAR[0..5] to use.
135
+ *
136
+ * @return N/A
119
137
*/
120
138
void
121
139
virtio_set_io_bar (struct virtio_base * base , int barnum )
@@ -131,12 +149,19 @@ virtio_set_io_bar(struct virtio_base *base, int barnum)
131
149
base -> legacy_pio_bar_idx = barnum ;
132
150
}
133
151
134
- /*
135
- * Initialize MSI-X vector capabilities if we're to use MSI-X,
152
+ /**
153
+ * @brief Initialize MSI-X vector capabilities if we're to use MSI-X,
136
154
* or MSI capabilities if not.
137
155
*
138
156
* We assume we want one MSI-X vector per queue, here, plus one
139
157
* for the config vec.
158
+ *
159
+ *
160
+ * @param base Pointer to struct virtio_base.
161
+ * @param barnum Which BAR[0..5] to use.
162
+ * @param use_msix If using MSI-X.
163
+ *
164
+ * @return 0 on success and non-zero on fail.
140
165
*/
141
166
int
142
167
virtio_intr_init (struct virtio_base * base , int barnum , int use_msix )
@@ -163,12 +188,17 @@ virtio_intr_init(struct virtio_base *base, int barnum, int use_msix)
163
188
return 0 ;
164
189
}
165
190
166
- /*
167
- * Initialize MSI-X vector capabilities if we're to use MSI-X,
191
+ /**
192
+ * @brief Initialize MSI-X vector capabilities if we're to use MSI-X,
168
193
* or MSI capabilities if not.
169
194
*
170
- * Wrapper function for virtio_intr_init() since by default we
171
- * will use bar 1 for MSI-X.
195
+ * Wrapper function for virtio_intr_init() for cases we directly use
196
+ * BAR 1 for MSI-X capabilities.
197
+ *
198
+ * @param base Pointer to struct virtio_base.
199
+ * @param use_msix If using MSI-X.
200
+ *
201
+ * @return 0 on success and non-zero on fail.
172
202
*/
173
203
int
174
204
virtio_interrupt_init (struct virtio_base * base , int use_msix )
@@ -1006,6 +1036,18 @@ virtio_set_modern_pio_bar(struct virtio_base *base, int barnum)
1006
1036
return 0 ;
1007
1037
}
1008
1038
1039
+ /**
1040
+ * @brief Set modern BAR (usually 4) to map PCI config registers.
1041
+ *
1042
+ * Set modern MMIO BAR (usually 4) to map virtio 1.0 capabilities and optional
1043
+ * set modern PIO BAR (usually 2) to map notify capability. This interface is
1044
+ * only valid for modern virtio.
1045
+ *
1046
+ * @param base Pointer to struct virtio_base.
1047
+ * @param use_notify_pio Whether use pio for notify capability.
1048
+ *
1049
+ * @return 0 on success and non-zero on fail.
1050
+ */
1009
1051
int
1010
1052
virtio_set_modern_bar (struct virtio_base * base , bool use_notify_pio )
1011
1053
{
@@ -1027,6 +1069,17 @@ virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio)
1027
1069
return rc ;
1028
1070
}
1029
1071
1072
+ /**
1073
+ * @brief Indicate the device has experienced an error.
1074
+ *
1075
+ * This is called when the device has experienced an error from which it
1076
+ * cannot re-cover. DEVICE_NEEDS_RESET is set to the device status register
1077
+ * and a config change intr is sent to the guest driver.
1078
+ *
1079
+ * @param base Pointer to struct virtio_base.
1080
+ *
1081
+ * @return N/A
1082
+ */
1030
1083
void
1031
1084
virtio_dev_error (struct virtio_base * base )
1032
1085
{
@@ -1604,6 +1657,21 @@ virtio_pci_modern_pio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
1604
1657
pthread_mutex_unlock (base -> mtx );
1605
1658
}
1606
1659
1660
+ /**
1661
+ * @brief Handle PCI configuration space reads.
1662
+ *
1663
+ * Handle virtio standard register reads, and dispatch other reads to
1664
+ * actual virtio device driver.
1665
+ *
1666
+ * @param ctx Pointer to struct vmctx representing VM context.
1667
+ * @param vcpu VCPU ID.
1668
+ * @param dev Pointer to struct pci_vdev which emulates a PCI device.
1669
+ * @param baridx Which BAR[0..5] to use.
1670
+ * @param offset Register offset in bytes within a BAR region.
1671
+ * @param size Access range in bytes.
1672
+ *
1673
+ * @return register value.
1674
+ */
1607
1675
uint64_t
1608
1676
virtio_pci_read (struct vmctx * ctx , int vcpu , struct pci_vdev * dev ,
1609
1677
int baridx , uint64_t offset , int size )
@@ -1634,6 +1702,22 @@ virtio_pci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
1634
1702
return size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff ;
1635
1703
}
1636
1704
1705
+ /**
1706
+ * @brief Handle PCI configuration space writes.
1707
+ *
1708
+ * Handle virtio standard register writes, and dispatch other writes to
1709
+ * actual virtio device driver.
1710
+ *
1711
+ * @param ctx Pointer to struct vmctx representing VM context.
1712
+ * @param vcpu VCPU ID.
1713
+ * @param dev Pointer to struct pci_vdev which emulates a PCI device.
1714
+ * @param baridx Which BAR[0..5] to use.
1715
+ * @param offset Register offset in bytes within a BAR region.
1716
+ * @param size Access range in bytes.
1717
+ * @param value Data value to be written into register.
1718
+ *
1719
+ * @return N/A
1720
+ */
1637
1721
void
1638
1722
virtio_pci_write (struct vmctx * ctx , int vcpu , struct pci_vdev * dev ,
1639
1723
int baridx , uint64_t offset , int size , uint64_t value )
@@ -1670,6 +1754,22 @@ virtio_pci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
1670
1754
base -> vops -> name , baridx );
1671
1755
}
1672
1756
1757
+ /**
1758
+ * @brief Handle PCI configuration space reads.
1759
+ *
1760
+ * Handle virtio PCI configuration space reads. Only the specific registers
1761
+ * that need speical operation are handled in this callback. For others just
1762
+ * fallback to pci core. This interface is only valid for virtio modern.
1763
+ *
1764
+ * @param ctx Pointer to struct vmctx representing VM context.
1765
+ * @param vcpu VCPU ID.
1766
+ * @param dev Pointer to struct pci_vdev which emulates a PCI device.
1767
+ * @param coff Register offset in bytes within PCI configuration space.
1768
+ * @param bytes Access range in bytes.
1769
+ * @param rv The value returned as read.
1770
+ *
1771
+ * @return 0 on handled and non-zero on non-handled.
1772
+ */
1673
1773
int
1674
1774
virtio_pci_modern_cfgread (struct vmctx * ctx , int vcpu , struct pci_vdev * dev ,
1675
1775
int coff , int bytes , uint32_t * rv )
@@ -1719,6 +1819,22 @@ virtio_pci_modern_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
1719
1819
return -1 ;
1720
1820
}
1721
1821
1822
+ /**
1823
+ * @brief Handle PCI configuration space writes.
1824
+ *
1825
+ * Handle virtio PCI configuration space writes. Only the specific registers
1826
+ * that need speical operation are handled in this callback. For others just
1827
+ * fallback to pci core. This interface is only valid for virtio modern.
1828
+ *
1829
+ * @param ctx Pointer to struct vmctx representing VM context.
1830
+ * @param vcpu VCPU ID.
1831
+ * @param dev Pointer to struct pci_vdev which emulates a PCI device.
1832
+ * @param coff Register offset in bytes within PCI configuration space.
1833
+ * @param bytes Access range in bytes.
1834
+ * @param val The value to write.
1835
+ *
1836
+ * @return 0 on handled and non-zero on non-handled.
1837
+ */
1722
1838
int
1723
1839
virtio_pci_modern_cfgwrite (struct vmctx * ctx , int vcpu , struct pci_vdev * dev ,
1724
1840
int coff , int bytes , uint32_t val )
0 commit comments