Mon Dec 30 19:50:29 2019 UTC ()
If a device node is a child of a module device, and the module device declares DMA range restrictions, use them.


(jmcneill)
diff -r1.14 -r1.15 src/sys/arch/arm/acpi/acpi_machdep.c

cvs diff -r1.14 -r1.15 src/sys/arch/arm/acpi/acpi_machdep.c (expand / switch to unified diff)

--- src/sys/arch/arm/acpi/acpi_machdep.c 2019/12/29 23:47:56 1.14
+++ src/sys/arch/arm/acpi/acpi_machdep.c 2019/12/30 19:50:29 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_machdep.c,v 1.14 2019/12/29 23:47:56 jmcneill Exp $ */ 1/* $NetBSD: acpi_machdep.c,v 1.15 2019/12/30 19:50:29 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jared McNeill <jmcneill@invisible.ca>. 8 * by Jared McNeill <jmcneill@invisible.ca>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include "pci.h" 32#include "pci.h"
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.14 2019/12/29 23:47:56 jmcneill Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.15 2019/12/30 19:50:29 jmcneill Exp $");
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/bus.h> 39#include <sys/bus.h>
40#include <sys/cpu.h> 40#include <sys/cpu.h>
41#include <sys/device.h> 41#include <sys/device.h>
42 42
43#include <uvm/uvm_extern.h> 43#include <uvm/uvm_extern.h>
44 44
45#include <dev/fdt/fdtvar.h> 45#include <dev/fdt/fdtvar.h>
46 46
47#include <dev/acpi/acpica.h> 47#include <dev/acpi/acpica.h>
48#include <dev/acpi/acpivar.h> 48#include <dev/acpi/acpivar.h>
@@ -357,28 +357,84 @@ acpi_md_callback(struct acpi_softc *sc) @@ -357,28 +357,84 @@ acpi_md_callback(struct acpi_softc *sc)
357 acpi_madt_walk(acpi_md_madt_probe_cpu, sc); 357 acpi_madt_walk(acpi_md_madt_probe_cpu, sc);
358 acpi_madt_walk(acpi_md_madt_probe_gic, sc); 358 acpi_madt_walk(acpi_md_madt_probe_gic, sc);
359 acpi_madt_unmap(); 359 acpi_madt_unmap();
360 360
361 if (acpi_gtdt_map() != AE_OK) 361 if (acpi_gtdt_map() != AE_OK)
362 panic("Failed to map GTDT"); 362 panic("Failed to map GTDT");
363 acpi_gtdt_walk(acpi_md_gtdt_probe, sc); 363 acpi_gtdt_walk(acpi_md_gtdt_probe, sc);
364 acpi_gtdt_unmap(); 364 acpi_gtdt_unmap();
365 365
366 if (ACPI_SUCCESS(AcpiGetTable(ACPI_SIG_GTDT, 0, &hdrp))) 366 if (ACPI_SUCCESS(AcpiGetTable(ACPI_SIG_GTDT, 0, &hdrp)))
367 config_found_ia(sc->sc_dev, "acpisdtbus", hdrp, NULL); 367 config_found_ia(sc->sc_dev, "acpisdtbus", hdrp, NULL);
368} 368}
369 369
 370static const char * const module_hid[] = {
 371 "ACPI0004", /* Module device */
 372 NULL
 373};
 374
 375static bus_dma_tag_t
 376arm_acpi_dma_tag_subregion(struct acpi_softc *sc, bus_dma_tag_t dmat,
 377 ACPI_HANDLE handle)
 378{
 379 struct acpi_resources res;
 380 struct acpi_mem *mem;
 381 bus_dma_tag_t newtag;
 382 ACPI_STATUS rv;
 383 int error;
 384
 385 rv = acpi_resource_parse(sc->sc_dev, handle, "_DMA", &res,
 386 &acpi_resource_parse_ops_quiet);
 387 if (ACPI_FAILURE(rv))
 388 return dmat; /* no translation required */
 389
 390 mem = acpi_res_mem(&res, 0);
 391 if (mem == NULL)
 392 goto done;
 393
 394 aprint_debug_dev(sc->sc_dev, "_DMA range %#lx-%#lx\n",
 395 mem->ar_base, mem->ar_base + mem->ar_length - 1);
 396
 397 error = bus_dmatag_subregion(dmat,
 398 mem->ar_base, mem->ar_base + mem->ar_length - 1,
 399 &newtag, BUS_DMA_WAITOK);
 400 if (error != 0) {
 401 aprint_error_dev(sc->sc_dev,
 402 "_DMA subregion failed: %d\n", error);
 403 goto done;
 404 }
 405 dmat = newtag;
 406
 407done:
 408 acpi_resource_cleanup(&res);
 409
 410 return dmat;
 411}
 412
370bus_dma_tag_t 413bus_dma_tag_t
371arm_acpi_dma_tag(struct acpi_softc *sc, struct acpi_devnode *ad) 414arm_acpi_dma_tag(struct acpi_softc *sc, struct acpi_devnode *ad)
372{ 415{
373 ACPI_INTEGER cca; 416 ACPI_INTEGER cca;
 417 bus_dma_tag_t dmat;
374 418
375 if (ACPI_FAILURE(acpi_eval_integer(ad->ad_handle, "_CCA", &cca))) 419 if (ACPI_FAILURE(acpi_eval_integer(ad->ad_handle, "_CCA", &cca)))
376 cca = 1; 420 cca = 1;
377 421
378 if (cca) 422 if (cca)
379 return &acpi_coherent_dma_tag; 423 dmat = &acpi_coherent_dma_tag;
380 else 424 else
381 return &arm_generic_dma_tag; 425 dmat = &arm_generic_dma_tag;
 426
 427 /*
 428 * If the parent device is a bus, it may define valid DMA ranges
 429 * and translations for child nodes.
 430 */
 431 if (ad->ad_parent != NULL &&
 432 acpi_match_hid(ad->ad_parent->ad_devinfo, module_hid)) {
 433 dmat = arm_acpi_dma_tag_subregion(sc, dmat,
 434 ad->ad_parent->ad_handle);
 435 }
 436
 437 return dmat;
382} 438}
383__strong_alias(acpi_get_dma_tag,arm_acpi_dma_tag); 439__strong_alias(acpi_get_dma_tag,arm_acpi_dma_tag);
384__strong_alias(acpi_get_dma64_tag,arm_acpi_dma_tag); 440__strong_alias(acpi_get_dma64_tag,arm_acpi_dma_tag);