From: kettenis Date: Sun, 30 Apr 2017 13:54:00 +0000 (+0000) Subject: Make early attrbute work here as well. Remove unreachable panic while there. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bc8204c3a8187abdb3a6ed257ecfdd423a9335bb;p=openbsd Make early attrbute work here as well. Remove unreachable panic while there. ok visa@ --- diff --git a/sys/arch/arm64/dev/mainbus.c b/sys/arch/arm64/dev/mainbus.c index 1d8c8bbc274..a5e6bf3f785 100644 --- a/sys/arch/arm64/dev/mainbus.c +++ b/sys/arch/arm64/dev/mainbus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mainbus.c,v 1.4 2017/04/27 10:23:19 kettenis Exp $ */ +/* $OpenBSD: mainbus.c,v 1.5 2017/04/30 13:54:00 kettenis Exp $ */ /* * Copyright (c) 2016 Patrick Wildt * Copyright (c) 2017 Mark Kettenis @@ -40,12 +40,14 @@ int mainbus_match_secondary(struct device *, void *, void *); 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, struct device *self, void *aux) 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, struct device *self, void *aux) } /* 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 node, cfmatch_t submatch) 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 *parent, void *match, void *aux) 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