1*89ca88e0Sjmcneill /* $NetBSD: fdt_userconf.c,v 1.1 2022/03/25 21:23:51 jmcneill Exp $ */
2*89ca88e0Sjmcneill
3*89ca88e0Sjmcneill /*-
4*89ca88e0Sjmcneill * Copyright (c) 2022 Jared McNeill <jmcneill@invisible.ca>
5*89ca88e0Sjmcneill * All rights reserved.
6*89ca88e0Sjmcneill *
7*89ca88e0Sjmcneill * Redistribution and use in source and binary forms, with or without
8*89ca88e0Sjmcneill * modification, are permitted provided that the following conditions
9*89ca88e0Sjmcneill * are met:
10*89ca88e0Sjmcneill * 1. Redistributions of source code must retain the above copyright
11*89ca88e0Sjmcneill * notice, this list of conditions and the following disclaimer.
12*89ca88e0Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright
13*89ca88e0Sjmcneill * notice, this list of conditions and the following disclaimer in the
14*89ca88e0Sjmcneill * documentation and/or other materials provided with the distribution.
15*89ca88e0Sjmcneill *
16*89ca88e0Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*89ca88e0Sjmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*89ca88e0Sjmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*89ca88e0Sjmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20*89ca88e0Sjmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21*89ca88e0Sjmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*89ca88e0Sjmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23*89ca88e0Sjmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24*89ca88e0Sjmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*89ca88e0Sjmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*89ca88e0Sjmcneill * SUCH DAMAGE.
27*89ca88e0Sjmcneill */
28*89ca88e0Sjmcneill
29*89ca88e0Sjmcneill #include <sys/cdefs.h>
30*89ca88e0Sjmcneill __KERNEL_RCSID(0, "$NetBSD: fdt_userconf.c,v 1.1 2022/03/25 21:23:51 jmcneill Exp $");
31*89ca88e0Sjmcneill
32*89ca88e0Sjmcneill #include <sys/param.h>
33*89ca88e0Sjmcneill #include <sys/systm.h>
34*89ca88e0Sjmcneill #include <sys/userconf.h>
35*89ca88e0Sjmcneill
36*89ca88e0Sjmcneill #include <libfdt.h>
37*89ca88e0Sjmcneill #include <dev/fdt/fdtvar.h>
38*89ca88e0Sjmcneill
39*89ca88e0Sjmcneill #define FDT_CHOSEN_PATH "/chosen"
40*89ca88e0Sjmcneill #define FDT_CHOSEN_USERCONF_PROP "netbsd,userconf"
41*89ca88e0Sjmcneill
42*89ca88e0Sjmcneill void
userconf_bootinfo(void)43*89ca88e0Sjmcneill userconf_bootinfo(void)
44*89ca88e0Sjmcneill {
45*89ca88e0Sjmcneill const void *fdt = fdtbus_get_data();
46*89ca88e0Sjmcneill const char *cmd;
47*89ca88e0Sjmcneill int chosen, index;
48*89ca88e0Sjmcneill
49*89ca88e0Sjmcneill if (fdt == NULL) {
50*89ca88e0Sjmcneill return;
51*89ca88e0Sjmcneill }
52*89ca88e0Sjmcneill
53*89ca88e0Sjmcneill chosen = fdt_path_offset(fdt, FDT_CHOSEN_PATH);
54*89ca88e0Sjmcneill if (chosen < 0) {
55*89ca88e0Sjmcneill return;
56*89ca88e0Sjmcneill }
57*89ca88e0Sjmcneill
58*89ca88e0Sjmcneill index = 0;
59*89ca88e0Sjmcneill do {
60*89ca88e0Sjmcneill cmd = fdt_stringlist_get(fdt, chosen, FDT_CHOSEN_USERCONF_PROP,
61*89ca88e0Sjmcneill index++, NULL);
62*89ca88e0Sjmcneill if (cmd != NULL) {
63*89ca88e0Sjmcneill aprint_debug("Processing userconf command: %s\n", cmd);
64*89ca88e0Sjmcneill userconf_parse(__UNCONST(cmd));
65*89ca88e0Sjmcneill }
66*89ca88e0Sjmcneill } while (cmd != NULL);
67*89ca88e0Sjmcneill }
68