Skip to content

Commit d261b4b

Browse files
Shuo Liudbkinder
authored andcommitted
doc: update virtio related functions doc comments
Update some virtio, VBS-K, vhost APIs documents. Tracked-On: #1595 Signed-off-by: Shuo Liu <shuo.a.liu@intel.com>
1 parent ea801a1 commit d261b4b

File tree

13 files changed

+647
-89
lines changed

13 files changed

+647
-89
lines changed

devicemodel/core/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ pincpu_parse(const char *opt)
209209
return 0;
210210
}
211211

212+
/**
213+
* @brief Convert guest physical address to host virtual address
214+
*
215+
* @param ctx Pointer to to struct vmctx representing VM context.
216+
* @param gaddr Guest physical address base.
217+
* @param len Guest physical address length.
218+
*
219+
* @return NULL on convert failed and host virtual address on successful.
220+
*/
212221
void *
213222
paddr_guest2host(struct vmctx *ctx, uintptr_t gaddr, size_t len)
214223
{

devicemodel/hw/pci/core.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,14 @@ pci_msix_enabled(struct pci_vdev *dev)
16381638
return (dev->msix.enabled && !dev->msi.enabled);
16391639
}
16401640

1641+
/**
1642+
* @brief Generate a MSI-X interrupt to guest
1643+
*
1644+
* @param dev Pointer to struct pci_vdev representing virtual PCI device.
1645+
* @param index MSIx table entry index.
1646+
*
1647+
* @return N/A
1648+
*/
16411649
void
16421650
pci_generate_msix(struct pci_vdev *dev, int index)
16431651
{
@@ -1659,6 +1667,14 @@ pci_generate_msix(struct pci_vdev *dev, int index)
16591667
}
16601668
}
16611669

1670+
/**
1671+
* @brief Generate a MSI interrupt to guest
1672+
*
1673+
* @param dev Pointer to struct pci_vdev representing virtual PCI device.
1674+
* @param index Message data index.
1675+
*
1676+
* @return N/A
1677+
*/
16621678
void
16631679
pci_generate_msi(struct pci_vdev *dev, int index)
16641680
{
@@ -1760,6 +1776,13 @@ pci_lintr_route(struct pci_vdev *dev)
17601776
pci_set_cfgdata8(dev, PCIR_INTLINE, pirq_irq(ii->ii_pirq_pin));
17611777
}
17621778

1779+
/**
1780+
* @brief Assert INTx pin of virtual PCI device
1781+
*
1782+
* @param dev Pointer to struct pci_vdev representing virtual PCI device.
1783+
*
1784+
* @return N/A
1785+
*/
17631786
void
17641787
pci_lintr_assert(struct pci_vdev *dev)
17651788
{
@@ -1776,6 +1799,13 @@ pci_lintr_assert(struct pci_vdev *dev)
17761799
pthread_mutex_unlock(&dev->lintr.lock);
17771800
}
17781801

1802+
/**
1803+
* @brief Deassert INTx pin of virtual PCI device
1804+
*
1805+
* @param dev Pointer to struct pci_vdev representing virtual PCI device.
1806+
*
1807+
* @return N/A
1808+
*/
17791809
void
17801810
pci_lintr_deassert(struct pci_vdev *dev)
17811811
{

devicemodel/hw/pci/virtio/vhost.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,22 @@ vhost_set_mem_table(struct vhost_dev *vdev)
581581
return 0;
582582
}
583583

