Home | History | Annotate | Line # | Download | only in dev
elb.c revision 1.9
      1  1.9    dyoung /*	$NetBSD: elb.c,v 1.9 2011/07/01 19:02:32 dyoung Exp $	*/
      2  1.1   hannken 
      3  1.1   hannken /*-
      4  1.1   hannken  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  1.1   hannken  * All rights reserved.
      6  1.1   hannken  *
      7  1.1   hannken  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1   hannken  * by Juergen Hannken-Illjes.
      9  1.1   hannken  *
     10  1.1   hannken  * Redistribution and use in source and binary forms, with or without
     11  1.1   hannken  * modification, are permitted provided that the following conditions
     12  1.1   hannken  * are met:
     13  1.1   hannken  * 1. Redistributions of source code must retain the above copyright
     14  1.1   hannken  *    notice, this list of conditions and the following disclaimer.
     15  1.1   hannken  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1   hannken  *    notice, this list of conditions and the following disclaimer in the
     17  1.1   hannken  *    documentation and/or other materials provided with the distribution.
     18  1.1   hannken  *
     19  1.1   hannken  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1   hannken  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1   hannken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1   hannken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1   hannken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1   hannken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1   hannken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1   hannken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1   hannken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1   hannken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1   hannken  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1   hannken  */
     31  1.2     lukem 
     32  1.2     lukem #include <sys/cdefs.h>
     33  1.9    dyoung __KERNEL_RCSID(0, "$NetBSD: elb.c,v 1.9 2011/07/01 19:02:32 dyoung Exp $");
     34  1.1   hannken 
     35  1.1   hannken #include <sys/param.h>
     36  1.1   hannken #include <sys/conf.h>
     37  1.1   hannken #include <sys/device.h>
     38  1.1   hannken #include <sys/systm.h>
     39  1.3       scw #include <sys/extent.h>
     40  1.1   hannken 
     41  1.1   hannken #include <machine/explora.h>
     42  1.3       scw #define _POWERPC_BUS_DMA_PRIVATE
     43  1.9    dyoung #include <sys/bus.h>
     44  1.1   hannken 
     45  1.1   hannken #include <powerpc/ibm4xx/dcr403cgx.h>
     46  1.1   hannken 
     47  1.1   hannken #include <evbppc/explora/dev/elbvar.h>
     48  1.1   hannken 
     49  1.1   hannken struct elb_dev {
     50  1.1   hannken 	const char *elb_name;
     51  1.1   hannken 	int elb_addr;
     52  1.1   hannken 	int elb_addr2;
     53  1.1   hannken 	int elb_irq;
     54  1.3       scw 	bus_space_tag_t elb_bt;
     55  1.1   hannken };
     56  1.1   hannken 
     57  1.7      matt static int	elb_match(device_t, cfdata_t, void *);
     58  1.7      matt static void	elb_attach(device_t, device_t, void *);
     59  1.1   hannken static int	elb_print(void *, const char *);
     60  1.1   hannken 
     61  1.3       scw static struct powerpc_bus_space elb_tag = {
     62  1.3       scw 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE | 1,	/* stride 1 */
     63  1.3       scw 	0x00000000,
     64  1.3       scw 	BASE_PCKBC,
     65  1.3       scw 	BASE_PCKBC + 0x6ff
     66  1.3       scw };
     67  1.3       scw static struct powerpc_bus_space elb_fb_tag = {
     68  1.3       scw 	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
     69  1.3       scw 	0x00000000,
     70  1.3       scw 	BASE_FB,
     71  1.3       scw 	BASE_FB2 + SIZE_FB - 1
     72  1.3       scw };
     73  1.8      matt 
     74  1.8      matt static char elb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
     75  1.8      matt     __attribute__((aligned(8)));
     76  1.3       scw static char elbfb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
     77  1.3       scw     __attribute__((aligned(8)));
     78  1.8      matt 
     79  1.8      matt static bool elb_tag_init_done;
     80  1.8      matt static bool elbfb_tag_init_done;
     81  1.3       scw 
     82  1.3       scw /*
     83  1.3       scw  * DMA struct, nothing special.
     84  1.3       scw  */
     85  1.3       scw static struct powerpc_bus_dma_tag elb_bus_dma_tag = {
     86  1.3       scw 	0,			/* _bounce_thresh */
     87  1.3       scw 	_bus_dmamap_create,
     88  1.3       scw 	_bus_dmamap_destroy,
     89  1.3       scw 	_bus_dmamap_load,
     90  1.3       scw 	_bus_dmamap_load_mbuf,
     91  1.3       scw 	_bus_dmamap_load_uio,
     92  1.3       scw 	_bus_dmamap_load_raw,
     93  1.3       scw 	_bus_dmamap_unload,
     94  1.3       scw 	_bus_dmamap_sync,
     95  1.3       scw 	_bus_dmamem_alloc,
     96  1.3       scw 	_bus_dmamem_free,
     97  1.3       scw 	_bus_dmamem_map,
     98  1.3       scw 	_bus_dmamem_unmap,
     99  1.3       scw 	_bus_dmamem_mmap,
    100  1.3       scw 	_bus_dma_phys_to_bus_mem_generic,
    101  1.3       scw 	_bus_dma_bus_mem_to_phys_generic,
    102  1.3       scw };
    103  1.3       scw 
    104  1.8      matt static const struct elb_dev elb_devs[] = {
    105  1.3       scw 	{ "cpu",	0,		0,		-1, NULL },
    106  1.3       scw 	{ "pckbc",	BASE_PCKBC,	BASE_PCKBC2,	31, &elb_tag },
    107  1.3       scw 	{ "com",	BASE_COM,	0,		30, &elb_tag },
    108  1.3       scw 	{ "lpt",	BASE_LPT,	0,		-1, &elb_tag },
    109  1.3       scw 	{ "fb",		BASE_FB,	BASE_FB2,	-1, &elb_fb_tag },
    110  1.3       scw 	{ "le",		BASE_LE,	0,		28, &elb_fb_tag },
    111  1.1   hannken };
    112  1.1   hannken 
    113  1.7      matt CFATTACH_DECL_NEW(elb, 0,
    114  1.1   hannken     elb_match, elb_attach, NULL, NULL);
    115  1.1   hannken 
    116  1.1   hannken /*
    117  1.1   hannken  * Probe for the elb; always succeeds.
    118  1.1   hannken  */
    119  1.1   hannken static int
    120  1.7      matt elb_match(device_t parent, cfdata_t cf, void *aux)
    121  1.1   hannken {
    122  1.1   hannken 	return (1);
    123  1.1   hannken }
    124  1.1   hannken 
    125  1.1   hannken /*
    126  1.1   hannken  * Attach the Explora local bus.
    127  1.1   hannken  */
    128  1.1   hannken static void
    129  1.7      matt elb_attach(device_t parent, device_t self, void *aux)
    130  1.1   hannken {
    131  1.1   hannken 	struct elb_attach_args eaa;
    132  1.8      matt 	const struct elb_dev *elb;
    133  1.8      matt 	size_t i;
    134  1.1   hannken 
    135  1.1   hannken 	printf("\n");
    136  1.8      matt 	for (i = 0, elb = elb_devs; i < __arraycount(elb_devs); i++, elb++) {
    137  1.8      matt 		eaa.elb_name = elb->elb_name;
    138  1.8      matt 		eaa.elb_bt = elb_get_bus_space_tag(elb->elb_addr);
    139  1.3       scw 		eaa.elb_dmat = &elb_bus_dma_tag;
    140  1.8      matt 		eaa.elb_base = elb->elb_addr;
    141  1.8      matt 		eaa.elb_base2 = elb->elb_addr2;
    142  1.8      matt 		eaa.elb_irq = elb->elb_irq;
    143  1.1   hannken 
    144  1.4  drochner 		(void) config_found(self, &eaa, elb_print);
    145  1.1   hannken 	}
    146  1.1   hannken }
    147  1.1   hannken 
    148  1.1   hannken static int
    149  1.1   hannken elb_print(void *aux, const char *pnp)
    150  1.1   hannken {
    151  1.1   hannken 	struct elb_attach_args *eaa = aux;
    152  1.1   hannken 
    153  1.1   hannken 	if (pnp)
    154  1.1   hannken 		aprint_normal("%s at %s", eaa->elb_name, pnp);
    155  1.1   hannken 	if (eaa->elb_irq != -1)
    156  1.1   hannken 		aprint_normal(" irq %d", eaa->elb_irq);
    157  1.1   hannken 
    158  1.1   hannken 	return (UNCONF);
    159  1.3       scw }
    160  1.3       scw 
    161  1.3       scw bus_space_tag_t
    162  1.3       scw elb_get_bus_space_tag(bus_addr_t addr)
    163  1.3       scw {
    164  1.3       scw 
    165  1.3       scw 	if ((addr & 0xff000000) == 0x74000000) {
    166  1.3       scw 		if (!elb_tag_init_done) {
    167  1.3       scw 			if (bus_space_init(&elb_tag, "elbtag",
    168  1.3       scw 			    elb_ex_storage, sizeof(elb_ex_storage)))
    169  1.3       scw 				panic("elb_get_bus_space_tag: elb_tag");
    170  1.3       scw 
    171  1.8      matt 			elb_tag_init_done = true;
    172  1.3       scw 		}
    173  1.3       scw 		return (&elb_tag);
    174  1.3       scw 	} else {
    175  1.3       scw 		if (!elbfb_tag_init_done) {
    176  1.3       scw 			if (bus_space_init(&elb_fb_tag, "elbfbtag",
    177  1.3       scw 			    elbfb_ex_storage, sizeof(elbfb_ex_storage)))
    178  1.3       scw 				panic("elb_get_bus_space_tag: elb_fb_tag");
    179  1.3       scw 
    180  1.8      matt 			elbfb_tag_init_done = true;
    181  1.3       scw 		}
    182  1.3       scw 		return (&elb_fb_tag);
    183  1.3       scw 	}
    184  1.1   hannken }
    185