From patchwork Mon Jan 2 13:31:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 9493641 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 B82E162AB4 for ; Mon, 2 Jan 2017 13:36:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A84731FF35 for ; Mon, 2 Jan 2017 13:36:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BE772679B; Mon, 2 Jan 2017 13:36:17 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2454D1FF35 for ; Mon, 2 Jan 2017 13:36:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cO2lC-0006Ip-Li; Mon, 02 Jan 2017 13:34:46 +0000 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cO2ki-0005nt-Op for linux-arm-kernel@lists.infradead.org; Mon, 02 Jan 2017 13:34:22 +0000 Received: by mail-pf0-x232.google.com with SMTP id i88so72928280pfk.2 for ; Mon, 02 Jan 2017 05:33:56 -0800 (PST) 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=hFyrimkXdY/OiqicucoMjRD2mw0daGgz6Y8qdMqkeHI=; b=Pzw7uXkybwbugPfOAzbU4ThdinX92hGQvuo9w/poXr3kKYd9Y7TpYJgtfdeehJTmMV JrgouEwErZ5eTEJnw8xbu8qt2QhIJPAntEWKr8qwszNTQAM61TpbYe1dTMTAuk4+T1a1 zL+4uYlEozSTk/RoodP58v63756Nfh6YhRWeI= 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=hFyrimkXdY/OiqicucoMjRD2mw0daGgz6Y8qdMqkeHI=; b=JKOS6+jibC4x0Ku74jCC61RtC05Gu5HSsmFoiweKoUxfukGzZfgWfgpMVmeAdGef9H 5JzTts4Es1lyatI1ADga+P4DPgCo5GcFJ3+Xu1QxHPy1Pw7qh5OuF45wHBHe9hgXxGsc 0T41SzGohzDbV8I+EGiSLbyrnAnc9h9C7NvrV2L5aoyf2jpFL+q6t2q92IjKZwdBhdfX NG1hBdzA0fN9iSiR82rF12HIw2uwy81qq//m2uVdAmcyzLsashC2TM4ue3GkBuk8Fve7 4Ue5Vw++/C3pux8fqkpP8FBByKCAuJXJ34gwJ5qj6cGh3V/jd94bPu2QsJGrz+1CWLOr SnsQ== X-Gm-Message-State: AIkVDXLSm6uSNfiaM3CIxNk90BQ2Ot1IkAitfSgfvDa7ck0LIcFQ76X7G+mkoqqs8/MxYV/9 X-Received: by 10.84.210.38 with SMTP id z35mr110278332plh.111.1483364035396; Mon, 02 Jan 2017 05:33:55 -0800 (PST) Received: from localhost ([104.237.91.251]) by smtp.googlemail.com with ESMTPSA id s3sm132679211pfe.27.2017.01.02.05.33.53 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 02 Jan 2017 05:33:54 -0800 (PST) From: Hanjun Guo To: Marc Zyngier , "Rafael J. Wysocki" , Lorenzo Pieralisi Subject: [PATCH v6 10/14] ACPI: ARM64: IORT: rework iort_node_get_id() for NC->SMMU->ITS case Date: Mon, 2 Jan 2017 21:31:41 +0800 Message-Id: <1483363905-2806-11-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483363905-2806-1-git-send-email-hanjun.guo@linaro.org> References: <1483363905-2806-1-git-send-email-hanjun.guo@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170102_053417_285967_F36AF22B X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huxinwei@huawei.com, Kefeng Wang , charles.garcia-tobin@arm.com, Jon Masters , yimin@huawei.com, Greg KH , linux-kernel@vger.kernel.org, linuxarm@huawei.com, Sinan Kaya , linux-acpi@vger.kernel.org, Hanjun Guo , Tomasz Nowicki , Thomas Gleixner , Agustin Vega-Frias , linux-arm-kernel@lists.infradead.org, Ma Jun 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_node_get_id() for now only support NC(named componant)->SMMU or NC->ITS cases, we also have other device topology such NC-> SMMU->ITS, so rework iort_node_get_id() for those cases. Signed-off-by: Hanjun Guo Tested-by: Majun Tested-by: Xinwei Kong Cc: Lorenzo Pieralisi --- drivers/acpi/arm64/iort.c | 61 ++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 6b72fcb..99f079b 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -292,22 +292,28 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, return status; } -static int iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, - u32 *rid_out) +static int iort_id_single_map(struct acpi_iort_id_mapping *map, u8 type, + u32 *rid_out) { /* Single mapping does not care for input id */ if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { if (type == ACPI_IORT_NODE_NAMED_COMPONENT || type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { - *rid_out = map->output_base; + if (rid_out) + *rid_out = map->output_base; return 0; } pr_warn(FW_BUG "[map %p] SINGLE MAPPING flag not allowed for node type %d, skipping ID map\n", map, type); - return -ENXIO; } + return -ENXIO; +} + +static int iort_id_map(struct acpi_iort_id_mapping *map, u32 rid_in, + u32 *rid_out) +{ if (rid_in < map->input_base || (rid_in >= map->input_base + map->id_count)) return -ENXIO; @@ -324,33 +330,34 @@ struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, struct acpi_iort_node *parent; struct acpi_iort_id_mapping *map; - if (!node->mapping_offset || !node->mapping_count || - index >= node->mapping_count) - return NULL; - - map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, - node->mapping_offset); + while (node) { + if (!node->mapping_offset || !node->mapping_count || + index >= node->mapping_count) + return NULL; - /* Firmware bug! */ - if (!map->output_reference) { - pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", - node, node->type); - return NULL; - } + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, + node->mapping_offset); - parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, - map->output_reference); + /* Firmware bug! */ + if (!map->output_reference) { + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", + node, node->type); + return NULL; + } - if (!(IORT_TYPE_MASK(parent->type) & type_mask)) - return NULL; + parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, + map->output_reference); - if (map[index].flags & ACPI_IORT_ID_SINGLE_MAPPING) { - if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || - node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { - if (id_out) - *id_out = map[index].output_base; - return parent; + /* go upstream to find its parent */ + if (!(IORT_TYPE_MASK(parent->type) & type_mask)) { + node = parent; + continue; } + + if (iort_id_single_map(&map[index], node->type, id_out)) + break; + + return parent; } return NULL; @@ -388,7 +395,7 @@ static struct acpi_iort_node *iort_node_map_rid(struct acpi_iort_node *node, /* Do the RID translation */ for (i = 0; i < node->mapping_count; i++, map++) { - if (!iort_id_map(map, node->type, rid, &rid)) + if (!iort_id_map(map, rid, &rid)) break; }