File: intel_mocs.c

package info (click to toggle)
intel-gpu-tools 2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,504 kB
  • sloc: xml: 781,458; ansic: 378,272; python: 8,407; yacc: 2,781; perl: 1,196; sh: 1,177; lex: 487; asm: 227; lisp: 35; makefile: 30
file content (134 lines) | stat: -rw-r--r-- 3,292 bytes parent folder | download
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
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2022 Intel Corporation
 */

#include "igt.h"
#include "intel_mocs.h"

struct drm_intel_mocs_index {
	uint8_t uc_index;
	uint8_t wb_index;
	uint8_t displayable_index;
	uint8_t defer_to_pat_index;
};

/**
 * SECTION:intel_mocs
 * @short_description: Intel Memory Object Control State (MOCS) helpers
 * @title: Intel MOCS helpers
 * @include: igt.h
 *
 * Memory Object Control State (MOCS) defines the behaviour of memory accesses
 * beyond the graphics core, including encryption, graphics data types that
 * allow selective flushing of data from outer caches, and controlling
 * cacheability in the outer caches.
 */

static void get_mocs_index(int fd, struct drm_intel_mocs_index *mocs)
{
	uint16_t devid = intel_get_drm_devid(fd);
	unsigned int ip_ver = intel_graphics_ver(devid);

	/*
	 * Gen >= 12 onwards don't have a setting for PTE,
	 * so using I915_MOCS_PTE as mocs index may leads to
	 * some undefined MOCS behavior.
	 * This helper function is providing current UC as well
	 * as WB MOCS index based on platform.
	 */
	if (ip_ver >= IP_VER(20, 0)) {
		mocs->uc_index = 3;
		mocs->wb_index = 4;
		mocs->displayable_index = 1;
		mocs->defer_to_pat_index = 0;
	} else if (IS_METEORLAKE(devid)) {
		mocs->uc_index = 5;
		mocs->wb_index = 1;
		mocs->displayable_index = 14;
	} else if (IS_DG2(devid)) {
		mocs->uc_index = 1;
		mocs->wb_index = 3;
		mocs->displayable_index = 3;
	} else if (IS_DG1(devid)) {
		mocs->uc_index = 1;
		mocs->wb_index = 5;
		mocs->displayable_index = 5;
	} else if (ip_ver >= IP_VER(12, 0)) {
		mocs->uc_index = 3;
		mocs->wb_index = 2;
		mocs->displayable_index = 61;
	} else {
		mocs->uc_index = I915_MOCS_PTE;
		mocs->wb_index = I915_MOCS_CACHED;
		mocs->displayable_index = I915_MOCS_PTE;
	}
}

/**
 * intel_get_wb_mocs_index:
 * @fd: the DRM file descriptor
 *
 * Returns: The MOCS index corresponding to the basic write-back behaviour for
 * the open Intel DRM device.
 */
uint8_t intel_get_wb_mocs_index(int fd)
{
	struct drm_intel_mocs_index mocs;

	get_mocs_index(fd, &mocs);

	return mocs.wb_index;
}

/**
 * intel_get_uc_mocs_index:
 * @fd: the DRM file descriptor
 *
 * Returns: The MOCS index corresponding to the uncached behaviour for the open
 * Intel DRM device.
 */
uint8_t intel_get_uc_mocs_index(int fd)
{
	struct drm_intel_mocs_index mocs;

	get_mocs_index(fd, &mocs);

	return mocs.uc_index;
}

/**
 * intel_get_displayable_mocs_index:
 * @fd: the DRM file descriptor
 *
 * Returns: The MOCS index corresponding to the uncached displayable behaviour
 * for the open Intel DRM device. This should be used for buffers which may be
 * simultaneously displayed and rendered to.
 */
uint8_t intel_get_displayable_mocs_index(int fd)
{
	struct drm_intel_mocs_index mocs;

	get_mocs_index(fd, &mocs);

	return mocs.displayable_index;
}

/**
 * intel_get_defer_to_pat_mocs_index:
 * @fd: the DRM file descriptor
 *
 * Returns: The MOCS index corresponding to the "defer to PAT" caching
 * behaviour, or asserts if the platform does not support this mode.
 */
uint8_t intel_get_defer_to_pat_mocs_index(int fd)
{
	struct drm_intel_mocs_index mocs;
	uint16_t dev_id = intel_get_drm_devid(fd);

	igt_assert(intel_gen(dev_id) >= 20);

	get_mocs_index(fd, &mocs);

	return mocs.defer_to_pat_index;
}