1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd. 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy 5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal 6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights 7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is 9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#ifndef PVR_BO_H 25bf215546Sopenharmony_ci#define PVR_BO_H 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include <stddef.h> 28bf215546Sopenharmony_ci#include <stdint.h> 29bf215546Sopenharmony_ci#include <vulkan/vulkan.h> 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "util/list.h" 32bf215546Sopenharmony_ci#include "util/macros.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct pvr_device; 35bf215546Sopenharmony_cistruct pvr_winsys_bo; 36bf215546Sopenharmony_cistruct pvr_winsys_vma; 37bf215546Sopenharmony_cistruct pvr_winsys_heap; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistruct pvr_bo { 40bf215546Sopenharmony_ci /* Since multiple components (csb, caching logic, etc) can make use of 41bf215546Sopenharmony_ci * linking buffers in a list, we add 'link' in pvr_bo to avoid an extra 42bf215546Sopenharmony_ci * level of structure inheritance. It's the responsibility of the buffer 43bf215546Sopenharmony_ci * user to manage the list and remove the buffer from the list before 44bf215546Sopenharmony_ci * freeing it. 45bf215546Sopenharmony_ci */ 46bf215546Sopenharmony_ci struct list_head link; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci struct pvr_winsys_bo *bo; 49bf215546Sopenharmony_ci struct pvr_winsys_vma *vma; 50bf215546Sopenharmony_ci}; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/** 53bf215546Sopenharmony_ci * \brief Flag passed to #pvr_bo_alloc() to indicate that the buffer should be 54bf215546Sopenharmony_ci * CPU accessible. This is required in order to map a buffer with 55bf215546Sopenharmony_ci * #pvr_bo_cpu_map(). 56bf215546Sopenharmony_ci */ 57bf215546Sopenharmony_ci#define PVR_BO_ALLOC_FLAG_CPU_ACCESS BITFIELD_BIT(0U) 58bf215546Sopenharmony_ci/** 59bf215546Sopenharmony_ci * \brief Flag passed to #pvr_bo_alloc() to indicate that the buffer should 60bf215546Sopenharmony_ci * be mapped to the CPU. Implies #PVR_BO_ALLOC_FLAG_CPU_ACCESS. 61bf215546Sopenharmony_ci */ 62bf215546Sopenharmony_ci#define PVR_BO_ALLOC_FLAG_CPU_MAPPED \ 63bf215546Sopenharmony_ci (BITFIELD_BIT(1U) | PVR_BO_ALLOC_FLAG_CPU_ACCESS) 64bf215546Sopenharmony_ci/** 65bf215546Sopenharmony_ci * \brief Flag passed to #pvr_bo_alloc() to indicate that the buffer should be 66bf215546Sopenharmony_ci * mapped to the GPU as uncached. 67bf215546Sopenharmony_ci */ 68bf215546Sopenharmony_ci#define PVR_BO_ALLOC_FLAG_GPU_UNCACHED BITFIELD_BIT(2U) 69bf215546Sopenharmony_ci/** 70bf215546Sopenharmony_ci * \brief Flag passed to #pvr_bo_alloc() to indicate that the buffer GPU mapping 71bf215546Sopenharmony_ci * should be restricted to only allow access to the Parameter Manager unit and 72bf215546Sopenharmony_ci * firmware processor. 73bf215546Sopenharmony_ci */ 74bf215546Sopenharmony_ci#define PVR_BO_ALLOC_FLAG_PM_FW_PROTECT BITFIELD_BIT(3U) 75bf215546Sopenharmony_ci/** 76bf215546Sopenharmony_ci * \brief Flag passed to #pvr_bo_alloc() to indicate that the buffer should be 77bf215546Sopenharmony_ci * zeroed at allocation time. 78bf215546Sopenharmony_ci */ 79bf215546Sopenharmony_ci#define PVR_BO_ALLOC_FLAG_ZERO_ON_ALLOC BITFIELD_BIT(4U) 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ciVkResult pvr_bo_alloc(struct pvr_device *device, 82bf215546Sopenharmony_ci struct pvr_winsys_heap *heap, 83bf215546Sopenharmony_ci uint64_t size, 84bf215546Sopenharmony_ci uint64_t alignment, 85bf215546Sopenharmony_ci uint64_t flags, 86bf215546Sopenharmony_ci struct pvr_bo **const bo_out); 87bf215546Sopenharmony_civoid *pvr_bo_cpu_map(struct pvr_device *device, struct pvr_bo *bo); 88bf215546Sopenharmony_civoid pvr_bo_cpu_unmap(struct pvr_device *device, struct pvr_bo *bo); 89bf215546Sopenharmony_civoid pvr_bo_free(struct pvr_device *device, struct pvr_bo *bo); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci#endif /* PVR_BO_H */ 92