@@ -977,82 +977,95 @@ struct bo_setup {
977
977
u32 * batch , size_t max_size );
978
978
};
979
979
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 )
987
- {
988
- u32 * cmd , * buf = NULL ;
980
+ struct bo_setup_state {
981
+ /* Input: */
982
+ struct xe_lrc * lrc ;
983
+ struct xe_hw_engine * hwe ;
984
+ size_t max_size ;
985
+ unsigned int offset ;
986
+ const struct bo_setup * funcs ;
987
+ unsigned int num_funcs ;
988
+
989
+ /* State: */
990
+ u32 * buffer ;
991
+ u32 * ptr ;
992
+ };
993
+
994
+ static int setup_bo (struct bo_setup_state * state )
995
+ {
989
996
ssize_t remain ;
990
997
991
- if (lrc -> bo -> vmap .is_iomem ) {
992
- buf = kmalloc (max_size , GFP_KERNEL );
993
- if (!buf )
994
- return ERR_PTR (- ENOMEM );
995
- cmd = buf ;
996
- * free = buf ;
998
+ if (state -> lrc -> bo -> vmap .is_iomem ) {
999
+ state -> buffer = kmalloc (state -> max_size , GFP_KERNEL );
1000
+ if (!state -> buffer )
1001
+ return - ENOMEM ;
1002
+ state -> ptr = state -> buffer ;
997
1003
} else {
998
- cmd = lrc -> bo -> vmap .vaddr + offset ;
999
- * free = NULL ;
1004
+ state -> ptr = state -> lrc -> bo -> vmap .vaddr + state -> offset ;
1005
+ state -> buffer = NULL ;
1000
1006
}
1001
1007
1002
- remain = max_size / sizeof (* cmd );
1008
+ remain = state -> max_size / sizeof (u32 );
1003
1009
1004
- for (size_t i = 0 ; i < num_funcs ; i ++ ) {
1005
- ssize_t len = funcs [i ].setup (lrc , hwe , cmd , remain );
1010
+ for (size_t i = 0 ; i < state -> num_funcs ; i ++ ) {
1011
+ ssize_t len = state -> funcs [i ].setup (state -> lrc , state -> hwe ,
1012
+ state -> ptr , remain );
1006
1013
1007
1014
remain -= len ;
1008
1015
1009
1016
/*
1010
1017
* There should always be at least 1 additional dword for
1011
1018
* the end marker
1012
1019
*/
1013
- if (len < 0 || xe_gt_WARN_ON (lrc -> gt , remain < 1 ))
1020
+ if (len < 0 || xe_gt_WARN_ON (state -> lrc -> gt , remain < 1 ))
1014
1021
goto fail ;
1015
1022
1016
- cmd += len ;
1023
+ state -> ptr += len ;
1017
1024
}
1018
1025
1019
- return cmd ;
1026
+ return 0 ;
1020
1027
1021
1028
fail :
1022
- kfree (buf );
1023
- return ERR_PTR ( - ENOSPC ) ;
1029
+ kfree (state -> buffer );
1030
+ return - ENOSPC ;
1024
1031
}
1025
1032
1026
- static void finish_bo (struct xe_lrc * lrc , unsigned int offset , u32 * cmd ,
1027
- u32 * free )
1033
+ static void finish_bo (struct bo_setup_state * state )
1028
1034
{
1029
- if (!free )
1035
+ if (!state -> buffer )
1030
1036
return ;
1031
1037
1032
- xe_map_memcpy_to (gt_to_xe (lrc -> gt ), & lrc -> bo -> vmap , offset , free ,
1033
- (cmd - free ) * sizeof (* cmd ));
1034
- kfree (free );
1038
+ xe_map_memcpy_to (gt_to_xe (state -> lrc -> gt ), & state -> lrc -> bo -> vmap ,
1039
+ state -> offset , state -> buffer ,
1040
+ (state -> ptr - state -> buffer ) * sizeof (u32 ));
1041
+ kfree (state -> buffer );
1035
1042
}
1036
1043
1037
1044
static int setup_wa_bb (struct xe_lrc * lrc , struct xe_hw_engine * hwe )
1038
1045
{
1039
1046
static const struct bo_setup funcs [] = {
1040
1047
{ .setup = wa_bb_setup_utilization },
1041
1048
};
1042
- unsigned int offset = __xe_lrc_wa_bb_offset (lrc );
1043
- u32 * cmd , * buf = NULL ;
1049
+ struct bo_setup_state state = {
1050
+ .lrc = lrc ,
1051
+ .hwe = hwe ,
1052
+ .max_size = LRC_WA_BB_SIZE ,
1053
+ .offset = __xe_lrc_wa_bb_offset (lrc ),
1054
+ .funcs = funcs ,
1055
+ .num_funcs = ARRAY_SIZE (funcs ),
1056
+ };
1057
+ int ret ;
1044
1058
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 );
1059
+ ret = setup_bo (& state );
1060
+ if (ret )
1061
+ return ret ;
1049
1062
1050
- * cmd ++ = MI_BATCH_BUFFER_END ;
1063
+ * state . ptr ++ = MI_BATCH_BUFFER_END ;
1051
1064
1052
- finish_bo (lrc , offset , cmd , buf );
1065
+ finish_bo (& state );
1053
1066
1054
1067
xe_lrc_write_ctx_reg (lrc , CTX_BB_PER_CTX_PTR ,
1055
- xe_bo_ggtt_addr (lrc -> bo ) + offset + 1 );
1068
+ xe_bo_ggtt_addr (lrc -> bo ) + state . offset + 1 );
1056
1069
1057
1070
return 0 ;
1058
1071
}
0 commit comments