Home | History | Annotate | Line # | Download | only in rmi
rmixl_obio.c revision 1.6
      1  1.6  thorpej /*	$NetBSD: rmixl_obio.c,v 1.6 2021/04/24 23:36:43 thorpej Exp $	*/
      2  1.2     matt 
      3  1.2     matt /*
      4  1.2     matt  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      5  1.2     matt  * All rights reserved.
      6  1.2     matt  *
      7  1.2     matt  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.2     matt  *
      9  1.2     matt  * Redistribution and use in source and binary forms, with or without
     10  1.2     matt  * modification, are permitted provided that the following conditions
     11  1.2     matt  * are met:
     12  1.2     matt  * 1. Redistributions of source code must retain the above copyright
     13  1.2     matt  *    notice, this list of conditions and the following disclaimer.
     14  1.2     matt  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2     matt  *    notice, this list of conditions and the following disclaimer in the
     16  1.2     matt  *    documentation and/or other materials provided with the distribution.
     17  1.2     matt  * 3. All advertising materials mentioning features or use of this software
     18  1.2     matt  *    must display the following acknowledgement:
     19  1.2     matt  *	This product includes software developed for the NetBSD Project by
     20  1.2     matt  *	Wasabi Systems, Inc.
     21  1.2     matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.2     matt  *    or promote products derived from this software without specific prior
     23  1.2     matt  *    written permission.
     24  1.2     matt  *
     25  1.2     matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.2     matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2     matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2     matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.2     matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2     matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2     matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2     matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2     matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2     matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2     matt  * POSSIBILITY OF SUCH DAMAGE.
     36  1.2     matt  */
     37  1.2     matt 
     38  1.2     matt /*
     39  1.2     matt  * On-board device autoconfiguration support for RMI {XLP, XLR, XLS} chips
     40  1.2     matt  */
     41  1.2     matt 
     42  1.2     matt #include <sys/cdefs.h>
     43  1.6  thorpej __KERNEL_RCSID(0, "$NetBSD: rmixl_obio.c,v 1.6 2021/04/24 23:36:43 thorpej Exp $");
     44  1.2     matt 
     45  1.2     matt #include "locators.h"
     46  1.2     matt #include "pci.h"
     47  1.5     matt #define _MIPS_BUS_DMA_PRIVATE
     48  1.2     matt 
     49  1.2     matt #include <sys/param.h>
     50  1.5     matt #include <sys/bus.h>
     51  1.2     matt #include <sys/device.h>
     52  1.2     matt #include <sys/extent.h>
     53  1.2     matt #include <sys/malloc.h>
     54  1.5     matt #include <sys/systm.h>
     55  1.2     matt 
     56  1.5     matt #include <mips/int_fmtio.h>
     57  1.2     matt 
     58  1.2     matt #include <mips/rmi/rmixlreg.h>
     59  1.2     matt #include <mips/rmi/rmixlvar.h>
     60  1.3     matt #include <mips/rmi/rmixl_intr.h>
     61  1.2     matt #include <mips/rmi/rmixl_obiovar.h>
     62  1.2     matt #include <mips/rmi/rmixl_pcievar.h>
     63  1.2     matt 
     64  1.3     matt #include <evbmips/rmixl/autoconf.h>
     65  1.3     matt 
     66  1.2     matt #ifdef OBIO_DEBUG
     67  1.3     matt int obio_rmixl_debug = OBIO_DEBUG;
     68  1.3     matt # define DPRINTF(x)	do { if (obio_rmixl_debug) printf x ; } while (0)
     69  1.2     matt #else
     70  1.2     matt # define DPRINTF(x)
     71  1.2     matt #endif
     72  1.2     matt 
     73  1.2     matt static int  obio_match(device_t, cfdata_t, void *);
     74  1.2     matt static void obio_attach(device_t, device_t, void *);
     75  1.2     matt static int  obio_print(void *, const char *);
     76  1.2     matt static int  obio_search(device_t, cfdata_t, const int *, void *);
     77  1.2     matt static void obio_bus_init(struct obio_softc *);
     78  1.3     matt static void obio_dma_init_64(bus_dma_tag_t);
     79  1.2     matt static int  rmixl_addr_error_intr(void *);
     80  1.2     matt 
     81  1.2     matt 
     82  1.3     matt CFATTACH_DECL_NEW(obio_rmixl, sizeof(struct obio_softc),
     83  1.2     matt     obio_match, obio_attach, NULL, NULL);
     84  1.2     matt 
     85  1.2     matt int obio_found;
     86  1.2     matt 
     87  1.2     matt static int
     88  1.2     matt obio_match(device_t parent, cfdata_t cf, void *aux)
     89  1.2     matt {
     90  1.3     matt 	struct mainbus_attach_args *aa = aux;
     91  1.3     matt 
     92  1.3     matt 	if (obio_found == 0)
     93  1.3     matt 		if (strncmp(aa->ma_name, cf->cf_name, strlen(cf->cf_name)) == 0)
     94  1.3     matt 			return 1;
     95  1.3     matt 
     96  1.3     matt 	return 0;
     97  1.2     matt }
     98  1.2     matt 
     99  1.2     matt static void
    100  1.2     matt obio_attach(device_t parent, device_t self, void *aux)
    101  1.2     matt {
    102  1.2     matt 	struct obio_softc *sc = device_private(self);
    103  1.2     matt 	bus_addr_t ba;
    104  1.2     matt 
    105  1.2     matt 	obio_found = 1;
    106  1.2     matt 	sc->sc_dev = self;
    107  1.2     matt 
    108  1.2     matt 	ba = (bus_addr_t)rmixl_configuration.rc_io_pbase;
    109  1.2     matt 	KASSERT(ba != 0);
    110  1.2     matt 
    111  1.2     matt 	obio_bus_init(sc);
    112  1.2     matt 
    113  1.2     matt 	aprint_normal(" addr %#"PRIxBUSADDR" size %#"PRIxBUSSIZE"\n",
    114  1.2     matt 		ba, (bus_size_t)RMIXL_IO_DEV_SIZE);
    115  1.2     matt 	aprint_naive("\n");
    116  1.2     matt 
    117  1.2     matt 	/*
    118  1.2     matt 	 * Attach on-board devices as specified in the kernel config file.
    119  1.2     matt 	 */
    120  1.6  thorpej 	config_search(self, NULL,
    121  1.6  thorpej 	    CFARG_SEARCH, obio_search,
    122  1.6  thorpej 	    CFARG_EOL);
    123  1.2     matt 
    124  1.2     matt }
    125  1.2     matt 
    126  1.2     matt static int
    127  1.2     matt obio_print(void *aux, const char *pnp)
    128  1.2     matt {
    129  1.2     matt 	struct obio_attach_args *obio = aux;
    130  1.2     matt 
    131  1.2     matt 	if (obio->obio_addr != OBIOCF_ADDR_DEFAULT) {
    132  1.2     matt 		aprint_normal(" addr %#"PRIxBUSADDR, obio->obio_addr);
    133  1.2     matt 		if (obio->obio_size != OBIOCF_SIZE_DEFAULT)
    134  1.2     matt 			aprint_normal("-%#"PRIxBUSADDR,
    135  1.2     matt 				obio->obio_addr + (obio->obio_size - 1));
    136  1.2     matt 	}
    137  1.2     matt 	if (obio->obio_mult != OBIOCF_MULT_DEFAULT)
    138  1.2     matt 		aprint_normal(" mult %d", obio->obio_mult);
    139  1.2     matt 	if (obio->obio_intr != OBIOCF_INTR_DEFAULT)
    140  1.2     matt 		aprint_normal(" intr %d", obio->obio_intr);
    141  1.3     matt 	if (obio->obio_tmsk != OBIOCF_TMSK_DEFAULT)
    142  1.3     matt 		aprint_normal(" tmsk %d", obio->obio_tmsk);
    143  1.2     matt 
    144  1.2     matt 	return (UNCONF);
    145  1.2     matt }
    146  1.2     matt 
    147  1.2     matt static int
    148  1.2     matt obio_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    149  1.2     matt {
    150  1.2     matt 	struct obio_softc *sc = device_private(parent);
    151  1.2     matt 	struct obio_attach_args obio;
    152  1.2     matt 
    153  1.3     matt 	obio.obio_eb_bst = sc->sc_eb_bst;
    154  1.3     matt 	obio.obio_el_bst = sc->sc_el_bst;
    155  1.2     matt 	obio.obio_addr = cf->cf_loc[OBIOCF_ADDR];
    156  1.2     matt 	obio.obio_size = cf->cf_loc[OBIOCF_SIZE];
    157  1.2     matt 	obio.obio_mult = cf->cf_loc[OBIOCF_MULT];
    158  1.2     matt 	obio.obio_intr = cf->cf_loc[OBIOCF_INTR];
    159  1.3     matt 	obio.obio_tmsk = cf->cf_loc[OBIOCF_TMSK];
    160  1.2     matt 	obio.obio_29bit_dmat = sc->sc_29bit_dmat;
    161  1.2     matt 	obio.obio_32bit_dmat = sc->sc_32bit_dmat;
    162  1.2     matt 	obio.obio_64bit_dmat = sc->sc_64bit_dmat;
    163  1.2     matt 
    164  1.6  thorpej 	if (config_probe(parent, cf, &obio))
    165  1.6  thorpej 		config_attach(parent, cf, &obio, obio_print, CFARG_EOL);
    166  1.2     matt 
    167  1.2     matt 	return 0;
    168  1.2     matt }
    169  1.2     matt 
    170  1.2     matt static void
    171  1.2     matt obio_bus_init(struct obio_softc *sc)
    172  1.2     matt {
    173  1.2     matt 	struct rmixl_config *rcp = &rmixl_configuration;
    174  1.2     matt 	static int done = 0;
    175  1.3     matt 	int error;
    176  1.2     matt 
    177  1.2     matt 	if (done)
    178  1.2     matt 		return;
    179  1.2     matt 	done = 1;
    180  1.2     matt 
    181  1.3     matt 	/* obio (devio) space, Big Endian */
    182  1.3     matt 	if (rcp->rc_obio_eb_memt.bs_cookie == 0)
    183  1.3     matt 		rmixl_obio_eb_bus_mem_init(&rcp->rc_obio_eb_memt, rcp);
    184  1.3     matt 
    185  1.3     matt 	/* obio (devio) space, Little Endian */
    186  1.3     matt 	if (rcp->rc_obio_el_memt.bs_cookie == 0)
    187  1.3     matt 		rmixl_obio_el_bus_mem_init(&rcp->rc_obio_el_memt, rcp);
    188  1.3     matt 
    189  1.3     matt 	/* dma space for all memory, including >= 4GB */
    190  1.3     matt 	if (rcp->rc_dma_tag._cookie == 0)
    191  1.3     matt 		obio_dma_init_64(&rcp->rc_dma_tag);
    192  1.3     matt 	rcp->rc_64bit_dmat = &rcp->rc_dma_tag;
    193  1.3     matt 
    194  1.3     matt 	/* dma space for addr < 4GB */
    195  1.3     matt 	if (rcp->rc_32bit_dmat == NULL) {
    196  1.3     matt 		error = bus_dmatag_subregion(rcp->rc_64bit_dmat,
    197  1.3     matt 		    0, (bus_addr_t)1 << 32, &rcp->rc_32bit_dmat, 0);
    198  1.3     matt 		if (error)
    199  1.3     matt 			panic("%s: failed to create 32bit dma tag: %d",
    200  1.3     matt 			    __func__, error);
    201  1.3     matt 	}
    202  1.2     matt 
    203  1.2     matt 	/* dma space for addr < 512MB */
    204  1.3     matt 	if (rcp->rc_29bit_dmat == NULL) {
    205  1.3     matt 		error = bus_dmatag_subregion(rcp->rc_32bit_dmat,
    206  1.3     matt 		    0, (bus_addr_t)1 << 29, &rcp->rc_29bit_dmat, 0);
    207  1.3     matt 		if (error)
    208  1.3     matt 			panic("%s: failed to create 29bit dma tag: %d",
    209  1.3     matt 			    __func__, error);
    210  1.3     matt 	}
    211  1.2     matt 
    212  1.2     matt 	sc->sc_base = (bus_addr_t)rcp->rc_io_pbase;
    213  1.2     matt 	sc->sc_size = (bus_size_t)RMIXL_IO_DEV_SIZE;
    214  1.3     matt 	sc->sc_eb_bst = (bus_space_tag_t)&rcp->rc_obio_eb_memt;
    215  1.3     matt 	sc->sc_el_bst = (bus_space_tag_t)&rcp->rc_obio_el_memt;
    216  1.3     matt 	sc->sc_29bit_dmat = rcp->rc_29bit_dmat;
    217  1.3     matt 	sc->sc_32bit_dmat = rcp->rc_32bit_dmat;
    218  1.3     matt 	sc->sc_64bit_dmat = rcp->rc_64bit_dmat;
    219  1.2     matt }
    220  1.2     matt 
    221  1.2     matt static void
    222  1.3     matt obio_dma_init_64(bus_dma_tag_t t)
    223  1.2     matt {
    224  1.2     matt 	t->_cookie = t;
    225  1.2     matt 	t->_wbase = 0;
    226  1.3     matt 	t->_bounce_alloc_lo = 0;
    227  1.3     matt 	t->_bounce_alloc_hi = 0;
    228  1.3     matt 	t->_dmamap_ops = mips_bus_dmamap_ops;
    229  1.3     matt 	t->_dmamem_ops = mips_bus_dmamem_ops;
    230  1.3     matt 	t->_dmatag_ops = mips_bus_dmatag_ops;
    231  1.2     matt }
    232  1.2     matt 
    233  1.2     matt void
    234  1.2     matt rmixl_addr_error_init(void)
    235  1.2     matt {
    236  1.2     matt 	uint32_t r;
    237  1.2     matt 
    238  1.2     matt 	/*
    239  1.2     matt 	 * activate error addr detection on all (configurable) devices
    240  1.2     matt 	 * preserve reserved bit fields
    241  1.2     matt 	 * note some of these bits are read-only (writes are ignored)
    242  1.2     matt 	 */
    243  1.2     matt 	r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_DEVICE_MASK);
    244  1.2     matt 	r |= ~(__BITS(19,16) | __BITS(10,9) | __BITS(7,5));
    245  1.2     matt 	RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_DEVICE_MASK, r);
    246  1.2     matt 
    247  1.2     matt 	/*
    248  1.2     matt 	 * enable the address error interrupts
    249  1.2     matt 	 * "upgrade" cache and CPU errors to A1
    250  1.2     matt 	 */
    251  1.2     matt #define _ADDR_ERR_DEVSTAT_A1	(__BIT(8) | __BIT(1) | __BIT(0))
    252  1.2     matt #define _ADDR_ERR_RESV		\
    253  1.2     matt 		(__BITS(31,21) | __BITS(15,14) | __BITS(10,9) | __BITS(7,2))
    254  1.2     matt #define _BITERR_INT_EN_RESV	(__BITS(31,8) | __BIT(4))
    255  1.2     matt 
    256  1.2     matt 	r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_EN);
    257  1.2     matt 	r &= _ADDR_ERR_RESV;
    258  1.2     matt 	r |= ~_ADDR_ERR_RESV;
    259  1.2     matt 	RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR0_EN, r);
    260  1.2     matt 
    261  1.2     matt 	r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_UPG);
    262  1.2     matt 	r &= _ADDR_ERR_RESV;
    263  1.2     matt 	r |= _ADDR_ERR_DEVSTAT_A1;
    264  1.2     matt 	RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR0_UPG, r);
    265  1.2     matt 
    266  1.2     matt 	/*
    267  1.2     matt 	 * clear the log regs and the dev stat (interrupt status) regs
    268  1.2     matt 	 * "Write any value to bit[0] to clear"
    269  1.2     matt 	 */
    270  1.2     matt 	r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_CLEAR);
    271  1.2     matt 	RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_AERR1_CLEAR, r);
    272  1.2     matt 
    273  1.2     matt 	/*
    274  1.2     matt 	 * enable the double bit error interrupts
    275  1.2     matt 	 * (assume reserved bits, which are read-only,  are ignored)
    276  1.2     matt 	 */
    277  1.2     matt 	r = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_BITERR_INT_EN);
    278  1.2     matt 	r &= _BITERR_INT_EN_RESV;
    279  1.2     matt 	r |= __BITS(7,5);
    280  1.2     matt 	RMIXL_IOREG_WRITE(RMIXL_ADDR_ERR_BITERR_INT_EN, r);
    281  1.2     matt 
    282  1.2     matt 	/*
    283  1.2     matt 	 * establish address error ISR
    284  1.3     matt 	 * XXX assuming "int 16 (bridge_tb)" is our irq
    285  1.3     matt 	 * XXX is true for XLS family only
    286  1.2     matt 	 */
    287  1.3     matt 	if (cpu_rmixls(mips_options.mips_cpu))
    288  1.3     matt 		rmixl_intr_establish(16, 1, IPL_HIGH,
    289  1.3     matt 			RMIXL_TRIG_LEVEL, RMIXL_POLR_HIGH,
    290  1.3     matt 			rmixl_addr_error_intr, NULL, false);
    291  1.2     matt }
    292  1.2     matt 
    293  1.2     matt int
    294  1.2     matt rmixl_addr_error_check(void)
    295  1.2     matt {
    296  1.2     matt 	uint32_t aerr0_devstat;
    297  1.2     matt 	uint32_t aerr0_log1;
    298  1.2     matt 	uint32_t aerr0_log2;
    299  1.2     matt 	uint32_t aerr0_log3;
    300  1.2     matt 	uint32_t aerr1_devstat;
    301  1.2     matt 	uint32_t aerr1_log1;
    302  1.2     matt 	uint32_t aerr1_log2;
    303  1.2     matt 	uint32_t aerr1_log3;
    304  1.2     matt 	uint32_t sbe_counts;
    305  1.2     matt 	uint32_t dbe_counts;
    306  1.2     matt 
    307  1.2     matt 	aerr0_devstat = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_DEVSTAT);
    308  1.2     matt 	aerr0_log1 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG1);
    309  1.2     matt 	aerr0_log2 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG2);
    310  1.2     matt 	aerr0_log3 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR0_LOG3);
    311  1.2     matt 
    312  1.2     matt 	aerr1_devstat = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_DEVSTAT);
    313  1.2     matt 	aerr1_log1 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG1);
    314  1.2     matt 	aerr1_log2 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG2);
    315  1.2     matt 	aerr1_log3 = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_AERR1_LOG3);
    316  1.2     matt 
    317  1.2     matt 	sbe_counts = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_SBE_COUNTS);
    318  1.2     matt 	dbe_counts = RMIXL_IOREG_READ(RMIXL_ADDR_ERR_DBE_COUNTS);
    319  1.2     matt 
    320  1.2     matt 	if (aerr0_log1|aerr0_log2|aerr0_log3
    321  1.2     matt 	   |aerr1_log1|aerr1_log2|aerr1_log3
    322  1.2     matt 	   |dbe_counts) {
    323  1.2     matt 		printf("aerr0: stat %#x, logs: %#x, %#x, %#x\n",
    324  1.2     matt 			aerr0_devstat, aerr0_log1, aerr0_log2, aerr0_log2);
    325  1.2     matt 		printf("aerr1: stat %#x, logs: %#x, %#x, %#x\n",
    326  1.2     matt 			aerr1_devstat, aerr1_log1, aerr1_log2, aerr1_log2);
    327  1.2     matt 		printf("1-bit errors: %#x, 2-bit errors: %#x\n",
    328  1.2     matt 			sbe_counts, dbe_counts);
    329  1.2     matt 		return 1;
    330  1.2     matt 	}
    331  1.2     matt 	return 0;
    332  1.2     matt }
    333  1.2     matt 
    334  1.2     matt static int
    335  1.2     matt rmixl_addr_error_intr(void *arg)
    336  1.2     matt {
    337  1.2     matt 	int err;
    338  1.2     matt 
    339  1.2     matt 	err = rmixl_addr_error_check();
    340  1.2     matt 	if (err != 0) {
    341  1.2     matt #if DDB
    342  1.2     matt 		printf("%s\n", __func__);
    343  1.2     matt 		Debugger();
    344  1.2     matt #endif
    345  1.2     matt 		panic("Address Error");
    346  1.2     matt 	}
    347  1.2     matt 	return 1;
    348  1.2     matt }
    349