summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gm20b/fb_gm20b.c
blob: 8f124eec1a63d85e0eb7aa31ed1a4639a5d212e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/*
 * GM20B GPC MMU
 *
 * Copyright (c) 2014-2017, NVIDIA CORPORATION.  All rights reserved.
*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#include "gk20a/gk20a.h"
#include "gk20a/kind_gk20a.h"
#include "gk20a/fb_gk20a.h"
#include "gm20b/fb_gm20b.h"

#include <nvgpu/hw/gm20b/hw_fb_gm20b.h>
#include <nvgpu/hw/gm20b/hw_top_gm20b.h>
#include <nvgpu/hw/gm20b/hw_gmmu_gm20b.h>
#include <nvgpu/hw/gm20b/hw_gr_gm20b.h>

#define VPR_INFO_FETCH_WAIT	(5)
#define WPR_INFO_ADDR_ALIGNMENT 0x0000000c

void fb_gm20b_init_fs_state(struct gk20a *g)
{
	gk20a_dbg_info("initialize gm20b fb");

	gk20a_writel(g, fb_fbhub_num_active_ltcs_r(),
			g->ltc_count);
}

noinline_for_stack void gm20b_init_uncompressed_kind_map(void)
{
	int i;

	for (i = 0; i < 256; i++)
		gk20a_uc_kind_map[i] = gmmu_pte_kind_invalid_v();

	/* From gm20b */
	gk20a_uc_kind_map[gmmu_pte_kind_s8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8_2s_v()] =
		gmmu_pte_kind_s8_v();

	/* From gk20a */
	gk20a_uc_kind_map[gmmu_pte_kind_z16_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms2_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms4_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms8_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_2z_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms2_2z_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms4_2z_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z16_ms8_2z_v()] =
		gmmu_pte_kind_z16_v();

	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms2_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms4_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms8_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms2_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_s8z24_ms8_2cs_v()] =
		gmmu_pte_kind_s8z24_v();

	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc4_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc4_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc4_2zv_v()] =
		gmmu_pte_kind_v8z24_ms4_vc4_v();

	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc8_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc8_2zv_v()] =
		gmmu_pte_kind_v8z24_ms8_vc8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc12_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc12_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc12_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms4_vc12_2zv_v()] =
		gmmu_pte_kind_v8z24_ms4_vc12_v();

	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc24_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc24_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc24_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_v8z24_ms8_vc24_2zv_v()] =
		gmmu_pte_kind_v8z24_ms8_vc24_v();

	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms2_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms2_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms4_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24s8_ms8_2cz_v()] =
		gmmu_pte_kind_z24s8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms2_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms2_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms4_2cz_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_ms8_2cz_v()] =
		gmmu_pte_kind_zf32_v();

	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_2cszv_v()] =
		gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_v();

	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc4_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms4_vc4_2cszv_v()] =
		gmmu_pte_kind_x8z24_x16v8s8_ms4_vc4_v();

	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc8_2cszv_v()] =
		gmmu_pte_kind_x8z24_x16v8s8_ms8_vc8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_2cszv_v()] =
		gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_2cszv_v()] =
		gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc4_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms4_vc4_2cszv_v()] =
		gmmu_pte_kind_zf32_x16v8s8_ms4_vc4_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc8_2cszv_v()] =
		gmmu_pte_kind_zf32_x16v8s8_ms8_vc8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_2cszv_v()] =
		gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_v();

	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_2cszv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms2_2cszv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms4_2cszv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms8_2cszv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms2_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_zf32_x24s8_ms8_2cs_v()] =
		gmmu_pte_kind_zf32_x24s8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_c32_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_2cba_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_2bra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms2_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms2_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms4_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms4_2cbr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms4_2cba_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms4_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms4_2bra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms8_ms16_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c32_ms8_ms16_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_2cbr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_2cba_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_2bra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms2_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms2_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms4_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms4_2cbr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms4_2cba_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms4_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms4_2bra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms8_ms16_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c64_ms8_ms16_2cra_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_2cr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms2_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms2_2cr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms4_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms4_2cr_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms8_ms16_2c_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_c128_ms8_ms16_2cr_v()] =
		gmmu_pte_kind_generic_16bx2_v();

	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc4_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc4_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc4_2zv_v()] =
		gmmu_pte_kind_z24v8_ms4_vc4_v();

	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc12_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc12_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms4_vc12_2zv_v()] =
		gmmu_pte_kind_z24v8_ms4_vc12_v();

	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc8_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc8_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc8_2zv_v()] =
		gmmu_pte_kind_z24v8_ms8_vc8_v();

	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc24_2cs_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc24_2czv_v()] =
	gk20a_uc_kind_map[gmmu_pte_kind_z24v8_ms8_vc24_2zv_v()] =
		gmmu_pte_kind_z24v8_ms8_vc24_v();

	gk20a_uc_kind_map[gmmu_pte_kind_x8c24_v()] =
		gmmu_pte_kind_x8c24_v();
}

