On Sun, Apr 30, 2017 at 03:04:38PM +0200, Mark Kettenis wrote:
> Here is a diff that makes mainbus(4) behave in a similar way as
> simplebus(4). Needed for the Firefly-RK3399 since it attaches most
> devices directly on mainbus(4) and need to control the order a bit.
>
> I dropped the "no device tree" panic. We really can't get this far
> without having an FDT.
>
> I'll do a similar diff for armv7 as the RK3288 will need this as well.
>
> ok?
ok patrick@
>
>
> Index: arch/arm64/dev/mainbus.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/arm64/dev/mainbus.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 mainbus.c
> --- arch/arm64/dev/mainbus.c 27 Apr 2017 10:23:19 -0000 1.4
> +++ arch/arm64/dev/mainbus.c 30 Apr 2017 13:00:28 -0000
> @@ -40,12 +40,14 @@ int mainbus_match_secondary(struct devic
>
> struct mainbus_softc {
> struct device sc_dev;
> + int sc_node;
> bus_space_tag_t sc_iot;
> bus_dma_tag_t sc_dmat;
> int sc_acells;
> int sc_scells;
> int *sc_ranges;
> int sc_rangeslen;
> + int sc_early;
> };
>
> struct cfattach mainbus_ca = {
> @@ -96,18 +98,17 @@ mainbus_attach(struct device *parent, st
> char model[128];
> int node, len;
>
> - if ((node = OF_peer(0)) == 0)
> - panic("mainbus: no device tree");
> -
> arm_intr_init_fdt();
> agtimer_init();
>
> + sc->sc_node = OF_peer(0);
> sc->sc_iot = &arm64_bs_tag;
> sc->sc_dmat = &mainbus_dma_tag;
> sc->sc_acells = OF_getpropint(OF_peer(0), "#address-cells", 1);
> sc->sc_scells = OF_getpropint(OF_peer(0), "#size-cells", 1);
>
> - if ((len = OF_getprop(node, "model", model, sizeof(model))) > 0) {
> + len = OF_getprop(sc->sc_node, "model", model, sizeof(model));
> + if (len > 0) {
> printf(": %s\n", model);
> hw_prod = malloc(len, M_DEVBUF, M_NOWAIT);
> if (hw_prod)
> @@ -126,9 +127,14 @@ mainbus_attach(struct device *parent, st
> }
>
> /* Scan the whole tree. */
> - for (node = OF_child(node); node != 0; node = OF_peer(node))
> + sc->sc_early = 1;
> + for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
> mainbus_attach_node(self, node, NULL);
>
> + sc->sc_early = 0;
> + for (node = OF_child(sc->sc_node); node != 0; node = OF_peer(node))
> + mainbus_attach_node(self, node, NULL);
> +
> /* Attach secondary CPUs. */
> mainbus_attach_cpus(self, mainbus_match_secondary);
> }
> @@ -204,6 +210,7 @@ mainbus_attach_node(struct device *self,
> int
> mainbus_match_status(struct device *parent, void *match, void *aux)
> {
> + struct mainbus_softc *sc = (struct mainbus_softc *)parent;
> struct fdt_attach_args *fa = aux;
> struct cfdata *cf = match;
> char buf[32];
> @@ -212,7 +219,9 @@ mainbus_match_status(struct device *pare
> strcmp(buf, "disabled") == 0)
> return 0;
>
> - return (*cf->cf_attach->ca_match)(parent, match, aux);
> + if (cf->cf_loc[0] == sc->sc_early)
> + return (*cf->cf_attach->ca_match)(parent, match, aux);
> + return 0;
> }
>
> void
>