Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Fix up bcm283[56] bus_space(4) to really use bus ad...



details:   https://anonhg.NetBSD.org/src/rev/49a1866aa427
branches:  trunk
changeset: 343408:49a1866aa427
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Feb 02 13:55:50 2016 +0000

description:
Fix up bcm283[56] bus_space(4) to really use bus addresses for
peripherals, etc

Simplifies the code in various places and uses the abstraction in
more places. (bcm2835_gpio_subr.c still doesn't)

diffstat:

 sys/arch/arm/broadcom/bcm2835_emmc.c      |  15 +++-----
 sys/arch/arm/broadcom/bcm2835_gpio.c      |  21 ++++++++----
 sys/arch/arm/broadcom/bcm2835_gpio_subr.c |  10 +++--
 sys/arch/arm/broadcom/bcm2835_pwm.c       |  11 +++---
 sys/arch/arm/broadcom/bcm2835_space.c     |  23 ++++++++++---
 sys/arch/arm/broadcom/bcm2835reg.h        |  51 ++++++++++++++----------------
 sys/arch/evbarm/rpi/rpi_machdep.c         |  17 +++-------
 7 files changed, 78 insertions(+), 70 deletions(-)

diffs (truncated from 379 to 300 lines):

diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835_emmc.c
--- a/sys/arch/arm/broadcom/bcm2835_emmc.c      Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_emmc.c      Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_emmc.c,v 1.28 2015/08/09 13:06:44 mlelstv Exp $        */
+/*     $NetBSD: bcm2835_emmc.c,v 1.29 2016/02/02 13:55:50 skrll Exp $  */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.28 2015/08/09 13:06:44 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.29 2016/02/02 13:55:50 skrll Exp $");
 
 #include "bcmdmac.h"
 
@@ -60,6 +60,7 @@
 
        bus_space_tag_t         sc_iot;
        bus_space_handle_t      sc_ioh;
+       bus_addr_t              sc_iob;
        bus_size_t              sc_ios;
        struct sdhc_host        *sc_hosts[1];
        void                    *sc_ih;
@@ -73,8 +74,6 @@
        bus_dmamap_t            sc_dmamap;
        bus_dma_segment_t       sc_segs[1];     /* XXX assumes enough descriptors fit in one page */
        struct bcm_dmac_conblk  *sc_cblk;
-
-       uint32_t                sc_physaddr;
 };
 
 static int bcmemmc_match(device_t, struct cfdata *, void *);
@@ -137,8 +136,8 @@
                    "can't map registers for %s: %d\n", aaa->aaa_name, error);
                return;
        }
+       sc->sc_iob = aaa->aaa_addr;
        sc->sc_ios = aaa->aaa_size;
-       sc->sc_physaddr = aaa->aaa_addr;
 
        aprint_naive(": SDHC controller\n");
        aprint_normal(": SDHC controller\n");
@@ -267,8 +266,7 @@
                                sc->sc_cblk[seg].cb_ti |= DMAC_TI_DEST_WIDTH;
                        sc->sc_cblk[seg].cb_ti |= DMAC_TI_SRC_DREQ;
                        sc->sc_cblk[seg].cb_source_ad =