static noinline_for_stack bool gm20b_kind_supported(u8 k)
{
	return /* From gm20b */
		(k == gmmu_pte_kind_smsked_message_v())
		|| (k >= gmmu_pte_kind_s8_v() &&
		    k <= gmmu_pte_kind_s8_2s_v())
		/* From gk20a */
		|| gk20a_kind_work_creation(k)
		|| (k == gmmu_pte_kind_invalid_v())
		|| (k == gmmu_pte_kind_pitch_v())
		|| (k >= gmmu_pte_kind_z16_v() &&
			k <= gmmu_pte_kind_z16_ms8_2c_v())
		|| (k >= gmmu_pte_kind_z16_2z_v() &&
			k <= gmmu_pte_kind_z16_ms8_2z_v())
		|| (k == gmmu_pte_kind_s8z24_v())
		|| (k >= gmmu_pte_kind_s8z24_2cz_v() &&
			k <= gmmu_pte_kind_s8z24_ms8_2cz_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_2zv_v())
		|| (k == gmmu_pte_kind_z24s8_v())
		|| (k >= gmmu_pte_kind_z24s8_2cz_v() &&
			k <= gmmu_pte_kind_z24s8_ms8_2cz_v())
		|| (k == gmmu_pte_kind_zf32_v())
		|| (k >= gmmu_pte_kind_zf32_2cz_v() &&
			k <= gmmu_pte_kind_zf32_ms8_2cz_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_2cszv_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_2cszv_v() &&
			k <= gmmu_pte_kind_zf32_x24s8_v())
		|| (k >= gmmu_pte_kind_zf32_x24s8_2cszv_v() &&
			k <= gmmu_pte_kind_zf32_x24s8_ms8_2cszv_v())
		|| (k == gmmu_pte_kind_generic_16bx2_v())
		|| (k == gmmu_pte_kind_c32_2c_v())
		|| (k == gmmu_pte_kind_c32_2cra_v())
		|| (k == gmmu_pte_kind_c32_ms2_2c_v())
		|| (k == gmmu_pte_kind_c32_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms4_2c_v() &&
			k <= gmmu_pte_kind_c32_ms4_2cbr_v())
		|| (k >= gmmu_pte_kind_c32_ms4_2cra_v() &&
			k <= gmmu_pte_kind_c64_2c_v())
		|| (k == gmmu_pte_kind_c64_2cra_v())
		|| (k == gmmu_pte_kind_c64_ms2_2c_v())
		|| (k == gmmu_pte_kind_c64_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms4_2c_v() &&
			k <= gmmu_pte_kind_c64_ms4_2cbr_v())
		|| (k >= gmmu_pte_kind_c64_ms4_2cra_v() &&
			k <= gmmu_pte_kind_c128_ms8_ms16_2cr_v())
		|| (k == gmmu_pte_kind_pitch_no_swizzle_v());
}

static noinline_for_stack bool gm20b_kind_z(u8 k)
{
	return /* From gm20b */
		(k >= gmmu_pte_kind_s8_v() &&
			k <= gmmu_pte_kind_s8_2s_v())
		/* From gk20a */
		|| (k >= gmmu_pte_kind_z16_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_zf32_x24s8_ms16_1cs_v());
}

