From patchwork Wed Apr 12 18:21:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Cox X-Patchwork-Id: 40773 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cyMtq-0003ys-S2; Wed, 12 Apr 2017 18:21:50 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-7) with esmtp id 1cyMto-0002va-24; Wed, 12 Apr 2017 20:21:50 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755218AbdDLSVq (ORCPT + 1 other); Wed, 12 Apr 2017 14:21:46 -0400 Received: from mga01.intel.com ([192.55.52.88]:60281 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754684AbdDLSVp (ORCPT ); Wed, 12 Apr 2017 14:21:45 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Apr 2017 11:21:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,191,1488873600"; d="scan'208";a="1134574846" Received: from acox1-desk1.ger.corp.intel.com ([10.252.16.134]) by fmsmga001.fm.intel.com with ESMTP; 12 Apr 2017 11:21:36 -0700 Subject: [PATCH 08/14] atomisp: remove indirection from sh_css_malloc From: Alan Cox To: greg@kroah.com, linux-media@vger.kernel.org Date: Wed, 12 Apr 2017 19:21:33 +0100 Message-ID: <149202128908.16615.8884323049461863996.stgit@acox1-desk1.ger.corp.intel.com> In-Reply-To: <149202119790.16615.4841216953457109397.stgit@acox1-desk1.ger.corp.intel.com> References: <149202119790.16615.4841216953457109397.stgit@acox1-desk1.ger.corp.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2017.4.12.181517 X-PMX-Spam: Gauge=X, Probability=10%, Report=' HASHBUSTER_BLOCK_V2 0.5, HTML_00_01 0.05, HTML_00_10 0.05, MSGID_ADDED_BY_MTA 0.05, BODY_SIZE_6000_6999 0, BODY_SIZE_7000_LESS 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, NO_URI_HTTPS 0, REFERENCES 0, __ANY_URI 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FRAUD_MONEY_BIG_COIN 0, __FRAUD_MONEY_BIG_COIN_DIG 0, __HASHBUSTER_BLOCK_V2_1 0, __HAS_FROM 0, __HAS_LIST_ID 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' 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 --- .../atomisp/pci/atomisp2/atomisp_compat_css20.c | 3 - .../atomisp/pci/atomisp2/css2400/ia_css_env.h | 19 ------- .../media/atomisp/pci/atomisp2/css2400/sh_css.c | 52 +++++++++----------- 3 files changed, 25 insertions(+), 49 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c index 6586842..b830b24 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/atomisp_compat_css20.c @@ -923,9 +923,6 @@ int atomisp_css_load_firmware(struct atomisp_device *isp) isp->css_env.isp_css_fw.data = (void *)isp->firmware->data; isp->css_env.isp_css_fw.bytes = isp->firmware->size; - isp->css_env.isp_css_env.cpu_mem_env.alloc = atomisp_kernel_zalloc; - isp->css_env.isp_css_env.cpu_mem_env.free = atomisp_kernel_free; - isp->css_env.isp_css_env.hw_access_env.store_8 = atomisp_css2_hw_store_8; isp->css_env.isp_css_env.hw_access_env.store_16 = diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h index 4d54aea..1ae9daf 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h @@ -39,25 +39,8 @@ enum ia_css_mem_attr { * This is never expected to allocate more than one page of memory (4K bytes). */ struct ia_css_cpu_mem_env { - void * (*alloc)(size_t bytes, bool zero_mem); - /**< Allocation function with boolean argument to indicate whether - the allocated memory should be zeroed out or not, true (or 1) - meaning the memory given to CSS must be zeroed */ - void (*free)(void *ptr); - /**< Corresponding free function. The function must also accept - a NULL argument, similar to C89 free(). */ void (*flush)(struct ia_css_acc_fw *fw); /**< Flush function to flush the cache for given accelerator. */ -#ifdef ISP2401 - - #if !defined(__SVOS__) - /* a set of matching functions with additional debug params */ - void * (*alloc_ex)(size_t bytes, bool zero_mem, const char *caller_func, int caller_line); - /**< same as alloc above, only with additional debug parameters */ - void (*free_ex)(void *ptr, const char *caller_func, int caller_line); - /**< same as free above, only with additional debug parameters */ - #endif -#endif }; /** Environment with function pointers to access the CSS hardware. This includes @@ -103,7 +86,7 @@ struct ia_css_print_env { * Windows and several simulation environments. */ struct ia_css_env { - struct ia_css_cpu_mem_env cpu_mem_env; /**< local malloc and free. */ + struct ia_css_cpu_mem_env cpu_mem_env; /**< local flush. */ struct ia_css_hw_access_env hw_access_env; /**< CSS HW access functions */ struct ia_css_print_env print_env; /**< Message printing env. */ }; diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c index aa19419..30f7196 100644 --- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c +++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c @@ -13,6 +13,10 @@ */ /*! \file */ +#include +#include +#include + #include "ia_css.h" #include "sh_css_hrt.h" /* only for file 2 MIPI */ #include "ia_css_buffer.h" @@ -1679,15 +1683,8 @@ ia_css_load_firmware(const struct ia_css_env *env, ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_load_firmware() enter\n"); /* make sure we initialize my_css */ - if ((my_css.malloc != env->cpu_mem_env.alloc) || - (my_css.free != env->cpu_mem_env.free) || - (my_css.flush != env->cpu_mem_env.flush) - ) - { + if (my_css.flush != env->cpu_mem_env.flush) { ia_css_reset_defaults(&my_css); - - my_css.malloc = env->cpu_mem_env.alloc; - my_css.free = env->cpu_mem_env.free; my_css.flush = env->cpu_mem_env.flush; } @@ -1715,8 +1712,6 @@ ia_css_init(const struct ia_css_env *env, ia_css_blctrl_cfg blctrl_cfg; #endif - void *(*malloc_func)(size_t size, bool zero_mem); - void (*free_func)(void *ptr); void (*flush_func)(struct ia_css_acc_fw *fw); hrt_data select, enable; @@ -1765,8 +1760,6 @@ ia_css_init(const struct ia_css_env *env, IA_CSS_ENTER("void"); - malloc_func = env->cpu_mem_env.alloc; - free_func = env->cpu_mem_env.free; flush_func = env->cpu_mem_env.flush; pipe_global_init(); @@ -1786,16 +1779,9 @@ ia_css_init(const struct ia_css_env *env, ia_css_save_mmu_base_addr(mmu_l1_base); #endif - if (malloc_func == NULL || free_func == NULL) { - IA_CSS_LEAVE_ERR(IA_CSS_ERR_INVALID_ARGUMENTS); - return IA_CSS_ERR_INVALID_ARGUMENTS; - } - ia_css_reset_defaults(&my_css); my_css_save.driver_env = *env; - my_css.malloc = malloc_func; - my_css.free = free_func; my_css.flush = flush_func; err = ia_css_rmgr_init(); @@ -2018,25 +2004,35 @@ ia_css_enable_isys_event_queue(bool enable) void *sh_css_malloc(size_t size) { ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "sh_css_malloc() enter: size=%d\n",size); - if (size > 0 && my_css.malloc) - return my_css.malloc(size, false); - return NULL; + /* FIXME: This first test can probably go away */ + if (size == 0) + return NULL; + if (size > PAGE_SIZE) + return vmalloc(size); + return kmalloc(size, GFP_KERNEL); } void *sh_css_calloc(size_t N, size_t size) { + void *p; + ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "sh_css_calloc() enter: N=%d, size=%d\n",N,size); - if (size > 0 && my_css.malloc) - return my_css.malloc(N*size, true); + + /* FIXME: this test can probably go away */ + if (size > 0) { + p = sh_css_malloc(N*size); + if (p) + memset(p, 0, size); + } return NULL; } void sh_css_free(void *ptr) { - IA_CSS_ENTER_PRIVATE("ptr = %p", ptr); - if (ptr && my_css.free) - my_css.free(ptr); - IA_CSS_LEAVE_PRIVATE("void"); + if (is_vmalloc_addr(ptr)) + vfree(ptr); + else + kfree(ptr); } /* For Acceleration API: Flush FW (shared buffer pointer) arguments */