Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add x86 MD MSI/MSI-X support code.



details:   https://anonhg.NetBSD.org/src/rev/a8084bcdc580
branches:  trunk
changeset: 337776:a8084bcdc580
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Mon Apr 27 07:03:57 2015 +0000

description:
add x86 MD MSI/MSI-X support code.

diffstat:

 distrib/sets/lists/comp/mi                |   36 +-
 share/man/man9/Makefile                   |   20 +-
 share/man/man9/pci_msi.9                  |  210 ++++++++
 sys/arch/amd64/amd64/mainbus.c            |    7 +-
 sys/arch/amd64/include/types.h            |    3 +-
 sys/arch/i386/i386/mainbus.c              |    7 +-
 sys/arch/i386/include/types.h             |    6 +-
 sys/arch/x86/conf/files.x86               |    4 +-
 sys/arch/x86/include/i82093var.h          |   23 +-
 sys/arch/x86/include/pci_machdep.h        |    3 +-
 sys/arch/x86/include/pci_machdep_common.h |   31 +-
 sys/arch/x86/include/pic.h                |    7 +-
 sys/arch/x86/pci/msipic.c                 |  737 ++++++++++++++++++++++++++++++
 sys/arch/x86/pci/msipic.h                 |   46 +
 sys/arch/x86/pci/pci_intr_machdep.c       |  144 ++---
 sys/arch/x86/pci/pci_machdep.c            |  131 +++++-
 sys/arch/x86/pci/pci_msi_machdep.c        |  686 +++++++++++++++++++++++++++
 sys/arch/x86/x86/intr.c                   |   73 ++-
 sys/arch/x86/x86/ioapic.c                 |    6 +-
 sys/arch/xen/include/intr.h               |    6 +-
 sys/dev/pci/pci.c                         |   65 ++-
 sys/dev/pci/pcireg.h                      |    8 +-
 sys/dev/pci/pcivar.h                      |    3 +-
 23 files changed, 2119 insertions(+), 143 deletions(-)

diffs (truncated from 2800 to 300 lines):

diff -r b1bbf24379bd -r a8084bcdc580 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Mon Apr 27 06:56:53 2015 +0000
+++ b/distrib/sets/lists/comp/mi        Mon Apr 27 07:03:57 2015 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1955 2015/04/27 06:42:52 knakahara Exp $
+#      $NetBSD: mi,v 1.1956 2015/04/27 07:03:57 knakahara Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -17367,10 +17367,27 @@
 ./usr/share/man/html9/pci_intr_evcnt.html      comp-sys-htmlman        html
 ./usr/share/man/html9/pci_intr_map.html                comp-sys-htmlman        html
 ./usr/share/man/html9/pci_intr_string.html     comp-sys-htmlman        html
+./usr/share/man/html9/pci_intx_alloc.html      comp-sys-htmlman        html
+./usr/share/man/html9/pci_intx_release.html    comp-sys-htmlman        html
 ./usr/share/man/html9/pci_make_tag.html                comp-sys-htmlman        html
 ./usr/share/man/html9/pci_mapreg_info.html     comp-sys-htmlman        html
 ./usr/share/man/html9/pci_mapreg_map.html      comp-sys-htmlman        html
 ./usr/share/man/html9/pci_mapreg_type.html     comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi.html             comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_alloc.html       comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_alloc_exact.html comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_count.html       comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_disestablish.html        comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_establish.html   comp-sys-htmlman        html
+./usr/share/man/html9/pci_msi_release.html     comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix.html            comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_alloc.html      comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_alloc_exact.html        comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_alloc_map.html  comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_count.html      comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_disestablish.html       comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_establish.html  comp-sys-htmlman        html
+./usr/share/man/html9/pci_msix_release.html    comp-sys-htmlman        html
 ./usr/share/man/html9/pci_set_powerstate.html  comp-sys-htmlman        html
 ./usr/share/man/html9/pci_vpd_read.html                comp-sys-htmlman        html
 ./usr/share/man/html9/pci_vpd_write.html       comp-sys-htmlman        html
@@ -24306,10 +24323,27 @@
 ./usr/share/man/man9/pci_intr_evcnt.9          comp-sys-man            .man
 ./usr/share/man/man9/pci_intr_map.9            comp-sys-man            .man
 ./usr/share/man/man9/pci_intr_string.9         comp-sys-man            .man
