From 90211fbd2c7c310df593736b18f1c99f053e2957 Mon Sep 17 00:00:00 2001 From: Thanos Makatos Date: Tue, 8 Dec 2020 10:58:29 -0500 Subject: 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 --- samples/lspci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'samples') 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); -- cgit v1.1