From nobody Tue Dec 17 11:47:10 2024
X-Original-To: dev-commits-src-main@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 4YCFR22Xj1z5h6ly;
Tue, 17 Dec 2024 11:47:10 +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 "R10" (verified OK))
by mx1.freebsd.org (Postfix) with ESMTPS id 4YCFR2225zz4XGy;
Tue, 17 Dec 2024 11:47:10 +0000 (UTC)
(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1734436030;
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=Vx7PQpPWSM1R5FhHntyXbohA4tjxdcm83hPvdxmY9c0=;
b=MP9liO5j+AsAGoaC4KFKrdJNgYEoaxi0OQJBKQZhVSGTIx6/V7s0s5isdfi2M0ZbE0YAjl
+PNWD7mB5Yj5CLzVtTUhTsHrAKmxIVimHq7RDKEmwegNRIGGA19Oe+iQI/9r2BQaqC1RES
ckbgNo4kGqbfFhzNGmSkVxfyWRPKHwF4NQmu7UFlhFTLK1CxK5GAdvDKe3wkP5zwe4HAnw
iuBU0nQOXR1c/LAd2HDOT0iBHxWwKAJBK2GVjfGARJWZ8X+5hVG0oivpp+c5REED3BtGrF
QuMyD+DLutKTeFsjMecmnOll5H9Glxb2GCdA+v0AE9pX1p7F7mdWVXEmA/yQcg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
s=dkim; t=1734436030;
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=Vx7PQpPWSM1R5FhHntyXbohA4tjxdcm83hPvdxmY9c0=;
b=eBpimZid9ZEUkUgdSdm4mP17waoCwSMrOfe4KWAw//Idqh3vx296oqZEADcoZBpU88sgPj
ZR4j8AfRlx7DYSuzSFMwB5Zr7MECb8da1EBCkUPOJS4RmQOSMXga+2rQXacGs8Lf+Rrg3d
o19CeuD8aLwOkSlxQALbrKoQv43JQhWYqT7f0ws9+Aq9BvTjuQWsqf9NtWkTL1aDRUlJCL
K93WQrFNhiY3MTOGBZyZ8Km+I0DU0yFlyfiO5NgNrbwKloa8odbIuiMfppaOjoHh4YXUUG
LU0QGIe2HHnXmVJ5Ls6SFVLlswgs64SIavADGTRzQQVELgAg/QXq13Q2AlDbCQ==
ARC-Authentication-Results: i=1;
mx1.freebsd.org;
none
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734436030; a=rsa-sha256; cv=none;
b=Fnl+Jll68amrhQGyJDlibWaAUloN7WFVKizMGQkj4DfN90TaguNCwNdMJTbe8J4AMW5BZv
QssDwwAZtQU0ABeXBKqPwyYkYaf5am5IA+zqV4SZNh3/QQzq9D5u9GHzRWqaePyl1cgtMi
gbMOhdIghGKfVRyxtthAYRZ/VHF/RUQyF2XfCvmHpUa5UdIpxJc0fOMHWQlbFCaghdTmVX
KDzxf9ZRKYuhSJCYleerccM/LEHS1JzXg/0RmoOGuAkfEvF9DAYa/4kmifRZEhP9AHXlMp
vFbhH7OckVdQYkYBfiRkMAGnWtebHLE6fjtXlJ4dZaAUimt1Tp3GqgKyIU8T5g==
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 4YCFR21C6bzLHR;
Tue, 17 Dec 2024 11:47:10 +0000 (UTC)
(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BHBlA1W010568;
Tue, 17 Dec 2024 11:47:10 GMT
(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BHBlAs7010565;
Tue, 17 Dec 2024 11:47:10 GMT
(envelope-from git)
Date: Tue, 17 Dec 2024 11:47:10 GMT
Message-Id: <202412171147.4BHBlAs7010565@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: 56816e687557 - main - riscv: Eswin hwreset support
added.
List-Id: Commit messages for the main branch of the src repository
List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main
List-Help:
List-Post:
List-Subscribe:
List-Unsubscribe:
X-BeenThere: dev-commits-src-main@freebsd.org
Sender: owner-dev-commits-src-main@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: 56816e68755725371ac89dc5aa882fdce46605a5
Auto-Submitted: auto-generated
The branch main has been updated by br:
URL: https://cgit.FreeBSD.org/src/commit/?id=56816e68755725371ac89dc5aa882fdce46605a5
commit 56816e68755725371ac89dc5aa882fdce46605a5
Author: Ruslan Bukin
AuthorDate: 2024-12-17 11:35:08 +0000
Commit: Ruslan Bukin
CommitDate: 2024-12-17 11:46:10 +0000
riscv: Eswin hwreset support added.
Add reset controller driver for Eswin EIC7700.
This one has two reset cells in FDT, which is unusual, so provide a
custom hwreset_map method.
Tested on SiFive Premier P550.
Reviewed by: mhorne, jrtc27
Differential Revision: https://reviews.freebsd.org/D47853
---
sys/riscv/eswin/eswin_reset.c | 190 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 190 insertions(+)
diff --git a/sys/riscv/eswin/eswin_reset.c b/sys/riscv/eswin/eswin_reset.c
new file mode 100644
index 000000000000..13139e0c85ea
--- /dev/null
+++ b/sys/riscv/eswin/eswin_reset.c
@@ -0,0 +1,190 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ruslan Bukin
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include "syscon_if.h"
+#include "hwreset_if.h"
+
+struct eswin_rst_softc {
+ device_t dev;
+ struct mtx mtx;
+ struct syscon *syscon;
+};
+
+#define RESET_BLOCK 0x400
+#define RESET_ID_TO_REG(x) (RESET_BLOCK + (x) * 4)
+
+#define ERST_LOCK(sc) mtx_lock(&(sc)->mtx)
+#define ERST_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
+#define ERST_ASSERT_LOCKED(sc) mtx_assert(&(sc)->mtx, MA_OWNED);
+#define ERST_ASSERT_UNLOCKED(sc) mtx_assert(&(sc)->mtx, MA_NOTOWNED);
+
+#define ERST_READ(_sc, _reg) \
+ SYSCON_READ_4(sc->syscon, (_reg))
+#define ERST_WRITE(_sc, _reg, _val) \
+ SYSCON_WRITE_4(sc->syscon, (_reg), (_val))
+
+static struct ofw_compat_data compat_data[] = {
+ { "eswin,eic7700-reset", 1 },
+ { NULL, 0 },
+};
+
+static int
+eswin_rst_probe(device_t dev)
+{
+
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
+ return (ENXIO);
+
+ device_set_desc(dev, "Eswin Reset");
+
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+eswin_rst_attach(device_t dev)
+{
+ struct eswin_rst_softc *sc;
+ int error;
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+
+ error = syscon_get_by_ofw_node(dev, OF_parent(ofw_bus_get_node(dev)),
+ &sc->syscon);
+ if (error != 0) {
+ device_printf(dev, "Couldn't get syscon handle of parent\n");
+ return (error);
+ }
+
+ mtx_init(&sc->mtx, device_get_nameunit(sc->dev), NULL, MTX_DEF);
+
+ hwreset_register_ofw_provider(dev);
+
+ return (0);
+}
+
+static int
+eswin_rst_reset_assert(device_t dev, intptr_t id, bool reset)
+{
+ struct eswin_rst_softc *sc;
+ uint32_t reg;
+ uint32_t base;
+ uint32_t bit;
+
+ sc = device_get_softc(dev);
+
+ base = RESET_ID_TO_REG(id >> 5);
+ bit = id & 0x1f;
+
+ ERST_LOCK(sc);
+ reg = ERST_READ(sc, base);
+ if (reset)
+ reg &= ~(1 << bit);
+ else
+ reg |= (1 << bit);
+ ERST_WRITE(sc, base, reg);
+ ERST_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+eswin_rst_reset_is_asserted(device_t dev, intptr_t id, bool *reset)
+{
+ struct eswin_rst_softc *sc;
+ uint32_t reg;
+ uint32_t base;
+ uint32_t bit;
+
+ sc = device_get_softc(dev);
+
+ base = RESET_ID_TO_REG(id >> 5);
+ bit = id & 0x1f;
+
+ ERST_LOCK(sc);
+ reg = ERST_READ(sc, base);
+ *reset = (reg & (1 << bit)) == 0;
+ ERST_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+eswin_rst_map(device_t provider_dev, phandle_t xref, int ncells,
+ pcell_t *cells, intptr_t *id)
+{
+
+ KASSERT(ncells == 2, ("wrong ncells"));
+
+ *id = cells[0] << 5;
+ *id |= ilog2(cells[1]);
+
+ return (0);
+}
+
+static device_method_t eswin_rst_methods[] = {
+ /* Device interface. */
+ DEVMETHOD(device_probe, eswin_rst_probe),
+ DEVMETHOD(device_attach, eswin_rst_attach),
+
+ /* Reset interface. */
+ DEVMETHOD(hwreset_assert, eswin_rst_reset_assert),
+ DEVMETHOD(hwreset_is_asserted, eswin_rst_reset_is_asserted),
+ DEVMETHOD(hwreset_map, eswin_rst_map),
+
+ DEVMETHOD_END
+};
+
+static driver_t eswin_rst_driver = {
+ "eswin_rst",
+ eswin_rst_methods,
+ sizeof(struct eswin_rst_softc)
+};
+
+EARLY_DRIVER_MODULE(eswin_rst, simplebus, eswin_rst_driver, 0, 0,
+ BUS_PASS_BUS + BUS_PASS_ORDER_LATE);