diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2019-08-23 11:32:24 -0400 |
---|---|---|
committer | Felipe Franciosi <felipe@nutanix.com> | 2019-09-05 16:45:35 +0100 |
commit | 1693baa1870d141434f1e0d0606d8b08c6fe22c5 (patch) | |
tree | d4f27d99b74c43b28a461496053ec378864e6459 /lib | |
parent | 0967019779613ba70e70c6a1d994138fa462790e (diff) | |
download | libvfio-user-1693baa1870d141434f1e0d0606d8b08c6fe22c5.zip libvfio-user-1693baa1870d141434f1e0d0606d8b08c6fe22c5.tar.gz libvfio-user-1693baa1870d141434f1e0d0606d8b08c6fe22c5.tar.bz2 |
move region callbacks in region_info
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libmuser.c | 37 | ||||
-rw-r--r-- | lib/muser.h | 21 | ||||
-rw-r--r-- | lib/pci.h | 10 |
3 files changed, 20 insertions, 48 deletions
diff --git a/lib/libmuser.c b/lib/libmuser.c index c36f85f..92ffe1a 100644 --- a/lib/libmuser.c +++ b/lib/libmuser.c @@ -542,7 +542,7 @@ lm_get_region(lm_ctx_t * const lm_ctx, const loff_t pos, const size_t count, static ssize_t handle_pci_config_space_access(lm_ctx_t *lm_ctx, char *buf, size_t count, loff_t pos, bool is_write, - lm_non_bar_access_t *pci_config_fn) + lm_region_access_t *pci_config_fn) { int r1, r2 = 0; @@ -569,7 +569,6 @@ do_access(lm_ctx_t * const lm_ctx, char * const buf, size_t count, loff_t pos, { int idx; loff_t offset; - int ret = -EINVAL; lm_pci_info_t *pci_info; assert(lm_ctx != NULL); @@ -583,31 +582,26 @@ do_access(lm_ctx_t * const lm_ctx, char * const buf, size_t count, loff_t pos, return idx; } + 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, + is_write, pci_info->reg_info[idx].fn); + } /* * Checking whether a callback exists might sound expensive however this * code is not performance critical. This works well when we don't expect a * region to be used, so the user of the library can simply leave the * callback NULL in lm_ctx_create. */ - switch (idx) { - case LM_DEV_BAR0_REG_IDX ... LM_DEV_BAR5_REG_IDX: - if (pci_info->bar_fn) - return pci_info->bar_fn(lm_ctx->pvt, idx, buf, count, offset, - is_write); - case LM_DEV_ROM_REG_IDX: - if (pci_info->rom_fn) - return pci_info->rom_fn(lm_ctx->pvt, buf, count, offset, is_write); - case LM_DEV_CFG_REG_IDX: - return handle_pci_config_space_access(lm_ctx, buf, count, offset, - is_write, pci_info->pci_config_fn); - case LM_DEV_VGA_REG_IDX: - if (pci_info->vga_fn) - return pci_info->vga_fn(lm_ctx->pvt, buf, count, offset, is_write); - default: - lm_log(lm_ctx, LM_ERR, "bad region %d\n", idx); + if (pci_info->reg_info[idx].fn) { + return pci_info->reg_info[idx].fn(lm_ctx->pvt, buf, count, offset, + is_write); } - return ret; + return -EINVAL; } /* @@ -1007,11 +1001,6 @@ lm_ctx_create(lm_dev_info_t * const dev_info) lm_ctx->log = dev_info->log; lm_ctx->log_lvl = dev_info->log_lvl; - lm_ctx->pci_info.bar_fn = dev_info->pci_info.bar_fn; - lm_ctx->pci_info.rom_fn = dev_info->pci_info.rom_fn; - lm_ctx->pci_info.pci_config_fn = dev_info->pci_info.pci_config_fn; - lm_ctx->pci_info.vga_fn = dev_info->pci_info.vga_fn; - err = lm_caps_init(lm_ctx, dev_info->caps, dev_info->nr_caps); out: diff --git a/lib/muser.h b/lib/muser.h index 904c7b8..c022edf 100644 --- a/lib/muser.h +++ b/lib/muser.h @@ -51,33 +51,12 @@ typedef struct { unsigned long (*mmap) (void *pvt, unsigned long pgoff); } lm_fops_t; - -/** - * Callback function signatures for each regions. - * - * @lm_bar_access_t: typedef for BAR access function. - * @lm_non_bar_access_t: typedef for non-BAR(rom, pci config, - * vga) access functions. - */ -typedef ssize_t (lm_bar_access_t) (void *pvt, const int region_index, - char * const buf, size_t count, - loff_t offset, const bool is_write); -typedef ssize_t (lm_non_bar_access_t) (void *pvt, char * const buf, - size_t count, loff_t offset, - const bool is_write); - typedef struct { uint32_t irq_count[LM_DEV_NUM_IRQS]; lm_reg_info_t reg_info[LM_DEV_NUM_REGS]; lm_pci_hdr_id_t id; lm_pci_hdr_cc_t cc; - - /* PCI region access callbacks. */ - lm_bar_access_t *bar_fn; - lm_non_bar_access_t *rom_fn; - lm_non_bar_access_t *pci_config_fn; - lm_non_bar_access_t *vga_fn; } lm_pci_info_t; /** @@ -241,10 +241,14 @@ _Static_assert(sizeof(struct lm_pci_config_space) == 0x100, #define LM_REG_FLAG_RW (LM_REG_FLAG_READ | LM_REG_FLAG_WRITE) #define LM_REG_FLAG_MEM (1 << 3) // if unset, bar is IO +typedef ssize_t (lm_region_access_t) (void *pvt, char * const buf, size_t count, + loff_t offset, const bool is_write); + struct lm_reg_info { - uint32_t flags; - uint32_t size; - uint64_t offset; + uint32_t flags; + uint32_t size; + uint64_t offset; + lm_region_access_t *fn; }; enum { |