Home | History | Annotate | Line # | Download | only in dev
neptune.c revision 1.18
      1 /*	$NetBSD: neptune.c,v 1.18 2008/06/25 08:14:59 isaki Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The 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  *
     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 /*
     33  * Neptune-X -- X68k-ISA Bus Bridge
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: neptune.c,v 1.18 2008/06/25 08:14:59 isaki Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/malloc.h>
     43 
     44 #include <machine/bus.h>
     45 #include <machine/cpu.h>
     46 #include <machine/frame.h>
     47 
     48 #include <arch/x68k/dev/intiovar.h>
     49 #include <arch/x68k/dev/neptunevar.h>
     50 
     51 /* bus_space stuff */
     52 static int neptune_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
     53 	int, bus_space_handle_t *);
     54 static void neptune_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
     55 	bus_size_t);
     56 static int neptune_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
     57 	bus_size_t, bus_size_t, bus_space_handle_t *);
     58 
     59 static struct x68k_bus_space neptune_bus = {
     60 #if 0
     61 	X68K_NEPUTUNE_BUS,
     62 #endif
     63 	neptune_bus_space_map, neptune_bus_space_unmap,
     64 	neptune_bus_space_subregion,
     65 	x68k_bus_space_alloc, x68k_bus_space_free,
     66 };
     67 
     68 
     69 static int neptune_match(device_t, cfdata_t, void *);
     70 static void neptune_attach(device_t, device_t, void *);
     71 static int neptune_search(device_t, cfdata_t, const int *, void *);
     72 static int neptune_print(void *, const char *);
     73 
     74 CFATTACH_DECL_NEW(neptune, sizeof(struct neptune_softc),
     75     neptune_match, neptune_attach, NULL, NULL);
     76 
     77 static int
     78 neptune_match(device_t parent, cfdata_t cf, void *aux)
     79 {
     80 	struct intio_attach_args *ia = aux;
     81 
     82 	if (strcmp(ia->ia_name, "neptune") != 0)
     83 		return 0;
     84 
     85 	ia->ia_size = 0x400;
     86 	if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
     87 		return 0;
     88 
     89 	/* Neptune is a virtual device.  Always there. */
     90 
     91 	return (1);
     92 }
     93 
     94 
     95 static void
     96 neptune_attach(device_t parent, device_t self, void *aux)
     97 {
     98 	struct neptune_softc *sc = device_private(self);
     99 	struct intio_attach_args *ia = aux;
    100 	struct neptune_attach_args na;
    101 	int r;
    102 	cfdata_t cf;
    103 
    104 	ia->ia_size = 0x400;
    105 	r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
    106 #ifdef DIAGNOSTIC
    107 	if (r)
    108 		panic("IO map for Neptune corruption??");
    109 #endif
    110 
    111 	sc->sc_bst = malloc(sizeof(struct x68k_bus_space), M_DEVBUF, M_NOWAIT);
    112 	if (sc->sc_bst == NULL)
    113 		panic("neptune_attach: can't allocate bus_space structure");
    114 	*sc->sc_bst = neptune_bus;
    115 	sc->sc_bst->x68k_bus_device = self;
    116 
    117 	sc->sc_addr = (vaddr_t)(ia->ia_addr - PHYS_INTIODEV + intiobase);
    118 
    119 	na.na_bst = sc->sc_bst;
    120 	na.na_intr = ia->ia_intr;
    121 
    122 	cf = config_search_ia(neptune_search, self, "neptune", &na);
    123 	if (cf) {
    124 		aprint_normal(": Neptune-X ISA bridge\n");
    125 		config_attach(self, cf, &na, neptune_print);
    126 	} else {
    127 		aprint_normal(": no device found.\n");
    128 		intio_map_free_region(parent, ia);
    129 	}
    130 }
    131 
    132 static int
    133 neptune_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    134 {
    135 	struct neptune_attach_args *na = aux;
    136 
    137 	na->na_addr = cf->neptune_cf_addr;
    138 
    139 	return config_match(parent, cf, na);
    140 }
    141 
    142 static int
    143 neptune_print(void *aux, const char *name)
    144 {
    145 	struct neptune_attach_args *na = aux;
    146 
    147 /*	if (na->na_addr > 0)	*/
    148 		aprint_normal(" addr 0x%06x", na->na_addr);
    149 
    150 	return (QUIET);
    151 }
    152 
    153 
    154 /*
    155  * neptune bus space stuff.
    156  */
    157 static int
    158 neptune_bus_space_map(bus_space_tag_t t, bus_addr_t bpa, bus_size_t size,
    159     int flags, bus_space_handle_t *bshp)
    160 {
    161 	struct neptune_softc *sc = device_private(t->x68k_bus_device);
    162 	vaddr_t start = sc->sc_addr;
    163 
    164 	/*
    165 	 * Neptune bus is mapped permanently.
    166 	 */
    167 	*bshp = (bus_space_handle_t) ((u_int)start + ((u_int)bpa - 0x200) * 2);
    168 
    169 	if (badaddr((void *)*bshp)) {
    170 		return 1;
    171 	}
    172 
    173 	*bshp |= 0x80000000;	/* higher byte (= even address) only */
    174 
    175 	return (0);
    176 }
    177 
    178 static void
    179 neptune_bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
    180     bus_size_t size)
    181 {
    182 	return;
    183 }
    184 
    185 static int
    186 neptune_bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
    187     bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
    188 {
    189 
    190 	*nbshp = bsh + offset*2;
    191 	return (0);
    192 }
    193