From patchwork Thu Sep 21 13:17:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 9963937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6181C6056A for ; Thu, 21 Sep 2017 13:27:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A713293F7 for ; Thu, 21 Sep 2017 13:27:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F349293F9; Thu, 21 Sep 2017 13:27:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11922293F7 for ; Thu, 21 Sep 2017 13:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nJ/HmCxSaiXryCMOjWUoCiQF/TL/meHqOK6Vj0hY23c=; b=kURIB1S1nfl0zs fgkNcPtHbd1PW9BuoHqP4OiMguYjRRN9+hIA1NhY56sFspyzrj9Hvjz0Kb9VludRWpNRLfaon/c+X JmyNW3gNc6Xm7/eGrOepiuE11QuwXHS5n8ICi+I2e/VW+mURVevgkLCSa28jiScn/uVIzmbFxsPrt poaL9b5feBrpnVkEawcdap1Yc9tbJff7ce3N1Zo/5mzn3QsowpnELFGA1xBEu2ZYAMVxoy7tLRJK3 hR5TY+WQ0/BeGR2n2YkdEjs0s6+KKvX5+XGPzZ4XJQGxq3CZDa1szE0bri3JBqIWVXJUNX40Nm+UM F751qk13Vh6ufg4b0ugg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dv1Vz-0002UT-UA; Thu, 21 Sep 2017 13:27:39 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dv1UV-0001C0-EB for linux-arm-kernel@lists.infradead.org; Thu, 21 Sep 2017 13:26:16 +0000 Received: from 172.30.72.58 (EHLO DGGEMS407-HUB.china.huawei.com) ([172.30.72.58]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DHT62125; Thu, 21 Sep 2017 21:25:31 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.301.0; Thu, 21 Sep 2017 21:25:20 +0800 From: Hanjun Guo To: Lorenzo Pieralisi , Robin Murphy Subject: [RFC PATCH v2 4/4] ACPI: IORT: SMMUv3 nodes MSI support Date: Thu, 21 Sep 2017 21:17:18 +0800 Message-ID: <1505999838-52530-5-git-send-email-guohanjun@huawei.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1505999838-52530-1-git-send-email-guohanjun@huawei.com> References: <1505999838-52530-1-git-send-email-guohanjun@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0C0202.59C3BDCB.00CA, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: acb0349afdb7923f3c45dd1723f23269 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170921_062608_702233_93833C76 X-CRM114-Status: GOOD ( 16.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , Marc Zyngier , linuxarm@huawei.com, linux-acpi@vger.kernel.org, Hanjun Guo , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Lorenzo Pieralisi Since we make single mappings valid for SMMUv3 (and PMCG), also we have a mapping index for SMMUv3 MSI, we can directly use that index to get the map entry, then retrieve dev ID and ITS parent to add SMMUv3 MSI support. Introduce a new API iort_set_device_domain() to find the MSI domain for an SMMUv3 (or any other IORT table node) to reduce the complex of doing that via acpi_configure_pmsi_domain(), then reuse the iort_node_get_id() to get the dev id for SMMU MSI. Signed-off-by: Lorenzo Pieralisi Signed-off-by: Hanjun Guo --- drivers/acpi/arm64/iort.c | 99 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 269959e..bbab2ab 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -357,7 +357,8 @@ struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || - node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { + node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX || + node->type == ACPI_IORT_NODE_SMMU_V3) { *id_out = map->output_base; return parent; } @@ -366,8 +367,8 @@ struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, return NULL; } -static int iort_get_smmu_v3_id_mapping_index(struct acpi_iort_node *node, - u32 *index) +static int iort_get_id_mapping_index(struct acpi_iort_node *node, + u32 *index) { struct acpi_iort_smmu_v3 *smmu; @@ -378,20 +379,28 @@ static int iort_get_smmu_v3_id_mapping_index(struct acpi_iort_node *node, if (node->revision < 1) return -EINVAL; - smmu = (struct acpi_iort_smmu_v3 *)node->node_data; - /* if any of the gsi for control interrupts is not 0, ignore the MSI */ - if (smmu->event_gsiv || smmu->pri_gsiv || smmu->gerr_gsiv - || smmu->sync_gsiv) - return -EINVAL; + switch (node->type) { + case ACPI_IORT_NODE_SMMU_V3: + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + /* + * if any of the gsi for control interrupts is not 0, + * ignore the MSI + */ + if (smmu->event_gsiv || smmu->pri_gsiv || smmu->gerr_gsiv + || smmu->sync_gsiv) + return -EINVAL; - if (smmu->id_mapping_index >= node->mapping_count) { - pr_err(FW_BUG "[node %p type %d] ID mapping index overflows valid mappings\n", - node, node->type); + if (smmu->id_mapping_index >= node->mapping_count) { + pr_err(FW_BUG "[node %p type %d] ID mapping index overflows valid mappings\n", + node, node->type); + return -EINVAL; + } + + *index = smmu->id_mapping_index; + return 0; + default: return -EINVAL; } - - *index = smmu->id_mapping_index; - return 0; } static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, @@ -431,7 +440,7 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, * associated ID map for single mapping cases. */ if (node->type == ACPI_IORT_NODE_SMMU_V3) - ret = iort_get_smmu_v3_id_mapping_index(node, &index); + ret = iort_get_id_mapping_index(node, &index); /* Do the ID translation */ for (i = 0; i < node->mapping_count; i++, map++) { @@ -555,9 +564,18 @@ int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) if (!node) return -ENODEV; - for (i = 0; i < node->mapping_count; i++) { - if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i)) - return 0; + if (node->type == ACPI_IORT_NODE_SMMU_V3) { + u32 index; + + if (!iort_get_id_mapping_index(node, &index)) { + if (iort_node_get_id(node, dev_id, index)) + return 0; + } + } else { + for (i = 0; i < node->mapping_count; i++) { + if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i)) + return 0; + } } return -ENODEV; @@ -620,6 +638,49 @@ struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id) return irq_find_matching_fwnode(handle, DOMAIN_BUS_PCI_MSI); } +static void iort_set_device_domain(struct device *dev, + struct acpi_iort_node *node) +{ + struct acpi_iort_its_group *its; + struct acpi_iort_node *msi_parent; + struct acpi_iort_id_mapping *map; + struct fwnode_handle *iort_fwnode; + struct irq_domain *domain; + int ret, index; + + ret = iort_get_id_mapping_index(node, &index); + if (ret < 0) + return; + + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, + node->mapping_offset + index * sizeof(*map)); + + /* Firmware bug! */ + if (!map->output_reference || + !(map->flags & ACPI_IORT_ID_SINGLE_MAPPING)) { + pr_err(FW_BUG "[node %p type %d] Invalid MSI mapping\n", + node, node->type); + return; + } + + msi_parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, + map->output_reference); + + if (!msi_parent || msi_parent->type != ACPI_IORT_NODE_ITS_GROUP) + return; + + /* Move to ITS specific data */ + its = (struct acpi_iort_its_group *)msi_parent->node_data; + + iort_fwnode = iort_find_domain_token(its->identifiers[0]); + if (!iort_fwnode) + return; + + domain = irq_find_matching_fwnode(iort_fwnode, DOMAIN_BUS_PLATFORM_MSI); + if (domain) + dev_set_msi_domain(dev, domain); +} + /** * iort_get_platform_device_domain() - Find MSI domain related to a * platform device @@ -1246,6 +1307,8 @@ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node) /* Configure DMA for the page table walker */ acpi_dma_configure(&pdev->dev, attr); + iort_set_device_domain(&pdev->dev, node); + ret = platform_device_add(pdev); if (ret) goto dma_deconfigure;