Skip to content

Commit 2d1fcec

Browse files
committed
drm/xe/oa: Introduce stream->oa_unit
Previously, the oa_unit associated with an OA stream was derived from hwe associated with the stream (stream->hwe->oa_unit). This breaks with OAM_SAG since OAM_SAG does not have any attached hardware engines. Resolve this by introducing stream->oa_unit and stop depending on stream->hwe. Signed-off-by: Ashutosh Dixit <[email protected]> Reviewed-by: Umesh Nerlige Ramappa <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f3a3fd2 commit 2d1fcec

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

drivers/gpu/drm/xe/xe_oa.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct xe_oa_config {
8383

8484
struct xe_oa_open_param {
8585
struct xe_file *xef;
86-
u32 oa_unit_id;
86+
struct xe_oa_unit *oa_unit;
8787
bool sample;
8888
u32 metric_set;
8989
enum xe_oa_format_name oa_format;
@@ -200,7 +200,7 @@ static void free_oa_config_bo(struct xe_oa_config_bo *oa_bo, struct dma_fence *l
200200

201201
static const struct xe_oa_regs *__oa_regs(struct xe_oa_stream *stream)
202202
{
203-
return &stream->hwe->oa_unit->regs;
203+
return &stream->oa_unit->regs;
204204
}
205205

206206
static u32 xe_oa_hw_tail_read(struct xe_oa_stream *stream)
@@ -460,7 +460,7 @@ static u32 __oa_ccs_select(struct xe_oa_stream *stream)
460460

461461
static u32 __oactrl_used_bits(struct xe_oa_stream *stream)
462462
{
463-
return stream->hwe->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG ?
463+
return stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG ?
464464
OAG_OACONTROL_USED_BITS : OAM_OACONTROL_USED_BITS;
465465
}
466466

@@ -481,7 +481,7 @@ static void xe_oa_enable(struct xe_oa_stream *stream)
481481
__oa_ccs_select(stream) | OAG_OACONTROL_OA_COUNTER_ENABLE;
482482

483483
if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
484-
stream->hwe->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG)
484+
stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG)
485485
val |= OAG_OACONTROL_OA_PES_DISAG_EN;
486486

487487
xe_mmio_rmw32(&stream->gt->mmio, regs->oa_ctrl, __oactrl_used_bits(stream), val);
@@ -848,7 +848,7 @@ static void xe_oa_disable_metric_set(struct xe_oa_stream *stream)
848848

849849
static void xe_oa_stream_destroy(struct xe_oa_stream *stream)
850850
{
851-
struct xe_oa_unit *u = stream->hwe->oa_unit;
851+
struct xe_oa_unit *u = stream->oa_unit;
852852
struct xe_gt *gt = stream->hwe->gt;
853853

854854
if (WARN_ON(stream != u->exclusive_stream))
@@ -1145,14 +1145,31 @@ static int decode_oa_format(struct xe_oa *oa, u64 fmt, enum xe_oa_format_name *n
11451145
return -EINVAL;
11461146
}
11471147

1148+
static struct xe_oa_unit *xe_oa_lookup_oa_unit(struct xe_oa *oa, u32 oa_unit_id)
1149+
{
1150+
struct xe_gt *gt;
1151+
int gt_id, i;
1152+
1153+
for_each_gt(gt, oa->xe, gt_id) {
1154+
for (i = 0; i < gt->oa.num_oa_units; i++) {
1155+
struct xe_oa_unit *u = &gt->oa.oa_unit[i];
1156+
1157+
if (u->oa_unit_id == oa_unit_id)
1158+
return u;
1159+
}
1160+
}
1161+
1162+
return NULL;
1163+
}
1164+
11481165
static int xe_oa_set_prop_oa_unit_id(struct xe_oa *oa, u64 value,
11491166
struct xe_oa_open_param *param)
11501167
{
1151-
if (value >= oa->oa_unit_ids) {
1168+
param->oa_unit = xe_oa_lookup_oa_unit(oa, value);
1169+
if (!param->oa_unit) {
11521170
drm_dbg(&oa->xe->drm, "OA unit ID out of range %lld\n", value);
11531171
return -EINVAL;
11541172
}
1155-
param->oa_unit_id = value;
11561173
return 0;
11571174
}
11581175

@@ -1683,13 +1700,13 @@ static const struct file_operations xe_oa_fops = {
16831700
static int xe_oa_stream_init(struct xe_oa_stream *stream,
16841701
struct xe_oa_open_param *param)
16851702
{
1686-
struct xe_oa_unit *u = param->hwe->oa_unit;
16871703
struct xe_gt *gt = param->hwe->gt;
16881704
unsigned int fw_ref;
16891705
int ret;
16901706

16911707
stream->exec_q = param->exec_q;
16921708
stream->poll_period_ns = DEFAULT_POLL_PERIOD_NS;
1709+
stream->oa_unit = param->oa_unit;
16931710
stream->hwe = param->hwe;
16941711
stream->gt = stream->hwe->gt;
16951712
stream->oa_buffer.format = &stream->oa->oa_formats[param->oa_format];
@@ -1710,7 +1727,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,
17101727
* buffer whose size, circ_size, is a multiple of the report size
17111728
*/
17121729
if (GRAPHICS_VER(stream->oa->xe) >= 20 &&
1713-
stream->hwe->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG && stream->sample)
1730+
stream->oa_unit->type == DRM_XE_OA_UNIT_TYPE_OAG && stream->sample)
17141731
stream->oa_buffer.circ_size =
17151732
param->oa_buffer_size -
17161733
param->oa_buffer_size % stream->oa_buffer.format->size;
@@ -1768,7 +1785,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,
17681785
drm_dbg(&stream->oa->xe->drm, "opening stream oa config uuid=%s\n",
17691786
stream->oa_config->uuid);
17701787

1771-
WRITE_ONCE(u->exclusive_stream, stream);
1788+
WRITE_ONCE(stream->oa_unit->exclusive_stream, stream);
17721789

17731790
hrtimer_setup(&stream->poll_check_timer, xe_oa_poll_check_timer_cb, CLOCK_MONOTONIC,
17741791
HRTIMER_MODE_REL);
@@ -1804,7 +1821,7 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
18041821
int ret;
18051822

18061823
/* We currently only allow exclusive access */
1807-
if (param->hwe->oa_unit->exclusive_stream) {
1824+
if (param->oa_unit->exclusive_stream) {
18081825
drm_dbg(&oa->xe->drm, "OA unit already in use\n");
18091826
ret = -EBUSY;
18101827
goto exit;
@@ -1880,9 +1897,9 @@ static u64 oa_exponent_to_ns(struct xe_gt *gt, int exponent)
18801897
return div_u64(nom + den - 1, den);
18811898
}
18821899

1883-
static bool engine_supports_oa_format(const struct xe_hw_engine *hwe, int type)
1900+
static bool oa_unit_supports_oa_format(struct xe_oa_open_param *param, int type)
18841901
{
1885-
switch (hwe->oa_unit->type) {
1902+
switch (param->oa_unit->type) {
18861903
case DRM_XE_OA_UNIT_TYPE_OAG:
18871904
return type == DRM_XE_OA_FMT_TYPE_OAG || type == DRM_XE_OA_FMT_TYPE_OAR ||
18881905
type == DRM_XE_OA_FMT_TYPE_OAC || type == DRM_XE_OA_FMT_TYPE_PEC;
@@ -1922,18 +1939,18 @@ static int xe_oa_assign_hwe(struct xe_oa *oa, struct xe_oa_open_param *param)
19221939
/* Else just get the first hwe attached to the oa unit */
19231940
for_each_gt(gt, oa->xe, i) {
19241941
for_each_hw_engine(hwe, gt, id) {
1925-
if (xe_oa_unit_id(hwe) == param->oa_unit_id) {
1942+
if (hwe->oa_unit == param->oa_unit) {
19261943
param->hwe = hwe;
19271944
goto out;
19281945
}
19291946
}
19301947
}
19311948
}
19321949
out:
1933-
if (!param->hwe || xe_oa_unit_id(param->hwe) != param->oa_unit_id) {
1950+
if (!param->hwe || param->hwe->oa_unit != param->oa_unit) {
19341951
drm_dbg(&oa->xe->drm, "Unable to find hwe (%d, %d) for OA unit ID %d\n",
19351952
param->exec_q ? param->exec_q->class : -1,
1936-
param->engine_instance, param->oa_unit_id);
1953+
param->engine_instance, param->oa_unit->oa_unit_id);
19371954
ret = -EINVAL;
19381955
}
19391956

@@ -2014,7 +2031,7 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *f
20142031

20152032
f = &oa->oa_formats[param.oa_format];
20162033
if (!param.oa_format || !f->size ||
2017-
!engine_supports_oa_format(param.hwe, f->type)) {
2034+
!oa_unit_supports_oa_format(&param, f->type)) {
20182035
drm_dbg(&oa->xe->drm, "Invalid OA format %d type %d size %d for class %d\n",
20192036
param.oa_format, f->type, f->size, param.hwe->class);
20202037
ret = -EINVAL;

drivers/gpu/drm/xe/xe_oa_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ struct xe_oa_stream {
182182
/** @gt: gt associated with the oa stream */
183183
struct xe_gt *gt;
184184

185+
/** @oa_unit: oa unit for this stream */
186+
struct xe_oa_unit *oa_unit;
187+
185188
/** @hwe: hardware engine associated with this oa stream */
186189
struct xe_hw_engine *hwe;
187190

0 commit comments

Comments
 (0)