xref: /netbsd-src/sys/arch/sgimips/mace/pci_mace.c (revision e5fbc36ada28f9b9a5836ecffaf4a06aa1ebb687)
1*e5fbc36aSthorpej /*	$NetBSD: pci_mace.c,v 1.26 2023/12/20 15:29:07 thorpej Exp $	*/
263b59c4dSsekiya 
363b59c4dSsekiya /*
463b59c4dSsekiya  * Copyright (c) 2001,2003 Christopher Sekiya
563b59c4dSsekiya  * Copyright (c) 2000 Soren S. Jorvang
663b59c4dSsekiya  * All rights reserved.
763b59c4dSsekiya  *
863b59c4dSsekiya  * Redistribution and use in source and binary forms, with or without
963b59c4dSsekiya  * modification, are permitted provided that the following conditions
1063b59c4dSsekiya  * are met:
1163b59c4dSsekiya  * 1. Redistributions of source code must retain the above copyright
1263b59c4dSsekiya  *    notice, this list of conditions and the following disclaimer.
1363b59c4dSsekiya  * 2. Redistributions in binary form must reproduce the above copyright
1463b59c4dSsekiya  *    notice, this list of conditions and the following disclaimer in the
1563b59c4dSsekiya  *    documentation and/or other materials provided with the distribution.
1663b59c4dSsekiya  * 3. All advertising materials mentioning features or use of this software
1763b59c4dSsekiya  *    must display the following acknowledgement:
1863b59c4dSsekiya  *          This product includes software developed for the
1963b59c4dSsekiya  *          NetBSD Project.  See http://www.NetBSD.org/ for
2063b59c4dSsekiya  *          information about NetBSD.
2163b59c4dSsekiya  * 4. The name of the author may not be used to endorse or promote products
2263b59c4dSsekiya  *    derived from this software without specific prior written permission.
2363b59c4dSsekiya  *
2463b59c4dSsekiya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2563b59c4dSsekiya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2663b59c4dSsekiya  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2763b59c4dSsekiya  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2863b59c4dSsekiya  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2963b59c4dSsekiya  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3063b59c4dSsekiya  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3163b59c4dSsekiya  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3263b59c4dSsekiya  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3363b59c4dSsekiya  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3463b59c4dSsekiya  */
3563b59c4dSsekiya 
3663b59c4dSsekiya #include <sys/cdefs.h>
37*e5fbc36aSthorpej __KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.26 2023/12/20 15:29:07 thorpej Exp $");
38936c3743Stsutsui 
39936c3743Stsutsui #include "opt_pci.h"
40936c3743Stsutsui #include "pci.h"
4163b59c4dSsekiya 
4263b59c4dSsekiya #include <sys/param.h>
4363b59c4dSsekiya #include <sys/device.h>
4463b59c4dSsekiya #include <sys/systm.h>
4563b59c4dSsekiya 
4663b59c4dSsekiya #include <machine/cpu.h>
4763b59c4dSsekiya #include <machine/locore.h>
4863b59c4dSsekiya #include <machine/autoconf.h>
4963b59c4dSsekiya #include <machine/vmparam.h>
50cf10107dSdyoung #include <sys/bus.h>
5163b59c4dSsekiya #include <machine/machtype.h>
5263b59c4dSsekiya 
53936c3743Stsutsui #include <mips/cache.h>
54936c3743Stsutsui 
5563b59c4dSsekiya #include <dev/pci/pcivar.h>
5663b59c4dSsekiya #include <dev/pci/pcireg.h>
5763b59c4dSsekiya #include <dev/pci/pcidevs.h>
5863b59c4dSsekiya 
59936c3743Stsutsui #include <dev/pci/pciconf.h>
60936c3743Stsutsui 
6163b59c4dSsekiya #include <sgimips/mace/macereg.h>
6263b59c4dSsekiya #include <sgimips/mace/macevar.h>
6363b59c4dSsekiya 
6463b59c4dSsekiya #include <sgimips/mace/pcireg_mace.h>
6563b59c4dSsekiya 
668223c423Smacallan #ifndef __mips_o32
678223c423Smacallan #define USE_HIGH_PCI
688223c423Smacallan #endif
698223c423Smacallan 
708223c423Smacallan 
7163b59c4dSsekiya struct macepci_softc {
7263b59c4dSsekiya 	struct sgimips_pci_chipset sc_pc;
7363b59c4dSsekiya };
7463b59c4dSsekiya 
75cbab9cadSchs static int	macepci_match(device_t, cfdata_t, void *);
76cbab9cadSchs static void	macepci_attach(device_t, device_t, void *);
77aa71bc78Srumble static int	macepci_bus_maxdevs(pci_chipset_tag_t, int);
78aa71bc78Srumble static pcireg_t	macepci_conf_read(pci_chipset_tag_t, pcitag_t, int);
79aa71bc78Srumble static void	macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
803d764674Sdyoung static int	macepci_intr_map(const struct pci_attach_args *,
813d764674Sdyoung 		    pci_intr_handle_t *);
82aa71bc78Srumble static const char *
83e58a356cSchristos 		macepci_intr_string(pci_chipset_tag_t, pci_intr_handle_t,
84e58a356cSchristos 		    char *, size_t);
85aa71bc78Srumble static int	macepci_intr(void *);
8663b59c4dSsekiya 
87cbab9cadSchs CFATTACH_DECL_NEW(macepci, sizeof(struct macepci_softc),
8863b59c4dSsekiya     macepci_match, macepci_attach, NULL, NULL);
8963b59c4dSsekiya 
90eb488f67Smacallan static void pcimem_bus_mem_init(bus_space_tag_t, void *);
91eb488f67Smacallan static void pciio_bus_mem_init(bus_space_tag_t, void *);
92eb488f67Smacallan static struct mips_bus_space	pcimem_mbst;
93eb488f67Smacallan static struct mips_bus_space	pciio_mbst;
94eb488f67Smacallan bus_space_tag_t	mace_pci_memt = NULL;
95eb488f67Smacallan bus_space_tag_t	mace_pci_iot = NULL;
96eb488f67Smacallan 
97ca8ce3aeSthorpej #define	PCI_IO_START	0x00001000
98ca8ce3aeSthorpej #define	PCI_IO_END	0x01ffffff
99ca8ce3aeSthorpej #define	PCI_IO_SIZE	((PCI_IO_END - PCI_IO_START) + 1)
100ca8ce3aeSthorpej 
101ca8ce3aeSthorpej #ifdef USE_HIGH_PCI
102ca8ce3aeSthorpej #define	PCI_MEM_START	0x80000000
103ca8ce3aeSthorpej #define	PCI_MEM_END	0xffffffff
104ca8ce3aeSthorpej #else /* ! USE_HIGH_PCI */
105ca8ce3aeSthorpej /* XXX no idea why we limit ourselves to only half of the 32MB window */
106ca8ce3aeSthorpej #define	PCI_MEM_START	0x80100000
107ca8ce3aeSthorpej #define	PCI_MEM_END	0x81ffffff
108ca8ce3aeSthorpej #endif /* USE_HIGH_PCI */
109ca8ce3aeSthorpej 
110ca8ce3aeSthorpej #define	PCI_MEM_SIZE	((PCI_MEM_END - PCI_MEM_START) + 1)
111ca8ce3aeSthorpej 
11263b59c4dSsekiya static int
macepci_match(device_t parent,cfdata_t match,void * aux)113cbab9cadSchs macepci_match(device_t parent, cfdata_t match, void *aux)
11463b59c4dSsekiya {
11563b59c4dSsekiya 
11663b59c4dSsekiya 	return (1);
11763b59c4dSsekiya }
11863b59c4dSsekiya 
11963b59c4dSsekiya static void
macepci_attach(device_t parent,device_t self,void * aux)120cbab9cadSchs macepci_attach(device_t parent, device_t self, void *aux)
12163b59c4dSsekiya {
122cbab9cadSchs 	struct macepci_softc *sc = device_private(self);
12363b59c4dSsekiya 	pci_chipset_tag_t pc = &sc->sc_pc;
12463b59c4dSsekiya 	struct mace_attach_args *maa = aux;
12563b59c4dSsekiya 	struct pcibus_attach_args pba;
12663b59c4dSsekiya 	u_int32_t control;
127936c3743Stsutsui 	int rev;
12863b59c4dSsekiya 
12963b59c4dSsekiya 	if (bus_space_subregion(maa->maa_st, maa->maa_sh,
13063b59c4dSsekiya 	    maa->maa_offset, 0, &pc->ioh) )
13163b59c4dSsekiya 		panic("macepci_attach: couldn't map");
13263b59c4dSsekiya 
13363b59c4dSsekiya 	pc->iot = maa->maa_st;
13463b59c4dSsekiya 
13563b59c4dSsekiya 	rev = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_REVISION);
13663b59c4dSsekiya 	printf(": rev %d\n", rev);
13763b59c4dSsekiya 
138eb488f67Smacallan 	pcimem_bus_mem_init(&pcimem_mbst, NULL);
139eb488f67Smacallan 	mace_pci_memt = &pcimem_mbst;
140eb488f67Smacallan 	pciio_bus_mem_init(&pciio_mbst, NULL);
141eb488f67Smacallan 	mace_pci_iot = &pciio_mbst;
142eb488f67Smacallan 
143aa71bc78Srumble 	pc->pc_bus_maxdevs = macepci_bus_maxdevs;
14463b59c4dSsekiya 	pc->pc_conf_read = macepci_conf_read;
14563b59c4dSsekiya 	pc->pc_conf_write = macepci_conf_write;
146aa71bc78Srumble 	pc->pc_intr_map = macepci_intr_map;
147aa71bc78Srumble 	pc->pc_intr_string = macepci_intr_string;
1488590eac4Ssekiya 	pc->intr_establish = mace_intr_establish;
1498590eac4Ssekiya 	pc->intr_disestablish = mace_intr_disestablish;
15063b59c4dSsekiya 
15163b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR, 0);
15263b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS, 0);
15363b59c4dSsekiya 
15463b59c4dSsekiya 	/* Turn on PCI error interrupts */
15563b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONTROL,
15663b59c4dSsekiya 	    MACE_PCI_CONTROL_SERR_ENA |
15763b59c4dSsekiya 	    MACE_PCI_CONTROL_PARITY_ERR |
15863b59c4dSsekiya 	    MACE_PCI_CONTROL_PARK_LIU |
15963b59c4dSsekiya 	    MACE_PCI_CONTROL_OVERRUN_INT |
16063b59c4dSsekiya 	    MACE_PCI_CONTROL_PARITY_INT |
16163b59c4dSsekiya 	    MACE_PCI_CONTROL_SERR_INT |
16263b59c4dSsekiya 	    MACE_PCI_CONTROL_IT_INT |
16363b59c4dSsekiya 	    MACE_PCI_CONTROL_RE_INT |
16463b59c4dSsekiya 	    MACE_PCI_CONTROL_DPED_INT |
16563b59c4dSsekiya 	    MACE_PCI_CONTROL_TAR_INT |
16663b59c4dSsekiya 	    MACE_PCI_CONTROL_MAR_INT);
16763b59c4dSsekiya 
16863b59c4dSsekiya 	/*
16963b59c4dSsekiya 	 * Enable all MACE PCI interrupts. They will be masked by
17063b59c4dSsekiya 	 * the CRIME code.
17163b59c4dSsekiya 	 */
17263b59c4dSsekiya 	control = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_CONTROL);
17363b59c4dSsekiya 	control |= CONTROL_INT_MASK;
17463b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACEPCI_CONTROL, control);
17563b59c4dSsekiya 
17663b59c4dSsekiya #if NPCI > 0
177ca8ce3aeSthorpej 	struct pciconf_resources *pcires = pciconf_resource_init();
178ca8ce3aeSthorpej 
179ca8ce3aeSthorpej 	pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
180ca8ce3aeSthorpej 	    PCI_IO_START, PCI_IO_SIZE);
181ca8ce3aeSthorpej 	pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
182ca8ce3aeSthorpej 	    PCI_MEM_START, PCI_MEM_SIZE);
183ca8ce3aeSthorpej 
184ca8ce3aeSthorpej 	pci_configure_bus(pc, pcires, 0,
18523347d39Smatt 	    mips_cache_info.mci_dcache_align);
186ca8ce3aeSthorpej 
187ca8ce3aeSthorpej 	pciconf_resource_fini(pcires);
188ca8ce3aeSthorpej 
18963b59c4dSsekiya 	memset(&pba, 0, sizeof pba);
1908223c423Smacallan 	pba.pba_iot = mace_pci_iot;
1918223c423Smacallan 	pba.pba_memt = mace_pci_memt;
19263b59c4dSsekiya 	pba.pba_dmat = &pci_bus_dma_tag;
19363b59c4dSsekiya 	pba.pba_dmat64 = NULL;
19463b59c4dSsekiya 	pba.pba_bus = 0;
19563b59c4dSsekiya 	pba.pba_bridgetag = NULL;
196a6b2b839Sdyoung 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
19763b59c4dSsekiya 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
19863b59c4dSsekiya 	pba.pba_pc = pc;
19963b59c4dSsekiya 
20063b59c4dSsekiya #ifdef MACEPCI_IO_WAS_BUGGY
20163b59c4dSsekiya 	if (rev == 0)
202a6b2b839Sdyoung 		pba.pba_flags &= ~PCI_FLAGS_IO_OKAY;		/* Buggy? */
20363b59c4dSsekiya #endif
20463b59c4dSsekiya 
20563b59c4dSsekiya 	cpu_intr_establish(maa->maa_intr, IPL_NONE, macepci_intr, sc);
20663b59c4dSsekiya 
207c7fb772bSthorpej 	config_found(self, &pba, pcibusprint, CFARGS_NONE);
20863b59c4dSsekiya #endif
20963b59c4dSsekiya }
21063b59c4dSsekiya 
211aa71bc78Srumble int
macepci_bus_maxdevs(pci_chipset_tag_t pc,int busno)212aa71bc78Srumble macepci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
213aa71bc78Srumble {
214aa71bc78Srumble 
215aa71bc78Srumble 	if (busno == 0)
216aa71bc78Srumble 		return 5;	/* 2 on-board SCSI chips, slots 0, 1 and 2 */
217aa71bc78Srumble 	else
218aa71bc78Srumble 		return 0;	/* XXX */
219aa71bc78Srumble }
220aa71bc78Srumble 
22163b59c4dSsekiya pcireg_t
macepci_conf_read(pci_chipset_tag_t pc,pcitag_t tag,int reg)222551d2b9aSsekiya macepci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
22363b59c4dSsekiya {
22463b59c4dSsekiya 	pcireg_t data;
22563b59c4dSsekiya 
226605f564fSmsaitoh 	if ((unsigned int)reg >= PCI_CONF_SIZE)
227605f564fSmsaitoh 		return (pcireg_t) -1;
228605f564fSmsaitoh 
22963b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
23063b59c4dSsekiya 	data = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA);
23163b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
23263b59c4dSsekiya 
23363b59c4dSsekiya 	return data;
23463b59c4dSsekiya }
23563b59c4dSsekiya 
23663b59c4dSsekiya void
macepci_conf_write(pci_chipset_tag_t pc,pcitag_t tag,int reg,pcireg_t data)237551d2b9aSsekiya macepci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
23863b59c4dSsekiya {
23963b59c4dSsekiya 
240605f564fSmsaitoh 	if ((unsigned int)reg >= PCI_CONF_SIZE)
241605f564fSmsaitoh 		return;
242605f564fSmsaitoh 
24363b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
24463b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA, data);
24563b59c4dSsekiya 	bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
24663b59c4dSsekiya }
24763b59c4dSsekiya 
248aa71bc78Srumble int
macepci_intr_map(const struct pci_attach_args * pa,pci_intr_handle_t * ihp)2493d764674Sdyoung macepci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
250aa71bc78Srumble {
251aa71bc78Srumble 	pci_chipset_tag_t pc = pa->pa_pc;
252aa71bc78Srumble 	pcitag_t intrtag = pa->pa_intrtag;
253aa71bc78Srumble 	int pin = pa->pa_intrpin;
254aa71bc78Srumble 	int bus, dev, func, start;
255aa71bc78Srumble 
256aa71bc78Srumble 	pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
257aa71bc78Srumble 
258aa71bc78Srumble 	if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
259aa71bc78Srumble 		panic("SCSI0 and SCSI1 must be hardwired!");
260aa71bc78Srumble 
261aa71bc78Srumble 	switch (pin) {
262aa71bc78Srumble 	default:
263aa71bc78Srumble 	case PCI_INTERRUPT_PIN_NONE:
264aa71bc78Srumble 		return -1;
265aa71bc78Srumble 
266aa71bc78Srumble 	case PCI_INTERRUPT_PIN_A:
267aa71bc78Srumble 		/*
268aa71bc78Srumble 		 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
269aa71bc78Srumble 		 * for pin A?
270aa71bc78Srumble 		 */
271aa71bc78Srumble 		*ihp = dev + 7;
272aa71bc78Srumble 		return 0;
273aa71bc78Srumble 
274aa71bc78Srumble 	case PCI_INTERRUPT_PIN_B:
275aa71bc78Srumble 		start = 0;
276aa71bc78Srumble 		break;
277aa71bc78Srumble 	case PCI_INTERRUPT_PIN_C:
278aa71bc78Srumble 		start = 1;
279aa71bc78Srumble 		break;
280aa71bc78Srumble 	case PCI_INTERRUPT_PIN_D:
281aa71bc78Srumble 		start = 2;
282aa71bc78Srumble 		break;
283aa71bc78Srumble 	}
284aa71bc78Srumble 
285aa71bc78Srumble 	/* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
286aa71bc78Srumble 	*ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
287aa71bc78Srumble 	return 0;
288aa71bc78Srumble }
289aa71bc78Srumble 
290aa71bc78Srumble const char *
macepci_intr_string(pci_chipset_tag_t pc,pci_intr_handle_t ih,char * buf,size_t len)291e58a356cSchristos macepci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf,
292e58a356cSchristos     size_t len)
293aa71bc78Srumble {
294e58a356cSchristos 	snprintf(buf, len, "crime interrupt %d", ih);
295e58a356cSchristos 	return buf;
296aa71bc78Srumble }
297aa71bc78Srumble 
29863b59c4dSsekiya 
29963b59c4dSsekiya /*
30063b59c4dSsekiya  * Handle PCI error interrupts.
30163b59c4dSsekiya  */
30263b59c4dSsekiya int
macepci_intr(void * arg)303551d2b9aSsekiya macepci_intr(void *arg)
30463b59c4dSsekiya {
30563b59c4dSsekiya 	struct macepci_softc *sc = (struct macepci_softc *)arg;
30663b59c4dSsekiya 	pci_chipset_tag_t pc = &sc->sc_pc;
307139ff8f9Smacallan 	uint32_t error, address;
30863b59c4dSsekiya 
30963b59c4dSsekiya 	error = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS);
31063b59c4dSsekiya 	address = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR);
311139ff8f9Smacallan 	if (error & 0xffc00000) {
31263b59c4dSsekiya 		if (error & MACE_PERR_MASTER_ABORT) {
31363b59c4dSsekiya 			/*
31463b59c4dSsekiya 			 * this seems to be a more-or-less normal error
31563b59c4dSsekiya 			 * condition (e.g., "pcictl pci0 list" generates
31663b59c4dSsekiya 			 * a _lot_ of these errors, so no message for now
31763b59c4dSsekiya 			 * while I figure out if I missed a trick somewhere.
31863b59c4dSsekiya 			 */
31963b59c4dSsekiya 		}
32063b59c4dSsekiya 
32163b59c4dSsekiya 		if (error & MACE_PERR_TARGET_ABORT) {
32263b59c4dSsekiya 			printf("mace: target abort at %x\n", address);
32363b59c4dSsekiya 		}
32463b59c4dSsekiya 
32563b59c4dSsekiya 		if (error & MACE_PERR_DATA_PARITY_ERR) {
32663b59c4dSsekiya 			printf("mace: parity error at %x\n", address);
32763b59c4dSsekiya 		}
32863b59c4dSsekiya 
32963b59c4dSsekiya 		if (error & MACE_PERR_RETRY_ERR) {
33063b59c4dSsekiya 			printf("mace: retry error at %x\n", address);
33163b59c4dSsekiya 		}
33263b59c4dSsekiya 
33363b59c4dSsekiya 		if (error & MACE_PERR_ILLEGAL_CMD) {
33463b59c4dSsekiya 			printf("mace: illegal command at %x\n", address);
33563b59c4dSsekiya 		}
33663b59c4dSsekiya 
33763b59c4dSsekiya 		if (error & MACE_PERR_SYSTEM_ERR) {
33863b59c4dSsekiya 			printf("mace: system error at %x\n", address);
33963b59c4dSsekiya 		}
34063b59c4dSsekiya 
34163b59c4dSsekiya 		if (error & MACE_PERR_INTERRUPT_TEST) {
34263b59c4dSsekiya 			printf("mace: interrupt test at %x\n", address);
34363b59c4dSsekiya 		}
34463b59c4dSsekiya 
34563b59c4dSsekiya 		if (error & MACE_PERR_PARITY_ERR) {
34663b59c4dSsekiya 			printf("mace: parity error at %x\n", address);
34763b59c4dSsekiya 		}
34863b59c4dSsekiya 
34963b59c4dSsekiya 		if (error & MACE_PERR_RSVD) {
35063b59c4dSsekiya 			printf("mace: reserved condition at %x\n", address);
35163b59c4dSsekiya 		}
35263b59c4dSsekiya 
35363b59c4dSsekiya 		if (error & MACE_PERR_OVERRUN) {
35463b59c4dSsekiya 			printf("mace: overrun at %x\n", address);
35563b59c4dSsekiya 		}
356139ff8f9Smacallan 
357139ff8f9Smacallan 		/* clear all */
358139ff8f9Smacallan 		bus_space_write_4(pc->iot, pc->ioh,
359139ff8f9Smacallan 			    MACE_PCI_ERROR_FLAGS, error & ~0xffc00000);
36063b59c4dSsekiya 	}
36163b59c4dSsekiya 	return 0;
36263b59c4dSsekiya }
363eb488f67Smacallan 
364eb488f67Smacallan /*
365eb488f67Smacallan  * use the 32MB windows to access PCI space when running a 32bit kernel,
366eb488f67Smacallan  * use full views at >4GB in LP64
367eb488f67Smacallan  * XXX access to PCI space is endian-twiddled which can't be turned off so we
368eb488f67Smacallan  * need to instruct bus_space to un-twiddle them for us so 8bit and 16bit
369eb488f67Smacallan  * accesses look little-endian
370eb488f67Smacallan  */
371eb488f67Smacallan #define CHIP	   		pcimem
372eb488f67Smacallan #define	CHIP_MEM		/* defined */
373eb488f67Smacallan #define CHIP_WRONG_ENDIAN
374eb488f67Smacallan 
375eb488f67Smacallan /*
376eb488f67Smacallan  * the lower 2GB of PCI space are two views of system memory, with and without
377eb488f67Smacallan  * endianness twiddling
378eb488f67Smacallan  */
379eb488f67Smacallan #define	CHIP_W1_BUS_START(v)	0x80000000UL
380eb488f67Smacallan #define CHIP_W1_BUS_END(v)	0xffffffffUL
3818223c423Smacallan #ifdef USE_HIGH_PCI
382eb488f67Smacallan #define	CHIP_W1_SYS_START(v)	MACE_PCI_HI_MEMORY
383eb488f67Smacallan #define	CHIP_W1_SYS_END(v)	MACE_PCI_HI_MEMORY + 0x7fffffffUL
384eb488f67Smacallan #else
385eb488f67Smacallan #define	CHIP_W1_SYS_START(v)	MACE_PCI_LOW_MEMORY
386eb488f67Smacallan #define	CHIP_W1_SYS_END(v)	MACE_PCI_LOW_MEMORY + 0x01ffffffUL
387eb488f67Smacallan #endif
388eb488f67Smacallan 
389eb488f67Smacallan #include <mips/mips/bus_space_alignstride_chipdep.c>
390eb488f67Smacallan 
391eb488f67Smacallan #undef CHIP
392eb488f67Smacallan #undef CHIP_W1_BUS_START
393eb488f67Smacallan #undef CHIP_W1_BUS_END
394eb488f67Smacallan #undef CHIP_W1_SYS_START
395eb488f67Smacallan #undef CHIP_W1_SYS_END
396eb488f67Smacallan 
397eb488f67Smacallan #define CHIP	   		pciio
398eb488f67Smacallan /*
399eb488f67Smacallan  * Even though it's PCI IO space, it's memory mapped so there is no reason not
400eb488f67Smacallan  * to allow linear mappings or mmapings into userland. In fact we may need to
401eb488f67Smacallan  * do just that in order to use things like PCI graphics cards in X.
402eb488f67Smacallan  */
403eb488f67Smacallan #define	CHIP_MEM		/* defined */
404eb488f67Smacallan #define	CHIP_W1_BUS_START(v)	0x00000000UL
405eb488f67Smacallan #define CHIP_W1_BUS_END(v)	0xffffffffUL
4068223c423Smacallan #ifdef USE_HIGH_PCI
407eb488f67Smacallan #define	CHIP_W1_SYS_START(v)	MACE_PCI_HI_IO
408eb488f67Smacallan #define	CHIP_W1_SYS_END(v)	MACE_PCI_HI_IO + 0xffffffffUL
409eb488f67Smacallan #else
410eb488f67Smacallan #define	CHIP_W1_SYS_START(v)	MACE_PCI_LOW_IO
411eb488f67Smacallan #define	CHIP_W1_SYS_END(v)	MACE_PCI_LOW_IO + 0x01ffffffUL
412eb488f67Smacallan #endif
413eb488f67Smacallan 
414eb488f67Smacallan #include <mips/mips/bus_space_alignstride_chipdep.c>
415