diff options
-rw-r--r-- | lib/cap.c | 9 | ||||
-rw-r--r-- | lib/cap.h | 2 | ||||
-rw-r--r-- | lib/common.h | 9 | ||||
-rw-r--r-- | lib/dma.c | 26 | ||||
-rw-r--r-- | lib/dma.h | 51 | ||||
-rw-r--r-- | lib/libmuser.c | 132 | ||||
-rw-r--r-- | lib/libmuser_pci.c | 29 | ||||
-rw-r--r-- | lib/muser.h | 47 | ||||
-rw-r--r-- | lib/muser_priv.h | 11 | ||||
-rw-r--r-- | lib/python_bindings.c | 7 |
10 files changed, 173 insertions, 150 deletions
@@ -46,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; }; /* @@ -92,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; @@ -208,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; @@ -242,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); @@ -43,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/common.h b/lib/common.h index 622ba7c..85ad610 100644 --- a/lib/common.h +++ b/lib/common.h @@ -48,11 +48,12 @@ #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__ */ @@ -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; @@ -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 9ba163e..b5cc60e 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" + [VFIO_PCI_ERR_IRQ_INDEX] = "ERR", + [VFIO_PCI_REQ_IRQ_INDEX] = "REQ" }; /* FIXME need to validate index */ 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; } *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; @@ -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; @@ -782,8 +790,7 @@ lm_access(lm_ctx_t * const lm_ctx, char *buf, size_t count, } 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; @@ -854,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; @@ -899,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; @@ -946,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; @@ -983,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; @@ -998,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; @@ -1032,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; @@ -1048,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); @@ -1063,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; @@ -1087,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; @@ -1121,7 +1130,7 @@ lm_caps_init(lm_ctx_t *lm_ctx, lm_cap_t *caps, int nr_caps) } 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; @@ -1237,8 +1246,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; @@ -1267,7 +1276,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; @@ -1277,42 +1286,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 048d292..cd0a7ba 100644 --- a/lib/muser.h +++ b/lib/muser.h @@ -89,8 +89,8 @@ 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 @@ -195,7 +195,7 @@ typedef struct { /* * 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 +210,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 +226,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 { @@ -308,14 +308,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 @@ -325,7 +327,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. @@ -334,7 +337,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. @@ -347,7 +351,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 */ @@ -376,8 +381,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 @@ -394,7 +400,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); /** @@ -407,7 +413,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); /** @@ -421,7 +427,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. @@ -430,12 +436,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); +dump_buffer(lm_ctx_t *lm_ctx, const char *prefix, + const unsigned char *buf, uint32_t count); #endif #endif /* LIB_MUSER_H */ diff --git a/lib/muser_priv.h b/lib/muser_priv.h index 66600aa..dca6810 100644 --- a/lib/muser_priv.h +++ b/lib/muser_priv.h @@ -36,12 +36,13 @@ #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/python_bindings.c b/lib/python_bindings.c index 75bef91..3953c1f 100644 --- a/lib/python_bindings.c +++ b/lib/python_bindings.c @@ -53,8 +53,8 @@ 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) +region_access_wrap(void *pvt, char *buf, size_t count, loff_t offset, + bool is_write, int region) { PyObject *arglist; PyObject *result = NULL; @@ -131,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; |