1 /* 2 * Copyright (c) 2018 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #ifndef INTEL_AUX_MAP_H 25 #define INTEL_AUX_MAP_H 26 27 #include "intel_buffer_alloc.h" 28 29 #include "isl/isl.h" 30 31 #include <stdint.h> 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /** 38 * Auxiliary surface mapping implementation 39 * 40 * These functions are implemented in common code shared by drivers. 41 */ 42 43 struct intel_aux_map_context; 44 struct intel_device_info; 45 46 #define INTEL_AUX_MAP_ENTRY_VALID_BIT 0x1ull 47 48 struct intel_aux_map_context * 49 intel_aux_map_init(void *driver_ctx, 50 struct intel_mapped_pinned_buffer_alloc *buffer_alloc, 51 const struct intel_device_info *devinfo); 52 53 uint32_t 54 intel_aux_map_get_alignment(struct intel_aux_map_context *ctx); 55 56 void 57 intel_aux_map_finish(struct intel_aux_map_context *ctx); 58 59 uint32_t 60 intel_aux_map_get_state_num(struct intel_aux_map_context *ctx); 61 62 /** 63 * Returns the current number of buffers used by the aux-map tables 64 * 65 * When preparing to execute a new batch, use this function to determine how 66 * many buffers will be required. More buffers may be added by concurrent 67 * accesses of the aux-map functions, but they won't be required for since 68 * they involve surfaces not used by this batch. 69 */ 70 uint32_t 71 intel_aux_map_get_num_buffers(struct intel_aux_map_context *ctx); 72 73 /** 74 * Returns the mask of meta data address in L1 entry 75 * 76 * The mask value is effected by page size of meta data specific to a platform. 77 */ 78 uint64_t 79 intel_aux_get_meta_address_mask(struct intel_aux_map_context *ctx); 80 81 /** 82 * Returns the ratio between the granularity of main surface and AUX data 83 */ 84 uint64_t 85 intel_aux_get_main_to_aux_ratio(struct intel_aux_map_context *ctx); 86 87 /** 88 * Takes a relative offset in the main surface and returns a relative offset 89 * in the aux surface that maps to the main offset. 90 */ 91 uint64_t 92 intel_aux_main_to_aux_offset(struct intel_aux_map_context *ctx, 93 uint64_t main_offset); 94 95 /** 96 * Fill an array of exec_object2 with aux-map buffer handles 97 * 98 * The intel_aux_map_get_num_buffers call should be made, then the driver can 99 * make sure the `obj` array is large enough before calling this function. 100 */ 101 void 102 intel_aux_map_fill_bos(struct intel_aux_map_context *ctx, void **driver_bos, 103 uint32_t max_bos); 104 105 uint64_t 106 intel_aux_map_get_base(struct intel_aux_map_context *ctx); 107 108 uint64_t 109 intel_aux_map_format_bits(enum isl_tiling tiling, enum isl_format format, 110 uint8_t plane); 111 112 uint64_t 113 intel_aux_map_format_bits_for_isl_surf(const struct isl_surf *isl_surf); 114 115 uint64_t * 116 intel_aux_map_get_entry(struct intel_aux_map_context *ctx, 117 uint64_t main_address, 118 uint64_t *aux_entry_address); 119 120 /* Fails if a mapping is attempted that would conflict with an existing one. 121 * This increase the refcount of the mapped region if already mapped, sets it 122 * to 1 otherwise. 123 */ 124 bool 125 intel_aux_map_add_mapping(struct intel_aux_map_context *ctx, uint64_t main_address, 126 uint64_t aux_address, uint64_t main_size_B, 127 uint64_t format_bits); 128 129 /* Decrease the refcount of a mapped region. When the refcount reaches 0, the 130 * region is unmapped. 131 */ 132 void 133 intel_aux_map_del_mapping(struct intel_aux_map_context *ctx, uint64_t main_address, 134 uint64_t size); 135 136 /* Unmaps a region, refcount is reset to 0. 137 */ 138 void 139 intel_aux_map_unmap_range(struct intel_aux_map_context *ctx, uint64_t main_address, 140 uint64_t size); 141 142 #ifdef __cplusplus 143 } 144 #endif 145 146 #endif /* INTEL_AUX_MAP_H */ 147