From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01B32C48BDF for ; Tue, 22 Jun 2021 07:48:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4BD5611CE for ; Tue, 22 Jun 2021 07:48:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4BD5611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date :Message-ID:From:References:Cc:To:Subject:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YPFFYm92vbMZL4HEfMX3gmTfNRYVC4ZB4qdE3U4zlho=; b=pmslZHP7T/MU/h JoWV/5cqZVLAQWrAnt9vyLd/4fHAfUaG651MfKbnDlr9GjDtTXpuNkNh0lFZqH1F6SjohtpoOQwOC ICkCYv2yxL4sersntR3NZynECAB1tWI4NdvkyfW0sJe3MLOij1FyVrJGL9Q8Isu1PMmsa/xCGUJbF zAGqdomr6werXTA2gLoJHelX/q7kxixtJNLa9fKhe6BahNcj3ueR+vzlMRjHeaapQO9TZqwJJNEiP 8fiW6n0NIvlLMkSPVLhtaUfu7OHXNZe7LCeFRb0sewa8q1+6dS7PiYNl9VweXY70GR2tMUUKvyDR+ 7b0qz3ECVj5m9VnmMvXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvb7Y-0065cu-Gj; Tue, 22 Jun 2021 07:46:56 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvb79-0065UE-8L for linux-arm-kernel@lists.infradead.org; Tue, 22 Jun 2021 07:46:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624347990; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x5f3bvS7GZvWVtyFwxLN1QlKyB6zTisOpr3FYaadj24=; b=duLAhcngzVOkNlgswjWMGLO8UBLYN1guCeZXzNnOj3SUVFEaVGuT8oT4yDSt2WrJd6MWge sK4ForLidMY8ZBu90JOxxKg0+EkvIiGSk4BkmsvkSPXAWW1RgasmOL/fDj0BOPW9BTRcpl aiRI+9/tNYcb+ZMfDV/JqlXYrbkSdeE= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-222-4N_JogMvNP-plWN2DBUk9A-1; Tue, 22 Jun 2021 03:46:29 -0400 X-MC-Unique: 4N_JogMvNP-plWN2DBUk9A-1 Received: by mail-wm1-f72.google.com with SMTP id h14-20020a05600c350eb02901dfc071c176so960754wmq.3 for ; Tue, 22 Jun 2021 00:46:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=x5f3bvS7GZvWVtyFwxLN1QlKyB6zTisOpr3FYaadj24=; b=TyihMiZ2EOPyM2jWN83fMrCSRCaeCW08zWrbZlsDbsVBJyl1oPSEWVYHb4/Lm/8cQF AbnMkIC/B60dvRzuHNDRlXNTMewCOrbjzOg8vH5WuXq2IQsk2BZydpBY3GqDLJskXafS ceCe1uvo9s8D2cPz0NhI0RrRt1tfVmsEpkxjM+ZOj03TULF+duSApUjLWyY/ASrWwGCl KIPSaIM7JPwfB3QLZQMJ7nReBUdQO7OHn7YmxuqaOa34aX16jpCUPnDQ4jKTcJRm6pOC LWPAehF39fiOHIhnoZtiqrKVmIyUZniEdJI/9SvFVIDVOey5y2i2ConSmg5k+qCkVtFS gbXg== X-Gm-Message-State: AOAM531WJCpiwjO/kPOfgKB+oNZIvNpa65Fb9SKDmgl/d2BdiPNihlmT 7ws0ndA5FTmSrykN22BsG9E0gJyKLmovptTje2I5In2tJtmzKLUR8u4dOF3Lw6xf0ATh8IszBw4 My7HNuAfptkgtSxLPNtvcFz7mkYFtUxfOQeU= X-Received: by 2002:adf:c54b:: with SMTP id s11mr3106155wrf.349.1624347988023; Tue, 22 Jun 2021 00:46:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7QcWI8FJ95aqU4FW0VTatFzT/ZlH2y3xbB+zmvo9mrdoUIlvfW4P0sodDcWmUan4mPoZSHw== X-Received: by 2002:adf:c54b:: with SMTP id s11mr3106134wrf.349.1624347987821; Tue, 22 Jun 2021 00:46:27 -0700 (PDT) Received: from [192.168.43.95] ([37.173.9.63]) by smtp.gmail.com with ESMTPSA id g10sm1443719wmh.33.2021.06.22.00.46.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 00:46:27 -0700 (PDT) Subject: Re: [PATCH v5 2/5] ACPI: Move IOMMU setup code out of IORT To: Jean-Philippe Brucker , rjw@rjwysocki.net, lenb@kernel.org, joro@8bytes.org, mst@redhat.com Cc: will@kernel.org, catalin.marinas@arm.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, sebastien.boeuf@intel.com, robin.murphy@arm.com, kevin.tian@intel.com, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com References: <20210618152059.1194210-1-jean-philippe@linaro.org> <20210618152059.1194210-3-jean-philippe@linaro.org> From: Eric Auger Message-ID: <6da435e7-3204-e0d1-4c53-e7115e537cb5@redhat.com> Date: Tue, 22 Jun 2021 09:46:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210618152059.1194210-3-jean-philippe@linaro.org> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eric.auger@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210622_004631_469849_2CEC9976 X-CRM114-Status: GOOD ( 34.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: eric.auger@redhat.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Jean, On 6/18/21 5:20 PM, Jean-Philippe Brucker wrote: > Extract the code that sets up the IOMMU infrastructure from IORT, since > it can be reused by VIOT. Move it one level up into a new > acpi_iommu_configure_id() function, which calls the IORT parsing > function which in turn calls the acpi_iommu_fwspec_init() helper. > > Signed-off-by: Jean-Philippe Brucker Reviewed-by: Eric Auger Thanks Eric > --- > include/acpi/acpi_bus.h | 3 ++ > include/linux/acpi_iort.h | 8 ++--- > drivers/acpi/arm64/iort.c | 74 +++++---------------------------------- > drivers/acpi/scan.c | 73 +++++++++++++++++++++++++++++++++++++- > 4 files changed, 86 insertions(+), 72 deletions(-) > > diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h > index 3a82faac5767..41f092a269f6 100644 > --- a/include/acpi/acpi_bus.h > +++ b/include/acpi/acpi_bus.h > @@ -588,6 +588,9 @@ struct acpi_pci_root { > > bool acpi_dma_supported(struct acpi_device *adev); > enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); > +int acpi_iommu_fwspec_init(struct device *dev, u32 id, > + struct fwnode_handle *fwnode, > + const struct iommu_ops *ops); > int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset, > u64 *size); > int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h > index f7f054833afd..f1f0842a2cb2 100644 > --- a/include/linux/acpi_iort.h > +++ b/include/linux/acpi_iort.h > @@ -35,8 +35,7 @@ void acpi_configure_pmsi_domain(struct device *dev); > int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id); > /* IOMMU interface */ > int iort_dma_get_ranges(struct device *dev, u64 *size); > -const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > - const u32 *id_in); > +int iort_iommu_configure_id(struct device *dev, const u32 *id_in); > int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head); > phys_addr_t acpi_iort_dma_get_max_cpu_address(void); > #else > @@ -50,9 +49,8 @@ static inline void acpi_configure_pmsi_domain(struct device *dev) { } > /* IOMMU interface */ > static inline int iort_dma_get_ranges(struct device *dev, u64 *size) > { return -ENODEV; } > -static inline const struct iommu_ops *iort_iommu_configure_id( > - struct device *dev, const u32 *id_in) > -{ return NULL; } > +static inline int iort_iommu_configure_id(struct device *dev, const u32 *id_in) > +{ return -ENODEV; } > static inline > int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) > { return 0; } > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > index a940be1cf2af..487d1095030d 100644 > --- a/drivers/acpi/arm64/iort.c > +++ b/drivers/acpi/arm64/iort.c > @@ -806,23 +806,6 @@ static struct acpi_iort_node *iort_get_msi_resv_iommu(struct device *dev) > return NULL; > } > > -static inline const struct iommu_ops *iort_fwspec_iommu_ops(struct device *dev) > -{ > - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > - > - return (fwspec && fwspec->ops) ? fwspec->ops : NULL; > -} > - > -static inline int iort_add_device_replay(struct device *dev) > -{ > - int err = 0; > - > - if (dev->bus && !device_iommu_mapped(dev)) > - err = iommu_probe_device(dev); > - > - return err; > -} > - > /** > * iort_iommu_msi_get_resv_regions - Reserved region driver helper > * @dev: Device from iommu_get_resv_regions() > @@ -900,18 +883,6 @@ static inline bool iort_iommu_driver_enabled(u8 type) > } > } > > -static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, > - struct fwnode_handle *fwnode, > - const struct iommu_ops *ops) > -{ > - int ret = iommu_fwspec_init(dev, fwnode, ops); > - > - if (!ret) > - ret = iommu_fwspec_add_ids(dev, &streamid, 1); > - > - return ret; > -} > - > static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node) > { > struct acpi_iort_root_complex *pci_rc; > @@ -946,7 +917,7 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, > return iort_iommu_driver_enabled(node->type) ? > -EPROBE_DEFER : -ENODEV; > > - return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); > + return acpi_iommu_fwspec_init(dev, streamid, iort_fwnode, ops); > } > > struct iort_pci_alias_info { > @@ -1020,24 +991,13 @@ static int iort_nc_iommu_map_id(struct device *dev, > * @dev: device to configure > * @id_in: optional input id const value pointer > * > - * Returns: iommu_ops pointer on configuration success > - * NULL on configuration failure > + * Returns: 0 on success, <0 on failure > */ > -const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > - const u32 *id_in) > +int iort_iommu_configure_id(struct device *dev, const u32 *id_in) > { > struct acpi_iort_node *node; > - const struct iommu_ops *ops; > int err = -ENODEV; > > - /* > - * If we already translated the fwspec there > - * is nothing left to do, return the iommu_ops. > - */ > - ops = iort_fwspec_iommu_ops(dev); > - if (ops) > - return ops; > - > if (dev_is_pci(dev)) { > struct iommu_fwspec *fwspec; > struct pci_bus *bus = to_pci_dev(dev)->bus; > @@ -1046,7 +1006,7 @@ const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, > iort_match_node_callback, &bus->dev); > if (!node) > - return NULL; > + return -ENODEV; > > info.node = node; > err = pci_for_each_dma_alias(to_pci_dev(dev), > @@ -1059,7 +1019,7 @@ const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, > iort_match_node_callback, dev); > if (!node) > - return NULL; > + return -ENODEV; > > err = id_in ? iort_nc_iommu_map_id(dev, node, id_in) : > iort_nc_iommu_map(dev, node); > @@ -1068,32 +1028,14 @@ const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > iort_named_component_init(dev, node); > } > > - /* > - * 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 (!err) { > - ops = iort_fwspec_iommu_ops(dev); > - err = iort_add_device_replay(dev); > - } > - > - /* Ignore all other errors apart from EPROBE_DEFER */ > - if (err == -EPROBE_DEFER) { > - ops = ERR_PTR(err); > - } else if (err) { > - dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); > - ops = NULL; > - } > - > - return ops; > + return err; > } > > #else > int iort_iommu_msi_get_resv_regions(struct device *dev, struct list_head *head) > { return 0; } > -const struct iommu_ops *iort_iommu_configure_id(struct device *dev, > - const u32 *input_id) > -{ return NULL; } > +int iort_iommu_configure_id(struct device *dev, const u32 *input_id) > +{ return -ENODEV; } > #endif > > static int nc_dma_get_range(struct device *dev, u64 *size) > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c > index ea613df8f913..2a2e690040e9 100644 > --- a/drivers/acpi/scan.c > +++ b/drivers/acpi/scan.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1520,6 +1521,76 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset, > return ret >= 0 ? 0 : ret; > } > > +#ifdef CONFIG_IOMMU_API > +int acpi_iommu_fwspec_init(struct device *dev, u32 id, > + struct fwnode_handle *fwnode, > + const struct iommu_ops *ops) > +{ > + int ret = iommu_fwspec_init(dev, fwnode, ops); > + > + if (!ret) > + ret = iommu_fwspec_add_ids(dev, &id, 1); > + > + return ret; > +} > + > +static inline const struct iommu_ops *acpi_iommu_fwspec_ops(struct device *dev) > +{ > + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > + > + return fwspec ? fwspec->ops : NULL; > +} > + > +static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > + const u32 *id_in) > +{ > + int err; > + const struct iommu_ops *ops; > + > + /* > + * If we already translated the fwspec there is nothing left to do, > + * return the iommu_ops. > + */ > + ops = acpi_iommu_fwspec_ops(dev); > + if (ops) > + return ops; > + > + err = iort_iommu_configure_id(dev, id_in); > + > + /* > + * If we have reason to believe the IOMMU driver missed the initial > + * iommu_probe_device() call for dev, replay it to get things in order. > + */ > + if (!err && dev->bus && !device_iommu_mapped(dev)) > + err = iommu_probe_device(dev); > + > + /* Ignore all other errors apart from EPROBE_DEFER */ > + if (err == -EPROBE_DEFER) { > + return ERR_PTR(err); > + } else if (err) { > + dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); > + return NULL; > + } > + return acpi_iommu_fwspec_ops(dev); > +} > + > +#else /* !CONFIG_IOMMU_API */ > + > +int acpi_iommu_fwspec_init(struct device *dev, u32 id, > + struct fwnode_handle *fwnode, > + const struct iommu_ops *ops) > +{ > + return -ENODEV; > +} > + > +static const struct iommu_ops *acpi_iommu_configure_id(struct device *dev, > + const u32 *id_in) > +{ > + return NULL; > +} > + > +#endif /* !CONFIG_IOMMU_API */ > + > /** > * acpi_dma_configure_id - Set-up DMA configuration for the device. > * @dev: The pointer to the device > @@ -1539,7 +1610,7 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, > > acpi_arch_dma_setup(dev, &dma_addr, &size); > > - iommu = iort_iommu_configure_id(dev, input_id); > + iommu = acpi_iommu_configure_id(dev, input_id); > if (PTR_ERR(iommu) == -EPROBE_DEFER) > return -EPROBE_DEFER; > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel