@@ -218,6 +218,32 @@ static const char *const sm_cache_map_vector[] = {
218
218
};
219
219
#endif
220
220
221
+ typedef void cache_flush_op_fn (const void * , const void * );
222
+
223
+ #if defined(CONFIG_CPU_CACHE_V7 )
224
+ extern cache_flush_op_fn v7_dma_inv_range ;
225
+ extern cache_flush_op_fn v7_dma_clean_range ;
226
+ static cache_flush_op_fn * const flushops [4 ] =
227
+ {
228
+ 0 ,
229
+ v7_dma_inv_range ,
230
+ v7_dma_clean_range ,
231
+ v7_dma_flush_range ,
232
+ };
233
+ #elif defined(CONFIG_CPU_CACHE_V6 )
234
+ extern cache_flush_op_fn v6_dma_inv_range ;
235
+ extern cache_flush_op_fn v6_dma_clean_range ;
236
+ static cache_flush_op_fn * const flushops [4 ] =
237
+ {
238
+ 0 ,
239
+ v6_dma_inv_range ,
240
+ v6_dma_clean_range ,
241
+ v6_dma_flush_range ,
242
+ };
243
+ #else
244
+ #error Unknown cache config
245
+ #endif
246
+
221
247
/* ---- Private Function Prototypes -------------------------------------- */
222
248
223
249
/* ---- Private Functions ------------------------------------------------ */
@@ -2984,7 +3010,7 @@ static long vc_sm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2984
3010
ret = - EFAULT ;
2985
3011
goto out ;
2986
3012
}
2987
- block = kcalloc (ioparam .op_count ,
3013
+ block = kmalloc (ioparam .op_count *
2988
3014
sizeof (struct vmcs_sm_ioctl_clean_invalid_block ),
2989
3015
GFP_KERNEL );
2990
3016
if (!block ) {
@@ -3000,35 +3026,21 @@ static long vc_sm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3000
3026
}
3001
3027
3002
3028
for (i = 0 ; i < ioparam .op_count ; i ++ ) {
3003
- struct vmcs_sm_ioctl_clean_invalid_block * op = block + i ;
3029
+ const struct vmcs_sm_ioctl_clean_invalid_block * const op = block + i ;
3030
+ cache_flush_op_fn * const op_fn = flushops [op -> invalidate_mode & 3 ];
3004
3031
3005
- for (j = 0 ; j < op -> block_count ; ++ j ) {
3032
+ if ((op -> invalidate_mode & ~3 ) != 0 ) {
3033
+ ret = - EINVAL ;
3034
+ break ;
3035
+ }
3006
3036
3037
+ if (op_fn == 0 )
3038
+ continue ;
3007
3039
3008
- extern void v6_dma_inv_range (void * start , void * end );
3009
- extern void v6_dma_clean_range (void * start , void * end );
3010
- unsigned long base = (unsigned long )op -> start_address + j * op -> inter_block_stride ;
3011
- unsigned long end = base + op -> block_size ;
3012
- /* L1/L2 cache clean */
3013
- if (op -> invalidate_mode & 2 ) {
3014
- #if defined(CONFIG_CPU_CACHE_V7 )
3015
- extern void v7_dma_clean_range (void * start , void * end );
3016
- v7_dma_clean_range ((void * )base , (void * )end );
3017
- #elif defined(CONFIG_CPU_CACHE_V6 )
3018
- extern void v6_dma_clean_range (void * start , void * end );
3019
- v6_dma_clean_range ((void * )base , (void * )end );
3020
- #endif
3021
- /* L1/L2 cache invalidate */
3022
- }
3023
- if (op -> invalidate_mode & 1 ) {
3024
- #if defined(CONFIG_CPU_CACHE_V7 )
3025
- extern void v7_dma_inv_range (void * start , void * end );
3026
- v7_dma_inv_range ((void * )base , (void * )end );
3027
- #elif defined(CONFIG_CPU_CACHE_V6 )
3028
- extern void v6_dma_inv_range (void * start , void * end );
3029
- v6_dma_inv_range ((void * )base , (void * )end );
3030
- #endif
3031
- }
3040
+ for (j = 0 ; j < op -> block_count ; ++ j ) {
3041
+ const char * const base = (const char * )op -> start_address + j * op -> inter_block_stride ;
3042
+ const char * const end = base + op -> block_size ;
3043
+ op_fn (base , end );
3032
3044
}
3033
3045
}
3034
3046
kfree (block );
0 commit comments