From patchwork Thu Sep 17 18:00:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 7209621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CEB4EBF036 for ; Thu, 17 Sep 2015 18:03:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F27B72077E for ; Thu, 17 Sep 2015 18:03:21 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 15E472077C for ; Thu, 17 Sep 2015 18:03:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcdVC-0002li-Uq; Thu, 17 Sep 2015 18:01:46 +0000 Received: from mail-ig0-x232.google.com ([2607:f8b0:4001:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZcdUu-0002VQ-BZ for linux-arm-kernel@lists.infradead.org; Thu, 17 Sep 2015 18:01:29 +0000 Received: by igbkq10 with SMTP id kq10so18488547igb.0 for ; Thu, 17 Sep 2015 11:01:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+ikmnAA1LidBqW/umBLZn7+huJ2ytivLlV5MY2y2QNQ=; b=MyHsih+YbjRrqNAHGUvjKQWzrg+TZWnN+ab6qw4m+VqrrTB86BQRPEX7G+0pNsjUJp SUrWkPvwV/wS3lj6XAAf2SN3u5AS2Pt3pWOldT46u8Q4u+nwCNPmBChDmRIGQ5jU9nKm jcbP4GnzCZUwDFdeaB9Myfg66sgaZ0CUMpFvgRz9QpGRHaWLOkW/3AF1yqxwHS9efmco 8X0YkFfGleN3i0qOtKgfRPkY4IVJoz4pr/MVeHV45pPc0wkgTRUdvBwuJeZ8DQMhQRLu A3xJRikUH9OY8EgOc4RCaPpPlkiTHHiRiBBpqIhWsiFRS5q2lTAvlu6x5mam5wveGWfM aMdg== X-Received: by 10.50.1.44 with SMTP id 12mr26690212igj.61.1442512867427; Thu, 17 Sep 2015 11:01:07 -0700 (PDT) Received: from dl.caveonetworks.com (64.2.3.194.ptr.us.xo.net. [64.2.3.194]) by smtp.gmail.com with ESMTPSA id p142sm1798425iop.4.2015.09.17.11.01.05 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 17 Sep 2015 11:01:06 -0700 (PDT) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id t8HI14xK031698; Thu, 17 Sep 2015 11:01:04 -0700 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id t8HI14ED031697; Thu, 17 Sep 2015 11:01:04 -0700 From: David Daney To: linux-kernel@vger.kernel.org, Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH 2/2] irqchip/gicv3-its: Handle OF device tree "msi-map" properties. Date: Thu, 17 Sep 2015 11:00:59 -0700 Message-Id: <1442512859-31633-3-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1442512859-31633-1-git-send-email-ddaney.cavm@gmail.com> References: <1442512859-31633-1-git-send-email-ddaney.cavm@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150917_110128_527888_FC8B5370 X-CRM114-Status: GOOD ( 17.38 ) X-Spam-Score: -2.7 (--) 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: David Daney MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Daney Search up the device hierarchy to find devices with a "msi-map" property, if found apply the mapping to the GIC device id. Signed-off-by: David Daney --- drivers/irqchip/irq-gic-v3-its-pci-msi.c | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/irqchip/irq-gic-v3-its-pci-msi.c b/drivers/irqchip/irq-gic-v3-its-pci-msi.c index cf351c6..aa61cef 100644 --- a/drivers/irqchip/irq-gic-v3-its-pci-msi.c +++ b/drivers/irqchip/irq-gic-v3-its-pci-msi.c @@ -73,6 +73,8 @@ static int its_pci_msi_prepare(struct irq_domain *domain, struct device *dev, struct pci_dev *pdev; struct its_pci_alias dev_alias; struct msi_domain_info *msi_info; + struct device *parent_dev; + struct device_node *msi_controller_node = NULL; if (!dev_is_pci(dev)) return -EINVAL; @@ -84,6 +86,77 @@ static int its_pci_msi_prepare(struct irq_domain *domain, struct device *dev, dev_alias.count = nvec; pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias); + /* + * Walk up the device parent links looking for one with a + * "msi-map" property. + */ + for (parent_dev = dev; parent_dev; parent_dev = parent_dev->parent) { + u32 msi_mask, masked_devid; + u32 rid_base, msi_base, rid_len, phandle; + int msi_map_len; + const __be32 *msi_map; + bool matched; + + if (!parent_dev->of_node) + continue; + + msi_map = of_get_property(parent_dev->of_node, + "msi-map", &msi_map_len); + if (!msi_map) + continue; + + /* The default is to select all bits. */ + msi_mask = 0xffffffff; + + /* + * Can be overridden by "msi-mask" property. If + * of_property_read_u32() fails, the default is + * used. + */ + of_property_read_u32(parent_dev->of_node, + "msi-mask", &msi_mask); + + masked_devid = msi_mask & dev_alias.dev_id; + matched = false; + while (msi_map_len >= 4 * sizeof(__be32)) { + rid_base = be32_to_cpup(msi_map + 0); + phandle = be32_to_cpup(msi_map + 1); + msi_base = be32_to_cpup(msi_map + 2); + rid_len = be32_to_cpup(msi_map + 3); + + if (masked_devid < rid_base || + masked_devid >= rid_base + rid_len) { + msi_map_len -= 4 * sizeof(__be32); + msi_map += 4; + continue; + } + matched = true; + break; + } + if (!matched) { + dev_err(dev, + "No match in \"msi-map\" of %s for dev_id: %x\n", + dev_name(parent_dev), dev_alias.dev_id); + break; + } + + msi_controller_node = of_find_node_by_phandle(phandle); + if (domain->of_node != msi_controller_node) { + dev_err(dev, + "ERROR: msi-map mismatch \"%s\" vs. \"%s\"\n", + domain->of_node->full_name, + msi_controller_node ? NULL : msi_controller_node->full_name); + break; + } + dev_dbg(dev, + "msi-map at: %s, len: %d, using mask %08x, rid: %08x, msi: %08x, rid_len: %08x, dev_id: %08x\n", + dev_name(parent_dev), msi_map_len, msi_mask, rid_base, + msi_base, rid_len, dev_alias.dev_id); + dev_alias.dev_id = masked_devid + msi_base; + dev_dbg(dev, "New dev_id: %08x\n", dev_alias.dev_id); + break; + } + of_node_put(msi_controller_node); /* ITS specific DeviceID, as the core ITS ignores dev. */ info->scratchpad[0].ul = dev_alias.dev_id;