diff options
author | John Levon <john.levon@nutanix.com> | 2020-11-24 15:22:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-24 15:22:18 +0000 |
commit | d33f124c5b0335c0525187e820c6b42be0bae743 (patch) | |
tree | 365d4e92589e1f34f7665b00a0c68761129a6d80 /include/pci_caps | |
parent | ee9c3d1860bc81ebd43862d502ef2f9f71e6c299 (diff) | |
download | libvfio-user-d33f124c5b0335c0525187e820c6b42be0bae743.zip libvfio-user-d33f124c5b0335c0525187e820c6b42be0bae743.tar.gz libvfio-user-d33f124c5b0335c0525187e820c6b42be0bae743.tar.bz2 |
clean up headers
Introduce include/ dir for public headers, and clean up include guards etc.
Diffstat (limited to 'include/pci_caps')
-rw-r--r-- | include/pci_caps/common.h | 54 | ||||
-rw-r--r-- | include/pci_caps/msi.h | 77 | ||||
-rw-r--r-- | include/pci_caps/msix.h | 78 | ||||
-rw-r--r-- | include/pci_caps/pm.h | 80 | ||||
-rw-r--r-- | include/pci_caps/px.h | 158 |
5 files changed, 447 insertions, 0 deletions
diff --git a/include/pci_caps/common.h b/include/pci_caps/common.h new file mode 100644 index 0000000..aefa209 --- /dev/null +++ b/include/pci_caps/common.h @@ -0,0 +1,54 @@ +/* + * 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 LIB_MUSER_PCI_CAPS_COMMON_H +#define LIB_MUSER_PCI_CAPS_COMMON_H + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +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"); + +#ifdef __cplusplus +} +#endif + +#endif /* LIB_MUSER_PCI_CAPS_COMMON_H */ + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/pci_caps/msi.h b/include/pci_caps/msi.h new file mode 100644 index 0000000..1f1a77f --- /dev/null +++ b/include/pci_caps/msi.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019 Nutanix Inc. All rights reserved. + * + * Authors: Thanos Makatos <thanos@nutanix.com> + * Swapnil Ingle <swapnil.ingle@nutanix.com> + * Felipe Franciosi <felipe@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 LIB_MUSER_PCI_CAPS_MSI_H +#define LIB_MUSER_PCI_CAPS_MSI_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct mc { + unsigned int msie:1; + unsigned int mmc:3; + unsigned int mme:3; + unsigned int c64:1; + unsigned int pvm:1; + unsigned int res1:7; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct mc) == 0x2, "bad MC size"); + +struct ma { + unsigned int res1:2; + unsigned int addr:30; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct ma) == 0x4, "bad MA size"); + +struct msicap { + struct cap_hdr hdr; + struct mc mc; + struct ma ma; + uint32_t mua; + uint16_t md; + uint16_t padding; + uint32_t mmask; + uint32_t mpend; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct msicap) == 0x18, "bad MSICAP size"); +_Static_assert(offsetof(struct msicap, hdr) == 0, "bad offset"); + +#ifdef __cplusplus +} +#endif + +#endif /* LM_CAP_MSI_H */ + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/pci_caps/msix.h b/include/pci_caps/msix.h new file mode 100644 index 0000000..95447bf --- /dev/null +++ b/include/pci_caps/msix.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019 Nutanix Inc. All rights reserved. + * + * Authors: Thanos Makatos <thanos@nutanix.com> + * Swapnil Ingle <swapnil.ingle@nutanix.com> + * Felipe Franciosi <felipe@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 LIB_MUSER_PCI_CAPS_MSIX_H +#define LIB_MUSER_PCI_CAPS_MSIX_H + +#include <linux/pci_regs.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct mxc { + unsigned int ts:11; + unsigned int reserved:3; + unsigned int fm:1; + unsigned int mxe:1; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct mxc) == PCI_MSIX_FLAGS, "bad MXC size"); + +struct mtab { + unsigned int tbir:3; + unsigned int to:29; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct mtab) == PCI_MSIX_TABLE, "bad MTAB size"); + +struct mpba { + unsigned int pbir:3; + unsigned int pbao:29; +} __attribute__ ((packed)); +_Static_assert(sizeof(struct mtab) == PCI_MSIX_PBA - PCI_MSIX_TABLE, + "bad MPBA size"); + +struct msixcap { + 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"); + +#ifdef __cplusplus +} +#endif + +#endif /* LM_CAP_MSIX_H */ + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/pci_caps/pm.h b/include/pci_caps/pm.h new file mode 100644 index 0000000..391deac --- /dev/null +++ b/include/pci_caps/pm.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 Nutanix Inc. All rights reserved. + * + * Authors: Thanos Makatos <thanos@nutanix.com> + * Swapnil Ingle <swapnil.ingle@nutanix.com> + * Felipe Franciosi <felipe@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 LIB_MUSER_PCI_CAPS_PM_H +#define LIB_MUSER_PCI_CAPS_PM_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pc { + unsigned int vs:3; + unsigned int pmec:1; + unsigned int res:1; + unsigned int dsi:1; + unsigned int auxc:3; + unsigned int d1s:1; + unsigned int d2s:1; + unsigned int psup:5; +} __attribute__((packed)); +_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; +} __attribute__((packed)); +_Static_assert(sizeof(struct pc) == 0x2, "bad PMCS size"); + +struct pmcap { + struct cap_hdr hdr; + struct pc pc; + struct pmcs pmcs; +} __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"); + +#ifdef __cplusplus +} +#endif + +#endif /* LM_CAP_PM_H */ + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/pci_caps/px.h b/include/pci_caps/px.h new file mode 100644 index 0000000..ac53e15 --- /dev/null +++ b/include/pci_caps/px.h @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2019 Nutanix Inc. All rights reserved. + * + * Authors: Thanos Makatos <thanos@nutanix.com> + * Swapnil Ingle <swapnil.ingle@nutanix.com> + * Felipe Franciosi <felipe@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 LIB_MUSER_PCI_CAPS_PX_H +#define LIB_MUSER_PCI_CAPS_PX_H + +#include "common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct pxcaps { + unsigned int ver:4; + unsigned int dpt:4; + unsigned int si:1; + unsigned int imn:5; + unsigned int res1:2; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxcaps) == 0x2, "bad PXCAPS size"); + +struct pxdcap { + unsigned int mps:3; + unsigned int pfs:2; + unsigned int etfs:1; + unsigned int l0sl:3; + unsigned int l1l:3; + unsigned int per:1; + unsigned int res1:2; + unsigned int csplv:8; + unsigned int cspls:2; + unsigned int flrc:1; + unsigned int res2:3; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxdcap) == 0x4, "bad PXDCAP size"); + +union pxdc { + uint16_t raw; + struct { + unsigned int cere:1; + unsigned int nfere:1; + unsigned int fere:1; + unsigned int urre:1; + unsigned int ero:1; + unsigned int mps:3; + unsigned int ete:1; + unsigned int pfe:1; + unsigned int appme:1; + unsigned int ens:1; + unsigned int mrrs:3; + unsigned int iflr:1; + } __attribute__((packed)); +} __attribute__((packed)); +_Static_assert(sizeof(union pxdc) == 0x2, "bad PXDC size"); + +/* TODO not defining for now since all values are 0 for reset */ +struct pxds { + unsigned int stuff:16; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxds) == 0x2, "bad PXDS size"); + +struct pxlcap { + unsigned int stuff:32; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxlcap) == 0x4, "bad PXLCAP size"); + +struct pxlc { + unsigned int stuff:16; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxlc) == 0x2, "bad PXLC size"); + +struct pxls { + unsigned int stuff:16; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxls) == 0x2, "bad PXLS size"); + +struct pxdcap2 { + unsigned int ctrs:4; + unsigned int ctds:1; + unsigned int arifs:1; + unsigned int aors:1; + unsigned int aocs32:1; + unsigned int aocs64:1; + unsigned int ccs128:1; + unsigned int nprpr:1; + unsigned int ltrs:1; + unsigned int tphcs:2; + unsigned int obffs:2; + unsigned int effs:1; + unsigned int eetps:1; + unsigned int meetp:2; + unsigned int res1:8; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxdcap2) == 0x4, "bad PXDCAP2 size"); + +struct pxdc2 { + unsigned int stuff:16; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxdc2) == 0x2, "bad PXDC2 size"); + +/* + * TODO the definition of this struct varies, check PCI Express 2.1 + * specification. Maybe we should only define the idividual registers but not + * the whole struct. + */ +struct pxcap { + struct cap_hdr hdr; + struct pxcaps pxcaps; + struct pxdcap pxdcap; + union pxdc pxdc; + struct pxds pxds; + struct pxlcap pxlcap; + struct pxlc pxlc; + struct pxls pxls; + uint8_t pad[0x10]; + struct pxdcap2 pxdcap2; + struct pxdc2 pxdc2; +} __attribute__((packed)); +_Static_assert(sizeof(struct pxcap) == 0x2a, + "bad PCI Express Capability size"); +_Static_assert(offsetof(struct pxcap, hdr) == 0, "bad offset"); + +#ifdef __cplusplus +} +#endif + +#endif /* LIB_MUSER_PCI_CAPS_PX_H */ + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ |