From: patrick Date: Sun, 28 Feb 2021 21:31:10 +0000 (+0000) Subject: Add acpiiort(4), a driver for the ACPI I/O Remapping Table. This table X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ffdeadb517b142331b770fc2004b6e192e61ba55;p=openbsd Add acpiiort(4), a driver for the ACPI I/O Remapping Table. This table contains information which IOMMUs we have and how the devices are routed. ok kettenis@ --- diff --git a/sys/arch/arm64/dev/acpiiort.c b/sys/arch/arm64/dev/acpiiort.c new file mode 100644 index 00000000000..4ce2e5438fe --- /dev/null +++ b/sys/arch/arm64/dev/acpiiort.c @@ -0,0 +1,103 @@ +/* $OpenBSD: acpiiort.c,v 1.1 2021/02/28 21:31:10 patrick Exp $ */ +/* + * Copyright (c) 2021 Patrick Wildt + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include + +#include + +SIMPLEQ_HEAD(, acpiiort_smmu) acpiiort_smmu_list = + SIMPLEQ_HEAD_INITIALIZER(acpiiort_smmu_list); + +int acpiiort_match(struct device *, void *, void *); +void acpiiort_attach(struct device *, struct device *, void *); + +struct cfattach acpiiort_ca = { + sizeof(struct device), acpiiort_match, acpiiort_attach +}; + +struct cfdriver acpiiort_cd = { + NULL, "acpiiort", DV_DULL +}; + +int +acpiiort_match(struct device *parent, void *match, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct acpi_table_header *hdr; + + /* If we do not have a table, it is not us */ + if (aaa->aaa_table == NULL) + return 0; + + /* If it is an IORT table, we can attach */ + hdr = (struct acpi_table_header *)aaa->aaa_table; + if (memcmp(hdr->signature, IORT_SIG, sizeof(IORT_SIG) - 1) != 0) + return 0; + + return 1; +} + +void +acpiiort_attach(struct device *parent, struct device *self, void *aux) +{ + struct acpi_attach_args *aaa = aux; + struct acpi_iort *iort = (struct acpi_iort *)aaa->aaa_table; + struct acpi_iort_node *node; + struct acpiiort_attach_args aia; + uint32_t offset; + int i; + + printf("\n"); + + memset(&aia, 0, sizeof(aia)); + aia.aia_iot = aaa->aaa_iot; + aia.aia_memt = aaa->aaa_memt; + aia.aia_dmat = aaa->aaa_dmat; + + offset = iort->offset; + for (i = 0; i < iort->number_of_nodes; i++) { + node = (struct acpi_iort_node *)((char *)iort + offset); + aia.aia_node = node; + config_found(self, &aia, NULL); + offset += node->length; + } +} + +void +acpiiort_smmu_register(struct acpiiort_smmu *as) +{ + SIMPLEQ_INSERT_TAIL(&acpiiort_smmu_list, as, as_list); +} + +void +acpiiort_smmu_hook(struct acpi_iort_node *node, uint32_t rid, + struct pci_attach_args *pa) +{ + struct acpiiort_smmu *as; + + SIMPLEQ_FOREACH(as, &acpiiort_smmu_list, as_list) { + if (as->as_node == node) { + as->as_hook(as->as_cookie, rid, pa); + break; + } + } +} diff --git a/sys/arch/arm64/dev/acpiiort.h b/sys/arch/arm64/dev/acpiiort.h new file mode 100644 index 00000000000..2ee15345d00 --- /dev/null +++ b/sys/arch/arm64/dev/acpiiort.h @@ -0,0 +1,35 @@ +/* $OpenBSD: acpiiort.h,v 1.1 2021/02/28 21:31:10 patrick Exp $ */ +/* + * Copyright (c) 2021 Patrick Wildt + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +struct acpiiort_attach_args { + struct acpi_iort_node *aia_node; + bus_space_tag_t aia_iot; + bus_space_tag_t aia_memt; + bus_dma_tag_t aia_dmat; +}; + +struct acpiiort_smmu { + SIMPLEQ_ENTRY(acpiiort_smmu) as_list; + struct acpi_iort_node *as_node; + void *as_cookie; + void (*as_hook)(void *, uint32_t, + struct pci_attach_args *); +}; + +void acpiiort_smmu_register(struct acpiiort_smmu *); +void acpiiort_smmu_hook(struct acpi_iort_node *, uint32_t, + struct pci_attach_args *);