diff --git a/share/man/man9/pci_msi.9 b/share/man/man9/pci_msi.9 index dba9a13..ae74b6e 100644 --- a/share/man/man9/pci_msi.9 +++ b/share/man/man9/pci_msi.9 @@ -24,7 +24,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 8, 2015 +.Dd May 11, 2015 .Dt PCI_MSI 9 .Os .Sh NAME @@ -33,19 +33,12 @@ .Nm pci_msi_count , .Nm pci_msi_alloc , .Nm pci_msi_alloc_exact , -.Nm pci_msi_release , -.Nm pci_msi_establish , -.Nm pci_msi_disestablish , -.Nm pci_msi_string .Nm pci_msix_count , .Nm pci_msix_alloc , .Nm pci_msix_alloc_exact , .Nm pci_msix_alloc_map , -.Nm pci_msix_release , -.Nm pci_msix_establish , -.Nm pci_msix_disestablish , .Nm pci_intx_alloc , -.Nm pci_intx_release +.Nm pci_intr_release .Nd PCI MSI{,-X} manipulation functions .Sh SYNOPSIS .Ft int @@ -56,16 +49,6 @@ .Ft int .Fn pci_msi_alloc_exect "struct pci_attach_args *pa" \ "pci_intr_handle_t **ihps" "int count" -.Ft void -.Fn pci_msi_release "pci_intr_handle_t **pihs" "int count" -.Ft void * -.Fn pci_msi_establish "pci_chipset_tag_t pc" "pci_intr_handle_t ih" \ -"int level" "int (*func)(void *)" "void *arg" -.Ft void -.Fn pci_msi_disestablish "pci_chipset_tag_t pc" "void *cookie" -.Ft const char * -.Ft pci_msi_string "pci_chipset_tag_t pc" \ -"pci_intr_handle_t, char *buf" "size_t len" .Ft int .Fn pci_msix_count "struct pci_attach_args *pa" .Ft int @@ -77,17 +60,12 @@ .Ft int .Fn pci_msix_alloc_map "struct pci_attach_args *pa" \ "pci_intr_handle_t **ihps" "u_int *table_indexes" "int count" -.Ft void -.Fn pci_msix_release "pci_intr_handle_t **pihs" "int count" -.Ft void * -.Fn pci_msix_establish "pci_chipset_tag_t pc" "pci_intr_handle_t ih" \ -"int level" "int (*func)(void *)" "void *arg" -.Fn pci_msix_disestablish "pci_chipset_tag_t pc" "void *cookie" .Ft int .Fn pci_intx_alloc "struct pci_attach_args *pa" \ "pci_intr_handle_t **ihp" .Ft void -.Fn pci_intx_release "pci_intr_handle_t *pih" +.Fn pci_intr_release "pci_chipset_tag_t pc" \ +"pci_intr_handle_t *pih" "int count" .Sh DESCRIPTION The .Nm @@ -142,34 +120,34 @@ can not decrement .Pp If the driver wishes to refer to the MSI source in an attach or error message, it should use the value returned by -.Fn pci_msi_string . +.Fn pci_intr_string +the same as INTx. The buffer passed to -.Fn pci_msi_string +.Fn pci_intr_string should be at least .Dv PCI_INTRSTR_LEN bytes long. .Pp Subsequently, when the driver is prepared to receive MSIs, it should call -.Fn pci_msi_establish -to actually establish the handler; when the device interrupts, +.Fn pci_intr_establish +the same as INTx to actually establish the handler; +when the device interrupts, .Fa intrhand will be called with a single argument .Fa intrarg , and will run at the interrupt priority level .Fa ipl . -This is the same as -.Fn pci_intr_establish . .Pp The return value of -.Fn pci_msi_establish +.Fn pci_intr_establish may be saved and passed to -.Fn pci_msi_disestablish -to disable the interrupt handler +.Fn pci_intr_disestablish +to disable the interrupt handler the same as INTx when the driver is no longer interested in MSIs from the device. After that, the driver should also call -.Fn pci_msi_release -to free resources about MSI. +.Fn pci_intr_release +to free resources about MSI as well as INTx and MSI-X. .Pp If a driver wishes to establish an MSI-X handler for the device, it is almost the same as MSI. @@ -195,7 +173,7 @@ this way: If the driver wants to fall back to INTx, the driver should use .Fn pci_intx_alloc and -.Fn pci_intx_release +.Fn pci_intr_release instead of .Fn pci_intr_map to resolve contradiction of the interrupt handler ownership. @@ -207,3 +185,5 @@ in contrast, and .Fn pci_msix_alloc have (the functions allocate memory for interrupt handlers). +.Sh SEE ALSO +.Xr pci_intr 9 diff --git a/sys/arch/x86/include/pci_machdep_common.h b/sys/arch/x86/include/pci_machdep_common.h index 3b5fe7b..ee9a3a5 100644 --- a/sys/arch/x86/include/pci_machdep_common.h +++ b/sys/arch/x86/include/pci_machdep_common.h @@ -127,19 +127,13 @@ int pci_intr_distribute(void *, const kcpuset_t *, kcpuset_t *); */ int pci_intx_alloc(const struct pci_attach_args *, pci_intr_handle_t **); -void pci_intx_release(pci_chipset_tag_t, pci_intr_handle_t *); /* experimental MSI support */ -const char *pci_msi_string(pci_chipset_tag_t, pci_intr_handle_t, char *, size_t); int pci_msi_count(const struct pci_attach_args *); int pci_msi_alloc(const struct pci_attach_args *, pci_intr_handle_t **, int *); int pci_msi_alloc_exact(const struct pci_attach_args *, pci_intr_handle_t **, int); -void pci_msi_release(pci_chipset_tag_t, pci_intr_handle_t **, int); -void *pci_msi_establish(pci_chipset_tag_t, pci_intr_handle_t, - int, int (*)(void *), void *); -void pci_msi_disestablish(pci_chipset_tag_t, void *); /* experimental MSI-X support */ int pci_msix_count(const struct pci_attach_args *); @@ -149,10 +143,9 @@ int pci_msix_alloc_exact(const struct pci_attach_args *, pci_intr_handle_t **, int); int pci_msix_alloc_map(const struct pci_attach_args *, pci_intr_handle_t **, u_int *, int); -void pci_msix_release(pci_chipset_tag_t, pci_intr_handle_t **, int); -void *pci_msix_establish(pci_chipset_tag_t, pci_intr_handle_t, - int, int (*)(void *), void *); -void pci_msix_disestablish(pci_chipset_tag_t, void *); + +void pci_intr_release(pci_chipset_tag_t, pci_intr_handle_t *, + int count); /* * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED diff --git a/sys/arch/x86/pci/pci_intr_machdep.c b/sys/arch/x86/pci/pci_intr_machdep.c index 43aac0a..b56638f 100644 --- a/sys/arch/x86/pci/pci_intr_machdep.c +++ b/sys/arch/x86/pci/pci_intr_machdep.c @@ -102,6 +102,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.30 2015/04/27 07:03:58 knakah #include #include #include +#include #endif #ifdef MPBIOS @@ -225,9 +226,6 @@ pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, { pci_chipset_tag_t ipc; - if (INT_VIA_MSI(ih)) - return pci_msi_string(pc, ih, buf, len); - for (ipc = pc; ipc != NULL; ipc = ipc->pc_super) { if ((ipc->pc_present & PCI_OVERRIDE_INTR_STRING) == 0) continue; @@ -235,6 +233,9 @@ pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, buf, len); } + if (INT_VIA_MSI(ih)) + return x86_pci_msi_string(pc, ih, buf, len); + return intr_string(ih & ~MPSAFE_MASK, buf, len); } @@ -292,6 +293,13 @@ pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, pc, ih, level, func, arg); } + if (INT_VIA_MSI(ih)) { + if (MSI_INT_IS_MSIX(ih)) + return x86_pci_msix_establish(pc, ih, level, func, arg); + else + return x86_pci_msi_establish(pc, ih, level, func, arg); + } + pic = &i8259_pic; pin = irq = APIC_IRQ_LEGACY_IRQ(ih); mpsafe = ((ih & MPSAFE_MASK) != 0); @@ -328,6 +336,7 @@ pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) return; } + /* MSI/MSI-X processing is switched in intr_disestablish(). */ intr_disestablish(cookie); } @@ -341,6 +350,20 @@ pci_intr_distribute(void *cookie, const kcpuset_t *newset, kcpuset_t *oldset) } #if NIOAPIC > 0 +static void +x86_pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih) +{ + char intrstr_buf[INTRIDBUF]; + const char *intrstr; + + intrstr = pci_intr_string(NULL, *pih, intrstr_buf, sizeof(intrstr_buf)); + mutex_enter(&cpu_lock); + intr_free_io_intrsource(intrstr); + mutex_exit(&cpu_lock); + + kmem_free(pih, sizeof(*pih)); +} + int pci_intx_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **pih) { @@ -382,19 +405,20 @@ error: } void -pci_intx_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih) +pci_intr_release(pci_chipset_tag_t pc, pci_intr_handle_t *pih, int count) { - char intrstr_buf[INTRIDBUF]; - const char *intrstr; - if (pih == NULL) return; - intrstr = pci_intr_string(NULL, *pih, intrstr_buf, sizeof(intrstr_buf)); - mutex_enter(&cpu_lock); - intr_free_io_intrsource(intrstr); - mutex_exit(&cpu_lock); + if (INT_VIA_MSI(*pih)) { + if (MSI_INT_IS_MSIX(*pih)) + return x86_pci_msix_release(pc, pih, count); + else + return x86_pci_msi_release(pc, pih, count); + } else { + KASSERT(count == 1); + return x86_pci_intx_release(pc, pih); + } - kmem_free(pih, sizeof(*pih)); } #endif diff --git a/sys/arch/x86/pci/pci_msi_machdep.c b/sys/arch/x86/pci/pci_msi_machdep.c index 33ed9774..973d771 100644 --- a/sys/arch/x86/pci/pci_msi_machdep.c +++ b/sys/arch/x86/pci/pci_msi_machdep.c @@ -53,6 +53,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_msi_machdep.c,v 1.2 2015/05/08 04:27:48 knakahar #include #include +#include #ifdef INTRDEBUG #define MSIDEBUG @@ -64,28 +65,6 @@ __KERNEL_RCSID(0, "$NetBSD: pci_msi_machdep.c,v 1.2 2015/05/08 04:27:48 knakahar #define DPRINTF(msg) #endif -/* - * Return intrid for a MSI/MSI-X device. - * "buf" must be allocated by caller. - */ -const char * -pci_msi_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, - size_t len) -{ - int dev, vec; - - KASSERT(INT_VIA_MSI(ih)); - - dev = MSI_INT_DEV(ih); - vec = MSI_INT_VEC(ih); - if (MSI_INT_IS_MSIX(ih)) - snprintf(buf, len, "msix%d vec %d", dev, vec); - else - snprintf(buf, len, "msi%d vec %d", dev, vec); - - return buf; -} - static pci_intr_handle_t pci_msi_calculate_handle(struct pic *msi_pic, int vector) { @@ -133,7 +112,7 @@ pci_msi_alloc_vectors(struct pic *msi_pic, uint *table_indexes, int *count) pih = pci_msi_calculate_handle(msi_pic, table_index); - intrstr = pci_msi_string(NULL, pih, intrstr_buf, + intrstr = x86_pci_msi_string(NULL, pih, intrstr_buf, sizeof(intrstr_buf)); isp = intr_allocate_io_intrsource(intrstr); if (isp == NULL) { @@ -161,7 +140,7 @@ pci_msi_free_vectors(struct pic *msi_pic, pci_intr_handle_t *pihs, int count) mutex_enter(&cpu_lock); for (i = 0; i < count; i++) { pih = pci_msi_calculate_handle(msi_pic, i); - intrstr = pci_msi_string(NULL, pih, intrstr_buf, + intrstr = x86_pci_msi_string(NULL, pih, intrstr_buf, sizeof(intrstr_buf)); intr_free_io_intrsource(intrstr); } @@ -171,7 +150,7 @@ pci_msi_free_vectors(struct pic *msi_pic, pci_intr_handle_t *pihs, int count) } static int -pci_msi_alloc_md_common(pci_intr_handle_t **ihps, int *count, +pci_msi_alloc_common(pci_intr_handle_t **ihps, int *count, const struct pci_attach_args *pa, bool exact) { struct pic *msi_pic; @@ -225,37 +204,6 @@ pci_msi_alloc_md_common(pci_intr_handle_t **ihps, int *count, return 0; } -static int -pci_msi_alloc_md(pci_intr_handle_t **ihps, int *count, - const struct pci_attach_args *pa) -{ - - return pci_msi_alloc_md_common(ihps, count, pa, false); -} - -static int -pci_msi_alloc_exact_md(pci_intr_handle_t **ihps, int count, - const struct pci_attach_args *pa) -{ - - return pci_msi_alloc_md_common(ihps, &count, pa, true); -} - -static void -pci_msi_release_md(pci_intr_handle_t **pihs, int count) -{ - struct pic *pic; - pci_intr_handle_t *vectors; - - vectors = *pihs; - pic = msipic_find_msi_pic(MSI_INT_DEV(vectors[0])); - if (pic == NULL) - return; - - pci_msi_free_vectors(pic, vectors, count); - msipic_destruct_msi_pic(pic); -} - static void * pci_msi_common_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg, struct pic *pic) @@ -281,7 +229,7 @@ pci_msi_common_disestablish(pci_chipset_tag_t pc, void *cookie) } static int -pci_msix_alloc_md_common(pci_intr_handle_t **ihps, u_int *table_indexes, +pci_msix_alloc_common(pci_intr_handle_t **ihps, u_int *table_indexes, int *count, const struct pci_attach_args *pa, bool exact) { struct pic *msix_pic; @@ -335,47 +283,191 @@ pci_msix_alloc_md_common(pci_intr_handle_t **ihps, u_int *table_indexes, } static int -pci_msix_alloc_md(pci_intr_handle_t **ihps, int *count, +x86_pci_msi_alloc(pci_intr_handle_t **ihps, int *count, + const struct pci_attach_args *pa) +{ + + return pci_msi_alloc_common(ihps, count, pa, false); +} + +static int +x86_pci_msi_alloc_exact(pci_intr_handle_t **ihps, int count, const struct pci_attach_args *pa) { - return pci_msix_alloc_md_common(ihps, NULL, count, pa, false); + return pci_msi_alloc_common(ihps, &count, pa, true); +} + +static void +x86_pci_msi_release_internal(pci_intr_handle_t *pihs, int count) +{ + struct pic *pic; + + pic = msipic_find_msi_pic(MSI_INT_DEV(pihs[0])); + if (pic == NULL) + return; + + pci_msi_free_vectors(pic, pihs, count); + msipic_destruct_msi_pic(pic); } static int -pci_msix_alloc_exact_md(pci_intr_handle_t **ihps, int count, +x86_pci_msix_alloc(pci_intr_handle_t **ihps, int *count, const struct pci_attach_args *pa) { - return pci_msix_alloc_md_common(ihps, NULL, &count, pa, true); + return pci_msix_alloc_common(ihps, NULL, count, pa, false); } static int -pci_msix_alloc_map_md(pci_intr_handle_t **ihps, u_int *table_indexes, int count, +x86_pci_msix_alloc_exact(pci_intr_handle_t **ihps, int count, const struct pci_attach_args *pa) { - return pci_msix_alloc_md_common(ihps, table_indexes, &count, pa, true); + return pci_msix_alloc_common(ihps, NULL, &count, pa, true); +} + +static int +x86_pci_msix_alloc_map(pci_intr_handle_t **ihps, u_int *table_indexes, + int count, const struct pci_attach_args *pa) +{ + + return pci_msix_alloc_common(ihps, table_indexes, &count, pa, true); } static void -pci_msix_release_md(pci_intr_handle_t **pihs, int count) +x86_pci_msix_release_internal(pci_intr_handle_t *pihs, int count) { struct pic *pic; - pci_intr_handle_t *vectors; - vectors = *pihs; - pic = msipic_find_msi_pic(MSI_INT_DEV(vectors[0])); + pic = msipic_find_msi_pic(MSI_INT_DEV(pihs[0])); if (pic == NULL) return; - pci_msi_free_vectors(pic, vectors, count); + pci_msi_free_vectors(pic, pihs, count); msipic_destruct_msix_pic(pic); } /*****************************************************************************/ /* - * these APIs may be MI code. + * extern for MD code. + */ + +/* + * Return intrid for a MSI/MSI-X device. + * "buf" must be allocated by caller. + */ +const char * +x86_pci_msi_string(pci_chipset_tag_t pc, pci_intr_handle_t ih, char *buf, + size_t len) +{ + int dev, vec; + + KASSERT(INT_VIA_MSI(ih)); + + dev = MSI_INT_DEV(ih); + vec = MSI_INT_VEC(ih); + if (MSI_INT_IS_MSIX(ih)) + snprintf(buf, len, "msix%d vec %d", dev, vec); + else + snprintf(buf, len, "msi%d vec %d", dev, vec); + + return buf; +} + +/* + * Release MSI handles. + */ +void +x86_pci_msi_release(pci_chipset_tag_t pc, pci_intr_handle_t *pihs, int count) +{ + + if (count < 1) + return; + + return x86_pci_msi_release_internal(pihs, count); +} + +/* + * Establish a MSI handle. + * If multiple MSI handle is requied to establish, device driver must call + * this function for each handle. + */ +void * +x86_pci_msi_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, + int level, int (*func)(void *), void *arg) +{ + struct pic *pic; + + pic = msipic_find_msi_pic(MSI_INT_DEV(ih)); + if (pic == NULL) { + DPRINTF(("pci_intr_handler has no msi_pic\n")); + return NULL; + } + + return pci_msi_common_establish(pc, ih, level, func, arg, pic); +} + +/* + * Disestablish a MSI handle. + * If multiple MSI handle is requied to disestablish, device driver must call + * this function for each handle. + */ +void +x86_pci_msi_disestablish(pci_chipset_tag_t pc, void *cookie) +{ + + pci_msi_common_disestablish(pc, cookie); +} + +/* + * Release MSI-X handles. + */ +void +x86_pci_msix_release(pci_chipset_tag_t pc, pci_intr_handle_t *pihs, int count) +{ + + if (count < 1) + return; + + return x86_pci_msix_release_internal(pihs, count); +} + +/* + * Establish a MSI-X handle. + * If multiple MSI-X handle is requied to establish, device driver must call + * this function for each handle. + */ +void * +x86_pci_msix_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, + int level, int (*func)(void *), void *arg) +{ + struct pic *pic; + + pic = msipic_find_msi_pic(MSI_INT_DEV(ih)); + if (pic == NULL) { + DPRINTF(("pci_intr_handler has no msi_pic\n")); + return NULL; + } + + return pci_msi_common_establish(pc, ih, level, func, arg, pic); +} + +/* + * Disestablish a MSI-X handle. + * If multiple MSI-X handle is requied to disestablish, device driver must call + * this function for each handle. + */ +void +x86_pci_msix_disestablish(pci_chipset_tag_t pc, void *cookie) +{ + + pci_msi_common_disestablish(pc, cookie); +} + +/*****************************************************************************/ +/* + * extern for MI code. */ /* @@ -434,7 +526,7 @@ pci_msi_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps, *count = hw_max; /* cut off hw_max */ } - return pci_msi_alloc_md(ihps, count, pa); + return x86_pci_msi_alloc(ihps, count, pa); } /* @@ -464,52 +556,7 @@ pci_msi_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps, return EINVAL; } - return pci_msi_alloc_exact_md(ihps, count, pa); -} - -/* - * Release MSI handles. - */ -void -pci_msi_release(pci_chipset_tag_t pc, pci_intr_handle_t **pihs, int count) -{ - - if (count < 1) - return; - - return pci_msi_release_md(pihs, count); -} - -/* - * Establish a MSI handle. - * If multiple MSI handle is requied to establish, device driver must call - * this function for each handle. - */ -void * -pci_msi_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, - int level, int (*func)(void *), void *arg) -{ - struct pic *pic; - - pic = msipic_find_msi_pic(MSI_INT_DEV(ih)); - if (pic == NULL) { - DPRINTF(("pci_intr_handler has no msi_pic\n")); - return NULL; - } - - return pci_msi_common_establish(pc, ih, level, func, arg, pic); -} - -/* - * Disestablish a MSI handle. - * If multiple MSI handle is requied to disestablish, device driver must call - * this function for each handle. - */ -void -pci_msi_disestablish(pci_chipset_tag_t pc, void *cookie) -{ - - pci_msi_common_disestablish(pc, cookie); + return x86_pci_msi_alloc_exact(ihps, count, pa); } /* @@ -558,7 +605,7 @@ pci_msix_alloc(const struct pci_attach_args *pa, pci_intr_handle_t **ihps, *count = hw_max; /* cut off hw_max */ } - return pci_msix_alloc_md(ihps, count, pa); + return x86_pci_msix_alloc(ihps, count, pa); } /* @@ -585,10 +632,9 @@ pci_msix_alloc_exact(const struct pci_attach_args *pa, pci_intr_handle_t **ihps, return EINVAL; } - return pci_msix_alloc_exact_md(ihps, count, pa); + return x86_pci_msix_alloc_exact(ihps, count, pa); } - /* * This function is used by device drivers like pci_intr_map(). * Futhermore, this function can map each handle to a MSI-X table index. @@ -639,50 +685,5 @@ pci_msix_alloc_map(const struct pci_attach_args *pa, pci_intr_handle_t **ihps, } } - return pci_msix_alloc_map_md(ihps, table_indexes, count, pa); -} - -/* - * Release MSI-X handles. - */ -void -pci_msix_release(pci_chipset_tag_t pc, pci_intr_handle_t **pihs, int count) -{ - - if (count < 1) - return; - - return pci_msix_release_md(pihs, count); -} - -/* - * Establish a MSI-X handle. - * If multiple MSI-X handle is requied to establish, device driver must call - * this function for each handle. - */ -void * -pci_msix_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, - int level, int (*func)(void *), void *arg) -{ - struct pic *pic; - - pic = msipic_find_msi_pic(MSI_INT_DEV(ih)); - if (pic == NULL) { - DPRINTF(("pci_intr_handler has no msi_pic\n")); - return NULL; - } - - return pci_msi_common_establish(pc, ih, level, func, arg, pic); -} - -/* - * Disestablish a MSI-X handle. - * If multiple MSI-X handle is requied to disestablish, device driver must call - * this function for each handle. - */ -void -pci_msix_disestablish(pci_chipset_tag_t pc, void *cookie) -{ - - pci_msi_common_disestablish(pc, cookie); + return x86_pci_msix_alloc_map(ihps, table_indexes, count, pa); } diff --git a/sys/arch/x86/pci/pci_msi_machdep.h b/sys/arch/x86/pci/pci_msi_machdep.h new file mode 100644 index 0000000..8f5056e --- /dev/null +++ b/sys/arch/x86/pci/pci_msi_machdep.h @@ -0,0 +1,46 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 2015 Internet Initiative Japan Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _X86_PCI_PCI_MSI_MACHDEP_H_ +#define _X86_PCI_PCI_MSI_MACHDEP_H_ + +const char *x86_pci_msi_string(pci_chipset_tag_t, pci_intr_handle_t, + char *, size_t); +void x86_pci_msi_release(pci_chipset_tag_t, pci_intr_handle_t *, + int); +void *x86_pci_msi_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *); +void x86_pci_msi_disestablish(pci_chipset_tag_t, void *); + +void x86_pci_msix_release(pci_chipset_tag_t, pci_intr_handle_t *, + int); +void *x86_pci_msix_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *); +void x86_pci_msix_disestablish(pci_chipset_tag_t, void *); + +#endif /* _X86_PCI_PCI_MSI_MACHDEP_H_ */ diff --git a/sys/arch/x86/x86/intr.c b/sys/arch/x86/x86/intr.c index 6581f94..46a2922 100644 --- a/sys/arch/x86/x86/intr.c +++ b/sys/arch/x86/x86/intr.c @@ -177,6 +177,7 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.84 2015/05/09 13:05:51 christos Exp $"); #endif #include +#include #if NPCI == 0 #define msipic_is_msi_pic(PIC) (false) @@ -487,7 +488,7 @@ create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len) else if (pic->pic_type == PIC_MSIX) MSI_INT_MAKE_MSIX(pih); - return pci_msi_string(NULL, pih, buf, len); + return x86_pci_msi_string(NULL, pih, buf, len); } #endif diff --git a/sys/dev/pci/if_iwm.c b/sys/dev/pci/if_iwm.c index 912bc87..8cb0623 100644 --- a/sys/dev/pci/if_iwm.c +++ b/sys/dev/pci/if_iwm.c @@ -6679,14 +6679,10 @@ iwm_attach(device_t parent, device_t self, void *aux) } /* Install interrupt handler. */ - sc->sc_intr_type = IWM_INTR_INTX; #ifdef __HAVE_PCI_MSI_MSIX error = ENODEV; - if (pci_msi_count(pa) > 0) { + if (pci_msi_count(pa) > 0) error = pci_msi_alloc_exact(pa, &sc->sc_pihp, 1); - if (error == 0) - sc->sc_intr_type = IWM_INTR_MSI; - } if (error != 0) { if (pci_intx_alloc(pa, &sc->sc_pihp)) { aprint_error_dev(self, "can't map interrupt\n"); @@ -6704,17 +6700,8 @@ iwm_attach(device_t parent, device_t self, void *aux) #ifdef __HAVE_PCI_MSI_MSIX intrstr = pci_intr_string(sc->sc_pct, sc->sc_pihp[0], intrbuf, sizeof(intrbuf)); - switch (sc->sc_intr_type) { - case IWM_INTR_MSI: - sc->sc_ih = pci_msi_establish(sc->sc_pct, sc->sc_pihp[0], - IPL_NET, iwm_intr, sc); - break; - - case IWM_INTR_INTX: - sc->sc_ih = pci_intr_establish(sc->sc_pct, sc->sc_pihp[0], - IPL_NET, iwm_intr, sc); - break; - } + sc->sc_ih = pci_intr_establish(sc->sc_pct, sc->sc_pihp[0], IPL_NET, + iwm_intr, sc); #else /* !__HAVE_PCI_MSI_MSIX */ intrstr = pci_intr_string(sc->sc_pct, ih, intrbuf, sizeof(intrbuf)); sc->sc_ih = pci_intr_establish(sc->sc_pct, ih, IPL_NET, iwm_intr, sc); diff --git a/sys/dev/pci/if_iwmvar.h b/sys/dev/pci/if_iwmvar.h index 2af33be..882cda8 100644 --- a/sys/dev/pci/if_iwmvar.h +++ b/sys/dev/pci/if_iwmvar.h @@ -363,11 +363,6 @@ struct iwm_bf_data { int last_cqm_event; }; -enum iwm_intr_type { - IWM_INTR_INTX, - IWM_INTR_MSI -}; - struct iwm_softc { device_t sc_dev; struct ethercom sc_ec; @@ -381,7 +376,6 @@ struct iwm_softc { bus_space_tag_t sc_st; bus_space_handle_t sc_sh; - enum iwm_intr_type sc_intr_type; #ifdef __HAVE_PCI_MSI_MSIX pci_intr_handle_t *sc_pihp; #endif