@@ -972,32 +972,36 @@ static ssize_t wa_bb_setup_utilization(struct xe_lrc *lrc, struct xe_hw_engine *
972
972
return cmd - batch ;
973
973
}
974
974
975
- struct wa_bb_setup {
975
+ struct bo_setup {
976
976
ssize_t (* setup )(struct xe_lrc * lrc , struct xe_hw_engine * hwe ,
977
977
u32 * batch , size_t max_size );
978
978
};
979
979
980
- static int setup_wa_bb (struct xe_lrc * lrc , struct xe_hw_engine * hwe )
980
+ static u32 * setup_bo (struct xe_lrc * lrc ,
981
+ struct xe_hw_engine * hwe ,
982
+ const size_t max_size ,
983
+ unsigned int offset ,
984
+ const struct bo_setup * funcs ,
985
+ unsigned int num_funcs ,
986
+ u32 * * free )
981
987
{
982
- const size_t max_size = LRC_WA_BB_SIZE ;
983
- static const struct wa_bb_setup funcs [] = {
984
- { .setup = wa_bb_setup_utilization },
985
- };
986
- ssize_t remain ;
987
988
u32 * cmd , * buf = NULL ;
989
+ ssize_t remain ;
988
990
989
991
if (lrc -> bo -> vmap .is_iomem ) {
990
992
buf = kmalloc (max_size , GFP_KERNEL );
991
993
if (!buf )
992
- return - ENOMEM ;
994
+ return ERR_PTR ( - ENOMEM ) ;
993
995
cmd = buf ;
996
+ * free = buf ;
994
997
} else {
995
- cmd = lrc -> bo -> vmap .vaddr + __xe_lrc_wa_bb_offset (lrc );
998
+ cmd = lrc -> bo -> vmap .vaddr + offset ;
999
+ * free = NULL ;
996
1000
}
997
1001
998
1002
remain = max_size / sizeof (* cmd );
999
1003
1000
- for (size_t i = 0 ; i < ARRAY_SIZE ( funcs ) ; i ++ ) {
1004
+ for (size_t i = 0 ; i < num_funcs ; i ++ ) {
1001
1005
ssize_t len = funcs [i ].setup (lrc , hwe , cmd , remain );
1002
1006
1003
1007
remain -= len ;
@@ -1012,23 +1016,45 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
1012
1016
cmd += len ;
1013
1017
}
1014
1018
1019
+ return cmd ;
1020
+
1021
+ fail :
1022
+ kfree (buf );
1023
+ return ERR_PTR (- ENOSPC );
1024
+ }
1025
+
1026
+ static void finish_bo (struct xe_lrc * lrc , unsigned int offset , u32 * cmd ,
1027
+ u32 * free )
1028
+ {
1029
+ if (!free )
1030
+ return ;
1031
+
1032
+ xe_map_memcpy_to (gt_to_xe (lrc -> gt ), & lrc -> bo -> vmap , offset , free ,
1033
+ (cmd - free ) * sizeof (* cmd ));
1034
+ kfree (free );
1035
+ }
1036
+
1037
+ static int setup_wa_bb (struct xe_lrc * lrc , struct xe_hw_engine * hwe )
1038
+ {
1039
+ static const struct bo_setup funcs [] = {
1040
+ { .setup = wa_bb_setup_utilization },
1041
+ };
1042
+ unsigned int offset = __xe_lrc_wa_bb_offset (lrc );
1043
+ u32 * cmd , * buf = NULL ;
1044
+
1045
+ cmd = setup_bo (lrc , hwe , LRC_WA_BB_SIZE , offset , funcs ,
1046
+ ARRAY_SIZE (funcs ), & buf );
1047
+ if (IS_ERR (cmd ))
1048
+ return PTR_ERR (cmd );
1049
+
1015
1050
* cmd ++ = MI_BATCH_BUFFER_END ;
1016
1051
1017
- if (buf ) {
1018
- xe_map_memcpy_to (gt_to_xe (lrc -> gt ), & lrc -> bo -> vmap ,
1019
- __xe_lrc_wa_bb_offset (lrc ), buf ,
1020
- (cmd - buf ) * sizeof (* cmd ));
1021
- kfree (buf );
1022
- }
1052
+ finish_bo (lrc , offset , cmd , buf );
1023
1053
1024
- xe_lrc_write_ctx_reg (lrc , CTX_BB_PER_CTX_PTR , xe_bo_ggtt_addr ( lrc -> bo ) +
1025
- __xe_lrc_wa_bb_offset (lrc ) + 1 );
1054
+ xe_lrc_write_ctx_reg (lrc , CTX_BB_PER_CTX_PTR ,
1055
+ xe_bo_ggtt_addr (lrc -> bo ) + offset + 1 );
1026
1056
1027
1057
return 0 ;
1028
-
1029
- fail :
1030
- kfree (buf );
1031
- return - ENOSPC ;
1032
1058
}
1033
1059
1034
1060
#define PVC_CTX_ASID (0x2e + 1)
0 commit comments