584+
/**
585+
* @brief vhost_dev initialization.
586+
*
587+
* This interface is called to initialize the vhost_dev. It must be called
588+
* before the actual feature negotiation with the guest OS starts.
589+
*
590+
* @param vdev Pointer to struct vhost_dev.
591+
* @param base Pointer to struct virtio_base.
592+
* @param fd fd of the vhost chardev.
593+
* @param vq_idx The first virtqueue which would be used by this vhost dev.
594+
* @param vhost_features Subset of vhost features which would be enabled.
595+
* @param vhost_ext_features Specific vhost internal features to be enabled.
596+
* @param busyloop_timeout Busy loop timeout in us.
597+
*
598+
* @return 0 on success and -1 on failure.
599+
*/
584600
int
585601
vhost_dev_init(struct vhost_dev *vdev,
586602
struct virtio_base *base,
@@ -645,6 +661,15 @@ vhost_dev_init(struct vhost_dev *vdev,
645661
return -1;
646662
}
647663

664+
/**
665+
* @brief vhost_dev cleanup.
666+
*
667+
* This interface is called to cleanup the vhost_dev.
668+
*
669+
* @param vdev Pointer to struct vhost_dev.
670+
*
671+
* @return 0 on success and -1 on failure.
672+
*/
648673
int
649674
vhost_dev_deinit(struct vhost_dev *vdev)
650675
{
@@ -661,6 +686,15 @@ vhost_dev_deinit(struct vhost_dev *vdev)
661686
return 0;
662687
}
663688

689+
/**
690+
* @brief start vhost data plane.
691+
*
692+
* This interface is called to start the data plane in vhost.
693+
*
694+
* @param vdev Pointer to struct vhost_dev.
695+
*
696+
* @return 0 on success and -1 on failure.
697+
*/
664698
int
665699
vhost_dev_start(struct vhost_dev *vdev)
666700
{
@@ -736,6 +770,15 @@ vhost_dev_start(struct vhost_dev *vdev)
736770
return -1;
737771
}
738772

773+
/**
774+
* @brief stop vhost data plane.
775+
*
776+
* This interface is called to stop the data plane in vhost.
777+
*
778+
* @param vdev Pointer to struct vhost_dev.
779+
*
780+
* @return 0 on success and -1 on failure.
781+
*/
739782
int
740783
vhost_dev_stop(struct vhost_dev *vdev)
741784
{
@@ -758,6 +801,17 @@ vhost_dev_stop(struct vhost_dev *vdev)
758801
return rc;
759802
}
760803

804+
/**
805+
* @brief set backend fd of vhost net.
806+
*
807+
* This interface is called to set the backend fd (for example tap fd)
808+
* to vhost.
809+
*
810+
* @param vdev Pointer to struct vhost_dev.
811+
* @param backend_fd fd of backend (for example tap fd).
812+
*
813+
* @return 0 on success and -1 on failure.
814+
*/
761815
int
762816
vhost_net_set_backend(struct vhost_dev *vdev, int backend_fd)
763817
{

devicemodel/hw/pci/virtio/virtio.c

Lines changed: 132 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@
4545
*/
4646
#define DEV_STRUCT(vs) ((void *)(vs))
4747

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
5159
*/
5260
void
5361
virtio_linkup(struct virtio_base *base, struct virtio_ops *vops,
@@ -69,14 +77,19 @@ virtio_linkup(struct virtio_base *base, struct virtio_ops *vops,
6977
}
7078
}
7179

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).
7682
*
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.
7886
*
87+
* It resets negotiated features to "none".
7988
* 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
8093
*/
8194
void
8295
virtio_reset_dev(struct virtio_base *base)
@@ -114,8 +127,13 @@ virtio_reset_dev(struct virtio_base *base)
114127
base->config_generation = 0;
115128
}
116129

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
119137
*/
120138
void
121139
virtio_set_io_bar(struct virtio_base *base, int barnum)
@@ -131,12 +149,19 @@ virtio_set_io_bar(struct virtio_base *base, int barnum)
131149
base->legacy_pio_bar_idx = barnum;
132150
}
133151

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,
136154
* or MSI capabilities if not.
137155
*
138156
* We assume we want one MSI-X vector per queue, here, plus one
139157
* 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.
140165
*/
141166
int
142167
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)
163188
return 0;
164189
}
165190

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,
168193
* or MSI capabilities if not.
169194
*
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.
172202
*/
173203
int
174204
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)
10061036
return 0;
10071037
}
10081038

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+
*/
10091051
int
10101052
virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio)
10111053
{
@@ -1027,6 +1069,17 @@ virtio_set_modern_bar(struct virtio_base *base, bool use_notify_pio)
10271069
return rc;
10281070
}
10291071

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+
*/
10301083
void
10311084
virtio_dev_error(struct virtio_base *base)
10321085
{
@@ -1604,6 +1657,21 @@ virtio_pci_modern_pio_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
16041657
pthread_mutex_unlock(base->mtx);
16051658
}
16061659

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+
*/
16071675
uint64_t
16081676
virtio_pci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
16091677
int baridx, uint64_t offset, int size)
@@ -1634,6 +1702,22 @@ virtio_pci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
16341702
return size == 1 ? 0xff : size == 2 ? 0xffff : 0xffffffff;
16351703
}
16361704

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+
*/
16371721
void
16381722
virtio_pci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
16391723
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,
16701754
base->vops->name, baridx);
16711755
}
16721756

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+
*/
16731773
int
16741774
virtio_pci_modern_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
16751775
int coff, int bytes, uint32_t *rv)
@@ -1719,6 +1819,22 @@ virtio_pci_modern_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
17191819
return -1;
17201820
}
17211821

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+
*/
17221838
int
17231839
virtio_pci_modern_cfgwrite(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
17241840
int coff, int bytes, uint32_t val)

0 commit comments

Comments
 (0)