aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2020-07-16 10:07:43 -0400
committerThanos Makatos <thanos.makatos@nutanix.com>2020-07-16 10:07:43 -0400
commit454377a97525e68c889ac43d0b2314843351a5a8 (patch)
treef8dde69242ebe4d97533217dac15c1b5ed69c267
parentab8e0c6e74e8f14aa011e6ef5525dbe084203cf1 (diff)
downloadlibvfio-user-454377a97525e68c889ac43d0b2314843351a5a8.zip
libvfio-user-454377a97525e68c889ac43d0b2314843351a5a8.tar.gz
libvfio-user-454377a97525e68c889ac43d0b2314843351a5a8.tar.bz2
add common definition for PCI capability header
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r--lib/caps/common.h46
-rw-r--r--lib/caps/msi.h9
-rw-r--r--lib/caps/msix.h9
-rw-r--r--lib/caps/pm.h11
-rw-r--r--lib/caps/px.h9
5 files changed, 58 insertions, 26 deletions
diff --git a/lib/caps/common.h b/lib/caps/common.h
new file mode 100644
index 0000000..2181a3b
--- /dev/null
+++ b/lib/caps/common.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2020 Nutanix Inc. All rights reserved.
+ *
+ * Authors: Thanos Makatos <thanos@nutanix.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Nutanix nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ */
+
+#ifndef LM_PCI_CAP_COMMON_H
+#define LM_PCI_CAP_COMMON_H
+
+#include <stddef.h>
+
+struct cap_hdr {
+ uint8_t id;
+ uint8_t next;
+} __attribute__((packed));
+_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");
+
+#endif /* LM_PCI_CAP_COMMON_H */
+
+/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/caps/msi.h b/lib/caps/msi.h
index b310ae9..5933006 100644
--- a/lib/caps/msi.h
+++ b/lib/caps/msi.h
@@ -33,11 +33,7 @@
#ifndef LM_PCI_CAP_MSI_H
#define LM_PCI_CAP_MSI_H
-struct mid {
- unsigned int cid:8;
- unsigned int next:8;
-} __attribute__ ((packed));
-_Static_assert(sizeof(struct mid) == 0x2, "bad MID size");
+#include "common.h"
struct mc {
unsigned int msie:1;
@@ -56,7 +52,7 @@ struct ma {
_Static_assert(sizeof(struct ma) == 0x4, "bad MA size");
struct msicap {
- struct mid mid;
+ struct cap_hdr hdr;
struct mc mc;
struct ma ma;
uint32_t mua;
@@ -66,6 +62,7 @@ struct msicap {
uint32_t mpend;
} __attribute__ ((packed));
_Static_assert(sizeof(struct msicap) == 0x18, "bad MSICAP size");
+_Static_assert(offsetof(struct msicap, hdr) == 0, "bad offset");
#endif /* LM_CAP_MSI_H */
diff --git a/lib/caps/msix.h b/lib/caps/msix.h
index b13c1c8..b0bc1a5 100644
--- a/lib/caps/msix.h
+++ b/lib/caps/msix.h
@@ -35,12 +35,6 @@
#include <linux/pci_regs.h>
-struct mxid {
- unsigned int cid:8;
- unsigned int next:8;
-} __attribute__ ((packed));
-_Static_assert(sizeof(struct mxid) == 0x2, "bad MXID size");
-
struct mxc {
unsigned int ts:11;
unsigned int reserved:3;
@@ -63,12 +57,13 @@ _Static_assert(sizeof(struct mtab) == PCI_MSIX_PBA - PCI_MSIX_TABLE,
"bad MPBA size");
struct msixcap {
- struct mxid mxid;
+ struct cap_hdr hdr;
struct mxc mxc;
struct mtab mtab;
struct mpba mpba;
} __attribute__ ((packed)) __attribute__ ((aligned(4)));
_Static_assert(sizeof(struct msixcap) == PCI_CAP_MSIX_SIZEOF, "bad MSI-X size");
+_Static_assert(offsetof(struct msixcap, hdr) == 0, "bad offset");
#endif /* LM_CAP_MSIX_H */
diff --git a/lib/caps/pm.h b/lib/caps/pm.h
index b7953ae..e976d95 100644
--- a/lib/caps/pm.h
+++ b/lib/caps/pm.h
@@ -33,11 +33,7 @@
#ifndef LM_PCI_CAP_PM_H
#define LM_PCI_CAP_PM_H
-struct pid {
- unsigned int cid:8;
- unsigned int next:8;
-} __attribute__((packed));
-_Static_assert(sizeof(struct pid) == 0x2, "bad PID size");
+#include "common.h"
struct pc {
unsigned int vs:3;
@@ -64,11 +60,12 @@ struct pmcs {
_Static_assert(sizeof(struct pc) == 0x2, "bad PMCS size");
struct pmcap {
- struct pid pid;
+ struct cap_hdr hdr;
struct pc pc;
struct pmcs pmcs;
-} __attribute__((packed)) __attribute__ ((aligned(8)));
+} __attribute__((packed)) __attribute__ ((aligned(8))); /* FIXME why does it need to be aligned? */
_Static_assert(sizeof(struct pmcap) == PCI_PM_SIZEOF, "bad PC size");
+_Static_assert(offsetof(struct pmcap, hdr) == 0, "bad offset");
#endif /* LM_CAP_PM_H */
diff --git a/lib/caps/px.h b/lib/caps/px.h
index ce17cfe..28a04d5 100644
--- a/lib/caps/px.h
+++ b/lib/caps/px.h
@@ -33,11 +33,7 @@
#ifndef LM_PCI_CAP_PX_H
#define LM_PCI_CAP_PX_H
-struct pxid {
- unsigned int cid:8;
- unsigned int next:8;
-} __attribute__((packed));
-_Static_assert(sizeof(struct pxid) == 0x2, "bad PXID size");
+#include "common.h"
struct pxcaps {
unsigned int ver:4;
@@ -133,7 +129,7 @@ _Static_assert(sizeof(struct pxdc2) == 0x2, "bad PXDC2 size");
* the whole struct.
*/
struct pxcap {
- struct pxid pxid;
+ struct cap_hdr hdr;
struct pxcaps pxcaps;
struct pxdcap pxdcap;
union pxdc pxdc;
@@ -147,6 +143,7 @@ struct pxcap {
} __attribute__((packed));
_Static_assert(sizeof(struct pxcap) == 0x2a,
"bad PCI Express Capability size");
+_Static_assert(offsetof(struct pxcap, hdr) == 0, "bad offset");
#endif /* LM_PCI_CAP_PX_H */