static noinline_for_stack bool gm20b_kind_c(u8 k)
{
	return gk20a_kind_work_creation(k)
		|| (k == gmmu_pte_kind_pitch_v())
		|| (k == gmmu_pte_kind_generic_16bx2_v())
		|| (k >= gmmu_pte_kind_c32_2c_v() &&
			k <= gmmu_pte_kind_c32_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c32_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms4_2c_v() &&
			k <= gmmu_pte_kind_c64_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c64_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms4_2c_v() &&
			k <= gmmu_pte_kind_pitch_no_swizzle_v());
}

static noinline_for_stack bool gm20b_kind_compressible(u8 k)
{
	return /* From gm20b */
		(k >= gmmu_pte_kind_s8_v() &&
			k <= gmmu_pte_kind_s8_2s_v())
		/* From gk20a */
		|| (k >= gmmu_pte_kind_z16_2c_v() &&
			k <= gmmu_pte_kind_z16_ms16_4cz_v())
		|| (k >= gmmu_pte_kind_s8z24_1z_v() &&
			k <= gmmu_pte_kind_s8z24_ms16_4cszv_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_4cszv_v())
		|| (k >= gmmu_pte_kind_z24s8_1z_v() &&
			k <= gmmu_pte_kind_z24s8_ms16_4cszv_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_4cszv_v())
		|| (k >= gmmu_pte_kind_zf32_1z_v() &&
			k <= gmmu_pte_kind_zf32_ms16_2cz_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_1cs_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_2cszv_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_1cs_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_1zv_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_2cszv_v())
		|| (k >= gmmu_pte_kind_zf32_x24s8_1cs_v() &&
			k <= gmmu_pte_kind_zf32_x24s8_ms16_1cs_v())
		|| (k >= gmmu_pte_kind_zf32_x24s8_2cszv_v() &&
			k <= gmmu_pte_kind_c32_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c32_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms4_2c_v() &&
			k <= gmmu_pte_kind_c64_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c64_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms4_2c_v() &&
			k <= gmmu_pte_kind_c128_ms8_ms16_2cr_v());
}

static noinline_for_stack bool gm20b_kind_zbc(u8 k)
{
	return /* From gm20b */
		(k >= gmmu_pte_kind_s8_v() &&
			k <= gmmu_pte_kind_s8_2s_v())
		/* From gk20a */
		|| (k >= gmmu_pte_kind_z16_2c_v() &&
			k <= gmmu_pte_kind_z16_ms16_2c_v())
		|| (k >= gmmu_pte_kind_z16_4cz_v() &&
			k <= gmmu_pte_kind_z16_ms16_4cz_v())
		|| (k >= gmmu_pte_kind_s8z24_2cz_v() &&
			k <= gmmu_pte_kind_s8z24_ms16_4cszv_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_2cs_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_2czv_v())
		|| (k >= gmmu_pte_kind_v8z24_ms4_vc12_4cszv_v() &&
			k <= gmmu_pte_kind_v8z24_ms8_vc24_4cszv_v())
		|| (k >= gmmu_pte_kind_z24s8_2cs_v() &&
			k <= gmmu_pte_kind_z24s8_ms16_4cszv_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_2cs_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_2cs_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_2czv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_2czv_v())
		|| (k >= gmmu_pte_kind_z24v8_ms4_vc12_4cszv_v() &&
			k <= gmmu_pte_kind_z24v8_ms8_vc24_4cszv_v())
		|| (k >= gmmu_pte_kind_zf32_2cs_v() &&
			k <= gmmu_pte_kind_zf32_ms16_2cz_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_1cs_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_x8z24_x16v8s8_ms4_vc12_1czv_v() &&
			k <= gmmu_pte_kind_x8z24_x16v8s8_ms8_vc24_2cszv_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_1cs_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_1cs_v())
		|| (k >= gmmu_pte_kind_zf32_x16v8s8_ms4_vc12_1czv_v() &&
			k <= gmmu_pte_kind_zf32_x16v8s8_ms8_vc24_2cszv_v())
		|| (k >= gmmu_pte_kind_zf32_x24s8_1cs_v() &&
			k <= gmmu_pte_kind_zf32_x24s8_ms16_1cs_v())
		|| (k >= gmmu_pte_kind_zf32_x24s8_2cszv_v() &&
			k <= gmmu_pte_kind_c32_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms2_2c_v() &&
			k <= gmmu_pte_kind_c32_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c32_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms4_2c_v() &&
			k <= gmmu_pte_kind_c32_ms4_2cra_v())
		|| (k >= gmmu_pte_kind_c32_ms8_ms16_2c_v() &&
			k <= gmmu_pte_kind_c64_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms2_2c_v() &&
			k <= gmmu_pte_kind_c64_ms2_2cbr_v())
		|| (k == gmmu_pte_kind_c64_ms2_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms4_2c_v() &&
			k <= gmmu_pte_kind_c64_ms4_2cra_v())
		|| (k >= gmmu_pte_kind_c64_ms8_ms16_2c_v() &&
			k <= gmmu_pte_kind_c128_ms8_ms16_2cr_v());
}

