LCOV - code coverage report
Current view: top level - drivers/crypto/bcmfs - bcmfs_vfio.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 38 0.0 %
Date: 2025-11-01 17:50:34 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 12 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2020 Broadcom.
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <uapi/linux/vfio.h>
       7                 :            : 
       8                 :            : #include <errno.h>
       9                 :            : #include <sys/mman.h>
      10                 :            : #include <sys/ioctl.h>
      11                 :            : 
      12                 :            : #include <rte_vfio.h>
      13                 :            : 
      14                 :            : #include "bcmfs_device.h"
      15                 :            : #include "bcmfs_logs.h"
      16                 :            : #include "bcmfs_vfio.h"
      17                 :            : 
      18                 :            : static int
      19                 :          0 : vfio_map_dev_obj(const char *path, const char *dev_obj,
      20                 :            :                  uint32_t *size, void **addr, int *dev_fd)
      21                 :            : {
      22                 :            :         int32_t ret;
      23                 :            :         struct vfio_group_status status = { .argsz = sizeof(status) };
      24                 :            : 
      25                 :          0 :         struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
      26                 :          0 :         struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
      27                 :            : 
      28                 :          0 :         ret = rte_vfio_setup_device(path, dev_obj, dev_fd, &d_info);
      29         [ #  # ]:          0 :         if (ret) {
      30                 :          0 :                 BCMFS_LOG(ERR, "VFIO Setting for device failed");
      31                 :          0 :                 return ret;
      32                 :            :         }
      33                 :            : 
      34                 :            :         /* getting device region info*/
      35                 :          0 :         ret = ioctl(*dev_fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info);
      36         [ #  # ]:          0 :         if (ret < 0) {
      37                 :          0 :                 BCMFS_LOG(ERR, "Error in VFIO getting REGION_INFO");
      38                 :          0 :                 goto map_failed;
      39                 :            :         }
      40                 :            : 
      41                 :          0 :         *addr = mmap(NULL, reg_info.size,
      42                 :            :                      PROT_WRITE | PROT_READ, MAP_SHARED,
      43                 :          0 :                      *dev_fd, reg_info.offset);
      44         [ #  # ]:          0 :         if (*addr == MAP_FAILED) {
      45                 :          0 :                 BCMFS_LOG(ERR, "Error mapping region (errno = %d)", errno);
      46                 :          0 :                 ret = errno;
      47                 :          0 :                 goto map_failed;
      48                 :            :         }
      49                 :          0 :         *size = reg_info.size;
      50                 :            : 
      51                 :          0 :         return 0;
      52                 :            : 
      53                 :          0 : map_failed:
      54                 :          0 :         rte_vfio_release_device(path, dev_obj, *dev_fd);
      55                 :            : 
      56                 :          0 :         return ret;
      57                 :            : }
      58                 :            : 
      59                 :            : int
      60                 :          0 : bcmfs_attach_vfio(struct bcmfs_device *dev)
      61                 :            : {
      62                 :            :         int ret;
      63                 :            :         int vfio_dev_fd;
      64                 :          0 :         void  *v_addr = NULL;
      65                 :          0 :         uint32_t size = 0;
      66                 :            : 
      67                 :          0 :         ret = vfio_map_dev_obj(dev->dirname, dev->name,
      68                 :            :                                &size, &v_addr, &vfio_dev_fd);
      69         [ #  # ]:          0 :         if (ret)
      70                 :            :                 return -1;
      71                 :            : 
      72                 :          0 :         dev->mmap_size = size;
      73                 :          0 :         dev->mmap_addr = v_addr;
      74                 :          0 :         dev->vfio_dev_fd = vfio_dev_fd;
      75                 :            : 
      76                 :          0 :         return 0;
      77                 :            : }
      78                 :            : 
      79                 :            : void
      80                 :          0 : bcmfs_release_vfio(struct bcmfs_device *dev)
      81                 :            : {
      82                 :            :         int ret;
      83                 :            : 
      84         [ #  # ]:          0 :         if (dev == NULL)
      85                 :            :                 return;
      86                 :            : 
      87                 :            :         /* unmap the addr */
      88                 :          0 :         munmap(dev->mmap_addr, dev->mmap_size);
      89                 :            :         /* release the device */
      90                 :          0 :         ret = rte_vfio_release_device(dev->dirname, dev->name,
      91                 :            :                                       dev->vfio_dev_fd);
      92         [ #  # ]:          0 :         if (ret < 0) {
      93                 :          0 :                 BCMFS_LOG(ERR, "cannot release device");
      94                 :          0 :                 return;
      95                 :            :         }
      96                 :            : }

Generated by: LCOV version 1.14