[dpdk-dev,v3,06/16] vfio: generalize pci_vfio_has_supported_extensions
Commit Message
The pci_vfio_has_supported_extensions is not PCI-specific and it is a private
function of the eal_pci_vfio.c. We just rename the function and make it
available even for non-PCI devices.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 36 +-----------------------------
lib/librte_eal/linuxapp/eal/eal_vfio.c | 33 +++++++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 4 ++++
3 files changed, 38 insertions(+), 35 deletions(-)
Comments
There is a small error in this patch:
2016-07-04 17:16, Jan Viktorin:
> The pci_vfio_has_supported_extensions is not PCI-specific and it is a private
> function of the eal_pci_vfio.c. We just rename the function and make it
> available even for non-PCI devices.
|...]
|> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -62,6 +62,39 @@ vfio_set_iommu_type(int vfio_container_fd) {
> }
>
> int
> +vfio_has_supported_extensions(int vfio_container_fd) {
> + int ret;
> + unsigned idx, n_extensions = 0;
> + for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
> + const struct vfio_iommu_type *t = &iommu_types[idx];
> +
> + ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
> + t->type_id);
> + if (ret < 0) {
> + RTE_LOG(ERR, EAL, " could not get IOMMU type, "
> + "error %i (%s)\n", errno,
> + strerror(errno));
> + close(vfio_container_fd);
lib/librte_eal/linuxapp/eal/eal_vfio.c:77:4: error:
implicit declaration of function ‘close’
It is fixed in patch 8 with "#include <unistd.h>".
@@ -203,40 +203,6 @@ pci_vfio_set_bus_master(int dev_fd)
return 0;
}
-/* check if we have any supported extensions */
-static int
-pci_vfio_has_supported_extensions(int vfio_container_fd) {
- int ret;
- unsigned idx, n_extensions = 0;
- for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
- const struct vfio_iommu_type *t = &iommu_types[idx];
-
- ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
- t->type_id);
- if (ret < 0) {
- RTE_LOG(ERR, EAL, " could not get IOMMU type, "
- "error %i (%s)\n", errno,
- strerror(errno));
- close(vfio_container_fd);
- return -1;
- } else if (ret == 1) {
- /* we found a supported extension */
- n_extensions++;
- }
- RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n",
- t->type_id, t->name,
- ret ? "supported" : "not supported");
- }
-
- /* if we didn't find any supported IOMMU types, fail */
- if (!n_extensions) {
- close(vfio_container_fd);
- return -1;
- }
-
- return 0;
-}
-
/* set up interrupt support (but not enable interrupts) */
static int
pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
@@ -360,7 +326,7 @@ pci_vfio_get_container_fd(void)
return -1;
}
- ret = pci_vfio_has_supported_extensions(vfio_container_fd);
+ ret = vfio_has_supported_extensions(vfio_container_fd);
if (ret) {
RTE_LOG(ERR, EAL, " no supported IOMMU "
"extensions found!\n");
@@ -62,6 +62,39 @@ vfio_set_iommu_type(int vfio_container_fd) {
}
int
+vfio_has_supported_extensions(int vfio_container_fd) {
+ int ret;
+ unsigned idx, n_extensions = 0;
+ for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
+ const struct vfio_iommu_type *t = &iommu_types[idx];
+
+ ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
+ t->type_id);
+ if (ret < 0) {
+ RTE_LOG(ERR, EAL, " could not get IOMMU type, "
+ "error %i (%s)\n", errno,
+ strerror(errno));
+ close(vfio_container_fd);
+ return -1;
+ } else if (ret == 1) {
+ /* we found a supported extension */
+ n_extensions++;
+ }
+ RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n",
+ t->type_id, t->name,
+ ret ? "supported" : "not supported");
+ }
+
+ /* if we didn't find any supported IOMMU types, fail */
+ if (!n_extensions) {
+ close(vfio_container_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
vfio_type1_dma_map(int vfio_container_fd)
{
const struct rte_memseg *ms = rte_eal_get_physmem_layout();
@@ -111,6 +111,10 @@ struct vfio_iommu_type {
const struct vfio_iommu_type *
vfio_set_iommu_type(int vfio_container_fd);
+/* check if we have any supported extensions */
+int
+vfio_has_supported_extensions(int vfio_container_fd);
+
int vfio_type1_dma_map(int);
int vfio_noiommu_dma_map(int);