void gm20b_init_kind_attr(void)
{
	u16 k;

	for (k = 0; k < NV_KIND_ATTR_SIZE; k++) {
		gk20a_kind_attr[k] = 0;
		if (gm20b_kind_supported((u8)k))
			gk20a_kind_attr[k] |= GK20A_KIND_ATTR_SUPPORTED;
		if (gm20b_kind_compressible((u8)k))
			gk20a_kind_attr[k] |= GK20A_KIND_ATTR_COMPRESSIBLE;
		if (gm20b_kind_z((u8)k))
			gk20a_kind_attr[k] |= GK20A_KIND_ATTR_Z;
		if (gm20b_kind_c((u8)k))
			gk20a_kind_attr[k] |= GK20A_KIND_ATTR_C;
		if (gm20b_kind_zbc((u8)k))
			gk20a_kind_attr[k] |= GK20A_KIND_ATTR_ZBC;
	}
}

void gm20b_fb_set_mmu_page_size(struct gk20a *g)
{
	/* set large page size in fb */
	u32 fb_mmu_ctrl = gk20a_readl(g, fb_mmu_ctrl_r());
	fb_mmu_ctrl |= fb_mmu_ctrl_use_pdb_big_page_size_true_f();
	gk20a_writel(g, fb_mmu_ctrl_r(), fb_mmu_ctrl);
}

bool gm20b_fb_set_use_full_comp_tag_line(struct gk20a *g)
{
	/* set large page size in fb */
	u32 fb_mmu_ctrl = gk20a_readl(g, fb_mmu_ctrl_r());
	fb_mmu_ctrl |= fb_mmu_ctrl_use_full_comp_tag_line_true_f();
	gk20a_writel(g, fb_mmu_ctrl_r(), fb_mmu_ctrl);

	return true;
}

unsigned int gm20b_fb_compression_page_size(struct gk20a *g)
{
	return SZ_128K;
}

unsigned int gm20b_fb_compressible_page_size(struct gk20a *g)
{
	return SZ_64K;
}

void gm20b_fb_dump_vpr_wpr_info(struct gk20a *g)
{
	u32 val;

	/* print vpr and wpr info */
	val = gk20a_readl(g, fb_mmu_vpr_info_r());
	val &= ~0x3;
	val |= fb_mmu_vpr_info_index_addr_lo_v();
	gk20a_writel(g, fb_mmu_vpr_info_r(), val);
	nvgpu_err(g, "VPR: %08x %08x %08x %08x",
		gk20a_readl(g, fb_mmu_vpr_info_r()),
		gk20a_readl(g, fb_mmu_vpr_info_r()),
		gk20a_readl(g, fb_mmu_vpr_info_r()),
		gk20a_readl(g, fb_mmu_vpr_info_r()));

	val = gk20a_readl(g, fb_mmu_wpr_info_r());
	val &= ~0xf;
	val |= (fb_mmu_wpr_info_index_allow_read_v());
	gk20a_writel(g, fb_mmu_wpr_info_r(), val);
	nvgpu_err(g, "WPR: %08x %08x %08x %08x %08x %08x",
		gk20a_readl(g, fb_mmu_wpr_info_r()),
		gk20a_readl(g, fb_mmu_wpr_info_r()),
		gk20a_readl(g, fb_mmu_wpr_info_r()),
		gk20a_readl(g, fb_mmu_wpr_info_r()),
		gk20a_readl(g, fb_mmu_wpr_info_r()),
		gk20a_readl(g, fb_mmu_wpr_info_r()));

}

