git: ffcd78861eda - main - fdt: Support SCMI shared memory under reserved-memory nodes
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 23 Oct 2026 14:18:31 UTC
The branch main has been updated by mmel:
URL: https://cgit.FreeBSD.org/src/commit/?id=ffcd78861eda41d5ff00a39120f46dbbe8f814b5
commit ffcd78861eda41d5ff00a39120f46dbbe8f814b5
Author: Michal Meloun <mmel@FreeBSD.org>
AuthorDate: 2025-12-06 16:50:36 +0000
Commit: Michal Meloun <mmel@FreeBSD.org>
CommitDate: 2026-10-23 14:08:31 +0000
fdt: Support SCMI shared memory under reserved-memory nodes
Add a simplebus-based pseudo-bus that matches the "reserved-memory"
node in the device tree. Update the SCMI shared memory driver so that
it can attach either as a child of mmio_sram or directly under
simplebus (via the new reserved-memory bus). Make the mmio_sram memory
resource shareable so both attachment methods can coexist when required.
MFC after: 1 week
Reviewed by: manu
---
sys/conf/files | 1 +
sys/dev/fdt/fdt_reserved_memory.c | 80 +++++++++++++++++++++++++++++++++++++++
sys/dev/firmware/arm/scmi_shmem.c | 43 ++++++++-------------
sys/dev/sram/mmio_sram.c | 2 +-
4 files changed, 98 insertions(+), 28 deletions(-)
diff --git a/sys/conf/files b/sys/conf/files
index d74bd0b0f648..c3b8e8288745 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1739,6 +1739,7 @@ dev/fdt/fdt_clock_if.m optional fdt fdt_clock
dev/fdt/fdt_common.c optional fdt
dev/fdt/fdt_pinctrl.c optional fdt fdt_pinctrl
dev/fdt/fdt_pinctrl_if.m optional fdt fdt_pinctrl
+dev/fdt/fdt_reserved_memory.c optional fdt
dev/fdt/fdt_slicer.c optional fdt cfi | fdt mx25l | fdt n25q | fdt at45d
dev/fdt/fdt_static_dtb.S optional fdt fdt_dtb_static \
dependency "${FDT_DTS_FILE:T:R}.dtb"
diff --git a/sys/dev/fdt/fdt_reserved_memory.c b/sys/dev/fdt/fdt_reserved_memory.c
new file mode 100644
index 000000000000..604d536330a2
--- /dev/null
+++ b/sys/dev/fdt/fdt_reserved_memory.c
@@ -0,0 +1,80 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
+ *
+ * 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 <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <dev/fdt/simplebus.h>
+
+#include <dev/ofw/ofw_bus.h>
+
+static int
+fdt_reserved_memory_probe(device_t dev)
+{
+ char *name;
+ phandle_t node;
+ int rv;
+
+ node = ofw_bus_get_node(dev);
+ if (node == -1)
+ return (ENXIO);
+
+ if (!OF_hasprop(node, "ranges"))
+ return (ENXIO);
+
+ rv = OF_getprop_alloc(node, "name", (void **)&name);
+ if (rv == -1)
+ return (ENXIO);
+
+ rv = strcmp(name, "reserved-memory");
+ free(name, M_OFWPROP);
+ if (rv != 0)
+ return (ENXIO);
+
+ device_set_desc(dev, "Reserved memory pseudo-bus");
+
+ return (BUS_PROBE_GENERIC);
+}
+
+static device_method_t fdt_reserved_memory_methods[] = {
+
+ /* Device interface */
+ DEVMETHOD(device_probe, fdt_reserved_memory_probe),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(fdt_reserved_memory, fdt_reserved_memory_driver,
+ fdt_reserved_memory_methods, 0, simplebus_driver);
+
+EARLY_DRIVER_MODULE(fdt_reserved_memory, simplebus, fdt_reserved_memory_driver,
+ 0, 0, BUS_PASS_BUS);
+MODULE_VERSION(fdt_reserved_memory, 1);
diff --git a/sys/dev/firmware/arm/scmi_shmem.c b/sys/dev/firmware/arm/scmi_shmem.c
index 32c260c8a9ad..c807ec49028f 100644
--- a/sys/dev/firmware/arm/scmi_shmem.c
+++ b/sys/dev/firmware/arm/scmi_shmem.c
@@ -32,19 +32,17 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
-#include <sys/cpu.h>
+#include <sys/rman.h>
#include <sys/kernel.h>
-#include <sys/lock.h>
#include <sys/module.h>
#include <machine/atomic.h>
+#include <machine/bus.h>
#include <dev/fdt/simplebus.h>
#include <dev/fdt/fdt_common.h>
#include <dev/ofw/ofw_bus_subr.h>
-#include "mmio_sram_if.h"
-
#include "scmi_shmem.h"
#include "scmi.h"
@@ -53,7 +51,7 @@
struct shmem_softc {
device_t dev;
- device_t parent;
+ struct resource *res;
int reg;
int inflight;
};
@@ -88,19 +86,16 @@ shmem_attach(device_t dev)
{
struct shmem_softc *sc;
phandle_t node;
- int reg;
+ int rid;
+ node = ofw_bus_get_node(dev);
sc = device_get_softc(dev);
sc->dev = dev;
- sc->parent = device_get_parent(dev);
- node = ofw_bus_get_node(dev);
- if (node == -1)
- return (ENXIO);
+ rid = 0;
+ sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
+ RF_ACTIVE | RF_SHAREABLE);
- OF_getencprop(node, "reg", ®, sizeof(reg));
-
- sc->reg = reg;
atomic_store_rel_int(&sc->inflight, INFLIGHT_NONE);
OF_device_register_xref(OF_xref_from_node(node), dev);
@@ -111,7 +106,10 @@ shmem_attach(device_t dev)
static int
shmem_detach(device_t dev)
{
+ struct shmem_softc *sc;
+ sc = device_get_softc(dev);
+ bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->res);
return (0);
}
@@ -119,15 +117,9 @@ static void
scmi_shmem_read(device_t dev, bus_size_t offset, void *buf, bus_size_t len)
{
struct shmem_softc *sc;
- uint8_t *addr;
- int i;
sc = device_get_softc(dev);
-
- addr = (uint8_t *)buf;
-
- for (i = 0; i < len; i++)
- addr[i] = MMIO_SRAM_READ_1(sc->parent, sc->reg + offset + i);
+ bus_read_region_1(sc->res, offset, buf, len);
}
static void
@@ -135,15 +127,10 @@ scmi_shmem_write(device_t dev, bus_size_t offset, const void *buf,
bus_size_t len)
{
struct shmem_softc *sc;
- const uint8_t *addr;
- int i;
sc = device_get_softc(dev);
-
- addr = (const uint8_t *)buf;
-
- for (i = 0; i < len; i++)
- MMIO_SRAM_WRITE_1(sc->parent, sc->reg + offset + i, addr[i]);
+ sc = device_get_softc(dev);
+ bus_write_region_1(sc->res, offset, buf, len);
}
device_t
@@ -322,4 +309,6 @@ DEFINE_CLASS_1(shmem, shmem_driver, shmem_methods, sizeof(struct shmem_softc),
EARLY_DRIVER_MODULE(shmem, mmio_sram, shmem_driver, 0, 0,
BUS_PASS_INTERRUPT + BUS_PASS_ORDER_MIDDLE);
+EARLY_DRIVER_MODULE(shmem, simplebus, shmem_driver, 0, 0,
+ BUS_PASS_INTERRUPT + BUS_PASS_ORDER_MIDDLE);
MODULE_VERSION(scmi_shmem, 1);
diff --git a/sys/dev/sram/mmio_sram.c b/sys/dev/sram/mmio_sram.c
index bad32d620bb9..b8b205988b61 100644
--- a/sys/dev/sram/mmio_sram.c
+++ b/sys/dev/sram/mmio_sram.c
@@ -46,7 +46,7 @@
#define dprintf(fmt, ...)
static struct resource_spec mmio_sram_spec[] = {
- { SYS_RES_MEMORY, 0, RF_ACTIVE },
+ { SYS_RES_MEMORY, 0, RF_ACTIVE | RF_SHAREABLE},
{ -1, 0 }
};