From 834ff46cdc127050471ec5871d62421e559b5881 Mon Sep 17 00:00:00 2001 From: dlg Date: Wed, 19 Apr 2023 02:01:02 +0000 Subject: [PATCH] dwmshc on rockchips don't support dma crossy 128M boundaries. let controllers pass the dma boundaries to sdmmc as part of the attach args so it can be used for the bus_dmamap_create. add the boundary to sdhci so dwmshc can set it to be bassed to sdmmc. tested on a radxa e25 booting and rooting off the onboard emmc. before this diff some programs would fault with weird instructions. --- sys/dev/fdt/dwmshc.c | 3 ++- sys/dev/sdmmc/sdhc.c | 3 ++- sys/dev/sdmmc/sdhcvar.h | 3 ++- sys/dev/sdmmc/sdmmc.c | 5 +++-- sys/dev/sdmmc/sdmmcchip.h | 3 ++- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sys/dev/fdt/dwmshc.c b/sys/dev/fdt/dwmshc.c index 4999e819101..9a7ffdd16ab 100644 --- a/sys/dev/fdt/dwmshc.c +++ b/sys/dev/fdt/dwmshc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwmshc.c,v 1.3 2023/04/19 01:41:12 dlg Exp $ */ +/* $OpenBSD: dwmshc.c,v 1.4 2023/04/19 02:01:02 dlg Exp $ */ /* * Copyright (c) 2023 David Gwynne @@ -231,6 +231,7 @@ dwmshc_attach(struct device *parent, struct device *self, void *aux) sdhc->sc_host = &sc->sc_host; sdhc->sc_dmat = faa->fa_dmat; + sdhc->sc_dma_boundary = 128 * 1024 * 1024; sdhc->sc_bus_clock_pre = dwmshc_clock_pre; sdhc->sc_bus_clock_post = dwmshc_clock_post; diff --git a/sys/dev/sdmmc/sdhc.c b/sys/dev/sdmmc/sdhc.c index 2ed10fea48b..2f3a6f4bce7 100644 --- a/sys/dev/sdmmc/sdhc.c +++ b/sys/dev/sdmmc/sdhc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdhc.c,v 1.74 2023/04/11 00:45:09 jsg Exp $ */ +/* $OpenBSD: sdhc.c,v 1.75 2023/04/19 02:01:02 dlg Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -397,6 +397,7 @@ sdhc_host_found(struct sdhc_softc *sc, bus_space_tag_t iot, saa.sch = hp; saa.caps = SMC_CAPS_4BIT_MODE; saa.dmat = sc->sc_dmat; + saa.dma_boundary = sc->sc_dma_boundary; if (ISSET(hp->flags, SHF_USE_DMA)) saa.caps |= SMC_CAPS_DMA; diff --git a/sys/dev/sdmmc/sdhcvar.h b/sys/dev/sdmmc/sdhcvar.h index fd964167f11..a4280bee1e1 100644 --- a/sys/dev/sdmmc/sdhcvar.h +++ b/sys/dev/sdmmc/sdhcvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sdhcvar.h,v 1.16 2022/01/18 11:36:21 patrick Exp $ */ +/* $OpenBSD: sdhcvar.h,v 1.17 2023/04/19 02:01:02 dlg Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -31,6 +31,7 @@ struct sdhc_softc { u_int sc_clkbase; bus_dma_tag_t sc_dmat; + bus_size_t sc_dma_boundary; void (*sc_bus_clock_pre)(struct sdhc_softc *, int, int); void (*sc_bus_clock_post)(struct sdhc_softc *, int, int); diff --git a/sys/dev/sdmmc/sdmmc.c b/sys/dev/sdmmc/sdmmc.c index 751e9d15021..7950050477d 100644 --- a/sys/dev/sdmmc/sdmmc.c +++ b/sys/dev/sdmmc/sdmmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmc.c,v 1.60 2022/09/03 15:29:43 kettenis Exp $ */ +/* $OpenBSD: sdmmc.c,v 1.61 2023/04/19 02:01:02 dlg Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -138,7 +138,8 @@ sdmmc_attach(struct device *parent, struct device *self, void *aux) if (ISSET(sc->sc_caps, SMC_CAPS_DMA) && sc->sc_dmap == NULL) { error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, SDMMC_MAXNSEGS, - sc->sc_max_seg, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, + sc->sc_max_seg, saa->dma_boundary, + BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW, &sc->sc_dmap); if (error) { printf("%s: can't create DMA map\n", DEVNAME(sc)); diff --git a/sys/dev/sdmmc/sdmmcchip.h b/sys/dev/sdmmc/sdmmcchip.h index 042f6993f45..7c232c58940 100644 --- a/sys/dev/sdmmc/sdmmcchip.h +++ b/sys/dev/sdmmc/sdmmcchip.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmcchip.h,v 1.14 2020/08/14 14:49:04 kettenis Exp $ */ +/* $OpenBSD: sdmmcchip.h,v 1.15 2023/04/19 02:01:02 dlg Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -112,6 +112,7 @@ struct sdmmcbus_attach_args { int caps; long max_seg; long max_xfer; + bus_size_t dma_boundary; void *cookies[SDMMC_MAX_FUNCTIONS]; }; -- 2.20.1