aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Franciosi <felipe@nutanix.com>2019-11-04 12:34:24 +0000
committerGitHub <noreply@github.com>2019-11-04 12:34:24 +0000
commitfa22ae22ac765b717d6bec39975ca4d90cd56f94 (patch)
tree5a4b40a4c54155de9a222f137f8bcd509f761859
parentb09684f012574a6a0b47a8021251f13dfcb66c8e (diff)
parent2ab50e0476d46148a2bbc81ea051aafc3593b13a (diff)
downloadlibvfio-user-fa22ae22ac765b717d6bec39975ca4d90cd56f94.zip
libvfio-user-fa22ae22ac765b717d6bec39975ca4d90cd56f94.tar.gz
libvfio-user-fa22ae22ac765b717d6bec39975ca4d90cd56f94.tar.bz2
Merge pull request #2 from franciozzy/cleanup
Cleanup
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt2
-rw-r--r--Makefile2
-rw-r--r--kmod/CMakeLists.txt2
-rw-r--r--kmod/muser.c3
-rw-r--r--lib/CMakeLists.txt2
-rw-r--r--lib/cap.c41
-rw-r--r--lib/cap.h34
-rw-r--r--lib/caps/msi.h5
-rw-r--r--lib/caps/msix.h5
-rw-r--r--lib/caps/pm.h7
-rw-r--r--lib/caps/px.h5
-rw-r--r--lib/common.h12
-rw-r--r--lib/dma.c30
-rw-r--r--lib/dma.h51
-rw-r--r--lib/libmuser.c144
-rw-r--r--lib/libmuser_pci.c29
-rw-r--r--lib/muser.h63
-rw-r--r--lib/muser_priv.h47
-rw-r--r--lib/pci.h3
-rw-r--r--lib/python_bindings.c85
-rwxr-xr-xlib/python_bindings_install.sh4
-rw-r--r--lib/setup.py2
-rw-r--r--samples/CMakeLists.txt2
-rw-r--r--samples/gpio-pci-idio-16.c33
25 files changed, 395 insertions, 220 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4c48135
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+build/
+cscope.out
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47a8e6f..7975983 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,7 +15,7 @@
# * 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
diff --git a/Makefile b/Makefile
index 11bd3fe..5a4482e 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
# * 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
diff --git a/kmod/CMakeLists.txt b/kmod/CMakeLists.txt
index 74d3047..685cf2b 100644
--- a/kmod/CMakeLists.txt
+++ b/kmod/CMakeLists.txt
@@ -15,7 +15,7 @@
# * 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
diff --git a/kmod/muser.c b/kmod/muser.c
index f0b4700..2102c09 100644
--- a/kmod/muser.c
+++ b/kmod/muser.c
@@ -441,7 +441,6 @@ static void unpin_pages(struct page_map *const pg_map)
pg_map->pages = NULL;
}
-
static int vm_insert_pages(struct vm_area_struct *const vma,
struct page *const pages[], const int nr_pages)
{
@@ -1006,7 +1005,7 @@ static ssize_t muser_read(struct mdev_device *mdev, char __user *buf,
_count = err;
else
_count = mucmd.muser_cmd.err;
-
+
if (_count < 0)
muser_dbg("failed to process read: %d, %d\n", err,
mucmd.muser_cmd.err);
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 3a0a811..1ae48f2 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -15,7 +15,7 @@
# * 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
diff --git a/lib/cap.c b/lib/cap.c
index 6f6f9dc..8536d75 100644
--- a/lib/cap.c
+++ b/lib/cap.c
@@ -1,3 +1,35 @@
+/*
+ * 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.
+ *
+ */
+
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
@@ -14,8 +46,8 @@ struct cap {
};
struct caps {
- struct cap caps[LM_MAX_CAPS];
- int nr_caps;
+ struct cap caps[LM_MAX_CAPS];
+ int nr_caps;
};
/*
@@ -60,7 +92,7 @@ cap_is_accessed(struct cap *caps, int nr_caps, loff_t offset)
* Returns the PCI capability that is contained within the specified region
* (offset + count).
*/
-static struct cap*
+static struct cap *
cap_find(struct cap *caps, int nr_caps, loff_t offset, size_t count)
{
struct cap *cap;
@@ -176,7 +208,7 @@ cap_is_valid(uint8_t id)
return id >= PCI_CAP_ID_PM && id <= PCI_CAP_ID_MAX;
}
-struct caps*
+struct caps *
caps_create(lm_cap_t *lm_caps, int nr_caps)
{
uint8_t prev_end;
@@ -210,6 +242,7 @@ caps_create(lm_cap_t *lm_caps, int nr_caps)
caps->caps[i].end = prev_end = caps->caps[i].start + lm_caps[i].size - 1;
}
caps->nr_caps = nr_caps;
+
out:
if (err) {
free(caps);
diff --git a/lib/cap.h b/lib/cap.h
index 4606737..3202cdd 100644
--- a/lib/cap.h
+++ b/lib/cap.h
@@ -1,3 +1,35 @@
+/*
+ * 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 __CAP_H__
#define __CAP_H__
@@ -11,7 +43,7 @@ struct caps;
* Returns <0 on error, 0 if no capabilities are to be added, and >0 if all
* capabilities have been added.
*/
-struct caps*
+struct caps *
caps_create(lm_cap_t *caps, int nr_caps);
/*
diff --git a/lib/caps/msi.h b/lib/caps/msi.h
index 141181f..b310ae9 100644
--- a/lib/caps/msi.h
+++ b/lib/caps/msi.h
@@ -30,6 +30,9 @@
*
*/
+#ifndef LM_PCI_CAP_MSI_H
+#define LM_PCI_CAP_MSI_H
+
struct mid {
unsigned int cid:8;
unsigned int next:8;
@@ -64,4 +67,6 @@ struct msicap {
} __attribute__ ((packed));
_Static_assert(sizeof(struct msicap) == 0x18, "bad MSICAP size");
+#endif /* LM_CAP_MSI_H */
+
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/caps/msix.h b/lib/caps/msix.h
index 4cc41a8..b13c1c8 100644
--- a/lib/caps/msix.h
+++ b/lib/caps/msix.h
@@ -30,6 +30,9 @@
*
*/
+#ifndef LM_PCI_CAP_MSIX_H
+#define LM_PCI_CAP_MSIX_H
+
#include <linux/pci_regs.h>
struct mxid {
@@ -67,4 +70,6 @@ struct msixcap {
} __attribute__ ((packed)) __attribute__ ((aligned(4)));
_Static_assert(sizeof(struct msixcap) == PCI_CAP_MSIX_SIZEOF, "bad MSI-X size");
+#endif /* LM_CAP_MSIX_H */
+
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/caps/pm.h b/lib/caps/pm.h
index 942f28a..ddae2e6 100644
--- a/lib/caps/pm.h
+++ b/lib/caps/pm.h
@@ -30,6 +30,9 @@
*
*/
+#ifndef LM_PCI_CAP_PM_H
+#define LM_PCI_CAP_PM_H
+
struct pid {
unsigned int cid:8;
unsigned int next:8;
@@ -44,7 +47,7 @@ struct pc {
unsigned int auxc:3;
unsigned int d1s:1;
unsigned int d2s:1;
- unsigned int psup:5;
+ unsigned int psup:5;
} __attribute__((packed));
_Static_assert(sizeof(struct pc) == 0x2, "bad PC size");
@@ -67,4 +70,6 @@ struct pmcap {
} __attribute__((packed)) __attribute__ ((aligned(8)));
_Static_assert(sizeof(struct pmcap) == PCI_PM_SIZEOF, "bad PC size");
+#endif /* LM_CAP_PM_H */
+
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/caps/px.h b/lib/caps/px.h
index 62388a1..ce17cfe 100644
--- a/lib/caps/px.h
+++ b/lib/caps/px.h
@@ -30,6 +30,9 @@
*
*/
+#ifndef LM_PCI_CAP_PX_H
+#define LM_PCI_CAP_PX_H
+
struct pxid {
unsigned int cid:8;
unsigned int next:8;
@@ -145,4 +148,6 @@ struct pxcap {
_Static_assert(sizeof(struct pxcap) == 0x2a,
"bad PCI Express Capability size");
+#endif /* LM_PCI_CAP_PX_H */
+
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/common.h b/lib/common.h
index 4fbc048..85ad610 100644
--- a/lib/common.h
+++ b/lib/common.h
@@ -48,13 +48,13 @@
#define ROUND_DOWN(x, a) ((x) & ~((a)-1))
#define ROUND_UP(x,a) ROUND_DOWN((x)+(a)-1, a)
-void lm_log(lm_ctx_t const *const lm_ctx, const lm_log_lvl_t lvl,
- char const *const fmt, ...);
+void
+lm_log(lm_ctx_t *lm_ctx, lm_log_lvl_t lvl, const char *fmt, ...);
-void dump_buffer(lm_ctx_t const *const lm_ctx, char const *const prefix,
- unsigned char const *const buf, uint32_t count);
+void
+dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
+ const unsigned char *buf, uint32_t count);
-
-#endif /* __COMMON_H__ */
+#endif /* __COMMON_H__ */
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/dma.c b/lib/dma.c
index 40b12b3..b88f980 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -13,7 +13,7 @@
* * 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
@@ -25,7 +25,7 @@
* 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.
- *
+ *
*/
#include <sys/types.h>
@@ -85,7 +85,7 @@ dma_controller_create(int max_regions)
}
static void
-_dma_controller_do_remove_region(dma_memory_region_t * const region)
+_dma_controller_do_remove_region(dma_memory_region_t *region)
{
assert(region);
#if DMA_MAP_FAST_IMPL
@@ -96,7 +96,7 @@ _dma_controller_do_remove_region(dma_memory_region_t * const region)
/* FIXME not thread safe */
int
-dma_controller_remove_region(dma_controller_t * dma, dma_addr_t dma_addr,
+dma_controller_remove_region(dma_controller_t *dma, dma_addr_t dma_addr,
size_t size, int fd)
{
int idx;
@@ -120,8 +120,7 @@ dma_controller_remove_region(dma_controller_t * dma, dma_addr_t dma_addr,
}
static inline void
-dma_controller_remove_regions(lm_ctx_t * const ctx,
- dma_controller_t * const dma)
+dma_controller_remove_regions(lm_ctx_t *ctx, dma_controller_t *dma)
{
int i;
@@ -138,14 +137,14 @@ dma_controller_remove_regions(lm_ctx_t * const ctx,
}
void
-dma_controller_destroy(lm_ctx_t * const ctx, dma_controller_t * dma)
+dma_controller_destroy(lm_ctx_t *lm_ctx, dma_controller_t *dma)
{
- dma_controller_remove_regions(ctx, dma);
+ dma_controller_remove_regions(lm_ctx, dma);
free(dma);
}
int
-dma_controller_add_region(lm_ctx_t * const lm_ctx, dma_controller_t * dma,
+dma_controller_add_region(lm_ctx_t *lm_ctx, dma_controller_t *dma,
dma_addr_t dma_addr, size_t size,
int fd, off_t offset)
{
@@ -237,7 +236,7 @@ err:
}
static inline void
-mmap_round(size_t * offset, size_t * size, size_t page_size)
+mmap_round(size_t *offset, size_t *size, size_t page_size)
{
size_t offset_orig = *offset;
*offset = ROUND_DOWN(offset_orig, page_size);
@@ -245,8 +244,7 @@ mmap_round(size_t * offset, size_t * size, size_t page_size)
}
void *
-dma_map_region(dma_memory_region_t * region, int prot,
- size_t offset, size_t len)
+dma_map_region(dma_memory_region_t *region, int prot, size_t offset, size_t len)
{
size_t mmap_offset, mmap_size = len;
char *mmap_base;
@@ -272,16 +270,16 @@ dma_map_region(dma_memory_region_t * region, int prot,
}
void
-dma_unmap_region(dma_memory_region_t * region, void *virt_addr, size_t len)
+dma_unmap_region(dma_memory_region_t *region, void *virt_addr, size_t len)
{
- mmap_round((size_t *) & virt_addr, &len, region->page_size);
+ mmap_round((size_t *)&virt_addr, &len, region->page_size);
munmap(virt_addr, len);
}
int
-_dma_addr_sg_split(lm_ctx_t * const ctx, const dma_controller_t * dma,
+_dma_addr_sg_split(lm_ctx_t *lm_ctx, const dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len,
- dma_sg_t * sg, int max_sg)
+ dma_sg_t *sg, int max_sg)
{
int idx;
int cnt = 0;
diff --git a/lib/dma.h b/lib/dma.h
index d9de811..62df86e 100644
--- a/lib/dma.h
+++ b/lib/dma.h
@@ -100,8 +100,11 @@ typedef struct {
dma_memory_region_t regions[0];
} dma_controller_t;
-dma_controller_t *dma_controller_create(int max_regions);
-void dma_controller_destroy(lm_ctx_t * const ctx, dma_controller_t * dma);
+dma_controller_t *
+dma_controller_create(int max_regions);
+
+void
+dma_controller_destroy(lm_ctx_t *ctx, dma_controller_t *dma);
/* Registers a new memory region.
* Returns:
@@ -110,17 +113,20 @@ void dma_controller_destroy(lm_ctx_t * const ctx, dma_controller_t * dma);
* where this region would have been mapped to if the call could succeed
* (e.g. due to conflict with existing region).
*/
-int dma_controller_add_region(lm_ctx_t * const ctx, dma_controller_t * dma,
- dma_addr_t dma_addr, size_t size,
- int fd, off_t offset);
+int
+dma_controller_add_region(lm_ctx_t *ctx, dma_controller_t *dma,
+ dma_addr_t dma_addr, size_t size,
+ int fd, off_t offset);
-int dma_controller_remove_region(dma_controller_t * dma, dma_addr_t dma_addr,
- size_t size, int fd);
+int
+dma_controller_remove_region(dma_controller_t *dma, dma_addr_t dma_addr,
+ size_t size, int fd);
// Helper for dma_addr_to_sg() slow path.
-int _dma_addr_sg_split(lm_ctx_t * const ctx, const dma_controller_t * dma,
- dma_addr_t dma_addr, uint32_t len,
- dma_sg_t * sg, int max_sg);
+int
+_dma_addr_sg_split(lm_ctx_t *ctx, const dma_controller_t *dma,
+ dma_addr_t dma_addr, uint32_t len,
+ dma_sg_t *sg, int max_sg);
/* Takes a linear dma address span and returns a sg list suitable for DMA.
* A single linear dma address span may need to be split into multiple
@@ -134,9 +140,9 @@ int _dma_addr_sg_split(lm_ctx_t * const ctx, const dma_controller_t * dma,
* necessary to complete this request.
*/
static inline int
-dma_addr_to_sg(lm_ctx_t * const ctx, const dma_controller_t * dma,
+dma_addr_to_sg(lm_ctx_t *ctx, const dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len,
- dma_sg_t * sg, int max_sg)
+ dma_sg_t *sg, int max_sg)
{
static __thread int region_hint;
int cnt;
@@ -160,15 +166,16 @@ dma_addr_to_sg(lm_ctx_t * const ctx, const dma_controller_t * dma,
return cnt;
}
-void *dma_map_region(dma_memory_region_t * region, int prot,
- size_t offset, size_t len);
+void *
+dma_map_region(dma_memory_region_t *region, int prot,
+ size_t offset, size_t len);
-void dma_unmap_region(dma_memory_region_t * region,
- void *virt_addr, size_t len);
+void
+dma_unmap_region(dma_memory_region_t *region, void *virt_addr, size_t len);
static inline int
-dma_map_sg(dma_controller_t * dma, int prot,
- const dma_sg_t * sg, struct iovec *iov, int cnt)
+dma_map_sg(dma_controller_t *dma, int prot,
+ const dma_sg_t *sg, struct iovec *iov, int cnt)
{
int i;
@@ -191,8 +198,8 @@ dma_map_sg(dma_controller_t * dma, int prot,
}
static inline void
-dma_unmap_sg(dma_controller_t * dma,
- const dma_sg_t * sg, struct iovec *iov, int cnt)
+dma_unmap_sg(dma_controller_t *dma,
+ const dma_sg_t *sg, struct iovec *iov, int cnt)
{
int i;
@@ -205,7 +212,7 @@ dma_unmap_sg(dma_controller_t * dma,
}
static inline void *
-dma_map_addr(lm_ctx_t * const ctx, dma_controller_t * dma, int prot,
+dma_map_addr(lm_ctx_t *ctx, dma_controller_t *dma, int prot,
dma_addr_t dma_addr, uint32_t len)
{
dma_sg_t sg;
@@ -220,7 +227,7 @@ dma_map_addr(lm_ctx_t * const ctx, dma_controller_t * dma, int prot,
}
static inline void
-dma_unmap_addr(lm_ctx_t * const ctx, dma_controller_t * dma,
+dma_unmap_addr(lm_ctx_t *ctx, dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len, void *addr)
{
dma_sg_t sg;
diff --git a/lib/libmuser.c b/lib/libmuser.c
index d7f62a5..d747c1b 100644
--- a/lib/libmuser.c
+++ b/lib/libmuser.c
@@ -92,38 +92,39 @@ MUST_BE_LAST(struct lm_ctx, irqs, lm_irqs_t);
#define LM2VFIO_IRQT(type) (type - 1)
-void lm_log(const lm_ctx_t * const ctx, const lm_log_lvl_t lvl,
- const char *const fmt, ...)
+void
+lm_log(lm_ctx_t *lm_ctx, lm_log_lvl_t lvl, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
- assert(ctx);
+ assert(lm_ctx != NULL);
- if (!ctx->log || lvl > ctx->log_lvl || !fmt) {
+ if (lm_ctx->log == NULL || lvl > lm_ctx->log_lvl || fmt == NULL) {
return;
}
va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- ctx->log(ctx->pvt, buf);
+ lm_ctx->log(lm_ctx->pvt, buf);
}
-static const char * const
-vfio_irq_idx_to_str(const int index) {
- static const char * const s[] = {
+static const char *
+vfio_irq_idx_to_str(int index) {
+ static const char *s[] = {
[VFIO_PCI_INTX_IRQ_INDEX] = "INTx",
- [VFIO_PCI_MSI_IRQ_INDEX] = "MSI",
+ [VFIO_PCI_MSI_IRQ_INDEX] = "MSI",
[VFIO_PCI_MSIX_IRQ_INDEX] = "MSI-X",
- [VFIO_PCI_ERR_IRQ_INDEX] = "ERR",
- [VFIO_PCI_REQ_IRQ_INDEX] = "REQ"
};
- /* FIXME need to validate index */
+
+ assert(index < LM_DEV_NUM_IRQS);
+
return s[index];
}
-static long irqs_disable(lm_ctx_t * lm_ctx, uint32_t index)
+static long
+irqs_disable(lm_ctx_t *lm_ctx, uint32_t index)
{
int *irq_efd = NULL;
uint32_t i;
@@ -162,7 +163,8 @@ static long irqs_disable(lm_ctx_t * lm_ctx, uint32_t index)
return -EINVAL;
}
-static int irqs_set_data_none(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set)
+static int
+irqs_set_data_none(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set)
{
int efd, i;
long ret;
@@ -193,6 +195,7 @@ irqs_set_data_bool(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data)
eventfd_t val;
assert(data != NULL);
+
for (i = irq_set->start, d8 = data; i < irq_set->start + irq_set->count;
i++, d8++) {
efd = lm_ctx->irqs.efds[i];
@@ -234,7 +237,7 @@ irqs_set_data_eventfd(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data
}
static long
-irqs_trigger(lm_ctx_t * lm_ctx, struct vfio_irq_set *irq_set, void *data)
+irqs_trigger(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data)
{
int err = 0;
@@ -328,7 +331,7 @@ dev_set_irqs_validate(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set)
}
static long
-dev_set_irqs(lm_ctx_t * lm_ctx, struct vfio_irq_set *irq_set, void *data)
+dev_set_irqs(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data)
{
long ret;
@@ -351,7 +354,8 @@ dev_set_irqs(lm_ctx_t * lm_ctx, struct vfio_irq_set *irq_set, void *data)
return irqs_trigger(lm_ctx, irq_set, data);
}
-static long dev_get_irqinfo(lm_ctx_t * lm_ctx, struct vfio_irq_info *irq_info)
+static long
+dev_get_irqinfo(lm_ctx_t *lm_ctx, struct vfio_irq_info *irq_info)
{
assert(lm_ctx != NULL);
assert(irq_info != NULL);
@@ -439,19 +443,19 @@ dev_get_sparse_mmap_cap(lm_ctx_t *lm_ctx, lm_reg_info_t *lm_reg,
#define LM_REGION_MASK ((1ULL << LM_REGION_SHIFT) - 1)
uint64_t
-region_to_offset(const uint32_t region)
+region_to_offset(uint32_t region)
{
return (uint64_t)region << LM_REGION_SHIFT;
}
uint32_t
-offset_to_region(const uint64_t offset)
+offset_to_region(uint64_t offset)
{
return (offset >> LM_REGION_SHIFT) & LM_REGION_MASK;
}
static long
-dev_get_reginfo(lm_ctx_t * lm_ctx, struct vfio_region_info *vfio_reg)
+dev_get_reginfo(lm_ctx_t *lm_ctx, struct vfio_region_info *vfio_reg)
{
lm_reg_info_t *lm_reg;
int err;
@@ -479,7 +483,8 @@ dev_get_reginfo(lm_ctx_t * lm_ctx, struct vfio_region_info *vfio_reg)
return 0;
}
-static long dev_get_info(struct vfio_device_info *dev_info)
+static long
+dev_get_info(struct vfio_device_info *dev_info)
{
assert(dev_info != NULL);
@@ -496,7 +501,7 @@ static long dev_get_info(struct vfio_device_info *dev_info)
}
static long
-do_muser_ioctl(lm_ctx_t * lm_ctx, struct muser_cmd_ioctl *cmd_ioctl, void *data)
+do_muser_ioctl(lm_ctx_t *lm_ctx, struct muser_cmd_ioctl *cmd_ioctl, void *data)
{
int err = -ENOTSUP;
@@ -525,7 +530,8 @@ do_muser_ioctl(lm_ctx_t * lm_ctx, struct muser_cmd_ioctl *cmd_ioctl, void *data)
return err;
}
-static int muser_dma_unmap(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
+static int
+muser_dma_unmap(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
{
int err;
@@ -552,7 +558,8 @@ static int muser_dma_unmap(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
return err;
}
-static int muser_dma_map(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
+static int
+muser_dma_map(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
{
int err;
@@ -584,7 +591,8 @@ static int muser_dma_map(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
/*
* Callback that is executed when device memory is to be mmap'd.
*/
-static int muser_mmap(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
+static int
+muser_mmap(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
{
int region, err = 0;
unsigned long addr;
@@ -628,35 +636,36 @@ out:
* ret), or a negative number on error.
*/
static int
-post_read(lm_ctx_t * const lm_ctx, struct muser_cmd *const cmd,
- const ssize_t count)
+post_read(lm_ctx_t *lm_ctx, struct muser_cmd *cmd, ssize_t count)
{
ssize_t ret = write(lm_ctx->fd, cmd->rw.buf, count);
+
if (ret != count) {
lm_log(lm_ctx, LM_ERR, "%s: bad muser write: %lu/%lu, %s\n",
__func__, ret, count, strerror(errno));
}
+
return ret;
}
int
-lm_get_region(const loff_t pos, const size_t count, loff_t * const off)
+lm_get_region(loff_t pos, size_t count, loff_t *off)
{
int r;
- assert(off);
+ assert(off != NULL);
r = offset_to_region(pos);
if (offset_to_region(pos + count) != r) {
- return -ENOENT;
+ return -ENOENT;
}
*off = pos - region_to_offset(r);
+
return r;
}
static ssize_t
-noop_cb(void *pvt, char * const buf, size_t count,
- loff_t offset, const bool is_write) {
+noop_cb(void *pvt, char *buf, size_t count, loff_t offset, bool is_write) {
return count;
}
@@ -686,8 +695,7 @@ handle_pci_config_space_access(lm_ctx_t *lm_ctx, char *buf, size_t count,
}
static ssize_t
-do_access(lm_ctx_t * const lm_ctx, char * const buf, size_t count, loff_t pos,
- const bool is_write)
+do_access(lm_ctx_t *lm_ctx, char *buf, size_t count, loff_t pos, bool is_write)
{
int idx;
loff_t offset;
@@ -707,7 +715,7 @@ do_access(lm_ctx_t * const lm_ctx, char * const buf, size_t count, loff_t pos,
if (idx < 0 || idx >= LM_DEV_NUM_REGS) {
lm_log(lm_ctx, LM_ERR, "bad region %d\n", idx);
return -EINVAL;
- }
+ }
if (idx == LM_DEV_CFG_REG_IDX) {
return handle_pci_config_space_access(lm_ctx, buf, count, offset,
@@ -737,8 +745,8 @@ do_access(lm_ctx_t * const lm_ctx, char * const buf, size_t count, loff_t pos,
* TODO function name same lm_access_t, fix
*/
ssize_t
-lm_access(lm_ctx_t * const lm_ctx, char *buf, size_t count,
- loff_t * const ppos, const bool is_write)
+lm_access(lm_ctx_t *lm_ctx, char *buf, size_t count, loff_t *ppos,
+ bool is_write)
{
unsigned int done = 0;
int ret;
@@ -781,10 +789,8 @@ lm_access(lm_ctx_t * const lm_ctx, char *buf, size_t count,
return done;
}
-
static inline int
-muser_access(lm_ctx_t * const lm_ctx, struct muser_cmd *const cmd,
- const bool is_write)
+muser_access(lm_ctx_t *lm_ctx, struct muser_cmd *cmd, bool is_write)
{
char *data;
int err;
@@ -855,7 +861,7 @@ out:
}
static int
-muser_ioctl(lm_ctx_t * lm_ctx, struct muser_cmd *cmd)
+muser_ioctl(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
{
void *data = NULL;
size_t size = 0;
@@ -900,7 +906,8 @@ out:
return ret;
}
-static int drive_loop(lm_ctx_t *lm_ctx)
+static int
+drive_loop(lm_ctx_t *lm_ctx)
{
struct muser_cmd cmd = { 0 };
int err;
@@ -947,9 +954,8 @@ static int drive_loop(lm_ctx_t *lm_ctx)
}
int
-lm_ctx_drive(lm_ctx_t * lm_ctx)
+lm_ctx_drive(lm_ctx_t *lm_ctx)
{
-
if (lm_ctx == NULL) {
errno = EINVAL;
return -1;
@@ -984,7 +990,7 @@ dev_attach(const char *uuid)
}
void *
-lm_mmap(lm_ctx_t * lm_ctx, off_t offset, size_t length)
+lm_mmap(lm_ctx_t *lm_ctx, off_t offset, size_t length)
{
off_t lm_off;
@@ -999,7 +1005,7 @@ lm_mmap(lm_ctx_t * lm_ctx, off_t offset, size_t length)
}
int
-lm_irq_trigger(lm_ctx_t * lm_ctx, uint32_t vector)
+lm_irq_trigger(lm_ctx_t *lm_ctx, uint32_t vector)
{
eventfd_t val = 1;
@@ -1033,7 +1039,7 @@ lm_irq_trigger(lm_ctx_t * lm_ctx, uint32_t vector)
}
void
-lm_ctx_destroy(lm_ctx_t * lm_ctx)
+lm_ctx_destroy(lm_ctx_t *lm_ctx)
{
if (lm_ctx == NULL) {
return;
@@ -1049,9 +1055,9 @@ lm_ctx_destroy(lm_ctx_t * lm_ctx)
}
static void
-init_pci_hdr(lm_pci_hdr_t * const hdr, const lm_pci_hdr_id_t * const id,
- const lm_pci_hdr_cc_t * const cc, const lm_pci_hdr_ss_t *ss,
- bool ipin)
+init_pci_hdr(lm_pci_hdr_t *hdr, const lm_pci_hdr_id_t *id,
+ const lm_pci_hdr_cc_t *cc, const lm_pci_hdr_ss_t *ss,
+ bool ipin)
{
assert(hdr);
assert(id);
@@ -1064,7 +1070,8 @@ init_pci_hdr(lm_pci_hdr_t * const hdr, const lm_pci_hdr_id_t * const id,
hdr->intr.ipin = ipin;
}
-static int copy_sparse_mmap_areas(lm_reg_info_t *dst, lm_reg_info_t *src)
+static int
+copy_sparse_mmap_areas(lm_reg_info_t *dst, lm_reg_info_t *src)
{
struct lm_sparse_mmap_areas *mmap_areas;
int nr_mmap_areas;
@@ -1088,7 +1095,8 @@ static int copy_sparse_mmap_areas(lm_reg_info_t *dst, lm_reg_info_t *src)
return 0;
}
-static void free_sparse_mmap_areas(lm_reg_info_t *reg_info)
+static void
+free_sparse_mmap_areas(lm_reg_info_t *reg_info)
{
int i;
@@ -1116,13 +1124,13 @@ lm_caps_init(lm_ctx_t *lm_ctx, lm_cap_t *caps, int nr_caps)
}
lm_ctx->pci_config_space->hdr.sts.cl = 0x1;
- lm_ctx->pci_config_space->hdr.cap = PCI_STD_HEADER_SIZEOF;
+ lm_ctx->pci_config_space->hdr.cap = PCI_STD_HEADER_SIZEOF;
return 0;
}
lm_ctx_t *
-lm_ctx_create(lm_dev_info_t * const dev_info)
+lm_ctx_create(lm_dev_info_t *dev_info)
{
lm_ctx_t *lm_ctx = NULL;
uint32_t max_ivs = 0, nr_mmap_areas = 0;
@@ -1180,9 +1188,6 @@ lm_ctx_create(lm_dev_info_t * const dev_info)
goto out;
}
- lm_ctx->pci_info.irq_count[LM_DEV_ERR_IRQ_IDX] = 1;
- lm_ctx->pci_info.irq_count[LM_DEV_REQ_IRQ_IDX] = 1;
-
lm_ctx->extended = dev_info->extended;
if (lm_ctx->extended) {
size = PCI_CFG_SPACE_EXP_SIZE;
@@ -1238,8 +1243,8 @@ out:
}
void
-dump_buffer(lm_ctx_t const *const lm_ctx, char const *const prefix,
- unsigned char const *const buf, const uint32_t count)
+dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
+ const unsigned char *buf, uint32_t count)
{
#ifdef DEBUG
int i;
@@ -1268,7 +1273,7 @@ dump_buffer(lm_ctx_t const *const lm_ctx, char const *const prefix,
* Returns a pointer to the standard part of the PCI configuration space.
*/
inline lm_pci_config_space_t *
-lm_get_pci_config_space(lm_ctx_t * const lm_ctx)
+lm_get_pci_config_space(lm_ctx_t *lm_ctx)
{
assert(lm_ctx != NULL);
return lm_ctx->pci_config_space;
@@ -1278,42 +1283,41 @@ lm_get_pci_config_space(lm_ctx_t * const lm_ctx)
* Returns a pointer to the non-standard part of the PCI configuration space.
*/
inline uint8_t *
-lm_get_pci_non_std_config_space(lm_ctx_t * const lm_ctx)
+lm_get_pci_non_std_config_space(lm_ctx_t *lm_ctx)
{
assert(lm_ctx != NULL);
- return (uint8_t *) & lm_ctx->pci_config_space->non_std;
+ return (uint8_t *)&lm_ctx->pci_config_space->non_std;
}
inline lm_reg_info_t *
-lm_get_region_info(lm_ctx_t * const lm_ctx)
+lm_get_region_info(lm_ctx_t *lm_ctx)
{
assert(lm_ctx != NULL);
return lm_ctx->pci_info.reg_info;
}
inline int
-lm_addr_to_sg(lm_ctx_t * const lm_ctx, dma_addr_t dma_addr,
- uint32_t len, dma_sg_t * sg, int max_sg)
+lm_addr_to_sg(lm_ctx_t *lm_ctx, dma_addr_t dma_addr,
+ uint32_t len, dma_sg_t *sg, int max_sg)
{
return dma_addr_to_sg(lm_ctx, lm_ctx->dma, dma_addr, len, sg, max_sg);
}
inline int
-lm_map_sg(lm_ctx_t * const lm_ctx, int prot,
- const dma_sg_t * sg, struct iovec *iov, int cnt)
+lm_map_sg(lm_ctx_t *lm_ctx, int prot,
+ const dma_sg_t *sg, struct iovec *iov, int cnt)
{
return dma_map_sg(lm_ctx->dma, prot, sg, iov, cnt);
}
inline void
-lm_unmap_sg(lm_ctx_t * const lm_ctx, const dma_sg_t * sg,
- struct iovec *iov, int cnt)
+lm_unmap_sg(lm_ctx_t *lm_ctx, const dma_sg_t *sg, struct iovec *iov, int cnt)
{
return dma_unmap_sg(lm_ctx->dma, sg, iov, cnt);
}
int
-lm_ctx_run(lm_dev_info_t * const dev_info)
+lm_ctx_run(lm_dev_info_t *dev_info)
{
int ret;
diff --git a/lib/libmuser_pci.c b/lib/libmuser_pci.c
index 4260dad..9c3d38c 100644
--- a/lib/libmuser_pci.c
+++ b/lib/libmuser_pci.c
@@ -45,8 +45,7 @@
#include "common.h"
static inline void
-muser_pci_hdr_write_bar(lm_ctx_t * const lm_ctx, const uint16_t bar_index,
- const char *const buf)
+muser_pci_hdr_write_bar(lm_ctx_t *lm_ctx, uint16_t bar_index, const char *buf)
{
uint32_t cfg_addr;
uint32_t *bar;
@@ -81,8 +80,8 @@ muser_pci_hdr_write_bar(lm_ctx_t * const lm_ctx, const uint16_t bar_index,
#define BAR_INDEX(offset) ((offset - PCI_BASE_ADDRESS_0) >> 2)
static int
-handle_command_write(lm_ctx_t * const ctx, lm_pci_config_space_t * const pci,
- const char * const buf, const size_t count)
+handle_command_write(lm_ctx_t *ctx, lm_pci_config_space_t *pci,
+ const char *buf, size_t count)
{
uint16_t v;
@@ -172,8 +171,8 @@ handle_command_write(lm_ctx_t * const ctx, lm_pci_config_space_t * const pci,
}
static int
-handle_erom_write(lm_ctx_t * const ctx, lm_pci_config_space_t * const pci,
- const char *const buf, const size_t count)
+handle_erom_write(lm_ctx_t *ctx, lm_pci_config_space_t *pci,
+ const char *buf, size_t count)
{
uint32_t v;
@@ -201,8 +200,8 @@ handle_erom_write(lm_ctx_t * const ctx, lm_pci_config_space_t * const pci,
}
static inline int
-muser_pci_hdr_write(lm_ctx_t * const lm_ctx, const uint16_t offset,
- const char *const buf, const size_t count)
+muser_pci_hdr_write(lm_ctx_t *lm_ctx, uint16_t offset,
+ const char *buf, size_t count)
{
uint32_t *bar;
lm_pci_config_space_t *pci;
@@ -264,9 +263,9 @@ muser_pci_hdr_write(lm_ctx_t * const lm_ctx, const uint16_t offset,
* @count: output parameter that receives the number of bytes read/written
*/
static inline int
-muser_do_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count,
- loff_t * const pos, const bool is_write,
- unsigned char *const buf)
+muser_do_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
+ loff_t *pos, bool is_write,
+ unsigned char *buf)
{
size_t _count;
loff_t _pos;
@@ -291,16 +290,16 @@ muser_do_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count,
}
static inline bool
-muser_is_pci_hdr_access(const lm_reg_info_t * const reg_info, const loff_t pos)
+muser_is_pci_hdr_access(const lm_reg_info_t *reg_info, loff_t pos)
{
const off_t off = (loff_t) region_to_offset(LM_DEV_CFG_REG_IDX);
return pos - off >= 0 && pos - off < PCI_STD_HEADER_SIZEOF;
}
int
-muser_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count,
- loff_t * const pos, const bool is_write,
- unsigned char *const buf)
+muser_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
+ loff_t *pos, bool is_write,
+ unsigned char *buf)
{
assert(lm_ctx);
assert(count);
diff --git a/lib/muser.h b/lib/muser.h
index 160d524..e1a9f85 100644
--- a/lib/muser.h
+++ b/lib/muser.h
@@ -89,10 +89,10 @@ struct lm_sparse_mmap_areas {
*
* @returns the number of bytes read or written, or a negative integer on error
*/
-typedef ssize_t (lm_region_access_t) (void *pvt, char * const buf, size_t count,
- loff_t offset, const bool is_write);
+typedef ssize_t (lm_region_access_t) (void *pvt, char *buf, size_t count,
+ loff_t offset, bool is_write);
-/**
+/**
* Prototype for memory access callback. The program MUST first map device
* memory in its own virtual address space using lm_mmap, do any additional
* work required, and finally return that memory. When a region is memory
@@ -114,7 +114,7 @@ typedef unsigned long (lm_map_region_t) (void *pvt, unsigned long off,
*
* @lm_ctx: the libmuser context to create mapping from
* @offset: offset of the region being mapped
- * @length: size of the region being mapped
+ * @length: size of the region being mapped
*
* @returns a pointer to the requested memory or MAP_FAILED on error. Sets errno.
*/
@@ -149,9 +149,7 @@ enum {
LM_DEV_INTX_IRQ_IDX,
LM_DEV_MSI_IRQ_IDX,
LM_DEV_MSIX_IRQ_IDX,
- LM_DEV_ERR_IRQ_IDX,
- LM_DEV_REQ_IRQ_IDX,
- LM_DEV_NUM_IRQS = 5
+ LM_DEV_NUM_IRQS = 3
};
enum {
@@ -188,14 +186,14 @@ typedef struct {
/*
* Class code.
- */
+ */
lm_pci_hdr_cc_t cc;
} lm_pci_info_t;
/*
* Returns a pointer to the non-standard part of the PCI configuration space.
*/
-lm_pci_config_space_t *lm_get_pci_config_space(lm_ctx_t * const lm_ctx);
+lm_pci_config_space_t *lm_get_pci_config_space(lm_ctx_t *lm_ctx);
#define LM_DMA_REGIONS 0x10
@@ -210,7 +208,7 @@ typedef enum {
*
* @lm_log_fn_t: typedef for log function.
*/
-typedef void (lm_log_fn_t) (void *pvt, const char *const msg);
+typedef void (lm_log_fn_t) (void *pvt, const char *msg);
/**
* Callback function that gets called when a capability is accessed. The
@@ -226,9 +224,9 @@ typedef void (lm_log_fn_t) (void *pvt, const char *const msg);
*
* @returns the number of bytes read or written
*/
-typedef ssize_t (lm_cap_access_t) (void *pvt, const uint8_t id,
- char * const buf, size_t count,
- loff_t offset, const bool is_write);
+typedef ssize_t (lm_cap_access_t) (void *pvt, uint8_t id,
+ char *buf, size_t count,
+ loff_t offset, bool is_write);
typedef struct {
@@ -299,7 +297,6 @@ typedef struct {
* Number of capabilities in above array.
*/
int nr_caps;
-
} lm_dev_info_t;
/**
@@ -309,14 +306,16 @@ typedef struct {
*
* @returns the lm_ctx to be used or NULL on error. Sets errno.
*/
-lm_ctx_t *lm_ctx_create(lm_dev_info_t * dev_info);
+lm_ctx_t *
+lm_ctx_create(lm_dev_info_t *dev_info);
/**
* Destroys libmuser context.
*
* @lm_ctx: the libmuser context to destroy
*/
-void lm_ctx_destroy(lm_ctx_t * lm_ctx);
+void
+lm_ctx_destroy(lm_ctx_t *lm_ctx);
/**
* Once the lm_ctx is configured lm_ctx_drive() drives it. This function waits
@@ -326,8 +325,8 @@ void lm_ctx_destroy(lm_ctx_t * lm_ctx);
*
* @returns 0 on success, -errno on failure.
*/
-
-int lm_ctx_drive(lm_ctx_t * lm_ctx);
+int
+lm_ctx_drive(lm_ctx_t *lm_ctx);
/**
* Creates and runs an lm_ctx.
@@ -336,7 +335,8 @@ int lm_ctx_drive(lm_ctx_t * lm_ctx);
*
* @returns 0 on success, -1 on failure. Sets errno.
*/
-int lm_ctx_run(lm_dev_info_t *dev_info);
+int
+lm_ctx_run(lm_dev_info_t *dev_info);
/**
* Triggers an interrupt.
@@ -349,7 +349,8 @@ int lm_ctx_run(lm_dev_info_t *dev_info);
*
* @returns 0 on success, or -1 on failure. Sets errno.
*/
-int lm_irq_trigger(lm_ctx_t * lm_ctx, uint32_t subindex);
+int
+lm_irq_trigger(lm_ctx_t *lm_ctx, uint32_t subindex);
/* Helper functions */
@@ -378,8 +379,9 @@ int lm_irq_trigger(lm_ctx_t * lm_ctx, uint32_t subindex);
* (-x - 1): if @max_sg is too small, where x is the number of scatter/gather
* entries necessary to complete this request.
*/
-int lm_addr_to_sg(lm_ctx_t * const lm_ctx, dma_addr_t dma_addr, uint32_t len,
- dma_sg_t *sg, int max_sg);
+int
+lm_addr_to_sg(lm_ctx_t *lm_ctx, dma_addr_t dma_addr, uint32_t len,
+ dma_sg_t *sg, int max_sg);
/**
* Maps a list scatter/gather entries from the guest's physical address space
@@ -396,7 +398,7 @@ int lm_addr_to_sg(lm_ctx_t * const lm_ctx, dma_addr_t dma_addr, uint32_t len,
* @returns 0 on success, -1 on failure
*/
int
-lm_map_sg(lm_ctx_t * const lm_ctx, int prot, const dma_sg_t * sg,
+lm_map_sg(lm_ctx_t *lm_ctx, int prot, const dma_sg_t *sg,
struct iovec *iov, int cnt);
/**
@@ -409,7 +411,7 @@ lm_map_sg(lm_ctx_t * const lm_ctx, int prot, const dma_sg_t * sg,
* @cnt: number of scatter/gather entries to unmap
*/
void
-lm_unmap_sg(lm_ctx_t * const lm_ctx, const dma_sg_t * sg,
+lm_unmap_sg(lm_ctx_t *lm_ctx, const dma_sg_t *sg,
struct iovec *iov, int cnt);
/**
@@ -423,7 +425,7 @@ lm_unmap_sg(lm_ctx_t * const lm_ctx, const dma_sg_t * sg,
* Returns the PCI region (LM_DEV_XXX_REG_IDX), or -errno on error.
*/
int
-lm_get_region(const loff_t pos, const size_t count, loff_t * const off);
+lm_get_region(loff_t pos, size_t count, loff_t *off);
/*
* Advanced stuff.
@@ -432,14 +434,13 @@ lm_get_region(const loff_t pos, const size_t count, loff_t * const off);
/**
* Returns the non-standard part of the PCI configuragion space.
*/
-uint8_t *lm_get_pci_non_std_config_space(lm_ctx_t * const lm_ctx);
+uint8_t *
+lm_get_pci_non_std_config_space(lm_ctx_t *lm_ctx);
-#ifdef DEBUG
void
-dump_buffer(lm_ctx_t const *const lm_ctx, char const *const prefix,
- unsigned char const *const buf, const uint32_t count);
-#endif
+dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
+ const unsigned char *buf, uint32_t count);
-#endif /* LIB_MUSER_H */
+#endif /* LIB_MUSER_H */
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/muser_priv.h b/lib/muser_priv.h
index e5af663..dca6810 100644
--- a/lib/muser_priv.h
+++ b/lib/muser_priv.h
@@ -1,11 +1,48 @@
+/*
+ * 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 MUSER_PRIV_H
+#define MUSER_PRIV_H
+
#include "muser.h"
int
-muser_pci_hdr_access(lm_ctx_t * const lm_ctx, size_t * const count,
- loff_t * const pos, const bool write,
- unsigned char *const buf);
+muser_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
+ loff_t *pos, bool write, unsigned char *buf);
-lm_reg_info_t *lm_get_region_info(lm_ctx_t * const lm_ctx);
+lm_reg_info_t *
+lm_get_region_info(lm_ctx_t *lm_ctx);
-uint64_t region_to_offset(const uint32_t region);
+uint64_t
+region_to_offset(uint32_t region);
+#endif /* MUSER_PRIV_H */
diff --git a/lib/pci.h b/lib/pci.h
index e4b7a78..3d6289f 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -35,7 +35,6 @@
#include <stdint.h>
#include <stdbool.h>
-
#include <linux/pci_regs.h>
/*
@@ -200,6 +199,6 @@ typedef struct {
_Static_assert(sizeof(lm_pci_config_space_t) == 0x100,
"bad PCI configuration space size");
-#endif /* LIBMUSER_PCI_H */
+#endif /* LIBMUSER_PCI_H */
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/python_bindings.c b/lib/python_bindings.c
index 874a58d..3953c1f 100644
--- a/lib/python_bindings.c
+++ b/lib/python_bindings.c
@@ -52,9 +52,9 @@ handle_read(char *dst, PyObject *result, int count)
*
* FIXME need a way to provide private pointer.
*/
-static ssize_t
-region_access_wrap(void *pvt, char * const buf, size_t count, loff_t offset,
- const bool is_write, int region)
+static ssize_t
+region_access_wrap(void *pvt, char *buf, size_t count, loff_t offset,
+ bool is_write, int region)
{
PyObject *arglist;
PyObject *result = NULL;
@@ -107,16 +107,17 @@ REGION_WRAP(6)
REGION_WRAP(7)
REGION_WRAP(8)
-static ssize_t (*region_access_wraps[LM_DEV_NUM_REGS])(void*, char * const, size_t, loff_t, const bool) = {
- r_0_wrap,
- r_1_wrap,
- r_2_wrap,
- r_3_wrap,
- r_4_wrap,
- r_5_wrap,
- r_6_wrap,
- r_7_wrap,
- r_8_wrap
+static ssize_t (*region_access_wraps[LM_DEV_NUM_REGS])(void *, char *, size_t,
+ loff_t, bool) = {
+ r_0_wrap,
+ r_1_wrap,
+ r_2_wrap,
+ r_3_wrap,
+ r_4_wrap,
+ r_5_wrap,
+ r_6_wrap,
+ r_7_wrap,
+ r_8_wrap
};
struct _region_info {
@@ -130,7 +131,8 @@ static const struct _region_info _0_ri;
static PyObject *log_fn;
static lm_log_lvl_t log_lvl = LM_ERR;
-static void _log_fn(void *pvt, const char *const msg)
+static void
+_log_fn(void *pvt, const char *msg)
{
PyObject *arglist;
PyObject *result = NULL;
@@ -155,25 +157,30 @@ libmuser_run(PyObject *self, PyObject *args, PyObject *kwargs)
int i;
struct _region_info _ri[LM_DEV_NUM_REGS] = { 0 };
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "HHs|Oi(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)IIIII", kwlist,
- &dev_info.pci_info.id.vid,
- &dev_info.pci_info.id.did,
- &dev_info.uuid,
- &log_fn, &log_lvl,
- &_ri[0].perm, &_ri[0].size, &_ri[0].fn,
- &_ri[1].perm, &_ri[1].size, &_ri[1].fn,
- &_ri[2].perm, &_ri[2].size, &_ri[2].fn,
- &_ri[3].perm, &_ri[3].size, &_ri[3].fn,
- &_ri[4].perm, &_ri[4].size, &_ri[4].fn,
- &_ri[5].perm, &_ri[5].size, &_ri[5].fn,
- &_ri[6].perm, &_ri[6].size, &_ri[6].fn,
- &_ri[7].perm, &_ri[7].size, &_ri[7].fn,
- &_ri[8].perm, &_ri[8].size, &_ri[8].fn,
- &dev_info.pci_info.irq_count[0],
- &dev_info.pci_info.irq_count[1],
- &dev_info.pci_info.irq_count[2],
- &dev_info.pci_info.irq_count[3],
- &dev_info.pci_info.irq_count[4])) {
+ if (!PyArg_ParseTupleAndKeywords(
+ args,
+ kwargs,
+ "HHs|Oi(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)(sIO)IIIII",
+ kwlist,
+ &dev_info.pci_info.id.vid,
+ &dev_info.pci_info.id.did,
+ &dev_info.uuid,
+ &log_fn,
+ &log_lvl,
+ &_ri[0].perm, &_ri[0].size, &_ri[0].fn,
+ &_ri[1].perm, &_ri[1].size, &_ri[1].fn,
+ &_ri[2].perm, &_ri[2].size, &_ri[2].fn,
+ &_ri[3].perm, &_ri[3].size, &_ri[3].fn,
+ &_ri[4].perm, &_ri[4].size, &_ri[4].fn,
+ &_ri[5].perm, &_ri[5].size, &_ri[5].fn,
+ &_ri[6].perm, &_ri[6].size, &_ri[6].fn,
+ &_ri[7].perm, &_ri[7].size, &_ri[7].fn,
+ &_ri[8].perm, &_ri[8].size, &_ri[8].fn,
+ &dev_info.pci_info.irq_count[0],
+ &dev_info.pci_info.irq_count[1],
+ &dev_info.pci_info.irq_count[2],
+ &dev_info.pci_info.irq_count[3],
+ &dev_info.pci_info.irq_count[4])) {
return NULL;
}
@@ -205,7 +212,7 @@ libmuser_run(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (log_fn != NULL) {
- if (!PyCallable_Check(log_fn)) {
+ if (!PyCallable_Check(log_fn)) {
return NULL;
}
dev_info.log = _log_fn;
@@ -217,14 +224,18 @@ libmuser_run(PyObject *self, PyObject *args, PyObject *kwargs)
}
static PyMethodDef LibmuserMethods[] = {
- {"run", (PyCFunction)libmuser_run, METH_VARARGS | METH_KEYWORDS, "runs a device"},
- {NULL, NULL, 0, NULL}
+ { "run",
+ (PyCFunction)libmuser_run,
+ METH_VARARGS | METH_KEYWORDS,
+ "runs a device"
+ },
+ { NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC
initmuser(void)
{
- (void) Py_InitModule("muser", LibmuserMethods);
+ (void)Py_InitModule("muser", LibmuserMethods);
}
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/python_bindings_install.sh b/lib/python_bindings_install.sh
index 7b209f2..e539d6b 100755
--- a/lib/python_bindings_install.sh
+++ b/lib/python_bindings_install.sh
@@ -1,3 +1,4 @@
+#!/bin/bash
#
# Copyright (c) 2019 Nutanix Inc. All rights reserved.
#
@@ -15,7 +16,7 @@
# * 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
@@ -27,7 +28,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-#!/bin/bash
# 'python setup.py install' expects to find a directory named 'build' with
# subdirectories 'lib.linux-x86_64-2.7' and 'temp.linux-x86_64-2.7'. If not,
diff --git a/lib/setup.py b/lib/setup.py
index b1ad34c..73bd93d 100644
--- a/lib/setup.py
+++ b/lib/setup.py
@@ -15,7 +15,7 @@
# * 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
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index 8a03c30..7f30be5 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -15,7 +15,7 @@
# * 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
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c
index e16cae2..beb1bd1 100644
--- a/samples/gpio-pci-idio-16.c
+++ b/samples/gpio-pci-idio-16.c
@@ -1,3 +1,36 @@
+/*
+ * Userspace mediated device sample application
+ *
+ * Copyright (c) 2019, Nutanix Inc. All rights reserved.
+ * Author: 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.
+ *
+ */
+
/* gpio-pci-idio-16 */
#include <stdio.h>