#include "portal/dpaa2_hw_pvt.h"
#include "portal/dpaa2_hw_dpio.h"
-#define VFIO_MAX_CONTAINERS 1
-
#define FSLMC_VFIO_LOG(level, fmt, args...) \
RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args)
#define SYSFS_FSL_MC_DEVICES "/sys/bus/fsl-mc/devices"
/* Number of VFIO containers & groups with in */
-static struct fslmc_vfio_group vfio_groups[VFIO_MAX_GRP];
-static struct fslmc_vfio_container vfio_containers[VFIO_MAX_CONTAINERS];
+static struct fslmc_vfio_group vfio_group;
+static struct fslmc_vfio_container vfio_container;
static int container_device_fd;
static uint32_t *msi_intr_vaddr;
void *(*rte_mcp_ptr_list);
TAILQ_INSERT_TAIL(&fslmc_obj_list, object, next);
}
-static int vfio_connect_container(struct fslmc_vfio_group *vfio_group)
+static int vfio_connect_container(void)
{
- struct fslmc_vfio_container *container;
- int i, fd, ret;
+ int fd, ret;
/* Try connecting to vfio container if already created */
- for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
- container = &vfio_containers[i];
- if (!ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER,
- &container->fd)) {
- FSLMC_VFIO_LOG(INFO,
- "Container pre-exists with FD[0x%x] for this group",
- container->fd);
- vfio_group->container = container;
- return 0;
- }
+ if (!ioctl(vfio_group.fd, VFIO_GROUP_SET_CONTAINER,
+ &vfio_container.fd)) {
+ FSLMC_VFIO_LOG(INFO,
+ "Container pre-exists with FD[0x%x] for this group",
+ vfio_container.fd);
+ vfio_group.container = &vfio_container;
+ return 0;
}
/* Opens main vfio file descriptor which represents the "container" */
/* Check whether support for SMMU type IOMMU present or not */
if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
/* Connect group to container */
- ret = ioctl(vfio_group->fd, VFIO_GROUP_SET_CONTAINER, &fd);
+ ret = ioctl(vfio_group.fd, VFIO_GROUP_SET_CONTAINER, &fd);
if (ret) {
FSLMC_VFIO_LOG(ERR, "Failed to setup group container");
close(fd);
return -EINVAL;
}
- container = NULL;
- for (i = 0; i < VFIO_MAX_CONTAINERS; i++) {
- if (vfio_containers[i].used)
- continue;
- container = &vfio_containers[i];
- }
- if (!container) {
- FSLMC_VFIO_LOG(ERR, "No free container found");
- close(fd);
- return -ENOMEM;
- }
+ vfio_container.used = 1;
+ vfio_container.fd = fd;
+ vfio_container.group = &vfio_group;
+ vfio_group.container = &vfio_container;
- container->used = 1;
- container->fd = fd;
- container->group_list[container->index] = vfio_group;
- vfio_group->container = container;
- container->index++;
return 0;
}
#endif
/* SET DMA MAP for IOMMU */
- group = &vfio_groups[0];
+ group = &vfio_group;
if (!group->container) {
FSLMC_VFIO_LOG(ERR, "Container is not connected ");
char path[PATH_MAX];
int64_t v_addr;
int ndev_count;
- struct fslmc_vfio_group *group = &vfio_groups[0];
+ struct fslmc_vfio_group *group = &vfio_group;
static int process_once;
/* if already done once */
{
struct fslmc_vfio_group *group = NULL;
int groupid;
- int ret, i;
+ int ret;
char *container;
struct vfio_group_status status = { .argsz = sizeof(status) };
FSLMC_VFIO_LOG(DEBUG, "VFIO iommu group id = %d", groupid);
/* Check if group already exists */
- for (i = 0; i < VFIO_MAX_GRP; i++) {
- group = &vfio_groups[i];
- if (group->groupid == groupid) {
- FSLMC_VFIO_LOG(ERR, "groupid already exists %d",
- groupid);
- return 0;
- }
+ group = &vfio_group;
+ if (group->groupid == groupid) {
+ FSLMC_VFIO_LOG(ERR, "groupid already exists %d",
+ groupid);
+ return 0;
}
/* get the actual group fd */
/* check if group does not have a container yet */
if (!(status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
/* Now connect this IOMMU group to given container */
- ret = vfio_connect_container(group);
+ ret = vfio_connect_container();
if (ret) {
FSLMC_VFIO_LOG(ERR, "VFIO error connecting container"
" with groupid %d", groupid);