Home | History | Annotate | Line # | Download | only in dev
      1 /*	$Id: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software developed for The NetBSD Foundation
      8  * by Masao Uebayashi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $");
     34 
     35 #include "locators.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/extent.h>
     41 #include <sys/bus.h>
     42 
     43 #include <powerpc/ibm4xx/dcr4xx.h>
     44 #include <powerpc/ibm4xx/dev/exbvar.h>
     45 
     46 struct exb_softc {
     47 };
     48 
     49 extern const struct exb_conf exb_confs[];
     50 
     51 static int exb_match(device_t, cfdata_t, void *);
     52 static void exb_attach(device_t, device_t, void *);
     53 static int exb_print(void *, const char *);
     54 
     55 CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach,
     56     NULL, NULL);
     57 
     58 static struct powerpc_bus_space exb_bus_space_tag =
     59     { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 };
     60 
     61 static int
     62 exb_match(device_t parent, cfdata_t cf, void *aux)
     63 {
     64 
     65 	return 1;
     66 }
     67 
     68 static void
     69 exb_attach(device_t parent, device_t self, void *aux)
     70 {
     71 	const struct exb_conf *ec = exb_confs;
     72 	uint32_t ebc0_bNcr;
     73 	bus_addr_t base, size;
     74 	int locs[EXBCF_NLOCS];
     75 
     76 	printf("\n");
     77 
     78 	/* mtdcr needs a constant */
     79 	switch (device_unit(self)) {
     80 	case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR);	break;
     81 	case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR);	break;
     82 	case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR);	break;
     83 	case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR);	break;
     84 	case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR);	break;
     85 	case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR);	break;
     86 	case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR);	break;
     87 	case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR);	break;
     88 	}
     89 	ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA);
     90 	base = ebc0_bNcr & 0xfff00000;
     91 	size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17);
     92 
     93 	exb_bus_space_tag.pbs_base = base;
     94 	exb_bus_space_tag.pbs_limit = base + size - 1;
     95 
     96 	while (ec->ec_name) {
     97 		struct exb_conf ec1;
     98 
     99 		locs[EXBCF_ADDR] = ec->ec_addr;
    100 
    101 		ec1 = *ec;
    102 		ec1.ec_bust = exb_get_bus_space_tag();
    103 
    104 		config_found(self, &ec1, exb_print,
    105 		    CFARGS(.submatch = config_stdsubmatch,
    106 			   .locators = locs));
    107 		ec++;
    108 	}
    109 }
    110 
    111 static int
    112 exb_print(void *aux, const char *bus)
    113 {
    114 	struct exb_conf *ec = aux;
    115 
    116 	if (bus)
    117 		return QUIET;
    118 
    119 	if (ec->ec_addr)
    120 		printf(" addr %"PRIxBUSADDR, ec->ec_addr);
    121 
    122 	return UNCONF;
    123 }
    124 
    125 bus_space_tag_t
    126 exb_get_bus_space_tag(void)
    127 {
    128 	static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
    129 	    __attribute__((aligned(8)));
    130 	static int exb_bus_space_tag_inited;
    131 
    132 	if (exb_bus_space_tag_inited == 0) {
    133 		if (bus_space_init(&exb_bus_space_tag, "exbtag",
    134 		    ex_storage, sizeof(ex_storage)))
    135 			panic("exb_attach: Failed to initialise exb_bus_space_tag");
    136 		exb_bus_space_tag_inited = 1;
    137 	}
    138 	return &exb_bus_space_tag;
    139 }
    140