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: 89502 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp7592879qgi; Mon, 2 Jan 2017 05:34:12 -0800 (PST) X-Received: by 10.84.211.69 with SMTP id b63mr127910732pli.25.1483364052854; Mon, 02 Jan 2017 05:34:12 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si33962076pfl.94.2017.01.02.05.34.12; Mon, 02 Jan 2017 05:34:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933168AbdABNd7 (ORCPT + 25 others); Mon, 2 Jan 2017 08:33:59 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:34637 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933135AbdABNd4 (ORCPT ); Mon, 2 Jan 2017 08:33:56 -0500 Received: by mail-pf0-f173.google.com with SMTP id c4so73073061pfb.1 for ; Mon, 02 Jan 2017 05:33:55 -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=ftwnhqgG+jqcB6KUYlGGAlUEtaNfgEIGVFIVAURKy3kX980Db7CgE8xHabLEedDoqi W7I5Tt+sLEl9i6Opf7ay7ZO/uiqGk52Xt7sb663/XeygXtfIcY6tCGCDY1OQmngyrn14 zDLRUsL20W1aD0gTyk0u1mfj3axAsJigIhNDT6QOK4+rPTuO+tkL4SHywGFKNJp/0trn LmdWZL1g9YutawlV/qcCpoHyQM3E1qQIhrTh6DZ1xRWI9IoYVBrxEyRLnodxmiG4jp7r LKWCV1C3W7qkKQuq+eKoP08LmoH7Z++lYmuA54kRXRc9buYx5tfmn7gNG9qM+iG0xKyj Z+Uw== X-Gm-Message-State: AIkVDXJcWCuidTYHmb7Nfl7Jqc/mwhkiVOeCthPJG4TKyuKQYIf4uyjJr+amFQSKzNTIhYFG 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 Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, Thomas Gleixner , Greg KH , Tomasz Nowicki , Ma Jun , Kefeng Wang , Agustin Vega-Frias , Sinan Kaya , charles.garcia-tobin@arm.com, huxinwei@huawei.com, yimin@huawei.com, Jon Masters , Hanjun Guo 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.9.1 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; }