1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2019 Google LLC 3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * based in part on anv and radv which are: 6bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation 7bf215546Sopenharmony_ci * Copyright © 2016 Red Hat. 8bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen 9bf215546Sopenharmony_ci */ 10bf215546Sopenharmony_ci 11bf215546Sopenharmony_ci#ifndef VN_DEVICE_MEMORY_H 12bf215546Sopenharmony_ci#define VN_DEVICE_MEMORY_H 13bf215546Sopenharmony_ci 14bf215546Sopenharmony_ci#include "vn_common.h" 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_cistruct vn_device_memory_pool { 17bf215546Sopenharmony_ci mtx_t mutex; 18bf215546Sopenharmony_ci struct vn_device_memory *memory; 19bf215546Sopenharmony_ci VkDeviceSize used; 20bf215546Sopenharmony_ci}; 21bf215546Sopenharmony_ci 22bf215546Sopenharmony_cistruct vn_device_memory { 23bf215546Sopenharmony_ci struct vn_object_base base; 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci VkDeviceSize size; 26bf215546Sopenharmony_ci VkMemoryPropertyFlags flags; 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci /* non-NULL when suballocated */ 29bf215546Sopenharmony_ci struct vn_device_memory *base_memory; 30bf215546Sopenharmony_ci /* non-NULL when mappable or external */ 31bf215546Sopenharmony_ci struct vn_renderer_bo *base_bo; 32bf215546Sopenharmony_ci /* enforce kernel and ring ordering between memory export and free */ 33bf215546Sopenharmony_ci bool bo_roundtrip_seqno_valid; 34bf215546Sopenharmony_ci uint32_t bo_roundtrip_seqno; 35bf215546Sopenharmony_ci VkDeviceSize base_offset; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci VkDeviceSize map_end; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci /* non-NULL when backed by AHB */ 40bf215546Sopenharmony_ci struct AHardwareBuffer *ahb; 41bf215546Sopenharmony_ci}; 42bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vn_device_memory, 43bf215546Sopenharmony_ci base.base, 44bf215546Sopenharmony_ci VkDeviceMemory, 45bf215546Sopenharmony_ci VK_OBJECT_TYPE_DEVICE_MEMORY) 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_civoid 48bf215546Sopenharmony_civn_device_memory_pool_fini(struct vn_device *dev, uint32_t mem_type_index); 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_ciVkResult 51bf215546Sopenharmony_civn_device_memory_import_dma_buf(struct vn_device *dev, 52bf215546Sopenharmony_ci struct vn_device_memory *mem, 53bf215546Sopenharmony_ci const VkMemoryAllocateInfo *alloc_info, 54bf215546Sopenharmony_ci bool force_unmappable, 55bf215546Sopenharmony_ci int fd); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ciVkResult 58bf215546Sopenharmony_civn_get_memory_dma_buf_properties(struct vn_device *dev, 59bf215546Sopenharmony_ci int fd, 60bf215546Sopenharmony_ci uint64_t *out_alloc_size, 61bf215546Sopenharmony_ci uint32_t *out_mem_type_bits); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci#endif /* VN_DEVICE_MEMORY_H */ 64