Changeset View
Standalone View
sys/dev/acpica/acpi.c
| Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | |||||
| static int acpi_child_location_method(device_t acdev, device_t child, | static int acpi_child_location_method(device_t acdev, device_t child, | ||||
| struct sbuf *sb); | struct sbuf *sb); | ||||
| static int acpi_child_pnpinfo_method(device_t acdev, device_t child, | static int acpi_child_pnpinfo_method(device_t acdev, device_t child, | ||||
| struct sbuf *sb); | struct sbuf *sb); | ||||
| static void acpi_enable_pcie(void); | static void acpi_enable_pcie(void); | ||||
| static void acpi_hint_device_unit(device_t acdev, device_t child, | static void acpi_hint_device_unit(device_t acdev, device_t child, | ||||
| const char *name, int *unitp); | const char *name, int *unitp); | ||||
| static void acpi_reset_interfaces(device_t dev); | static void acpi_reset_interfaces(device_t dev); | ||||
| static bus_dma_tag_t acpi_get_dma_tag(device_t dev, device_t child); | |||||
| static device_method_t acpi_methods[] = { | static device_method_t acpi_methods[] = { | ||||
| /* Device interface */ | /* Device interface */ | ||||
| DEVMETHOD(device_probe, acpi_probe), | DEVMETHOD(device_probe, acpi_probe), | ||||
| DEVMETHOD(device_attach, acpi_attach), | DEVMETHOD(device_attach, acpi_attach), | ||||
| DEVMETHOD(device_shutdown, acpi_shutdown), | DEVMETHOD(device_shutdown, acpi_shutdown), | ||||
| DEVMETHOD(device_detach, bus_generic_detach), | DEVMETHOD(device_detach, bus_generic_detach), | ||||
| DEVMETHOD(device_suspend, acpi_suspend), | DEVMETHOD(device_suspend, acpi_suspend), | ||||
| Show All 19 Lines | static device_method_t acpi_methods[] = { | ||||
| DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), | DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), | ||||
| DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), | DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), | ||||
| DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), | DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), | ||||
| DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), | DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), | ||||
| DEVMETHOD(bus_hint_device_unit, acpi_hint_device_unit), | DEVMETHOD(bus_hint_device_unit, acpi_hint_device_unit), | ||||
| DEVMETHOD(bus_get_cpus, acpi_get_cpus), | DEVMETHOD(bus_get_cpus, acpi_get_cpus), | ||||
| DEVMETHOD(bus_get_domain, acpi_get_domain), | DEVMETHOD(bus_get_domain, acpi_get_domain), | ||||
| DEVMETHOD(bus_get_property, acpi_bus_get_prop), | DEVMETHOD(bus_get_property, acpi_bus_get_prop), | ||||
| DEVMETHOD(bus_get_dma_tag, acpi_get_dma_tag), | |||||
| /* ACPI bus */ | /* ACPI bus */ | ||||
| DEVMETHOD(acpi_id_probe, acpi_device_id_probe), | DEVMETHOD(acpi_id_probe, acpi_device_id_probe), | ||||
| DEVMETHOD(acpi_evaluate_object, acpi_device_eval_obj), | DEVMETHOD(acpi_evaluate_object, acpi_device_eval_obj), | ||||
| DEVMETHOD(acpi_get_property, acpi_device_get_prop), | DEVMETHOD(acpi_get_property, acpi_device_get_prop), | ||||
| DEVMETHOD(acpi_pwr_for_sleep, acpi_device_pwr_for_sleep), | DEVMETHOD(acpi_pwr_for_sleep, acpi_device_pwr_for_sleep), | ||||
| DEVMETHOD(acpi_scan_children, acpi_device_scan_children), | DEVMETHOD(acpi_scan_children, acpi_device_scan_children), | ||||
| ▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | return (ENXIO); | ||||
| sbuf_putc(&sb, ' '); | sbuf_putc(&sb, ' '); | ||||
| sbuf_bcat(&sb, rsdt->OemTableId, ACPI_OEM_TABLE_ID_SIZE); | sbuf_bcat(&sb, rsdt->OemTableId, ACPI_OEM_TABLE_ID_SIZE); | ||||
| sbuf_trim(&sb); | sbuf_trim(&sb); | ||||
| sbuf_finish(&sb); | sbuf_finish(&sb); | ||||
| sbuf_delete(&sb); | sbuf_delete(&sb); | ||||
| AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER)); | AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER)); | ||||
| snprintf(acpi_ca_version, sizeof(acpi_ca_version), "%x", ACPI_CA_VERSION); | snprintf(acpi_ca_version, sizeof(acpi_ca_version), "%x", ACPI_CA_VERSION); | ||||
| return (0); | |||||
| } | |||||
| struct dma_limits { | |||||
| bus_addr_t lowaddr; | |||||
| }; | |||||
| static ACPI_STATUS | |||||
| dma_on_resource(ACPI_RESOURCE *res, void *arg) | |||||
| { | |||||
| struct dma_limits *limits = arg; | |||||
| bus_addr_t min, len; | |||||
| /* | |||||
| * The minimum and maximum are device-side. To get the CPU-side minimum, | |||||
| * we add the translation offset. This can overflow to signify lower addresses | |||||
| * on the CPU than the device, e.g. "Bus 0xC0000000 -> CPU 0x00000000" | |||||
| * on the RPi4 is represented as 0xC0000000 min + 0xFFFFFFFF40000000 offset. | |||||
| */ | |||||
| switch (res->Type) { | |||||
| case ACPI_RESOURCE_TYPE_ADDRESS16: | |||||
| min = (uint16_t)(res->Data.Address16.Address.Minimum + | |||||
| res->Data.Address16.Address.TranslationOffset); | |||||
| len = res->Data.Address16.Address.AddressLength; | |||||
| break; | |||||
| case ACPI_RESOURCE_TYPE_ADDRESS32: | |||||
| min = (uint32_t)(res->Data.Address32.Address.Minimum + | |||||
| res->Data.Address32.Address.TranslationOffset); | |||||
| len = res->Data.Address32.Address.AddressLength; | |||||
| break; | |||||
| case ACPI_RESOURCE_TYPE_ADDRESS64: | |||||
| min = (uint64_t)(res->Data.Address64.Address.Minimum + | |||||
| res->Data.Address64.Address.TranslationOffset); | |||||
| len = res->Data.Address64.Address.AddressLength; | |||||
| break; | |||||
| case ACPI_RESOURCE_TYPE_END_TAG: | |||||
| return (AE_OK); | |||||
| default: | |||||
| printf("ACPI: warning: DMA limit with unsupported resource type %d\n", | |||||
| res->Type); | |||||
| return (AE_OK); | |||||
| } | |||||
| if (min != 0) | |||||
| printf("ACPI: warning: DMA limit with non-zero minimum address" | |||||
| " not supported yet\n"); | |||||
| limits->lowaddr = MIN(limits->lowaddr, min + len); | |||||
| return (AE_OK); | |||||
| } | |||||
| static int | |||||
| get_dma_tag(ACPI_HANDLE handle, bus_dma_tag_t *result) | |||||
| { | |||||
| ACPI_HANDLE parent; | |||||
| unsigned int coherent; | |||||
| struct dma_limits limits = { | |||||
| .lowaddr = BUS_SPACE_MAXADDR, | |||||
| }; | |||||
| if (ACPI_FAILURE(AcpiWalkResources(handle, "_DMA", | |||||
| dma_on_resource, (void *)&limits))) { | |||||
| /* Inherit resources from parent handle if we don't have our own */ | |||||
| if (ACPI_SUCCESS(AcpiGetParent(handle, &parent))) | |||||
| return (get_dma_tag(parent, result)); | |||||
| /* The root (which has no parent) has no restrictions */ | |||||
| *result = NULL; | |||||
| return (0); | |||||
| } | |||||
| if (ACPI_FAILURE(acpi_GetInteger(handle, "_CCA", &coherent))) | |||||
| coherent = 0; | |||||
| if (bus_dma_tag_create(NULL, 1, 0, | |||||
| limits.lowaddr, BUS_SPACE_MAXADDR, NULL, NULL, | |||||
markmi_dsl-only.net: Based on sysctl hw.busdma output and testing a change for the u-boot/DTB/fdt code context that… | |||||
Not Done Inline ActionsFYI: sys/arm64/arm64/busdma_machdep.c 's common_bus_dma_tag_create has: common->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); common->highaddr = trunc_page((vm_paddr_t)highaddr) + (PAGE_SIZE - 1); and so forces reference to the last byte of the page identified by lowaddr (and highaddr). Thus lowaddr needs to identify the last page that can avoid bouncing (or earlier). arm64, arm, powerpc, riscv, mips, and x86 all use the trunc_page and PAGE_SIZE-1 computation. I do not remember a hint of that from the documentation for bus_dma_tag_create. markmi_dsl-only.net: FYI: sys/arm64/arm64/busdma_machdep.c 's common_bus_dma_tag_create has:
```
common… | |||||
| BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED, BUS_SPACE_MAXSIZE, | |||||
Not Done Inline ActionsNote: from a RPi4B: /usr/include/machine/bus.h:#define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFFUL bus_dma(9) reports for maxsize and maxsegsz: Maximum size, in bytes, of the sum of all
segment lengths
Maximum size, in bytes, of a segment in any DMA
mapped region.The above code reads to me like the bus_dma_tag_create call allows for segments too large to fit the context (maxsegsz should be no larger than limits.lowaddr) and a sum of all segments max size with the same problem (maxsize should be no larger than limits.lowaddr). markmi_dsl-only.net: Note: from a RPi4B:
/usr/include/machine/bus.h:#define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFFUL… | |||||
Done Inline Actions
I thought the code that uses the tags would be smart enough to take the lowest of the limits into account :) val_packett.cool: > should be no larger than limits.lowaddr
I thought the code that uses the tags would be smart… | |||||
Not Done Inline ActionsDid I miss bus_dma(9)'s documentation of such implicitly applied constraints relative to the 4th argument? I see maxsegsz vs. boundary constraints in the dma implementation code but not relative to the 4th argment to bus_dma_tag_create. Nor maxsize relative to it. Maxmem does not seem to be based on lowaddr either so constraints relative to it do not track the issue in question. But the code is not familiar and I may have missed something. If the intent for maxsegsz and maxsize is to be implicitly constrained by other figures from the call, I think that bus_dma(9) should document that. (Not that this apic.c update is the right place for also doing such or that you would be the right person for such.) markmi_dsl-only.net: Did I miss bus_dma(9)'s documentation of such implicitly applied constraints relative to the… | |||||
Done Inline ActionsI adjusted part of your patch to use: + if (bus_dma_tag_create(NULL, 1, 0, + limits.lowaddr, BUS_SPACE_MAXADDR, NULL, NULL, + limits.lowaddr, BUS_SPACE_UNRESTRICTED, limits.lowaddr, + coherent ? BUS_DMA_COHERENT : 0, NULL, NULL, + result) != 0) + return (ENOMEM); Result: The huge-file duplicate-and-diff tests still fail when > 3072 MiByte of RAM is enabled. So what I questioned is irrelevant to the test failures. Sorry for the noise. markmi_dsl-only.net: I adjusted part of your patch to use:
```
+ if (bus_dma_tag_create(NULL, 1, 0,
+… | |||||
| coherent ? BUS_DMA_COHERENT : 0, NULL, NULL, | |||||
| result) != 0) | |||||
| return (ENOMEM); | |||||
| return (0); | return (0); | ||||
| } | } | ||||
| static bus_dma_tag_t | |||||
| acpi_get_dma_tag(device_t dev, device_t child) | |||||
| { | |||||
| bus_dma_tag_t result; | |||||
| if (get_dma_tag(acpi_get_handle(child), &result) != 0) { | |||||
| device_printf(child, "could not get ACPI DMA limits\n"); | |||||
| return (NULL); | |||||
| } | |||||
| return (result); | |||||
| } | |||||
| /* | /* | ||||
| * Fetch some descriptive data from ACPI to put in our attach message. | * Fetch some descriptive data from ACPI to put in our attach message. | ||||
| */ | */ | ||||
| static int | static int | ||||
| acpi_probe(device_t dev) | acpi_probe(device_t dev) | ||||
| { | { | ||||
| ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | ||||
| ▲ Show 20 Lines • Show All 4,046 Lines • Show Last 20 Lines | |||||
Based on sysctl hw.busdma output and testing a change for the u-boot/DTB/fdt code context that worked, I've tried using limits.lowaddr-1 here instead.
So far the installed build now passes my huge-file duplicate-and-diff tests when booted via uefi/ACPI v1.20 .
What sysctl showed me was the likes of (before
changes that lead to lack of zone2 for u-boot/dtb/fdt):
So I've guessed that lowaddr should identify the
end page of the possibly-use-it region, not the
first do-not-use-it page. If I've guessed wrong,
at most it would bounce one page that it could
avoid bouncing. But, if I guessed correct, it
might bounce a page that it should instead of
not doing so. Thus the "-1" addition.
For reference, after the first duplicate-and-diff test: