77
88#include <kunit/visibility.h>
99
10+ #include <drm/drm_managed.h>
11+
1012#include "regs/xe_gt_regs.h"
1113#include "xe_gt_types.h"
1214#include "xe_platform_types.h"
@@ -140,10 +142,44 @@ static const struct xe_rtp_entry_sr lrc_tunings[] = {
140142 {}
141143};
142144
145+ /**
146+ * xe_tuning_init - initialize gt with tunings bookkeeping
147+ * @gt: GT instance to initialize
148+ *
149+ * Returns 0 for success, negative error code otherwise.
150+ */
151+ int xe_tuning_init (struct xe_gt * gt )
152+ {
153+ struct xe_device * xe = gt_to_xe (gt );
154+ size_t n_lrc , n_engine , n_gt , total ;
155+ unsigned long * p ;
156+
157+ n_gt = BITS_TO_LONGS (ARRAY_SIZE (gt_tunings ));
158+ n_engine = BITS_TO_LONGS (ARRAY_SIZE (engine_tunings ));
159+ n_lrc = BITS_TO_LONGS (ARRAY_SIZE (lrc_tunings ));
160+ total = n_gt + n_engine + n_lrc ;
161+
162+ p = drmm_kzalloc (& xe -> drm , sizeof (* p ) * total , GFP_KERNEL );
163+ if (!p )
164+ return - ENOMEM ;
165+
166+ gt -> tuning_active .gt = p ;
167+ p += n_gt ;
168+ gt -> tuning_active .engine = p ;
169+ p += n_engine ;
170+ gt -> tuning_active .lrc = p ;
171+
172+ return 0 ;
173+ }
174+ ALLOW_ERROR_INJECTION (xe_tuning_init , ERRNO ); /* See xe_pci_probe() */
175+
143176void xe_tuning_process_gt (struct xe_gt * gt )
144177{
145178 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER (gt );
146179
180+ xe_rtp_process_ctx_enable_active_tracking (& ctx ,
181+ gt -> tuning_active .gt ,
182+ ARRAY_SIZE (gt_tunings ));
147183 xe_rtp_process_to_sr (& ctx , gt_tunings , & gt -> reg_sr );
148184}
149185EXPORT_SYMBOL_IF_KUNIT (xe_tuning_process_gt );
@@ -152,6 +188,9 @@ void xe_tuning_process_engine(struct xe_hw_engine *hwe)
152188{
153189 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER (hwe );
154190
191+ xe_rtp_process_ctx_enable_active_tracking (& ctx ,
192+ hwe -> gt -> tuning_active .engine ,
193+ ARRAY_SIZE (engine_tunings ));
155194 xe_rtp_process_to_sr (& ctx , engine_tunings , & hwe -> reg_sr );
156195}
157196EXPORT_SYMBOL_IF_KUNIT (xe_tuning_process_engine );
@@ -168,5 +207,25 @@ void xe_tuning_process_lrc(struct xe_hw_engine *hwe)
168207{
169208 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER (hwe );
170209
210+ xe_rtp_process_ctx_enable_active_tracking (& ctx ,
211+ hwe -> gt -> tuning_active .lrc ,
212+ ARRAY_SIZE (lrc_tunings ));
171213 xe_rtp_process_to_sr (& ctx , lrc_tunings , & hwe -> reg_lrc );
172214}
215+
216+ void xe_tuning_dump (struct xe_gt * gt , struct drm_printer * p )
217+ {
218+ size_t idx ;
219+
220+ drm_printf (p , "GT Tunings\n" );
221+ for_each_set_bit (idx , gt -> tuning_active .gt , ARRAY_SIZE (gt_tunings ))
222+ drm_printf_indent (p , 1 , "%s\n" , gt_tunings [idx ].name );
223+
224+ drm_printf (p , "\nEngine Tunings\n" );
225+ for_each_set_bit (idx , gt -> tuning_active .engine , ARRAY_SIZE (engine_tunings ))
226+ drm_printf_indent (p , 1 , "%s\n" , engine_tunings [idx ].name );
227+
228+ drm_printf (p , "\nLRC Tunings\n" );
229+ for_each_set_bit (idx , gt -> tuning_active .lrc , ARRAY_SIZE (lrc_tunings ))
230+ drm_printf_indent (p , 1 , "%s\n" , lrc_tunings [idx ].name );
231+ }
0 commit comments