Rev 3299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3254 | Serge | 1 | /* |
2 | * Copyright (c) 2011 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 FROM, |
||
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||
21 | * SOFTWARE. |
||
22 | * |
||
23 | * Authors: |
||
24 | * Chris Wilson |
||
25 | * |
||
26 | */ |
||
27 | |||
28 | #ifndef KGEM_H |
||
29 | #define KGEM_H |
||
30 | |||
3299 | Serge | 31 | #define HAS_DEBUG_FULL 0 |
3258 | Serge | 32 | |
3254 | Serge | 33 | #include |
34 | #include |
||
3258 | Serge | 35 | #include |
3254 | Serge | 36 | #include |
37 | |||
3769 | Serge | 38 | #include |
3254 | Serge | 39 | |
40 | #include "compiler.h" |
||
41 | #include "intel_list.h" |
||
42 | |||
3299 | Serge | 43 | static inline void delay(uint32_t time) |
44 | { |
||
45 | __asm__ __volatile__( |
||
46 | "int $0x40" |
||
47 | ::"a"(5), "b"(time) |
||
48 | :"memory"); |
||
49 | }; |
||
3254 | Serge | 50 | |
3769 | Serge | 51 | #undef DBG |
3254 | Serge | 52 | |
53 | #if HAS_DEBUG_FULL |
||
54 | #define DBG(x) printf x |
||
55 | #else |
||
56 | #define DBG(x) |
||
57 | #endif |
||
58 | |||
59 | struct kgem_bo { |
||
60 | struct kgem_request *rq; |
||
61 | #define RQ(rq) ((struct kgem_request *)((uintptr_t)(rq) & ~3)) |
||
62 | #define RQ_RING(rq) ((uintptr_t)(rq) & 3) |
||
63 | #define RQ_IS_BLT(rq) (RQ_RING(rq) == KGEM_BLT) |
||
64 | struct drm_i915_gem_exec_object2 *exec; |
||
65 | |||
66 | struct kgem_bo *proxy; |
||
67 | |||
68 | struct list list; |
||
69 | struct list request; |
||
70 | struct list vma; |
||
71 | |||
72 | void *map; |
||
73 | #define IS_CPU_MAP(ptr) ((uintptr_t)(ptr) & 1) |
||
74 | #define IS_GTT_MAP(ptr) (ptr && ((uintptr_t)(ptr) & 1) == 0) |
||
75 | |||
76 | struct kgem_bo_binding { |
||
77 | struct kgem_bo_binding *next; |
||
78 | uint32_t format; |
||
79 | uint16_t offset; |
||
80 | } binding; |
||
81 | |||
82 | uint32_t unique_id; |
||
83 | uint32_t refcnt; |
||
84 | uint32_t handle; |
||
85 | uint32_t target_handle; |
||
86 | uint32_t presumed_offset; |
||
87 | uint32_t delta; |
||
88 | union { |
||
89 | struct { |
||
90 | uint32_t count:27; |
||
91 | #define PAGE_SIZE 4096 |
||
92 | uint32_t bucket:5; |
||
93 | #define NUM_CACHE_BUCKETS 16 |
||
94 | #define MAX_CACHE_SIZE (1 << (NUM_CACHE_BUCKETS+12)) |
||
95 | } pages; |
||
96 | uint32_t bytes; |
||
97 | } size; |
||
98 | uint32_t pitch : 18; /* max 128k */ |
||
99 | uint32_t tiling : 2; |
||
100 | uint32_t reusable : 1; |
||
101 | uint32_t dirty : 1; |
||
102 | uint32_t domain : 2; |
||
103 | uint32_t needs_flush : 1; |
||
104 | uint32_t snoop : 1; |
||
105 | uint32_t io : 1; |
||
106 | uint32_t flush : 1; |
||
107 | uint32_t scanout : 1; |
||
108 | uint32_t purged : 1; |
||
109 | }; |
||
110 | #define DOMAIN_NONE 0 |
||
111 | #define DOMAIN_CPU 1 |
||
112 | #define DOMAIN_GTT 2 |
||
113 | #define DOMAIN_GPU 3 |
||
114 | |||
115 | struct kgem_request { |
||
116 | struct list list; |
||
117 | struct kgem_bo *bo; |
||
118 | struct list buffers; |
||
119 | int ring; |
||
120 | }; |
||
121 | |||
122 | enum { |
||
123 | MAP_GTT = 0, |
||
124 | MAP_CPU, |
||
125 | NUM_MAP_TYPES, |
||
126 | }; |
||
127 | |||
128 | struct kgem { |
||
129 | int fd; |
||
130 | int wedged; |
||
131 | unsigned gen; |
||
132 | |||
133 | uint32_t unique_id; |
||
134 | |||
135 | enum kgem_mode { |
||
136 | /* order matches I915_EXEC_RING ordering */ |
||
137 | KGEM_NONE = 0, |
||
138 | KGEM_RENDER, |
||
139 | KGEM_BSD, |
||
140 | KGEM_BLT, |
||
141 | } mode, ring; |
||
142 | |||
143 | struct list flushing; |
||
144 | struct list large; |
||
145 | struct list large_inactive; |
||
146 | struct list active[NUM_CACHE_BUCKETS][3]; |
||
147 | struct list inactive[NUM_CACHE_BUCKETS]; |
||
148 | struct list pinned_batches[2]; |
||
149 | struct list snoop; |
||
150 | struct list scanout; |
||
151 | struct list batch_buffers, active_buffers; |
||
152 | |||
153 | struct list requests[2]; |
||
154 | struct kgem_request *next_request; |
||
155 | struct kgem_request static_request; |
||
156 | |||
157 | struct { |
||
158 | struct list inactive[NUM_CACHE_BUCKETS]; |
||
159 | int16_t count; |
||
160 | } vma[NUM_MAP_TYPES]; |
||
161 | |||
162 | uint32_t batch_flags; |
||
163 | uint32_t batch_flags_base; |
||
164 | #define I915_EXEC_SECURE (1<<9) |
||
165 | #define LOCAL_EXEC_OBJECT_WRITE (1<<2) |
||
166 | |||
167 | uint16_t nbatch; |
||
168 | uint16_t surface; |
||
169 | uint16_t nexec; |
||
170 | uint16_t nreloc; |
||
171 | uint16_t nreloc__self; |
||
172 | uint16_t nfence; |
||
173 | uint16_t batch_size; |
||
174 | uint16_t min_alignment; |
||
175 | |||
176 | uint32_t flush:1; |
||
177 | uint32_t need_expire:1; |
||
178 | uint32_t need_purge:1; |
||
179 | uint32_t need_retire:1; |
||
180 | uint32_t need_throttle:1; |
||
181 | uint32_t scanout_busy:1; |
||
182 | uint32_t busy:1; |
||
183 | |||
184 | uint32_t has_userptr :1; |
||
185 | uint32_t has_blt :1; |
||
186 | uint32_t has_relaxed_fencing :1; |
||
187 | uint32_t has_relaxed_delta :1; |
||
188 | uint32_t has_semaphores :1; |
||
189 | uint32_t has_secure_batches :1; |
||
190 | uint32_t has_pinned_batches :1; |
||
191 | uint32_t has_cacheing :1; |
||
192 | uint32_t has_llc :1; |
||
193 | uint32_t has_no_reloc :1; |
||
194 | uint32_t has_handle_lut :1; |
||
195 | |||
196 | uint32_t can_blt_cpu :1; |
||
197 | |||
198 | uint16_t fence_max; |
||
199 | uint16_t half_cpu_cache_pages; |
||
200 | uint32_t aperture_total, aperture_high, aperture_low, aperture_mappable; |
||
201 | uint32_t aperture, aperture_fenced; |
||
202 | uint32_t max_upload_tile_size, max_copy_tile_size; |
||
203 | uint32_t max_gpu_size, max_cpu_size; |
||
204 | uint32_t large_object_size, max_object_size; |
||
205 | uint32_t buffer_size; |
||
206 | |||
207 | void (*context_switch)(struct kgem *kgem, int new_mode); |
||
208 | void (*retire)(struct kgem *kgem); |
||
209 | void (*expire)(struct kgem *kgem); |
||
210 | |||
211 | uint32_t batch[64*1024-8]; |
||
212 | struct drm_i915_gem_exec_object2 exec[256]; |
||
213 | struct drm_i915_gem_relocation_entry reloc[4096]; |
||
214 | uint16_t reloc__self[256]; |
||
215 | |||
216 | #ifdef DEBUG_MEMORY |
||
217 | struct { |
||
218 | int bo_allocs; |
||
219 | size_t bo_bytes; |
||
220 | } debug_memory; |
||
221 | #endif |
||
222 | }; |
||
223 | |||
224 | #define KGEM_BATCH_RESERVED 1 |
||
225 | #define KGEM_RELOC_RESERVED 4 |
||
226 | #define KGEM_EXEC_RESERVED 1 |
||
227 | |||
228 | #ifndef ARRAY_SIZE |
||
229 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) |
||
230 | #endif |
||
231 | |||
232 | #define KGEM_BATCH_SIZE(K) ((K)->batch_size-KGEM_BATCH_RESERVED) |
||
233 | #define KGEM_EXEC_SIZE(K) (int)(ARRAY_SIZE((K)->exec)-KGEM_EXEC_RESERVED) |
||
234 | #define KGEM_RELOC_SIZE(K) (int)(ARRAY_SIZE((K)->reloc)-KGEM_RELOC_RESERVED) |
||
235 | |||
236 | void kgem_init(struct kgem *kgem, int fd, struct pci_device *dev, unsigned gen); |
||
237 | void kgem_reset(struct kgem *kgem); |
||
238 | |||
239 | struct kgem_bo *kgem_create_map(struct kgem *kgem, |
||
240 | void *ptr, uint32_t size, |
||
241 | bool read_only); |
||
242 | |||
243 | struct kgem_bo *kgem_create_for_name(struct kgem *kgem, uint32_t name); |
||
244 | |||
245 | struct kgem_bo *kgem_create_linear(struct kgem *kgem, int size, unsigned flags); |
||
246 | struct kgem_bo *kgem_create_proxy(struct kgem *kgem, |
||
247 | struct kgem_bo *target, |
||
248 | int offset, int length); |
||
249 | |||
250 | |||
251 | int kgem_choose_tiling(struct kgem *kgem, |
||
252 | int tiling, int width, int height, int bpp); |
||
253 | unsigned kgem_can_create_2d(struct kgem *kgem, int width, int height, int depth); |
||
254 | #define KGEM_CAN_CREATE_GPU 0x1 |
||
255 | #define KGEM_CAN_CREATE_CPU 0x2 |
||
256 | #define KGEM_CAN_CREATE_LARGE 0x4 |
||
257 | #define KGEM_CAN_CREATE_GTT 0x8 |
||
258 | |||
259 | struct kgem_bo * |
||
260 | kgem_replace_bo(struct kgem *kgem, |
||
261 | struct kgem_bo *src, |
||
262 | uint32_t width, |
||
263 | uint32_t height, |
||
264 | uint32_t pitch, |
||
265 | uint32_t bpp); |
||
266 | enum { |
||
267 | CREATE_EXACT = 0x1, |
||