mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
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
This commit is contained in:
1 parent
775e421dc3
commit
ffcd78861e
4 files changed
+99
-29
No files matched your search
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
sc->dev = dev;
|
||||
sc->parent = device_get_parent(dev);
|
||||
int rid;
|
||||
|
||||
node = ofw_bus_get_node(dev);
|
||||
if (node == -1)
|
||||
return (ENXIO);
|
||||
sc = device_get_softc(dev);
|
||||
sc->dev = dev;
|
||||
|
||||
OF_getencprop(node, "reg", ®, sizeof(reg));
|
||||
rid = 0;
|
||||
sc->res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
|
||||
RF_ACTIVE | RF_SHAREABLE);
|
||||
|
||||
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);
|
||||
@@ -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 }
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user