xref: /openbmc/qemu/include/sysemu/iommufd.h (revision 2d1bf258)
19005f928SZhenzhong Duan /*
29005f928SZhenzhong Duan  * iommufd container backend declaration
39005f928SZhenzhong Duan  *
49005f928SZhenzhong Duan  * Copyright (C) 2024 Intel Corporation.
59005f928SZhenzhong Duan  * Copyright Red Hat, Inc. 2024
69005f928SZhenzhong Duan  *
79005f928SZhenzhong Duan  * Authors: Yi Liu <yi.l.liu@intel.com>
89005f928SZhenzhong Duan  *          Eric Auger <eric.auger@redhat.com>
99005f928SZhenzhong Duan  *          Zhenzhong Duan <zhenzhong.duan@intel.com>
109005f928SZhenzhong Duan  *
119005f928SZhenzhong Duan  * SPDX-License-Identifier: GPL-2.0-or-later
129005f928SZhenzhong Duan  */
139005f928SZhenzhong 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"
209005f928SZhenzhong 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);
5042965386SZhenzhong Duan bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
5142965386SZhenzhong Duan                                      uint32_t *type, void *data, uint32_t len,
52*2d1bf258SJoao Martins                                      uint64_t *caps, Error **errp);
539005f928SZhenzhong Duan 
549005f928SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
556e6d8ac6SEric Auger #endif
56