Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp16729pxh; Thu, 7 Apr 2022 12:34:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPmeT9Nms828Vo/NCEWbFOFDwj97nEhvX6vI3d5tAbA7zg6cF/DHBvP+n2n36ix9c/c41M X-Received: by 2002:aa7:8883:0:b0:4fb:20dd:c07f with SMTP id z3-20020aa78883000000b004fb20ddc07fmr15682051pfe.22.1649360074467; Thu, 07 Apr 2022 12:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649360074; cv=none; d=google.com; s=arc-20160816; b=Y2llPgx/rf1i+JBJJGWs4NzGruM8pDBg1zWOL43Hf0Zn2mHvbTEgkVJRSUD7a602xW TElCSrqNm/5kCDy93aRsUMuPPopt2EB0HBCqe4Knlsz+vp9MUsyU/qYT6OzIa+AFgXMA 7UCpCQVZdUIQI0UewCEvPAjZvs9j2FneNJAeVNqmzhfZdtUcKRzD4dgv7UGhHwS32s5c +0D9yfYQ8UClUhfwo/HRfcoOk8FJVR8Kj6gO30O0CNcU8qSvL11nFarxMAR+dGUKlutk 5WXUUsaU4nAF5qAuzFnvUvGsPPMLKDwjlG2MHIjhe4au0x7N8U7iPdJ+KB+FFHEKXhNO A9cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=ZyR/TygfCbUExokdnRACNhP8xxcDHNCiO5v2h8FSOhA=; b=WQYVGmOH9KfSl2z5M6rSHdzvkZw2dDTuShWOB5zXufvQ6Go896+1EVkkXmiXLkBSqi kDYuP4YL6YmNfHVQPyMv5rxXm2wUtWlxeibeTZPBjU/nonmbkAPEqTh9118+p5i+4nTP VDEDvwqI6copFl7hNK6kR2d0HBwx+fF+uYz2Y20AooPgDlFigaPTsJ5GbFkBjtqciUp+ dQe8S4Q4P71pAB6Ta97G3Nz7dSY8oC7j/pi6c/2LlzFaUORvAUjE9ADA+2pq0QIqkJsI zegHWIZ3wW7+BErCaGa4Tj5/ePA7IwlwjBWLVskbIcpin9JVYVf/dBQL9b+nh7pq+tTG MVZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b="NCdmti/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g11-20020a63e60b000000b003981febb082si12987740pgh.488.2022.04.07.12.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 12:34:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=fail header.i=@metrotek.ru header.s=mail header.b="NCdmti/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8D522405AC; Thu, 7 Apr 2022 12:14:32 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343722AbiDGNkR (ORCPT + 99 others); Thu, 7 Apr 2022 09:40:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbiDGNkO (ORCPT ); Thu, 7 Apr 2022 09:40:14 -0400 Received: from mail.pr-group.ru (mail.pr-group.ru [178.18.215.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB0C375229; Thu, 7 Apr 2022 06:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=metrotek.ru; s=mail; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding: in-reply-to:references; bh=b1yyYtz2GdU/r5eopTZQx0YeXHlPl8KQW9yD+PhHq6I=; b=NCdmti/2FZt7wIvsk7xxtlUiQId6T1IWClxRxQYN/lH7WuwfXNxxVhnd3zX5VG9wnWbMyykw3Vm9h JYzTQ8QobExth4dnBZUZ1m8+7dC5o8tQWGOCEmL8RXWG3ww2thy5IsXwkaatEQgWOpue0jaFoQTEO6 hWf9//y8aaYzy384ba+iNLNZe/S59IY69GFfysiaIXDXCL5mkLuU8rQUsII1m8aNdfEWYdwDwhZgof YVN01C9w36so/p84wDjNxmpiWG0GwD9wQ8oNR8yNWS+dYkPgiYJEURxE2+ub2vQ9tD0vY5FY1UK+0a +hhutGwrpomdzYdR6JIzabXwDS2l8ug== X-Kerio-Anti-Spam: Build: [Engines: 2.16.2.1410, Stamp: 3], Multi: [Enabled, t: (0.000008,0.014288)], BW: [Enabled, t: (0.000018,0.000001)], RTDA: [Enabled, t: (0.083807), Hit: No, Details: v2.34.0; Id: 15.52k9il.1g023tlhi.7ob6; mclb], total: 0(700) X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: X-Footer: bWV0cm90ZWsucnU= Received: from h-e2.ddg ([85.143.252.66]) (authenticated user i.bornyakov@metrotek.ru) by mail.pr-group.ru with ESMTPSA (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)); Thu, 7 Apr 2022 16:37:45 +0300 From: Ivan Bornyakov Cc: Ivan Bornyakov , mdf@kernel.org, hao.wu@intel.com, yilun.xu@intel.com, trix@redhat.com, conor.dooley@microchip.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, system@metrotek.ru, linux-kernel@vger.kernel.org, linux-fpga@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v9 1/3] fpga: fpga-mgr: support bitstream offset in image buffer Date: Thu, 7 Apr 2022 16:36:56 +0300 Message-Id: <20220407133658.15699-2-i.bornyakov@metrotek.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407133658.15699-1-i.bornyakov@metrotek.ru> References: <20220407133658.15699-1-i.bornyakov@metrotek.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is not always whole FPGA image buffer meant to be written to the device. Add bitstream_start and bitstream_size to the fpga_image_info struct and adjust fpga_mgr_write() callers with respect to them. If initial_header_size is not known beforehand, pass whole buffer to low level driver's write_init() so it could setup info->bitstream_start and info->bitstream_size regardless. Signed-off-by: Ivan Bornyakov --- drivers/fpga/fpga-mgr.c | 48 +++++++++++++++++++++++++++++------ include/linux/fpga/fpga-mgr.h | 5 ++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index d49a9ce34568..c64e60e23a71 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c @@ -139,7 +139,8 @@ EXPORT_SYMBOL_GPL(fpga_image_info_free); * Call the low level driver's write_init function. This will do the * device-specific things to get the FPGA into the state where it is ready to * receive an FPGA image. The low level driver only gets to see the first - * initial_header_size bytes in the buffer. + * initial_header_size bytes in the buffer, if initial_header_size is set. + * Otherwise, the whole buffer will be passed. */ static int fpga_mgr_write_init_buf(struct fpga_manager *mgr, struct fpga_image_info *info, @@ -148,12 +149,10 @@ static int fpga_mgr_write_init_buf(struct fpga_manager *mgr, int ret; mgr->state = FPGA_MGR_STATE_WRITE_INIT; - if (!mgr->mops->initial_header_size) - ret = fpga_mgr_write_init(mgr, info, NULL, 0); - else - ret = fpga_mgr_write_init( - mgr, info, buf, min(mgr->mops->initial_header_size, count)); + if (mgr->mops->initial_header_size) + count = min(mgr->mops->initial_header_size, count); + ret = fpga_mgr_write_init(mgr, info, buf, count); if (ret) { dev_err(&mgr->dev, "Error preparing FPGA for writing\n"); mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR; @@ -235,13 +234,33 @@ static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr, if (mgr->mops->write_sg) { ret = fpga_mgr_write_sg(mgr, sgt); } else { + size_t offset, count, length, bitstream_size; struct sg_mapping_iter miter; + offset = info->bitstream_start; + bitstream_size = info->bitstream_size; + count = 0; + sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG); while (sg_miter_next(&miter)) { - ret = fpga_mgr_write(mgr, miter.addr, miter.length); - if (ret) + if (offset >= miter.length) { + offset -= miter.length; + continue; + } + + if (bitstream_size) + length = min(miter.length - offset, + bitstream_size - count); + else + length = miter.length - offset; + + count += length; + + ret = fpga_mgr_write(mgr, miter.addr + offset, length); + if (ret || count == bitstream_size) break; + + offset = 0; } sg_miter_stop(&miter); } @@ -265,6 +284,19 @@ static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr, if (ret) return ret; + if (info->bitstream_start > count) { + dev_err(&mgr->dev, + "Bitstream start %zd outruns firmware image %zd\n", + info->bitstream_start, count); + return -EINVAL; + } + + if (info->bitstream_size) + count = min(info->bitstream_start + info->bitstream_size, count); + + buf += info->bitstream_start; + count -= info->bitstream_start; + /* * Write the FPGA image to the FPGA. */ diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 0f9468771bb9..32464fd10cca 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -85,6 +85,9 @@ enum fpga_mgr_states { * @sgt: scatter/gather table containing FPGA image * @buf: contiguous buffer containing FPGA image * @count: size of buf + * @bitstream_start: offset in image buffer where bitstream data starts + * @bitstream_size: size of bitstream. + * If 0, (count - bitstream_start) will be used. * @region_id: id of target region * @dev: device that owns this * @overlay: Device Tree overlay @@ -98,6 +101,8 @@ struct fpga_image_info { struct sg_table *sgt; const char *buf; size_t count; + size_t bitstream_start; + size_t bitstream_size; int region_id; struct device *dev; #ifdef CONFIG_OF -- 2.25.1