From patchwork Wed Sep 27 01:20:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 9972905 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 C0CFD60365 for ; Wed, 27 Sep 2017 01:33:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B548628D54 for ; Wed, 27 Sep 2017 01:33:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A94E629040; Wed, 27 Sep 2017 01:33:59 +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 3DB1B28D54 for ; Wed, 27 Sep 2017 01:33:59 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=7q53d7/wYl3uULWQrdMHkI9yY5zay9+JUgbi0LV/+x0=; b=p4QSHe3QLcy34QX8ZB6u6dwkQs cnOYtFuwd00AFH6K/szJVGM9dzvQKQcyS3CK4zUHOc0mR5TfsRWz1P+5QBEo9JUOA8JPRdFn6QdNF dQZKAYE9MiS31+qhdgxcdyA2t2MSbHLIB9qM8chnJ53DrQyTUWgLOQvGXqGNBw2TYw0AyekVyPCs0 TiBiiAPq4PUGm/xuTMnXdbs/jUBCYy3xISjprFgRUv1mXKLTOn2vlmB1tp82PpfKhPu+fT726R4/V SPo+CNtOiTqpLZ4IuIRP2zpnuOoYaSvZcqypwSOr0KMoeXAs36/MT64uOOVsOKjir71AwhSCRiaMD +apbZMMg==; 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 1dx1Eb-00022i-IK; Wed, 27 Sep 2017 01:33:57 +0000 Received: from mail-pg0-x230.google.com ([2607:f8b0:400e:c05::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dx122-0002Ht-AQ for linux-arm-kernel@lists.infradead.org; Wed, 27 Sep 2017 01:21:04 +0000 Received: by mail-pg0-x230.google.com with SMTP id 7so6862875pgd.13 for ; Tue, 26 Sep 2017 18:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LCrVw/tMCQA9Z3zMu4C/+3jm0PyjF+UcxwnmGZ5oECs=; b=B9aYNe3hqoMHMHsNfFATvLVwb+YZIwDSKlP2POGCswd9YZ1IEeY2k9XdCc9opJ+BEA lO2aBcUx2F6ICA1lJ85cQOElEvoyJW9v5E98OfhiiaN/Ea5Ua9T399Xkk3Jd76Kt4bJa OOjYgtp+oNUDVGAsu1rqP3xS7gi8wyI1ctYG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LCrVw/tMCQA9Z3zMu4C/+3jm0PyjF+UcxwnmGZ5oECs=; b=rg7tIhgt+ezfTRQMxo5vHI5fRQNoEXeisIOdaag31sUlwDKh5x4n1BfT2wjsHBz/2H CKGnxJlHGen8K5tL2vPKIeynNcZVlAyWVZZaAd2/jDUbRw+sojEw7cUFeLERTFM8kYDg Eesp2kGC1hstOBeP5Z96XloRLkJts/CSjAi+H2FNGS253Ev/D5D7jWuT8Bgzo55D5KvA JjFWaMtfWcVx1ZV5YfOPmj+kfF5YeGkluo57uvrnAIUFusBs4U0WH04woxs28KaYrm1Y o1049yLg/7QiUmVfEwQdG02sf6Yt12sx5w6VYKjdPJ4oIMHDNK5UP5nqTjrzF0A0Om/R 5U6w== X-Gm-Message-State: AHPjjUikTsbpOYNKd9miciDcfG05tH6AMRSC3FMakrpennP7Rq0PYOOT EeC0IveAi1tgnbUjLymFn1u8cg== X-Google-Smtp-Source: AOwi7QDEzAqThiAjVuW/ET+0J8lct/4fBTp3u44ZU7qRpx0UpZJWET6FaIR+lt4yE3i31go7DcoUHA== X-Received: by 10.101.78.12 with SMTP id r12mr12634008pgt.289.1506475237381; Tue, 26 Sep 2017 18:20:37 -0700 (PDT) Received: from localhost ([70.35.39.2]) by smtp.googlemail.com with ESMTPSA id s27sm18510873pgo.59.2017.09.26.18.20.36 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 26 Sep 2017 18:20:36 -0700 (PDT) From: Hanjun Guo To: Lorenzo Pieralisi , Robin Murphy Subject: [PATCH 3/4] ACPI: IORT: Skip SMMUv3 device ID map for two steps mappings Date: Wed, 27 Sep 2017 09:20:14 +0800 Message-Id: <1506475215-2731-4-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1506475215-2731-1-git-send-email-hanjun.guo@linaro.org> References: <1506475215-2731-1-git-send-email-hanjun.guo@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170926_182058_602136_48BD457B X-CRM114-Status: GOOD ( 21.60 ) 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: Marc Zyngier , "Rafael J. Wysocki" , linuxarm@huawei.com, linux-acpi@vger.kernel.org, Lv Zheng , linux-arm-kernel@lists.infradead.org, Hanjun Guo MIME-Version: 1.0 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 IORT revision C introduced SMMUv3 MSI support which adding a device ID mapping index in SMMUv3 sub table, to get the SMMUv3 device ID mapping for the output ID (dev ID for ITS) and the link to which ITS. So if a platform supports SMMUv3 MSI for control interrupt, there will be a additional single map entry under SMMU, this will not introduce any difference for devices just use one step map to get its output ID and parent (ITS or SMMU), such as PCI/NC/PMCG ---> ITS or PCI/NC ---> SMMU, but we need to do the special handling for two steps map case such as PCI/NC--->SMMUv3--->ITS. Take a PCI hostbridge for example, |----------------------| | Root Complex Node | |----------------------| | map entry[x] | |----------------------| | id value | | output_reference | |---|------------------| | | |----------------------| |-->| SMMUv3 | |----------------------| | SMMU dev ID | | mapping index 0 | |----------------------| | map entry[0] | |----------------------| | id value | | output_reference-----------> ITS 1 (SMMU MSI domain) |----------------------| | map entry[1] | |----------------------| | id value | | output_reference-----------> ITS 2 (PCI MSI domain) |----------------------| When the SMMU dev ID mapping index is 0, there is entry[0] to map to a ITS, we need to skip that map entry for PCI or NC (named component), or we may get the wrong ITS parent. Introduce iort_get_id_mapping_index() to get the index then skip the map entry in iort_node_map_id(), also to get the dev ID directly for iort_pmsi_get_dev_id() for ITS platform MSI preparation. Signed-off-by: Hanjun Guo --- drivers/acpi/arm64/iort.c | 64 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index db71d7f..1c1160e 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,6 +367,40 @@ struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, return NULL; } +static int iort_get_id_mapping_index(struct acpi_iort_node *node) +{ + struct acpi_iort_smmu_v3 *smmu; + + switch (node->type) { + case ACPI_IORT_NODE_SMMU_V3: + /* + * SMMUv3 dev ID mapping index was introdueced in revision 1 + * table, not available in revision 0 + */ + if (node->revision < 1) + return -EINVAL; + + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + /* + * ID mapping index is only ignored if all interrupts are + * GSIV based + */ + 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); + return -EINVAL; + } + + return smmu->id_mapping_index; + default: + return -EINVAL; + } +} + static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, u32 id_in, u32 *id_out, u8 type_mask) @@ -375,7 +410,7 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, /* Parse the ID mapping tree to find specified node type */ while (node) { struct acpi_iort_id_mapping *map; - int i; + int i, index; if (IORT_TYPE_MASK(node->type) & type_mask) { if (id_out) @@ -396,8 +431,19 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, goto fail_map; } + /* + * we need to get SMMUv3 dev ID mapping index and skip its + * associated ID map for single mapping cases, error value + * returned for index will be an invalid value in practical. + */ + index = iort_get_id_mapping_index(node); + /* Do the ID translation */ for (i = 0; i < node->mapping_count; i++, map++) { + /* if it's a SMMUv3 device id mapping index, skip it */ + if (i == index) + continue; + if (!iort_id_map(map, node->type, id, &id)) break; } @@ -507,16 +553,24 @@ u32 iort_msi_map_rid(struct device *dev, u32 req_id) */ int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) { - int i; + int i, index; struct acpi_iort_node *node; node = iort_find_dev_node(dev); 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)) + index = iort_get_id_mapping_index(node); + /* if there is a valid index, go get the dev_id directly */ + if (index >= 0) { + 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;