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
|
// SPDX-License-Identifier: MIT
/*
* Copyright © 2024 Intel Corporation
*/
#include <linux/bitfield.h>
#include <drm/drm_print.h>
#include "abi/guc_klvs_abi.h"
#include "xe_guc_klv_helpers.h"
#include "xe_guc_klv_thresholds_set.h"
#define make_u64(hi, lo) ((u64)((u64)(u32)(hi) << 32 | (u32)(lo)))
/**
* xe_guc_klv_key_to_string - Convert KLV key into friendly name.
* @key: the `GuC KLV`_ key
*
* Return: name of the KLV key.
*/
const char *xe_guc_klv_key_to_string(u16 key)
{
switch (key) {
/* VGT POLICY keys */
case GUC_KLV_VGT_POLICY_SCHED_IF_IDLE_KEY:
return "sched_if_idle";
case GUC_KLV_VGT_POLICY_ADVERSE_SAMPLE_PERIOD_KEY:
return "sample_period";
case GUC_KLV_VGT_POLICY_RESET_AFTER_VF_SWITCH_KEY:
return "reset_engine";
/* VF CFG keys */
case GUC_KLV_VF_CFG_GGTT_START_KEY:
return "ggtt_start";
case GUC_KLV_VF_CFG_GGTT_SIZE_KEY:
return "ggtt_size";
case GUC_KLV_VF_CFG_LMEM_SIZE_KEY:
return "lmem_size";
case GUC_KLV_VF_CFG_NUM_CONTEXTS_KEY:
return "num_contexts";
case GUC_KLV_VF_CFG_TILE_MASK_KEY:
return "tile_mask";
case GUC_KLV_VF_CFG_NUM_DOORBELLS_KEY:
return "num_doorbells";
case GUC_KLV_VF_CFG_EXEC_QUANTUM_KEY:
return "exec_quantum";
case GUC_KLV_VF_CFG_PREEMPT_TIMEOUT_KEY:
return "preempt_timeout";
case GUC_KLV_VF_CFG_BEGIN_DOORBELL_ID_KEY:
return "begin_db_id";
case GUC_KLV_VF_CFG_BEGIN_CONTEXT_ID_KEY:
return "begin_ctx_id";
/* VF CFG threshold keys */
#define define_threshold_key_to_string_case(TAG, NAME, ...) \
\
case MAKE_GUC_KLV_VF_CFG_THRESHOLD_KEY(TAG): \
return #NAME;
/* private: auto-generated case statements */
MAKE_XE_GUC_KLV_THRESHOLDS_SET(define_threshold_key_to_string_case)
#undef define_threshold_key_to_string_case
default:
return "(unknown)";
}
}
/**
* xe_guc_klv_print - Print content of the buffer with `GuC KLV`_.
* @klvs: the buffer with KLVs
* @num_dwords: number of dwords (u32) available in the buffer
* @p: the &drm_printer
*
* The buffer may contain more than one KLV.
*/
void xe_guc_klv_print(const u32 *klvs, u32 num_dwords, struct drm_printer *p)
{
while (num_dwords >= GUC_KLV_LEN_MIN) {
u32 key = FIELD_GET(GUC_KLV_0_KEY, klvs[0]);
u32 len = FIELD_GET(GUC_KLV_0_LEN, klvs[0]);
klvs += GUC_KLV_LEN_MIN;
num_dwords -= GUC_KLV_LEN_MIN;
if (num_dwords < len) {
drm_printf(p, "{ key %#06x : truncated %zu of %zu bytes %*ph } # %s\n",
key, num_dwords * sizeof(u32), len * sizeof(u32),
(int)(num_dwords * sizeof(u32)), klvs,
xe_guc_klv_key_to_string(key));
return;
}
switch (len) {
case 0:
drm_printf(p, "{ key %#06x : no value } # %s\n",
key, xe_guc_klv_key_to_string(key));
break;
case 1:
drm_printf(p, "{ key %#06x : 32b value %u } # %s\n",
key, klvs[0], xe_guc_klv_key_to_string(key));
break;
case 2:
drm_printf(p, "{ key %#06x : 64b value %#llx } # %s\n",
key, make_u64(klvs[1], klvs[0]),
xe_guc_klv_key_to_string(key));
break;
default:
drm_printf(p, "{ key %#06x : %zu bytes %*ph } # %s\n",
key, len * sizeof(u32), (int)(len * sizeof(u32)),
klvs, xe_guc_klv_key_to_string(key));
break;
}
klvs += len;
num_dwords -= len;
}
/* we don't expect any leftovers, fix if KLV header is ever changed */
BUILD_BUG_ON(GUC_KLV_LEN_MIN > 1);
}
/**
* xe_guc_klv_count - Count KLVs present in the buffer.
* @klvs: the buffer with KLVs
* @num_dwords: number of dwords (u32) in the buffer
*
* Return: number of recognized KLVs or
* a negative error code if KLV buffer is truncated.
*/
int xe_guc_klv_count(const u32 *klvs, u32 num_dwords)
{
int num_klvs = 0;
while (num_dwords >= GUC_KLV_LEN_MIN) {
u32 len = FIELD_GET(GUC_KLV_0_LEN, klvs[0]);
if (num_dwords < len + GUC_KLV_LEN_MIN)
break;
klvs += GUC_KLV_LEN_MIN + len;
num_dwords -= GUC_KLV_LEN_MIN + len;
num_klvs++;
}
return num_dwords ? -ENODATA : num_klvs;
}
|