1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_compat.h>
18 * VFIO socket for communication between primary and secondary processes.
20 * This file is only compiled if RTE_EAL_VFIO is set.
26 vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)
30 struct rte_mp_msg reply;
31 struct vfio_mp_param *r = (struct vfio_mp_param *)reply.param;
32 const struct vfio_mp_param *m =
33 (const struct vfio_mp_param *)msg->param;
35 if (msg->len_param != sizeof(*m)) {
36 RTE_LOG(ERR, EAL, "vfio received invalid message!\n");
40 memset(&reply, 0, sizeof(reply));
43 case SOCKET_REQ_GROUP:
44 r->req = SOCKET_REQ_GROUP;
45 r->group_num = m->group_num;
46 fd = rte_vfio_get_group_fd(m->group_num);
47 if (fd < 0 && fd != -ENOENT)
48 r->result = SOCKET_ERR;
49 else if (fd == -ENOENT)
50 /* if VFIO group exists but isn't bound to VFIO driver */
51 r->result = SOCKET_NO_FD;
53 /* if group exists and is bound to VFIO driver */
54 r->result = SOCKET_OK;
59 case SOCKET_REQ_CONTAINER:
60 r->req = SOCKET_REQ_CONTAINER;
61 fd = rte_vfio_get_container_fd();
63 r->result = SOCKET_ERR;
65 r->result = SOCKET_OK;
70 case SOCKET_REQ_DEFAULT_CONTAINER:
71 r->req = SOCKET_REQ_DEFAULT_CONTAINER;
72 fd = vfio_get_default_container_fd();
74 r->result = SOCKET_ERR;
76 r->result = SOCKET_OK;
81 case SOCKET_REQ_IOMMU_TYPE:
85 r->req = SOCKET_REQ_IOMMU_TYPE;
87 iommu_type_id = vfio_get_iommu_type();
89 if (iommu_type_id < 0)
90 r->result = SOCKET_ERR;
92 r->iommu_type_id = iommu_type_id;
93 r->result = SOCKET_OK;
98 RTE_LOG(ERR, EAL, "vfio received invalid message!\n");
102 strcpy(reply.name, EAL_VFIO_MP);
103 reply.len_param = sizeof(*r);
105 ret = rte_mp_reply(&reply, peer);
106 if (m->req == SOCKET_REQ_CONTAINER && fd >= 0)
112 vfio_mp_sync_setup(void)
114 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
115 int ret = rte_mp_action_register(EAL_VFIO_MP, vfio_mp_primary);
116 if (ret && rte_errno != ENOTSUP)