From patchwork Mon Mar 13 21:53:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Tull X-Patchwork-Id: 9622209 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 2ED9A60522 for ; Mon, 13 Mar 2017 21:54:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F65F28491 for ; Mon, 13 Mar 2017 21:54:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 144FD2850F; Mon, 13 Mar 2017 21:54:07 +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 8ECFC284CB for ; Mon, 13 Mar 2017 21:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754392AbdCMVxw (ORCPT ); Mon, 13 Mar 2017 17:53:52 -0400 Received: from mail.kernel.org ([198.145.29.136]:57876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754325AbdCMVxt (ORCPT ); Mon, 13 Mar 2017 17:53:49 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1774203E9; Mon, 13 Mar 2017 21:53:46 +0000 (UTC) Received: from localhost.localdomain (unknown [192.55.54.60]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B81B203F1; Mon, 13 Mar 2017 21:53:44 +0000 (UTC) From: Alan Tull To: Moritz Fischer Cc: Alan Tull , linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH 1/5] fpga-mgr: pass parameters for loading fpga in image info Date: Mon, 13 Mar 2017 16:53:29 -0500 Message-Id: <20170313215333.3008-2-atull@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170313215333.3008-1-atull@kernel.org> References: <20170313215333.3008-1-atull@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP 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 Currently fpga-mgr.c has three methods for loading FPGA's depending on how the FPGA image is presented: in a sg table, as a single buffer, or as a firmware file. This commit adds these parameters to the fpga_image_info struct and adds a single function that can accept the image as any of these three. This allows code to be written that could use any of the three methods. Signed-off-by: Alan Tull --- v1: changed order that methods are tried --- drivers/fpga/fpga-mgr.c | 12 ++++++++++++ drivers/fpga/fpga-region.c | 17 +++++++---------- include/linux/fpga/fpga-mgr.h | 10 ++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 86d2cb2..fde605b 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -309,6 +309,18 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, } EXPORT_SYMBOL_GPL(fpga_mgr_firmware_load); +int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info) +{ + if (info->sgt) + return fpga_mgr_buf_load_sg(mgr, info, info->sgt); + if (info->buf && info->count) + return fpga_mgr_buf_load(mgr, info, info->buf, info->count); + if (info->firmware_name) + return fpga_mgr_firmware_load(mgr, info, info->firmware_name); + return -EINVAL; +} +EXPORT_SYMBOL_GPL(fpga_mgr_load); + static const char * const state_str[] = { [FPGA_MGR_STATE_UNKNOWN] = "unknown", [FPGA_MGR_STATE_POWER_OFF] = "power off", diff --git a/drivers/fpga/fpga-region.c b/drivers/fpga/fpga-region.c index 3222fdb..24f4ed5 100644 --- a/drivers/fpga/fpga-region.c +++ b/drivers/fpga/fpga-region.c @@ -223,14 +223,11 @@ static int fpga_region_get_bridges(struct fpga_region *region, /** * fpga_region_program_fpga - program FPGA * @region: FPGA region - * @firmware_name: name of FPGA image firmware file * @overlay: device node of the overlay - * Program an FPGA using information in the device tree. - * Function assumes that there is a firmware-name property. + * Program an FPGA using information in the region's fpga image info. * Return 0 for success or negative error code. */ static int fpga_region_program_fpga(struct fpga_region *region, - const char *firmware_name, struct device_node *overlay) { struct fpga_manager *mgr; @@ -260,7 +257,7 @@ static int fpga_region_program_fpga(struct fpga_region *region, goto err_put_br; } - ret = fpga_mgr_firmware_load(mgr, region->info, firmware_name); + ret = fpga_mgr_load(mgr, region->info); if (ret) { pr_err("failed to load fpga image\n"); goto err_put_br; @@ -351,7 +348,6 @@ static int child_regions_with_firmware(struct device_node *overlay) static int fpga_region_notify_pre_apply(struct fpga_region *region, struct of_overlay_notify_data *nd) { - const char *firmware_name = NULL; struct fpga_image_info *info; int ret; @@ -373,7 +369,8 @@ static int fpga_region_notify_pre_apply(struct fpga_region *region, if (of_property_read_bool(nd->overlay, "external-fpga-config")) info->flags |= FPGA_MGR_EXTERNAL_CONFIG; - of_property_read_string(nd->overlay, "firmware-name", &firmware_name); + of_property_read_string(nd->overlay, "firmware-name", + &info->firmware_name); of_property_read_u32(nd->overlay, "region-unfreeze-timeout-us", &info->enable_timeout_us); @@ -382,7 +379,7 @@ static int fpga_region_notify_pre_apply(struct fpga_region *region, &info->disable_timeout_us); /* If FPGA was externally programmed, don't specify firmware */ - if ((info->flags & FPGA_MGR_EXTERNAL_CONFIG) && firmware_name) { + if ((info->flags & FPGA_MGR_EXTERNAL_CONFIG) && info->firmware_name) { pr_err("error: specified firmware and external-fpga-config"); return -EINVAL; } @@ -392,12 +389,12 @@ static int fpga_region_notify_pre_apply(struct fpga_region *region, return 0; /* If we got this far, we should be programming the FPGA */ - if (!firmware_name) { + if (!info->firmware_name) { pr_err("should specify firmware-name or external-fpga-config\n"); return -EINVAL; } - return fpga_region_program_fpga(region, firmware_name, nd->overlay); + return fpga_region_program_fpga(region, nd->overlay); } /** diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 57beb5d..45df05a 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -76,11 +76,19 @@ enum fpga_mgr_states { * @flags: boolean flags as defined above * @enable_timeout_us: maximum time to enable traffic through bridge (uSec) * @disable_timeout_us: maximum time to disable traffic through bridge (uSec) + * @firmware_name: name of FPGA image firmware file + * @sgt: scatter/gather table containing FPGA image + * @buf: contiguous buffer containing FPGA image + * @count: size of buf */ struct fpga_image_info { u32 flags; u32 enable_timeout_us; u32 disable_timeout_us; + const char *firmware_name; + struct sg_table *sgt; + const char *buf; + size_t count; }; /** @@ -139,6 +147,8 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, struct fpga_image_info *info, const char *image_name); +int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info); + struct fpga_manager *of_fpga_mgr_get(struct device_node *node); struct fpga_manager *fpga_mgr_get(struct device *dev);