Source-Changes-HG archive

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

[src/trunk]: src/sys/arch On second thought, get rid of "bs_base" from struct...



details:   https://anonhg.NetBSD.org/src/rev/478c7d70fdd6
branches:  trunk
changeset: 445984:478c7d70fdd6
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Nov 19 10:45:47 2018 +0000

description:
On second thought, get rid of "bs_base" from struct bus_space and use a
custom bs_map for acpipchb instead.

diffstat:

 sys/arch/aarch64/aarch64/bus_space.c     |  12 +------
 sys/arch/arm/acpi/acpipchb.c             |  50 ++++++++++++++++++++++++-------
 sys/arch/arm/arm32/armv7_generic_space.c |   8 +---
 sys/arch/arm/include/bus_defs.h          |   3 +-
 4 files changed, 44 insertions(+), 29 deletions(-)

diffs (223 lines):

diff -r c1935f73820e -r 478c7d70fdd6 sys/arch/aarch64/aarch64/bus_space.c
--- a/sys/arch/aarch64/aarch64/bus_space.c      Mon Nov 19 10:14:40 2018 +0000
+++ b/sys/arch/aarch64/aarch64/bus_space.c      Mon Nov 19 10:45:47 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_space.c,v 1.6 2018/11/18 20:21:48 jmcneill Exp $ */
+/* $NetBSD: bus_space.c,v 1.7 2018/11/19 10:45:47 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: bus_space.c,v 1.6 2018/11/18 20:21:48 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: bus_space.c,v 1.7 2018/11/19 10:45:47 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -46,7 +46,6 @@
 struct bus_space arm_generic_bs_tag = {
        .bs_cookie = &arm_generic_bs_tag,
 
-       .bs_base = 0,
        .bs_stride = 0,
        .bs_flags = 0,
 
@@ -169,7 +168,6 @@
 struct bus_space aarch64_generic_dsb_bs_tag = {
        .bs_cookie = &aarch64_generic_dsb_bs_tag,
 
-       .bs_base = 0,
        .bs_stride = 0,
        .bs_flags = 0,
 
@@ -292,7 +290,6 @@
 struct bus_space arm_generic_a4x_bs_tag = {
        .bs_cookie = &arm_generic_a4x_bs_tag,
 
-       .bs_base = 0,
        .bs_stride = 2,
        .bs_flags = 0,
 
@@ -415,7 +412,6 @@
 struct bus_space aarch64_generic_a4x_dsb_bs_tag = {
        .bs_cookie = &aarch64_generic_a4x_dsb_bs_tag,
 
-       .bs_base = 0,
        .bs_stride = 2,
        .bs_flags = 0,
 
@@ -539,15 +535,11 @@
 generic_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag,
     bus_space_handle_t *bshp)
 {
-       const struct bus_space *bs = t;
        const struct pmap_devmap *pd;
        paddr_t startpa, endpa, pa;
        vaddr_t va;
        int pmapflags;
 
-       if (bs)
-               bpa += bs->bs_base;
-
        if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
                *bshp = pd->pd_va + (bpa - pd->pd_pa);
                return 0;
diff -r c1935f73820e -r 478c7d70fdd6 sys/arch/arm/acpi/acpipchb.c
--- a/sys/arch/arm/acpi/acpipchb.c      Mon Nov 19 10:14:40 2018 +0000
+++ b/sys/arch/arm/acpi/acpipchb.c      Mon Nov 19 10:45:47 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpipchb.c,v 1.6 2018/11/18 20:22:20 jmcneill Exp $ */
+/* $NetBSD: acpipchb.c,v 1.7 2018/11/19 10:45:47 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpipchb.c,v 1.6 2018/11/18 20:22:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpipchb.c,v 1.7 2018/11/19 10:45:47 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -59,6 +59,17 @@
 
 #define        PCIHOST_CACHELINE_SIZE          arm_dcache_align
 
+struct acpipchb_bus_space {
+       struct bus_space        bs;
+
+       bus_addr_t              min;
+       bus_addr_t              max;
+       bus_addr_t              offset;
+
+       int                     (*map)(void *, bus_addr_t, bus_size_t,
+                                      int, bus_space_handle_t *);
+};
+
 struct acpipchb_softc {
        device_t                sc_dev;
 
@@ -68,7 +79,7 @@
        ACPI_HANDLE             sc_handle;
        ACPI_INTEGER            sc_bus;
 
-       struct bus_space        sc_pciio_bst;
+       struct acpipchb_bus_space sc_pciio_bst;
 };
 
 static struct arm32_dma_range ahcipchb_coherent_ranges[] = {
@@ -163,11 +174,24 @@
        struct pcibus_attach_args *pba;
 };
 
+static int
+acpipchb_bus_space_map(void *t, bus_addr_t bpa, bus_size_t size, int flag,
+    bus_space_handle_t *bshp)
+{
+       struct acpipchb_bus_space * const abs = t;
+
+       if (bpa < abs->min || bpa + size >= abs->max)
+               return ERANGE;
+
+       return abs->map(t, bpa + abs->offset, size, flag, bshp);
+}
+
 static ACPI_STATUS
 acpipchb_setup_pciio_cb(ACPI_RESOURCE *res, void *ctx)
 {
        struct acpipchb_setup_pciio_args * const args = ctx;
        struct acpipchb_softc * const sc = args->sc;
+       struct acpipchb_bus_space * const abs = &sc->sc_pciio_bst;
        struct pcibus_attach_args *pba = args->pba;
 
        if (res->Type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
@@ -177,23 +201,27 @@
        if (res->Data.Address.ResourceType != ACPI_IO_RANGE)
                return AE_OK;
 
-       sc->sc_pciio_bst = *pba->pba_memt;
-       sc->sc_pciio_bst.bs_cookie = &sc->sc_pciio_bst;
+       abs->bs = *pba->pba_memt;
+       abs->bs.bs_cookie = abs;
+       abs->map = abs->bs.bs_map;
+       abs->bs.bs_map = acpipchb_bus_space_map;
 
        switch (res->Type) {
        case ACPI_RESOURCE_TYPE_ADDRESS32:
-               sc->sc_pciio_bst.bs_base = res->Data.Address32.Address.TranslationOffset;
-               sc->sc_pciio_bst.bs_stride = res->Data.Address32.Address.Granularity;
+               abs->min = res->Data.Address32.Address.Minimum;
+               abs->max = res->Data.Address32.Address.Maximum;
+               abs->offset = res->Data.Address32.Address.TranslationOffset;
                break;
        case ACPI_RESOURCE_TYPE_ADDRESS64:
-               sc->sc_pciio_bst.bs_base = res->Data.Address64.Address.TranslationOffset;
-               sc->sc_pciio_bst.bs_stride = res->Data.Address64.Address.Granularity;
+               abs->min = res->Data.Address64.Address.Minimum;
+               abs->max = res->Data.Address64.Address.Maximum;
+               abs->offset = res->Data.Address64.Address.TranslationOffset;
                break;
        }
 
-       aprint_debug_dev(sc->sc_dev, "PCI I/O base %#lx stride %d\n", sc->sc_pciio_bst.bs_base, sc->sc_pciio_bst.bs_stride);
+       aprint_debug_dev(sc->sc_dev, "PCI I/O [%#lx-%#lx] -> %#lx\n", abs->min, abs->max, abs->offset);
 
-       pba->pba_iot = &sc->sc_pciio_bst;
+       pba->pba_iot = &sc->sc_pciio_bst.bs;
        pba->pba_flags |= PCI_FLAGS_IO_OKAY;
 
        return AE_LIMIT;
diff -r c1935f73820e -r 478c7d70fdd6 sys/arch/arm/arm32/armv7_generic_space.c
--- a/sys/arch/arm/arm32/armv7_generic_space.c  Mon Nov 19 10:14:40 2018 +0000
+++ b/sys/arch/arm/arm32/armv7_generic_space.c  Mon Nov 19 10:45:47 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: armv7_generic_space.c,v 1.9 2018/11/18 20:21:48 jmcneill Exp $ */
+/*     $NetBSD: armv7_generic_space.c,v 1.10 2018/11/19 10:45:47 jmcneill Exp $        */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: armv7_generic_space.c,v 1.9 2018/11/18 20:21:48 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: armv7_generic_space.c,v 1.10 2018/11/19 10:45:47 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -291,15 +291,11 @@
 armv7_generic_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag,
     bus_space_handle_t *bshp)
 {
-       const struct bus_space *bs = t;
        u_long startpa, endpa, pa;
        const struct pmap_devmap *pd;
        int pmapflags;
        vaddr_t va;
 
-       if (bs)
-               bpa += bs->bs_base;
-
        if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
                /* Device was statically mapped. */
                *bshp = pd->pd_va + (bpa - pd->pd_pa);
diff -r c1935f73820e -r 478c7d70fdd6 sys/arch/arm/include/bus_defs.h
--- a/sys/arch/arm/include/bus_defs.h   Mon Nov 19 10:14:40 2018 +0000
+++ b/sys/arch/arm/include/bus_defs.h   Mon Nov 19 10:45:47 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_defs.h,v 1.12 2018/11/18 20:21:48 jmcneill Exp $   */
+/*     $NetBSD: bus_defs.h,v 1.13 2018/11/19 10:45:47 jmcneill Exp $   */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -102,7 +102,6 @@
        void            *bs_cookie;
 
        /* used for aarch64. require ".bs_cookie = bus_space" */
-       bus_addr_t      bs_base;
        int             bs_stride;      /* offset <<= bs_stride (if needed) */
        int             bs_flags;
 



Home | Main Index | Thread Index | Old Index