1*c7fb772bSthorpej /* $Id: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $ */
27e4dfb0fSuebayasi
37e4dfb0fSuebayasi /*-
47e4dfb0fSuebayasi * Copyright (c) 2010 The NetBSD Foundation, Inc.
57e4dfb0fSuebayasi * All rights reserved.
67e4dfb0fSuebayasi *
77e4dfb0fSuebayasi * This code is derived from software developed for The NetBSD Foundation
87e4dfb0fSuebayasi * by Masao Uebayashi.
97e4dfb0fSuebayasi *
107e4dfb0fSuebayasi * Redistribution and use in source and binary forms, with or without
117e4dfb0fSuebayasi * modification, are permitted provided that the following conditions
127e4dfb0fSuebayasi * are met:
137e4dfb0fSuebayasi * 1. Redistributions of source code must retain the above copyright
147e4dfb0fSuebayasi * notice, this list of conditions and the following disclaimer.
157e4dfb0fSuebayasi * 2. Redistributions in binary form must reproduce the above copyright
167e4dfb0fSuebayasi * notice, this list of conditions and the following disclaimer in the
177e4dfb0fSuebayasi * documentation and/or other materials provided with the distribution.
187e4dfb0fSuebayasi *
197e4dfb0fSuebayasi * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207e4dfb0fSuebayasi * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
217e4dfb0fSuebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
227e4dfb0fSuebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
237e4dfb0fSuebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
247e4dfb0fSuebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
257e4dfb0fSuebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
267e4dfb0fSuebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
277e4dfb0fSuebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
287e4dfb0fSuebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
297e4dfb0fSuebayasi * POSSIBILITY OF SUCH DAMAGE.
307e4dfb0fSuebayasi */
317e4dfb0fSuebayasi
327e4dfb0fSuebayasi #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $");
347e4dfb0fSuebayasi
357e4dfb0fSuebayasi #include "locators.h"
367e4dfb0fSuebayasi
377e4dfb0fSuebayasi #include <sys/param.h>
387e4dfb0fSuebayasi #include <sys/systm.h>
397e4dfb0fSuebayasi #include <sys/device.h>
407e4dfb0fSuebayasi #include <sys/extent.h>
417e4dfb0fSuebayasi #include <sys/bus.h>
427e4dfb0fSuebayasi
437e4dfb0fSuebayasi #include <powerpc/ibm4xx/dcr4xx.h>
447e4dfb0fSuebayasi #include <powerpc/ibm4xx/dev/exbvar.h>
457e4dfb0fSuebayasi
467e4dfb0fSuebayasi struct exb_softc {
477e4dfb0fSuebayasi };
487e4dfb0fSuebayasi
497e4dfb0fSuebayasi extern const struct exb_conf exb_confs[];
507e4dfb0fSuebayasi
51036ca983Smatt static int exb_match(device_t, cfdata_t, void *);
52036ca983Smatt static void exb_attach(device_t, device_t, void *);
537e4dfb0fSuebayasi static int exb_print(void *, const char *);
547e4dfb0fSuebayasi
557e4dfb0fSuebayasi CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach,
567e4dfb0fSuebayasi NULL, NULL);
577e4dfb0fSuebayasi
587e4dfb0fSuebayasi static struct powerpc_bus_space exb_bus_space_tag =
597e4dfb0fSuebayasi { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 };
607e4dfb0fSuebayasi
617e4dfb0fSuebayasi static int
exb_match(device_t parent,cfdata_t cf,void * aux)62036ca983Smatt exb_match(device_t parent, cfdata_t cf, void *aux)
637e4dfb0fSuebayasi {
647e4dfb0fSuebayasi
657e4dfb0fSuebayasi return 1;
667e4dfb0fSuebayasi }
677e4dfb0fSuebayasi
687e4dfb0fSuebayasi static void
exb_attach(device_t parent,device_t self,void * aux)697e4dfb0fSuebayasi exb_attach(device_t parent, device_t self, void *aux)
707e4dfb0fSuebayasi {
717e4dfb0fSuebayasi const struct exb_conf *ec = exb_confs;
727e4dfb0fSuebayasi uint32_t ebc0_bNcr;
737e4dfb0fSuebayasi bus_addr_t base, size;
747e4dfb0fSuebayasi int locs[EXBCF_NLOCS];
757e4dfb0fSuebayasi
767e4dfb0fSuebayasi printf("\n");
777e4dfb0fSuebayasi
787e4dfb0fSuebayasi /* mtdcr needs a constant */
797e4dfb0fSuebayasi switch (device_unit(self)) {
807e4dfb0fSuebayasi case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR); break;
817e4dfb0fSuebayasi case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR); break;
827e4dfb0fSuebayasi case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR); break;
837e4dfb0fSuebayasi case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR); break;
847e4dfb0fSuebayasi case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR); break;
857e4dfb0fSuebayasi case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR); break;
867e4dfb0fSuebayasi case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR); break;
877e4dfb0fSuebayasi case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR); break;
887e4dfb0fSuebayasi }
897e4dfb0fSuebayasi ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA);
907e4dfb0fSuebayasi base = ebc0_bNcr & 0xfff00000;
917e4dfb0fSuebayasi size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17);
927e4dfb0fSuebayasi
937e4dfb0fSuebayasi exb_bus_space_tag.pbs_base = base;
947e4dfb0fSuebayasi exb_bus_space_tag.pbs_limit = base + size - 1;
957e4dfb0fSuebayasi
967e4dfb0fSuebayasi while (ec->ec_name) {
977e4dfb0fSuebayasi struct exb_conf ec1;
987e4dfb0fSuebayasi
997e4dfb0fSuebayasi locs[EXBCF_ADDR] = ec->ec_addr;
1007e4dfb0fSuebayasi
1017e4dfb0fSuebayasi ec1 = *ec;
1027e4dfb0fSuebayasi ec1.ec_bust = exb_get_bus_space_tag();
1037e4dfb0fSuebayasi
1042685996bSthorpej config_found(self, &ec1, exb_print,
105*c7fb772bSthorpej CFARGS(.submatch = config_stdsubmatch,
106*c7fb772bSthorpej .locators = locs));
1077e4dfb0fSuebayasi ec++;
1087e4dfb0fSuebayasi }
1097e4dfb0fSuebayasi }
1107e4dfb0fSuebayasi
1117e4dfb0fSuebayasi static int
exb_print(void * aux,const char * bus)1127e4dfb0fSuebayasi exb_print(void *aux, const char *bus)
1137e4dfb0fSuebayasi {
1147e4dfb0fSuebayasi struct exb_conf *ec = aux;
1157e4dfb0fSuebayasi
1167e4dfb0fSuebayasi if (bus)
1177e4dfb0fSuebayasi return QUIET;
1187e4dfb0fSuebayasi
1197e4dfb0fSuebayasi if (ec->ec_addr)
1207e4dfb0fSuebayasi printf(" addr %"PRIxBUSADDR, ec->ec_addr);
1217e4dfb0fSuebayasi
1227e4dfb0fSuebayasi return UNCONF;
1237e4dfb0fSuebayasi }
1247e4dfb0fSuebayasi
1257e4dfb0fSuebayasi bus_space_tag_t
exb_get_bus_space_tag(void)1267e4dfb0fSuebayasi exb_get_bus_space_tag(void)
1277e4dfb0fSuebayasi {
1287e4dfb0fSuebayasi static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
1297e4dfb0fSuebayasi __attribute__((aligned(8)));
1307e4dfb0fSuebayasi static int exb_bus_space_tag_inited;
1317e4dfb0fSuebayasi
1327e4dfb0fSuebayasi if (exb_bus_space_tag_inited == 0) {
1337e4dfb0fSuebayasi if (bus_space_init(&exb_bus_space_tag, "exbtag",
1347e4dfb0fSuebayasi ex_storage, sizeof(ex_storage)))
1357e4dfb0fSuebayasi panic("exb_attach: Failed to initialise exb_bus_space_tag");
1367e4dfb0fSuebayasi exb_bus_space_tag_inited = 1;
1377e4dfb0fSuebayasi }
1387e4dfb0fSuebayasi return &exb_bus_space_tag;
1397e4dfb0fSuebayasi }
140