aboutsummaryrefslogtreecommitdiff
path: root/samples/lspci.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2020-12-08 10:58:29 -0500
committerThanos Makatos <tmakatos@gmail.com>2020-12-11 12:54:21 +0000
commit90211fbd2c7c310df593736b18f1c99f053e2957 (patch)
tree03462a28541581cbf3ea6eb8f9fde05591c3e893 /samples/lspci.c
parenta7ecdc3de9f237d600ceaaa44285115a4e790829 (diff)
downloadlibvfio-user-90211fbd2c7c310df593736b18f1c99f053e2957.zip
libvfio-user-90211fbd2c7c310df593736b18f1c99f053e2957.tar.gz
libvfio-user-90211fbd2c7c310df593736b18f1c99f053e2957.tar.bz2
add support PCI vendor-specific capability
The PCI vendor-specific capability is blindly read/written by the library. It is possible that the user might want to intercept accesses to it, in which case we'll have to add callback. The best way to do this to introduce a new function that configures callbacks for the PCI capabilities, e.g. typedef ssize_t (vfu_cap_access_t) (void *pvt, uint8_t id, char *buf, size_t count, loff_t offset, bool is_write); vfu_pci_cap_set_cb(vfu_ctx-T *vfu_ctx, uint8_t cap_id, vfu_cap_access_t *cb); This way the existing API won't have to change. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples/lspci.c')
-rw-r--r--samples/lspci.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/samples/lspci.c b/samples/lspci.c
index 20d938a..61861d6 100644
--- a/samples/lspci.c
+++ b/samples/lspci.c
@@ -46,7 +46,8 @@ int main(void)
vfu_pci_hdr_ss_t ss = { 0 };
vfu_pci_hdr_cc_t cc = { { 0 } };
vfu_cap_t pm = { .pm = { .hdr.id = PCI_CAP_ID_PM, .pmcs.nsfrst = 0x1 } };
- vfu_cap_t *caps[1] = { &pm };
+ vfu_cap_t *vsc = alloca(sizeof(*vsc) + 0xd);
+ vfu_cap_t *caps[2] = { &pm, vsc };
vfu_ctx_t *vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, "",
LIBVFIO_USER_FLAG_ATTACH_NB, NULL,
VFU_DEV_TYPE_PCI);
@@ -56,13 +57,15 @@ int main(void)
if (vfu_pci_setup_config_hdr(vfu_ctx, id, ss, cc, VFU_PCI_TYPE_CONVENTIONAL, 0) < 0) {
err(EXIT_FAILURE, "failed to setup PCI configuration space header");
}
- if (vfu_pci_setup_caps(vfu_ctx, caps, 1) < 0) {
+ vsc->vsc.hdr.id = PCI_CAP_ID_VNDR;
+ vsc->vsc.size = 0x10;
+ if (vfu_pci_setup_caps(vfu_ctx, caps, 2) < 0) {
err(EXIT_FAILURE, "failed to setup PCI capabilities");
}
if (vfu_realize_ctx(vfu_ctx) < 0) {
err(EXIT_FAILURE, "failed to realize device");
}
- buf = (char*)vfu_pci_get_config_space(vfu_ctx);;
+ buf = (char*)vfu_pci_get_config_space(vfu_ctx);
printf("00:00.0 bogus PCI device\n");
for (i = 0; i < PCI_CFG_SPACE_SIZE / bytes_per_line; i++) {
printf("%02x:", i * bytes_per_line);