pcib.c revision 1.7
11.7Slukem/*	$NetBSD: pcib.c,v 1.7 2003/07/15 01:29:23 lukem 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.7Slukem
281.7Slukem#include <sys/cdefs.h>
291.7Slukem__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.7 2003/07/15 01:29:23 lukem Exp $");
301.1Ssoren
311.1Ssoren#include <sys/types.h>
321.1Ssoren#include <sys/param.h>
331.1Ssoren#include <sys/systm.h>
341.1Ssoren#include <sys/device.h>
351.2Ssoren#include <sys/malloc.h>
361.1Ssoren
371.2Ssoren#include <machine/cpu.h>
381.1Ssoren#include <machine/bus.h>
391.2Ssoren#include <machine/autoconf.h>
401.2Ssoren#include <machine/intr.h>
411.3Saugustss#include <machine/intr_machdep.h>
421.1Ssoren
431.1Ssoren#include <dev/pci/pcivar.h>
441.1Ssoren#include <dev/pci/pcireg.h>
451.2Ssoren#include <dev/pci/pcidevs.h>
461.1Ssoren
471.2Ssoren#include <dev/isa/isareg.h>
481.1Ssoren
491.1Ssorenstatic int	pcib_match(struct device *, struct cfdata *, void *);
501.1Ssorenstatic void	pcib_attach(struct device *, struct device *, void *);
511.2Ssorenstatic int	icu_intr(void *);
521.1Ssoren
531.6SthorpejCFATTACH_DECL(pcib, sizeof(struct device),
541.6Sthorpej    pcib_match, pcib_attach, NULL, NULL);
551.1Ssoren
561.3Saugustssstatic struct cobalt_intr icu[IO_ICUSIZE];
571.2Ssoren
581.1Ssorenstatic int
591.1Ssorenpcib_match(parent, match, aux)
601.1Ssoren	struct device *parent;
611.1Ssoren	struct cfdata *match;
621.1Ssoren	void *aux;
631.1Ssoren{
641.1Ssoren	struct pci_attach_args *pa = aux;
651.1Ssoren
661.1Ssoren	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) &&
671.1Ssoren	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA))
681.1Ssoren		return 1;
691.1Ssoren
701.1Ssoren	return 0;
711.1Ssoren}
721.1Ssoren
731.1Ssorenstatic void
741.1Ssorenpcib_attach(parent, self, aux)
751.1Ssoren	struct device *parent;
761.1Ssoren	struct device *self;
771.1Ssoren	void *aux;
781.1Ssoren{
791.1Ssoren	struct pci_attach_args *pa = aux;
801.1Ssoren	char devinfo[256];
811.1Ssoren
821.1Ssoren	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
831.1Ssoren	printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo,
841.1Ssoren					PCI_REVISION(pa->pa_class));
851.2Ssoren
861.2Ssoren	/*
871.2Ssoren	 * Initialize ICU. Since we block all these interrupts with
881.2Ssoren	 * splbio(), we can just enable all of them all the time here.
891.2Ssoren	 */
901.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10;
911.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff;
921.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10;
931.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff;
941.2Ssoren	wbflush();
951.2Ssoren
961.2Ssoren	cpu_intr_establish(4, IPL_NONE, icu_intr, NULL);
971.2Ssoren}
981.2Ssoren
991.2Ssorenvoid *
1001.2Ssorenicu_intr_establish(irq, type, level, func, arg)
1011.2Ssoren        int irq;
1021.2Ssoren        int type;
1031.2Ssoren        int level;
1041.2Ssoren        int (*func)(void *);
1051.2Ssoren        void *arg;
1061.2Ssoren{
1071.2Ssoren	int i;
1081.2Ssoren
1091.4Saugustss	for (i = 0; i < IO_ICUSIZE; i++) {
1101.4Saugustss		if (icu[i].func == NULL) {
1111.4Saugustss			icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU;
1121.4Saugustss			icu[i].func = func;
1131.4Saugustss			icu[i].arg = arg;
1141.4Saugustss			return &icu[i];
1151.4Saugustss		}
1161.2Ssoren	}
1171.2Ssoren
1181.4Saugustss	panic("too many IRQs");
1191.3Saugustss}
1201.3Saugustss
1211.3Saugustssvoid
1221.3Saugustssicu_intr_disestablish(cookie)
1231.3Saugustss	void *cookie;
1241.3Saugustss{
1251.3Saugustss	struct cobalt_intr *p = cookie;
1261.3Saugustss
1271.3Saugustss	if (p->cookie_type == COBALT_COOKIE_TYPE_ICU) {
1281.3Saugustss		p->func = NULL;
1291.3Saugustss		p->arg = NULL;
1301.3Saugustss	}
1311.2Ssoren}
1321.2Ssoren
1331.2Ssorenint
1341.2Ssorenicu_intr(arg)
1351.2Ssoren	void *arg;
1361.2Ssoren{
1371.2Ssoren	int i;
1381.2Ssoren
1391.2Ssoren	for (i = 0; i < IO_ICUSIZE; i++) {
1401.2Ssoren		if (icu[i].func == NULL)
1411.2Ssoren			return 0;
1421.2Ssoren
1431.2Ssoren		(*icu[i].func)(icu[i].arg);
1441.2Ssoren	}
1451.2Ssoren
1461.2Ssoren	return 0;
1471.1Ssoren}
148