1 | /* $NetBSD: aapic.c,v 1.8 2009/11/25 15:06:26 njoly Exp $ */ |
2 | |
3 | #include <sys/cdefs.h> |
4 | __KERNEL_RCSID(0, "$NetBSD: aapic.c,v 1.8 2009/11/25 15:06:26 njoly 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 | aprint_naive("\n" ); |
52 | aprint_normal(": %s (rev. 0x%02x)\n" , devinfo, rev); |
53 | |
54 | #if NIOAPIC > 0 |
55 | if (nioapics == 0) |
56 | return; |
57 | #else |
58 | return; |
59 | #endif |
60 | |
61 | reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL); |
62 | reg |= AMD8131_IOAEN; |
63 | pci_conf_write(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL, reg); |
64 | |
65 | pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func); |
66 | func = 0; |
67 | tag = pci_make_tag(pa->pa_pc, bus, dev, func); |
68 | reg = pci_conf_read(pa->pa_pc, tag, AMD8131_PCIX_MISC); |
69 | reg &= ~AMD8131_NIOAMODE; |
70 | pci_conf_write(pa->pa_pc, tag, AMD8131_PCIX_MISC, reg); |
71 | } |
72 | |