xref: /aosp_15_r20/external/mesa3d/src/intel/common/intel_aux_map.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 /**
49  * The ratio between the granularity of main surface pitch and AUX data pitch
50  * (when viewed as a surface).
51  *
52  * In agreement with Bspec 44930, the kernel expects that every 512B of the
53  * main surface pitch maps to 64B of the AUX data pitch. This is not
54  * documented in drm_fourcc.h.
55  */
56 #define INTEL_AUX_MAP_MAIN_PITCH_SCALEDOWN (512 / 64)
57 
58 /**
59  * The ratio between the granularity of main surface and AUX data.
60  *
61  * The value is from Bspec 47709, MCS/CCS Buffers for Render Target(s):
62  *
63  *    "CCS is a linear buffer created for storing meta-data (AUX data) for
64  *    lossless compression. This buffer related information is mentioned in
65  *    Render Surface State. CCS buffer's size is based on the padded main
66  *    surface (after following Halign and Valign requirements mentioned in the
67  *    Render Surface State). CCS_Buffer_Size = Padded_Main_Surface_Size/256"
68  *
69  * The aux-map only exists on Xe, so this is equivalent to
70  * ISL_MAIN_TO_CCS_SIZE_RATIO_XE.
71  */
72 #define INTEL_AUX_MAP_MAIN_SIZE_SCALEDOWN 256
73 
74 /**
75  * The alignment at which the AUX data virtual addresses should start.
76  *
77  * The diagram in Bspec 44930 shows that the CCS is indexed in 256B chunks for
78  * TGL, 4K chunks for MTL. However, when modifiers are in use, the 4K
79  * alignment requirement of the PLANE_AUX_DIST::Auxiliary Surface Distance
80  * field must be considered (Bspec 50379). Keep things simple and just use 4K.
81  */
82 #define INTEL_AUX_MAP_META_ALIGNMENT_B 4096
83 
84 struct intel_aux_map_context *
85 intel_aux_map_init(void *driver_ctx,
86                    struct intel_mapped_pinned_buffer_alloc *buffer_alloc,
87                    const struct intel_device_info *devinfo);
88 
89 uint32_t
90 intel_aux_map_get_alignment(struct intel_aux_map_context *ctx);
91 
92 void
93 intel_aux_map_finish(struct intel_aux_map_context *ctx);
94 
95 uint32_t
96 intel_aux_map_get_state_num(struct intel_aux_map_context *ctx);
97 
98 /**
99  * Returns the current number of buffers used by the aux-map tables
100  *
101  * When preparing to execute a new batch, use this function to determine how
102  * many buffers will be required. More buffers may be added by concurrent
103  * accesses of the aux-map functions, but they won't be required for since
104  * they involve surfaces not used by this batch.
105  */
106 uint32_t
107 intel_aux_map_get_num_buffers(struct intel_aux_map_context *ctx);
108 
109 /**
110  * Returns the mask of meta data address in L1 entry
111  *
112  * The mask value is effected by page size of meta data specific to a platform.
113  */
114 uint64_t
115 intel_aux_get_meta_address_mask(struct intel_aux_map_context *ctx);
116 
117 /**
118  * Takes a relative offset in the main surface and returns a relative offset
119  * in the aux surface that maps to the main offset.
120  */
121 uint64_t
122 intel_aux_main_to_aux_offset(struct intel_aux_map_context *ctx,
123                              uint64_t main_offset);
124 
125 /**
126  * Fill an array of exec_object2 with aux-map buffer handles
127  *
128  * The intel_aux_map_get_num_buffers call should be made, then the driver can
129  * make sure the `obj` array is large enough before calling this function.
130  */
131 void
132 intel_aux_map_fill_bos(struct intel_aux_map_context *ctx, void **driver_bos,
133                        uint32_t max_bos);
134 
135 uint64_t
136 intel_aux_map_get_base(struct intel_aux_map_context *ctx);
137 
138 uint64_t
139 intel_aux_map_format_bits(enum isl_tiling tiling, enum isl_format format,
140                           uint8_t plane);
141 
142 uint64_t
143 intel_aux_map_format_bits_for_isl_surf(const struct isl_surf *isl_surf);
144 
145 uint64_t *
146 intel_aux_map_get_entry(struct intel_aux_map_context *ctx,
147                         uint64_t main_address,
148                         uint64_t *aux_entry_address);
149 
150 /* Fails if a mapping is attempted that would conflict with an existing one.
151  * This increase the refcount of the mapped region if already mapped, sets it
152  * to 1 otherwise.
153  */
154 bool
155 intel_aux_map_add_mapping(struct intel_aux_map_context *ctx, uint64_t main_address,
156                           uint64_t aux_address, uint64_t main_size_B,
157                           uint64_t format_bits);
158 
159 /* Decrease the refcount of a mapped region. When the refcount reaches 0, the
160  * region is unmapped.
161  */
162 void
163 intel_aux_map_del_mapping(struct intel_aux_map_context *ctx, uint64_t main_address,
164                           uint64_t size);
165 
166 /* Unmaps a region, refcount is reset to 0.
167  */
168 void
169 intel_aux_map_unmap_range(struct intel_aux_map_context *ctx, uint64_t main_address,
170                           uint64_t size);
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* INTEL_AUX_MAP_H */
177