1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright (C) 2019 Collabora, Ltd.
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 FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci * Authors:
24bf215546Sopenharmony_ci *   Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
25bf215546Sopenharmony_ci */
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <xf86drm.h>
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include "util/u_math.h"
30bf215546Sopenharmony_ci#include "util/macros.h"
31bf215546Sopenharmony_ci#include "util/hash_table.h"
32bf215546Sopenharmony_ci#include "util/u_thread.h"
33bf215546Sopenharmony_ci#include "drm-uapi/panfrost_drm.h"
34bf215546Sopenharmony_ci#include "pan_encoder.h"
35bf215546Sopenharmony_ci#include "pan_device.h"
36bf215546Sopenharmony_ci#include "pan_bo.h"
37bf215546Sopenharmony_ci#include "pan_texture.h"
38bf215546Sopenharmony_ci#include "wrap.h"
39bf215546Sopenharmony_ci#include "pan_util.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci/* Fixed "minimum revisions" */
42bf215546Sopenharmony_ci#define NO_ANISO (~0)
43bf215546Sopenharmony_ci#define HAS_ANISO (0)
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci#define MODEL(gpu_id_, shortname, counters_, min_rev_anisotropic_, tib_size_, quirks_) \
46bf215546Sopenharmony_ci        { \
47bf215546Sopenharmony_ci                .gpu_id = gpu_id_, \
48bf215546Sopenharmony_ci                .name = "Mali-" shortname " (Panfrost)", \
49bf215546Sopenharmony_ci                .performance_counters = counters_, \
50bf215546Sopenharmony_ci                .min_rev_anisotropic = min_rev_anisotropic_, \
51bf215546Sopenharmony_ci                .tilebuffer_size = tib_size_, \
52bf215546Sopenharmony_ci                .quirks = quirks_, \
53bf215546Sopenharmony_ci        }
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci/* Table of supported Mali GPUs */
56bf215546Sopenharmony_ciconst struct panfrost_model panfrost_model_list[] = {
57bf215546Sopenharmony_ci        MODEL(0x720, "T720", "T72x", NO_ANISO, 8192, { .no_hierarchical_tiling = true }),
58bf215546Sopenharmony_ci        MODEL(0x750, "T760", "T76x", NO_ANISO, 8192, {}),
59bf215546Sopenharmony_ci        MODEL(0x820, "T820", "T82x", NO_ANISO, 8192, { .no_hierarchical_tiling = true }),
60bf215546Sopenharmony_ci        MODEL(0x830, "T830", "T83x", NO_ANISO, 8192, { .no_hierarchical_tiling = true }),
61bf215546Sopenharmony_ci        MODEL(0x860, "T860", "T86x", NO_ANISO, 8192, {}),
62bf215546Sopenharmony_ci        MODEL(0x880, "T880", "T88x", NO_ANISO, 8192, {}),
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci        MODEL(0x6000, "G71", "TMIx", NO_ANISO, 8192, {}),
65bf215546Sopenharmony_ci        MODEL(0x6221, "G72", "THEx", 0x0030 /* r0p3 */, 16384, {}),
66bf215546Sopenharmony_ci        MODEL(0x7090, "G51", "TSIx", 0x1010 /* r1p1 */, 16384, {}),
67bf215546Sopenharmony_ci        MODEL(0x7093, "G31", "TDVx", HAS_ANISO, 16384, {}),
68bf215546Sopenharmony_ci        MODEL(0x7211, "G76", "TNOx", HAS_ANISO, 16384, {}),
69bf215546Sopenharmony_ci        MODEL(0x7212, "G52", "TGOx", HAS_ANISO, 16384, {}),
70bf215546Sopenharmony_ci        MODEL(0x7402, "G52 r1", "TGOx", HAS_ANISO, 16384, {}),
71bf215546Sopenharmony_ci        MODEL(0x9093, "G57", "TNAx", HAS_ANISO, 16384, {}),
72bf215546Sopenharmony_ci};
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci#undef NO_ANISO
75bf215546Sopenharmony_ci#undef HAS_ANISO
76bf215546Sopenharmony_ci#undef MODEL
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci/*
79bf215546Sopenharmony_ci * Look up a supported model by its GPU ID, or return NULL if the model is not
80bf215546Sopenharmony_ci * supported at this time.
81bf215546Sopenharmony_ci */
82bf215546Sopenharmony_ciconst struct panfrost_model *
83bf215546Sopenharmony_cipanfrost_get_model(uint32_t gpu_id)
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci        for (unsigned i = 0; i < ARRAY_SIZE(panfrost_model_list); ++i) {
86bf215546Sopenharmony_ci                if (panfrost_model_list[i].gpu_id == gpu_id)
87bf215546Sopenharmony_ci                        return &panfrost_model_list[i];
88bf215546Sopenharmony_ci        }
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci        return NULL;
91bf215546Sopenharmony_ci}
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci/* Abstraction over the raw drm_panfrost_get_param ioctl for fetching
94bf215546Sopenharmony_ci * information about devices */
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_cistatic __u64
97bf215546Sopenharmony_cipanfrost_query_raw(
98bf215546Sopenharmony_ci                int fd,
99bf215546Sopenharmony_ci                enum drm_panfrost_param param,
100bf215546Sopenharmony_ci                bool required,
101bf215546Sopenharmony_ci                unsigned default_value)
102bf215546Sopenharmony_ci{
103bf215546Sopenharmony_ci        struct drm_panfrost_get_param get_param = {0,};
104bf215546Sopenharmony_ci        ASSERTED int ret;
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci        get_param.param = param;
107bf215546Sopenharmony_ci        ret = drmIoctl(fd, DRM_IOCTL_PANFROST_GET_PARAM, &get_param);
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci        if (ret) {
110bf215546Sopenharmony_ci                assert(!required);
111bf215546Sopenharmony_ci                return default_value;
112bf215546Sopenharmony_ci        }
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci        return get_param.value;
115bf215546Sopenharmony_ci}
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_cistatic unsigned
118bf215546Sopenharmony_cipanfrost_query_gpu_version(int fd)
119bf215546Sopenharmony_ci{
120bf215546Sopenharmony_ci        return panfrost_query_raw(fd, DRM_PANFROST_PARAM_GPU_PROD_ID, true, 0);
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistatic unsigned
124bf215546Sopenharmony_cipanfrost_query_gpu_revision(int fd)
125bf215546Sopenharmony_ci{
126bf215546Sopenharmony_ci        return panfrost_query_raw(fd, DRM_PANFROST_PARAM_GPU_REVISION, true, 0);
127bf215546Sopenharmony_ci}
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ciunsigned
130bf215546Sopenharmony_cipanfrost_query_l2_slices(const struct panfrost_device *dev)
131bf215546Sopenharmony_ci{
132bf215546Sopenharmony_ci        /* Query MEM_FEATURES register */
133bf215546Sopenharmony_ci        uint32_t mem_features =
134bf215546Sopenharmony_ci                panfrost_query_raw(dev->fd, DRM_PANFROST_PARAM_MEM_FEATURES,
135bf215546Sopenharmony_ci                                   true, 0);
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci        /* L2_SLICES is MEM_FEATURES[11:8] minus(1) */
138bf215546Sopenharmony_ci        return ((mem_features >> 8) & 0xF) + 1;
139bf215546Sopenharmony_ci}
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_cistatic struct panfrost_tiler_features
142bf215546Sopenharmony_cipanfrost_query_tiler_features(int fd)
143bf215546Sopenharmony_ci{
144bf215546Sopenharmony_ci        /* Default value (2^9 bytes and 8 levels) to match old behaviour */
145bf215546Sopenharmony_ci        uint32_t raw = panfrost_query_raw(fd, DRM_PANFROST_PARAM_TILER_FEATURES,
146bf215546Sopenharmony_ci                        false, 0x809);
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci        /* Bin size is log2 in the first byte, max levels in the second byte */
149bf215546Sopenharmony_ci        return (struct panfrost_tiler_features) {
150bf215546Sopenharmony_ci                .bin_size = (1 << (raw & BITFIELD_MASK(5))),
151bf215546Sopenharmony_ci                .max_levels = (raw >> 8) & BITFIELD_MASK(4)
152bf215546Sopenharmony_ci        };
153bf215546Sopenharmony_ci}
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_cistatic unsigned
156bf215546Sopenharmony_cipanfrost_query_core_count(int fd, unsigned *core_id_range)
157bf215546Sopenharmony_ci{
158bf215546Sopenharmony_ci        /* On older kernels, worst-case to 16 cores */
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci        unsigned mask = panfrost_query_raw(fd,
161bf215546Sopenharmony_ci                        DRM_PANFROST_PARAM_SHADER_PRESENT, false, 0xffff);
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci        /* Some cores might be absent. In some cases, we care
164bf215546Sopenharmony_ci         * about the range of core IDs (that is, the greatest core ID + 1). If
165bf215546Sopenharmony_ci         * the core mask is contiguous, this equals the core count.
166bf215546Sopenharmony_ci         */
167bf215546Sopenharmony_ci        *core_id_range = util_last_bit(mask);
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ci        /* The actual core count skips overs the gaps */
170bf215546Sopenharmony_ci        return util_bitcount(mask);
171bf215546Sopenharmony_ci}
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci/* Architectural maximums, since this register may be not implemented
174bf215546Sopenharmony_ci * by a given chip. G31 is actually 512 instead of 768 but it doesn't
175bf215546Sopenharmony_ci * really matter. */
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_cistatic unsigned
178bf215546Sopenharmony_cipanfrost_max_thread_count(unsigned arch)
179bf215546Sopenharmony_ci{
180bf215546Sopenharmony_ci        switch (arch) {
181bf215546Sopenharmony_ci        /* Midgard */
182bf215546Sopenharmony_ci        case 4:
183bf215546Sopenharmony_ci        case 5:
184bf215546Sopenharmony_ci                return 256;
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_ci        /* Bifrost, first generation */
187bf215546Sopenharmony_ci        case 6:
188bf215546Sopenharmony_ci                return 384;
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci        /* Bifrost, second generation (G31 is 512 but it doesn't matter) */
191bf215546Sopenharmony_ci        case 7:
192bf215546Sopenharmony_ci                return 768;
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci        /* Valhall (for completeness) */
195bf215546Sopenharmony_ci        default:
196bf215546Sopenharmony_ci                return 1024;
197bf215546Sopenharmony_ci        }
198bf215546Sopenharmony_ci}
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_cistatic unsigned
201bf215546Sopenharmony_cipanfrost_query_thread_tls_alloc(int fd, unsigned major)
202bf215546Sopenharmony_ci{
203bf215546Sopenharmony_ci        unsigned tls = panfrost_query_raw(fd,
204bf215546Sopenharmony_ci                        DRM_PANFROST_PARAM_THREAD_TLS_ALLOC, false, 0);
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci        return (tls > 0) ? tls : panfrost_max_thread_count(major);
207bf215546Sopenharmony_ci}
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_cistatic uint32_t
210bf215546Sopenharmony_cipanfrost_query_compressed_formats(int fd)
211bf215546Sopenharmony_ci{
212bf215546Sopenharmony_ci        /* If unspecified, assume ASTC/ETC only. Factory default for Juno, and
213bf215546Sopenharmony_ci         * should exist on any Mali configuration. All hardware should report
214bf215546Sopenharmony_ci         * these texture formats but the kernel might not be new enough. */
215bf215546Sopenharmony_ci
216bf215546Sopenharmony_ci        uint32_t default_set =
217bf215546Sopenharmony_ci                (1 << MALI_ETC2_RGB8) |
218bf215546Sopenharmony_ci                (1 << MALI_ETC2_R11_UNORM) |
219bf215546Sopenharmony_ci                (1 << MALI_ETC2_RGBA8) |
220bf215546Sopenharmony_ci                (1 << MALI_ETC2_RG11_UNORM) |
221bf215546Sopenharmony_ci                (1 << MALI_ETC2_R11_SNORM) |
222bf215546Sopenharmony_ci                (1 << MALI_ETC2_RG11_SNORM) |
223bf215546Sopenharmony_ci                (1 << MALI_ETC2_RGB8A1) |
224bf215546Sopenharmony_ci                (1 << MALI_ASTC_3D_LDR) |
225bf215546Sopenharmony_ci                (1 << MALI_ASTC_3D_HDR) |
226bf215546Sopenharmony_ci                (1 << MALI_ASTC_2D_LDR) |
227bf215546Sopenharmony_ci                (1 << MALI_ASTC_2D_HDR);
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci        return panfrost_query_raw(fd, DRM_PANFROST_PARAM_TEXTURE_FEATURES0,
230bf215546Sopenharmony_ci                        false, default_set);
231bf215546Sopenharmony_ci}
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci/* DRM_PANFROST_PARAM_TEXTURE_FEATURES0 will return a bitmask of supported
234bf215546Sopenharmony_ci * compressed formats, so we offer a helper to test if a format is supported */
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_cibool
237bf215546Sopenharmony_cipanfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt)
238bf215546Sopenharmony_ci{
239bf215546Sopenharmony_ci        if (MALI_EXTRACT_TYPE(fmt) != MALI_FORMAT_COMPRESSED)
240bf215546Sopenharmony_ci                return true;
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci        unsigned idx = fmt & ~MALI_FORMAT_COMPRESSED;
243bf215546Sopenharmony_ci        assert(idx < 32);
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci        return dev->compressed_formats & (1 << idx);
246bf215546Sopenharmony_ci}
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_ci/* Check for AFBC hardware support. AFBC is introduced in v5. Implementations
249bf215546Sopenharmony_ci * may omit it, signaled as a nonzero value in the AFBC_FEATURES property. */
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_cistatic bool
252bf215546Sopenharmony_cipanfrost_query_afbc(int fd, unsigned arch)
253bf215546Sopenharmony_ci{
254bf215546Sopenharmony_ci        unsigned reg = panfrost_query_raw(fd,
255bf215546Sopenharmony_ci                                          DRM_PANFROST_PARAM_AFBC_FEATURES,
256bf215546Sopenharmony_ci                                          false, 0);
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_ci        return (arch >= 5) && (reg == 0);
259bf215546Sopenharmony_ci}
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci/*
262bf215546Sopenharmony_ci * To pipeline multiple tiles, a given tile may use at most half of the tile
263bf215546Sopenharmony_ci * buffer. This function returns the optimal size (assuming pipelining).
264bf215546Sopenharmony_ci *
265bf215546Sopenharmony_ci * For Mali-G510 and Mali-G310, we will need extra logic to query the tilebuffer
266bf215546Sopenharmony_ci * size for the particular variant. The CORE_FEATURES register might help.
267bf215546Sopenharmony_ci */
268bf215546Sopenharmony_cistatic unsigned
269bf215546Sopenharmony_cipanfrost_query_optimal_tib_size(const struct panfrost_device *dev)
270bf215546Sopenharmony_ci{
271bf215546Sopenharmony_ci        /* Preconditions ensure the returned value is a multiple of 1 KiB, the
272bf215546Sopenharmony_ci         * granularity of the colour buffer allocation field.
273bf215546Sopenharmony_ci         */
274bf215546Sopenharmony_ci        assert(dev->model->tilebuffer_size >= 2048);
275bf215546Sopenharmony_ci        assert(util_is_power_of_two_nonzero(dev->model->tilebuffer_size));
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci        return dev->model->tilebuffer_size / 2;
278bf215546Sopenharmony_ci}
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_civoid
281bf215546Sopenharmony_cipanfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
282bf215546Sopenharmony_ci{
283bf215546Sopenharmony_ci        dev->fd = fd;
284bf215546Sopenharmony_ci        dev->memctx = memctx;
285bf215546Sopenharmony_ci        dev->gpu_id = panfrost_query_gpu_version(fd);
286bf215546Sopenharmony_ci        dev->arch = pan_arch(dev->gpu_id);
287bf215546Sopenharmony_ci        dev->kernel_version = drmGetVersion(fd);
288bf215546Sopenharmony_ci        dev->revision = panfrost_query_gpu_revision(fd);
289bf215546Sopenharmony_ci        dev->model = panfrost_get_model(dev->gpu_id);
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci        /* If we don't recognize the model, bail early */
292bf215546Sopenharmony_ci        if (!dev->model)
293bf215546Sopenharmony_ci                return;
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci        dev->core_count = panfrost_query_core_count(fd, &dev->core_id_range);
296bf215546Sopenharmony_ci        dev->thread_tls_alloc = panfrost_query_thread_tls_alloc(fd, dev->arch);
297bf215546Sopenharmony_ci        dev->optimal_tib_size = panfrost_query_optimal_tib_size(dev);
298bf215546Sopenharmony_ci        dev->compressed_formats = panfrost_query_compressed_formats(fd);
299bf215546Sopenharmony_ci        dev->tiler_features = panfrost_query_tiler_features(fd);
300bf215546Sopenharmony_ci        dev->has_afbc = panfrost_query_afbc(fd, dev->arch);
301bf215546Sopenharmony_ci
302bf215546Sopenharmony_ci        if (dev->arch <= 6)
303bf215546Sopenharmony_ci                dev->formats = panfrost_pipe_format_v6;
304bf215546Sopenharmony_ci        else if (dev->arch <= 7)
305bf215546Sopenharmony_ci                dev->formats = panfrost_pipe_format_v7;
306bf215546Sopenharmony_ci        else
307bf215546Sopenharmony_ci                dev->formats = panfrost_pipe_format_v9;
308bf215546Sopenharmony_ci
309bf215546Sopenharmony_ci        util_sparse_array_init(&dev->bo_map, sizeof(struct panfrost_bo), 512);
310bf215546Sopenharmony_ci
311bf215546Sopenharmony_ci        pthread_mutex_init(&dev->bo_cache.lock, NULL);
312bf215546Sopenharmony_ci        list_inithead(&dev->bo_cache.lru);
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci        for (unsigned i = 0; i < ARRAY_SIZE(dev->bo_cache.buckets); ++i)
315bf215546Sopenharmony_ci                list_inithead(&dev->bo_cache.buckets[i]);
316bf215546Sopenharmony_ci
317bf215546Sopenharmony_ci        /* Initialize pandecode before we start allocating */
318bf215546Sopenharmony_ci        if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC))
319bf215546Sopenharmony_ci                pandecode_initialize(!(dev->debug & PAN_DBG_TRACE));
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci        /* Tiler heap is internally required by the tiler, which can only be
322bf215546Sopenharmony_ci         * active for a single job chain at once, so a single heap can be
323bf215546Sopenharmony_ci         * shared across batches/contextes */
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci        dev->tiler_heap = panfrost_bo_create(dev, 128 * 1024 * 1024,
326bf215546Sopenharmony_ci                        PAN_BO_INVISIBLE | PAN_BO_GROWABLE, "Tiler heap");
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci        pthread_mutex_init(&dev->submit_lock, NULL);
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci        /* Done once on init */
331bf215546Sopenharmony_ci        panfrost_upload_sample_positions(dev);
332bf215546Sopenharmony_ci}
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_civoid
335bf215546Sopenharmony_cipanfrost_close_device(struct panfrost_device *dev)
336bf215546Sopenharmony_ci{
337bf215546Sopenharmony_ci        /* If we don't recognize the model, the rest of the device won't exist,
338bf215546Sopenharmony_ci         * we will have early-exited the device open.
339bf215546Sopenharmony_ci         */
340bf215546Sopenharmony_ci        if (dev->model) {
341bf215546Sopenharmony_ci                pthread_mutex_destroy(&dev->submit_lock);
342bf215546Sopenharmony_ci                panfrost_bo_unreference(dev->tiler_heap);
343bf215546Sopenharmony_ci                panfrost_bo_cache_evict_all(dev);
344bf215546Sopenharmony_ci                pthread_mutex_destroy(&dev->bo_cache.lock);
345bf215546Sopenharmony_ci                util_sparse_array_finish(&dev->bo_map);
346bf215546Sopenharmony_ci        }
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci        drmFreeVersion(dev->kernel_version);
349bf215546Sopenharmony_ci        close(dev->fd);
350bf215546Sopenharmony_ci}
351