pcib.c revision 1.10
11.10Sitojun/*	$NetBSD: pcib.c,v 1.10 2004/04/23 21:13:05 itojun 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.10Sitojun__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.10 2004/04/23 21:13:05 itojun 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.8Stsutsui#include <machine/autoconf.h>
401.2Ssoren#include <machine/intr.h>
411.1Ssoren
421.1Ssoren#include <dev/pci/pcivar.h>
431.1Ssoren#include <dev/pci/pcireg.h>
441.2Ssoren#include <dev/pci/pcidevs.h>
451.1Ssoren
461.2Ssoren#include <dev/isa/isareg.h>
471.1Ssoren
481.1Ssorenstatic int	pcib_match(struct device *, struct cfdata *, void *);
491.1Ssorenstatic void	pcib_attach(struct device *, struct device *, void *);
501.2Ssorenstatic int	icu_intr(void *);
511.1Ssoren
521.6SthorpejCFATTACH_DECL(pcib, sizeof(struct device),
531.6Sthorpej    pcib_match, pcib_attach, NULL, NULL);
541.1Ssoren
551.9Stsutsuistatic struct cobalt_intrhand icu[IO_ICUSIZE];
561.2Ssoren
571.1Ssorenstatic int
581.1Ssorenpcib_match(parent, match, aux)
591.1Ssoren	struct device *parent;
601.1Ssoren	struct cfdata *match;
611.1Ssoren	void *aux;
621.1Ssoren{
631.1Ssoren	struct pci_attach_args *pa = aux;
641.1Ssoren
651.1Ssoren	if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH) &&
661.1Ssoren	    (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_ISA))
671.1Ssoren		return 1;
681.1Ssoren
691.1Ssoren	return 0;
701.1Ssoren}
711.1Ssoren
721.1Ssorenstatic void
731.1Ssorenpcib_attach(parent, self, aux)
741.1Ssoren	struct device *parent;
751.1Ssoren	struct device *self;
761.1Ssoren	void *aux;
771.1Ssoren{
781.1Ssoren	struct pci_attach_args *pa = aux;
791.1Ssoren	char devinfo[256];
801.1Ssoren
811.10Sitojun	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
821.1Ssoren	printf("\n%s: %s, rev %d\n", self->dv_xname, devinfo,
831.1Ssoren					PCI_REVISION(pa->pa_class));
841.2Ssoren
851.2Ssoren	/*
861.2Ssoren	 * Initialize ICU. Since we block all these interrupts with
871.2Ssoren	 * splbio(), we can just enable all of them all the time here.
881.2Ssoren	 */
891.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1) = 0x10;
901.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU1+1) = 0xff;
911.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2) = 0x10;
921.2Ssoren	*(volatile u_int8_t *)MIPS_PHYS_TO_KSEG1(0x10000000 + IO_ICU2+1) = 0xff;
931.2Ssoren	wbflush();
941.2Ssoren
951.2Ssoren	cpu_intr_establish(4, IPL_NONE, icu_intr, NULL);
961.2Ssoren}
971.2Ssoren
981.8Stsutsuivoid *
991.2Ssorenicu_intr_establish(irq, type, level, func, arg)
1001.8Stsutsui	int irq;
1011.8Stsutsui	int type;
1021.8Stsutsui	int level;
1031.8Stsutsui	int (*func)(void *);
1041.8Stsutsui	void *arg;
1051.2Ssoren{
1061.2Ssoren	int i;
1071.2Ssoren
1081.4Saugustss	for (i = 0; i < IO_ICUSIZE; i++) {
1091.9Stsutsui		if (icu[i].ih_func == NULL) {
1101.4Saugustss			icu[i].cookie_type = COBALT_COOKIE_TYPE_ICU;
1111.9Stsutsui			icu[i].ih_func = func;
1121.9Stsutsui			icu[i].ih_arg = arg;
1131.4Saugustss			return &icu[i];
1141.4Saugustss		}
1151.2Ssoren	}
1161.2Ssoren
1171.4Saugustss	panic("too many IRQs");
1181.3Saugustss}
1191.3Saugustss
1201.3Saugustssvoid
1211.3Saugustssicu_intr_disestablish(cookie)
1221.3Saugustss	void *cookie;
1231.3Saugustss{
1241.9Stsutsui	struct cobalt_intrhand *ih = cookie;
1251.3Saugustss
1261.9Stsutsui	if (ih->cookie_type == COBALT_COOKIE_TYPE_ICU) {
1271.9Stsutsui		ih->ih_func = NULL;
1281.9Stsutsui		ih->ih_arg = NULL;
1291.3Saugustss	}
1301.2Ssoren}
1311.2Ssoren
1321.2Ssorenint
1331.2Ssorenicu_intr(arg)
1341.2Ssoren	void *arg;
1351.2Ssoren{
1361.2Ssoren	int i;
1371.2Ssoren
1381.2Ssoren	for (i = 0; i < IO_ICUSIZE; i++) {
1391.9Stsutsui		if (icu[i].ih_func == NULL)
1401.2Ssoren			return 0;
1411.2Ssoren
1421.9Stsutsui		(*icu[i].ih_func)(icu[i].ih_arg);
1431.2Ssoren	}
1441.2Ssoren
1451.2Ssoren	return 0;
1461.1Ssoren}
147