aapic.c revision 1.6 1 /* $NetBSD: aapic.c,v 1.6 2008/07/09 21:07:25 joerg Exp $ */
2
3 #include <sys/cdefs.h>
4 __KERNEL_RCSID(0, "$NetBSD: aapic.c,v 1.6 2008/07/09 21:07:25 joerg Exp $");
5
6 #include <sys/param.h>
7 #include <sys/systm.h>
8 #include <sys/kernel.h>
9 #include <sys/device.h>
10
11 #include <dev/pci/pcireg.h>
12 #include <dev/pci/pcivar.h>
13 #include <dev/pci/pcidevs.h>
14
15 #include <arch/x86/pci/amd8131reg.h>
16
17 #include "ioapic.h"
18
19 #if NIOAPIC > 0
20 extern int nioapics;
21 #endif
22
23 static int aapic_match(device_t, cfdata_t, void *));
24 static void aapic_attach(device_t, device_t, void *));
25
26 CFATTACH_DECL_NEW(aapic, 0, aapic_match, aapic_attach, NULL, NULL);
27
28 static int
29 aapic_match(device_t parent, cfdata_t match, void *aux)
30 {
31 struct pci_attach_args *pa = aux;
32
33 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
34 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PCIX8131_APIC)
35 return (1);
36
37 return (0);
38 }
39
40 static void
41 aapic_attach(device_t parent, device_t self, void *aux)
42 {
43 struct pci_attach_args *pa = aux;
44 char devinfo[256];
45 int bus, dev, func, rev;
46 pcitag_t tag;
47 pcireg_t reg;
48
49 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
50 rev = PCI_REVISION(pa->pa_class);
51 printf(": %s (rev. 0x%02x)\n", devinfo, rev);
52
53 #if NIOAPIC > 0
54 if (nioapics == 0)
55 return;
56 #else
57 return;
58 #endif
59
60 reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL);
61 reg |= AMD8131_IOAEN;
62 pci_conf_write(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL, reg);
63
64 pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func);
65 func = 0;
66 tag = pci_make_tag(pa->pa_pc, bus, dev, func);
67 reg = pci_conf_read(pa->pa_pc, tag, AMD8131_PCIX_MISC);
68 reg &= ~AMD8131_NIOAMODE;
69 pci_conf_write(pa->pa_pc, tag, AMD8131_PCIX_MISC, reg);
70 }
71