Skip to content

Commit da22013

Browse files
Alan Coxgregkh
authored andcommitted
atomisp: remove indirection from sh_css_malloc
We have one hard coded set of behaviour so unpick the indirection and function pointers. This isn't the whole story. A lot of the callers are known sizes and use cases so we can switch them directly to kmalloc later on. Signed-off-by: Alan Cox <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 83fceac commit da22013

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed

drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,6 @@ int atomisp_css_load_firmware(struct atomisp_device *isp)
923923
isp->css_env.isp_css_fw.data = (void *)isp->firmware->data;
924924
isp->css_env.isp_css_fw.bytes = isp->firmware->size;
925925

926-
isp->css_env.isp_css_env.cpu_mem_env.alloc = atomisp_kernel_zalloc;
927-
isp->css_env.isp_css_env.cpu_mem_env.free = atomisp_kernel_free;
928-
929926
isp->css_env.isp_css_env.hw_access_env.store_8 =
930927
atomisp_css2_hw_store_8;
931928
isp->css_env.isp_css_env.hw_access_env.store_16 =

drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,8 @@ enum ia_css_mem_attr {
3939
* This is never expected to allocate more than one page of memory (4K bytes).
4040
*/
4141
struct ia_css_cpu_mem_env {
42-
void * (*alloc)(size_t bytes, bool zero_mem);
43-
/**< Allocation function with boolean argument to indicate whether
44-
the allocated memory should be zeroed out or not, true (or 1)
45-
meaning the memory given to CSS must be zeroed */
46-
void (*free)(void *ptr);
47-
/**< Corresponding free function. The function must also accept
48-
a NULL argument, similar to C89 free(). */
4942
void (*flush)(struct ia_css_acc_fw *fw);
5043
/**< Flush function to flush the cache for given accelerator. */
51-
#ifdef ISP2401
52-
53-
#if !defined(__SVOS__)
54-
/* a set of matching functions with additional debug params */
55-
void * (*alloc_ex)(size_t bytes, bool zero_mem, const char *caller_func, int caller_line);
56-
/**< same as alloc above, only with additional debug parameters */
57-
void (*free_ex)(void *ptr, const char *caller_func, int caller_line);
58-
/**< same as free above, only with additional debug parameters */
59-
#endif
60-
#endif
6144
};
6245

6346
/** Environment with function pointers to access the CSS hardware. This includes
@@ -103,7 +86,7 @@ struct ia_css_print_env {
10386
* Windows and several simulation environments.
10487
*/
10588
struct ia_css_env {
106-
struct ia_css_cpu_mem_env cpu_mem_env; /**< local malloc and free. */
89+
struct ia_css_cpu_mem_env cpu_mem_env; /**< local flush. */
10790
struct ia_css_hw_access_env hw_access_env; /**< CSS HW access functions */
10891
struct ia_css_print_env print_env; /**< Message printing env. */
10992
};

drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
*/
1414

1515
/*! \file */
16+
#include <linux/mm.h>
17+
#include <linux/slab.h>
18+
#include <linux/vmalloc.h>
19+
1620
#include "ia_css.h"
1721
#include "sh_css_hrt.h" /* only for file 2 MIPI */
1822
#include "ia_css_buffer.h"
@@ -1679,15 +1683,8 @@ ia_css_load_firmware(const struct ia_css_env *env,
16791683
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_load_firmware() enter\n");
16801684

16811685
/* make sure we initialize my_css */
1682-
if ((my_css.malloc != env->cpu_mem_env.alloc) ||
1683-
(my_css.free != env->cpu_mem_env.free) ||
1684-
(my_css.flush != env->cpu_mem_env.flush)
1685-
)
1686-
{
1686+
if (my_css.flush != env->cpu_mem_env.flush) {
16871687
ia_css_reset_defaults(&my_css);
1688-
1689-
my_css.malloc = env->cpu_mem_env.alloc;
1690-
my_css.free = env->cpu_mem_env.free;
16911688
my_css.flush = env->cpu_mem_env.flush;
16921689
}
16931690

@@ -1715,8 +1712,6 @@ ia_css_init(const struct ia_css_env *env,
17151712
ia_css_blctrl_cfg blctrl_cfg;
17161713
#endif
17171714

1718-
void *(*malloc_func)(size_t size, bool zero_mem);
1719-
void (*free_func)(void *ptr);
17201715
void (*flush_func)(struct ia_css_acc_fw *fw);
17211716
hrt_data select, enable;
17221717

@@ -1765,8 +1760,6 @@ ia_css_init(const struct ia_css_env *env,
17651760

17661761
IA_CSS_ENTER("void");
17671762

1768-
malloc_func = env->cpu_mem_env.alloc;
1769-
free_func = env->cpu_mem_env.free;
17701763
flush_func = env->cpu_mem_env.flush;
17711764

17721765
pipe_global_init();
@@ -1786,16 +1779,9 @@ ia_css_init(const struct ia_css_env *env,
17861779
ia_css_save_mmu_base_addr(mmu_l1_base);
17871780
#endif
17881781

1789-
if (malloc_func == NULL || free_func == NULL) {
1790-
IA_CSS_LEAVE_ERR(IA_CSS_ERR_INVALID_ARGUMENTS);
1791-
return IA_CSS_ERR_INVALID_ARGUMENTS;
1792-
}
1793-
17941782
ia_css_reset_defaults(&my_css);
17951783

17961784
my_css_save.driver_env = *env;
1797-
my_css.malloc = malloc_func;
1798-
my_css.free = free_func;
17991785
my_css.flush = flush_func;
18001786

18011787
err = ia_css_rmgr_init();
@@ -2018,25 +2004,35 @@ ia_css_enable_isys_event_queue(bool enable)
20182004
void *sh_css_malloc(size_t size)
20192005
{
20202006
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "sh_css_malloc() enter: size=%d\n",size);
2021-
if (size > 0 && my_css.malloc)
2022-
return my_css.malloc(size, false);
2023-
return NULL;
2007+
/* FIXME: This first test can probably go away */
2008+
if (size == 0)
2009+
return NULL;
2010+
if (size > PAGE_SIZE)
2011+
return vmalloc(size);
2012+
return kmalloc(size, GFP_KERNEL);
20242013
}
20252014

20262015
void *sh_css_calloc(size_t N, size_t size)
20272016
{
2017+
void *p;
2018+
20282019
ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "sh_css_calloc() enter: N=%d, size=%d\n",N,size);
2029-
if (size > 0 && my_css.malloc)
2030-
return my_css.malloc(N*size, true);
2020+
2021+
/* FIXME: this test can probably go away */
2022+
if (size > 0) {
2023+
p = sh_css_malloc(N*size);
2024+
if (p)
2025+
memset(p, 0, size);
2026+
}
20312027
return NULL;
20322028
}
20332029

20342030
void sh_css_free(void *ptr)
20352031
{
2036-
IA_CSS_ENTER_PRIVATE("ptr = %p", ptr);
2037-
if (ptr && my_css.free)
2038-
my_css.free(ptr);
2039-
IA_CSS_LEAVE_PRIVATE("void");
2032+
if (is_vmalloc_addr(ptr))
2033+
vfree(ptr);
2034+
else
2035+
kfree(ptr);
20402036
}
20412037

20422038
/* For Acceleration API: Flush FW (shared buffer pointer) arguments */

0 commit comments

Comments
 (0)