+./usr/share/man/man9/pci_intx_alloc.9          comp-sys-man            .man
+./usr/share/man/man9/pci_intx_release.9                comp-sys-man            .man
 ./usr/share/man/man9/pci_make_tag.9            comp-sys-man            .man
 ./usr/share/man/man9/pci_mapreg_info.9         comp-sys-man            .man
 ./usr/share/man/man9/pci_mapreg_map.9          comp-sys-man            .man
 ./usr/share/man/man9/pci_mapreg_type.9         comp-sys-man            .man
+./usr/share/man/man9/pci_msi.9                 comp-sys-man            .man
+./usr/share/man/man9/pci_msi_alloc.9           comp-sys-man            .man
+./usr/share/man/man9/pci_msi_alloc_exact.9     comp-sys-man            .man
+./usr/share/man/man9/pci_msi_count.9           comp-sys-man            .man
+./usr/share/man/man9/pci_msi_disestablish.9    comp-sys-man            .man
+./usr/share/man/man9/pci_msi_establish.9       comp-sys-man            .man
+./usr/share/man/man9/pci_msi_release.9         comp-sys-man            .man
+./usr/share/man/man9/pci_msix.9                        comp-sys-man            .man
+./usr/share/man/man9/pci_msix_alloc.9          comp-sys-man            .man
+./usr/share/man/man9/pci_msix_alloc_exact.9    comp-sys-man            .man
+./usr/share/man/man9/pci_msix_alloc_map.9      comp-sys-man            .man
+./usr/share/man/man9/pci_msix_count.9          comp-sys-man            .man
+./usr/share/man/man9/pci_msix_disestablish.9   comp-sys-man            .man
+./usr/share/man/man9/pci_msix_establish.9      comp-sys-man            .man
+./usr/share/man/man9/pci_msix_release.9                comp-sys-man            .man
 ./usr/share/man/man9/pci_set_powerstate.9      comp-sys-man            .man
 ./usr/share/man/man9/pci_vpd_read.9            comp-sys-man            .man
 ./usr/share/man/man9/pci_vpd_write.9           comp-sys-man            .man
diff -r b1bbf24379bd -r a8084bcdc580 share/man/man9/Makefile
--- a/share/man/man9/Makefile   Mon Apr 27 06:56:53 2015 +0000
+++ b/share/man/man9/Makefile   Mon Apr 27 07:03:57 2015 +0000
@@ -1,4 +1,4 @@
-#       $NetBSD: Makefile,v 1.385 2015/04/27 06:42:52 knakahara Exp $
+#       $NetBSD: Makefile,v 1.386 2015/04/27 07:03:57 knakahara Exp $
 
 #      Makefile for section 9 (kernel function and variable) manual pages.
 
@@ -40,7 +40,7 @@
        mstohz.9 mutex.9 m_tag.9 namecache.9 \
        namei.9 nullop.9 opencrypto.9 optstr.9 \
        panic.9 pathbuf.9 pci.9 pci_configure_bus.9 pci_intr.9 \
-       pci_intr_distribute.9 pckbport.9 pcmcia.9 pcq.9 pcu.9 \
+       pci_intr_distribute.9 pci_msi.9 pckbport.9 pcmcia.9 pcq.9 pcu.9 \
        percpu.9 pfil.9 physio.9 pmap.9 pmatch.9 pmc.9 pmf.9 pool.9 \
        pool_cache.9 powerhook_establish.9 ppi.9 ppsratecheck.9 preempt.9 \
        proc_find.9 pserialize.9 putter.9 \
@@ -572,6 +572,22 @@
        pci.9 PCI_VENDOR.9 \
        pci.9 PCI_PRODUCT.9 \
        pci.9 PCI_REVISION.9
+MLINKS+=pci_msi.9 pci_msix.9 \
+       pci_msi.9 pci_intx_alloc.9 \
+       pci_msi.9 pci_intx_release.9 \
+       pci_msi.9 pci_msi_count.9 \
+       pci_msi.9 pci_msi_alloc.9 \
+       pci_msi.9 pci_msi_alloc_exact.9 \
+       pci_msi.9 pci_msi_release.9 \
+       pci_msi.9 pci_msi_establish.9 \
+       pci_msi.9 pci_msi_disestablish.9 \
+       pci_msi.9 pci_msix_count.9 \
+       pci_msi.9 pci_msix_alloc.9 \
+       pci_msi.9 pci_msix_alloc_exact.9 \
+       pci_msi.9 pci_msix_alloc_map.9 \
+       pci_msi.9 pci_msix_release.9 \
+       pci_msi.9 pci_msix_establish.9 \
+       pci_msi.9 pci_msix_disestablish.9
 MLINKS+=pci_configure_bus.9 pci_conf_hook.9 \
        pci_configure_bus.9 pci_conf_interrupt.9
 MLINKS+=pckbport.9 pckbport_attach.9 \
