Home | History | Annotate | Line # | Download | only in sun2
obmem.c revision 1.1
      1 /*	$NetBSD: obmem.c,v 1.1 2001/04/06 15:05:57 fredette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Adam Glass, Gordon W. Ross, and Matthew Fredette.
      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. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 
     43 #include <uvm/uvm_extern.h>
     44 
     45 #include <machine/autoconf.h>
     46 #include <machine/pmap.h>
     47 
     48 #include <sun2/sun2/control.h>
     49 #include <sun2/sun2/machdep.h>
     50 
     51 static int  obmem_match __P((struct device *, struct cfdata *, void *));
     52 static void obmem_attach __P((struct device *, struct device *, void *));
     53 
     54 struct obmem_softc {
     55 	struct device	sc_dev;		/* base device */
     56 	bus_space_tag_t	sc_bustag;	/* parent bus tag */
     57 	bus_dma_tag_t	sc_dmatag;	/* parent bus dma tag */
     58 };
     59 
     60 struct cfattach obmem_ca = {
     61 	sizeof(struct obmem_softc), obmem_match, obmem_attach
     62 };
     63 
     64 static	int obmem_bus_mmap __P((bus_space_tag_t, bus_type_t, bus_addr_t,
     65 			       int, bus_space_handle_t *));
     66 static	int _obmem_bus_map __P((bus_space_tag_t, bus_type_t, bus_addr_t,
     67 			       bus_size_t, int,
     68 			       vaddr_t, bus_space_handle_t *));
     69 
     70 static struct sun2_bus_space_tag obmem_space_tag = {
     71 	NULL,				/* cookie */
     72 	NULL,				/* parent bus tag */
     73 	_obmem_bus_map,			/* bus_space_map */
     74 	NULL,				/* bus_space_unmap */
     75 	NULL,				/* bus_space_subregion */
     76 	NULL,				/* bus_space_barrier */
     77 	obmem_bus_mmap,			/* bus_space_mmap */
     78 	NULL				/* bus_intr_establish */
     79 };
     80 
     81 static int
     82 obmem_match(parent, cf, aux)
     83 	struct device *parent;
     84 	struct cfdata *cf;
     85 	void *aux;
     86 {
     87 	struct confargs *ca = aux;
     88 
     89 	return (strcmp(cf->cf_driver->cd_name, ca->ca_name) == 0);
     90 }
     91 
     92 static void
     93 obmem_attach(parent, self, aux)
     94 	struct device *parent;
     95 	struct device *self;
     96 	void *aux;
     97 {
     98 	struct confargs *ca = aux;
     99 	struct obmem_softc *sc = (struct obmem_softc *)self;
    100 	struct confargs sub_ca;
    101 	const char *const *cpp;
    102 	static const char *const special[] = {
    103 		/* find these first */
    104 		NULL
    105 	};
    106 
    107 	/*
    108 	 * There is only one obmem bus
    109 	 */
    110 	if (self->dv_unit > 0) {
    111 		printf(" unsupported\n");
    112 		return;
    113 	}
    114 	printf("\n");
    115 
    116 	sc->sc_bustag = ca->ca_bustag;
    117 	sc->sc_dmatag = ca->ca_dmatag;
    118 
    119 	obmem_space_tag.cookie = sc;
    120 	obmem_space_tag.parent = sc->sc_bustag;
    121 
    122 	/*
    123 	 * Prepare the skeleton attach arguments for our devices.
    124 	 * The values we give in the locators are indications to
    125 	 * sun2_bus_search about which locators must and must not
    126 	 * be defined.
    127 	 */
    128 	sub_ca = *ca;
    129 	sub_ca.ca_bustag = &obmem_space_tag;
    130 	sub_ca.ca_intpri = LOCATOR_OPTIONAL;
    131 	sub_ca.ca_intvec = LOCATOR_FORBIDDEN;
    132 
    133 	/* Find all `early' obmem devices */
    134 	for (cpp = special; *cpp != NULL; cpp++) {
    135 		sub_ca.ca_name = *cpp;
    136 		(void)config_search(sun2_bus_search, self, &sub_ca);
    137 	}
    138 
    139 	/* Find all other obmem devices */
    140 	sub_ca.ca_name = NULL;
    141 	(void)config_search(sun2_bus_search, self, &sub_ca);
    142 }
    143 
    144 int
    145 _obmem_bus_map(t, btype, paddr, size, flags, vaddr, hp)
    146 	bus_space_tag_t t;
    147 	bus_type_t btype;
    148 	bus_addr_t paddr;
    149 	bus_size_t size;
    150 	int	flags;
    151 	vaddr_t vaddr;
    152 	bus_space_handle_t *hp;
    153 {
    154 	struct obmem_softc *sc = t->cookie;
    155 
    156 	return (bus_space_map2(sc->sc_bustag, PMAP_OBMEM, paddr,
    157 				size, flags, vaddr, hp));
    158 }
    159 
    160 int
    161 obmem_bus_mmap(t, btype, paddr, flags, hp)
    162 	bus_space_tag_t t;
    163 	bus_type_t btype;
    164 	bus_addr_t paddr;
    165 	int flags;
    166 	bus_space_handle_t *hp;
    167 {
    168 	struct obmem_softc *sc = t->cookie;
    169 
    170 	return (bus_space_mmap(sc->sc_bustag, PMAP_OBMEM, paddr, flags, hp));
    171 }
    172