-                           BCM2835_PERIPHERALS_TO_BUS(sc->sc_physaddr +
-                           SDHC_DATA);
+                           sc->sc_iob + SDHC_DATA;
                        sc->sc_cblk[seg].cb_dest_ad =
                            cmd->c_dmamap->dm_segs[seg].ds_addr;
                } else {
@@ -284,8 +282,7 @@
                        sc->sc_cblk[seg].cb_source_ad =
                            cmd->c_dmamap->dm_segs[seg].ds_addr;
                        sc->sc_cblk[seg].cb_dest_ad =
-                           BCM2835_PERIPHERALS_TO_BUS(sc->sc_physaddr +
-                           SDHC_DATA);
+                           sc->sc_iob + SDHC_DATA;
                }
                sc->sc_cblk[seg].cb_stride = 0;
                if (seg == cmd->c_dmamap->dm_nsegs - 1) {
diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835_gpio.c
--- a/sys/arch/arm/broadcom/bcm2835_gpio.c      Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_gpio.c      Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_gpio.c,v 1.2 2014/05/19 08:33:41 skrll Exp $   */
+/*     $NetBSD: bcm2835_gpio.c,v 1.3 2016/02/02 13:55:50 skrll Exp $   */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio.c,v 1.2 2014/05/19 08:33:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio.c,v 1.3 2016/02/02 13:55:50 skrll Exp $");
 
 /*
  * Driver for BCM2835 GPIO
@@ -101,9 +101,11 @@
 {
        struct bcmgpio_softc * const sc = device_private(self);
 #if NGPIO > 0
+       struct amba_attach_args *aaa = aux;
+       struct gpiobus_attach_args gba;
        int pin, minpin, maxpin;
        u_int func;
-       struct gpiobus_attach_args gba;
+       int error;
 #endif
        
        sc->sc_dev = self;
@@ -124,10 +126,15 @@
        aprint_naive("\n");     
        aprint_normal(": GPIO [%d...%d]\n", minpin, maxpin);
 
-       /* already mapped - nothing to gain from struct amba_attach_args */
-       sc->sc_iot = &bcm2835_bs_tag;
-       sc->sc_ioh = BCM2835_IOPHYSTOVIRT(BCM2835_GPIO_BASE);
-       
+       sc->sc_iot = aaa->aaa_iot;
+       error = bus_space_map(sc->sc_iot, aaa->aaa_addr, aaa->aaa_size, 0,
+           &sc->sc_ioh);
+       if (error) {
+               aprint_error_dev(self,
+                   "can't map registers for %s: %d\n", aaa->aaa_name, error);
+               return;
+       }
+
        for (pin = minpin; pin <= maxpin; pin++) {
                int epin = pin - minpin;
        
diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835_gpio_subr.c
--- a/sys/arch/arm/broadcom/bcm2835_gpio_subr.c Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_gpio_subr.c Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_gpio_subr.c,v 1.3 2014/04/22 18:51:35 kardel Exp $     */
+/*     $NetBSD: bcm2835_gpio_subr.c,v 1.4 2016/02/02 13:55:50 skrll Exp $      */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio_subr.c,v 1.3 2014/04/22 18:51:35 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_gpio_subr.c,v 1.4 2016/02/02 13:55:50 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -43,8 +43,9 @@
 void
 bcm2835gpio_function_select(u_int pin, u_int func)
 {
+       const paddr_t iop = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_GPIO_BASE);
        const bus_space_tag_t iot = &bcm2835_bs_tag;
-       const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(BCM2835_GPIO_BASE);
+       const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(iop);
        const u_int mask = (1 << BCM2835_GPIO_GPFSEL_BITS_PER_PIN) - 1;
        const u_int regid = (pin / BCM2835_GPIO_GPFSEL_PINS_PER_REGISTER);
        const u_int shift = (pin % BCM2835_GPIO_GPFSEL_PINS_PER_REGISTER) *
@@ -70,8 +71,9 @@
 u_int
 bcm2835gpio_function_read(u_int pin)
 {
+       const paddr_t iop = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_GPIO_BASE);
        const bus_space_tag_t iot = &bcm2835_bs_tag;
-       const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(BCM2835_GPIO_BASE);
+       const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(iop);
        const u_int mask = (1 << BCM2835_GPIO_GPFSEL_BITS_PER_PIN) - 1;
        const u_int regid = (pin / BCM2835_GPIO_GPFSEL_PINS_PER_REGISTER);
        const u_int shift = (pin % BCM2835_GPIO_GPFSEL_PINS_PER_REGISTER) *
diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835_pwm.c
--- a/sys/arch/arm/broadcom/bcm2835_pwm.c       Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_pwm.c       Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_pwm.c,v 1.1 2015/11/21 07:41:29 mlelstv Exp $ */
+/*     $NetBSD: bcm2835_pwm.c,v 1.2 2016/02/02 13:55:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_pwm.c,v 1.1 2015/11/21 07:41:29 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_pwm.c,v 1.2 2016/02/02 13:55:50 skrll Exp $");
 
 #include "bcmdmac.h"
 
@@ -67,12 +67,11 @@
 
        bus_space_tag_t         sc_iot;
        bus_space_handle_t      sc_ioh;
+       bus_addr_t              sc_iob;
 
        int                     sc_clockrate;
        struct bcm_pwm_channel  sc_channels[2];
        kmutex_t                sc_lock;
-
-       uint32_t                sc_physaddr;
 };
 
 #define PWM_WRITE(sc, reg, val) \
@@ -114,7 +113,7 @@
 
        sc->sc_dev = self;
        sc->sc_iot = aaa->aaa_iot;
-       sc->sc_physaddr = aaa->aaa_addr;
+       sc->sc_iob = aaa->aaa_addr;
 
        if (bus_space_map(aaa->aaa_iot, aaa->aaa_addr, BCM2835_PWM_SIZE, 0,
            &sc->sc_ioh)) {
@@ -336,6 +335,6 @@
 {
        struct bcm2835pwm_softc *sc = pwm->sc;
 
-       return BCM2835_PERIPHERALS_TO_BUS(sc->sc_physaddr + PWM_FIFO);
+       return sc->sc_iob + PWM_FIFO;
 }
 
diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835_space.c
--- a/sys/arch/arm/broadcom/bcm2835_space.c     Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_space.c     Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835_space.c,v 1.9 2015/12/19 08:27:01 skrll Exp $  */
+/*     $NetBSD: bcm2835_space.c,v 1.10 2016/02/02 13:55:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_space.c,v 1.9 2015/12/19 08:27:01 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_space.c,v 1.10 2016/02/02 13:55:50 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -290,11 +290,24 @@
        vaddr_t va;
        const struct pmap_devmap *pd;
        int pmap_flags;
-
+       bool match = false;
 
        /* Attempt to find the PA device mapping */
-       pa = ba;
-       if ((pd = pmap_devmap_find_pa(ba, size)) != NULL) {
+       if (ba >= BCM2835_PERIPHERALS_BASE_BUS &&
+           ba < BCM2835_PERIPHERALS_BASE_BUS + BCM2835_PERIPHERALS_SIZE) {
+               match = true;
+               pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(ba);
+               
+       }
+#ifdef BCM2836
+       if (ba >= BCM2836_ARM_LOCAL_BASE &&
+           ba < BCM2836_ARM_LOCAL_BASE + BCM2836_ARM_LOCAL_SIZE) {
+               match = true;
+               pa = ba;
+       }
+#endif
+
+       if (match && (pd = pmap_devmap_find_pa(pa, size)) != NULL) {
                /* Device was statically mapped. */
                *bshp = pd->pd_va + (pa - pd->pd_pa);
                return 0;
diff -r 0cf4f12e19af -r 49a1866aa427 sys/arch/arm/broadcom/bcm2835reg.h
--- a/sys/arch/arm/broadcom/bcm2835reg.h        Tue Feb 02 13:07:30 2016 +0000
+++ b/sys/arch/arm/broadcom/bcm2835reg.h        Tue Feb 02 13:55:50 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bcm2835reg.h,v 1.17 2015/12/17 08:31:50 skrll Exp $    */
+/*     $NetBSD: bcm2835reg.h,v 1.18 2016/02/02 13:55:50 skrll Exp $    */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -46,29 +46,32 @@
 #define        BCM2835_PERIPHERALS_BASE        0x20000000
 #endif
 #define        BCM2835_PERIPHERALS_SIZE        0x01000000      /* 16MBytes */
+
 #define        BCM2835_PERIPHERALS_BASE_BUS    0x7e000000
-#define        BCM2835_PERIPHERALS_TO_BUS(a) \
+#define        BCM2835_PERIPHERALS_PHYS_TO_BUS(a) \
     ((a) - BCM2835_PERIPHERALS_BASE + BCM2835_PERIPHERALS_BASE_BUS)
+#define        BCM2835_PERIPHERALS_BUS_TO_PHYS(a) \
+    ((a) - BCM2835_PERIPHERALS_BASE_BUS + BCM2835_PERIPHERALS_BASE)
 
-#define        BCM2835_STIMER_BASE     (BCM2835_PERIPHERALS_BASE + 0x00003000)
-#define        BCM2835_DMA0_BASE       (BCM2835_PERIPHERALS_BASE + 0x00007000)
-#define        BCM2835_ARM_BASE        (BCM2835_PERIPHERALS_BASE + 0x0000B000)
-#define        BCM2835_PM_BASE         (BCM2835_PERIPHERALS_BASE + 0x00100000)
-#define        BCM2835_CM_BASE         (BCM2835_PERIPHERALS_BASE + 0x00101000)
-#define        BCM2835_RNG_BASE        (BCM2835_PERIPHERALS_BASE + 0x00104000)
-#define        BCM2835_GPIO_BASE       (BCM2835_PERIPHERALS_BASE + 0x00200000)
-#define        BCM2835_UART0_BASE      (BCM2835_PERIPHERALS_BASE + 0x00201000)
-#define        BCM2835_PCM_BASE        (BCM2835_PERIPHERALS_BASE + 0x00203000)
-#define        BCM2835_SPI0_BASE       (BCM2835_PERIPHERALS_BASE + 0x00204000)
-#define        BCM2835_BSC0_BASE       (BCM2835_PERIPHERALS_BASE + 0x00205000)
-#define        BCM2835_PWM_BASE        (BCM2835_PERIPHERALS_BASE + 0x0020C000)
-#define        BCM2835_BSCSPISLV_BASE  (BCM2835_PERIPHERALS_BASE + 0x00214000)
-#define        BCM2835_AUX_BASE        (BCM2835_PERIPHERALS_BASE + 0x00215000)
-#define        BCM2835_EMMC_BASE       (BCM2835_PERIPHERALS_BASE + 0x00300000)
-#define        BCM2835_BSC1_BASE       (BCM2835_PERIPHERALS_BASE + 0x00804000)
-#define        BCM2835_BSC2_BASE       (BCM2835_PERIPHERALS_BASE + 0x00805000)
-#define        BCM2835_USB_BASE        (BCM2835_PERIPHERALS_BASE + 0x00980000)
-#define        BCM2835_DMA15_BASE      (BCM2835_PERIPHERALS_BASE + 0x00E05000)
+#define        BCM2835_STIMER_BASE     (BCM2835_PERIPHERALS_BASE_BUS + 0x00003000)
+#define        BCM2835_DMA0_BASE       (BCM2835_PERIPHERALS_BASE_BUS + 0x00007000)
+#define        BCM2835_ARM_BASE        (BCM2835_PERIPHERALS_BASE_BUS + 0x0000B000)
+#define        BCM2835_PM_BASE         (BCM2835_PERIPHERALS_BASE_BUS + 0x00100000)
+#define        BCM2835_CM_BASE         (BCM2835_PERIPHERALS_BASE_BUS + 0x00101000)
+#define        BCM2835_RNG_BASE        (BCM2835_PERIPHERALS_BASE_BUS + 0x00104000)
+#define        BCM2835_GPIO_BASE       (BCM2835_PERIPHERALS_BASE_BUS + 0x00200000)
+#define        BCM2835_UART0_BASE      (BCM2835_PERIPHERALS_BASE_BUS + 0x00201000)
+#define        BCM2835_PCM_BASE        (BCM2835_PERIPHERALS_BASE_BUS + 0x00203000)



Home | Main Index | Thread Index | Old Index