diff -r b1bbf24379bd -r a8084bcdc580 share/man/man9/pci_msi.9
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man9/pci_msi.9  Mon Apr 27 07:03:57 2015 +0000
@@ -0,0 +1,210 @@
+.\" $NetBSD: pci_msi.9,v 1.1 2015/04/27 07:03:57 knakahara Exp $
+.\"
+.\" 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.
+.\"
+.Dd April 8, 2015
+.Dt PCI_MSI 9 (DRAFT)
+.Os
+.Sh NAME (DRAFT)
+.Nm pci_msi ,
+.Nm pci_msix,
+.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
+.Nd PCI MSI{,-X} manipulation functions
+.Sh SYNOPSIS
+.In NOTYET
+.Ft int
+.Fn pci_msi_count "struct pci_attach_args *pa"
+.Ft int
+.Fn pci_msi_alloc  "struct pci_attach_args *pa" \
+"pci_intr_handle_t **ihps" "int *count"
+.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
+.Fn pci_msix_alloc  "struct pci_attach_args *pa" \
+"pci_intr_handle_t **ihps" "int *count"
+.Ft int
+.Fn pci_msix_alloc_exect "struct pci_attach_args *pa" \
+"pci_intr_handle_t **ihps" "int count"
+.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"
+.Sh DESCRIPTION
+XXX This decument describes draft APIs. These APIs may change later.
+.Pp
+The
+.Nm
+functions exist to allow device drivers to use MSI/MSI-X.
+When the system use MSI/MSI-X, it must define a __HAVE_PCI_MSI_MSIX
+build option.
+.Pp
+Each driver has an
+.Fn attach
+function which has a bus-specific
+.Ft attach_args
+structure.
+Each driver for a PCI device is passed a pointer to an object of type
+.Ft struct pci_attach_args
+which contains, among other things, information about the location
+of the device in the PCI bus topology sufficient to allow interrupts
+from the device to be handled.
+.Pp
+If a driver wishes to establish an MSI handler for the device,
+it should pass the
+.Ft struct pci_attach_args *
+and
+.Ft count
+.Fn pci_msi_alloc
+or
+.Fn pci_msi_alloc_exact
+functions, which returns zero on success, and nonzero on failure.
+When the functions successed, set the pointer to allocated handle
+array to
+.Ft pihs
+whose size is
+.Ft count
+or less. The difference between
+.Fn pci_msi_alloc
+and
+.Fn pci_msi_alloc_exact
+is
+.Ft count
+can be decremented or not.
+.Fn pci_msi_alloc
+can decrement
+.Ft count ,
+and
+which is similar to FreeBSD's
+.Fn pci_alloc_msi .
+In contrast,
+.Fn pci_msi_alloc_exact
+can not decrement
+.Ft count .
+.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 .
+The buffer passed to
+.Fn pci_msi_string
+should be at least
+.Dv PCI_INTRSTR_LEN
+bytes.
+.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,
+.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
+may be saved and passed to
+.Fn pci_msi_disestablish
+to disable the interrupt handler
+when the driver is no longer interested in MSIs from the device.
+After that, the driver should also
+.Fn pci_msi_release
+to free resources about MSI.
+.Pp
+If a driver wishes to establish an MSI-X handler for the device,
+it is alomost the same as MSI.
+The only differences is
+.Fn pci_msix_alloc_map .
+This function can assign each handles to MSI-X table entries.
+e.g. If the driver want assign each handler to
+.Bd -literal
+       msix_handler0 => MSI-X table index: 4
+       msix_handler1 => MSI-X table index: 5
+       msix_handler2 => MSI-X table index: 0
+.Ed
+, the driver should set
+.Bd -literal
+       table_indexes[0] = 4;
+       table_indexes[1] = 5;
+       table_indexes[2] = 0;



Home | Main Index | Thread Index | Old Index