xref: /openbmc/qemu/include/sysemu/iommufd.h (revision 7c30710b)
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,
522d1bf258SJoao Martins                                      uint64_t *caps, Error **errp);
535b1e96e6SJoao Martins bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
545b1e96e6SJoao Martins                                 uint32_t pt_id, uint32_t flags,
555b1e96e6SJoao Martins                                 uint32_t data_type, uint32_t data_len,
565b1e96e6SJoao Martins                                 void *data_ptr, uint32_t *out_hwpt,
575b1e96e6SJoao Martins                                 Error **errp);
5852ce8822SJoao Martins bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_id,
5952ce8822SJoao Martins                                         bool start, Error **errp);
60*7c30710bSJoao Martins bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
61*7c30710bSJoao Martins                                       uint64_t iova, ram_addr_t size,
62*7c30710bSJoao Martins                                       uint64_t page_size, uint64_t *data,
63*7c30710bSJoao Martins                                       Error **errp);
649005f928SZhenzhong Duan 
659005f928SZhenzhong Duan #define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
666e6d8ac6SEric Auger #endif
67