isa_machdep.c revision 1.7
11.7Stakemura/*	$NetBSD: isa_machdep.c,v 1.7 2000/09/12 02:12:20 takemura Exp $	*/
21.1Stakemura
31.1Stakemura/*
41.1Stakemura * Copyright (c) 1999, by UCHIYAMA Yasushi
51.1Stakemura * All rights reserved.
61.1Stakemura *
71.1Stakemura * Redistribution and use in source and binary forms, with or without
81.1Stakemura * modification, are permitted provided that the following conditions
91.1Stakemura * are met:
101.1Stakemura * 1. Redistributions of source code must retain the above copyright
111.1Stakemura *    notice, this list of conditions and the following disclaimer.
121.1Stakemura * 2. The name of the developer may NOT be used to endorse or promote products
131.1Stakemura *    derived from this software without specific prior written permission.
141.1Stakemura *
151.1Stakemura * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161.1Stakemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171.1Stakemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181.1Stakemura * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Stakemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Stakemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211.1Stakemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Stakemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Stakemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Stakemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Stakemura * SUCH DAMAGE.
261.1Stakemura *
271.1Stakemura */
281.1Stakemura#include <sys/param.h>
291.1Stakemura#include <sys/systm.h>
301.1Stakemura#include <sys/device.h>
311.1Stakemura
321.1Stakemura#include <machine/bus.h>
331.1Stakemura
341.1Stakemura#include <dev/isa/isavar.h>
351.1Stakemura#include <dev/isa/isareg.h>
361.1Stakemura
371.1Stakemura#include <machine/platid.h>
381.1Stakemura#include <machine/platid_mask.h>
391.1Stakemura
401.5Ssato#include <hpcmips/hpcmips/machdep.h>
411.1Stakemura#include <hpcmips/vr/vripreg.h>
421.1Stakemura#include <hpcmips/vr/vripvar.h>
431.1Stakemura#include <hpcmips/vr/vrgiureg.h>
441.1Stakemura
451.1Stakemura#include "locators.h"
461.1Stakemura
471.4Ssato#define VRISADEBUG
481.4Ssato
491.4Ssato#ifdef VRISADEBUG
501.4Ssato#ifndef VRISADEBUG_CONF
511.4Ssato#define VRISADEBUG_CONF 0
521.4Ssato#endif /* VRISADEBUG_CONF */
531.4Ssatoint vrisa_debug = VRISADEBUG_CONF;
541.4Ssato#define DPRINTF(arg) if (vrisa_debug) printf arg;
551.4Ssato#define DBITDISP32(mask) if (vrisa_debug) bitdisp32(mask);
561.5Ssato#define VPRINTF(arg) if (hpcmips_verbose || vrisa_debug) printf arg;
571.4Ssato#else /* VRISADEBUG */
581.4Ssato#define DPRINTF(arg)
591.4Ssato#define DBITDISP32(mask)
601.5Ssato#define VPRINTF(arg) if (hpcmips_verbose) printf arg;
611.4Ssato#endif /* VRISADEBUG */
621.4Ssato
631.1Stakemuraint	vrisabprint __P((void*, const char*));
641.1Stakemuraint	vrisabmatch __P((struct device*, struct cfdata*, void*));
651.1Stakemuravoid	vrisabattach __P((struct device*, struct device*, void*));
661.1Stakemura
671.1Stakemurastruct vrisab_softc {
681.1Stakemura	struct device sc_dev;
691.1Stakemura	vrgiu_chipset_tag_t sc_gc;
701.1Stakemura	vrgiu_function_tag_t sc_gf;
711.1Stakemura	int sc_intr_map[MAX_GPIO_INOUT]; /* ISA <-> GIU inerrupt line mapping */
721.3Stakemura	struct hpcmips_isa_chipset sc_isa_ic;
731.1Stakemura};
741.1Stakemura
751.1Stakemurastruct cfattach vrisab_ca = {
761.1Stakemura	sizeof(struct vrisab_softc), vrisabmatch, vrisabattach
771.1Stakemura};
781.1Stakemura
791.1Stakemura#ifdef DEBUG_FIND_PCIC
801.1Stakemura#include <mips/cpuregs.h>
811.1Stakemura#warning DEBUG_FIND_PCIC
821.1Stakemurastatic void __find_pcic __P((void));
831.1Stakemura#endif
841.1Stakemura
851.1Stakemuraint
861.1Stakemuravrisabmatch(parent, match, aux)
871.1Stakemura	struct device *parent;
881.1Stakemura	struct cfdata *match;
891.1Stakemura	void *aux;
901.1Stakemura{
911.1Stakemura	struct gpbus_attach_args *gpa = aux;
921.1Stakemura	platid_mask_t mask;
931.1Stakemura
941.1Stakemura	if (strcmp(gpa->gpa_busname, match->cf_driver->cd_name))
951.1Stakemura		return 0;
961.1Stakemura	if (match->cf_loc[VRISABIFCF_PLATFORM] == VRISABIFCF_PLATFORM_DEFAULT)
971.1Stakemura		return 1;
981.1Stakemura	mask = PLATID_DEREF(match->cf_loc[VRISABIFCF_PLATFORM]);
991.1Stakemura	if (platid_match(&platid, &mask))
1001.1Stakemura		return 2;
1011.1Stakemura	return 0;
1021.1Stakemura}
1031.1Stakemura
1041.1Stakemuravoid
1051.1Stakemuravrisabattach(parent, self, aux)
1061.1Stakemura	struct device *parent;
1071.1Stakemura	struct device *self;
1081.1Stakemura	void *aux;
1091.1Stakemura{
1101.1Stakemura	struct gpbus_attach_args *gpa = aux;
1111.1Stakemura	struct vrgiu_softc *chipset;
1121.1Stakemura	struct vrisab_softc *sc = (void*)self;
1131.1Stakemura	struct isabus_attach_args iba;
1141.1Stakemura	bus_addr_t offset;
1151.1Stakemura	int i;
1161.1Stakemura
1171.1Stakemura	sc->sc_gc = chipset = gpa->gpa_gc;
1181.1Stakemura	sc->sc_gf = gpa->gpa_gf;
1191.3Stakemura	sc->sc_isa_ic.ic_sc = sc;
1201.1Stakemura
1211.1Stakemura	iba.iba_busname = "isa";
1221.3Stakemura	iba.iba_ic	= &sc->sc_isa_ic;
1231.1Stakemura	iba.iba_dmat    = 0; /* XXX not yet */
1241.1Stakemura
1251.1Stakemura	/* Allocate ISA memory space */
1261.1Stakemura	iba.iba_memt    = hpcmips_alloc_bus_space_tag();
1271.1Stakemura	strcpy(iba.iba_memt->t_name, "ISA mem");
1281.1Stakemura	offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAMEMOFFSET];
1291.1Stakemura	iba.iba_memt->t_base = VR_ISA_MEM_BASE + offset;
1301.1Stakemura	iba.iba_memt->t_size = VR_ISA_MEM_SIZE - offset;
1311.1Stakemura	hpcmips_init_bus_space_extent(iba.iba_memt);
1321.1Stakemura
1331.1Stakemura	/* Allocate ISA port space */
1341.1Stakemura	iba.iba_iot     = hpcmips_alloc_bus_space_tag();
1351.1Stakemura	strcpy(iba.iba_iot->t_name, "ISA port");
1361.1Stakemura	/* Platform dependent setting. */
1371.1Stakemura	offset = sc->sc_dev.dv_cfdata->cf_loc[VRISABIFCF_ISAPORTOFFSET];
1381.1Stakemura	iba.iba_iot->t_base = VR_ISA_PORT_BASE + offset;
1391.1Stakemura	iba.iba_iot->t_size = VR_ISA_PORT_SIZE - offset;
1401.1Stakemura
1411.1Stakemura	hpcmips_init_bus_space_extent(iba.iba_iot);
1421.1Stakemura
1431.1Stakemura#ifdef DEBUG_FIND_PCIC
1441.1Stakemura#warning DEBUG_FIND_PCIC
1451.1Stakemura	__find_pcic();
1461.1Stakemura#else
1471.1Stakemura	/* Initialize ISA IRQ <-> GPIO mapping */
1481.1Stakemura	for (i = 0; i < MAX_GPIO_INOUT; i++)
1491.1Stakemura		sc->sc_intr_map[i] = -1;
1501.1Stakemura	printf (":ISA port %#x-%#x mem %#x-%#x\n",
1511.1Stakemura		iba.iba_iot->t_base, iba.iba_iot->t_base + iba.iba_iot->t_size,
1521.7Stakemura		iba.iba_memt->t_base, iba.iba_memt->t_base + iba.iba_memt->t_size);
1531.1Stakemura	config_found(self, &iba, vrisabprint);
1541.1Stakemura#endif
1551.1Stakemura}
1561.1Stakemura
1571.1Stakemuraint
1581.1Stakemuravrisabprint(aux, pnp)
1591.1Stakemura	void *aux;
1601.1Stakemura	const char *pnp;
1611.1Stakemura{
1621.1Stakemura	if (pnp)
1631.1Stakemura		return (QUIET);
1641.1Stakemura	return (UNCONF);
1651.1Stakemura}
1661.1Stakemura
1671.1Stakemuravoid
1681.1Stakemuraisa_attach_hook(parent, self, iba)
1691.1Stakemura	struct device *parent, *self;
1701.1Stakemura	struct isabus_attach_args *iba;
1711.1Stakemura{
1721.6Scgd}
1731.6Scgd
1741.6Scgdconst struct evcnt *
1751.6Scgdisa_intr_evcnt(isa_chipset_tag_t ic, int irq)
1761.6Scgd{
1771.6Scgd
1781.6Scgd	/* XXX for now, no evcnt parent reported */
1791.6Scgd	return NULL;
1801.1Stakemura}
1811.1Stakemura
1821.1Stakemuravoid *
1831.2Stakemuraisa_intr_establish(ic, intr, type, level, ih_fun, ih_arg)
1841.1Stakemura	isa_chipset_tag_t ic;
1851.2Stakemura	int intr;
1861.1Stakemura	int type;  /* XXX not yet */
1871.1Stakemura	int level;  /* XXX not yet */
1881.1Stakemura	int (*ih_fun) __P((void*));
1891.1Stakemura	void *ih_arg;
1901.1Stakemura{
1911.3Stakemura	struct vrisab_softc *sc = ic->ic_sc;
1921.3Stakemura	int port, irq, mode;
1931.2Stakemura
1941.2Stakemura	/*
1951.2Stakemura	 * 'intr' encoding:
1961.2Stakemura	 *
1971.2Stakemura	 * 0x0000000f ISA IRQ#
1981.3Stakemura	 * 0x00ff0000 GPIO port#
1991.2Stakemura	 * 0x01000000 interrupt signal hold/through	(1:hold/0:though)
2001.2Stakemura	 * 0x02000000 interrupt detection level		(1:low /0:high	)
2011.2Stakemura	 * 0x04000000 interrupt detection trigger	(1:edge/0:level	)
2021.2Stakemura	 */
2031.2Stakemura#define INTR_IRQ(i)	(((i)>> 0) & 0x0f)
2041.2Stakemura#define INTR_PORT(i)	(((i)>>16) & 0xff)
2051.2Stakemura#define INTR_MODE(i)	(((i)>>24) & 0x07)
2061.2Stakemura	static int intr_modes[8] = {
2071.2Stakemura		VRGIU_INTR_LEVEL_HIGH_THROUGH,
2081.2Stakemura		VRGIU_INTR_LEVEL_HIGH_HOLD,
2091.2Stakemura		VRGIU_INTR_LEVEL_LOW_THROUGH,
2101.2Stakemura		VRGIU_INTR_LEVEL_LOW_HOLD,
2111.2Stakemura		VRGIU_INTR_EDGE_THROUGH,
2121.2Stakemura		VRGIU_INTR_EDGE_HOLD,
2131.2Stakemura		VRGIU_INTR_EDGE_THROUGH,
2141.2Stakemura		VRGIU_INTR_EDGE_HOLD,
2151.2Stakemura	};
2161.4Ssato#ifdef VRISADEBUG
2171.2Stakemura	static char* intr_mode_names[8] = {
2181.2Stakemura		"level high through",
2191.2Stakemura		"level high hold",
2201.2Stakemura		"level low through",
2211.2Stakemura		"level low hold",
2221.2Stakemura		"edge through",
2231.2Stakemura		"edge hold",
2241.2Stakemura		"edge through",
2251.2Stakemura		"edge hold",
2261.2Stakemura	};
2271.4Ssato#endif /* VRISADEBUG */
2281.1Stakemura	/*
2291.1Stakemura	 * ISA IRQ <-> GPIO port mapping
2301.1Stakemura	 */
2311.2Stakemura	irq = INTR_IRQ(intr);
2321.3Stakemura	if (sc->sc_intr_map[irq] != -1) {
2331.3Stakemura		/* already mapped */
2341.3Stakemura		intr = sc->sc_intr_map[irq];
2351.2Stakemura	} else {
2361.3Stakemura		/* not mapped yet */
2371.3Stakemura		sc->sc_intr_map[irq] = intr; /* Register it */
2381.1Stakemura	}
2391.3Stakemura	mode = INTR_MODE(intr);
2401.3Stakemura	port = INTR_PORT(intr);
2411.3Stakemura
2421.5Ssato	VPRINTF(("ISA IRQ %d -> GPIO port %d, %s\n",
2431.4Ssato	       irq, port, intr_mode_names[mode]));
2441.3Stakemura
2451.1Stakemura	/* Call Vr routine */
2461.2Stakemura	return sc->sc_gf->gf_intr_establish(sc->sc_gc, port,
2471.3Stakemura					    intr_modes[mode],
2481.2Stakemura					    level, ih_fun, ih_arg);
2491.1Stakemura}
2501.1Stakemura
2511.1Stakemuravoid
2521.1Stakemuraisa_intr_disestablish(ic, arg)
2531.1Stakemura	isa_chipset_tag_t ic;
2541.1Stakemura	void *arg;
2551.1Stakemura{
2561.3Stakemura	struct vrisab_softc *sc = ic->ic_sc;
2571.1Stakemura	/* Call Vr routine */
2581.1Stakemura	sc->sc_gf->gf_intr_disestablish(sc->sc_gc, arg);
2591.1Stakemura}
2601.1Stakemura
2611.1Stakemuraint
2621.1Stakemuraisa_intr_alloc(ic, mask, type, irq)
2631.1Stakemura	isa_chipset_tag_t ic;
2641.1Stakemura	int mask;
2651.1Stakemura	int type;
2661.1Stakemura	int *irq;
2671.1Stakemura{
2681.1Stakemura	/* XXX not coded yet. this is temporary XXX */
2691.4Ssato	DPRINTF(("isa_intr_alloc:"));
2701.4Ssato	DBITDISP32(mask);
2711.3Stakemura	*irq = (ffs(mask) -1); /* XXX */
2721.1Stakemura	return 0;
2731.1Stakemura}
2741.1Stakemura
2751.1Stakemura#ifdef DEBUG_FIND_PCIC
2761.1Stakemura#warning DEBUG_FIND_PCIC
2771.1Stakemurastatic void
2781.1Stakemura__find_pcic(void)
2791.1Stakemura{
2801.1Stakemura	int i, j, step, found;
2811.1Stakemura	u_int32_t addr;
2821.1Stakemura	u_int8_t reg;
2831.1Stakemura	int __read_revid (u_int32_t port)
2841.1Stakemura		{
2851.1Stakemura			addr = MIPS_PHYS_TO_KSEG1(i + port);
2861.1Stakemura			printf("%#x\r", i);
2871.1Stakemura			for (found = 0, j = 0; j < 0x100; j += 0x40) {
2881.1Stakemura				*((volatile u_int8_t*)addr) = j;
2891.1Stakemura				reg = *((volatile u_int8_t*)(addr + 1));
2901.1Stakemura#ifdef DEBUG_FIND_PCIC_I82365SL_ONLY
2911.1Stakemura				if (reg == 0x82 || reg == 0x83) {
2921.1Stakemura#else
2931.1Stakemura				if ((reg & 0xc0) == 0x80) {
2941.1Stakemura#endif
2951.1Stakemura					found++;
2961.1Stakemura				}
2971.1Stakemura			}
2981.1Stakemura			if (found)
2991.1Stakemura				printf("\nfound %d socket at %#x (base from %#x)\n", found, addr,
3001.1Stakemura				       i + port - VR_ISA_PORT_BASE);
3011.1Stakemura		};
3021.1Stakemura	step = 0x1000000;
3031.1Stakemura	printf("\nFinding PCIC. Trying ISA port %#x-%#x step %#x\n",
3041.1Stakemura	       VR_ISA_PORT_BASE, VR_ISA_PORT_BASE + VR_ISA_PORT_SIZE, step);
3051.1Stakemura	for (i = VR_ISA_PORT_BASE; i < VR_ISA_PORT_BASE+VR_ISA_PORT_SIZE; i+= step) {
3061.1Stakemura		__read_revid (0x3e0);
3071.1Stakemura		__read_revid (0x3e2);
3081.1Stakemura	}
3091.1Stakemura}
3101.1Stakemura#endif
311