Initial version of libomxil-vc4 for RPI3
[platform/adaptation/broadcom/libomxil-vc4.git] / middleware / khronos / common / khrn_hw.h
1 /*
2 Copyright (c) 2012, Broadcom Europe Ltd
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in the
11       documentation and/or other materials provided with the distribution.
12     * Neither the name of the copyright holder nor the
13       names of its contributors may be used to endorse or promote products
14       derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef KHRN_HW_H
29 #define KHRN_HW_H
30
31 #include "interface/khronos/common/khrn_int_common.h"
32 #include "middleware/khronos/common/khrn_image.h"
33 #include "middleware/khronos/egl/egl_disp.h"
34 #include "interface/khronos/include/EGL/egl.h"
35 #include "interface/khronos/include/EGL/eglext.h"
36 #include "interface/vcos/vcos.h"
37
38 bool khrn_hw_common_init(void);
39 void khrn_hw_common_term(void);
40
41 void khrn_delayed_display(KHRN_IMAGE_T *image, EGL_DISP_SLOT_HANDLE_T slot_handle);
42 void khrn_delayed_wait_for_display(uint32_t fifo, EGL_DISP_HANDLE_T disp_handle, uint32_t pos);
43 void khrn_delayed_copy_buffer(MEM_HANDLE_T dst_handle, MEM_HANDLE_T src_handle);
44
45 bool khrn_hw_supports_early_z(void);
46
47 /* flush all queued stuff */
48 extern void khrn_hw_common_flush(void);
49
50 /* wait for all flushed stuff to finish */
51 extern void khrn_hw_common_wait(void);
52
53 /*
54    void khrn_hw_common_finish()
55
56    Flush all queued stuff. Wait for all flushed stuff to finish.
57
58    Preconditions:
59
60    -
61
62    Postcondtions:
63
64    For all KHRN_IMAGE_T image:
65       image.conceptual_readable_by_master is true
66       image.conceptual_writeable_by_master is true
67    conceptual_buffers_owned_by_master is true
68    conceptual_programs_owned_by_master is true
69 */
70
71 static INLINE void khrn_hw_common_finish(void)
72 {
73    khrn_hw_common_flush();
74    khrn_hw_common_wait();
75 }
76
77 extern void khrn_sync_init(void);
78 extern void khrn_sync_notify_master(void);
79 extern void khrn_sync_master_wait(void);
80 #ifdef KHRN_BCG_WAIT_TIMEOUT
81 extern bool khrn_sync_master_wait_timeout(unsigned int t);
82 #endif
83 extern void khrn_sync_display_returned_notify(void); /* called when something comes off the display */
84 extern void khrn_specify_event(VCOS_EVENT_T *ev);
85 extern int32_t khrn_do_suspend_resume(uint32_t up);
86
87 typedef void KHRN_SYNC_MASTER_WAIT_FUNC(void);
88 typedef void KHRN_SPECIFY_EVENT_FUNC(VCOS_EVENT_T *ev);
89 typedef int32_t KHRN_DO_SUSPEND_RESUME_FUNC(uint32_t up);
90
91 typedef struct {
92    uint32_t acquire;
93    uint32_t release;
94 } KHRN_CACHE_COUNTERS_T;
95
96 extern void khrn_memcpy(void *dest, const void *src, uint32_t size);
97 extern void khrn_memset(void *dest, uint32_t val, uint32_t size);
98
99 typedef struct {
100    /*
101       primitive counters
102    */
103
104    uint32_t fovcull;
105    uint32_t fovclip;
106    uint32_t revcull;
107    uint32_t nofepix;
108
109    /*
110       texture units
111    */
112
113    uint32_t tu0access;
114    uint32_t tu0miss;
115    uint32_t tu1access;
116    uint32_t tu1miss;
117
118    /*
119       backend
120    */
121
122    uint32_t dpthfail;
123    uint32_t stclfail;
124    uint32_t dpthstclpass;
125 } KHRN_PERF_COUNTERS_T;
126
127 typedef struct {
128    uint64_t qpu_cycles_idle;
129    uint64_t qpu_cycles_vert_shade;
130    uint64_t qpu_cycles_frag_shade;
131    uint64_t qpu_cycles_exe_valid;
132    uint64_t qpu_cycles_wait_tmu;
133    uint64_t qpu_cycles_wait_scb;
134    uint64_t qpu_cycles_wait_vary;
135    uint64_t qpu_icache_hits;
136    uint64_t qpu_icache_miss;
137    uint64_t qpu_ucache_hits;
138    uint64_t qpu_ucache_miss;
139
140    uint64_t tmu_total_quads;
141    uint64_t tmu_cache_miss;
142
143    uint64_t l2c_hits;
144    uint64_t l2c_miss;
145 } KHRN_DRIVER_HW_COUNTERS0_T;
146
147 typedef struct {
148    uint64_t fep_valid_prims;
149    uint64_t fep_valid_prims_no_pixels;
150    uint64_t fep_earlyz_clipped_quads;
151    uint64_t fep_valid_quads;
152
153    uint64_t tlb_quads_no_stencil_pass_pixels;
154    uint64_t tlb_quads_no_z_stencil_pass_pixels;
155    uint64_t tlb_quads_z_stencil_pass_pixels;
156    uint64_t tlb_quads_all_pixels_zero_cvg;
157    uint64_t tlb_quads_all_pixels_nonzero_cvg;
158    uint64_t tlb_quads_valid_pixels_written;
159
160    uint64_t ptb_prims_viewport_discarded;
161    uint64_t ptb_prims_needing_clip;
162
163    uint64_t pse_prims_reverse_discarded;
164
165    uint64_t vpm_cycles_vdw_stalled;
166    uint64_t vpm_cycles_vcd_stalled;
167 } KHRN_DRIVER_HW_COUNTERS1_T;
168
169 typedef struct {
170    uint32_t hard_clears;
171    uint32_t soft_clears;
172    uint32_t tb_grp_color_loads;
173    uint32_t tb_grp_ms_color_loads;
174    uint32_t tb_grp_ds_loads;
175    uint32_t tb_grp_color_stores;
176    uint32_t tb_grp_ms_color_stores;
177    uint32_t tb_grp_ds_stores;
178    uint32_t tb_color_loads;
179    uint32_t tb_ms_color_loads;
180    uint32_t tb_ds_loads;
181    uint32_t tb_color_stores;
182    uint32_t tb_ms_color_stores;
183    uint32_t tb_ds_stores;
184    uint32_t tex_submissions;
185    uint32_t tex_fast_paths;
186    uint32_t mipmap_gens;
187    uint32_t mipmap_gens_fast;
188    uint32_t draw_calls;
189    uint32_t num_swaps;
190
191    uint32_t hw_group_active;
192
193 #ifdef __linux__
194    uint32_t reset_time;       /* time in ms when the statistics were last reset */
195    uint32_t in_time;          /* time at which acquire happened */
196    uint32_t total_time;       /* total of all (release time - acquire time) */
197
198    uint32_t last_cpu_time;
199    uint32_t last_cpu_ticks;
200 #endif
201
202    union
203    {
204       KHRN_DRIVER_HW_COUNTERS0_T hw_0;
205       KHRN_DRIVER_HW_COUNTERS1_T hw_1;
206    } hw;
207
208    uint32_t l3c_group_active;
209    union
210    {
211       uint64_t l3c_read_bw_0;
212       uint64_t l3c_write_bw_1;
213    } l3c;
214    union
215    {
216       uint64_t l3c_mem_read_bw_0;
217       uint64_t l3c_mem_write_bw_1;
218    } l3c_mem;
219
220 } KHRN_DRIVER_COUNTERS_T;
221
222 extern void khrn_hw_register_perf_counters(KHRN_DRIVER_COUNTERS_T *counters);
223 extern void khrn_hw_unregister_perf_counters(void);
224 extern void khrn_reset_driver_counters(int32_t hw_bank, int32_t l3c_bank);
225
226 extern KHRN_DRIVER_COUNTERS_T *khrn_driver_counters(void);
227
228 #if EGL_BRCM_driver_monitor
229 #define INCR_DRIVER_COUNTER(counter) khrn_driver_counters()->counter++;
230 #else
231 #define INCR_DRIVER_COUNTER(counter) ;
232 #endif
233
234 extern void khrn_hw_kick(void);
235
236 #endif