• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2018-2019 Alyssa Rosenzweig
4  * Copyright 2018-2019 Collabora, Ltd.
5  * Copyright © 2015 Intel Corporation
6  * All Rights Reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sub license, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  **************************************************************************/
29 
30 #ifndef PAN_DEVICE_H
31 #define PAN_DEVICE_H
32 
33 #include <xf86drm.h>
34 #include "renderonly/renderonly.h"
35 #include "util/bitset.h"
36 #include "util/list.h"
37 #include "util/sparse_array.h"
38 #include "util/u_dynarray.h"
39 
40 #include "panfrost/util/pan_ir.h"
41 #include "pan_blend.h"
42 #include "pan_blitter.h"
43 #include "pan_indirect_dispatch.h"
44 #include "pan_pool.h"
45 #include "pan_props.h"
46 #include "pan_util.h"
47 
48 #include "kmod/pan_kmod.h"
49 
50 #include <genxml/gen_macros.h>
51 
52 #if defined(__cplusplus)
53 extern "C" {
54 #endif
55 
56 /* Driver limits */
57 #define PAN_MAX_CONST_BUFFERS 16
58 
59 /* How many power-of-two levels in the BO cache do we want? 2^12
60  * minimum chosen as it is the page size that all allocations are
61  * rounded to */
62 
63 #define MIN_BO_CACHE_BUCKET (12) /* 2^12 = 4KB */
64 #define MAX_BO_CACHE_BUCKET (22) /* 2^22 = 4MB */
65 
66 /* Fencepost problem, hence the off-by-one */
67 #define NR_BO_CACHE_BUCKETS (MAX_BO_CACHE_BUCKET - MIN_BO_CACHE_BUCKET + 1)
68 
69 struct panfrost_device {
70    /* For ralloc */
71    void *memctx;
72 
73    /* Kmod objects. */
74    struct {
75       /* The pan_kmod_dev object backing this device. */
76       struct pan_kmod_dev *dev;
77 
78       /* Cached pan_kmod_dev_props properties queried at device create time. */
79       struct pan_kmod_dev_props props;
80 
81       /* VM attached to this device. */
82       struct pan_kmod_vm *vm;
83    } kmod;
84 
85    /* For pandecode */
86    struct pandecode_context *decode_ctx;
87 
88    /* Properties of the GPU in use */
89    unsigned arch;
90 
91    /* Number of shader cores */
92    unsigned core_count;
93 
94    /* Range of core IDs, equal to the maximum core ID + 1. Satisfies
95     * core_id_range >= core_count.
96     */
97    unsigned core_id_range;
98 
99    /* Maximum tilebuffer size in bytes for optimal performance. */
100    unsigned optimal_tib_size;
101 
102    unsigned thread_tls_alloc;
103    struct panfrost_tiler_features tiler_features;
104    const struct panfrost_model *model;
105    bool has_afbc;
106 
107    /* Table of formats, indexed by a PIPE format */
108    const struct panfrost_format *formats;
109    const struct pan_blendable_format *blendable_formats;
110 
111    /* Bitmask of supported compressed texture formats */
112    uint32_t compressed_formats;
113 
114    /* debug flags, see pan_util.h how to interpret */
115    unsigned debug;
116 
117    struct renderonly *ro;
118 
119    pthread_mutex_t bo_map_lock;
120    struct util_sparse_array bo_map;
121 
122    struct {
123       pthread_mutex_t lock;
124 
125       /* List containing all cached BOs sorted in LRU (Least
126        * Recently Used) order. This allows us to quickly evict BOs
127        * that are more than 1 second old.
128        */
129       struct list_head lru;
130 
131       /* The BO cache is a set of buckets with power-of-two sizes
132        * ranging from 2^12 (4096, the page size) to
133        * 2^(12 + MAX_BO_CACHE_BUCKETS).
134        * Each bucket is a linked list of free panfrost_bo objects. */
135 
136       struct list_head buckets[NR_BO_CACHE_BUCKETS];
137    } bo_cache;
138 
139    struct pan_blitter_cache blitter;
140    struct pan_blend_shader_cache blend_shaders;
141    struct pan_indirect_dispatch_meta indirect_dispatch;
142 
143    /* Tiler heap shared across all tiler jobs, allocated against the
144     * device since there's only a single tiler. Since this is invisible to
145     * the CPU, it's okay for multiple contexts to reference it
146     * simultaneously; by keeping on the device struct, we eliminate a
147     * costly per-context allocation. */
148 
149    struct panfrost_bo *tiler_heap;
150 
151    /* The tiler heap is shared by all contexts, and is written by tiler
152     * jobs and read by fragment job. We need to ensure that a
153     * vertex/tiler job chain from one context is not inserted between
154     * the vertex/tiler and fragment job of another context, otherwise
155     * we end up with tiler heap corruption.
156     */
157    pthread_mutex_t submit_lock;
158 
159    /* Sample positions are preloaded into a write-once constant buffer,
160     * such that they can be referenced fore free later. Needed
161     * unconditionally on Bifrost, and useful for sharing with Midgard */
162 
163    struct panfrost_bo *sample_positions;
164 };
165 
166 static inline int
panfrost_device_fd(const struct panfrost_device * dev)167 panfrost_device_fd(const struct panfrost_device *dev)
168 {
169    return dev->kmod.dev->fd;
170 }
171 
172 static inline uint32_t
panfrost_device_gpu_id(const struct panfrost_device * dev)173 panfrost_device_gpu_id(const struct panfrost_device *dev)
174 {
175    return dev->kmod.props.gpu_prod_id;
176 }
177 
178 static inline uint32_t
panfrost_device_gpu_rev(const struct panfrost_device * dev)179 panfrost_device_gpu_rev(const struct panfrost_device *dev)
180 {
181    return dev->kmod.props.gpu_revision;
182 }
183 
184 static inline int
panfrost_device_kmod_version_major(const struct panfrost_device * dev)185 panfrost_device_kmod_version_major(const struct panfrost_device *dev)
186 {
187    return dev->kmod.dev->driver.version.major;
188 }
189 
190 static inline int
panfrost_device_kmod_version_minor(const struct panfrost_device * dev)191 panfrost_device_kmod_version_minor(const struct panfrost_device *dev)
192 {
193    return dev->kmod.dev->driver.version.minor;
194 }
195 
196 void panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev);
197 
198 void panfrost_close_device(struct panfrost_device *dev);
199 
200 bool panfrost_supports_compressed_format(struct panfrost_device *dev,
201                                          unsigned fmt);
202 
203 static inline struct panfrost_bo *
pan_lookup_bo(struct panfrost_device * dev,uint32_t gem_handle)204 pan_lookup_bo(struct panfrost_device *dev, uint32_t gem_handle)
205 {
206    return (struct panfrost_bo *)util_sparse_array_get(&dev->bo_map, gem_handle);
207 }
208 
209 static inline bool
pan_is_bifrost(const struct panfrost_device * dev)210 pan_is_bifrost(const struct panfrost_device *dev)
211 {
212    return dev->arch >= 6 && dev->arch <= 7;
213 }
214 
215 #if defined(__cplusplus)
216 } // extern "C"
217 #endif
218 
219 #endif
220