1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2014-2017 Broadcom
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef V3D_SCREEN_H
25bf215546Sopenharmony_ci#define V3D_SCREEN_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "pipe/p_screen.h"
28bf215546Sopenharmony_ci#include "renderonly/renderonly.h"
29bf215546Sopenharmony_ci#include "os/os_thread.h"
30bf215546Sopenharmony_ci#include "frontend/drm_driver.h"
31bf215546Sopenharmony_ci#include "util/disk_cache.h"
32bf215546Sopenharmony_ci#include "util/list.h"
33bf215546Sopenharmony_ci#include "util/slab.h"
34bf215546Sopenharmony_ci#include "broadcom/common/v3d_debug.h"
35bf215546Sopenharmony_ci#include "broadcom/common/v3d_device_info.h"
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistruct v3d_bo;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci/* These are tunable parameters in the HW design, but all the V3D
40bf215546Sopenharmony_ci * implementations agree.
41bf215546Sopenharmony_ci */
42bf215546Sopenharmony_ci#define V3D_UIFCFG_BANKS 8
43bf215546Sopenharmony_ci#define V3D_UIFCFG_PAGE_SIZE 4096
44bf215546Sopenharmony_ci#define V3D_UIFCFG_XOR_VALUE (1 << 4)
45bf215546Sopenharmony_ci#define V3D_PAGE_CACHE_SIZE (V3D_UIFCFG_PAGE_SIZE * V3D_UIFCFG_BANKS)
46bf215546Sopenharmony_ci#define V3D_UBLOCK_SIZE 64
47bf215546Sopenharmony_ci#define V3D_UIFBLOCK_SIZE (4 * V3D_UBLOCK_SIZE)
48bf215546Sopenharmony_ci#define V3D_UIFBLOCK_ROW_SIZE (4 * V3D_UIFBLOCK_SIZE)
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistruct v3d_simulator_file;
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_cistruct v3d_screen {
53bf215546Sopenharmony_ci        struct pipe_screen base;
54bf215546Sopenharmony_ci        struct renderonly *ro;
55bf215546Sopenharmony_ci        int fd;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci        struct v3d_device_info devinfo;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci        const char *name;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci        struct slab_parent_pool transfer_pool;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci        struct v3d_bo_cache {
64bf215546Sopenharmony_ci                /** List of struct v3d_bo freed, by age. */
65bf215546Sopenharmony_ci                struct list_head time_list;
66bf215546Sopenharmony_ci                /** List of struct v3d_bo freed, per size, by age. */
67bf215546Sopenharmony_ci                struct list_head *size_list;
68bf215546Sopenharmony_ci                uint32_t size_list_size;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci                mtx_t lock;
71bf215546Sopenharmony_ci        } bo_cache;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci        const struct v3d_compiler *compiler;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci        struct hash_table *bo_handles;
76bf215546Sopenharmony_ci        mtx_t bo_handles_mutex;
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci        uint32_t bo_size;
79bf215546Sopenharmony_ci        uint32_t bo_count;
80bf215546Sopenharmony_ci        uint32_t prim_types;
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci        bool has_csd;
83bf215546Sopenharmony_ci        bool has_cache_flush;
84bf215546Sopenharmony_ci        bool has_perfmon;
85bf215546Sopenharmony_ci        bool nonmsaa_texture_size_limit;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci        struct v3d_simulator_file *sim_file;
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci#ifdef ENABLE_SHADER_CACHE
90bf215546Sopenharmony_ci        struct disk_cache *disk_cache;
91bf215546Sopenharmony_ci#endif
92bf215546Sopenharmony_ci};
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_cistatic inline struct v3d_screen *
95bf215546Sopenharmony_civ3d_screen(struct pipe_screen *screen)
96bf215546Sopenharmony_ci{
97bf215546Sopenharmony_ci        return (struct v3d_screen *)screen;
98bf215546Sopenharmony_ci}
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_cistruct pipe_screen *v3d_screen_create(int fd,
101bf215546Sopenharmony_ci                                      const struct pipe_screen_config *config,
102bf215546Sopenharmony_ci                                      struct renderonly *ro);
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_civoid
105bf215546Sopenharmony_civ3d_fence_init(struct v3d_screen *screen);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci#ifdef ENABLE_SHADER_CACHE
108bf215546Sopenharmony_civoid
109bf215546Sopenharmony_civ3d_disk_cache_init(struct v3d_screen *screen);
110bf215546Sopenharmony_ci#endif
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci#endif /* V3D_SCREEN_H */
113