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 GEN_AUX_MAP_H
25 #define GEN_AUX_MAP_H
26 
27 #include "gen_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 gen_aux_map_context;
44 struct gen_device_info;
45 
46 #define GEN_AUX_MAP_ADDRESS_MASK       0x0000ffffffffff00ull
47 #define GEN_AUX_MAP_FORMAT_BITS_MASK   0xfff0000000000000ull
48 #define GEN_AUX_MAP_ENTRY_VALID_BIT    0x1ull
49 #define GEN_AUX_MAP_GEN12_CCS_SCALE    256
50 #define GEN_AUX_MAP_MAIN_PAGE_SIZE     (64 * 1024)
51 #define GEN_AUX_MAP_AUX_PAGE_SIZE \
52    (GEN_AUX_MAP_MAIN_PAGE_SIZE / GEN_AUX_MAP_GEN12_CCS_SCALE)
53 
54 struct gen_aux_map_context *
55 gen_aux_map_init(void *driver_ctx,
56                  struct gen_mapped_pinned_buffer_alloc *buffer_alloc,
57                  const struct gen_device_info *devinfo);
58 
59 void
60 gen_aux_map_finish(struct gen_aux_map_context *ctx);
61 
62 uint32_t
63 gen_aux_map_get_state_num(struct gen_aux_map_context *ctx);
64 
65 /** Returns the current number of buffers used by the aux-map tables
66  *
67  * When preparing to execute a new batch, use this function to determine how
68  * many buffers will be required. More buffers may be added by concurrent
69  * accesses of the aux-map functions, but they won't be required for since
70  * they involve surfaces not used by this batch.
71  */
72 uint32_t
73 gen_aux_map_get_num_buffers(struct gen_aux_map_context *ctx);
74 
75 /** Fill an array of exec_object2 with aux-map buffer handles
76  *
77  * The gen_aux_map_get_num_buffers call should be made, then the driver can
78  * make sure the `obj` array is large enough before calling this function.
79  */
80 void
81 gen_aux_map_fill_bos(struct gen_aux_map_context *ctx, void **driver_bos,
82                      uint32_t max_bos);
83 
84 uint64_t
85 gen_aux_map_get_base(struct gen_aux_map_context *ctx);
86 
87 uint64_t
88 gen_aux_map_format_bits(enum isl_tiling tiling, enum isl_format format,
89                         uint8_t plane);
90 
91 uint64_t
92 gen_aux_map_format_bits_for_isl_surf(const struct isl_surf *isl_surf);
93 
94 uint64_t *
95 gen_aux_map_get_entry(struct gen_aux_map_context *ctx,
96                       uint64_t address,
97                       uint64_t *entry_address);
98 
99 void
100 gen_aux_map_add_mapping(struct gen_aux_map_context *ctx, uint64_t address,
101                         uint64_t aux_address, uint64_t main_size_B,
102                         uint64_t format_bits);
103 
104 void
105 gen_aux_map_unmap_range(struct gen_aux_map_context *ctx, uint64_t address,
106                         uint64_t size);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* GEN_AUX_MAP_H */
113