diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2020-12-08 10:58:29 -0500 |
---|---|---|
committer | Thanos Makatos <tmakatos@gmail.com> | 2020-12-11 12:54:21 +0000 |
commit | 90211fbd2c7c310df593736b18f1c99f053e2957 (patch) | |
tree | 03462a28541581cbf3ea6eb8f9fde05591c3e893 /include | |
parent | a7ecdc3de9f237d600ceaaa44285115a4e790829 (diff) | |
download | libvfio-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 'include')
-rw-r--r-- | include/libvfio-user.h | 12 | ||||
-rw-r--r-- | include/pci_caps/common.h | 9 | ||||
-rw-r--r-- | include/pci_caps/pm.h | 21 |
3 files changed, 30 insertions, 12 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h index e5b6474..95c5e7d 100644 --- a/include/libvfio-user.h +++ b/include/libvfio-user.h @@ -221,6 +221,7 @@ vfu_ctx_t * vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt, vfu_dev_type_t dev_type); + /** * Setup logging information. * @vfu_ctx: the libvfio-user context @@ -261,15 +262,18 @@ vfu_pci_setup_config_hdr(vfu_ctx_t *vfu_ctx, vfu_pci_hdr_id_t id, /* FIXME does it have to be packed as well? */ typedef union { - struct msicap msi; - struct msixcap msix; - struct pmcap pm; - struct pxcap px; + struct msicap msi; + struct msixcap msix; + struct pmcap pm; + struct pxcap px; + struct vsc vsc; } vfu_cap_t; //TODO: Support variable size capabilities. + /** * Setup PCI capabilities. + * * @vfu_ctx: the libvfio-user context * @caps: array of (vfu_cap_t *) * @nr_caps: number of elements in @caps diff --git a/include/pci_caps/common.h b/include/pci_caps/common.h index 7e158f0..a820f0d 100644 --- a/include/pci_caps/common.h +++ b/include/pci_caps/common.h @@ -45,6 +45,15 @@ _Static_assert(sizeof(struct cap_hdr) == 0x2, "bad PCI capability header size"); _Static_assert(offsetof(struct cap_hdr, id) == PCI_CAP_LIST_ID, "bad offset"); _Static_assert(offsetof(struct cap_hdr, next) == PCI_CAP_LIST_NEXT, "bad offset"); +/* + * Vendor-specific capability + */ +struct vsc { + struct cap_hdr hdr; + uint8_t size; + uint8_t data[]; +} __attribute__ ((packed)); + #ifdef __cplusplus } #endif diff --git a/include/pci_caps/pm.h b/include/pci_caps/pm.h index 3098299..6daa812 100644 --- a/include/pci_caps/pm.h +++ b/include/pci_caps/pm.h @@ -52,14 +52,19 @@ struct pc { _Static_assert(sizeof(struct pc) == 0x2, "bad PC size"); struct pmcs { - unsigned int ps:2; - unsigned int res1:1; - unsigned int nsfrst:1; - unsigned int res2:4; - unsigned int pmee:1; - unsigned int dse:4; - unsigned int dsc:2; - unsigned int pmes:1; + union { + uint16_t raw; + struct { + unsigned int ps:2; + unsigned int res1:1; + unsigned int nsfrst:1; + unsigned int res2:4; + unsigned int pmee:1; + unsigned int dse:4; + unsigned int dsc:2; + unsigned int pmes:1; + }; + }; } __attribute__((packed)); _Static_assert(sizeof(struct pc) == 0x2, "bad PMCS size"); |