Home | History | Annotate | Line # | Download | only in dev
neptune.c revision 1.10
      1 /*	$NetBSD: neptune.c,v 1.10 2003/07/15 01:44:52 lukem 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.10 2003/07/15 01:44:52 lukem 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 __P((bus_space_tag_t, bus_addr_t, bus_size_t,
     59 				      int, bus_space_handle_t*));
     60 static void neptune_bus_space_unmap __P((bus_space_tag_t,
     61 					 bus_space_handle_t, bus_size_t));
     62 static int neptune_bus_space_subregion __P((bus_space_tag_t, bus_space_handle_t,
     63 					    bus_size_t, bus_size_t,
     64 					    bus_space_handle_t*));
     65 
     66 static struct x68k_bus_space neptune_bus = {
     67 #if 0
     68 	X68K_NEPUTUNE_BUS,
     69 #endif
     70 	neptune_bus_space_map, neptune_bus_space_unmap,
     71 	neptune_bus_space_subregion,
     72 	x68k_bus_space_alloc, x68k_bus_space_free,
     73 };
     74 
     75 
     76 static int neptune_match __P((struct device *, struct cfdata *, void *));
     77 static void neptune_attach __P((struct device *, struct device *, void *));
     78 static int neptune_search __P((struct device *, struct cfdata *cf, void *));
     79 static int neptune_print __P((void *, const char *));
     80 
     81 CFATTACH_DECL(neptune, sizeof(struct neptune_softc),
     82     neptune_match, neptune_attach, NULL, NULL);
     83 
     84 static int
     85 neptune_match(parent, cf, aux)
     86 	struct device *parent;
     87 	struct cfdata *cf;
     88 	void *aux;
     89 {
     90 	struct intio_attach_args *ia = aux;
     91 
     92 	if (strcmp(ia->ia_name, "neptune") != 0)
     93 		return 0;
     94 
     95 	ia->ia_size = 0x400;
     96 	if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
     97 		return 0;
     98 
     99 	/* Neptune is a virtual device.  Always there. */
    100 
    101 	return (1);
    102 }
    103 
    104 
    105 static void
    106 neptune_attach(parent, self, aux)
    107 	struct device *parent, *self;
    108 	void *aux;
    109 {
    110 	struct neptune_softc *sc = (struct neptune_softc *)self;
    111 	struct intio_attach_args *ia = aux;
    112 	struct neptune_attach_args na;
    113 	int r;
    114 	struct cfdata *cf;
    115 
    116 	ia->ia_size = 0x400;
    117 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    118 #ifdef DIAGNOSTIC
    119 	if (r)
    120 		panic ("IO map for Neptune corruption??");
    121 #endif
    122 
    123 	sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
    124 	if (sc->sc_bst == NULL)
    125 		panic("neptune_attach: can't allocate bus_space structure");
    126 	*sc->sc_bst = neptune_bus;
    127 	sc->sc_bst->x68k_bus_device = self;
    128 
    129 	sc->sc_addr = (vaddr_t) (ia->ia_addr - PHYS_INTIODEV + intiobase);
    130 
    131 	na.na_bst = sc->sc_bst;
    132 	na.na_intr = ia->ia_intr;
    133 
    134 	cf = config_search (neptune_search, self, &na);
    135 	if (cf) {
    136 		printf (": Neptune-X ISA bridge\n");
    137 		config_attach(self, cf, &na, neptune_print);
    138 	} else {
    139 		printf (": no device found.\n");
    140 		intio_map_free_region(parent, ia);
    141 	}
    142 }
    143 
    144 static int
    145 neptune_search(parent, cf, aux)
    146 	struct device *parent;
    147 	struct cfdata *cf;
    148 	void *aux;
    149 {
    150 	struct neptune_attach_args *na = aux;
    151 
    152 	na->na_addr = cf->neptune_cf_addr;
    153 
    154 	return config_match(parent, cf, na);
    155 }
    156 
    157 static int
    158 neptune_print(aux, name)
    159 	void *aux;
    160 	const char *name;
    161 {
    162 	struct neptune_attach_args *na = aux;
    163 
    164 /*	if (na->na_addr > 0)	*/
    165 		aprint_normal (" addr 0x%06x", na->na_addr);
    166 
    167 	return (QUIET);
    168 }
    169 
    170 
    171 /*
    172  * neptune bus space stuff.
    173  */
    174 static int
    175 neptune_bus_space_map(t, bpa, size, flags, bshp)
    176 	bus_space_tag_t t;
    177 	bus_addr_t bpa;
    178 	bus_size_t size;
    179 	int flags;
    180 	bus_space_handle_t *bshp;
    181 {
    182 	vaddr_t start = ((struct neptune_softc*) ((struct x68k_bus_space*) t)
    183 			 ->x68k_bus_device)->sc_addr;
    184 
    185 	/*
    186 	 * Neptune bus is mapped permanently.
    187 	 */
    188 	*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
    189 
    190 	if (badaddr((caddr_t)*bshp)) {
    191 		return 1;
    192 	}
    193 
    194 	*bshp |= 0x80000000;	/* higher byte (= even address) only */
    195 
    196 	return (0);
    197 }
    198 
    199 static void
    200 neptune_bus_space_unmap(t, bsh, size)
    201 	bus_space_tag_t t;
    202 	bus_space_handle_t bsh;
    203 	bus_size_t size;
    204 {
    205 	return;
    206 }
    207 
    208 static int
    209 neptune_bus_space_subregion(t, bsh, offset, size, nbshp)
    210 	bus_space_tag_t t;
    211 	bus_space_handle_t bsh;
    212 	bus_size_t offset, size;
    213 	bus_space_handle_t *nbshp;
    214 {
    215 
    216 	*nbshp = bsh + offset*2;
    217 	return (0);
    218 }
    219