pcib.c revision 1.6
11.6Sthorpej/*	$NetBSD: pcib.c,v 1.6 2002/10/02 05:07:44 thorpej Exp $	*/
21.1Ssoren
31.1Ssoren/*
41.1Ssoren * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
51.1Ssoren *
61.1Ssoren * Redistribution and use in source and binary forms, with or without
71.1Ssoren * modification, are permitted provided that the following conditions
81.1Ssoren * are met:
91.1Ssoren * 1. Redistributions of source code must retain the above copyright
101.1Ssoren *    notice, this list of conditions, and the following disclaimer.
111.1Ssoren * 2. Redistributions in binary form must reproduce the above copyright
121.1Ssoren *    notice, this list of conditions and the following disclaimer in the
131.1Ssoren *    documentation and/or other materials provided with the distribution.
141.1Ssoren *
151.1Ssoren * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161.1Ssoren * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171.1Ssoren * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181.1Ssoren * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191.1Ssoren * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201.1Ssoren * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211.1Ssoren * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221.1Ssoren * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231.1Ssoren * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241.1Ssoren * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251.1Ssoren * SUCH DAMAGE.
261.1Ssoren */
271.1Ssoren
281.1Ssoren#include <sys/types.h>
291.1Ssoren#include <sys/param.h>
301.1Ssoren#include <sys/systm.h>
311.1Ssoren#include <sys/device.h>
321.2Ssoren#include <sys/malloc.h>
331.1Ssoren
341.2Ssoren#include <machine/cpu.h>
351.1Ssoren#include <machine/bus.h>
361.2Ssoren#include <machine/autoconf.h>
371.2Ssoren#include <machine/intr.h>
381.3Saugustss#include <machine/intr_machdep.h>
391.1Ssoren
401.1Ssoren#include <dev/pci/pcivar.h>
411.1Ssoren#include <dev/pci/pcireg.h>
421.2Ssoren#include <dev/pci/pcidevs.h>
431.1Ssoren
441.2Ssoren#include <dev/isa/isareg.h>
451.1Ssoren
461.1Ssorenstatic int	pcib_match(struct device *, struct cfdata *, void *);
471.1Ssorenstatic void	pcib_attach(struct device *, struct device *, void *);
481.2Ssorenstatic int	icu_intr(void *);
491.1Ssoren
501.6SthorpejCFATTACH_DECL(pcib, sizeof(struct device),
511.6Sthorpej    pcib_match, pcib_attach, NULL, NULL);
521.1Ssoren
531.3Saugustssstatic struct cobalt_intr icu[IO_ICUSIZE];
541.2Ssoren
551.1Ssorenstatic int
561.1Ssorenpcib_match(parent, match, aux)
571.1Ssoren	struct device *parent;
581.1Ssoren	struct cfdata *match;
591.1Ssoren	void *aux;
601.1Ssoren{
611.1Ssoren	struct pci_attach_args *pa = aux;
621.1Ssoren
631.1Ssoren	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) &&
641.1Ssoren	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA))
651.1Ssoren		return 1;
661.1Ssoren
671.1Ssoren	return 0;
681.1Ssoren}
691.1Ssoren
701.1Ssorenstatic void
711.1Ssorenpcib_attach(parent, self, aux)
721.1Ssoren	struct device *parent;
731.1Ssoren	struct device *self;
741.1Ssoren	void *aux;
751.1Ssoren{
761.1Ssoren	struct pci_attach_args *pa = aux;
771.1Ssoren	char devinfo[256];
781.1Ssoren
791.1Ssoren	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
801.1Ssoren	printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo,
811.1Ssoren					PCI_REVISION(pa->pa_class));
821.2Ssoren
831.2Ssoren	/*
841.2Ssoren	 * Initialize ICU. Since we block all these interrupts with
851.2Ssoren	 * splbio(), we can just enable all of them all the time here.
861.2Ssoren	 */
871.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10;
881.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff;
891.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10;
901.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff;
911.2Ssoren	wbflush();
921.2Ssoren
931.2Ssoren	cpu_intr_establish(4, IPL_NONE, icu_intr, NULL);
941.2Ssoren}
951.2Ssoren
961.2Ssorenvoid *
971.2Ssorenicu_intr_establish(irq, type, level, func, arg)
981.2Ssoren        int irq;
991.2Ssoren        int type;
1001.2Ssoren        int level;
1011.2Ssoren        int (*func)(void *);
1021.2Ssoren        void *arg;
1031.2Ssoren{
1041.2Ssoren	int i;
1051.2Ssoren
1061.4Saugustss	for (i = 0; i < IO_ICUSIZE; i++) {
1071.4Saugustss		if (icu[i].func == NULL) {
1081.4Saugustss			icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU;
1091.4Saugustss			icu[i].func = func;
1101.4Saugustss			icu[i].arg = arg;
1111.4Saugustss			return &icu[i];
1121.4Saugustss		}
1131.2Ssoren	}
1141.2Ssoren
1151.4Saugustss	panic("too many IRQs");
1161.3Saugustss}
1171.3Saugustss
1181.3Saugustssvoid
1191.3Saugustssicu_intr_disestablish(cookie)
1201.3Saugustss	void *cookie;
1211.3Saugustss{
1221.3Saugustss	struct cobalt_intr *p = cookie;
1231.3Saugustss
1241.3Saugustss	if (p->cookie_type == COBALT_COOKIE_TYPE_ICU) {
1251.3Saugustss		p->func = NULL;
1261.3Saugustss		p->arg = NULL;
1271.3Saugustss	}
1281.2Ssoren}
1291.2Ssoren
1301.2Ssorenint
1311.2Ssorenicu_intr(arg)
1321.2Ssoren	void *arg;
1331.2Ssoren{
1341.2Ssoren	int i;
1351.2Ssoren
1361.2Ssoren	for (i = 0; i < IO_ICUSIZE; i++) {
1371.2Ssoren		if (icu[i].func == NULL)
1381.2Ssoren			return 0;
1391.2Ssoren
1401.2Ssoren		(*icu[i].func)(icu[i].arg);
1411.2Ssoren	}
1421.2Ssoren
1431.2Ssoren	return 0;
1441.1Ssoren}
145