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