From patchwork Sun Sep 14 06:30:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 37378 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6FC0E20CA0 for ; Sun, 14 Sep 2014 06:31:24 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id e53sf1467868eek.6 for ; Sat, 13 Sep 2014 23:31:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=3FeO4bxZlPEjMRZ9QJnzvvDogAvkntoMDrYQHf5MHF0=; b=d12m/vYDRvu4tUbaK3nFOzQ2zC7o5CIK7+BK6TTmAQYOMuW3ZhiyE3r81UAzS3DyOQ TxtT0h0aX/ekpbPZIW5RUtGeE8XxNOP/LEX0jQZtOOgeaWix7xKTRpAI4e8igKktM7Az yNXDA7nZHBULZnZJV1v3XB+myf445IlaKbP183lf2Vv0WeXa30SBZOJSwhb/lurR79we i2ui4+wsVOq2k/Uh8Pt0ymj5RSXLtZU/a9L+qettKLbh0/R0PKjp7jEIrc4AMvJGtxmD oH/xkltB48+mOKfJoVCeA7FVT04k5HlLqVOojJzTg/9q7jQQ4SWbE6ciEG6qYznGjIgp +3yQ== X-Gm-Message-State: ALoCoQmbLO6+ksec+7hSe+R7pW/YmwzPVlcpBLiZ3P4JmfGpCcyeJJsEQtyGYsG+zxUy9tv7kn9u X-Received: by 10.112.182.8 with SMTP id ea8mr198969lbc.11.1410676283245; Sat, 13 Sep 2014 23:31:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.193 with SMTP id c1ls278661lab.1.gmail; Sat, 13 Sep 2014 23:31:22 -0700 (PDT) X-Received: by 10.112.14.199 with SMTP id r7mr19106384lbc.58.1410676282597; Sat, 13 Sep 2014 23:31:22 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) by mx.google.com with ESMTPS id s10si13819400lal.38.2014.09.13.23.31.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 13 Sep 2014 23:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id ty20so3085051lab.35 for ; Sat, 13 Sep 2014 23:31:22 -0700 (PDT) X-Received: by 10.152.10.74 with SMTP id g10mr20217160lab.41.1410676282504; Sat, 13 Sep 2014 23:31:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp50779lbb; Sat, 13 Sep 2014 23:31:21 -0700 (PDT) X-Received: by 10.70.30.132 with SMTP id s4mr32116817pdh.96.1410676280894; Sat, 13 Sep 2014 23:31:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cq3si11152231pbb.193.2014.09.13.23.31.20 for ; Sat, 13 Sep 2014 23:31:20 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752550AbaINGbO (ORCPT + 27 others); Sun, 14 Sep 2014 02:31:14 -0400 Received: from mail-bl2on0130.outbound.protection.outlook.com ([65.55.169.130]:48309 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752494AbaINGbL (ORCPT ); Sun, 14 Sep 2014 02:31:11 -0400 Received: from BLUPR02MB472.namprd02.prod.outlook.com (10.141.82.23) by BLUPR02MB161.namprd02.prod.outlook.com (10.242.189.14) with Microsoft SMTP Server (TLS) id 15.0.1029.13; Sun, 14 Sep 2014 06:31:01 +0000 Received: from BY1PR0201CA0026.namprd02.prod.outlook.com (25.160.191.164) by BLUPR02MB472.namprd02.prod.outlook.com (10.141.82.23) with Microsoft SMTP Server (TLS) id 15.0.1029.13; Sun, 14 Sep 2014 06:30:59 +0000 Received: from BL2FFO11FD051.protection.gbl (2a01:111:f400:7c09::131) by BY1PR0201CA0026.outlook.office365.com (2a01:111:e400:4814::36) with Microsoft SMTP Server (TLS) id 15.0.1029.13 via Frontend Transport; Sun, 14 Sep 2014 06:30:58 +0000 Received: from atltwp02.amd.com (165.204.84.222) by BL2FFO11FD051.mail.protection.outlook.com (10.173.161.213) with Microsoft SMTP Server id 15.0.1019.14 via Frontend Transport; Sun, 14 Sep 2014 06:30:58 +0000 X-WSS-ID: 0NBVORG-08-F29-02 X-M-MSG: Received: from satlvexedge02.amd.com (satlvexedge02.amd.com [10.177.96.29]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by atltwp02.amd.com (Axway MailGate 5.3.1) with ESMTPS id 2BFD4D16007; Sun, 14 Sep 2014 01:30:51 -0500 (CDT) Received: from SATLEXDAG04.amd.com (10.181.40.9) by SATLVEXEDGE02.amd.com (10.177.96.29) with Microsoft SMTP Server (TLS) id 14.3.195.1; Sun, 14 Sep 2014 01:30:58 -0500 Received: from ssuthiku-fedora-lt.amd.com (10.180.168.240) by satlexdag04.amd.com (10.181.40.9) with Microsoft SMTP Server id 14.3.195.1; Sun, 14 Sep 2014 02:30:51 -0400 From: To: , , CC: , , , , , , , , , , Suravee Suthikulpanit , Mark Rutland , "Marc Zyngier" Subject: [PATCH 2/2 V6] irqchip: gicv2m: Add support for multiple MSI for ARM64 GICv2m Date: Sun, 14 Sep 2014 01:30:16 -0500 Message-ID: <1410676216-27953-3-git-send-email-suravee.suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1410676216-27953-1-git-send-email-suravee.suthikulpanit@amd.com> References: <1410676216-27953-1-git-send-email-suravee.suthikulpanit@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:165.204.84.222; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(428002)(199003)(189002)(47776003)(83322001)(104166001)(99396002)(46102001)(44976005)(20776003)(84676001)(19580405001)(31966008)(48376002)(79102001)(36756003)(19580395003)(53416004)(50986999)(62966002)(74662001)(68736004)(76176999)(87286001)(86362001)(92566001)(106466001)(4396001)(50466002)(81342001)(97736003)(76482001)(50226001)(77096002)(64706001)(102836001)(95666004)(105586002)(90102001)(77982001)(107046002)(74502001)(2201001)(85852003)(86152002)(80022001)(81542001)(101416001)(229853001)(33646002)(21056001)(92726001)(89996001)(87936001)(85306004)(77156001)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR02MB472; H:atltwp02.amd.com; FPR:; MLV:sfv; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:;UriScan:; X-Forefront-PRVS: 0334223192 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:; X-OriginatorOrg: amd4.onmicrosoft.com Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: suravee.suthikulpanit@amd.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Suravee Suthikulpanit This patch extend GICv2m MSI to support multiple MSI in ARM64. This requires the common arch_setup_msi_irqs() to be overwriten with ARM64 version which does not return 1 for PCI_CAP_ID_MSI and nvec > 1. Cc: Mark Rutland Cc: Marc Zyngier Cc: Jason Cooper Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Suravee Suthikulpanit --- arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/msi.c | 41 ++++++++++++++++++++ drivers/irqchip/irq-gic-v2m.c | 87 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 arch/arm64/kernel/msi.c diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index df7ef87..a921c42 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -29,6 +29,7 @@ arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o arm64-obj-$(CONFIG_KGDB) += kgdb.o arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o +arm64-obj-$(CONFIG_PCI_MSI) += msi.o obj-y += $(arm64-obj-y) vdso/ obj-m += $(arm64-obj-m) diff --git a/arch/arm64/kernel/msi.c b/arch/arm64/kernel/msi.c new file mode 100644 index 0000000..a295862 --- /dev/null +++ b/arch/arm64/kernel/msi.c @@ -0,0 +1,41 @@ +/* + * ARM64 architectural MSI implemention + * + * Support for Message Signalelled Interrupts for systems that + * implement ARM Generic Interrupt Controller: GICv2m. + * + * Copyright (C) 2014 Advanced Micro Devices, Inc. + * Authors: Suravee Suthikulpanit + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + */ + +#include +#include +#include + +/* + * ARM64 function for seting up MSI irqs. + * Based on driver/pci/msi.c: arch_setup_msi_irqs(). + * + * Note: + * Current implementation assumes that all interrupt controller used in + * ARM64 architecture _MUST_ supports multi-MSI. + */ +int arm64_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) +{ + struct msi_desc *entry; + int ret; + + list_for_each_entry(entry, &dev->msi_list, list) { + ret = arch_setup_msi_irq(dev, entry); + if (ret < 0) + return ret; + if (ret > 0) + return -ENOSPC; + } + + return 0; +} diff --git a/drivers/irqchip/irq-gic-v2m.c b/drivers/irqchip/irq-gic-v2m.c index 499bfb9..4ddb47d 100644 --- a/drivers/irqchip/irq-gic-v2m.c +++ b/drivers/irqchip/irq-gic-v2m.c @@ -99,13 +99,26 @@ static void gicv2m_teardown_msi_irq(struct msi_chip *chip, unsigned int irq) spin_unlock(&data->msi_cnt_lock); } +static int gicv2m_msi_get_vec_count(struct pci_dev *pdev, struct msi_desc *desc) +{ + int ret = -EINVAL; +#ifdef CONFIG_PCI_MSI + if (desc->msi_attrib.is_msix) + ret = pci_msix_vec_count(pdev); + else + ret = pci_msi_vec_count(pdev); +#endif + return ret; +} + static int gicv2m_setup_msi_irq(struct msi_chip *chip, struct pci_dev *pdev, struct msi_desc *desc) { - int irq, avail; + int i, irq, nvec, avail; struct msi_msg msg; phys_addr_t addr; + struct msi_desc *entry; struct v2m_data *data = container_of(chip, struct v2m_data, msi_chip); if (!desc) { @@ -114,16 +127,70 @@ static int gicv2m_setup_msi_irq(struct msi_chip *chip, return -EINVAL; } - avail = alloc_msi_irq(data, 1, &irq); - if (avail != 0) { - dev_err(&pdev->dev, - "GICv2m: MSI setup failed. Cannnot allocate IRQ\n"); - return -ENOSPC; - } + if (desc->msi_attrib.is_msix) { + /** + * For MSIx: + * We allocate one irq at a time + */ + avail = alloc_msi_irq(data, 1, &irq); + if (avail != 0) { + dev_err(&pdev->dev, + "GICv2m: MSI setup failed. Cannnot allocate IRQ\n"); + return -ENOSPC; + } - irq_set_chip_data(irq, chip); - irq_set_msi_desc(irq, desc); - irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING); + irq_set_chip_data(irq, chip); + irq_set_msi_desc(irq, desc); + irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING); + } else { + /** + * For MSI and Multi-MSI: + * All requested irqs are allocated and setup at + * once. Subsequent calls to this function would simply return + * success. This is to avoid having to implement a separate + * function for setting up multiple irqs. + */ + BUG_ON(list_empty(&pdev->msi_list)); + WARN_ON(!list_is_singular(&pdev->msi_list)); + + nvec = gicv2m_msi_get_vec_count(pdev, desc); + if (WARN_ON(nvec <= 0)) + return nvec; + + entry = list_first_entry(&pdev->msi_list, + struct msi_desc, list); + + if ((nvec > 1) && (entry->msi_attrib.multiple)) + return 0; + + avail = alloc_msi_irq(data, nvec, &irq); + if (avail != 0) { + dev_err(&pdev->dev, + "GICv2m: Failed to allocate %d irqs.\n", nvec); + return avail; + } + + if (nvec > 1) { + /* Set lowest of the new interrupts assigned + * to the PCI device + */ + entry->nvec_used = nvec; + entry->msi_attrib.multiple = ilog2( + __roundup_pow_of_two(nvec)); + } + + for (i = 0; i < nvec; i++) { + irq_set_chip_data(irq+i, chip); + if (irq_set_msi_desc_off(irq, i, entry)) { + dev_err(&pdev->dev, + "GICv2m: Failed to set up MSI irq %d\n", + (irq+i)); + return -EINVAL; + } + + irq_set_irq_type((irq+i), IRQ_TYPE_EDGE_RISING); + } + } addr = data->res.start + V2M_MSI_SETSPI_NS; msg.address_hi = (u32)(addr >> 32);