Module Name:    src
Committed By:   jmcneill
Date:           Tue Dec 31 12:27:50 UTC 2019

Modified Files:
        src/sys/dev/acpi: acpi.c acpi_resource.c acpivar.h

Log Message:
Fetch bus_dma tags when acpi devnodes are created. They do not change
and this allows MD code to create more complex tags without being
concerned with the tag being destroyed later. While here, capture
translations offsets for address32/address64 resources.


To generate a diff of this commit:
cvs rdiff -u -r1.281 -r1.282 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.78 -r1.79 src/sys/dev/acpi/acpivar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.281 src/sys/dev/acpi/acpi.c:1.282
--- src/sys/dev/acpi/acpi.c:1.281	Mon Dec 30 19:52:11 2019
+++ src/sys/dev/acpi/acpi.c	Tue Dec 31 12:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -200,6 +200,7 @@ static bool		acpi_resume(device_t, const
 
 static void		acpi_build_tree(struct acpi_softc *);
 static void		acpi_config_tree(struct acpi_softc *);
+static void		acpi_config_dma(struct acpi_softc *);
 static ACPI_STATUS	acpi_make_devnode(ACPI_HANDLE, uint32_t,
 					  void *, void **);
 static ACPI_STATUS	acpi_make_devnode_post(ACPI_HANDLE, uint32_t,
@@ -687,6 +688,10 @@ acpi_build_tree(struct acpi_softc *sc)
 static void
 acpi_config_tree(struct acpi_softc *sc)
 {
+	/*
+	 * Assign bus_dma resources
+	 */
+	acpi_config_dma(sc);
 
 	/*
 	 * Configure all everything found "at acpi?".
@@ -707,6 +712,24 @@ acpi_config_tree(struct acpi_softc *sc)
 	(void)config_defer(sc->sc_dev, acpi_rescan_capabilities);
 }
 
+static void
+acpi_config_dma(struct acpi_softc *sc)
+{
+	struct acpi_devnode *ad;
+
+	SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
+
+		if (ad->ad_device != NULL)
+			continue;
+
+		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
+			continue;
+
+		ad->ad_dmat = acpi_get_dma_tag(sc, ad);
+		ad->ad_dmat64 = acpi_get_dma64_tag(sc, ad);
+	}
+}
+
 static ACPI_STATUS
 acpi_make_devnode(ACPI_HANDLE handle, uint32_t level,
     void *context, void **status)
@@ -895,18 +918,11 @@ acpi_rescan_early(struct acpi_softc *sc)
 		aa.aa_pc = sc->sc_pc;
 		aa.aa_pciflags = sc->sc_pciflags;
 		aa.aa_ic = sc->sc_ic;
-		aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-		aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+		aa.aa_dmat = ad->ad_dmat;
+		aa.aa_dmat64 = ad->ad_dmat64;
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		    "acpinodebus", &aa, acpi_print);
-
-		if (ad->ad_device == NULL) {
-			if (aa.aa_dmat != NULL)
-				bus_dmatag_destroy(aa.aa_dmat);
-			if (aa.aa_dmat64 != NULL)
-				bus_dmatag_destroy(aa.aa_dmat64);
-		}
 	}
 }
 
@@ -964,18 +980,11 @@ acpi_rescan_nodes(struct acpi_softc *sc)
 		aa.aa_pc = sc->sc_pc;
 		aa.aa_pciflags = sc->sc_pciflags;
 		aa.aa_ic = sc->sc_ic;
-		aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-		aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+		aa.aa_dmat = ad->ad_dmat;
+		aa.aa_dmat64 = ad->ad_dmat64;
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		    "acpinodebus", &aa, acpi_print);
-
-		if (ad->ad_device == NULL) {
-			if (aa.aa_dmat != NULL)
-				bus_dmatag_destroy(aa.aa_dmat);
-			if (aa.aa_dmat64 != NULL)
-				bus_dmatag_destroy(aa.aa_dmat64);
-		}
 	}
 }
 

Index: src/sys/dev/acpi/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.38 src/sys/dev/acpi/acpi_resource.c:1.39
--- src/sys/dev/acpi/acpi_resource.c:1.38	Thu Oct 25 10:38:57 2018
+++ src/sys/dev/acpi/acpi_resource.c	Tue Dec 31 12:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -147,7 +147,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		if (ops->memory)
 			(*ops->memory)(arg->dev, arg->context,
 			    res->Data.FixedMemory32.Address,
-			    res->Data.FixedMemory32.AddressLength);
+			    res->Data.FixedMemory32.AddressLength,
+			    0);
 		break;
 
 	case ACPI_RESOURCE_TYPE_MEMORY32:
@@ -160,7 +161,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 			if (ops->memory)
 				(*ops->memory)(arg->dev, arg->context,
 				    res->Data.Memory32.Minimum,
-				    res->Data.Memory32.AddressLength);
+				    res->Data.Memory32.AddressLength,
+				    0);
 		} else {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 					     "Memory32 0x%x-0x%x/%u\n",
@@ -186,7 +188,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 			if (ops->memory)
 				(*ops->memory)(arg->dev, arg->context,
 				    res->Data.Memory24.Minimum,
-				    res->Data.Memory24.AddressLength);
+				    res->Data.Memory24.AddressLength,
+				    0);
 		} else {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 					     "Memory24 0x%x-0x%x/%u\n",
@@ -255,7 +258,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 				if (ops->memory)
 					(*ops->memory)(arg->dev, arg->context,
 					    res->Data.Address32.Address.Minimum,
-					    res->Data.Address32.Address.AddressLength);
+					    res->Data.Address32.Address.AddressLength,
+					    res->Data.Address32.Address.TranslationOffset);
 			} else {
 				if (ops->memrange)
 					(*ops->memrange)(arg->dev, arg->context,
@@ -308,7 +312,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 				if (ops->memory)
 					(*ops->memory)(arg->dev, arg->context,
 					    res->Data.Address64.Address.Minimum,
-					    res->Data.Address64.Address.AddressLength);
+					    res->Data.Address64.Address.AddressLength,
+					    res->Data.Address64.Address.TranslationOffset);
 			} else {
 				if (ops->memrange)
 					(*ops->memrange)(arg->dev, arg->context,
@@ -647,7 +652,7 @@ static void	acpi_res_parse_iorange(devic
 		    uint32_t, uint32_t, uint32_t);
 
 static void	acpi_res_parse_memory(device_t, void *, uint64_t,
-		    uint64_t);
+		    uint64_t, uint64_t);
 static void	acpi_res_parse_memrange(device_t, void *, uint64_t,
 		    uint64_t, uint64_t, uint64_t);
 
@@ -797,7 +802,7 @@ acpi_res_parse_iorange(device_t dev, voi
 
 static void
 acpi_res_parse_memory(device_t dev, void *context, uint64_t base,
-    uint64_t length)
+    uint64_t length, uint64_t offset)
 {
 	struct acpi_resources *res = context;
 	struct acpi_mem *ar;
@@ -813,6 +818,7 @@ acpi_res_parse_memory(device_t dev, void
 	ar->ar_index = res->ar_nmem++;
 	ar->ar_base = base;
 	ar->ar_length = length;
+	ar->ar_offset = offset;
 
 	SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
 }

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.78 src/sys/dev/acpi/acpivar.h:1.79
--- src/sys/dev/acpi/acpivar.h:1.78	Sun Dec 29 23:47:56 2019
+++ src/sys/dev/acpi/acpivar.h	Tue Dec 31 12:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.78 2019/12/29 23:47:56 jmcneill Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.79 2019/12/31 12:27:50 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -131,6 +131,8 @@ struct acpi_devnode {
 	uint32_t		 ad_flags;	/* Device flags */
 	uint32_t		 ad_type;	/* Device type */
 	int			 ad_state;	/* Device power state */
+	bus_dma_tag_t		 ad_dmat;	/* Bus DMA tag for device */
+	bus_dma_tag_t		 ad_dmat64;	/* Bus DMA tag for device (64-bit) */
 
 	SIMPLEQ_ENTRY(acpi_devnode)	ad_list;
 	SIMPLEQ_ENTRY(acpi_devnode)	ad_child_list;
@@ -224,6 +226,7 @@ struct acpi_mem {
 	int		ar_index;
 	bus_addr_t	ar_base;
 	bus_size_t	ar_length;
+	bus_addr_t	ar_offset;
 };
 
 struct acpi_memrange {
@@ -282,7 +285,7 @@ struct acpi_resource_parse_ops {
 	void	(*iorange)(device_t, void *, uint32_t, uint32_t,
 		    uint32_t, uint32_t);
 
-	void	(*memory)(device_t, void *, uint64_t, uint64_t);
+	void	(*memory)(device_t, void *, uint64_t, uint64_t, uint64_t);
 	void	(*memrange)(device_t, void *, uint64_t, uint64_t,
 		    uint64_t, uint64_t);
 

Reply via email to