1*9005f928SZhenzhong Duan /* 2*9005f928SZhenzhong Duan * iommufd container backend declaration 3*9005f928SZhenzhong Duan * 4*9005f928SZhenzhong Duan * Copyright (C) 2024 Intel Corporation. 5*9005f928SZhenzhong Duan * Copyright Red Hat, Inc. 2024 6*9005f928SZhenzhong Duan * 7*9005f928SZhenzhong Duan * Authors: Yi Liu <yi.l.liu@intel.com> 8*9005f928SZhenzhong Duan * Eric Auger <eric.auger@redhat.com> 9*9005f928SZhenzhong Duan * Zhenzhong Duan <zhenzhong.duan@intel.com> 10*9005f928SZhenzhong Duan * 11*9005f928SZhenzhong Duan * SPDX-License-Identifier: GPL-2.0-or-later 12*9005f928SZhenzhong Duan */ 13*9005f928SZhenzhong Duan 146e6d8ac6SEric Auger #ifndef SYSEMU_IOMMUFD_H 156e6d8ac6SEric Auger #define SYSEMU_IOMMUFD_H 166e6d8ac6SEric Auger 176e6d8ac6SEric Auger #include "qom/object.h" 186e6d8ac6SEric Auger #include "exec/hwaddr.h" 196e6d8ac6SEric Auger #include "exec/cpu-common.h" 20*9005f928SZhenzhong Duan #include "sysemu/host_iommu_device.h" 216e6d8ac6SEric Auger 226e6d8ac6SEric Auger #define TYPE_IOMMUFD_BACKEND "iommufd" 236e6d8ac6SEric Auger OBJECT_DECLARE_TYPE(IOMMUFDBackend, IOMMUFDBackendClass, IOMMUFD_BACKEND) 246e6d8ac6SEric Auger 256e6d8ac6SEric Auger struct IOMMUFDBackendClass { 266e6d8ac6SEric Auger ObjectClass parent_class; 276e6d8ac6SEric Auger }; 286e6d8ac6SEric Auger 296e6d8ac6SEric Auger struct IOMMUFDBackend { 306e6d8ac6SEric Auger Object parent; 316e6d8ac6SEric Auger 326e6d8ac6SEric Auger /*< protected >*/ 336e6d8ac6SEric Auger int fd; /* /dev/iommu file descriptor */ 346e6d8ac6SEric Auger bool owned; /* is the /dev/iommu opened internally */ 356e6d8ac6SEric Auger uint32_t users; 366e6d8ac6SEric Auger 376e6d8ac6SEric Auger /*< public >*/ 386e6d8ac6SEric Auger }; 396e6d8ac6SEric Auger 409067d50dSZhenzhong Duan bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp); 416e6d8ac6SEric Auger void iommufd_backend_disconnect(IOMMUFDBackend *be); 426e6d8ac6SEric Auger 439067d50dSZhenzhong Duan bool iommufd_backend_alloc_ioas(IOMMUFDBackend *be, uint32_t *ioas_id, 446e6d8ac6SEric Auger Error **errp); 456e6d8ac6SEric Auger void iommufd_backend_free_id(IOMMUFDBackend *be, uint32_t id); 466e6d8ac6SEric Auger int iommufd_backend_map_dma(IOMMUFDBackend *be, uint32_t ioas_id, hwaddr iova, 476e6d8ac6SEric Auger ram_addr_t size, void *vaddr, bool readonly); 486e6d8ac6SEric Auger int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id, 496e6d8ac6SEric Auger hwaddr iova, ram_addr_t size); 50*9005f928SZhenzhong Duan 51*9005f928SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd" 526e6d8ac6SEric Auger #endif 53