@@ -83,7 +83,7 @@ struct xe_oa_config {
83
83
84
84
struct xe_oa_open_param {
85
85
struct xe_file * xef ;
86
- u32 oa_unit_id ;
86
+ struct xe_oa_unit * oa_unit ;
87
87
bool sample ;
88
88
u32 metric_set ;
89
89
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
200
200
201
201
static const struct xe_oa_regs * __oa_regs (struct xe_oa_stream * stream )
202
202
{
203
- return & stream -> hwe -> oa_unit -> regs ;
203
+ return & stream -> oa_unit -> regs ;
204
204
}
205
205
206
206
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)
460
460
461
461
static u32 __oactrl_used_bits (struct xe_oa_stream * stream )
462
462
{
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 ?
464
464
OAG_OACONTROL_USED_BITS : OAM_OACONTROL_USED_BITS ;
465
465
}
466
466
@@ -481,7 +481,7 @@ static void xe_oa_enable(struct xe_oa_stream *stream)
481
481
__oa_ccs_select (stream ) | OAG_OACONTROL_OA_COUNTER_ENABLE ;
482
482
483
483
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 )
485
485
val |= OAG_OACONTROL_OA_PES_DISAG_EN ;
486
486
487
487
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)
848
848
849
849
static void xe_oa_stream_destroy (struct xe_oa_stream * stream )
850
850
{
851
- struct xe_oa_unit * u = stream -> hwe -> oa_unit ;
851
+ struct xe_oa_unit * u = stream -> oa_unit ;
852
852
struct xe_gt * gt = stream -> hwe -> gt ;
853
853
854
854
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
1145
1145
return - EINVAL ;
1146
1146
}
1147
1147
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
+
1148
1165
static int xe_oa_set_prop_oa_unit_id (struct xe_oa * oa , u64 value ,
1149
1166
struct xe_oa_open_param * param )
1150
1167
{
1151
- if (value >= oa -> oa_unit_ids ) {
1168
+ param -> oa_unit = xe_oa_lookup_oa_unit (oa , value );
1169
+ if (!param -> oa_unit ) {
1152
1170
drm_dbg (& oa -> xe -> drm , "OA unit ID out of range %lld\n" , value );
1153
1171
return - EINVAL ;
1154
1172
}
1155
- param -> oa_unit_id = value ;
1156
1173
return 0 ;
1157
1174
}
1158
1175
@@ -1683,13 +1700,13 @@ static const struct file_operations xe_oa_fops = {
1683
1700
static int xe_oa_stream_init (struct xe_oa_stream * stream ,
1684
1701
struct xe_oa_open_param * param )
1685
1702
{
1686
- struct xe_oa_unit * u = param -> hwe -> oa_unit ;
1687
1703
struct xe_gt * gt = param -> hwe -> gt ;
1688
1704
unsigned int fw_ref ;
1689
1705
int ret ;
1690
1706
1691
1707
stream -> exec_q = param -> exec_q ;
1692
1708
stream -> poll_period_ns = DEFAULT_POLL_PERIOD_NS ;
1709
+ stream -> oa_unit = param -> oa_unit ;
1693
1710
stream -> hwe = param -> hwe ;
1694
1711
stream -> gt = stream -> hwe -> gt ;
1695
1712
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,
1710
1727
* buffer whose size, circ_size, is a multiple of the report size
1711
1728
*/
1712
1729
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 )
1714
1731
stream -> oa_buffer .circ_size =
1715
1732
param -> oa_buffer_size -
1716
1733
param -> oa_buffer_size % stream -> oa_buffer .format -> size ;
@@ -1768,7 +1785,7 @@ static int xe_oa_stream_init(struct xe_oa_stream *stream,
1768
1785
drm_dbg (& stream -> oa -> xe -> drm , "opening stream oa config uuid=%s\n" ,
1769
1786
stream -> oa_config -> uuid );
1770
1787
1771
- WRITE_ONCE (u -> exclusive_stream , stream );
1788
+ WRITE_ONCE (stream -> oa_unit -> exclusive_stream , stream );
1772
1789
1773
1790
hrtimer_setup (& stream -> poll_check_timer , xe_oa_poll_check_timer_cb , CLOCK_MONOTONIC ,
1774
1791
HRTIMER_MODE_REL );
@@ -1804,7 +1821,7 @@ static int xe_oa_stream_open_ioctl_locked(struct xe_oa *oa,
1804
1821
int ret ;
1805
1822
1806
1823
/* We currently only allow exclusive access */
1807
- if (param -> hwe -> oa_unit -> exclusive_stream ) {
1824
+ if (param -> oa_unit -> exclusive_stream ) {
1808
1825
drm_dbg (& oa -> xe -> drm , "OA unit already in use\n" );
1809
1826
ret = - EBUSY ;
1810
1827
goto exit ;
@@ -1880,9 +1897,9 @@ static u64 oa_exponent_to_ns(struct xe_gt *gt, int exponent)
1880
1897
return div_u64 (nom + den - 1 , den );
1881
1898
}
1882
1899
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 )
1884
1901
{
1885
- switch (hwe -> oa_unit -> type ) {
1902
+ switch (param -> oa_unit -> type ) {
1886
1903
case DRM_XE_OA_UNIT_TYPE_OAG :
1887
1904
return type == DRM_XE_OA_FMT_TYPE_OAG || type == DRM_XE_OA_FMT_TYPE_OAR ||
1888
1905
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)
1922
1939
/* Else just get the first hwe attached to the oa unit */
1923
1940
for_each_gt (gt , oa -> xe , i ) {
1924
1941
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 ) {
1926
1943
param -> hwe = hwe ;
1927
1944
goto out ;
1928
1945
}
1929
1946
}
1930
1947
}
1931
1948
}
1932
1949
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 ) {
1934
1951
drm_dbg (& oa -> xe -> drm , "Unable to find hwe (%d, %d) for OA unit ID %d\n" ,
1935
1952
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 );
1937
1954
ret = - EINVAL ;
1938
1955
}
1939
1956
@@ -2014,7 +2031,7 @@ int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *f
2014
2031
2015
2032
f = & oa -> oa_formats [param .oa_format ];
2016
2033
if (!param .oa_format || !f -> size ||
2017
- !engine_supports_oa_format ( param . hwe , f -> type )) {
2034
+ !oa_unit_supports_oa_format ( & param , f -> type )) {
2018
2035
drm_dbg (& oa -> xe -> drm , "Invalid OA format %d type %d size %d for class %d\n" ,
2019
2036
param .oa_format , f -> type , f -> size , param .hwe -> class );
2020
2037
ret = - EINVAL ;
0 commit comments