From nobody Tue Jan 09 14:32:24 2024
X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1])
by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4T8YL04Qz0z55QHv;
Tue, 9 Jan 2024 14:32:24 +0000 (UTC)
(envelope-from git@FreeBSD.org)
Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256
client-signature RSA-PSS (4096 bits) client-digest SHA256)
(Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK))
by mx1.freebsd.org (Postfix) with ESMTPS id 4T8YL03Yv4z57n9;
Tue, 9 Jan 2024 14:32:24 +0000 (UTC)
(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1704810744;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding;
bh=SF0fq8QVeF/GosYLyejTOf5s/UW7jFFZTjOZe24RLl8=;
b=qimItXZPCtxFf9/kNlQCj4uy7WHaSXt2d/7rIULe6SUNv9aZncJzVo138sSkpXGWOsUhcW
E2IfH88Vy0taMn3+GeDb6BbSBy4Dp8QyyKVR6ApuH7O4YyNrYDtydcgmNUMRthcKObDPya
/UCtJReAM/bSvuqmnHRA4gLG9a5I2TzvNwwcqB0ZdaN6UrdAbm6VpKQ3ed5elDgPqK4eqc
2ZCixVGFX/tBqP2z22h87tLkzCxhtizWXMqDVMFTUa7uw65lH/Cgn7/N9/BrI1jCm+LrKH
BJU2bypZNNtVaGCAxbrJpovot2/iYmgOrMLiun+WPAJVgUggxMFbrQweOPZ0Sg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
s=dkim; t=1704810744;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding;
bh=SF0fq8QVeF/GosYLyejTOf5s/UW7jFFZTjOZe24RLl8=;
b=j2id3HabRh86Z9YHDnc3fS93rfY7owGOthW6JVC+DNZ0lUFx5QO+piU/0a/xoQSKjtoxQH
Ehi0l1kjnnkuZrTRh/DaFXhC1XFunTwXj16PFV/N89oHx25kbRQpmHGlhlLJChgY+j67kR
SmGYB4OzO+qLMjYyTnqdCi0m6b+9yyy1nY9SRTBVRLb77llbz3SeMVa3iNS+VnCgqshUuU
gGu7/IOW/3pG+VeStLqS3wXZtW9sh2X0In2lw/1XB9VmWA05bX23ZrhX6sCJEwzXILRUs8
C4SP47jVXTOUmpyJsQy7543EP6GqkPsVDqxMDDcGuzpxU64f73kyYcdmF1sqmA==
ARC-Authentication-Results: i=1;
mx1.freebsd.org;
none
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704810744; a=rsa-sha256; cv=none;
b=xdvD0oVWbmWTz4BEI1FUAgMDoJX9Tb9+dypcdykpLnTgWh4FmEKPO5qjTjGvUeMoVTQh5b
gYQ3rLEjQ+VTzJHTrGXFHmO+0pqsvobYgeCf307ZnWQhKSEtK+yajjyfx2zHS3yticf63a
qKY/3R2ne8C1r1wW9uruIBieZjaL2m0VdXeXbY+f8bNsksbB9WxAJHjiKW5IebMIs3pLw5
9UoKynjsHXAhlHLyyWpzgVMWNrvMtXs5UoyNy133JMpaSYwZLfeS973fODxz2Kc51elVJG
jzJJKwczSuHrLpY+j1ZIqgJyQwS3X+OVQnIWmMdcxC6Mh46HQcsqeK3jvUNoUQ==
Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
(Client did not present a certificate)
by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4T8YL02f1TzvJp;
Tue, 9 Jan 2024 14:32:24 +0000 (UTC)
(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 409EWOmO043708;
Tue, 9 Jan 2024 14:32:24 GMT
(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 409EWOuv043705;
Tue, 9 Jan 2024 14:32:24 GMT
(envelope-from git)
Date: Tue, 9 Jan 2024 14:32:24 GMT
Message-Id: <202401091432.409EWOuv043705@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
dev-commits-src-main@FreeBSD.org
From: Ruslan Bukin
Subject: git: ddf7fbbb57e2 - main - Intel FPGA: Support programming
larger bitfiles.
List-Id: Commit messages for all branches of the src repository
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all
List-Help:
List-Post:
List-Subscribe:
List-Unsubscribe:
Sender: owner-dev-commits-src-all@freebsd.org
X-BeenThere: dev-commits-src-all@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: br
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: ddf7fbbb57e271b392d1aea4866bf5df800a7cf9
Auto-Submitted: auto-generated
The branch main has been updated by br:
URL: https://cgit.FreeBSD.org/src/commit/?id=ddf7fbbb57e271b392d1aea4866bf5df800a7cf9
commit ddf7fbbb57e271b392d1aea4866bf5df800a7cf9
Author: Ruslan Bukin
AuthorDate: 2024-01-09 14:18:53 +0000
Commit: Ruslan Bukin
CommitDate: 2024-01-09 14:18:53 +0000
Intel FPGA: Support programming larger bitfiles.
Issue data claim command after every chunk of data programmed,
so we can reuse the SVC buffer for the next chunk.
Tested on Terasic DE10 Pro.
Sponsored by: UKRI
---
sys/arm64/intel/stratix10-soc-fpga-mgr.c | 82 +++++++++++++++++++++++---------
1 file changed, 59 insertions(+), 23 deletions(-)
diff --git a/sys/arm64/intel/stratix10-soc-fpga-mgr.c b/sys/arm64/intel/stratix10-soc-fpga-mgr.c
index 177fb694c870..baa35b9a85a6 100644
--- a/sys/arm64/intel/stratix10-soc-fpga-mgr.c
+++ b/sys/arm64/intel/stratix10-soc-fpga-mgr.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2019 Ruslan Bukin
+ * Copyright (c) 2019-2024 Ruslan Bukin
*
* This software was developed by SRI International and the University of
* Cambridge Computer Laboratory (Department of Computer Science and
@@ -32,6 +32,9 @@
/*
* Intel Stratix 10 FPGA Manager.
+ *
+ * FPGA Programming Example:
+ * dd if=cheri.core.rbf of=/dev/fpga_partial0 bs=512k
*/
#include
@@ -57,7 +60,7 @@
#include
#include
-#define SVC_BUF_SIZE (2 * 1024 * 1024)
+#define SVC_BUF_SIZE (512 * 1024)
struct fpgamgr_s10_softc {
struct cdev *mgr_cdev;
@@ -109,12 +112,45 @@ fpga_open(struct cdev *dev, int flags __unused,
return (0);
}
+static int
+fpga_submit(struct cdev *dev)
+{
+ struct fpgamgr_s10_softc *sc;
+ struct s10_svc_msg msg;
+ int ret;
+
+ sc = dev->si_drv1;
+
+ bzero(&msg, sizeof(struct s10_svc_msg));
+ msg.command = COMMAND_RECONFIG_DATA_SUBMIT;
+ msg.payload = (void *)sc->mem.paddr;
+ msg.payload_length = sc->mem.fill;
+ ret = s10_svc_send(sc->s10_svc_dev, &msg);
+ if (ret != 0) {
+ device_printf(sc->dev, "Failed to submit data\n");
+ s10_svc_free_memory(sc->s10_svc_dev, &sc->mem);
+ sc->opened = 0;
+ return (ENXIO);
+ }
+
+ /* Claim memory buffer back. */
+ bzero(&msg, sizeof(struct s10_svc_msg));
+ msg.command = COMMAND_RECONFIG_DATA_CLAIM;
+ ret = s10_svc_send(sc->s10_svc_dev, &msg);
+ if (ret)
+ device_printf(sc->dev, "Can't claim buffer back.\n");
+
+ return (ret);
+}
+
static int
fpga_write(struct cdev *dev, struct uio *uio, int ioflag)
{
struct fpgamgr_s10_softc *sc;
vm_offset_t addr;
+ int error;
int amnt;
+ int ret;
sc = dev->si_drv1;
@@ -127,11 +163,22 @@ fpga_write(struct cdev *dev, struct uio *uio, int ioflag)
while (uio->uio_resid > 0) {
addr = sc->mem.vaddr + sc->mem.fill;
- if (sc->mem.fill >= SVC_BUF_SIZE)
- return (ENOMEM);
amnt = MIN(uio->uio_resid, (SVC_BUF_SIZE - sc->mem.fill));
- uiomove((void *)addr, amnt, uio);
+ error = uiomove((void *)addr, amnt, uio);
+ if (error) {
+ device_printf(sc->dev, "uiomove returned error %d\n",
+ error);
+ break;
+ }
sc->mem.fill += amnt;
+ if (sc->mem.fill == SVC_BUF_SIZE) {
+ ret = fpga_submit(dev);
+ if (ret) {
+ sx_xunlock(&sc->sx);
+ return (ret);
+ }
+ sc->mem.fill = 0;
+ }
}
sx_xunlock(&sc->sx);
@@ -144,7 +191,6 @@ fpga_close(struct cdev *dev, int flags __unused,
int fmt __unused, struct thread *td __unused)
{
struct fpgamgr_s10_softc *sc;
- struct s10_svc_msg msg;
int ret;
sc = dev->si_drv1;
@@ -156,25 +202,15 @@ fpga_close(struct cdev *dev, int flags __unused,
return (ENXIO);
}
- /* Submit bitstream */
- bzero(&msg, sizeof(struct s10_svc_msg));
- msg.command = COMMAND_RECONFIG_DATA_SUBMIT;
- msg.payload = (void *)sc->mem.paddr;
- msg.payload_length = sc->mem.fill;
- ret = s10_svc_send(sc->s10_svc_dev, &msg);
- if (ret != 0) {
- device_printf(sc->dev, "Failed to submit data\n");
- s10_svc_free_memory(sc->s10_svc_dev, &sc->mem);
- sc->opened = 0;
- sx_xunlock(&sc->sx);
- return (0);
+ if (sc->mem.fill > 0) {
+ ret = fpga_submit(dev);
+ if (ret) {
+ sx_xunlock(&sc->sx);
+ return (ret);
+ }
+ sc->mem.fill = 0;
}
- /* Claim memory buffer back */
- bzero(&msg, sizeof(struct s10_svc_msg));
- msg.command = COMMAND_RECONFIG_DATA_CLAIM;
- s10_svc_send(sc->s10_svc_dev, &msg);
-
s10_svc_free_memory(sc->s10_svc_dev, &sc->mem);
sc->opened = 0;
sx_xunlock(&sc->sx);