1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "intel_mocs.h"
24#include "intel_lrc.h"
25#include "intel_ringbuffer.h"
26
27
28struct drm_i915_mocs_entry {
29 u32 control_value;
30 u16 l3cc_value;
31};
32
33struct drm_i915_mocs_table {
34 u32 size;
35 const struct drm_i915_mocs_entry *table;
36};
37
38
39#define LE_CACHEABILITY(value) ((value) << 0)
40#define LE_TGT_CACHE(value) ((value) << 2)
41#define LE_LRUM(value) ((value) << 4)
42#define LE_AOM(value) ((value) << 6)
43#define LE_RSC(value) ((value) << 7)
44#define LE_SCC(value) ((value) << 8)
45#define LE_PFM(value) ((value) << 11)
46#define LE_SCF(value) ((value) << 14)
47
48
49#define L3_ESC(value) ((value) << 0)
50#define L3_SCC(value) ((value) << 1)
51#define L3_CACHEABILITY(value) ((value) << 4)
52
53
54#define GEN9_NUM_MOCS_ENTRIES 62
55
56
57#define LE_PAGETABLE 0
58#define LE_UC 1
59#define LE_WT 2
60#define LE_WB 3
61
62
63#define L3_DIRECT 0
64#define L3_UC 1
65#define L3_RESERVED 2
66#define L3_WB 3
67
68
69#define LE_TC_PAGETABLE 0
70#define LE_TC_LLC 1
71#define LE_TC_LLC_ELLC 2
72#define LE_TC_LLC_ELLC_ALT 3
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99static const struct drm_i915_mocs_entry skylake_mocs_table[] = {
100 [I915_MOCS_UNCACHED] = {
101
102 .control_value = LE_CACHEABILITY(LE_UC) |
103 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
104 LE_LRUM(0) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
105 LE_PFM(0) | LE_SCF(0),
106
107
108 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_UC),
109 },
110 [I915_MOCS_PTE] = {
111
112 .control_value = LE_CACHEABILITY(LE_PAGETABLE) |
113 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
114 LE_LRUM(3) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
115 LE_PFM(0) | LE_SCF(0),
116
117 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_WB),
118 },
119 [I915_MOCS_CACHED] = {
120
121 .control_value = LE_CACHEABILITY(LE_WB) |
122 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
123 LE_LRUM(3) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
124 LE_PFM(0) | LE_SCF(0),
125
126 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_WB),
127 },
128};
129
130
131static const struct drm_i915_mocs_entry broxton_mocs_table[] = {
132 [I915_MOCS_UNCACHED] = {
133
134 .control_value = LE_CACHEABILITY(LE_UC) |
135 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
136 LE_LRUM(0) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
137 LE_PFM(0) | LE_SCF(0),
138
139
140 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_UC),
141 },
142 [I915_MOCS_PTE] = {
143
144 .control_value = LE_CACHEABILITY(LE_PAGETABLE) |
145 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
146 LE_LRUM(3) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
147 LE_PFM(0) | LE_SCF(0),
148
149
150 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_WB),
151 },
152 [I915_MOCS_CACHED] = {
153
154 .control_value = LE_CACHEABILITY(LE_UC) |
155 LE_TGT_CACHE(LE_TC_LLC_ELLC) |
156 LE_LRUM(3) | LE_AOM(0) | LE_RSC(0) | LE_SCC(0) |
157 LE_PFM(0) | LE_SCF(0),
158
159
160 .l3cc_value = L3_ESC(0) | L3_SCC(0) | L3_CACHEABILITY(L3_WB),
161 },
162};
163
164
165
166
167
168
169
170
171
172
173
174
175
176static bool get_mocs_settings(struct drm_i915_private *dev_priv,
177 struct drm_i915_mocs_table *table)
178{
179 bool result = false;
180
181 if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv)) {
182 table->size = ARRAY_SIZE(skylake_mocs_table);
183 table->table = skylake_mocs_table;
184 result = true;
185 } else if (IS_GEN9_LP(dev_priv)) {
186 table->size = ARRAY_SIZE(broxton_mocs_table);
187 table->table = broxton_mocs_table;
188 result = true;
189 } else {
190 WARN_ONCE(INTEL_INFO(dev_priv)->gen >= 9,
191 "Platform that should have a MOCS table does not.\n");
192 }
193
194
195 if (IS_GEN9(dev_priv)) {
196 int i;
197
198 for (i = 0; i < table->size; i++)
199 if (WARN_ON(table->table[i].l3cc_value &
200 (L3_ESC(1) | L3_SCC(0x7))))
201 return false;
202 }
203
204 return result;
205}
206
207static i915_reg_t mocs_register(enum intel_engine_id engine_id, int index)
208{
209 switch (engine_id) {
210 case RCS:
211 return GEN9_GFX_MOCS(index);
212 case VCS:
213 return GEN9_MFX0_MOCS(index);
214 case BCS:
215 return GEN9_BLT_MOCS(index);
216 case VECS:
217 return GEN9_VEBOX_MOCS(index);
218 case VCS2:
219 return GEN9_MFX1_MOCS(index);
220 default:
221 MISSING_CASE(engine_id);
222 return INVALID_MMIO_REG;
223 }
224}
225
226
227
228
229
230
231
232
233
234
235int intel_mocs_init_engine(struct intel_engine_cs *engine)
236{
237 struct drm_i915_private *dev_priv = engine->i915;
238 struct drm_i915_mocs_table table;
239 unsigned int index;
240
241 if (!get_mocs_settings(dev_priv, &table))
242 return 0;
243
244 if (WARN_ON(table.size > GEN9_NUM_MOCS_ENTRIES))
245 return -ENODEV;
246
247 for (index = 0; index < table.size; index++)
248 I915_WRITE(mocs_register(engine->id, index),
249 table.table[index].control_value);
250
251
252
253
254
255
256
257
258
259 for (; index < GEN9_NUM_MOCS_ENTRIES; index++)
260 I915_WRITE(mocs_register(engine->id, index),
261 table.table[0].control_value);
262
263 return 0;
264}
265
266
267
268
269
270
271
272
273
274
275
276static int emit_mocs_control_table(struct drm_i915_gem_request *req,
277 const struct drm_i915_mocs_table *table)
278{
279 enum intel_engine_id engine = req->engine->id;
280 unsigned int index;
281 u32 *cs;
282
283 if (WARN_ON(table->size > GEN9_NUM_MOCS_ENTRIES))
284 return -ENODEV;
285
286 cs = intel_ring_begin(req, 2 + 2 * GEN9_NUM_MOCS_ENTRIES);
287 if (IS_ERR(cs))
288 return PTR_ERR(cs);
289
290 *cs++ = MI_LOAD_REGISTER_IMM(GEN9_NUM_MOCS_ENTRIES);
291
292 for (index = 0; index < table->size; index++) {
293 *cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
294 *cs++ = table->table[index].control_value;
295 }
296
297
298
299
300
301
302
303
304
305 for (; index < GEN9_NUM_MOCS_ENTRIES; index++) {
306 *cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
307 *cs++ = table->table[0].control_value;
308 }
309
310 *cs++ = MI_NOOP;
311 intel_ring_advance(req, cs);
312
313 return 0;
314}
315
316static inline u32 l3cc_combine(const struct drm_i915_mocs_table *table,
317 u16 low,
318 u16 high)
319{
320 return table->table[low].l3cc_value |
321 table->table[high].l3cc_value << 16;
322}
323
324
325
326
327
328
329
330
331
332
333
334
335static int emit_mocs_l3cc_table(struct drm_i915_gem_request *req,
336 const struct drm_i915_mocs_table *table)
337{
338 unsigned int i;
339 u32 *cs;
340
341 if (WARN_ON(table->size > GEN9_NUM_MOCS_ENTRIES))
342 return -ENODEV;
343
344 cs = intel_ring_begin(req, 2 + GEN9_NUM_MOCS_ENTRIES);
345 if (IS_ERR(cs))
346 return PTR_ERR(cs);
347
348 *cs++ = MI_LOAD_REGISTER_IMM(GEN9_NUM_MOCS_ENTRIES / 2);
349
350 for (i = 0; i < table->size/2; i++) {
351 *cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(i));
352 *cs++ = l3cc_combine(table, 2 * i, 2 * i + 1);
353 }
354
355 if (table->size & 0x01) {
356
357 *cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(i));
358 *cs++ = l3cc_combine(table, 2 * i, 0);
359 i++;
360 }
361
362
363
364
365
366
367 for (; i < GEN9_NUM_MOCS_ENTRIES / 2; i++) {
368 *cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(i));
369 *cs++ = l3cc_combine(table, 0, 0);
370 }
371
372 *cs++ = MI_NOOP;
373 intel_ring_advance(req, cs);
374
375 return 0;
376}
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392void intel_mocs_init_l3cc_table(struct drm_i915_private *dev_priv)
393{
394 struct drm_i915_mocs_table table;
395 unsigned int i;
396
397 if (!get_mocs_settings(dev_priv, &table))
398 return;
399
400 for (i = 0; i < table.size/2; i++)
401 I915_WRITE(GEN9_LNCFCMOCS(i), l3cc_combine(&table, 2*i, 2*i+1));
402
403
404 if (table.size & 0x01) {
405 I915_WRITE(GEN9_LNCFCMOCS(i), l3cc_combine(&table, 2*i, 0));
406 i++;
407 }
408
409
410
411
412
413
414 for (; i < (GEN9_NUM_MOCS_ENTRIES / 2); i++)
415 I915_WRITE(GEN9_LNCFCMOCS(i), l3cc_combine(&table, 0, 0));
416}
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434int intel_rcs_context_init_mocs(struct drm_i915_gem_request *req)
435{
436 struct drm_i915_mocs_table t;
437 int ret;
438
439 if (get_mocs_settings(req->i915, &t)) {
440
441 ret = emit_mocs_control_table(req, &t);
442 if (ret)
443 return ret;
444
445
446 ret = emit_mocs_l3cc_table(req, &t);
447 if (ret)
448 return ret;
449 }
450
451 return 0;
452}
453