Home | History | Annotate | Line # | Download | only in mace
pci_mace.c revision 1.14.6.2
      1  1.14.6.2       tls /*	$NetBSD: pci_mace.c,v 1.14.6.2 2014/08/20 00:03:22 tls Exp $	*/
      2       1.1    sekiya 
      3       1.1    sekiya /*
      4       1.1    sekiya  * Copyright (c) 2001,2003 Christopher Sekiya
      5       1.1    sekiya  * Copyright (c) 2000 Soren S. Jorvang
      6       1.1    sekiya  * All rights reserved.
      7       1.1    sekiya  *
      8       1.1    sekiya  * Redistribution and use in source and binary forms, with or without
      9       1.1    sekiya  * modification, are permitted provided that the following conditions
     10       1.1    sekiya  * are met:
     11       1.1    sekiya  * 1. Redistributions of source code must retain the above copyright
     12       1.1    sekiya  *    notice, this list of conditions and the following disclaimer.
     13       1.1    sekiya  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1    sekiya  *    notice, this list of conditions and the following disclaimer in the
     15       1.1    sekiya  *    documentation and/or other materials provided with the distribution.
     16       1.1    sekiya  * 3. All advertising materials mentioning features or use of this software
     17       1.1    sekiya  *    must display the following acknowledgement:
     18       1.1    sekiya  *          This product includes software developed for the
     19       1.1    sekiya  *          NetBSD Project.  See http://www.NetBSD.org/ for
     20       1.1    sekiya  *          information about NetBSD.
     21       1.1    sekiya  * 4. The name of the author may not be used to endorse or promote products
     22       1.1    sekiya  *    derived from this software without specific prior written permission.
     23       1.1    sekiya  *
     24       1.1    sekiya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25       1.1    sekiya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26       1.1    sekiya  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27       1.1    sekiya  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28       1.1    sekiya  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29       1.1    sekiya  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30       1.1    sekiya  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31       1.1    sekiya  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32       1.1    sekiya  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33       1.1    sekiya  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34       1.1    sekiya  */
     35       1.1    sekiya 
     36       1.1    sekiya #include <sys/cdefs.h>
     37  1.14.6.2       tls __KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.14.6.2 2014/08/20 00:03:22 tls Exp $");
     38       1.7   tsutsui 
     39       1.7   tsutsui #include "opt_pci.h"
     40       1.7   tsutsui #include "pci.h"
     41       1.1    sekiya 
     42       1.1    sekiya #include <sys/param.h>
     43       1.1    sekiya #include <sys/device.h>
     44       1.1    sekiya #include <sys/systm.h>
     45       1.1    sekiya 
     46       1.1    sekiya #include <machine/cpu.h>
     47       1.1    sekiya #include <machine/locore.h>
     48       1.1    sekiya #include <machine/autoconf.h>
     49       1.1    sekiya #include <machine/vmparam.h>
     50      1.13    dyoung #include <sys/bus.h>
     51       1.1    sekiya #include <machine/machtype.h>
     52       1.1    sekiya 
     53       1.7   tsutsui #include <mips/cache.h>
     54       1.7   tsutsui 
     55       1.1    sekiya #include <dev/pci/pcivar.h>
     56       1.1    sekiya #include <dev/pci/pcireg.h>
     57       1.1    sekiya #include <dev/pci/pcidevs.h>
     58       1.1    sekiya 
     59       1.7   tsutsui #include <sys/extent.h>
     60       1.7   tsutsui #include <sys/malloc.h>
     61       1.7   tsutsui #include <dev/pci/pciconf.h>
     62       1.7   tsutsui 
     63       1.1    sekiya #include <sgimips/mace/macereg.h>
     64       1.1    sekiya #include <sgimips/mace/macevar.h>
     65       1.1    sekiya 
     66       1.1    sekiya #include <sgimips/mace/pcireg_mace.h>
     67       1.1    sekiya 
     68       1.1    sekiya struct macepci_softc {
     69       1.1    sekiya 	struct sgimips_pci_chipset sc_pc;
     70       1.1    sekiya };
     71       1.1    sekiya 
     72  1.14.6.1       tls static int	macepci_match(device_t, cfdata_t, void *);
     73  1.14.6.1       tls static void	macepci_attach(device_t, device_t, void *);
     74       1.8    rumble static int	macepci_bus_maxdevs(pci_chipset_tag_t, int);
     75       1.8    rumble static pcireg_t	macepci_conf_read(pci_chipset_tag_t, pcitag_t, int);
     76       1.8    rumble static void	macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
     77      1.11    dyoung static int	macepci_intr_map(const struct pci_attach_args *,
     78      1.11    dyoung 		    pci_intr_handle_t *);
     79       1.8    rumble static const char *
     80  1.14.6.2       tls 		macepci_intr_string(pci_chipset_tag_t, pci_intr_handle_t,
     81  1.14.6.2       tls 		    char *, size_t);
     82       1.8    rumble static int	macepci_intr(void *);
     83       1.1    sekiya 
     84  1.14.6.1       tls CFATTACH_DECL_NEW(macepci, sizeof(struct macepci_softc),
     85       1.1    sekiya     macepci_match, macepci_attach, NULL, NULL);
     86       1.1    sekiya 
     87       1.1    sekiya static int
     88  1.14.6.1       tls macepci_match(device_t parent, cfdata_t match, void *aux)
     89       1.1    sekiya {
     90       1.1    sekiya 
     91       1.2    sekiya 	return (1);
     92       1.1    sekiya }
     93       1.1    sekiya 
     94       1.1    sekiya static void
     95  1.14.6.1       tls macepci_attach(device_t parent, device_t self, void *aux)
     96       1.1    sekiya {
     97  1.14.6.1       tls 	struct macepci_softc *sc = device_private(self);
     98       1.1    sekiya 	pci_chipset_tag_t pc = &sc->sc_pc;
     99       1.1    sekiya 	struct mace_attach_args *maa = aux;
    100       1.1    sekiya 	struct pcibus_attach_args pba;
    101       1.1    sekiya 	u_int32_t control;
    102       1.7   tsutsui 	int rev;
    103       1.1    sekiya 
    104       1.1    sekiya 	if (bus_space_subregion(maa->maa_st, maa->maa_sh,
    105       1.1    sekiya 	    maa->maa_offset, 0, &pc->ioh) )
    106       1.1    sekiya 		panic("macepci_attach: couldn't map");
    107       1.1    sekiya 
    108       1.1    sekiya 	pc->iot = maa->maa_st;
    109       1.1    sekiya 
    110       1.1    sekiya 	rev = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_REVISION);
    111       1.1    sekiya 	printf(": rev %d\n", rev);
    112       1.1    sekiya 
    113       1.8    rumble 	pc->pc_bus_maxdevs = macepci_bus_maxdevs;
    114       1.1    sekiya 	pc->pc_conf_read = macepci_conf_read;
    115       1.1    sekiya 	pc->pc_conf_write = macepci_conf_write;
    116       1.8    rumble 	pc->pc_intr_map = macepci_intr_map;
    117       1.8    rumble 	pc->pc_intr_string = macepci_intr_string;
    118       1.4    sekiya 	pc->intr_establish = mace_intr_establish;
    119       1.4    sekiya 	pc->intr_disestablish = mace_intr_disestablish;
    120       1.1    sekiya 
    121       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR, 0);
    122       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS, 0);
    123       1.1    sekiya 
    124       1.1    sekiya 	/* Turn on PCI error interrupts */
    125       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONTROL,
    126       1.1    sekiya 	    MACE_PCI_CONTROL_SERR_ENA |
    127       1.1    sekiya 	    MACE_PCI_CONTROL_PARITY_ERR |
    128       1.1    sekiya 	    MACE_PCI_CONTROL_PARK_LIU |
    129       1.1    sekiya 	    MACE_PCI_CONTROL_OVERRUN_INT |
    130       1.1    sekiya 	    MACE_PCI_CONTROL_PARITY_INT |
    131       1.1    sekiya 	    MACE_PCI_CONTROL_SERR_INT |
    132       1.1    sekiya 	    MACE_PCI_CONTROL_IT_INT |
    133       1.1    sekiya 	    MACE_PCI_CONTROL_RE_INT |
    134       1.1    sekiya 	    MACE_PCI_CONTROL_DPED_INT |
    135       1.1    sekiya 	    MACE_PCI_CONTROL_TAR_INT |
    136       1.1    sekiya 	    MACE_PCI_CONTROL_MAR_INT);
    137       1.1    sekiya 
    138       1.1    sekiya 	/*
    139       1.1    sekiya 	 * Enable all MACE PCI interrupts. They will be masked by
    140       1.1    sekiya 	 * the CRIME code.
    141       1.1    sekiya 	 */
    142       1.1    sekiya 	control = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_CONTROL);
    143       1.1    sekiya 	control |= CONTROL_INT_MASK;
    144       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACEPCI_CONTROL, control);
    145       1.1    sekiya 
    146       1.1    sekiya #if NPCI > 0
    147       1.7   tsutsui 	pc->pc_ioext = extent_create("macepciio", 0x00001000, 0x01ffffff,
    148      1.14      para 	    NULL, 0, EX_NOWAIT);
    149       1.7   tsutsui 	pc->pc_memext = extent_create("macepcimem", 0x80100000, 0x81ffffff,
    150      1.14      para 	    NULL, 0, EX_NOWAIT);
    151       1.7   tsutsui 	pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
    152      1.10      matt 	    mips_cache_info.mci_dcache_align);
    153       1.1    sekiya 	memset(&pba, 0, sizeof pba);
    154       1.1    sekiya /*XXX*/	pba.pba_iot = SGIMIPS_BUS_SPACE_IO;
    155       1.1    sekiya /*XXX*/	pba.pba_memt = SGIMIPS_BUS_SPACE_MEM;
    156       1.1    sekiya 	pba.pba_dmat = &pci_bus_dma_tag;
    157       1.1    sekiya 	pba.pba_dmat64 = NULL;
    158       1.1    sekiya 	pba.pba_bus = 0;
    159       1.1    sekiya 	pba.pba_bridgetag = NULL;
    160      1.12    dyoung 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
    161       1.1    sekiya 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    162       1.1    sekiya 	pba.pba_pc = pc;
    163       1.1    sekiya 
    164       1.1    sekiya #ifdef MACEPCI_IO_WAS_BUGGY
    165       1.1    sekiya 	if (rev == 0)
    166      1.12    dyoung 		pba.pba_flags &= ~PCI_FLAGS_IO_OKAY;		/* Buggy? */
    167       1.1    sekiya #endif
    168       1.1    sekiya 
    169       1.1    sekiya 	cpu_intr_establish(maa->maa_intr, IPL_NONE, macepci_intr, sc);
    170       1.1    sekiya 
    171       1.3  drochner 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    172       1.1    sekiya #endif
    173       1.1    sekiya }
    174       1.1    sekiya 
    175       1.8    rumble int
    176       1.8    rumble macepci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    177       1.8    rumble {
    178       1.8    rumble 
    179       1.8    rumble 	if (busno == 0)
    180       1.8    rumble 		return 5;	/* 2 on-board SCSI chips, slots 0, 1 and 2 */
    181       1.8    rumble 	else
    182       1.8    rumble 		return 0;	/* XXX */
    183       1.8    rumble }
    184       1.8    rumble 
    185       1.1    sekiya pcireg_t
    186       1.5    sekiya macepci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
    187       1.1    sekiya {
    188       1.1    sekiya 	pcireg_t data;
    189       1.1    sekiya 
    190       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
    191       1.1    sekiya 	data = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA);
    192       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
    193       1.1    sekiya 
    194       1.1    sekiya 	return data;
    195       1.1    sekiya }
    196       1.1    sekiya 
    197       1.1    sekiya void
    198       1.5    sekiya macepci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
    199       1.1    sekiya {
    200       1.1    sekiya 	/* XXX O2 soren */
    201       1.1    sekiya 	if (tag == 0)
    202       1.1    sekiya 		return;
    203       1.1    sekiya 
    204       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
    205       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA, data);
    206       1.1    sekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
    207       1.1    sekiya }
    208       1.1    sekiya 
    209       1.8    rumble int
    210      1.11    dyoung macepci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    211       1.8    rumble {
    212       1.8    rumble 	pci_chipset_tag_t pc = pa->pa_pc;
    213       1.8    rumble 	pcitag_t intrtag = pa->pa_intrtag;
    214       1.8    rumble 	int pin = pa->pa_intrpin;
    215       1.8    rumble 	int bus, dev, func, start;
    216       1.8    rumble 
    217       1.8    rumble 	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
    218       1.8    rumble 
    219       1.8    rumble 	if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
    220       1.8    rumble 		panic("SCSI0 and SCSI1 must be hardwired!");
    221       1.8    rumble 
    222       1.8    rumble 	switch (pin) {
    223       1.8    rumble 	default:
    224       1.8    rumble 	case PCI_INTERRUPT_PIN_NONE:
    225       1.8    rumble 		return -1;
    226       1.8    rumble 
    227       1.8    rumble 	case PCI_INTERRUPT_PIN_A:
    228       1.8    rumble 		/*
    229       1.8    rumble 		 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
    230       1.8    rumble 		 * for pin A?
    231       1.8    rumble 		 */
    232       1.8    rumble 		*ihp = dev + 7;
    233       1.8    rumble 		return 0;
    234       1.8    rumble 
    235       1.8    rumble 	case PCI_INTERRUPT_PIN_B:
    236       1.8    rumble 		start = 0;
    237       1.8    rumble 		break;
    238       1.8    rumble 	case PCI_INTERRUPT_PIN_C:
    239       1.8    rumble 		start = 1;
    240       1.8    rumble 		break;
    241       1.8    rumble 	case PCI_INTERRUPT_PIN_D:
    242       1.8    rumble 		start = 2;
    243       1.8    rumble 		break;
    244       1.8    rumble 	}
    245       1.8    rumble 
    246       1.8    rumble 	/* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
    247       1.8    rumble 	*ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
    248       1.8    rumble 	return 0;
    249       1.8    rumble }
    250       1.8    rumble 
    251       1.8    rumble const char *
    252  1.14.6.2       tls macepci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
    253  1.14.6.2       tls     size_t len)
    254       1.8    rumble {
    255  1.14.6.2       tls 	snprintf(buf, len, "crime interrupt %d", ih);
    256  1.14.6.2       tls 	return buf;
    257       1.8    rumble }
    258       1.8    rumble 
    259       1.1    sekiya 
    260       1.1    sekiya /*
    261       1.1    sekiya  * Handle PCI error interrupts.
    262       1.1    sekiya  */
    263       1.1    sekiya int
    264       1.5    sekiya macepci_intr(void *arg)
    265       1.1    sekiya {
    266       1.1    sekiya 	struct macepci_softc *sc = (struct macepci_softc *)arg;
    267       1.1    sekiya 	pci_chipset_tag_t pc = &sc->sc_pc;
    268       1.1    sekiya 	u_int32_t error, address;
    269       1.1    sekiya 
    270       1.1    sekiya 	error = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS);
    271       1.1    sekiya 	address = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR);
    272       1.1    sekiya 	while (error & 0xffc00000) {
    273       1.1    sekiya 		if (error & MACE_PERR_MASTER_ABORT) {
    274       1.1    sekiya 			/*
    275       1.1    sekiya 			 * this seems to be a more-or-less normal error
    276       1.1    sekiya 			 * condition (e.g., "pcictl pci0 list" generates
    277       1.1    sekiya 			 * a _lot_ of these errors, so no message for now
    278       1.1    sekiya 			 * while I figure out if I missed a trick somewhere.
    279       1.1    sekiya 			 */
    280       1.1    sekiya 			error &= ~MACE_PERR_MASTER_ABORT;
    281       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    282       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    283       1.1    sekiya 		}
    284       1.1    sekiya 
    285       1.1    sekiya 		if (error & MACE_PERR_TARGET_ABORT) {
    286       1.1    sekiya 			printf("mace: target abort at %x\n", address);
    287       1.1    sekiya 			error &= ~MACE_PERR_TARGET_ABORT;
    288       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    289       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    290       1.1    sekiya 		}
    291       1.1    sekiya 
    292       1.1    sekiya 		if (error & MACE_PERR_DATA_PARITY_ERR) {
    293       1.1    sekiya 			printf("mace: parity error at %x\n", address);
    294       1.1    sekiya 			error &= ~MACE_PERR_DATA_PARITY_ERR;
    295       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    296       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    297       1.1    sekiya 		}
    298       1.1    sekiya 
    299       1.1    sekiya 		if (error & MACE_PERR_RETRY_ERR) {
    300       1.1    sekiya 			printf("mace: retry error at %x\n", address);
    301       1.1    sekiya 			error &= ~MACE_PERR_RETRY_ERR;
    302       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    303       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    304       1.1    sekiya 		}
    305       1.1    sekiya 
    306       1.1    sekiya 		if (error & MACE_PERR_ILLEGAL_CMD) {
    307       1.1    sekiya 			printf("mace: illegal command at %x\n", address);
    308       1.1    sekiya 			error &= ~MACE_PERR_ILLEGAL_CMD;
    309       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    310       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    311       1.1    sekiya 		}
    312       1.1    sekiya 
    313       1.1    sekiya 		if (error & MACE_PERR_SYSTEM_ERR) {
    314       1.1    sekiya 			printf("mace: system error at %x\n", address);
    315       1.1    sekiya 			error &= ~MACE_PERR_SYSTEM_ERR;
    316       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    317       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    318       1.1    sekiya 		}
    319       1.1    sekiya 
    320       1.1    sekiya 		if (error & MACE_PERR_INTERRUPT_TEST) {
    321       1.1    sekiya 			printf("mace: interrupt test at %x\n", address);
    322       1.1    sekiya 			error &= ~MACE_PERR_INTERRUPT_TEST;
    323       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    324       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    325       1.1    sekiya 		}
    326       1.1    sekiya 
    327       1.1    sekiya 		if (error & MACE_PERR_PARITY_ERR) {
    328       1.1    sekiya 			printf("mace: parity error at %x\n", address);
    329       1.1    sekiya 			error &= ~MACE_PERR_PARITY_ERR;
    330       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    331       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    332       1.1    sekiya 		}
    333       1.1    sekiya 
    334       1.1    sekiya 		if (error & MACE_PERR_RSVD) {
    335       1.1    sekiya 			printf("mace: reserved condition at %x\n", address);
    336       1.1    sekiya 			error &= ~MACE_PERR_RSVD;
    337       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    338       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    339       1.1    sekiya 		}
    340       1.1    sekiya 
    341       1.1    sekiya 		if (error & MACE_PERR_OVERRUN) {
    342       1.1    sekiya 			printf("mace: overrun at %x\n", address);
    343       1.1    sekiya 			error &= ~MACE_PERR_OVERRUN;
    344       1.1    sekiya 			bus_space_write_4(pc->iot, pc->ioh,
    345       1.1    sekiya 			    MACE_PCI_ERROR_FLAGS, error);
    346       1.1    sekiya 		}
    347       1.1    sekiya 	}
    348       1.1    sekiya 	return 0;
    349       1.1    sekiya }
    350