aapic.c revision 1.3 1 1.3 fvdl /* $NetBSD: aapic.c,v 1.3 2005/01/13 23:40:01 fvdl Exp $ */
2 1.1 fvdl
3 1.1 fvdl #include <sys/cdefs.h>
4 1.3 fvdl __KERNEL_RCSID(0, "$NetBSD: aapic.c,v 1.3 2005/01/13 23:40:01 fvdl 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.3 fvdl #include "ioapic.h"
18 1.3 fvdl
19 1.3 fvdl #if NIOAPIC > 0
20 1.3 fvdl extern int nioapics;
21 1.3 fvdl #endif
22 1.3 fvdl
23 1.1 fvdl static int aapic_match __P((struct device *, struct cfdata *, void *));
24 1.1 fvdl static void aapic_attach __P((struct device *, struct device *, void *));
25 1.1 fvdl
26 1.1 fvdl struct aapic_softc {
27 1.1 fvdl struct device sc_dev;
28 1.1 fvdl };
29 1.1 fvdl
30 1.1 fvdl CFATTACH_DECL(aapic, sizeof(struct aapic_softc),
31 1.1 fvdl aapic_match, aapic_attach, NULL, NULL);
32 1.1 fvdl
33 1.1 fvdl static int
34 1.1 fvdl aapic_match(parent, match, aux)
35 1.1 fvdl struct device *parent;
36 1.1 fvdl struct cfdata *match;
37 1.1 fvdl void *aux;
38 1.1 fvdl {
39 1.1 fvdl struct pci_attach_args *pa = aux;
40 1.1 fvdl
41 1.1 fvdl if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
42 1.1 fvdl PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PCIX8131_APIC)
43 1.1 fvdl return (1);
44 1.1 fvdl
45 1.1 fvdl return (0);
46 1.1 fvdl }
47 1.1 fvdl
48 1.1 fvdl static void
49 1.1 fvdl aapic_attach(parent, self, aux)
50 1.1 fvdl struct device *parent, *self;
51 1.1 fvdl void *aux;
52 1.1 fvdl {
53 1.1 fvdl struct pci_attach_args *pa = aux;
54 1.1 fvdl char devinfo[256];
55 1.1 fvdl int bus, dev, func, rev;
56 1.1 fvdl pcitag_t tag;
57 1.1 fvdl pcireg_t reg;
58 1.1 fvdl
59 1.2 itojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
60 1.1 fvdl rev = PCI_REVISION(pa->pa_class);
61 1.1 fvdl printf(": %s (rev. 0x%02x)\n", devinfo, rev);
62 1.1 fvdl
63 1.3 fvdl #if NIOAPIC > 0
64 1.3 fvdl if (nioapics == 0)
65 1.3 fvdl return;
66 1.3 fvdl #else
67 1.3 fvdl return;
68 1.3 fvdl #endif
69 1.3 fvdl
70 1.1 fvdl reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL);
71 1.3 fvdl reg |= AMD8131_IOAEN;
72 1.3 fvdl pci_conf_write(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL, reg);
73 1.3 fvdl
74 1.3 fvdl pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func);
75 1.3 fvdl func = 0;
76 1.3 fvdl tag = pci_make_tag(pa->pa_pc, bus, dev, func);
77 1.3 fvdl reg = pci_conf_read(pa->pa_pc, tag, AMD8131_PCIX_MISC);
78 1.3 fvdl reg &= ~AMD8131_NIOAMODE;
79 1.3 fvdl pci_conf_write(pa->pa_pc, tag, AMD8131_PCIX_MISC, reg);
80 1.1 fvdl }
81