From patchwork Sat May 20 06:48:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Yi" X-Patchwork-Id: 9738487 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F092C600C8 for ; Sat, 20 May 2017 06:53:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E57F0285BD for ; Sat, 20 May 2017 06:53:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9F72285C2; Sat, 20 May 2017 06:53:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47DCE285BD for ; Sat, 20 May 2017 06:53:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756819AbdETGxX (ORCPT ); Sat, 20 May 2017 02:53:23 -0400 Received: from mga09.intel.com ([134.134.136.24]:53531 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756818AbdETGxW (ORCPT ); Sat, 20 May 2017 02:53:22 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 May 2017 23:53:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,367,1491289200"; d="scan'208";a="1171971532" Received: from yi-patch.an.intel.com ([10.122.105.158]) by fmsmga002.fm.intel.com with ESMTP; 19 May 2017 23:53:19 -0700 From: yi1.li@linux.intel.com To: mcgrof@kernel.org, atull@kernel.org, gregkh@linuxfoundation.org, wagi@monom.org, dwmw2@infradead.org, rafal@milecki.pl, arend.vanspriel@broadcom.com, rjw@rjwysocki.net, moritz.fischer@ettus.com, pmladek@suse.com, johannes.berg@intel.com, emmanuel.grumbach@intel.com, luciano.coelho@intel.com, kvalo@codeaurora.org, luto@kernel.org, takahiro.akashi@linaro.org, dhowells@redhat.com, pjones@redhat.com Cc: linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, Yi Li Subject: [PATCHv2 1/2] firmware: Enable pre-allocated buffer support in driver_data Date: Sat, 20 May 2017 01:48:05 -0500 Message-Id: <1495262886-1045-2-git-send-email-yi1.li@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495262886-1045-1-git-send-email-yi1.li@linux.intel.com> References: <1495262886-1045-1-git-send-email-yi1.li@linux.intel.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yi Li This enables the equivalent feature of the legacy request_firmware_into_buf to driver_data, so caller can allocate and manage the firmware buffer instead of by driver_data class internally. The caller need to setup alloc_buf and alloc_buf_size in the @driver_data_req_params structure. Signed-off-by: Yi Li --- drivers/base/firmware_class.c | 21 ++++++++------------- include/linux/driver_data.h | 5 +++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 444c9a8..461c7c2 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -83,9 +83,6 @@ enum driver_data_priv_reqs { * @mode: mode of operation * @priv_reqs: private set of &enum driver_data_reqs, private requirements for * the driver data request - * @alloc_buf: buffer area allocated by the caller so we can place the - * respective driver data - * @alloc_buf_size: size of the @alloc_buf * @old_async_cb: used only for request_firmware_nowait() since we won't change * all async callbacks to get the return value on failure * @api: used internally for keeping track of the currently evaluated API @@ -98,8 +95,6 @@ enum driver_data_priv_reqs { struct driver_data_priv_params { enum driver_data_mode mode; u64 priv_reqs; - void *alloc_buf; - size_t alloc_buf_size; void (*old_async_cb)(const struct firmware *driver_data, void *context); u8 api; bool retry_api; @@ -149,12 +144,12 @@ struct driver_data_params { #define __DATA_REQ_FIRMWARE_BUF(buf, size) \ .req_params = { \ .reqs = DRIVER_DATA_REQ_NO_CACHE, \ + .alloc_buf = &buf, \ + .alloc_buf_size = size, \ }, \ .priv_params = { \ .priv_reqs = DRIVER_DATA_PRIV_REQ_FALLBACK | \ DRIVER_DATA_PRIV_REQ_FALLBACK_UEVENT, \ - .alloc_buf = buf, \ - .alloc_buf_size = size, \ } #define __DATA_REQ_FIRMWARE_NOWAIT(module, uevent, gfp, async_cb, async_ctx) \ @@ -265,9 +260,9 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name, void *buf; size_t size; - if (data_params) { - buf = data_params->priv_params.alloc_buf; - size = data_params->priv_params.alloc_buf_size; + if (data_params && data_params->req_params.alloc_buf) { + buf = *data_params->req_params.alloc_buf; + size = data_params->req_params.alloc_buf_size; } else { buf = NULL; size = 0; @@ -507,9 +502,9 @@ static struct firmware_buf *__allocate_fw_buf(const char *fw_name, void *dbuf; size_t size; - if (data_params) { - dbuf = data_params->priv_params.alloc_buf; - size = data_params->priv_params.alloc_buf_size; + if (data_params && data_params->req_params.alloc_buf) { + dbuf = *data_params->req_params.alloc_buf; + size = data_params->req_params.alloc_buf_size; } else { dbuf = NULL; size = 0; diff --git a/include/linux/driver_data.h b/include/linux/driver_data.h index b6ef5ee..a3a5fbe 100644 --- a/include/linux/driver_data.h +++ b/include/linux/driver_data.h @@ -144,6 +144,9 @@ enum driver_data_reqs { * highest version of API supported by the caller. * @api_name_postfix: optional, indicates to use this as the driver data name * postfix when %DRIVER_DATA_REQ_USE_API_VERSIONING is enabled. + * @alloc_buf: pointer of pointer to the buffer area allocated by the caller + * so we can place the respective driver data + * @alloc_buf_size: size of the @alloc_buf * * This data structure is intended to carry all requirements and specifications * required to complete the task to get the requested driver date file to the @@ -157,6 +160,8 @@ struct driver_data_req_params { u8 api_max; const char *api_name_postfix; const union driver_data_cbs cbs; + void **alloc_buf; + size_t alloc_buf_size; }; /*