Home | History | Annotate | Line # | Download | only in pci
aapic.c revision 1.2
      1  1.2  itojun /* 	$NetBSD: aapic.c,v 1.2 2004/04/23 21:13:06 itojun Exp $	*/
      2  1.1    fvdl 
      3  1.1    fvdl #include <sys/cdefs.h>
      4  1.2  itojun __KERNEL_RCSID(0, "$NetBSD: aapic.c,v 1.2 2004/04/23 21:13:06 itojun Exp $");
      5  1.1    fvdl 
      6  1.1    fvdl #include <sys/param.h>
      7  1.1    fvdl #include <sys/systm.h>
      8  1.1    fvdl #include <sys/kernel.h>
      9  1.1    fvdl #include <sys/device.h>
     10  1.1    fvdl 
     11  1.1    fvdl #include <dev/pci/pcireg.h>
     12  1.1    fvdl #include <dev/pci/pcivar.h>
     13  1.1    fvdl #include <dev/pci/pcidevs.h>
     14  1.1    fvdl 
     15  1.1    fvdl #include <arch/x86/pci/amd8131reg.h>
     16  1.1    fvdl 
     17  1.1    fvdl static int	aapic_match __P((struct device *, struct cfdata *, void *));
     18  1.1    fvdl static void	aapic_attach __P((struct device *, struct device *, void *));
     19  1.1    fvdl 
     20  1.1    fvdl struct aapic_softc {
     21  1.1    fvdl 	struct device sc_dev;
     22  1.1    fvdl };
     23  1.1    fvdl 
     24  1.1    fvdl CFATTACH_DECL(aapic, sizeof(struct aapic_softc),
     25  1.1    fvdl     aapic_match, aapic_attach, NULL, NULL);
     26  1.1    fvdl 
     27  1.1    fvdl static int
     28  1.1    fvdl aapic_match(parent, match, aux)
     29  1.1    fvdl 	struct device *parent;
     30  1.1    fvdl 	struct cfdata *match;
     31  1.1    fvdl 	void *aux;
     32  1.1    fvdl {
     33  1.1    fvdl 	struct pci_attach_args *pa = aux;
     34  1.1    fvdl 
     35  1.1    fvdl 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
     36  1.1    fvdl 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PCIX8131_APIC)
     37  1.1    fvdl 		return (1);
     38  1.1    fvdl 
     39  1.1    fvdl 	return (0);
     40  1.1    fvdl }
     41  1.1    fvdl 
     42  1.1    fvdl static void
     43  1.1    fvdl aapic_attach(parent, self, aux)
     44  1.1    fvdl 	struct device *parent, *self;
     45  1.1    fvdl 	void *aux;
     46  1.1    fvdl {
     47  1.1    fvdl 	struct pci_attach_args *pa = aux;
     48  1.1    fvdl 	char devinfo[256];
     49  1.1    fvdl 	int bus, dev, func, rev;
     50  1.1    fvdl 	pcitag_t tag;
     51  1.1    fvdl 	pcireg_t reg;
     52  1.1    fvdl 
     53  1.2  itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
     54  1.1    fvdl 	rev = PCI_REVISION(pa->pa_class);
     55  1.1    fvdl 	printf(": %s (rev. 0x%02x)\n", devinfo, rev);
     56  1.1    fvdl 
     57  1.1    fvdl 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL);
     58  1.1    fvdl 	if ((reg & AMD8131_IOAEN) == 0) {
     59  1.1    fvdl 		reg |= AMD8131_IOAEN;
     60  1.1    fvdl 		pci_conf_write(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL, reg);
     61  1.1    fvdl 	}
     62  1.1    fvdl 
     63  1.1    fvdl 	/*
     64  1.1    fvdl 	 * Work around erratum #22 for A0 and B0 revisions.
     65  1.1    fvdl 	 */
     66  1.1    fvdl 	if (rev == 0x01 || rev == 0x11) {
     67  1.1    fvdl 		pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func);
     68  1.1    fvdl 		func = 0;
     69  1.1    fvdl 		tag = pci_make_tag(pa->pa_pc, bus, dev, func);
     70  1.1    fvdl 		reg = pci_conf_read(pa->pa_pc, tag, AMD8131_PCIX_MISC);
     71  1.1    fvdl 		reg &= ~0x00000001;
     72  1.1    fvdl 		pci_conf_write(pa->pa_pc, tag, AMD8131_PCIX_MISC, reg);
     73  1.1    fvdl 	}
     74  1.1    fvdl }
     75