1f61dddd7SZhenzhong Duan /* 2f61dddd7SZhenzhong Duan * VFIO BASE CONTAINER 3f61dddd7SZhenzhong Duan * 4f61dddd7SZhenzhong Duan * Copyright (C) 2023 Intel Corporation. 5f61dddd7SZhenzhong Duan * Copyright Red Hat, Inc. 2023 6f61dddd7SZhenzhong Duan * 7f61dddd7SZhenzhong Duan * Authors: Yi Liu <yi.l.liu@intel.com> 8f61dddd7SZhenzhong Duan * Eric Auger <eric.auger@redhat.com> 9f61dddd7SZhenzhong Duan * 10f61dddd7SZhenzhong Duan * SPDX-License-Identifier: GPL-2.0-or-later 11f61dddd7SZhenzhong Duan */ 12f61dddd7SZhenzhong Duan 13f61dddd7SZhenzhong Duan #ifndef HW_VFIO_VFIO_CONTAINER_BASE_H 14f61dddd7SZhenzhong Duan #define HW_VFIO_VFIO_CONTAINER_BASE_H 15f61dddd7SZhenzhong Duan 16f61dddd7SZhenzhong Duan #include "exec/memory.h" 17f61dddd7SZhenzhong Duan 18f61dddd7SZhenzhong Duan typedef struct VFIODevice VFIODevice; 19f61dddd7SZhenzhong Duan typedef struct VFIOIOMMUOps VFIOIOMMUOps; 20f61dddd7SZhenzhong Duan 21f61dddd7SZhenzhong Duan typedef struct { 22f61dddd7SZhenzhong Duan unsigned long *bitmap; 23f61dddd7SZhenzhong Duan hwaddr size; 24f61dddd7SZhenzhong Duan hwaddr pages; 25f61dddd7SZhenzhong Duan } VFIOBitmap; 26f61dddd7SZhenzhong Duan 27f61dddd7SZhenzhong Duan /* 28f61dddd7SZhenzhong Duan * This is the base object for vfio container backends 29f61dddd7SZhenzhong Duan */ 30f61dddd7SZhenzhong Duan typedef struct VFIOContainerBase { 31f61dddd7SZhenzhong Duan const VFIOIOMMUOps *ops; 32f61dddd7SZhenzhong Duan } VFIOContainerBase; 33f61dddd7SZhenzhong Duan 34b08501a9SEric Auger int vfio_container_dma_map(VFIOContainerBase *bcontainer, 35b08501a9SEric Auger hwaddr iova, ram_addr_t size, 36b08501a9SEric Auger void *vaddr, bool readonly); 37b08501a9SEric Auger int vfio_container_dma_unmap(VFIOContainerBase *bcontainer, 38b08501a9SEric Auger hwaddr iova, ram_addr_t size, 39b08501a9SEric Auger IOMMUTLBEntry *iotlb); 40b08501a9SEric Auger 41*ed2f7f80SZhenzhong Duan void vfio_container_init(VFIOContainerBase *bcontainer, 42*ed2f7f80SZhenzhong Duan const VFIOIOMMUOps *ops); 43*ed2f7f80SZhenzhong Duan void vfio_container_destroy(VFIOContainerBase *bcontainer); 44*ed2f7f80SZhenzhong Duan 45f61dddd7SZhenzhong Duan struct VFIOIOMMUOps { 46f61dddd7SZhenzhong Duan /* basic feature */ 47f61dddd7SZhenzhong Duan int (*dma_map)(VFIOContainerBase *bcontainer, 48f61dddd7SZhenzhong Duan hwaddr iova, ram_addr_t size, 49f61dddd7SZhenzhong Duan void *vaddr, bool readonly); 50f61dddd7SZhenzhong Duan int (*dma_unmap)(VFIOContainerBase *bcontainer, 51f61dddd7SZhenzhong Duan hwaddr iova, ram_addr_t size, 52f61dddd7SZhenzhong Duan IOMMUTLBEntry *iotlb); 53f61dddd7SZhenzhong Duan int (*attach_device)(const char *name, VFIODevice *vbasedev, 54f61dddd7SZhenzhong Duan AddressSpace *as, Error **errp); 55f61dddd7SZhenzhong Duan void (*detach_device)(VFIODevice *vbasedev); 56f61dddd7SZhenzhong Duan /* migration feature */ 57f61dddd7SZhenzhong Duan int (*set_dirty_page_tracking)(VFIOContainerBase *bcontainer, bool start); 58f61dddd7SZhenzhong Duan int (*query_dirty_bitmap)(VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, 59f61dddd7SZhenzhong Duan hwaddr iova, hwaddr size); 60f61dddd7SZhenzhong Duan }; 61f61dddd7SZhenzhong Duan #endif /* HW_VFIO_VFIO_CONTAINER_BASE_H */ 62