File: xe_mmio.c

package info (click to toggle)
intel-gpu-tools 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 62,024 kB
  • sloc: xml: 769,439; ansic: 348,692; python: 8,307; yacc: 2,781; perl: 1,196; sh: 1,178; lex: 487; asm: 227; makefile: 27; lisp: 11
file content (200 lines) | stat: -rw-r--r-- 5,279 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: MIT
/*
 * Copyright(c) 2024 Intel Corporation. All rights reserved.
 */

#include "igt_device.h"

#include "xe/xe_mmio.h"
#include "xe/xe_query.h"

/**
 * xe_mmio_vf_access_init:
 * @pf_fd: xe device file descriptor
 * @vf_id: PCI virtual function number (0 if native or PF itself)
 * @mmio: xe mmio structure for IO operations
 *
 * This initializes the xe mmio structure, and maps the MMIO BAR owned by
 * the specified virtual function associated with @pf_fd.
 */
void xe_mmio_vf_access_init(int pf_fd, int vf_id, struct xe_mmio *mmio)
{
	struct pci_device *pci_dev = __igt_device_get_pci_device(pf_fd, vf_id);

	igt_assert_f(pci_dev, "No PCI device found for VF%u\n", vf_id);

	intel_register_access_init(&mmio->intel_mmio, pci_dev, false);
	mmio->fd = pf_fd;
}

/**
 * xe_mmio_access_init:
 * @pf_fd: xe device file descriptor
 * @mmio: xe mmio structure for IO operations
 *
 * This initializes the xe mmio structure, and maps MMIO BAR for @pf_fd device.
 */
void xe_mmio_access_init(int pf_fd, struct xe_mmio *mmio)
{
	xe_mmio_vf_access_init(pf_fd, 0, mmio);
}

/**
 * xe_mmio_access_fini:
 * @mmio: xe mmio structure for IO operations
 *
 * Clean up the mmio access helper initialized with
 * xe_mmio_access_init()/xe_mmio_vf_access_init().
 */
void xe_mmio_access_fini(struct xe_mmio *mmio)
{
	intel_register_access_fini(&mmio->intel_mmio);
}

/**
 * xe_mmio_read32:
 * @mmio: xe mmio structure for IO operations
 * @offset: mmio register offset
 *
 * 32-bit read of the register at @offset.
 *
 * Returns:
 * The value read from the register.
 */
uint32_t xe_mmio_read32(struct xe_mmio *mmio, uint32_t offset)
{
	return ioread32(mmio->intel_mmio.igt_mmio, offset);
}

/**
 * xe_mmio_read64:
 * @mmio: xe mmio structure for IO operations
 * @offset: mmio register offset
 *
 * 64-bit read of the register at @offset.
 *
 * Returns:
 * The value read from the register.
 */
uint64_t xe_mmio_read64(struct xe_mmio *mmio, uint32_t offset)
{
	return ioread64(mmio->intel_mmio.igt_mmio, offset);
}

/**
 * xe_mmio_write32:
 * @mmio: xe mmio structure for IO operations
 * @offset: mmio register offset
 * @val: value to write
 *
 * 32-bit write to the register at @offset.
 */
void xe_mmio_write32(struct xe_mmio *mmio, uint32_t offset, uint32_t val)
{
	return iowrite32(mmio->intel_mmio.igt_mmio, offset, val);
}

/**
 * xe_mmio_write64:
 * @mmio: xe mmio structure for IO operations
 * @offset: mmio register offset
 * @val: value to write
 *
 * 64-bit write to the register at @offset.
 */
void xe_mmio_write64(struct xe_mmio *mmio, uint32_t offset, uint64_t val)
{
	return iowrite64(mmio->intel_mmio.igt_mmio, offset, val);
}

/**
 * xe_mmio_gt_read32:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: mmio register offset in tile to which @gt belongs
 *
 * 32-bit read of the register at @offset in tile to which @gt belongs.
 *
 * Returns:
 * The value read from the register.
 */
uint32_t xe_mmio_gt_read32(struct xe_mmio *mmio, int gt, uint32_t offset)
{
	return xe_mmio_read32(mmio, offset + (TILE_MMIO_SIZE * xe_gt_get_tile_id(mmio->fd, gt)));
}

/**
 * xe_mmio_gt_read64:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: mmio register offset in tile to which @gt belongs
 *
 * 64-bit read of the register at @offset in tile to which @gt belongs.
 *
 * Returns:
 * The value read from the register.
 */
uint64_t xe_mmio_gt_read64(struct xe_mmio *mmio, int gt, uint32_t offset)
{
	return xe_mmio_read64(mmio, offset + (TILE_MMIO_SIZE * xe_gt_get_tile_id(mmio->fd, gt)));
}

/**
 * xe_mmio_gt_write32:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: mmio register offset
 * @val: value to write
 *
 * 32-bit write to the register at @offset in tile to which @gt belongs.
 */
void xe_mmio_gt_write32(struct xe_mmio *mmio, int gt, uint32_t offset, uint32_t val)
{
	return xe_mmio_write32(mmio, offset + (TILE_MMIO_SIZE * xe_gt_get_tile_id(mmio->fd, gt)),
			       val);
}

/**
 * xe_mmio_gt_write64:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: mmio register offset
 * @val: value to write
 *
 * 64-bit write to the register at @offset in tile to which @gt belongs.
 */
void xe_mmio_gt_write64(struct xe_mmio *mmio, int gt, uint32_t offset, uint64_t val)
{
	return xe_mmio_write64(mmio, offset + (TILE_MMIO_SIZE * xe_gt_get_tile_id(mmio->fd, gt)),
			       val);
}

/**
 * xe_mmio_ggtt_read:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: PTE offset from the beginning of GGTT, in tile to which @gt belongs
 *
 * Read of GGTT PTE at GGTT @offset in tile to which @gt belongs.
 *
 * Returns:
 * The value read from the register.
 */
xe_ggtt_pte_t xe_mmio_ggtt_read(struct xe_mmio *mmio, int gt, uint32_t offset)
{
	return xe_mmio_gt_read64(mmio, gt, offset + GGTT_OFFSET_IN_TILE);
}

/**
 * xe_mmio_ggtt_write:
 * @mmio: xe mmio structure for IO operations
 * @gt: gt id
 * @offset: PTE offset from the beginning of GGTT, in tile to which @gt belongs
 * @pte: PTE value to write
 *
 * Write PTE value at GGTT @offset in tile to which @gt belongs.
 */
void xe_mmio_ggtt_write(struct xe_mmio *mmio, int gt, uint32_t offset, xe_ggtt_pte_t pte)
{
	return xe_mmio_gt_write64(mmio, gt, offset + GGTT_OFFSET_IN_TILE, pte);
}