aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libvfio-user.h9
-rw-r--r--lib/libvfio-user.c9
-rw-r--r--lib/private.h1
-rw-r--r--samples/gpio-pci-idio-16.c3
-rw-r--r--samples/null.c3
-rw-r--r--samples/server.c3
6 files changed, 23 insertions, 5 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h
index ed4e302..721ea5d 100644
--- a/include/libvfio-user.h
+++ b/include/libvfio-user.h
@@ -238,17 +238,24 @@ typedef struct {
*/
#define LIBVFIO_USER_FLAG_ATTACH_NB (1 << 0)
+typedef enum {
+ VFU_DEV_TYPE_PCI
+} vfu_dev_type_t;
+
/**
* Creates libvfio-user context.
+ *
* @trans: transport type
* @path: path to socket file.
* @flags: context flag
* @pvt: private data
+ * @dev_type: device type
+ *
* @returns the vfu_ctx to be used or NULL on error. Sets errno.
*/
vfu_ctx_t *
vfu_create_ctx(vfu_trans_t trans, const char *path,
- int flags, void *pvt);
+ int flags, void *pvt, vfu_dev_type_t dev_type);
/**
* Setup logging information.
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 964091c..30416a9 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -1278,7 +1278,8 @@ vfu_ctx_try_attach(vfu_ctx_t *vfu_ctx)
}
vfu_ctx_t *
-vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt)
+vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt,
+ vfu_dev_type_t dev_type)
{
vfu_ctx_t *vfu_ctx = NULL;
int err = 0;
@@ -1288,10 +1289,16 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt)
return NULL;
}
+ if (dev_type != VFU_DEV_TYPE_PCI) {
+ errno = EINVAL;
+ return NULL;
+ }
+
vfu_ctx = calloc(1, sizeof(vfu_ctx_t));
if (vfu_ctx == NULL) {
return NULL;
}
+ vfu_ctx->dev_type = dev_type;
vfu_ctx->trans = &sock_transport_ops;
//FIXME: Validate arguments.
diff --git a/lib/private.h b/lib/private.h
index a2fb3a7..335ceaa 100644
--- a/lib/private.h
+++ b/lib/private.h
@@ -129,6 +129,7 @@ struct vfu_ctx {
uint32_t irq_count[VFU_DEV_NUM_IRQS];
vfu_irqs_t *irqs;
int ready;
+ vfu_dev_type_t dev_type;
};
int
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c
index 17dfdaa..1881ec0 100644
--- a/samples/gpio-pci-idio-16.c
+++ b/samples/gpio-pci-idio-16.c
@@ -99,7 +99,8 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "failed to register signal handler");
}
- vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind], 0, NULL);
+ vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind], 0, NULL,
+ VFU_DEV_TYPE_PCI);
if (vfu_ctx == NULL) {
if (errno == EINTR) {
printf("interrupted\n");
diff --git a/samples/null.c b/samples/null.c
index 99e35cc..4dd50d0 100644
--- a/samples/null.c
+++ b/samples/null.c
@@ -76,7 +76,8 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, "missing vfio-user socket path");
}
- vfu_ctx_t *vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[1], 0, NULL);
+ vfu_ctx_t *vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[1], 0, NULL,
+ VFU_DEV_TYPE_PCI);
if (vfu_ctx == NULL) {
err(EXIT_FAILURE, "failed to create libvfio-user context");
}
diff --git a/samples/server.c b/samples/server.c
index 571e374..ba1ac67 100644
--- a/samples/server.c
+++ b/samples/server.c
@@ -411,7 +411,8 @@ int main(int argc, char *argv[])
}
server_data.vfu_ctx = vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, argv[optind],
- 0, &server_data);
+ 0, &server_data,
+ VFU_DEV_TYPE_PCI);
if (vfu_ctx == NULL) {
err(EXIT_FAILURE, "failed to initialize device emulation\n");
}