Home | History | Annotate | Line # | Download | only in atheros
arbus.c revision 1.10.84.1
      1 /* $Id: arbus.c,v 1.10.84.1 2011/03/05 20:51:02 rmind Exp $ */
      2 /*
      3  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
      4  * Copyright (c) 2006 Garrett D'Amore.
      5  * All rights reserved.
      6  *
      7  * This code was written by Garrett D'Amore for the Champaign-Urbana
      8  * Community Wireless Network Project.
      9  *
     10  * Redistribution and use in source and binary forms, with or
     11  * without modification, are permitted provided that the following
     12  * conditions 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
     16  *    copyright notice, this list of conditions and the following
     17  *    disclaimer in the documentation and/or other materials provided
     18  *    with the distribution.
     19  * 3. All advertising materials mentioning features or use of this
     20  *    software must display the following acknowledgements:
     21  *      This product includes software developed by the Urbana-Champaign
     22  *      Independent Media Center.
     23  *	This product includes software developed by Garrett D'Amore.
     24  * 4. Urbana-Champaign Independent Media Center's name and Garrett
     25  *    D'Amore's name may not be used to endorse or promote products
     26  *    derived from this software without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
     29  * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
     30  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     31  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
     33  * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
     34  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     35  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     37  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     38  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     40  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: arbus.c,v 1.10.84.1 2011/03/05 20:51:02 rmind Exp $");
     45 
     46 #include "locators.h"
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/device.h>
     50 #include <sys/extent.h>
     51 #include <sys/malloc.h>
     52 
     53 #define	_MIPS_BUS_DMA_PRIVATE
     54 #include <machine/bus.h>
     55 #include <mips/atheros/include/ar5312reg.h>
     56 #include <mips/atheros/include/ar531xvar.h>
     57 #include <mips/atheros/include/arbusvar.h>
     58 
     59 static int arbus_match(device_t, struct cfdata *, void *);
     60 static void arbus_attach(device_t, device_t, void *);
     61 static int arbus_print(void *, const char *);
     62 static void arbus_bus_mem_init(bus_space_tag_t, void *);
     63 
     64 struct arbus_intrhand {
     65 	int		ih_cirq;
     66 	int		ih_mirq;
     67 	void		*ih_cookie;
     68 };
     69 
     70 CFATTACH_DECL_NEW(arbus, 0, arbus_match, arbus_attach, NULL, NULL);
     71 
     72 struct mips_bus_space	arbus_mbst;
     73 struct mips_bus_dma_tag	arbus_mdt = {
     74 	._dmamap_ops = _BUS_DMAMAP_OPS_INITIALIZER,
     75 	._dmamem_ops = _BUS_DMAMEM_OPS_INITIALIZER,
     76 	._dmatag_ops = _BUS_DMATAG_OPS_INITIALIZER,
     77 };
     78 
     79 void
     80 arbus_init(void)
     81 {
     82 	static bool done = false;
     83 	if (done)
     84 		return;
     85 	done = true;
     86 
     87 	arbus_bus_mem_init(&arbus_mbst, NULL);
     88 }
     89 
     90 /* this primarily exists so we can get to the console... */
     91 bus_space_tag_t
     92 arbus_get_bus_space_tag(void)
     93 {
     94 	arbus_init();
     95 	return (&arbus_mbst);
     96 }
     97 
     98 bus_dma_tag_t
     99 arbus_get_bus_dma_tag(void)
    100 {
    101 	arbus_init();
    102 	return (&arbus_mdt);
    103 }
    104 
    105 int
    106 arbus_match(device_t parent, cfdata_t match, void *aux)
    107 {
    108 
    109 	return 1;
    110 }
    111 
    112 void
    113 arbus_attach(device_t parent, device_t self, void *aux)
    114 {
    115 	struct arbus_attach_args aa;
    116 	const struct ar531x_device *devices;
    117 	int i;
    118 
    119 	printf("\n");
    120 	int locs[ARBUSCF_NLOCS];
    121 
    122 	arbus_init();
    123 
    124 	for (i = 0, devices = ar531x_get_devices(); devices[i].name; i++) {
    125 
    126 		aa.aa_name = devices[i].name;
    127 		aa.aa_size = devices[i].size;
    128 		aa.aa_dmat = &arbus_mdt;
    129 		aa.aa_bst = &arbus_mbst;
    130 		aa.aa_cirq = devices[i].cirq;
    131 		aa.aa_mirq = devices[i].mirq;
    132 		aa.aa_addr = devices[i].addr;
    133 
    134 		locs[ARBUSCF_ADDR] = aa.aa_addr;
    135 
    136 		if (ar531x_enable_device(&devices[i]) != 0) {
    137 			continue;
    138 		}
    139 
    140 		(void) config_found_sm_loc(self, "arbus", locs, &aa,
    141 		    arbus_print, config_stdsubmatch);
    142 	}
    143 }
    144 
    145 int
    146 arbus_print(void *aux, const char *pnp)
    147 {
    148 	struct arbus_attach_args *aa = aux;
    149 
    150 	if (pnp)
    151 		aprint_normal("%s at %s", aa->aa_name, pnp);
    152 
    153 	if (aa->aa_addr)
    154 		aprint_normal(" addr 0x%" PRIxBUSADDR, aa->aa_addr);
    155 
    156 	if (aa->aa_cirq >= 0)
    157 		aprint_normal(" cpu irq %d", aa->aa_cirq);
    158 
    159 	if (aa->aa_mirq >= 0)
    160 		aprint_normal(" misc irq %d", aa->aa_mirq);
    161 
    162 	return (UNCONF);
    163 }
    164 
    165 void *
    166 arbus_intr_establish(int cirq, int mirq, int (*handler)(void *), void *arg)
    167 {
    168 	struct arbus_intrhand	*ih;
    169 
    170 	ih = malloc(sizeof(*ih), M_DEVBUF, M_NOWAIT);
    171 	if (ih == NULL)
    172 		return NULL;
    173 
    174 	ih->ih_cirq = ih->ih_mirq = -1;
    175 	ih->ih_cookie = NULL;
    176 
    177 	if (mirq >= 0) {
    178 		ih->ih_mirq = mirq;
    179 		ih->ih_cookie = ar531x_misc_intr_establish(mirq, handler, arg);
    180 	} else if (cirq >= 0) {
    181 		ih->ih_cirq = cirq;
    182 		ih->ih_cookie = ar531x_cpu_intr_establish(cirq, handler, arg);
    183 	} else
    184 		return ih;
    185 
    186 	if (ih->ih_cookie == NULL) {
    187 		free(ih, M_DEVBUF);
    188 		return NULL;
    189 	}
    190 	return ih;
    191 }
    192 
    193 void
    194 arbus_intr_disestablish(void *arg)
    195 {
    196 	struct arbus_intrhand	*ih = arg;
    197 	if (ih->ih_mirq >= 0)
    198 		ar531x_misc_intr_disestablish(ih->ih_cookie);
    199 	else if (ih->ih_cirq >= 0)
    200 		ar531x_cpu_intr_disestablish(ih->ih_cookie);
    201 	free(ih, M_DEVBUF);
    202 }
    203 
    204 /*
    205  * CPU memory/register stuff
    206  */
    207 
    208 #define CHIP	   		arbus
    209 #define	CHIP_MEM		/* defined */
    210 #define	CHIP_W1_BUS_START(v)	0x00000000UL
    211 #define CHIP_W1_BUS_END(v)	0x1fffffffUL
    212 #define	CHIP_W1_SYS_START(v)	CHIP_W1_BUS_START(v)
    213 #define	CHIP_W1_SYS_END(v)	CHIP_W1_BUS_END(v)
    214 
    215 #include <mips/mips/bus_space_alignstride_chipdep.c>
    216