1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
17 * VFIO socket for communication between primary and secondary processes.
19 * This file is only compiled if RTE_EAL_VFIO is set.
25 vfio_mp_primary(const struct rte_mp_msg *msg, const void *peer)
29 struct rte_mp_msg reply;
30 struct vfio_mp_param *r = (struct vfio_mp_param *)reply.param;
31 const struct vfio_mp_param *m =
32 (const struct vfio_mp_param *)msg->param;
34 if (msg->len_param != sizeof(*m)) {
35 RTE_LOG(ERR, EAL, "vfio received invalid message!\n");
39 memset(&reply, 0, sizeof(reply));
42 case SOCKET_REQ_GROUP:
43 r->req = SOCKET_REQ_GROUP;
44 r->group_num = m->group_num;
45 fd = rte_vfio_get_group_fd(m->group_num);
46 if (fd < 0 && fd != -ENOENT)
47 r->result = SOCKET_ERR;
48 else if (fd == -ENOENT)
49 /* if VFIO group exists but isn't bound to VFIO driver */
50 r->result = SOCKET_NO_FD;
52 /* if group exists and is bound to VFIO driver */
53 r->result = SOCKET_OK;
58 case SOCKET_REQ_CONTAINER:
59 r->req = SOCKET_REQ_CONTAINER;
60 fd = rte_vfio_get_container_fd();
62 r->result = SOCKET_ERR;
64 r->result = SOCKET_OK;
69 case SOCKET_REQ_DEFAULT_CONTAINER:
70 r->req = SOCKET_REQ_DEFAULT_CONTAINER;
71 fd = vfio_get_default_container_fd();
73 r->result = SOCKET_ERR;
75 r->result = SOCKET_OK;
80 case SOCKET_REQ_IOMMU_TYPE:
84 r->req = SOCKET_REQ_IOMMU_TYPE;
86 iommu_type_id = vfio_get_iommu_type();
88 if (iommu_type_id < 0)
89 r->result = SOCKET_ERR;
91 r->iommu_type_id = iommu_type_id;
92 r->result = SOCKET_OK;
97 RTE_LOG(ERR, EAL, "vfio received invalid message!\n");
101 strcpy(reply.name, EAL_VFIO_MP);
102 reply.len_param = sizeof(*r);
104 ret = rte_mp_reply(&reply, peer);
105 if (m->req == SOCKET_REQ_CONTAINER && fd >= 0)
111 vfio_mp_sync_setup(void)
113 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
114 int ret = rte_mp_action_register(EAL_VFIO_MP, vfio_mp_primary);
115 if (ret && rte_errno != ENOTSUP)
123 vfio_mp_sync_cleanup(void)
125 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
128 rte_mp_action_unregister(EAL_VFIO_MP);