git: 253e4c56c8a6 - stable/13 - Add the fixed memory type to the pci ecam driver

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 15 May 2023 15:46:02 UTC
The branch stable/13 has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=253e4c56c8a6d4cb0fff963d735852095580ee49

commit 253e4c56c8a6d4cb0fff963d735852095580ee49
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2023-01-18 09:30:46 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-05-15 10:55:19 +0000

    Add the fixed memory type to the pci ecam driver
    
    Add ACPI_RESOURCE_TYPE_FIXED_MEMORY32 to the PCI ECAM driver. This is
    used on the Microsoft Dev Kit 2023 and reportedly the Lenovo x13s.
    
    Reviewed by:    Robert Clausecker <fuz@fuz.su> (Earlier version)
    Tested by:      Robert Clausecker <fuz@fuz.su> (Earlier version)
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D38031
    
    (cherry picked from commit 896f556205c8d87ef842dc844752daa7d2385336)
---
 sys/dev/pci/pci_host_generic_acpi.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/sys/dev/pci/pci_host_generic_acpi.c b/sys/dev/pci/pci_host_generic_acpi.c
index 9628517813a9..074e81be9a88 100644
--- a/sys/dev/pci/pci_host_generic_acpi.c
+++ b/sys/dev/pci/pci_host_generic_acpi.c
@@ -143,26 +143,43 @@ pci_host_generic_acpi_parse_resource(ACPI_RESOURCE *res, void *arg)
 	struct generic_pcie_acpi_softc *sc;
 	struct rman *rm;
 	rman_res_t min, max, off;
-	int r;
+	int r, restype;
 
 	rm = NULL;
 	sc = device_get_softc(dev);
 	r = sc->base.nranges;
 	switch (res->Type) {
 	case ACPI_RESOURCE_TYPE_ADDRESS16:
+		restype = res->Data.Address16.ResourceType;
 		min = res->Data.Address16.Address.Minimum;
 		max = res->Data.Address16.Address.Maximum;
 		break;
 	case ACPI_RESOURCE_TYPE_ADDRESS32:
+		restype = res->Data.Address32.ResourceType;
 		min = res->Data.Address32.Address.Minimum;
 		max = res->Data.Address32.Address.Maximum;
 		off = res->Data.Address32.Address.TranslationOffset;
 		break;
 	case ACPI_RESOURCE_TYPE_ADDRESS64:
+		restype = res->Data.Address64.ResourceType;
 		min = res->Data.Address64.Address.Minimum;
 		max = res->Data.Address64.Address.Maximum;
 		off = res->Data.Address64.Address.TranslationOffset;
 		break;
+	case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
+		/*
+		 * The Microsoft Dev Kit 2023 uses a fixed memory region
+		 * for some PCI controllers. For this memory the
+		 * ResourceType is ACPI_IO_RANGE meaning we create an IO
+		 * resource. As drivers expect it to be a memory resource
+		 * force the type here.
+		 */
+		restype = ACPI_MEMORY_RANGE;
+		min = res->Data.FixedMemory32.Address;
+		max = res->Data.FixedMemory32.Address +
+		    res->Data.FixedMemory32.AddressLength - 1;
+		off = 0;
+		break;
 	default:
 		return (AE_OK);
 	}
@@ -173,9 +190,9 @@ pci_host_generic_acpi_parse_resource(ACPI_RESOURCE *res, void *arg)
 		sc->base.ranges[r].pci_base = min;
 		sc->base.ranges[r].phys_base = min + off;
 		sc->base.ranges[r].size = max - min + 1;
-		if (res->Data.Address.ResourceType == ACPI_MEMORY_RANGE)
+		if (restype == ACPI_MEMORY_RANGE)
 			sc->base.ranges[r].flags |= FLAG_TYPE_MEM;
-		else if (res->Data.Address.ResourceType == ACPI_IO_RANGE)
+		else if (restype == ACPI_IO_RANGE)
 			sc->base.ranges[r].flags |= FLAG_TYPE_IO;
 		sc->base.nranges++;
 	} else if (res->Data.Address.ResourceType == ACPI_BUS_NUMBER_RANGE) {