Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm Add support for decoding PCI ID mappings using ...



details:   https://anonhg.NetBSD.org/src/rev/c775fcfad396
branches:  trunk
changeset: 837508:c775fcfad396
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Dec 08 15:04:40 2018 +0000

description:
Add support for decoding PCI ID mappings using IO remapping tables (IORT).

diffstat:

 sys/arch/arm/acpi/acpi_iort.c        |  110 +++++++++++++++++++++++++++++++++++
 sys/arch/arm/acpi/acpi_iort.h        |   37 +++++++++++
 sys/arch/arm/acpi/acpi_pci_machdep.c |   15 ++++-
 sys/arch/arm/acpi/files.acpi         |    3 +-
 sys/arch/arm/cortex/gicv3_its.c      |    9 +-
 sys/arch/arm/include/pci_machdep.h   |    5 +-
 6 files changed, 172 insertions(+), 7 deletions(-)

diffs (289 lines):

diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/acpi/acpi_iort.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/acpi/acpi_iort.c     Sat Dec 08 15:04:40 2018 +0000
@@ -0,0 +1,110 @@
+/* $NetBSD: acpi_iort.c,v 1.1 2018/12/08 15:04:40 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_iort.c,v 1.1 2018/12/08 15:04:40 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <arm/acpi/acpi_iort.h>
+
+static ACPI_IORT_ID_MAPPING *
+acpi_iort_id_map(ACPI_IORT_NODE *node, uint32_t *id)
+{
+       ACPI_IORT_ID_MAPPING *map;
+       uint32_t offset, n;
+
+       offset = node->MappingOffset;
+       for (n = 0; n < node->MappingCount; n++) {
+               map = ACPI_ADD_PTR(ACPI_IORT_ID_MAPPING, node, offset);
+               if (map->Flags & ACPI_IORT_ID_SINGLE_MAPPING) {
+                       *id = map->InputBase;
+                       return map;
+               }
+               if (*id >= map->InputBase && *id <= map->InputBase + map->IdCount) {
+                       *id = *id - map->InputBase + map->OutputBase;
+                       return map;
+               }
+               offset += sizeof(ACPI_IORT_ID_MAPPING);
+       }
+
+       return NULL;
+}
+
+static ACPI_IORT_NODE *
+acpi_iort_find_ref(ACPI_TABLE_IORT *iort, ACPI_IORT_NODE *node, uint32_t *id)
+{
+       ACPI_IORT_ID_MAPPING *map;
+
+       map = acpi_iort_id_map(node, id);
+       if (map == NULL)
+               return NULL;
+
+       return ACPI_ADD_PTR(ACPI_IORT_NODE, iort, map->OutputReference);
+}
+
+uint32_t
+acpi_iort_pci_root_map(u_int seg, uint32_t devid)
+{
+       ACPI_TABLE_IORT *iort;
+       ACPI_IORT_NODE *node;
+       ACPI_IORT_ROOT_COMPLEX *root;
+       uint32_t offset, n;
+       ACPI_STATUS rv;
+
+       rv = AcpiGetTable(ACPI_SIG_IORT, 0, (ACPI_TABLE_HEADER **)&iort);
+       if (ACPI_FAILURE(rv))
+               return devid;
+
+       offset = iort->NodeOffset;
+       for (n = 0; n < iort->NodeCount; n++) {
+               node = ACPI_ADD_PTR(ACPI_IORT_NODE, iort, offset);
+               if (node->Type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
+                       root = (ACPI_IORT_ROOT_COMPLEX *)node->NodeData;
+                       if (root->PciSegmentNumber == seg) {
+                               const uint32_t odevid = devid;
+                               do {
+                                       node = acpi_iort_find_ref(iort, node, &devid);
+                               } while (node != NULL);
+                               aprint_debug("ACPI: IORT remapped devid %#x -> %#x\n", odevid, devid);
+                               return devid;
+                       }
+               }
+               offset += node->Length;
+       }
+
+       return devid;
+}
diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/acpi/acpi_iort.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/acpi/acpi_iort.h     Sat Dec 08 15:04:40 2018 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: acpi_iort.h,v 1.1 2018/12/08 15:04:40 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * 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 _ARM_ACPI_ACPI_IORT_H
+#define _ARM_ACPI_ACPI_IORT_H
+
+uint32_t       acpi_iort_pci_root_map(u_int, uint32_t);
+
+#endif /* !_ARM_ACPI_ACPI_IORT_H */
diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/acpi/acpi_pci_machdep.c
--- a/sys/arch/arm/acpi/acpi_pci_machdep.c      Sat Dec 08 15:02:06 2018 +0000
+++ b/sys/arch/arm/acpi/acpi_pci_machdep.c      Sat Dec 08 15:04:40 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci_machdep.c,v 1.8 2018/11/16 15:06:21 jmcneill Exp $ */
+/* $NetBSD: acpi_pci_machdep.c,v 1.9 2018/12/08 15:04:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.8 2018/11/16 15:06:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_machdep.c,v 1.9 2018/12/08 15:04:40 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -55,6 +55,7 @@
 #include <dev/acpi/acpi_mcfg.h>
 #include <dev/acpi/acpi_pci.h>
 
+#include <arm/acpi/acpi_iort.h>
 #include <arm/acpi/acpi_pci_machdep.h>
 
 #include <arm/pci/pci_msi_machdep.h>
@@ -75,6 +76,7 @@
 static pcitag_t        acpi_pci_md_make_tag(void *, int, int, int);
 static void    acpi_pci_md_decompose_tag(void *, pcitag_t, int *, int *, int *);
 static u_int   acpi_pci_md_get_segment(void *);
+static uint32_t        acpi_pci_md_get_devid(void *, uint32_t);
 static pcireg_t        acpi_pci_md_conf_read(void *, pcitag_t, int);
 static void    acpi_pci_md_conf_write(void *, pcitag_t, int, pcireg_t);
 static int     acpi_pci_md_conf_hook(void *, int, int, int, pcireg_t);
@@ -98,6 +100,7 @@
        .pc_make_tag = acpi_pci_md_make_tag,
        .pc_decompose_tag = acpi_pci_md_decompose_tag,
        .pc_get_segment = acpi_pci_md_get_segment,
+       .pc_get_devid = acpi_pci_md_get_devid,
        .pc_conf_read = acpi_pci_md_conf_read,
        .pc_conf_write = acpi_pci_md_conf_write,
        .pc_conf_hook = acpi_pci_md_conf_hook,
@@ -240,6 +243,14 @@
        return ap->ap_seg;
 }
 
+static uint32_t
+acpi_pci_md_get_devid(void *v, uint32_t devid)
+{
+       struct acpi_pci_context * const ap = v;
+
+       return acpi_iort_pci_root_map(ap->ap_seg, devid);
+}
+
 static pcireg_t
 acpi_pci_md_conf_read(void *v, pcitag_t tag, int offset)
 {
diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/acpi/files.acpi
--- a/sys/arch/arm/acpi/files.acpi      Sat Dec 08 15:02:06 2018 +0000
+++ b/sys/arch/arm/acpi/files.acpi      Sat Dec 08 15:04:40 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.acpi,v 1.5 2018/11/12 12:56:05 jmcneill Exp $
+#      $NetBSD: files.acpi,v 1.6 2018/12/08 15:04:40 jmcneill Exp $
 #
 # Configuration info for ACPI compliant ARM boards.
 #
@@ -10,6 +10,7 @@
 
 include "dev/acpi/files.acpi"
 
+file   arch/arm/acpi/acpi_iort.c               acpi
 file   arch/arm/acpi/acpi_machdep.c            acpi
 file   arch/arm/acpi/acpi_pci_machdep.c        acpi & pci
 file   arch/arm/acpi/acpi_platform.c           acpi
diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/cortex/gicv3_its.c
--- a/sys/arch/arm/cortex/gicv3_its.c   Sat Dec 08 15:02:06 2018 +0000
+++ b/sys/arch/arm/cortex/gicv3_its.c   Sat Dec 08 15:04:40 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3_its.c,v 1.9 2018/11/28 22:54:11 jmcneill Exp $ */
+/* $NetBSD: gicv3_its.c,v 1.10 2018/12/08 15:04:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #define _INTR_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.9 2018/11/28 22:54:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.10 2018/12/08 15:04:40 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -282,11 +282,14 @@
 static uint32_t
 gicv3_its_devid(pci_chipset_tag_t pc, pcitag_t tag)
 {
+       uint32_t devid;
        int b, d, f;
 
        pci_decompose_tag(pc, tag, &b, &d, &f);
 
-       return (b << 8) | (d << 3) | f;
+       devid = (b << 8) | (d << 3) | f;
+
+       return pci_get_devid(pc, devid);
 }
 
 static int
diff -r 62cacf9b1f68 -r c775fcfad396 sys/arch/arm/include/pci_machdep.h
--- a/sys/arch/arm/include/pci_machdep.h        Sat Dec 08 15:02:06 2018 +0000
+++ b/sys/arch/arm/include/pci_machdep.h        Sat Dec 08 15:04:40 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.h,v 1.16 2018/11/16 15:06:22 jmcneill Exp $        */
+/*     $NetBSD: pci_machdep.h,v 1.17 2018/12/08 15:04:40 jmcneill Exp $        */
 
 /*
  * Modified for arm32 by Mark Brinicombe
@@ -92,6 +92,7 @@
        void            (*pc_decompose_tag)(void *, pcitag_t, int *,
                            int *, int *);
        u_int           (*pc_get_segment)(void *);
+       uint32_t        (*pc_get_devid)(void *, uint32_t);
        pcireg_t        (*pc_conf_read)(void *, pcitag_t, int);
        void            (*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
 
@@ -148,6 +149,8 @@
     (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
 #define pci_get_segment(c)                                             \
     ((c)->pc_get_segment ? (*(c)->pc_get_segment)((c)->pc_conf_v) : 0)
+#define pci_get_devid(c, d)                                            \
+    ((c)->pc_get_devid ? (*(c)->pc_get_devid)((c)->pc_conf_v, (d)) : (d))
 #define        pci_conf_read(c, t, r)                                          \
     (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
 #define        pci_conf_write(c, t, r, v)                                      \



Home | Main Index | Thread Index | Old Index