Home | History | Annotate | Line # | Download | only in dev
elb.c revision 1.3
      1 /*	$NetBSD: elb.c,v 1.3 2003/07/25 11:44:20 scw Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Juergen Hannken-Illjes.
      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: elb.c,v 1.3 2003/07/25 11:44:20 scw Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/conf.h>
     44 #include <sys/device.h>
     45 #include <sys/systm.h>
     46 #include <sys/extent.h>
     47 
     48 #include <machine/explora.h>
     49 #define _POWERPC_BUS_DMA_PRIVATE
     50 #include <machine/bus.h>
     51 
     52 #include <powerpc/ibm4xx/dcr403cgx.h>
     53 
     54 #include <evbppc/explora/dev/elbvar.h>
     55 
     56 struct elb_dev {
     57 	const char *elb_name;
     58 	int elb_addr;
     59 	int elb_addr2;
     60 	int elb_irq;
     61 	bus_space_tag_t elb_bt;
     62 };
     63 
     64 static int	elb_match(struct device *, struct cfdata *, void *);
     65 static void	elb_attach(struct device *, struct device *, void *);
     66 static int	elb_print(void *, const char *);
     67 
     68 static struct powerpc_bus_space elb_tag = {
     69 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE | 1,	/* stride 1 */
     70 	0x00000000,
     71 	BASE_PCKBC,
     72 	BASE_PCKBC + 0x6ff
     73 };
     74 static char elb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
     75     __attribute__((aligned(8)));
     76 static int elb_tag_init_done;
     77 
     78 static struct powerpc_bus_space elb_fb_tag = {
     79 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
     80 	0x00000000,
     81 	BASE_FB,
     82 	BASE_FB2 + SIZE_FB - 1
     83 };
     84 static char elbfb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
     85     __attribute__((aligned(8)));
     86 static int elbfb_tag_init_done;
     87 
     88 /*
     89  * DMA struct, nothing special.
     90  */
     91 static struct powerpc_bus_dma_tag elb_bus_dma_tag = {
     92 	0,			/* _bounce_thresh */
     93 	_bus_dmamap_create,
     94 	_bus_dmamap_destroy,
     95 	_bus_dmamap_load,
     96 	_bus_dmamap_load_mbuf,
     97 	_bus_dmamap_load_uio,
     98 	_bus_dmamap_load_raw,
     99 	_bus_dmamap_unload,
    100 	_bus_dmamap_sync,
    101 	_bus_dmamem_alloc,
    102 	_bus_dmamem_free,
    103 	_bus_dmamem_map,
    104 	_bus_dmamem_unmap,
    105 	_bus_dmamem_mmap,
    106 	_bus_dma_phys_to_bus_mem_generic,
    107 	_bus_dma_bus_mem_to_phys_generic,
    108 };
    109 
    110 static struct elb_dev elb_devs[] = {
    111 	{ "cpu",	0,		0,		-1, NULL },
    112 	{ "pckbc",	BASE_PCKBC,	BASE_PCKBC2,	31, &elb_tag },
    113 	{ "com",	BASE_COM,	0,		30, &elb_tag },
    114 	{ "lpt",	BASE_LPT,	0,		-1, &elb_tag },
    115 	{ "fb",		BASE_FB,	BASE_FB2,	-1, &elb_fb_tag },
    116 	{ "le",		BASE_LE,	0,		28, &elb_fb_tag },
    117 };
    118 
    119 CFATTACH_DECL(elb, sizeof(struct device),
    120     elb_match, elb_attach, NULL, NULL);
    121 
    122 /*
    123  * Probe for the elb; always succeeds.
    124  */
    125 static int
    126 elb_match(struct device *parent, struct cfdata *cf, void *aux)
    127 {
    128 	return (1);
    129 }
    130 
    131 /*
    132  * Attach the Explora local bus.
    133  */
    134 static void
    135 elb_attach(struct device *parent, struct device *self, void *aux)
    136 {
    137 	struct elb_attach_args eaa;
    138 	int i;
    139 
    140 	printf("\n");
    141 	for (i = 0; i < sizeof(elb_devs)/sizeof(elb_devs[0]); i++) {
    142 		eaa.elb_name = elb_devs[i].elb_name;
    143 		eaa.elb_bt = elb_get_bus_space_tag(elb_devs[i].elb_addr);
    144 		eaa.elb_dmat = &elb_bus_dma_tag;
    145 		eaa.elb_base = elb_devs[i].elb_addr;
    146 		eaa.elb_base2 = elb_devs[i].elb_addr2;
    147 		eaa.elb_irq = elb_devs[i].elb_irq;
    148 
    149 		(void) config_found_sm(self, &eaa, elb_print, NULL);
    150 	}
    151 }
    152 
    153 static int
    154 elb_print(void *aux, const char *pnp)
    155 {
    156 	struct elb_attach_args *eaa = aux;
    157 
    158 	if (pnp)
    159 		aprint_normal("%s at %s", eaa->elb_name, pnp);
    160 	if (eaa->elb_irq != -1)
    161 		aprint_normal(" irq %d", eaa->elb_irq);
    162 
    163 	return (UNCONF);
    164 }
    165 
    166 bus_space_tag_t
    167 elb_get_bus_space_tag(bus_addr_t addr)
    168 {
    169 
    170 	if ((addr & 0xff000000) == 0x74000000) {
    171 		if (!elb_tag_init_done) {
    172 			if (bus_space_init(&elb_tag, "elbtag",
    173 			    elb_ex_storage, sizeof(elb_ex_storage)))
    174 				panic("elb_get_bus_space_tag: elb_tag");
    175 
    176 			elb_tag_init_done = 1;
    177 		}
    178 		return (&elb_tag);
    179 	} else {
    180 		if (!elbfb_tag_init_done) {
    181 			if (bus_space_init(&elb_fb_tag, "elbfbtag",
    182 			    elbfb_ex_storage, sizeof(elbfb_ex_storage)))
    183 				panic("elb_get_bus_space_tag: elb_fb_tag");
    184 
    185 			elbfb_tag_init_done = 1;
    186 		}
    187 		return (&elb_fb_tag);
    188 	}
    189 }
    190