static int gm20b_fb_vpr_info_fetch_wait(struct gk20a *g,
					    unsigned int msec)
{
	struct nvgpu_timeout timeout;

	nvgpu_timeout_init(g, &timeout, msec, NVGPU_TIMER_CPU_TIMER);

	do {
		u32 val;

		val = gk20a_readl(g, fb_mmu_vpr_info_r());
		if (fb_mmu_vpr_info_fetch_v(val) ==
		    fb_mmu_vpr_info_fetch_false_v())
			return 0;

	} while (!nvgpu_timeout_expired(&timeout));

	return -ETIMEDOUT;
}

int gm20b_fb_vpr_info_fetch(struct gk20a *g)
{
	if (gm20b_fb_vpr_info_fetch_wait(g, VPR_INFO_FETCH_WAIT)) {
		return -ETIME;
	}

	gk20a_writel(g, fb_mmu_vpr_info_r(),
			fb_mmu_vpr_info_fetch_true_v());

	return gm20b_fb_vpr_info_fetch_wait(g, VPR_INFO_FETCH_WAIT);
}

void gm20b_fb_read_wpr_info(struct gk20a *g, struct wpr_carveout_info *inf)
{
	u32 val = 0;
	u64 wpr_start = 0;
	u64 wpr_end = 0;

	val = gk20a_readl(g, fb_mmu_wpr_info_r());
	val &= ~0xF;
	val |= fb_mmu_wpr_info_index_wpr1_addr_lo_v();
	gk20a_writel(g, fb_mmu_wpr_info_r(), val);

	val = gk20a_readl(g, fb_mmu_wpr_info_r()) >> 0x4;
	wpr_start = hi32_lo32_to_u64(
			(val >> (32 - WPR_INFO_ADDR_ALIGNMENT)),
			(val << WPR_INFO_ADDR_ALIGNMENT));

	val = gk20a_readl(g, fb_mmu_wpr_info_r());
	val &= ~0xF;
	val |= fb_mmu_wpr_info_index_wpr1_addr_hi_v();
	gk20a_writel(g, fb_mmu_wpr_info_r(), val);

	val = gk20a_readl(g, fb_mmu_wpr_info_r()) >> 0x4;
	wpr_end = hi32_lo32_to_u64(
			(val >> (32 - WPR_INFO_ADDR_ALIGNMENT)),
			(val << WPR_INFO_ADDR_ALIGNMENT));

	inf->wpr_base = wpr_start;
	inf->nonwpr_base = 0;
	inf->size = (wpr_end - wpr_start);
}

bool gm20b_fb_debug_mode_enabled(struct gk20a *g)
{
	u32 debug_ctrl = gk20a_readl(g, gr_gpcs_pri_mmu_debug_ctrl_r());
	return gr_gpcs_pri_mmu_debug_ctrl_debug_v(debug_ctrl) ==
		gr_gpcs_pri_mmu_debug_ctrl_debug_enabled_v();
}

void gm20b_fb_set_debug_mode(struct gk20a *g, bool enable)
{
	u32 reg_val, fb_debug_ctrl, gpc_debug_ctrl;

	if (enable) {
		fb_debug_ctrl = fb_mmu_debug_ctrl_debug_enabled_f();
		gpc_debug_ctrl = gr_gpcs_pri_mmu_debug_ctrl_debug_enabled_f();
		g->mmu_debug_ctrl = true;
	} else {
		fb_debug_ctrl = fb_mmu_debug_ctrl_debug_disabled_f();
		gpc_debug_ctrl = gr_gpcs_pri_mmu_debug_ctrl_debug_disabled_f();
		g->mmu_debug_ctrl = false;
	}

	reg_val = gk20a_readl(g, fb_mmu_debug_ctrl_r());
	reg_val = set_field(reg_val,
			fb_mmu_debug_ctrl_debug_m(), fb_debug_ctrl);
	gk20a_writel(g, fb_mmu_debug_ctrl_r(), reg_val);

	reg_val = gk20a_readl(g, gr_gpcs_pri_mmu_debug_ctrl_r());
	reg_val = set_field(reg_val,
			gr_gpcs_pri_mmu_debug_ctrl_debug_m(), gpc_debug_ctrl);
	gk20a_writel(g, gr_gpcs_pri_mmu_debug_ctrl_r(), reg_val);
}