Fri Mar 4 08:19:07 2022 UTC ()
Add mailbox and power-domain support.

power-domain support is very rudimentary.


(skrll)
diff -r0 -r1.1 src/sys/dev/fdt/fdt_mbox.c
diff -r0 -r1.1 src/sys/dev/fdt/fdt_powerdomain.c
diff -r1.45 -r1.46 src/sys/dev/fdt/fdtbus.c
diff -r1.76 -r1.77 src/sys/dev/fdt/fdtvar.h
diff -r1.62 -r1.63 src/sys/dev/fdt/files.fdt

File Added: src/sys/dev/fdt/fdt_mbox.c
/* $NetBSD: fdt_mbox.c,v 1.1 2022/03/04 08:19:06 skrll Exp $ */

/*-
 * Copyright (c) 2022 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Nick Hudson
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fdt_mbox.c,v 1.1 2022/03/04 08:19:06 skrll Exp $");

#include <sys/param.h>

#include <sys/bus.h>
#include <sys/kmem.h>
#include <sys/queue.h>

#include <libfdt.h>
#include <dev/fdt/fdtvar.h>


struct fdtbus_mbox_controller {
	device_t mc_dev;
	int mc_phandle;

	int mc_cells;

	const struct fdtbus_mbox_controller_func *mc_funcs;

	LIST_ENTRY(fdtbus_mbox_controller) mc_next;
};

static LIST_HEAD(, fdtbus_mbox_controller) fdtbus_mbox_controllers =
    LIST_HEAD_INITIALIZER(fdtbus_mbox_controllers);

int
fdtbus_register_mbox_controller(device_t dev, int phandle,
    const struct fdtbus_mbox_controller_func *funcs)
{
	struct fdtbus_mbox_controller *mc;

	uint32_t cells;
	if (of_getprop_uint32(phandle, "#mbox-cells", &cells) != 0) {
		aprint_debug_dev(dev, "missing #mbox-cells");
		return EINVAL;
	}

	mc = kmem_alloc(sizeof(*mc), KM_SLEEP);
	mc->mc_dev = dev;
	mc->mc_phandle = phandle;
	mc->mc_funcs = funcs;
	mc->mc_cells = cells;

	LIST_INSERT_HEAD(&fdtbus_mbox_controllers, mc, mc_next);

	return 0;
}

static struct fdtbus_mbox_controller *
fdtbus_mbox_lookup(int phandle)
{
	struct fdtbus_mbox_controller *mc;

	LIST_FOREACH(mc, &fdtbus_mbox_controllers, mc_next) {
		if (mc->mc_phandle == phandle)
			return mc;
	}

	return NULL;
}

struct fdtbus_mbox_channel *
fdtbus_mbox_get_index(int phandle, u_int index, void (*cb)(void *), void *cbarg)
{
	struct fdtbus_mbox_controller *mc;
	struct fdtbus_mbox_channel *mbox = NULL;
	void *mbox_priv = NULL;
	uint32_t *mboxes = NULL;
	uint32_t *p;
	u_int n;
	int len, resid;

	len = OF_getproplen(phandle, "mboxes");
	if (len <= 0)
		return NULL;

	mboxes = kmem_alloc(len, KM_SLEEP);
	if (OF_getprop(phandle, "mboxes", mboxes, len) != len) {
		kmem_free(mboxes, len);
		return NULL;
	}

	p = mboxes;
	for (n = 0, resid = len; resid > 0; n++) {
		const int mc_phandle =
		    fdtbus_get_phandle_from_native(be32toh(p[0]));

		mc = fdtbus_mbox_lookup(mc_phandle);
		if (mc == NULL)
			break;

		u_int mbox_cells = mc->mc_cells;
		if (n == index) {
			mbox_priv = mc->mc_funcs->mc_acquire(mc->mc_dev,
			    mbox_cells > 0 ? &p[1] : NULL, mbox_cells * 4,
			    cb, cbarg);
			if (mbox_priv) {
				mbox = kmem_alloc(sizeof(*mbox), KM_SLEEP);
				mbox->mb_ctlr = mc;
				mbox->mb_priv = mbox_priv;
			}
			break;
		}
		resid -= (mbox_cells + 1) * 4;
		p += mbox_cells + 1;
	}

	if (mboxes)
		kmem_free(mboxes, len);

	return mbox;
}

struct fdtbus_mbox_channel *
fdtbus_mbox_get(int phandle, const char *name, void (*cb)(void *), void *cbarg)
{
	u_int index;
	int err;

	err = fdtbus_get_index(phandle, "mbox-names", name, &index);
	if (err != 0)
		return NULL;

	return fdtbus_mbox_get_index(phandle, index, cb, cbarg);
}

void
fdtbus_mbox_put(struct fdtbus_mbox_channel *mbox)
{
	struct fdtbus_mbox_controller *mc = mbox->mb_ctlr;

	mc->mc_funcs->mc_release(mc->mc_dev, mbox->mb_priv);
	kmem_free(mbox, sizeof(*mbox));
}

int
fdtbus_mbox_send(struct fdtbus_mbox_channel *mbox, const void *data, size_t len)
{
	struct fdtbus_mbox_controller * const mc = mbox->mb_ctlr;

	return mc->mc_funcs->mc_send(mc->mc_dev, mbox->mb_priv, data, len);
}

int
fdtbus_mbox_recv(struct fdtbus_mbox_channel *mbox, void *data, size_t len)
{
	struct fdtbus_mbox_controller * const mc = mbox->mb_ctlr;

	return mc->mc_funcs->mc_recv(mc->mc_dev, mbox->mb_priv, data, len);
}

File Added: src/sys/dev/fdt/fdt_powerdomain.c
/* $NetBSD: fdt_powerdomain.c,v 1.1 2022/03/04 08:19:06 skrll Exp $ */

