Mon Dec 30 19:49:38 2019 UTC ()
MD code may allocate a new dma tag for attach args, so destroy it if the device node is not claimed


(jmcneill)
diff -r1.279 -r1.280 src/sys/dev/acpi/acpi.c

cvs diff -r1.279 -r1.280 src/sys/dev/acpi/acpi.c (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi.c 2019/12/29 23:47:56 1.279
+++ src/sys/dev/acpi/acpi.c 2019/12/30 19:49:38 1.280
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi.c,v 1.279 2019/12/29 23:47:56 jmcneill Exp $ */ 1/* $NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003, 2007 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 Charles M. Hannum of By Noon Software, Inc. 8 * by Charles M. Hannum of By Noon Software, Inc.
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.
@@ -90,27 +90,27 @@ @@ -90,27 +90,27 @@
90 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 90 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
91 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 91 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
92 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 92 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
93 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 93 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
94 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 94 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
95 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 95 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
96 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 96 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
97 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 97 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
98 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 98 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
99 * POSSIBILITY OF SUCH DAMAGE. 99 * POSSIBILITY OF SUCH DAMAGE.
100 */ 100 */
101 101
102#include <sys/cdefs.h> 102#include <sys/cdefs.h>
103__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.279 2019/12/29 23:47:56 jmcneill Exp $"); 103__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $");
104 104
105#include "pci.h" 105#include "pci.h"
106#include "opt_acpi.h" 106#include "opt_acpi.h"
107#include "opt_pcifixup.h" 107#include "opt_pcifixup.h"
108 108
109#include <sys/param.h> 109#include <sys/param.h>
110#include <sys/device.h> 110#include <sys/device.h>
111#include <sys/kernel.h> 111#include <sys/kernel.h>
112#include <sys/kmem.h> 112#include <sys/kmem.h>
113#include <sys/malloc.h> 113#include <sys/malloc.h>
114#include <sys/module.h> 114#include <sys/module.h>
115#include <sys/mutex.h> 115#include <sys/mutex.h>
116#include <sys/sysctl.h> 116#include <sys/sysctl.h>
@@ -889,26 +889,33 @@ acpi_rescan_early(struct acpi_softc *sc) @@ -889,26 +889,33 @@ acpi_rescan_early(struct acpi_softc *sc)
889 continue; 889 continue;
890 890
891 aa.aa_node = ad; 891 aa.aa_node = ad;
892 aa.aa_iot = sc->sc_iot; 892 aa.aa_iot = sc->sc_iot;
893 aa.aa_memt = sc->sc_memt; 893 aa.aa_memt = sc->sc_memt;
894 aa.aa_pc = sc->sc_pc; 894 aa.aa_pc = sc->sc_pc;
895 aa.aa_pciflags = sc->sc_pciflags; 895 aa.aa_pciflags = sc->sc_pciflags;
896 aa.aa_ic = sc->sc_ic; 896 aa.aa_ic = sc->sc_ic;
897 aa.aa_dmat = acpi_get_dma_tag(sc, ad); 897 aa.aa_dmat = acpi_get_dma_tag(sc, ad);
898 aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad); 898 aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
899 899
900 ad->ad_device = config_found_ia(sc->sc_dev, 900 ad->ad_device = config_found_ia(sc->sc_dev,
901 "acpinodebus", &aa, acpi_print); 901 "acpinodebus", &aa, acpi_print);
 902
 903 if (ad->ad_device == NULL) {
 904 if (aa.aa_dmat != NULL)
 905 bus_dmatag_destroy(aa.aa_dmat);
 906 if (aa.aa_dmat64 != NULL)
 907 bus_dmatag_destroy(aa.aa_dmat64);
 908 }
902 } 909 }
903} 910}
904 911
905static void 912static void
906acpi_rescan_nodes(struct acpi_softc *sc) 913acpi_rescan_nodes(struct acpi_softc *sc)
907{ 914{
908 const char * const hpet_ids[] = { "PNP0103", NULL }; 915 const char * const hpet_ids[] = { "PNP0103", NULL };
909 struct acpi_attach_args aa; 916 struct acpi_attach_args aa;
910 struct acpi_devnode *ad; 917 struct acpi_devnode *ad;
911 ACPI_DEVICE_INFO *di; 918 ACPI_DEVICE_INFO *di;
912 919
913 SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { 920 SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
914 921
@@ -951,26 +958,33 @@ acpi_rescan_nodes(struct acpi_softc *sc) @@ -951,26 +958,33 @@ acpi_rescan_nodes(struct acpi_softc *sc)
951 continue; 958 continue;
952 959
953 aa.aa_node = ad; 960 aa.aa_node = ad;
954 aa.aa_iot = sc->sc_iot; 961 aa.aa_iot = sc->sc_iot;
955 aa.aa_memt = sc->sc_memt; 962 aa.aa_memt = sc->sc_memt;
956 aa.aa_pc = sc->sc_pc; 963 aa.aa_pc = sc->sc_pc;
957 aa.aa_pciflags = sc->sc_pciflags; 964 aa.aa_pciflags = sc->sc_pciflags;
958 aa.aa_ic = sc->sc_ic; 965 aa.aa_ic = sc->sc_ic;
959 aa.aa_dmat = acpi_get_dma_tag(sc, ad); 966 aa.aa_dmat = acpi_get_dma_tag(sc, ad);
960 aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad); 967 aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
961 968
962 ad->ad_device = config_found_ia(sc->sc_dev, 969 ad->ad_device = config_found_ia(sc->sc_dev,
963 "acpinodebus", &aa, acpi_print); 970 "acpinodebus", &aa, acpi_print);
 971
 972 if (ad->ad_device == NULL) {
 973 if (aa.aa_dmat != NULL)
 974 bus_dmatag_destroy(aa.aa_dmat);
 975 if (aa.aa_dmat64 != NULL)
 976 bus_dmatag_destroy(aa.aa_dmat64);
 977 }
964 } 978 }
965} 979}
966 980
967static void 981static void
968acpi_rescan_capabilities(device_t self) 982acpi_rescan_capabilities(device_t self)
969{ 983{
970 struct acpi_softc *sc = device_private(self); 984 struct acpi_softc *sc = device_private(self);
971 struct acpi_devnode *ad; 985 struct acpi_devnode *ad;
972 ACPI_HANDLE tmp; 986 ACPI_HANDLE tmp;
973 ACPI_STATUS rv; 987 ACPI_STATUS rv;
974 988
975 SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) { 989 SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
976 990