xref: /netbsd-src/sys/arch/sgimips/dev/imc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: imc.c,v 1.37 2021/08/07 16:19:04 thorpej Exp $	*/
23b92374aSthorpej 
33b92374aSthorpej /*
43b92374aSthorpej  * Copyright (c) 2001 Rafal K. Boni
53b92374aSthorpej  * All rights reserved.
63b92374aSthorpej  *
73b92374aSthorpej  * Redistribution and use in source and binary forms, with or without
83b92374aSthorpej  * modification, are permitted provided that the following conditions
93b92374aSthorpej  * are met:
103b92374aSthorpej  * 1. Redistributions of source code must retain the above copyright
113b92374aSthorpej  *    notice, this list of conditions and the following disclaimer.
123b92374aSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
133b92374aSthorpej  *    notice, this list of conditions and the following disclaimer in the
143b92374aSthorpej  *    documentation and/or other materials provided with the distribution.
153b92374aSthorpej  * 3. The name of the author may not be used to endorse or promote products
163b92374aSthorpej  *    derived from this software without specific prior written permission.
173b92374aSthorpej  *
183b92374aSthorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
193b92374aSthorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
203b92374aSthorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
213b92374aSthorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b92374aSthorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
233b92374aSthorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
243b92374aSthorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
253b92374aSthorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
263b92374aSthorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
273b92374aSthorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
283b92374aSthorpej  */
293b92374aSthorpej 
30ed517291Slukem #include <sys/cdefs.h>
31*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: imc.c,v 1.37 2021/08/07 16:19:04 thorpej Exp $");
32ed517291Slukem 
333b92374aSthorpej #include <sys/param.h>
343b92374aSthorpej #include <sys/device.h>
353b92374aSthorpej #include <sys/systm.h>
363b92374aSthorpej 
373b92374aSthorpej #include <machine/cpu.h>
383b92374aSthorpej #include <machine/locore.h>
393b92374aSthorpej #include <machine/autoconf.h>
40cf10107dSdyoung #include <sys/bus.h>
41af0e157bSthorpej #include <machine/machtype.h>
42ffc95bbeSsekiya #include <machine/sysconf.h>
433b92374aSthorpej 
4439c82fe9Srafal #include <sgimips/dev/imcreg.h>
45a4d0bfd7Srumble #include <sgimips/dev/imcvar.h>
46a4d0bfd7Srumble 
47a4d0bfd7Srumble #include <sgimips/gio/giovar.h>
4839c82fe9Srafal 
493b92374aSthorpej #include "locators.h"
503b92374aSthorpej 
513b92374aSthorpej struct imc_softc {
52264219f6Ssekiya 	bus_space_tag_t iot;
53264219f6Ssekiya 	bus_space_handle_t ioh;
54264219f6Ssekiya 
55c830efd5Ssekiya 	int eisa_present;
563b92374aSthorpej };
573b92374aSthorpej 
58cbab9cadSchs static int	imc_match(device_t, cfdata_t, void *);
59cbab9cadSchs static void	imc_attach(device_t, device_t, void *);
603b92374aSthorpej static int	imc_print(void *, const char *);
6187586607Srumble static void	imc_bus_reset(void);
6223347d39Smatt static void	imc_bus_error(vaddr_t, uint32_t, uint32_t);
6387586607Srumble static void	imc_watchdog_reset(void);
6487586607Srumble static void	imc_watchdog_disable(void);
6587586607Srumble static void	imc_watchdog_enable(void);
663b92374aSthorpej 
67cbab9cadSchs CFATTACH_DECL_NEW(imc, sizeof(struct imc_softc),
6889bf5a8fSthorpej     imc_match, imc_attach, NULL, NULL);
693b92374aSthorpej 
703b92374aSthorpej struct imc_attach_args {
713b92374aSthorpej 	const char* iaa_name;
723b92374aSthorpej 
733b92374aSthorpej 	bus_space_tag_t iaa_st;
743b92374aSthorpej 	bus_space_handle_t iaa_sh;
753b92374aSthorpej 
763b92374aSthorpej /* ? */
773b92374aSthorpej 	long	iaa_offset;
783b92374aSthorpej 	int	iaa_intr;
793b92374aSthorpej #if 0
803b92374aSthorpej 	int	iaa_stride;
813b92374aSthorpej #endif
823b92374aSthorpej };
833b92374aSthorpej 
84a4d0bfd7Srumble int imc_gio64_arb_config(int, uint32_t);
85a4d0bfd7Srumble 
86264219f6Ssekiya struct imc_softc isc;
87264219f6Ssekiya 
883b92374aSthorpej static int
imc_match(device_t parent,cfdata_t match,void * aux)89cbab9cadSchs imc_match(device_t parent, cfdata_t match, void *aux)
903b92374aSthorpej {
913b92374aSthorpej 
92264219f6Ssekiya 	if ((mach_type == MACH_SGI_IP22) || (mach_type == MACH_SGI_IP20))
9334267609Stsutsui 		return 1;
94264219f6Ssekiya 
9534267609Stsutsui 	return 0;
963b92374aSthorpej }
973b92374aSthorpej 
983b92374aSthorpej static void
imc_attach(device_t parent,device_t self,void * aux)99cbab9cadSchs imc_attach(device_t parent, device_t self, void *aux)
1003b92374aSthorpej {
10134267609Stsutsui 	uint32_t reg;
1023b92374aSthorpej 	struct imc_attach_args iaa;
103264219f6Ssekiya 	struct mainbus_attach_args *ma = aux;
10434267609Stsutsui 	uint32_t sysid;
105264219f6Ssekiya 
106eb488f67Smacallan 	isc.iot = normal_memt;
107eb488f67Smacallan 	if (bus_space_map(isc.iot, ma->ma_addr, 0x100,
108264219f6Ssekiya 	    BUS_SPACE_MAP_LINEAR, &isc.ioh))
1090fa231ddSmacallan 		panic("imc_attach: could not map registers\n");
110264219f6Ssekiya 
111ffc95bbeSsekiya 	platform.bus_reset = imc_bus_reset;
11223020fc3Ssekiya 	platform.watchdog_reset = imc_watchdog_reset;
11323020fc3Ssekiya 	platform.watchdog_disable = imc_watchdog_disable;
11423020fc3Ssekiya 	platform.watchdog_enable = imc_watchdog_enable;
115ffc95bbeSsekiya 
116264219f6Ssekiya 	sysid = bus_space_read_4(isc.iot, isc.ioh, IMC_SYSID);
1173b92374aSthorpej 
1188c64b077Ssekiya 	/* EISA exists on IP22 only */
1198c64b077Ssekiya 	if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
120c830efd5Ssekiya 		isc.eisa_present = (sysid & IMC_SYSID_HAVEISA);
1218c64b077Ssekiya 	else
1228c64b077Ssekiya 		isc.eisa_present = 0;
1233b92374aSthorpej 
1246ce242b7Ssekiya 	printf(": revision %d", (sysid & IMC_SYSID_REVMASK));
1253b92374aSthorpej 
126264219f6Ssekiya 	if (isc.eisa_present)
1273b92374aSthorpej 		printf(", EISA bus present");
1283b92374aSthorpej 
1293b92374aSthorpej 	printf("\n");
1303b92374aSthorpej 
1313b92374aSthorpej 	/* Clear CPU/GIO error status registers to clear any leftover bits. */
13249ecfdf2Ssekiya 	imc_bus_reset();
13349ecfdf2Ssekiya 
13449ecfdf2Ssekiya 	/* Hook the bus error handler into the ISR */
13549ecfdf2Ssekiya 	platform.intr4 = imc_bus_error;
1363b92374aSthorpej 
1373b92374aSthorpej 	/*
13839c82fe9Srafal 	 * Enable parity reporting on GIO/main memory transactions.
13939c82fe9Srafal 	 * Disable parity checking on CPU bus transactions (as turning
14039c82fe9Srafal 	 * it on seems to cause spurious bus errors), but enable parity
14139c82fe9Srafal 	 * checking on CPU reads from main memory (note that this bit
14239c82fe9Srafal 	 * has the opposite sense... Turning it on turns the checks off!).
14339c82fe9Srafal 	 * Finally, turn on interrupt writes to the CPU from the MC.
1443b92374aSthorpej 	 */
145264219f6Ssekiya 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
14639c82fe9Srafal 	reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
14739c82fe9Srafal 	reg |= (IMC_CPUCTRL0_GPR | IMC_CPUCTRL0_MPR | IMC_CPUCTRL0_INTENA);
148264219f6Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
1493b92374aSthorpej 
1503b92374aSthorpej 	/* Setup the MC write buffer depth */
151264219f6Ssekiya 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL1);
15239c82fe9Srafal 	reg = (reg & ~IMC_CPUCTRL1_MCHWMSK) | 13;
153d023bcf0Srumble 
154d023bcf0Srumble 	/*
155d023bcf0Srumble 	 * Force endianness on the onboard HPC and both slots.
156d023bcf0Srumble 	 * This should be safe for Fullhouse, but leave it conditional
157d023bcf0Srumble 	 * for now.
158d023bcf0Srumble 	 */
159d023bcf0Srumble 	if (mach_type == MACH_SGI_IP20 || (mach_type == MACH_SGI_IP22 &&
160af1144f2Srumble 	    mach_subtype == MACH_SGI_IP22_GUINNESS)) {
161d023bcf0Srumble 		reg |=  IMC_CPUCTRL1_HPCFX;
162d023bcf0Srumble 		reg |=  IMC_CPUCTRL1_EXP0FX;
163d023bcf0Srumble 		reg |=  IMC_CPUCTRL1_EXP1FX;
164d023bcf0Srumble 		reg &= ~IMC_CPUCTRL1_HPCLITTLE;
165d023bcf0Srumble 		reg &= ~IMC_CPUCTRL1_EXP0LITTLE;
166d023bcf0Srumble 		reg &= ~IMC_CPUCTRL1_EXP1LITTLE;
167d023bcf0Srumble 	}
168264219f6Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL1, reg);
169264219f6Ssekiya 
1703b92374aSthorpej 
17139c82fe9Srafal 	/*
17239c82fe9Srafal 	 * Set GIO64 arbitrator configuration register:
17339c82fe9Srafal 	 *
17439c82fe9Srafal 	 * Preserve PROM-set graphics-related bits, as they seem to depend
17539c82fe9Srafal 	 * on the graphics variant present and I'm not sure how to figure
17639c82fe9Srafal 	 * that out or 100% sure what the correct settings are for each.
17739c82fe9Srafal 	 */
178264219f6Ssekiya 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
17939c82fe9Srafal 	reg &= (IMC_GIO64ARB_GRX64 | IMC_GIO64ARB_GRXRT | IMC_GIO64ARB_GRXMST);
1803b92374aSthorpej 
1814cbd24b2Swiz 	/* Rest of settings are machine/board dependent */
18234267609Stsutsui 	if (mach_type == MACH_SGI_IP20) {
183d023bcf0Srumble 		reg |=   IMC_GIO64ARB_ONEGIO;
184d023bcf0Srumble 	        reg |=  (IMC_GIO64ARB_EXP0RT	| IMC_GIO64ARB_EXP1RT);
185d023bcf0Srumble 		reg |=  (IMC_GIO64ARB_EXP0MST	| IMC_GIO64ARB_EXP1MST);
186264219f6Ssekiya 		reg &= ~(IMC_GIO64ARB_HPC64	|
187264219f6Ssekiya 			 IMC_GIO64ARB_HPCEXP64	| IMC_GIO64ARB_EISA64 |
188264219f6Ssekiya 			 IMC_GIO64ARB_EXP064	| IMC_GIO64ARB_EXP164 |
189d023bcf0Srumble 			 IMC_GIO64ARB_EXP0PIPE	| IMC_GIO64ARB_EXP1PIPE);
19034267609Stsutsui 	} else {
191d023bcf0Srumble 		/*
192d023bcf0Srumble 		 * GIO64 invariant for all IP22 platforms: one GIO bus,
193d023bcf0Srumble 		 * HPC1 @ 64
194d023bcf0Srumble 		 */
195d023bcf0Srumble 		reg |= IMC_GIO64ARB_ONEGIO | IMC_GIO64ARB_HPC64;
196d023bcf0Srumble 
19739c82fe9Srafal 		switch (mach_subtype) {
198af1144f2Srumble 		case MACH_SGI_IP22_GUINNESS:
199d023bcf0Srumble 			/* XXX is MST mutually exclusive? */
200d023bcf0Srumble 	        	reg |=  (IMC_GIO64ARB_EXP0RT	| IMC_GIO64ARB_EXP1RT);
201d023bcf0Srumble 			reg |=  (IMC_GIO64ARB_EXP0MST	| IMC_GIO64ARB_EXP1MST);
202d023bcf0Srumble 
20339c82fe9Srafal 			/* EISA can bus-master, is 64-bit */
20439c82fe9Srafal 			reg |= (IMC_GIO64ARB_EISAMST | IMC_GIO64ARB_EISA64);
20539c82fe9Srafal 			break;
20639c82fe9Srafal 
20739c82fe9Srafal 		case MACH_SGI_IP22_FULLHOUSE:
20839c82fe9Srafal 		/*
20939c82fe9Srafal 		 * All Fullhouse boards have a 64-bit HPC2 and pipelined
21039c82fe9Srafal 		 * EXP0 slot.
21139c82fe9Srafal 		 */
21239c82fe9Srafal 			reg |= (IMC_GIO64ARB_HPCEXP64 | IMC_GIO64ARB_EXP0PIPE);
21339c82fe9Srafal 
21439c82fe9Srafal 			if (mach_boardrev < 2) {
21539c82fe9Srafal 			/* EXP0 realtime, EXP1 can master */
21634267609Stsutsui 				reg |= (IMC_GIO64ARB_EXP0RT |
21734267609Stsutsui 				    IMC_GIO64ARB_EXP1MST);
21839c82fe9Srafal 			} else {
21939c82fe9Srafal 				/* EXP1 pipelined as well, EISA masters */
22034267609Stsutsui 				reg |= (IMC_GIO64ARB_EXP1PIPE |
22134267609Stsutsui 				    IMC_GIO64ARB_EISAMST);
22239c82fe9Srafal 			}
22339c82fe9Srafal 			break;
22439c82fe9Srafal 		}
225264219f6Ssekiya 	}
226707b8da2Ssimonb 
227264219f6Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
2283b92374aSthorpej 
229264219f6Ssekiya 	if (isc.eisa_present) {
2303b92374aSthorpej #if notyet
2313b92374aSthorpej 		memset(&iaa, 0, sizeof(iaa));
2323b92374aSthorpej 
2332685996bSthorpej 		config_found(self, &iaa, eisabusprint,
234*c7fb772bSthorpej 		    CFARGS(.iattr = "eisabus"));
2353b92374aSthorpej #endif
2363b92374aSthorpej 	}
2373b92374aSthorpej 
2383b92374aSthorpej 	memset(&iaa, 0, sizeof(iaa));
2393b92374aSthorpej 
2402685996bSthorpej 	config_found(self, &iaa, imc_print,
241*c7fb772bSthorpej 	    CFARGS(.iattr = "giobus"));
242280b50a3Ssekiya 
24323020fc3Ssekiya 	imc_watchdog_enable();
2443b92374aSthorpej }
2453b92374aSthorpej 
2463b92374aSthorpej 
2473b92374aSthorpej static int
imc_print(void * aux,const char * name)2488c64b077Ssekiya imc_print(void *aux, const char *name)
2493b92374aSthorpej {
25034267609Stsutsui 
2513b92374aSthorpej 	if (name)
2528c64b077Ssekiya 		aprint_normal("gio at %s", name);
2533b92374aSthorpej 
2543b92374aSthorpej 	return UNCONF;
2553b92374aSthorpej }
2563b92374aSthorpej 
25787586607Srumble static void
imc_bus_reset(void)258264219f6Ssekiya imc_bus_reset(void)
259264219f6Ssekiya {
26034267609Stsutsui 
261264219f6Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT, 0);
262264219f6Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT, 0);
263264219f6Ssekiya }
264280b50a3Ssekiya 
26587586607Srumble static void
imc_bus_error(vaddr_t pc,uint32_t status,uint32_t ipending)26623347d39Smatt imc_bus_error(vaddr_t pc, uint32_t status, uint32_t ipending)
267280b50a3Ssekiya {
26834267609Stsutsui 
269280b50a3Ssekiya 	printf("bus error: cpu_stat %08x addr %08x, gio_stat %08x addr %08x\n",
270280b50a3Ssekiya 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRSTAT),
271280b50a3Ssekiya 			bus_space_read_4(isc.iot, isc.ioh, IMC_CPU_ERRADDR),
272280b50a3Ssekiya 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRSTAT),
273280b50a3Ssekiya 			bus_space_read_4(isc.iot, isc.ioh, IMC_GIO_ERRADDR) );
274280b50a3Ssekiya 	imc_bus_reset();
275280b50a3Ssekiya }
276280b50a3Ssekiya 
27787586607Srumble static void
imc_watchdog_reset(void)27823020fc3Ssekiya imc_watchdog_reset(void)
279280b50a3Ssekiya {
28034267609Stsutsui 
281280b50a3Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
282280b50a3Ssekiya }
28387586607Srumble 
28487586607Srumble static void
imc_watchdog_disable(void)28523020fc3Ssekiya imc_watchdog_disable(void)
28623020fc3Ssekiya {
28734267609Stsutsui 	uint32_t reg;
28823020fc3Ssekiya 
28923020fc3Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_WDOG, 0);
29023020fc3Ssekiya 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
2916feffff0Ssekiya 	reg &= ~(IMC_CPUCTRL0_WDOG);
29223020fc3Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
29323020fc3Ssekiya }
29423020fc3Ssekiya 
29587586607Srumble static void
imc_watchdog_enable(void)29623020fc3Ssekiya imc_watchdog_enable(void)
29723020fc3Ssekiya {
29834267609Stsutsui 	uint32_t reg;
29923020fc3Ssekiya 
30023020fc3Ssekiya 	/* enable watchdog and clear it */
30123020fc3Ssekiya 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
30223020fc3Ssekiya 	reg |= IMC_CPUCTRL0_WDOG;
30323020fc3Ssekiya 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
30423020fc3Ssekiya 	imc_watchdog_reset();
30523020fc3Ssekiya }
306a4d0bfd7Srumble 
307a4d0bfd7Srumble /* intended to be called from gio/gio.c only */
308a4d0bfd7Srumble int
imc_gio64_arb_config(int slot,uint32_t flags)309a4d0bfd7Srumble imc_gio64_arb_config(int slot, uint32_t flags)
310a4d0bfd7Srumble {
311a4d0bfd7Srumble 	uint32_t reg;
312a4d0bfd7Srumble 
313a4d0bfd7Srumble 	/* GIO_SLOT_EXP1 is unusable on Fullhouse */
314a4d0bfd7Srumble 	if (slot == GIO_SLOT_EXP1 && mach_subtype == MACH_SGI_IP22_FULLHOUSE)
31534267609Stsutsui 		return EINVAL;
316a4d0bfd7Srumble 
317a4d0bfd7Srumble 	/* GIO_SLOT_GFX is only usable on Fullhouse */
318a4d0bfd7Srumble 	if (slot == GIO_SLOT_GFX && mach_subtype != MACH_SGI_IP22_FULLHOUSE)
31934267609Stsutsui 		return EINVAL;
320a4d0bfd7Srumble 
321a4d0bfd7Srumble 	/* GIO_SLOT_GFX is always pipelined */
322a4d0bfd7Srumble 	if (slot == GIO_SLOT_GFX && (flags & GIO_ARB_NOPIPE))
32334267609Stsutsui 		return EINVAL;
324a4d0bfd7Srumble 
325a4d0bfd7Srumble 	/* IP20 does not support pipelining (XXX what about Indy?) */
326a4d0bfd7Srumble 	if (((flags & GIO_ARB_PIPE) || (flags & GIO_ARB_NOPIPE)) &&
327a4d0bfd7Srumble 	    mach_type == MACH_SGI_IP20)
32834267609Stsutsui 		return EINVAL;
329a4d0bfd7Srumble 
330a4d0bfd7Srumble 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_GIO64ARB);
331a4d0bfd7Srumble 
332a4d0bfd7Srumble 	if (flags & GIO_ARB_RT) {
333a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
334a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP0RT;
335a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
336a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP1RT;
337a4d0bfd7Srumble 		else if (slot == GIO_SLOT_GFX)
338a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_GRXRT;
339a4d0bfd7Srumble 	}
340a4d0bfd7Srumble 
341a4d0bfd7Srumble 	if (flags & GIO_ARB_MST) {
342a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
343a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP0MST;
344a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
345a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP1MST;
346a4d0bfd7Srumble 		else if (slot == GIO_SLOT_GFX)
347a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_GRXMST;
348a4d0bfd7Srumble 	}
349a4d0bfd7Srumble 
350a4d0bfd7Srumble 	if (flags & GIO_ARB_PIPE) {
351a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
352a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP0PIPE;
353a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
354a4d0bfd7Srumble 			reg |= IMC_GIO64ARB_EXP1PIPE;
355a4d0bfd7Srumble 	}
356a4d0bfd7Srumble 
357a4d0bfd7Srumble 	if (flags & GIO_ARB_LB) {
358a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
359a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP0RT;
360a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
361a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP1RT;
362a4d0bfd7Srumble 		else if (slot == GIO_SLOT_GFX)
363a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_GRXRT;
364a4d0bfd7Srumble 	}
365a4d0bfd7Srumble 
366a4d0bfd7Srumble 	if (flags & GIO_ARB_SLV) {
367a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
368a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP0MST;
369a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
370a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP1MST;
371a4d0bfd7Srumble 		else if (slot == GIO_SLOT_GFX)
372a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_GRXMST;
373a4d0bfd7Srumble 	}
374a4d0bfd7Srumble 
375a4d0bfd7Srumble 	if (flags & GIO_ARB_NOPIPE) {
376a4d0bfd7Srumble 		if (slot == GIO_SLOT_EXP0)
377a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP0PIPE;
378a4d0bfd7Srumble 		else if (slot == GIO_SLOT_EXP1)
379a4d0bfd7Srumble 			reg &= ~IMC_GIO64ARB_EXP1PIPE;
380a4d0bfd7Srumble 	}
381a4d0bfd7Srumble 
3822c7e4582Srumble 	if (flags & GIO_ARB_32BIT) {
3832c7e4582Srumble 		if (slot == GIO_SLOT_EXP0)
3842c7e4582Srumble 			reg &= ~IMC_GIO64ARB_EXP064;
3852c7e4582Srumble 		else if (slot == GIO_SLOT_EXP1)
3862c7e4582Srumble 			reg &= ~IMC_GIO64ARB_EXP164;
3872c7e4582Srumble 	}
3882c7e4582Srumble 
3892c7e4582Srumble 	if (flags & GIO_ARB_64BIT) {
3902c7e4582Srumble 		if (slot == GIO_SLOT_EXP0)
3912c7e4582Srumble 			reg |= IMC_GIO64ARB_EXP064;
3922c7e4582Srumble 		else if (slot == GIO_SLOT_EXP1)
3932c7e4582Srumble 			reg |= IMC_GIO64ARB_EXP164;
3942c7e4582Srumble 	}
3952c7e4582Srumble 
3962c7e4582Srumble 	if (flags & GIO_ARB_HPC2_32BIT)
3972c7e4582Srumble 		reg &= ~IMC_GIO64ARB_HPCEXP64;
3982c7e4582Srumble 
3992c7e4582Srumble 	if (flags & GIO_ARB_HPC2_64BIT)
4002c7e4582Srumble 		reg |= IMC_GIO64ARB_HPCEXP64;
4012c7e4582Srumble 
402a4d0bfd7Srumble 	bus_space_write_4(isc.iot, isc.ioh, IMC_GIO64ARB, reg);
403a4d0bfd7Srumble 
40434267609Stsutsui 	return 0;
405a4d0bfd7Srumble }
406a4d0bfd7Srumble 
407a4d0bfd7Srumble /*
408a4d0bfd7Srumble  * According to chapter 19 of the "IRIX Device Driver Programmer's Guide",
409a4d0bfd7Srumble  * some GIO devices, which do not drive all data lines, may cause false
410a4d0bfd7Srumble  * memory read parity errors on the SysAD bus. The workaround is to disable
411a4d0bfd7Srumble  * parity checking.
412a4d0bfd7Srumble  */
413a4d0bfd7Srumble void
imc_disable_sysad_parity(void)41434267609Stsutsui imc_disable_sysad_parity(void)
415a4d0bfd7Srumble {
416a4d0bfd7Srumble 	uint32_t reg;
417a4d0bfd7Srumble 
418a4d0bfd7Srumble 	if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
419a4d0bfd7Srumble 		return;
420a4d0bfd7Srumble 
421a4d0bfd7Srumble 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
422a4d0bfd7Srumble 	reg |= IMC_CPUCTRL0_NCHKMEMPAR;
423a4d0bfd7Srumble 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
424a4d0bfd7Srumble }
425a4d0bfd7Srumble 
426a4d0bfd7Srumble void
imc_enable_sysad_parity(void)42734267609Stsutsui imc_enable_sysad_parity(void)
428a4d0bfd7Srumble {
429a4d0bfd7Srumble 	uint32_t reg;
430a4d0bfd7Srumble 
431a4d0bfd7Srumble 	if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
432a4d0bfd7Srumble 		return;
433a4d0bfd7Srumble 
434a4d0bfd7Srumble 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
435a4d0bfd7Srumble 	reg &= ~IMC_CPUCTRL0_NCHKMEMPAR;
436a4d0bfd7Srumble 	bus_space_write_4(isc.iot, isc.ioh, IMC_CPUCTRL0, reg);
437a4d0bfd7Srumble }
438a4d0bfd7Srumble 
439a4d0bfd7Srumble int
imc_is_sysad_parity_enabled(void)44034267609Stsutsui imc_is_sysad_parity_enabled(void)
441a4d0bfd7Srumble {
442a4d0bfd7Srumble 	uint32_t reg;
443a4d0bfd7Srumble 
444a4d0bfd7Srumble 	if (mach_type != MACH_SGI_IP20 && mach_type != MACH_SGI_IP22)
44534267609Stsutsui 		return 0;
446a4d0bfd7Srumble 
447a4d0bfd7Srumble 	reg = bus_space_read_4(isc.iot, isc.ioh, IMC_CPUCTRL0);
448a4d0bfd7Srumble 
44934267609Stsutsui 	return reg & IMC_CPUCTRL0_NCHKMEMPAR;
450a4d0bfd7Srumble }
451