xref: /netbsd-src/sys/arch/x86/pci/aapic.c (revision a323bb797ad15ff02145122d9f706a9f43f96ce4)
1*a323bb79Snjoly /* 	$NetBSD: aapic.c,v 1.8 2009/11/25 15:06:26 njoly Exp $	*/
29ad68fe1Sfvdl 
39ad68fe1Sfvdl #include <sys/cdefs.h>
4*a323bb79Snjoly __KERNEL_RCSID(0, "$NetBSD: aapic.c,v 1.8 2009/11/25 15:06:26 njoly Exp $");
59ad68fe1Sfvdl 
69ad68fe1Sfvdl #include <sys/param.h>
79ad68fe1Sfvdl #include <sys/systm.h>
89ad68fe1Sfvdl #include <sys/kernel.h>
99ad68fe1Sfvdl #include <sys/device.h>
109ad68fe1Sfvdl 
119ad68fe1Sfvdl #include <dev/pci/pcireg.h>
129ad68fe1Sfvdl #include <dev/pci/pcivar.h>
139ad68fe1Sfvdl #include <dev/pci/pcidevs.h>
149ad68fe1Sfvdl 
159ad68fe1Sfvdl #include <arch/x86/pci/amd8131reg.h>
169ad68fe1Sfvdl 
174880e836Sfvdl #include "ioapic.h"
184880e836Sfvdl 
194880e836Sfvdl #if NIOAPIC > 0
204880e836Sfvdl extern int nioapics;
214880e836Sfvdl #endif
224880e836Sfvdl 
230fa9592aSjoerg static int	aapic_match(device_t, cfdata_t, void *);
240fa9592aSjoerg static void	aapic_attach(device_t, device_t, void *);
259ad68fe1Sfvdl 
26ec61c372Sjoerg CFATTACH_DECL_NEW(aapic, 0, aapic_match, aapic_attach, NULL, NULL);
279ad68fe1Sfvdl 
289ad68fe1Sfvdl static int
aapic_match(device_t parent,cfdata_t match,void * aux)29b6a44bdcSjoerg aapic_match(device_t parent, cfdata_t match, void *aux)
309ad68fe1Sfvdl {
319ad68fe1Sfvdl 	struct pci_attach_args *pa = aux;
329ad68fe1Sfvdl 
339ad68fe1Sfvdl 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
349ad68fe1Sfvdl 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PCIX8131_APIC)
359ad68fe1Sfvdl 		return (1);
369ad68fe1Sfvdl 
379ad68fe1Sfvdl 	return (0);
389ad68fe1Sfvdl }
399ad68fe1Sfvdl 
409ad68fe1Sfvdl static void
aapic_attach(device_t parent,device_t self,void * aux)41b6a44bdcSjoerg aapic_attach(device_t parent, device_t self, void *aux)
429ad68fe1Sfvdl {
439ad68fe1Sfvdl 	struct pci_attach_args *pa = aux;
449ad68fe1Sfvdl 	char devinfo[256];
459ad68fe1Sfvdl 	int bus, dev, func, rev;
469ad68fe1Sfvdl 	pcitag_t tag;
479ad68fe1Sfvdl 	pcireg_t reg;
489ad68fe1Sfvdl 
4961230437Sitojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
509ad68fe1Sfvdl 	rev = PCI_REVISION(pa->pa_class);
51*a323bb79Snjoly 	aprint_naive("\n");
52*a323bb79Snjoly 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo, rev);
539ad68fe1Sfvdl 
544880e836Sfvdl #if NIOAPIC > 0
554880e836Sfvdl 	if (nioapics == 0)
564880e836Sfvdl 		return;
574880e836Sfvdl #else
584880e836Sfvdl 	return;
594880e836Sfvdl #endif
604880e836Sfvdl 
619ad68fe1Sfvdl 	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL);
629ad68fe1Sfvdl 	reg |= AMD8131_IOAEN;
639ad68fe1Sfvdl 	pci_conf_write(pa->pa_pc, pa->pa_tag, AMD8131_IOAPIC_CTL, reg);
649ad68fe1Sfvdl 
659ad68fe1Sfvdl 	pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus, &dev, &func);
669ad68fe1Sfvdl 	func = 0;
679ad68fe1Sfvdl 	tag = pci_make_tag(pa->pa_pc, bus, dev, func);
689ad68fe1Sfvdl 	reg = pci_conf_read(pa->pa_pc, tag, AMD8131_PCIX_MISC);
694880e836Sfvdl 	reg &= ~AMD8131_NIOAMODE;
709ad68fe1Sfvdl 	pci_conf_write(pa->pa_pc, tag, AMD8131_PCIX_MISC, reg);
719ad68fe1Sfvdl }
72