Home | History | Annotate | Line # | Download | only in dev
neptune.c revision 1.12
      1 /*	$NetBSD: neptune.c,v 1.12 2005/06/13 00:34:08 he Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Minoura Makoto.
      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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. The name of the author may not be used to endorse or promote products
     23  *    derived from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Neptune-X -- X68k-ISA Bus Bridge
     40  */
     41 
     42 #include <sys/cdefs.h>
     43 __KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.12 2005/06/13 00:34:08 he Exp $");
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/device.h>
     48 #include <sys/malloc.h>
     49 
     50 #include <machine/bus.h>
     51 #include <machine/cpu.h>
     52 #include <machine/frame.h>
     53 
     54 #include <arch/x68k/dev/intiovar.h>
     55 #include <arch/x68k/dev/neptunevar.h>
     56 
     57 /* bus_space stuff */
     58 static int neptune_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
     59 	int, bus_space_handle_t *);
     60 static void neptune_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
     61 	bus_size_t);
     62 static int neptune_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
     63 	bus_size_t, bus_size_t, bus_space_handle_t *);
     64 
     65 static struct x68k_bus_space neptune_bus = {
     66 #if 0
     67 	X68K_NEPUTUNE_BUS,
     68 #endif
     69 	neptune_bus_space_map, neptune_bus_space_unmap,
     70 	neptune_bus_space_subregion,
     71 	x68k_bus_space_alloc, x68k_bus_space_free,
     72 };
     73 
     74 
     75 static int neptune_match(struct device *, struct cfdata *, void *);
     76 static void neptune_attach(struct device *, struct device *, void *);
     77 static int neptune_search(struct device *, struct cfdata *cf, void *);
     78 static int neptune_print(void *, const char *);
     79 
     80 CFATTACH_DECL(neptune, sizeof(struct neptune_softc),
     81     neptune_match, neptune_attach, NULL, NULL);
     82 
     83 static int
     84 neptune_match(struct device *parent, struct cfdata *cf, void *aux)
     85 {
     86 	struct intio_attach_args *ia = aux;
     87 
     88 	if (strcmp(ia->ia_name, "neptune") != 0)
     89 		return 0;
     90 
     91 	ia->ia_size = 0x400;
     92 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
     93 		return 0;
     94 
     95 	/* Neptune is a virtual device.  Always there. */
     96 
     97 	return (1);
     98 }
     99 
    100 
    101 static void
    102 neptune_attach(struct device *parent, struct device *self, void *aux)
    103 {
    104 	struct neptune_softc *sc = (struct neptune_softc *)self;
    105 	struct intio_attach_args *ia = aux;
    106 	struct neptune_attach_args na;
    107 	int r;
    108 	struct cfdata *cf;
    109 
    110 	ia->ia_size = 0x400;
    111 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    112 #ifdef DIAGNOSTIC
    113 	if (r)
    114 		panic ("IO map for Neptune corruption??");
    115 #endif
    116 
    117 	sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
    118 	if (sc->sc_bst == NULL)
    119 		panic("neptune_attach: can't allocate bus_space structure");
    120 	*sc->sc_bst = neptune_bus;
    121 	sc->sc_bst->x68k_bus_device = self;
    122 
    123 	sc->sc_addr = (vaddr_t) (ia->ia_addr - PHYS_INTIODEV + intiobase);
    124 
    125 	na.na_bst = sc->sc_bst;
    126 	na.na_intr = ia->ia_intr;
    127 
    128 	cf = config_search (neptune_search, self, &na);
    129 	if (cf) {
    130 		printf (": Neptune-X ISA bridge\n");
    131 		config_attach(self, cf, &na, neptune_print);
    132 	} else {
    133 		printf (": no device found.\n");
    134 		intio_map_free_region(parent, ia);
    135 	}
    136 }
    137 
    138 static int
    139 neptune_search(struct device *parent, struct cfdata *cf, void *aux)
    140 {
    141 	struct neptune_attach_args *na = aux;
    142 
    143 	na->na_addr = cf->neptune_cf_addr;
    144 
    145 	return config_match(parent, cf, na);
    146 }
    147 
    148 static int
    149 neptune_print(void *aux, const char *name)
    150 {
    151 	struct neptune_attach_args *na = aux;
    152 
    153 /*	if (na->na_addr > 0)	*/
    154 		aprint_normal (" addr 0x%06x", na->na_addr);
    155 
    156 	return (QUIET);
    157 }
    158 
    159 
    160 /*
    161  * neptune bus space stuff.
    162  */
    163 static int
    164 neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
    165     int flags, bus_space_handle_t *bshp)
    166 {
    167 	vaddr_t start = ((struct neptune_softc*) ((struct x68k_bus_space*) t)
    168 			 ->x68k_bus_device)->sc_addr;
    169 
    170 	/*
    171 	 * Neptune bus is mapped permanently.
    172 	 */
    173 	*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
    174 
    175 	if (badaddr((void*)*bshp)) {
    176 		return 1;
    177 	}
    178 
    179 	*bshp |= 0x80000000;	/* higher byte (= even address) only */
    180 
    181 	return (0);
    182 }
    183 
    184 static void
    185 neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
    186     bus_size_t size)
    187 {
    188 	return;
    189 }
    190 
    191 static int
    192 neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
    193     bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    194 {
    195 
    196 	*nbshp = bsh + offset*2;
    197 	return (0);
    198 }
    199