From: Sricharan R <sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> To: robin.murphy-5wv7dgnIgG8@public.gmane.org, will.deacon-5wv7dgnIgG8@public.gmane.org, joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org, lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org Subject: [PATCH V5 11/12] drivers: acpi: Handle IOMMU lookup failure with deferred probing or error Date: Thu, 19 Jan 2017 20:35:55 +0530 [thread overview] Message-ID: <1484838356-24962-12-git-send-email-sricharan@codeaurora.org> (raw) In-Reply-To: <1484838356-24962-1-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> This is an equivalent to the DT's handling of the iommu master's probe with deferred probing when the corrsponding iommu is not probed yet. The lack of a registered IOMMU can be caused by the lack of a driver for the IOMMU, the IOMMU device probe not having been performed yet, having been deferred, or having failed. The first case occurs when the firmware describes the bus master and IOMMU topology correctly but no device driver exists for the IOMMU yet or the device driver has not been compiled in. Return NULL, the caller will configure the device without an IOMMU. The second and third cases are handled by deferring the probe of the bus master device which will eventually get reprobed after the IOMMU. The last case is currently handled by deferring the probe of the bus master device as well. A mechanism to either configure the bus master device without an IOMMU or to fail the bus master device probe depending on whether the IOMMU is optional or mandatory would be a good enhancement. Signed-off-by: Sricharan R <sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> --- * Removed the dma configuration for the pci devices in case of ACPI from pci_dma_configure which was hanging outside separately and doing it in dma_configure function itself. drivers/acpi/arm64/iort.c | 25 ++++++++++++++++++++++++- drivers/acpi/scan.c | 7 +++++-- drivers/base/dma-mapping.c | 2 +- include/acpi/acpi_bus.h | 2 +- include/linux/acpi.h | 7 +++++-- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index bf0ed09..d01bae8 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -550,8 +550,17 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev, return NULL; ops = iommu_get_instance(iort_fwnode); + /* + * If the ops look-up fails, this means that either + * the SMMU drivers have not been probed yet or that + * the SMMU drivers are not built in the kernel; + * Depending on whether the SMMU drivers are built-in + * in the kernel or not, defer the IOMMU configuration + * or just abort it. + */ if (!ops) - return NULL; + return iort_iommu_driver_enabled(node->type) ? + ERR_PTR(-EPROBE_DEFER) : NULL; ret = arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); } @@ -625,12 +634,26 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev) while (parent) { ops = iort_iommu_xlate(dev, parent, streamid); + if (IS_ERR_OR_NULL(ops)) + return ops; parent = iort_node_get_id(node, &streamid, IORT_IOMMU_TYPE, i++); } } + /* + * If we have reason to believe the IOMMU driver missed the initial + * add_device callback for dev, replay it to get things in order. + */ + if (!IS_ERR_OR_NULL(ops) && ops->add_device && + dev->bus && !dev->iommu_group) { + int err = ops->add_device(dev); + + if (err) + ops = ERR_PTR(err); + } + return ops; } diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1926918..823b005 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1373,20 +1373,23 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) * @dev: The pointer to the device * @attr: device dma attributes */ -void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) +int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) { const struct iommu_ops *iommu; iort_set_dma_mask(dev); iommu = iort_iommu_configure(dev); - + if (IS_ERR(iommu)) + return PTR_ERR(iommu); /* * Assume dma valid range starts at 0 and covers the whole * coherent_dma_mask. */ arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu, attr == DEV_DMA_COHERENT); + + return 0; } EXPORT_SYMBOL_GPL(acpi_dma_configure); diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 294942d..4b62a32 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -371,7 +371,7 @@ int dma_configure(struct device *dev) if (attr == DEV_DMA_NOT_SUPPORTED) dev_warn(dev, "DMA not supported.\n"); else - acpi_dma_configure(dev, attr); + ret = acpi_dma_configure(dev, attr); } if (is_pci) diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 4242c31..9aa762fe 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -573,7 +573,7 @@ struct acpi_pci_root { bool acpi_dma_supported(struct acpi_device *adev); enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); -void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); +int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); void acpi_dma_deconfigure(struct device *dev); struct acpi_device *acpi_find_child_device(struct acpi_device *parent, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 5b36974..8b958b6 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -764,8 +764,11 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) return DEV_DMA_NOT_SUPPORTED; } -static inline void acpi_dma_configure(struct device *dev, - enum dev_dma_attr attr) { } +static inline int acpi_dma_configure(struct device *dev, + enum dev_dma_attr attr) +{ + return 0; +} static inline void acpi_dma_deconfigure(struct device *dev) { } -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
WARNING: multiple messages have this Message-ID (diff)
From: sricharan@codeaurora.org (Sricharan R) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH V5 11/12] drivers: acpi: Handle IOMMU lookup failure with deferred probing or error Date: Thu, 19 Jan 2017 20:35:55 +0530 [thread overview] Message-ID: <1484838356-24962-12-git-send-email-sricharan@codeaurora.org> (raw) In-Reply-To: <1484838356-24962-1-git-send-email-sricharan@codeaurora.org> This is an equivalent to the DT's handling of the iommu master's probe with deferred probing when the corrsponding iommu is not probed yet. The lack of a registered IOMMU can be caused by the lack of a driver for the IOMMU, the IOMMU device probe not having been performed yet, having been deferred, or having failed. The first case occurs when the firmware describes the bus master and IOMMU topology correctly but no device driver exists for the IOMMU yet or the device driver has not been compiled in. Return NULL, the caller will configure the device without an IOMMU. The second and third cases are handled by deferring the probe of the bus master device which will eventually get reprobed after the IOMMU. The last case is currently handled by deferring the probe of the bus master device as well. A mechanism to either configure the bus master device without an IOMMU or to fail the bus master device probe depending on whether the IOMMU is optional or mandatory would be a good enhancement. Signed-off-by: Sricharan R <sricharan@codeaurora.org> --- * Removed the dma configuration for the pci devices in case of ACPI from pci_dma_configure which was hanging outside separately and doing it in dma_configure function itself. drivers/acpi/arm64/iort.c | 25 ++++++++++++++++++++++++- drivers/acpi/scan.c | 7 +++++-- drivers/base/dma-mapping.c | 2 +- include/acpi/acpi_bus.h | 2 +- include/linux/acpi.h | 7 +++++-- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index bf0ed09..d01bae8 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -550,8 +550,17 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev, return NULL; ops = iommu_get_instance(iort_fwnode); + /* + * If the ops look-up fails, this means that either + * the SMMU drivers have not been probed yet or that + * the SMMU drivers are not built in the kernel; + * Depending on whether the SMMU drivers are built-in + * in the kernel or not, defer the IOMMU configuration + * or just abort it. + */ if (!ops) - return NULL; + return iort_iommu_driver_enabled(node->type) ? + ERR_PTR(-EPROBE_DEFER) : NULL; ret = arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); } @@ -625,12 +634,26 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev) while (parent) { ops = iort_iommu_xlate(dev, parent, streamid); + if (IS_ERR_OR_NULL(ops)) + return ops; parent = iort_node_get_id(node, &streamid, IORT_IOMMU_TYPE, i++); } } + /* + * If we have reason to believe the IOMMU driver missed the initial + * add_device callback for dev, replay it to get things in order. + */ + if (!IS_ERR_OR_NULL(ops) && ops->add_device && + dev->bus && !dev->iommu_group) { + int err = ops->add_device(dev); + + if (err) + ops = ERR_PTR(err); + } + return ops; } diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1926918..823b005 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1373,20 +1373,23 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) * @dev: The pointer to the device * @attr: device dma attributes */ -void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) +int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) { const struct iommu_ops *iommu; iort_set_dma_mask(dev); iommu = iort_iommu_configure(dev); - + if (IS_ERR(iommu)) + return PTR_ERR(iommu); /* * Assume dma valid range starts at 0 and covers the whole * coherent_dma_mask. */ arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu, attr == DEV_DMA_COHERENT); + + return 0; } EXPORT_SYMBOL_GPL(acpi_dma_configure); diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 294942d..4b62a32 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -371,7 +371,7 @@ int dma_configure(struct device *dev) if (attr == DEV_DMA_NOT_SUPPORTED) dev_warn(dev, "DMA not supported.\n"); else - acpi_dma_configure(dev, attr); + ret = acpi_dma_configure(dev, attr); } if (is_pci) diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 4242c31..9aa762fe 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -573,7 +573,7 @@ struct acpi_pci_root { bool acpi_dma_supported(struct acpi_device *adev); enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); -void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); +int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); void acpi_dma_deconfigure(struct device *dev); struct acpi_device *acpi_find_child_device(struct acpi_device *parent, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 5b36974..8b958b6 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -764,8 +764,11 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev) return DEV_DMA_NOT_SUPPORTED; } -static inline void acpi_dma_configure(struct device *dev, - enum dev_dma_attr attr) { } +static inline int acpi_dma_configure(struct device *dev, + enum dev_dma_attr attr) +{ + return 0; +} static inline void acpi_dma_deconfigure(struct device *dev) { } -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
next prev parent reply other threads:[~2017-01-19 15:05 UTC|newest] Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-01-19 15:05 [PATCH V5 00/12] IOMMU probe deferral support Sricharan R 2017-01-19 15:05 ` Sricharan R [not found] ` <1484838356-24962-1-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> 2017-01-19 15:05 ` [PATCH V5 01/12] iommu/of: Refactor of_iommu_configure() for error handling Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 02/12] iommu/of: Prepare for deferred IOMMU configuration Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 03/12] of: dma: Move range size workaround to of_dma_get_range() Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 04/12] of: dma: Make of_dma_deconfigure() public Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 05/12] drivers: platform: Configure dma operations at probe time Sricharan R 2017-01-19 15:05 ` Sricharan R [not found] ` <1484838356-24962-6-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> 2017-01-19 16:48 ` Lorenzo Pieralisi 2017-01-19 16:48 ` Lorenzo Pieralisi 2017-01-20 5:34 ` Sricharan 2017-01-20 5:34 ` Sricharan 2017-01-19 17:49 ` Robin Murphy 2017-01-19 17:49 ` Robin Murphy [not found] ` <327b5a9b-35f6-f6e0-4ef9-d2ed15bb4e49-5wv7dgnIgG8@public.gmane.org> 2017-01-19 19:02 ` Lorenzo Pieralisi 2017-01-19 19:02 ` Lorenzo Pieralisi 2017-01-20 6:25 ` Sricharan 2017-01-20 6:25 ` Sricharan 2017-01-20 6:18 ` Sricharan 2017-01-20 6:18 ` Sricharan 2017-01-19 15:05 ` [PATCH V5 06/12] iommu: of: Handle IOMMU lookup failure with deferred probing or error Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 07/12] arm64: dma-mapping: Remove the notifier trick to handle early setting of dma_ops Sricharan R 2017-01-19 15:05 ` Sricharan R [not found] ` <1484838356-24962-8-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> 2017-01-19 16:20 ` Will Deacon 2017-01-19 16:20 ` Will Deacon 2017-01-19 15:05 ` [PATCH V5 08/12] iommu/arm-smmu: Clean up early-probing workarounds Sricharan R 2017-01-19 15:05 ` Sricharan R [not found] ` <1484838356-24962-9-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> 2017-01-19 16:18 ` Will Deacon 2017-01-19 16:18 ` Will Deacon 2017-01-20 19:20 ` Sricharan 2017-01-20 19:20 ` Sricharan 2017-01-19 16:50 ` Lorenzo Pieralisi 2017-01-19 16:50 ` Lorenzo Pieralisi 2017-01-19 17:58 ` Robin Murphy 2017-01-19 17:58 ` Robin Murphy [not found] ` <b3f0f112-e4a0-fa4d-4f18-44484392a5e9-5wv7dgnIgG8@public.gmane.org> 2017-01-20 6:32 ` Sricharan 2017-01-20 6:32 ` Sricharan 2017-01-19 15:05 ` [PATCH V5 09/12] ACPI/IORT: Add function to check SMMUs drivers presence Sricharan R 2017-01-19 15:05 ` Sricharan R 2017-01-19 15:05 ` [PATCH V5 10/12] drivers: acpi: Configure acpi devices dma operation at probe time Sricharan R 2017-01-19 15:05 ` Sricharan R [not found] ` <1484838356-24962-11-git-send-email-sricharan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org> 2017-01-19 16:42 ` Lorenzo Pieralisi 2017-01-19 16:42 ` Lorenzo Pieralisi 2017-01-20 5:31 ` Sricharan 2017-01-20 5:31 ` Sricharan 2017-01-19 15:05 ` Sricharan R [this message] 2017-01-19 15:05 ` [PATCH V5 11/12] drivers: acpi: Handle IOMMU lookup failure with deferred probing or error Sricharan R 2017-01-19 15:05 ` [PATCH V5 12/12] ACPI/IORT: Remove linker section for IORT entries probing Sricharan R 2017-01-19 15:05 ` Sricharan R
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1484838356-24962-12-git-send-email-sricharan@codeaurora.org \ --to=sricharan-sgv2jx0feol9jmxxk+q4oq@public.gmane.org \ --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \ --cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \ --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \ --cc=linux-arm-msm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \ --cc=lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org \ --cc=m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \ --cc=robin.murphy-5wv7dgnIgG8@public.gmane.org \ --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.