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