aboutsummaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-01-20 09:46:32 +0000
committerGitHub <noreply@github.com>2021-01-20 09:46:32 +0000
commit5aa56c58446c43f085da7ff6ca339d7361b8302d (patch)
tree1561f51430830157615fcaf79ed5e92d37ce95d5 /samples
parent7a9335eb438d29bf5be8caa67bf5252bb891076f (diff)
downloadlibvfio-user-5aa56c58446c43f085da7ff6ca339d7361b8302d.zip
libvfio-user-5aa56c58446c43f085da7ff6ca339d7361b8302d.tar.gz
libvfio-user-5aa56c58446c43f085da7ff6ca339d7361b8302d.tar.bz2
re-work API for adding capabilities (#200)
Allow to add capabilities individually, including extended capabilities, and those to be handled via the region callback. As a side effect, rework config space accesses to handle reads that straddle capabilities and non-standard areas and use callbacks as needed. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples')
-rw-r--r--samples/lspci.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/samples/lspci.c b/samples/lspci.c
index e2fa6fc..9484042 100644
--- a/samples/lspci.c
+++ b/samples/lspci.c
@@ -30,10 +30,11 @@
*
*/
-#include <stdio.h>
#include <err.h>
-#include <stdlib.h>
#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "libvfio-user.h"
@@ -42,9 +43,9 @@ int main(void)
int i, j;
char *buf;
const int bytes_per_line = 0x10;
- vfu_cap_t pm = { .pm = { .hdr.id = PCI_CAP_ID_PM, .pmcs.nsfrst = 0x1 } };
- vfu_cap_t *vsc = alloca(sizeof(*vsc) + 0xd);
- vfu_cap_t *caps[2] = { &pm, vsc };
+ struct vsc *vsc = alloca(sizeof(*vsc) + 0xd);
+ struct pmcap pm = { .hdr.id = PCI_CAP_ID_PM, .pmcs.nsfrst = 0x1 };
+
vfu_ctx_t *vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, "",
LIBVFIO_USER_FLAG_ATTACH_NB, NULL,
VFU_DEV_TYPE_PCI);
@@ -55,11 +56,20 @@ int main(void)
PCI_HEADER_TYPE_NORMAL, 0) < 0) {
err(EXIT_FAILURE, "vfu_pci_init() failed");
}
- 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_pci_add_capability(vfu_ctx, 0, 0, &pm) < 0) {
+ err(EXIT_FAILURE, "vfu_pci_add_capability() failed");
}
+
+ memset(vsc, 0, 0x10);
+ vsc->hdr.id = PCI_CAP_ID_VNDR;
+ vsc->size = 0x10;
+ memcpy(vsc->data, "abcdefgh", 8);
+
+ if (vfu_pci_add_capability(vfu_ctx, 0, 0, vsc) < 0) {
+ err(EXIT_FAILURE, "vfu_pci_add_capability() failed");
+ }
+
if (vfu_realize_ctx(vfu_ctx) < 0) {
err(EXIT_FAILURE, "failed to realize device");
}