Home | History | Annotate | Line # | Download | only in sun2
obmem.c revision 1.12
      1 /*	$NetBSD: obmem.c,v 1.12 2004/12/13 02:14:13 chs 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/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: obmem.c,v 1.12 2004/12/13 02:14:13 chs Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 
     46 #include <uvm/uvm_extern.h>
     47 
     48 #include <machine/autoconf.h>
     49 #include <machine/pmap.h>
     50 
     51 #include <sun2/sun2/control.h>
     52 #include <sun2/sun2/machdep.h>
     53 
     54 static int  obmem_match __P((struct device *, struct cfdata *, void *));
     55 static void obmem_attach __P((struct device *, struct device *, void *));
     56 
     57 struct obmem_softc {
     58 	struct device	sc_dev;		/* base device */
     59 	bus_space_tag_t	sc_bustag;	/* parent bus tag */
     60 	bus_dma_tag_t	sc_dmatag;	/* parent bus dma tag */
     61 };
     62 
     63 CFATTACH_DECL(obmem, sizeof(struct obmem_softc),
     64     obmem_match, obmem_attach, NULL, NULL);
     65 
     66 static int obmem_attached;
     67 
     68 static	paddr_t obmem_bus_mmap __P((bus_space_tag_t, bus_type_t, bus_addr_t,
     69 				off_t, int, int));
     70 static	int _obmem_bus_map __P((bus_space_tag_t, bus_type_t, bus_addr_t,
     71 			       bus_size_t, int,
     72 			       vaddr_t, bus_space_handle_t *));
     73 
     74 static struct sun68k_bus_space_tag obmem_space_tag = {
     75 	NULL,				/* cookie */
     76 	NULL,				/* parent bus tag */
     77 	_obmem_bus_map,			/* bus_space_map */
     78 	NULL,				/* bus_space_unmap */
     79 	NULL,				/* bus_space_subregion */
     80 	NULL,				/* bus_space_barrier */
     81 	obmem_bus_mmap,			/* bus_space_mmap */
     82 	NULL,				/* bus_intr_establish */
     83 	NULL,				/* bus_space_peek_N */
     84 	NULL				/* bus_space_poke_N */
     85 };
     86 
     87 static int
     88 obmem_match(parent, cf, aux)
     89 	struct device *parent;
     90 	struct cfdata *cf;
     91 	void *aux;
     92 {
     93 	struct mainbus_attach_args *ma = aux;
     94 
     95 	if (obmem_attached)
     96 		return 0;
     97 
     98 	return (ma->ma_name == NULL || strcmp(cf->cf_name, ma->ma_name) == 0);
     99 }
    100 
    101 static void
    102 obmem_attach(parent, self, aux)
    103 	struct device *parent;
    104 	struct device *self;
    105 	void *aux;
    106 {
    107 	struct mainbus_attach_args *ma = aux;
    108 	struct obmem_softc *sc = (struct obmem_softc *)self;
    109 	struct obmem_attach_args obma;
    110 	const char *const *cpp;
    111 	static const char *const special[] = {
    112 		/* find these first */
    113 		NULL
    114 	};
    115 
    116 	obmem_attached = 1;
    117 
    118 	printf("\n");
    119 
    120 	sc->sc_bustag = ma->ma_bustag;
    121 	sc->sc_dmatag = ma->ma_dmatag;
    122 
    123 	obmem_space_tag.cookie = sc;
    124 	obmem_space_tag.parent = sc->sc_bustag;
    125 
    126 	/*
    127 	 * Prepare the skeleton attach arguments for our devices.
    128 	 * The values we give in the locators are indications to
    129 	 * sun68k_bus_search about which locators must and must not
    130 	 * be defined.
    131 	 */
    132 	obma = *ma;
    133 	obma.obma_bustag = &obmem_space_tag;
    134 	obma.obma_paddr = LOCATOR_REQUIRED;
    135 	obma.obma_pri = LOCATOR_OPTIONAL;
    136 
    137 	/* Find all `early' obmem devices */
    138 	for (cpp = special; *cpp != NULL; cpp++) {
    139 		obma.obma_name = *cpp;
    140 		(void)config_search(sun68k_bus_search, self, &obma);
    141 	}
    142 
    143 	/* Find all other obmem devices */
    144 	obma.obma_name = NULL;
    145 	(void)config_search(sun68k_bus_search, self, &obma);
    146 }
    147 
    148 int
    149 _obmem_bus_map(t, btype, paddr, size, flags, vaddr, hp)
    150 	bus_space_tag_t t;
    151 	bus_type_t btype;
    152 	bus_addr_t paddr;
    153 	bus_size_t size;
    154 	int	flags;
    155 	vaddr_t vaddr;
    156 	bus_space_handle_t *hp;
    157 {
    158 	struct obmem_softc *sc = t->cookie;
    159 
    160 	return (bus_space_map2(sc->sc_bustag, PMAP_OBMEM, paddr,
    161 				size, flags, vaddr, hp));
    162 }
    163 
    164 paddr_t
    165 obmem_bus_mmap(t, btype, paddr, off, prot, flags)
    166 	bus_space_tag_t t;
    167 	bus_type_t btype;
    168 	bus_addr_t paddr;
    169 	off_t off;
    170 	int prot;
    171 	int flags;
    172 {
    173 	struct obmem_softc *sc = t->cookie;
    174 
    175 	return (bus_space_mmap2(sc->sc_bustag, PMAP_OBMEM, paddr, off,
    176 				prot, flags));
    177 }
    178