Module Name: src Committed By: knakahara Date: Thu Jan 4 01:01:59 UTC 2018
Modified Files: src/sys/arch/x86/include: intr.h src/sys/arch/x86/pci: pci_intr_machdep.c src/sys/arch/x86/x86: intr.c Log Message: fix "intrctl list" panic when ACPI is disabled. reviewed by cherry@n.o and tested by msaitoh@n.o, thanks. To generate a diff of this commit: cvs rdiff -u -r1.52 -r1.53 src/sys/arch/x86/include/intr.h cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/pci/pci_intr_machdep.c cvs rdiff -u -r1.113 -r1.114 src/sys/arch/x86/x86/intr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/include/intr.h diff -u src/sys/arch/x86/include/intr.h:1.52 src/sys/arch/x86/include/intr.h:1.53 --- src/sys/arch/x86/include/intr.h:1.52 Sat Nov 4 14:56:48 2017 +++ src/sys/arch/x86/include/intr.h Thu Jan 4 01:01:59 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.h,v 1.52 2017/11/04 14:56:48 cherry Exp $ */ +/* $NetBSD: intr.h,v 1.53 2018/01/04 01:01:59 knakahara Exp $ */ /*- * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -222,6 +222,9 @@ int intr_find_mpmapping(int, int, intr_h struct pic *intr_findpic(int); void intr_printconfig(void); +#if !defined(XEN) +const char *intr_create_intrid(int, struct pic *, int, char *, size_t); +#endif /* XEN */ struct intrsource *intr_allocate_io_intrsource(const char *); void intr_free_io_intrsource(const char *); Index: src/sys/arch/x86/pci/pci_intr_machdep.c diff -u src/sys/arch/x86/pci/pci_intr_machdep.c:1.41 src/sys/arch/x86/pci/pci_intr_machdep.c:1.42 --- src/sys/arch/x86/pci/pci_intr_machdep.c:1.41 Fri Jul 28 14:26:50 2017 +++ src/sys/arch/x86/pci/pci_intr_machdep.c Thu Jan 4 01:01:59 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_intr_machdep.c,v 1.41 2017/07/28 14:26:50 maxv Exp $ */ +/* $NetBSD: pci_intr_machdep.c,v 1.42 2018/01/04 01:01:59 knakahara Exp $ */ /*- * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.41 2017/07/28 14:26:50 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.42 2018/01/04 01:01:59 knakahara Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -273,15 +273,42 @@ pci_intr_setattr(pci_chipset_tag_t pc, p } } +static int +pci_intr_find_intx_irq(pci_intr_handle_t ih, int *irq, struct pic **pic, + int *pin) +{ + + KASSERT(irq != NULL); + KASSERT(pic != NULL); + KASSERT(pin != NULL); + + *pic = &i8259_pic; + *pin = *irq = APIC_IRQ_LEGACY_IRQ(ih); + +#if NIOAPIC > 0 + if (ih & APIC_INT_VIA_APIC) { + struct ioapic_softc *ioapic; + + ioapic = ioapic_find(APIC_IRQ_APIC(ih)); + if (ioapic == NULL) + return ENOENT; + *pic = &ioapic->sc_pic; + *pin = APIC_IRQ_PIN(ih); + *irq = APIC_IRQ_LEGACY_IRQ(ih); + if (*irq < 0 || *irq >= NUM_LEGACY_IRQS) + *irq = -1; + } +#endif + + return 0; +} + static void * pci_intr_establish_xname_internal(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg, const char *xname) { int pin, irq; struct pic *pic; -#if NIOAPIC > 0 - struct ioapic_softc *ioapic; -#endif bool mpsafe; pci_chipset_tag_t ipc; @@ -301,25 +328,13 @@ pci_intr_establish_xname_internal(pci_ch xname); } - pic = &i8259_pic; - pin = irq = APIC_IRQ_LEGACY_IRQ(ih); - mpsafe = ((ih & MPSAFE_MASK) != 0); - -#if NIOAPIC > 0 - if (ih & APIC_INT_VIA_APIC) { - ioapic = ioapic_find(APIC_IRQ_APIC(ih)); - if (ioapic == NULL) { - aprint_normal("pci_intr_establish: bad ioapic %d\n", - APIC_IRQ_APIC(ih)); - return NULL; - } - pic = &ioapic->sc_pic; - pin = APIC_IRQ_PIN(ih); - irq = APIC_IRQ_LEGACY_IRQ(ih); - if (irq < 0 || irq >= NUM_LEGACY_IRQS) - irq = -1; + if (pci_intr_find_intx_irq(ih, &irq, &pic, &pin)) { + aprint_normal("%s: bad pic %d\n", __func__, + APIC_IRQ_APIC(ih)); + return NULL; } -#endif + + mpsafe = ((ih & MPSAFE_MASK) != 0); return intr_establish_xname(irq, pic, pin, IST_LEVEL, level, func, arg, mpsafe, xname); @@ -376,6 +391,31 @@ pci_intr_type(pci_chipset_tag_t pc, pci_ } } +static const char * +x86_pci_intx_create_intrid(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, + size_t len) +{ +#if !defined(XEN) + int pin, irq; + struct pic *pic; + + KASSERT(!INT_VIA_MSI(ih)); + + pic = &i8259_pic; + pin = irq = APIC_IRQ_LEGACY_IRQ(ih); + + if (pci_intr_find_intx_irq(ih, &irq, &pic, &pin)) { + aprint_normal("%s: bad pic %d\n", __func__, + APIC_IRQ_APIC(ih)); + return NULL; + } + + return intr_create_intrid(irq, pic, pin, buf, len); +#else + return pci_intr_string(pc, ih, buf, len); +#endif /* !XEN */ +} + static void x86_pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih) { @@ -406,8 +446,11 @@ pci_intx_alloc(const struct pci_attach_a goto error; } - intrstr = pci_intr_string(pa->pa_pc, *handle, - intrstr_buf, sizeof(intrstr_buf)); + /* + * must be the same intrstr as intr_establish_xname() + */ + intrstr = x86_pci_intx_create_intrid(pa->pa_pc, *handle, intrstr_buf, + sizeof(intrstr_buf)); mutex_enter(&cpu_lock); isp = intr_allocate_io_intrsource(intrstr); mutex_exit(&cpu_lock); Index: src/sys/arch/x86/x86/intr.c diff -u src/sys/arch/x86/x86/intr.c:1.113 src/sys/arch/x86/x86/intr.c:1.114 --- src/sys/arch/x86/x86/intr.c:1.113 Wed Dec 13 16:30:18 2017 +++ src/sys/arch/x86/x86/intr.c Thu Jan 4 01:01:59 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: intr.c,v 1.113 2017/12/13 16:30:18 bouyer Exp $ */ +/* $NetBSD: intr.c,v 1.114 2018/01/04 01:01:59 knakahara Exp $ */ /*- * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -133,7 +133,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.113 2017/12/13 16:30:18 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.114 2018/01/04 01:01:59 knakahara Exp $"); #include "opt_intrdebug.h" #include "opt_multiprocessor.h" @@ -253,9 +253,6 @@ static void intr_redistribute_xc_s1(void static void intr_redistribute_xc_s2(void *, void *); static bool intr_redistribute(struct cpu_info *); -#if !defined(XEN) -static const char *create_intrid(int, struct pic *, int, char *, size_t); -#endif /* XEN */ static struct intrsource *intr_get_io_intrsource(const char *); static void intr_free_io_intrsource_direct(struct intrsource *); #if !defined(XEN) @@ -495,8 +492,8 @@ intr_scan_bus(int bus, int pin, intr_han * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used * by MI code and intrctl(8). */ -static const char * -create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len) +const char * +intr_create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len) { int ih = 0; @@ -958,7 +955,7 @@ intr_establish_xname(int legacy_irq, str "non-legacy IRQ on i8259"); ih = kmem_alloc(sizeof(*ih), KM_SLEEP); - intrstr = create_intrid(legacy_irq, pic, pin, intrstr_buf, + intrstr = intr_create_intrid(legacy_irq, pic, pin, intrstr_buf, sizeof(intrstr_buf)); KASSERT(intrstr != NULL);