/*-
 * Copyright (c) 2022 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Nick Hudson
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fdt_powerdomain.c,v 1.1 2022/03/04 08:19:06 skrll Exp $");

#include <sys/param.h>

#include <sys/bus.h>
#include <sys/kmem.h>
#include <sys/queue.h>

#include <libfdt.h>
#include <dev/fdt/fdtvar.h>


struct fdtbus_powerdomain_controller {
	device_t pdc_dev;
	int pdc_phandle;

	void *pdc_cookie;

	int pdc_cells;

	const struct fdtbus_powerdomain_controller_func *pdc_funcs;

	LIST_ENTRY(fdtbus_powerdomain_controller) pdc_next;
};

static LIST_HEAD(, fdtbus_powerdomain_controller) fdtbus_powerdomain_controllers =
    LIST_HEAD_INITIALIZER(fdtbus_powerdomain_controllers);

int
fdtbus_register_powerdomain_controller(device_t dev, int phandle,
    const struct fdtbus_powerdomain_controller_func *funcs)
{
	struct fdtbus_powerdomain_controller *pdc;

	uint32_t cells;
	if (of_getprop_uint32(phandle, "#power-domain-cells", &cells) != 0) {
		aprint_debug_dev(dev, "missing #power-domain-cells");
		return EINVAL;
	}

	pdc = kmem_alloc(sizeof(*pdc), KM_SLEEP);
	pdc->pdc_dev = dev;
	pdc->pdc_phandle = phandle;
	pdc->pdc_funcs = funcs;
	pdc->pdc_cells = cells;

	LIST_INSERT_HEAD(&fdtbus_powerdomain_controllers, pdc, pdc_next);

	return 0;
}

static struct fdtbus_powerdomain_controller *
fdtbus_powerdomain_lookup(int phandle)
{
	struct fdtbus_powerdomain_controller *pdc;

	LIST_FOREACH(pdc, &fdtbus_powerdomain_controllers, pdc_next) {
		if (pdc->pdc_phandle == phandle)
			return pdc;
	}

	return NULL;
}

static int
fdtbus_powerdomain_enable_internal(int phandle, int index, bool enable)
{
	int len;
	const uint32_t *pds = fdtbus_get_prop(phandle, "power-domains", &len);

	if (pds == NULL)
		return EINVAL;

	for (const uint32_t *pd = pds; pd < pds + len; index--) {
		uint32_t pd_node =
		   fdtbus_get_phandle_from_native(be32toh(pd[0]));
		struct fdtbus_powerdomain_controller *pdc =
		    fdtbus_powerdomain_lookup(pd_node);

		if (pdc == NULL)
			return ENXIO;

		if (index < 0 || index == 0)
			pdc->pdc_funcs->pdc_enable(pdc->pdc_dev, pd, enable);
		if (index == 0)
			break;

		pd += pdc->pdc_cells + 1;
	}

	return 0;
}

int
fdtbus_powerdomain_enable_index(int phandle, int index)
{
	return fdtbus_powerdomain_enable_internal(phandle, index, true);
}

int
fdtbus_powerdomain_disable_index(int phandle, int index)
{
	return fdtbus_powerdomain_enable_internal(phandle, index, false);
}

int
fdtbus_powerdomain_enable(int node)
{
	return fdtbus_powerdomain_enable_index(node, -1);
}

int
fdtbus_powerdomain_disable(int node)
{
	return fdtbus_powerdomain_disable_index(node, -1);
}

cvs diff -r1.45 -r1.46 src/sys/dev/fdt/fdtbus.c (expand / switch to unified diff)

--- src/sys/dev/fdt/fdtbus.c 2022/01/22 11:49:17 1.45
+++ src/sys/dev/fdt/fdtbus.c 2022/03/04 08:19:06 1.46
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fdtbus.c,v 1.45 2022/01/22 11:49:17 thorpej Exp $ */ 1/* $NetBSD: fdtbus.c,v 1.46 2022/03/04 08:19:06 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.45 2022/01/22 11:49:17 thorpej Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.46 2022/03/04 08:19:06 skrll Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34#include <sys/device.h> 34#include <sys/device.h>
35#include <sys/kmem.h> 35#include <sys/kmem.h>
36#include <sys/cpu.h> 36#include <sys/cpu.h>
37 37
38#include <sys/bus.h> 38#include <sys/bus.h>
39 39
40#include <dev/ofw/openfirm.h> 40#include <dev/ofw/openfirm.h>
41 41
42#include <dev/fdt/fdtvar.h> 42#include <dev/fdt/fdtvar.h>
43 43
@@ -458,26 +458,28 @@ fdt_pre_attach(struct fdt_node *node) @@ -458,26 +458,28 @@ fdt_pre_attach(struct fdt_node *node)
458 int error; 458 int error;
459 459
460 node->n_pinctrl_init = fdtbus_pinctrl_has_config(node->n_phandle, "init"); 460 node->n_pinctrl_init = fdtbus_pinctrl_has_config(node->n_phandle, "init");
461 461
462 cfgname = node->n_pinctrl_init ? "init" : "default"; 462 cfgname = node->n_pinctrl_init ? "init" : "default";
463 463
464 aprint_debug_dev(node->n_bus, "set %s config for %s\n", cfgname, node->n_name); 464 aprint_debug_dev(node->n_bus, "set %s config for %s\n", cfgname, node->n_name);
465 465
466 error = fdtbus_pinctrl_set_config(node->n_phandle, cfgname); 466 error = fdtbus_pinctrl_set_config(node->n_phandle, cfgname);
467 if (error != 0 && error != ENOENT) 467 if (error != 0 && error != ENOENT)
468 aprint_debug_dev(node->n_bus, 468 aprint_debug_dev(node->n_bus,
469 "failed to set %s config on %s: %d\n", 469 "failed to set %s config on %s: %d\n",
470 cfgname, node->n_name, error); 470 cfgname, node->n_name, error);
 471
 472 fdtbus_powerdomain_enable(node->n_phandle);
471} 473}
472 474
473static void 475static void
474fdt_post_attach(struct fdt_node *node) 476fdt_post_attach(struct fdt_node *node)
475{ 477{
476 char buf[FDT_MAX_PATH]; 478 char buf[FDT_MAX_PATH];
477 prop_dictionary_t dict; 479 prop_dictionary_t dict;
478 int error; 480 int error;
479 481
480 dict = device_properties(node->n_dev); 482 dict = device_properties(node->n_dev);
481 if (fdtbus_get_path(node->n_phandle, buf, sizeof(buf))) 483 if (fdtbus_get_path(node->n_phandle, buf, sizeof(buf)))
482 prop_dictionary_set_string(dict, "fdt-path", buf); 484 prop_dictionary_set_string(dict, "fdt-path", buf);
483 485

cvs diff -r1.76 -r1.77 src/sys/dev/fdt/fdtvar.h (expand / switch to unified diff)

--- src/sys/dev/fdt/fdtvar.h 2022/02/23 08:56:11 1.76
+++ src/sys/dev/fdt/fdtvar.h 2022/03/04 08:19:06 1.77
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fdtvar.h,v 1.76 2022/02/23 08:56:11 skrll Exp $ */ 1/* $NetBSD: fdtvar.h,v 1.77 2022/03/04 08:19:06 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -147,26 +147,40 @@ struct fdtbus_interrupt_controller_func  @@ -147,26 +147,40 @@ struct fdtbus_interrupt_controller_func
147 int (*)(void *), void *, const char *); 147 int (*)(void *), void *, const char *);
148 void (*disestablish)(device_t, void *); 148 void (*disestablish)(device_t, void *);
149 bool (*intrstr)(device_t, u_int *, char *, size_t); 149 bool (*intrstr)(device_t, u_int *, char *, size_t);
150 void (*mask)(device_t, void *); 150 void (*mask)(device_t, void *);
151 void (*unmask)(device_t, void *); 151 void (*unmask)(device_t, void *);
152}; 152};
153 153
154 154
155struct fdtbus_iommu_func { 155struct fdtbus_iommu_func {
156 bus_dma_tag_t (*map)(device_t, const u_int *, bus_dma_tag_t); 156 bus_dma_tag_t (*map)(device_t, const u_int *, bus_dma_tag_t);
157}; 157};
158 158
159 159
 160struct fdtbus_mbox_channel {
 161 struct fdtbus_mbox_controller *mb_ctlr;
 162 void *mb_priv;
 163};
 164
 165struct fdtbus_mbox_controller_func {
 166 void * (*mc_acquire)(device_t, const void *, size_t, void (*)(void *),
 167 void *);
 168 void (*mc_release)(device_t, void *);
 169 int (*mc_recv)(device_t, void *, void *, size_t);
 170 int (*mc_send)(device_t, void *, const void *, size_t);
 171};
 172
 173
160struct fdtbus_mmc_pwrseq; 174struct fdtbus_mmc_pwrseq;
161 175
162struct fdtbus_mmc_pwrseq_func { 176struct fdtbus_mmc_pwrseq_func {
163 void (*pre_power_on)(device_t); 177 void (*pre_power_on)(device_t);
164 void (*post_power_on)(device_t); 178 void (*post_power_on)(device_t);
165 void (*power_off)(device_t); 179 void (*power_off)(device_t);
166 void (*reset)(device_t); 180 void (*reset)(device_t);
167}; 181};
168 182
169 183
170struct fdtbus_phy_controller; 184struct fdtbus_phy_controller;
171 185
172struct fdtbus_phy { 186struct fdtbus_phy {
@@ -191,26 +205,33 @@ struct fdtbus_pinctrl_pin { @@ -191,26 +205,33 @@ struct fdtbus_pinctrl_pin {
191struct fdtbus_pinctrl_controller_func { 205struct fdtbus_pinctrl_controller_func {
192 int (*set_config)(device_t, const void *, size_t); 206 int (*set_config)(device_t, const void *, size_t);
193}; 207};
194 208
195 209
196struct fdtbus_power_controller; 210struct fdtbus_power_controller;
197 211
198struct fdtbus_power_controller_func { 212struct fdtbus_power_controller_func {
199 void (*reset)(device_t); 213 void (*reset)(device_t);
200 void (*poweroff)(device_t); 214 void (*poweroff)(device_t);
201}; 215};
202 216
203 217
 218struct fdtbus_powerdomain_controller;
 219
 220struct fdtbus_powerdomain_controller_func {
 221 void (*pdc_enable)(device_t, const uint32_t *, bool);
 222};
 223
 224
204struct fdtbus_pwm_controller_func { 225struct fdtbus_pwm_controller_func {
205 pwm_tag_t (*get_tag)(device_t, const void *, size_t); 226 pwm_tag_t (*get_tag)(device_t, const void *, size_t);
206}; 227};
207 228
208 229
209struct fdtbus_regulator_controller; 230struct fdtbus_regulator_controller;
210 231
211struct fdtbus_regulator { 232struct fdtbus_regulator {
212 struct fdtbus_regulator_controller *reg_rc; 233 struct fdtbus_regulator_controller *reg_rc;
213}; 234};
214 235
215struct fdtbus_regulator_controller_func { 236struct fdtbus_regulator_controller_func {
216 int (*acquire)(device_t); 237 int (*acquire)(device_t);
@@ -296,32 +317,36 @@ struct fdt_dma_range { @@ -296,32 +317,36 @@ struct fdt_dma_range {
296int fdtbus_register_clock_controller(device_t, int, 317int fdtbus_register_clock_controller(device_t, int,
297 const struct fdtbus_clock_controller_func *); 318 const struct fdtbus_clock_controller_func *);
298int fdtbus_register_dai_controller(device_t, int, 319int fdtbus_register_dai_controller(device_t, int,
299 const struct fdtbus_dai_controller_func *); 320 const struct fdtbus_dai_controller_func *);
300int fdtbus_register_dma_controller(device_t, int, 321int fdtbus_register_dma_controller(device_t, int,
301 const struct fdtbus_dma_controller_func *); 322 const struct fdtbus_dma_controller_func *);
302int fdtbus_register_gpio_controller(device_t, int, 323int fdtbus_register_gpio_controller(device_t, int,
303 const struct fdtbus_gpio_controller_func *); 324 const struct fdtbus_gpio_controller_func *);
304int fdtbus_register_i2c_controller(i2c_tag_t, int); 325int fdtbus_register_i2c_controller(i2c_tag_t, int);
305int fdtbus_register_interrupt_controller(device_t, int, 326int fdtbus_register_interrupt_controller(device_t, int,
306 const struct fdtbus_interrupt_controller_func *); 327 const struct fdtbus_interrupt_controller_func *);
307int fdtbus_register_iommu(device_t, int, 328int fdtbus_register_iommu(device_t, int,
308 const struct fdtbus_iommu_func *); 329 const struct fdtbus_iommu_func *);
 330int fdtbus_register_mbox_controller(device_t, int,
 331 const struct fdtbus_mbox_controller_func *);
309int fdtbus_register_mmc_pwrseq(device_t, int, 332int fdtbus_register_mmc_pwrseq(device_t, int,
310 const struct fdtbus_mmc_pwrseq_func *); 333 const struct fdtbus_mmc_pwrseq_func *);
311int fdtbus_register_pinctrl_config(device_t, int, 334int fdtbus_register_pinctrl_config(device_t, int,
312 const struct fdtbus_pinctrl_controller_func *); 335 const struct fdtbus_pinctrl_controller_func *);
313int fdtbus_register_power_controller(device_t, int, 336int fdtbus_register_power_controller(device_t, int,
314 const struct fdtbus_power_controller_func *); 337 const struct fdtbus_power_controller_func *);
 338int fdtbus_register_powerdomain_controller(device_t, int,
 339 const struct fdtbus_powerdomain_controller_func *);
315int fdtbus_register_phy_controller(device_t, int, 340int fdtbus_register_phy_controller(device_t, int,
316 const struct fdtbus_phy_controller_func *); 341 const struct fdtbus_phy_controller_func *);
317int fdtbus_register_pwm_controller(device_t, int, 342int fdtbus_register_pwm_controller(device_t, int,
318 const struct fdtbus_pwm_controller_func *); 343 const struct fdtbus_pwm_controller_func *);
319int fdtbus_register_regulator_controller(device_t, int, 344int fdtbus_register_regulator_controller(device_t, int,
320 const struct fdtbus_regulator_controller_func *); 345 const struct fdtbus_regulator_controller_func *);
321int fdtbus_register_reset_controller(device_t, int, 346int fdtbus_register_reset_controller(device_t, int,
322 const struct fdtbus_reset_controller_func *); 347 const struct fdtbus_reset_controller_func *);
323int fdtbus_register_spi_controller(device_t, int, 348int fdtbus_register_spi_controller(device_t, int,
324 const struct fdtbus_spi_controller_func *); 349 const struct fdtbus_spi_controller_func *);
325int fdtbus_register_syscon(device_t, int, struct syscon *); 350int fdtbus_register_syscon(device_t, int, struct syscon *);
326 351
327void fdtbus_set_decoderegprop(bool); 352void fdtbus_set_decoderegprop(bool);
@@ -382,26 +407,35 @@ void * fdtbus_intr_establish_byname(int @@ -382,26 +407,35 @@ void * fdtbus_intr_establish_byname(int
382 int (*func)(void *), void *arg, const char *); 407 int (*func)(void *), void *arg, const char *);
383void * fdtbus_intr_establish_raw(int, const u_int *, int, int, 408void * fdtbus_intr_establish_raw(int, const u_int *, int, int,
384 int (*func)(void *), void *arg, const char *); 409 int (*func)(void *), void *arg, const char *);
385void fdtbus_intr_mask(int, void *); 410void fdtbus_intr_mask(int, void *);
386void fdtbus_intr_unmask(int, void *); 411void fdtbus_intr_unmask(int, void *);
387void fdtbus_intr_disestablish(int, void *); 412void fdtbus_intr_disestablish(int, void *);
388bool fdtbus_intr_str(int, u_int, char *, size_t); 413bool fdtbus_intr_str(int, u_int, char *, size_t);
389bool fdtbus_intr_str_raw(int, const u_int *, char *, size_t); 414bool fdtbus_intr_str_raw(int, const u_int *, char *, size_t);
390int fdtbus_intr_parent(int); 415int fdtbus_intr_parent(int);
391 416
392bus_dma_tag_t fdtbus_iommu_map(int, u_int, bus_dma_tag_t); 417bus_dma_tag_t fdtbus_iommu_map(int, u_int, bus_dma_tag_t);
393bus_dma_tag_t fdtbus_iommu_map_pci(int, uint32_t, bus_dma_tag_t); 418bus_dma_tag_t fdtbus_iommu_map_pci(int, uint32_t, bus_dma_tag_t);
394 419
 420struct fdtbus_mbox_channel *
 421 fdtbus_mbox_get(int, const char *, void (*)(void *), void *);
 422struct fdtbus_mbox_channel *
 423 fdtbus_mbox_get_index(int, u_int, void (*)(void *),
 424 void *);
 425int fdtbus_mbox_send(struct fdtbus_mbox_channel *, const void *, size_t);
 426int fdtbus_mbox_recv(struct fdtbus_mbox_channel *, void *, size_t);
 427void fdtbus_mbox_put(struct fdtbus_mbox_channel *);
 428
395struct fdtbus_mmc_pwrseq * 429struct fdtbus_mmc_pwrseq *
396 fdtbus_mmc_pwrseq_get(int); 430 fdtbus_mmc_pwrseq_get(int);
397void fdtbus_mmc_pwrseq_pre_power_on(struct fdtbus_mmc_pwrseq *); 431void fdtbus_mmc_pwrseq_pre_power_on(struct fdtbus_mmc_pwrseq *);
398void fdtbus_mmc_pwrseq_post_power_on(struct fdtbus_mmc_pwrseq *); 432void fdtbus_mmc_pwrseq_post_power_on(struct fdtbus_mmc_pwrseq *);
399void fdtbus_mmc_pwrseq_power_off(struct fdtbus_mmc_pwrseq *); 433void fdtbus_mmc_pwrseq_power_off(struct fdtbus_mmc_pwrseq *);
400void fdtbus_mmc_pwrseq_reset(struct fdtbus_mmc_pwrseq *); 434void fdtbus_mmc_pwrseq_reset(struct fdtbus_mmc_pwrseq *);
401 435
402struct fdtbus_phy * 436struct fdtbus_phy *
403 fdtbus_phy_get(int, const char *); 437 fdtbus_phy_get(int, const char *);
404struct fdtbus_phy * 438struct fdtbus_phy *
405 fdtbus_phy_get_index(int, u_int); 439 fdtbus_phy_get_index(int, u_int);
406void fdtbus_phy_put(struct fdtbus_phy *); 440void fdtbus_phy_put(struct fdtbus_phy *);
407device_t fdtbus_phy_device(struct fdtbus_phy *); 441device_t fdtbus_phy_device(struct fdtbus_phy *);
@@ -437,26 +471,31 @@ int fdtbus_regulator_supports_voltage(s @@ -437,26 +471,31 @@ int fdtbus_regulator_supports_voltage(s
437struct fdtbus_reset * 471struct fdtbus_reset *
438 fdtbus_reset_get(int, const char *); 472 fdtbus_reset_get(int, const char *);
439struct fdtbus_reset * 473struct fdtbus_reset *
440 fdtbus_reset_get_index(int, u_int); 474 fdtbus_reset_get_index(int, u_int);
441void fdtbus_reset_put(struct fdtbus_reset *); 475void fdtbus_reset_put(struct fdtbus_reset *);
442int fdtbus_reset_assert(struct fdtbus_reset *); 476int fdtbus_reset_assert(struct fdtbus_reset *);
443int fdtbus_reset_deassert(struct fdtbus_reset *); 477int fdtbus_reset_deassert(struct fdtbus_reset *);
444 478
445int fdtbus_todr_attach(device_t, int, todr_chip_handle_t); 479int fdtbus_todr_attach(device_t, int, todr_chip_handle_t);
446 480
447void fdtbus_power_reset(void); 481void fdtbus_power_reset(void);
448void fdtbus_power_poweroff(void); 482void fdtbus_power_poweroff(void);
449 483
 484int fdtbus_powerdomain_enable(int);
 485int fdtbus_powerdomain_enable_index(int, int);
 486int fdtbus_powerdomain_disable(int);
 487int fdtbus_powerdomain_disable_index(int, int);
 488
450struct syscon * fdtbus_syscon_acquire(int, const char *); 489struct syscon * fdtbus_syscon_acquire(int, const char *);
451struct syscon * fdtbus_syscon_lookup(int); 490struct syscon * fdtbus_syscon_lookup(int);
452 491
453 492
454device_t fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t); 493device_t fdtbus_attach_i2cbus(device_t, int, i2c_tag_t, cfprint_t);
455device_t fdtbus_attach_spibus(device_t, int, cfprint_t); 494device_t fdtbus_attach_spibus(device_t, int, cfprint_t);
456 495
457bool fdtbus_init(const void *); 496bool fdtbus_init(const void *);
458const void * fdtbus_get_data(void); 497const void * fdtbus_get_data(void);
459int fdtbus_phandle2offset(int); 498int fdtbus_phandle2offset(int);
460int fdtbus_offset2phandle(int); 499int fdtbus_offset2phandle(int);
461bool fdtbus_get_path(int, char *, size_t); 500bool fdtbus_get_path(int, char *, size_t);
462 501

cvs diff -r1.62 -r1.63 src/sys/dev/fdt/files.fdt (expand / switch to unified diff)

--- src/sys/dev/fdt/files.fdt 2021/09/04 12:34:39 1.62
+++ src/sys/dev/fdt/files.fdt 2022/03/04 08:19:06 1.63
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: files.fdt,v 1.62 2021/09/04 12:34:39 jmcneill Exp $ 1# $NetBSD: files.fdt,v 1.63 2022/03/04 08:19:06 skrll Exp $
2 2
3include "external/bsd/libfdt/conf/files.libfdt" 3include "external/bsd/libfdt/conf/files.libfdt"
4 4
5defflag opt_fdt.h FDTBASE : libfdt, ofw_subr 5defflag opt_fdt.h FDTBASE : libfdt, ofw_subr
6defflag opt_fdt.h FDT: FDTBASE 6defflag opt_fdt.h FDT: FDTBASE
7defparam opt_fdt.h FDT_MEMORY_RANGES 7defparam opt_fdt.h FDT_MEMORY_RANGES
8defparam opt_fdt.h FDT_DEFAULT_STDOUT_PATH 8defparam opt_fdt.h FDT_DEFAULT_STDOUT_PATH
9 9
10define fdt { [pass = 10] } : clk, pwm 10define fdt { [pass = 10] } : clk, pwm
11 11
12device simplebus: fdt 12device simplebus: fdt
13attach simplebus at fdt 13attach simplebus at fdt
14file dev/fdt/fdtbus.c fdt 14file dev/fdt/fdtbus.c fdt
@@ -64,29 +64,31 @@ file dev/fdt/i2cmux_fdt.c iicmux_fdt @@ -64,29 +64,31 @@ file dev/fdt/i2cmux_fdt.c iicmux_fdt
64 64
65file dev/fdt/fdt_memory.c fdtbase 65file dev/fdt/fdt_memory.c fdtbase
66file dev/fdt/fdt_openfirm.c fdtbase 66file dev/fdt/fdt_openfirm.c fdtbase
67file dev/fdt/fdt_subr.c fdtbase 67file dev/fdt/fdt_subr.c fdtbase
68 68
69file dev/fdt/fdt_clock.c fdt 69file dev/fdt/fdt_clock.c fdt
70file dev/fdt/fdt_dai.c fdt 70file dev/fdt/fdt_dai.c fdt
71file dev/fdt/fdt_dma.c fdt 71file dev/fdt/fdt_dma.c fdt
72file dev/fdt/fdt_ddb.c fdt & ddb 72file dev/fdt/fdt_ddb.c fdt & ddb
73file dev/fdt/fdt_gpio.c fdt 73file dev/fdt/fdt_gpio.c fdt
74file dev/fdt/fdt_i2c.c fdt 74file dev/fdt/fdt_i2c.c fdt
75file dev/fdt/fdt_iommu.c fdt 75file dev/fdt/fdt_iommu.c fdt
76file dev/fdt/fdt_intr.c fdt 76file dev/fdt/fdt_intr.c fdt
 77file dev/fdt/fdt_mbox.c fdt
77file dev/fdt/fdt_mmc_pwrseq.c fdt 78file dev/fdt/fdt_mmc_pwrseq.c fdt
78file dev/fdt/fdt_phy.c fdt 79file dev/fdt/fdt_phy.c fdt
79file dev/fdt/fdt_power.c fdt 80file dev/fdt/fdt_power.c fdt
 81file dev/fdt/fdt_powerdomain.c fdt
80file dev/fdt/fdt_pwm.c fdt 82file dev/fdt/fdt_pwm.c fdt
81file dev/fdt/fdt_regulator.c fdt 83file dev/fdt/fdt_regulator.c fdt
82file dev/fdt/fdt_reset.c fdt 84file dev/fdt/fdt_reset.c fdt
83file dev/fdt/fdt_rtc.c fdt 85file dev/fdt/fdt_rtc.c fdt
84file dev/fdt/fdt_spi.c fdt 86file dev/fdt/fdt_spi.c fdt
85file dev/fdt/fdt_syscon.c fdt 87file dev/fdt/fdt_syscon.c fdt
86file dev/fdt/fdt_pinctrl.c fdt 88file dev/fdt/fdt_pinctrl.c fdt
87 89
88device cpus: fdt 90device cpus: fdt
89attach cpus at fdt 91attach cpus at fdt
90file dev/fdt/cpus.c cpus 92file dev/fdt/cpus.c cpus
91 93
92device mmcpwrseq 94device mmcpwrseq