Skip to content

Commit

Permalink
dm: fill region ID to dm-land ivshmem PCI config space
Browse files Browse the repository at this point in the history
  1) region ID shall be configured by user via config tool.
  2) region ID is programmed to "Subsystem ID" of PCI config space.
  2) "Subsystem Vendor ID" is harded coded as 0x8086

  Parameters to configure dm-land IVSHMEM device example generated
  by config tool as below:
  `add_virtual_device   8 ivshmem hv:/shm_region_0,256,2`

Tracked-On: projectacrn#8566
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Jian Jun Chen <jian.jun.chen@intel.com>
  • Loading branch information
yonghuah committed Mar 17, 2024
1 parent 3f5d88b commit cfbdbed
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions devicemodel/hw/pci/ivshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define IVSHMEM_DEVICE_ID 0x1110
#define IVSHMEM_CLASS 0x05
#define IVSHMEM_REV 0x01
#define IVSHMEM_INTEL_SUBVENDOR_ID 0x8086U


/* IVSHMEM MMIO Registers */
Expand Down Expand Up @@ -249,13 +250,13 @@ pci_ivshmem_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
static int
pci_ivshmem_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{
uint32_t size;
char *tmp, *name, *orig;
uint32_t size, region_id = 0;
char *tmp, *name, *size_str, *orig;
struct pci_ivshmem_vdev *ivshmem_vdev = NULL;
bool is_hv_land;
int rc;

/* ivshmem device usage: "-s N,ivshmem,shm_name,shm_size" */
/* ivshmem device usage: "-s N,ivshmem,shm_name,shm_size,region_id" */
tmp = orig = strdup(opts);
if (!orig) {
pr_warn("No memory for strdup\n");
Expand All @@ -277,8 +278,9 @@ pci_ivshmem_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
goto err;
}

if (dm_strtoui(tmp, &tmp, 10, &size) != 0) {
pr_warn("the shared memory size is incorrect, %s\n", tmp);
size_str = strsep(&tmp, ",");
if (dm_strtoui(size_str, &size_str, 10, &size) != 0) {
pr_warn("the shared memory size is incorrect, %s\n", size_str);
goto err;
}
size *= 0x100000; /* convert to megabytes */
Expand All @@ -289,6 +291,13 @@ pci_ivshmem_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
goto err;
}

if (tmp) {
if (dm_strtoui(tmp, &tmp, 10, &region_id) != 0) {
pr_warn("shared memory region ID is incorrect, %s, 0 will used.\n", tmp);
region_id = 0;
}
}

ivshmem_vdev = calloc(1, sizeof(struct pci_ivshmem_vdev));
if (!ivshmem_vdev) {
pr_warn("failed to allocate ivshmem device\n");
Expand All @@ -304,6 +313,8 @@ pci_ivshmem_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
pci_set_cfgdata16(dev, PCIR_DEVICE, IVSHMEM_DEVICE_ID);
pci_set_cfgdata16(dev, PCIR_REVID, IVSHMEM_REV);
pci_set_cfgdata8(dev, PCIR_CLASS, IVSHMEM_CLASS);
pci_set_cfgdata16(dev, PCIR_SUBDEV_0, (uint16_t)region_id);
pci_set_cfgdata16(dev, PCIR_SUBVEND_0, IVSHMEM_INTEL_SUBVENDOR_ID);

pci_emul_alloc_bar(dev, IVSHMEM_MMIO_BAR, PCIBAR_MEM32, IVSHMEM_REG_SIZE);
pci_emul_alloc_bar(dev, IVSHMEM_MSIX_BAR, PCIBAR_MEM32, IVSHMEM_MSIX_PBA_SIZE);
Expand Down

0 comments on commit cfbdbed

Please sign in to comment.