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