1 1.4 riastrad /* $NetBSD: amdgpu_gart.h,v 1.4 2021/12/19 12:21:29 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2017 Advanced Micro Devices, Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad #ifndef __AMDGPU_GART_H__ 27 1.1 riastrad #define __AMDGPU_GART_H__ 28 1.1 riastrad 29 1.1 riastrad #include <linux/types.h> 30 1.1 riastrad 31 1.1 riastrad /* 32 1.1 riastrad * GART structures, functions & helpers 33 1.1 riastrad */ 34 1.1 riastrad struct amdgpu_device; 35 1.1 riastrad struct amdgpu_bo; 36 1.1 riastrad 37 1.1 riastrad #define AMDGPU_GPU_PAGE_SIZE 4096 38 1.1 riastrad #define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1) 39 1.1 riastrad #define AMDGPU_GPU_PAGE_SHIFT 12 40 1.1 riastrad #define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK) 41 1.1 riastrad 42 1.1 riastrad #define AMDGPU_GPU_PAGES_IN_CPU_PAGE (PAGE_SIZE / AMDGPU_GPU_PAGE_SIZE) 43 1.1 riastrad 44 1.1 riastrad struct amdgpu_gart { 45 1.3 riastrad #ifdef __NetBSD__ 46 1.3 riastrad bus_dma_segment_t ag_table_seg; 47 1.3 riastrad bus_dmamap_t ag_table_map; 48 1.3 riastrad #endif 49 1.1 riastrad struct amdgpu_bo *bo; 50 1.1 riastrad /* CPU kmapped address of gart table */ 51 1.1 riastrad void *ptr; 52 1.1 riastrad unsigned num_gpu_pages; 53 1.1 riastrad unsigned num_cpu_pages; 54 1.1 riastrad unsigned table_size; 55 1.1 riastrad #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS 56 1.1 riastrad struct page **pages; 57 1.1 riastrad #endif 58 1.1 riastrad bool ready; 59 1.1 riastrad 60 1.1 riastrad /* Asic default pte flags */ 61 1.1 riastrad uint64_t gart_pte_flags; 62 1.1 riastrad }; 63 1.1 riastrad 64 1.1 riastrad int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev); 65 1.1 riastrad void amdgpu_gart_table_vram_free(struct amdgpu_device *adev); 66 1.1 riastrad int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev); 67 1.1 riastrad void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev); 68 1.1 riastrad int amdgpu_gart_init(struct amdgpu_device *adev); 69 1.1 riastrad void amdgpu_gart_fini(struct amdgpu_device *adev); 70 1.2 riastrad #ifdef __NetBSD__ 71 1.4 riastrad int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t gpu_start, 72 1.2 riastrad unsigned npages); 73 1.4 riastrad int amdgpu_gart_map(struct amdgpu_device *adev, uint64_t gpu_start, 74 1.4 riastrad unsigned npages, bus_size_t map_start, bus_dmamap_t map, uint32_t flags, 75 1.4 riastrad void *dst); 76 1.2 riastrad int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t gpu_start, 77 1.2 riastrad unsigned npages, struct page **pagelist, bus_dmamap_t dmamap, 78 1.2 riastrad uint32_t flags); 79 1.2 riastrad #else 80 1.1 riastrad int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset, 81 1.1 riastrad int pages); 82 1.1 riastrad int amdgpu_gart_map(struct amdgpu_device *adev, uint64_t offset, 83 1.1 riastrad int pages, dma_addr_t *dma_addr, uint64_t flags, 84 1.1 riastrad void *dst); 85 1.1 riastrad int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset, 86 1.1 riastrad int pages, struct page **pagelist, 87 1.1 riastrad dma_addr_t *dma_addr, uint64_t flags); 88 1.2 riastrad #endif 89 1.1 riastrad 90 1.1 riastrad #endif 91