1 /* 2 * iommufd container backend declaration 3 * 4 * Copyright (C) 2024 Intel Corporation. 5 * Copyright Red Hat, Inc. 2024 6 * 7 * Authors: Yi Liu <yi.l.liu@intel.com> 8 * Eric Auger <eric.auger@redhat.com> 9 * Zhenzhong Duan <zhenzhong.duan@intel.com> 10 * 11 * SPDX-License-Identifier: GPL-2.0-or-later 12 */ 13 14 #ifndef SYSEMU_IOMMUFD_H 15 #define SYSEMU_IOMMUFD_H 16 17 #include "qom/object.h" 18 #include "exec/hwaddr.h" 19 #include "exec/cpu-common.h" 20 #include "sysemu/host_iommu_device.h" 21 22 #define TYPE_IOMMUFD_BACKEND "iommufd" 23 OBJECT_DECLARE_TYPE(IOMMUFDBackend, IOMMUFDBackendClass, IOMMUFD_BACKEND) 24 25 struct IOMMUFDBackendClass { 26 ObjectClass parent_class; 27 }; 28 29 struct IOMMUFDBackend { 30 Object parent; 31 32 /*< protected >*/ 33 int fd; /* /dev/iommu file descriptor */ 34 bool owned; /* is the /dev/iommu opened internally */ 35 uint32_t users; 36 37 /*< public >*/ 38 }; 39 40 bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); 41 void iommufd_backend_disconnect(IOMMUFDBackend *be); 42 43 bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, 44 Error **errp); 45 void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); 46 int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, 47 ram_addr_t size, void *vaddr, bool readonly); 48 int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, 49 hwaddr iova, ram_addr_t size); 50 bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid, 51 uint32_t *type, void *data, uint32_t len, 52 uint64_t *caps, Error **errp); 53 bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id, 54 uint32_t pt_id, uint32_t flags, 55 uint32_t data_type, uint32_t data_len, 56 void *data_ptr, uint32_t *out_hwpt, 57 Error **errp); 58 59 #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" 60 #endif 61