From patchwork Tue Aug 8 12:22:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 9888015 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 C639060384 for ; Tue, 8 Aug 2017 12:25:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B779728881 for ; Tue, 8 Aug 2017 12:25:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC3C328883; Tue, 8 Aug 2017 12:25:13 +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=-1.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE 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 19BD728884 for ; Tue, 8 Aug 2017 12:25:13 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=Ix9/01/lPQyyRe45NxJYuO5XbixHFIbDwHMWH5ph+Yg=; b=XIVVRGkKn6avMC snItllseu2P/DaBNs3rmf1j7I7y4jGObMTpdp9igB6ldp+j9r78ajVVdYmJ5TjEe+xmhU014ZBrj2 KCk+hhOmwNPHc6q4rdR/iQeXA25Xr7HFXQxAFcEmoO1CCgq9TO1NsGQNhhaxtFBgMkBq/ZKENSe8u zn6McjApEQ/SHOlQ8UfT2uZ8qCu2o+FjFqy9CUNM2m/5E+ZJaZj1Wq0nfJQdPKvkFktnMlUDAGOFM m3wGj24D37f9Uh3ZccjsaA6ALOk6eNOWMGcqaC4ahcv6sCZwGWYpbJtK7JqNn8Zn5yLapXIFF3a/c ScyVEUntU24ar9/XakIw==; 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 1df3ZO-0006Qd-S0; Tue, 08 Aug 2017 12:25:10 +0000 Received: from mail-by2nam03on0041.outbound.protection.outlook.com ([104.47.42.41] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1df3YR-0004A1-9y for linux-arm-kernel@lists.infradead.org; Tue, 08 Aug 2017 12:24:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Ru7EggEfpt//OZKXAlUepv6OOrZoWEN5Mqv3Js120rs=; b=EWttptqQYaumk9xn98ZEIWPVWUfqvmXBHjF3ttZHCGM550KNMoj0PnvwdxNrcWfgJI7nnnKCncz+R8CpdqKiP+xOgt/MoL5SSvdxfM4sku5v1M54MPW7Jfr98dFX2bVBFrN3CmVt1EdH/VA40vN2dTq6A0tVYUpomDJYDVQZYtQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robert.Richter@cavium.com; Received: from rric.localdomain (78.55.120.224) by CY1PR07MB2346.namprd07.prod.outlook.com (10.166.194.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1320.16; Tue, 8 Aug 2017 12:23:41 +0000 From: Robert Richter To: Thomas Gleixner , Jason Cooper , Marc Zyngier Subject: [PATCH v3 8/8] irqchip, gicv3-its, cma: Use CMA for allocation of large device tables Date: Tue, 8 Aug 2017 14:22:58 +0200 Message-Id: <20170808122259.6299-9-rrichter@cavium.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170808122259.6299-1-rrichter@cavium.com> References: <20170808122259.6299-1-rrichter@cavium.com> MIME-Version: 1.0 X-Originating-IP: [78.55.120.224] X-ClientProxiedBy: AM5PR06CA0030.eurprd06.prod.outlook.com (10.167.168.43) To CY1PR07MB2346.namprd07.prod.outlook.com (10.166.194.145) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e773aa95-0d89-4e1c-13c7-08d4de584f24 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:CY1PR07MB2346; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2346; 3:RMSekyOi6AKFh1hTRpV+k34Pn+c7OiD9KV/M69HTOy3lmnLqLj+F+X6dFe+FYLHVmOigJhsyM7IofJSghPb2yx3oIrDfmtaXykYXRCwX/h+lVAfA4xZD4xVKv3NT5Go6nc6pCXmxP2sqlFMjQbw3pAdOOiT/jZfxDqOdmkUXS1wS2n4TgnGjt4wn5LAzdpstuX85ZjpLOzBkT0p9I4xxgUm4r/f8MHtbTv7wH9ZpPB/KXp4PR0TuRsHwbu3PsU9r; 25:vJ5dDiPBG92FsR0ppJA9Todb50ymkOjrlywxLSN2bErAFIQ95EgbGxyu99AKGRaXVo3RCQvEqyd15G2zxk3D3i7RcasRqLOozfj0SfEzfH7tCLqm4h48uC+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3ZYslmtD7EgfUpBCwE9ZBjvPp+LwBHVdfEMUd1HY4V547CFFIBes/Fk0OTEWx5W0RrxUkt8FTF/szXc7XBK/Z+ex3wKUq2KWILhbB5nyJPOABVD7jnxp9nGKJ/c5g37K/chfs2t4UQsHxHqJN7Jz5ZQlH20bRRoZuSo7LSOUE5Myj9YFkN01k6hSWnuNoh77M41BvlZYSK9Pq0IkkuNzY7Srgs/9AQr08dWoBKI/I1099YaWzi X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(3002001)(6041248)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123560025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY1PR07MB2346; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY1PR07MB2346; X-Forefront-PRVS: 03932714EB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39840400002)(39410400002)(39850400002)(39400400002)(39450400003)(199003)(189002)(33646002)(66066001)(106356001)(68736007)(2950100002)(189998001)(54906002)(6116002)(3846002)(97736004)(72206003)(6666003)(81166006)(50226002)(6486002)(25786009)(5003940100001)(107886003)(38730400002)(4326008)(305945005)(50986999)(101416001)(5660300001)(42186005)(81156014)(2906002)(7736002)(6512007)(36756003)(76176999)(1076002)(105586002)(7350300001)(6506006)(48376002)(47776003)(478600001)(53936002)(50466002)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2346; H:rric.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2346; 23:AONo1gFmcI/hG5MXnuiWQ19A3StGsczpOcX/pyD5n?= =?us-ascii?Q?dLWZsROtM1a+r9RQsAeXEq4+14B6+QeFWyrwogx9QIn+mQTJGVVyK7xcK3ig?= =?us-ascii?Q?IUKiQqCztC6WhtNB+Alw4zWwbqlRl332VSHZGlUwCgxsUoZPXPPdHpsUlyVY?= =?us-ascii?Q?6ZpZH0u9e66aZX51onW4qB7z0uc/SyaBkwNcyvgifQ80E76eeBHH3e3EaXoY?= =?us-ascii?Q?Pl/N3H+10S6YznNqz164hs9rfa3qfIbKSR2h+B33Zf6mupX7aYn3wiuNypav?= =?us-ascii?Q?jDR1aeqd0vcC7U5t/cX0lk+pdBiDDBygl3xBOCzXg7qwlXzzZ5CIzPVLd41r?= =?us-ascii?Q?bNmLUSFIKkQCeE61SdOWYf7szqko3GHOOcJzQZmpgT4sdBJxdm2qI7cY8jHW?= =?us-ascii?Q?2FHWUPbE6otAzV/hbcc0ITrE+1XZdhikni6FEXVyBvSMTlYTwNeEUGWkYTay?= =?us-ascii?Q?V6USITltlieDzb/ve5Klm9AivCegxdIkObZh0LBLAgkNSOICKbBOBar+il80?= =?us-ascii?Q?cYv1J9GwtE4gj4BpCSkJoKPsd6HWpbwHGq07HZYV9umH2sbBBoc0SpZo7Cfc?= =?us-ascii?Q?72YRKJfPDCTI95na7C1zxkwfH7qj7FqKLdwkLFXoW25iZDpA0w4cpuDpNoR/?= =?us-ascii?Q?k7a5f8RGtbN20nKmUME1et+YTjXthkIfTh04Nl8KGFS0LyU030tWUKmdOcqH?= =?us-ascii?Q?XUkxsjbH1Ro2POcgIAFghnWHaSmNpHbEDmZQvjnjo+vTmU+3xZ6fhFwAYOJc?= =?us-ascii?Q?rup762I6kLL/2Fi/+zAcWELtRlg97HVOlvj8bcjXNbbwLoBCdDZ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Oc9r7/G8IUMMrjK/5XOeJ4kpdjGxhn78Q==; 24:iPeG5SrKUJRO7eIlNzjXoWyOajE+30aQIcmKVwnP27/efnZxTBj5ZmJg7sFSnsw/2nObZg2lainaFwcwQ4Zw4Q7nW2KSV60PlzKGDAQu7gk=; 7:GauXX/ygIvMbH7nrVtcignJlR4xSLz8qsQrFxwggZYOeph3ARlss84rqym7ddGS8323f55r8f8Xt2/pQYefsOIGYtQfavdqryGFSQaQ4reklW8JFWPprePeL0QeUX9W5qnzYcqsMCK3wVQL0ifRHfeSISjUMXMG9QW1c4QyVYf9gixyIIlQ+PC5s+MUX0163jG5zca4TrXfK9n+zGyY0MdaPQnyVHMDLqrmdl06tjjo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2017 12:23:41.6866 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2346 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170808_052411_552883_C5930AA1 X-CRM114-Status: GOOD ( 15.70 ) 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: Robert Richter , linux-arm-kernel@lists.infradead.org, Shanker Donthineni , linux-kernel@vger.kernel.org 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 The gicv3-its device table may have a size of up to 16MB. With 4k pagesize the maximum size of memory allocation is 4MB. Use CMA for allocation of large tables. We use the device managed version of dma_alloc_coherent(). Thus, we don't need to release it manually on device removal. Signed-off-by: Robert Richter --- drivers/irqchip/irq-gic-v3-its.c | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index b7d853dd6b75..8da9b423f9e1 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -866,6 +867,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, u64 type = GITS_BASER_TYPE(val); u32 alloc_pages; void *base; + dma_addr_t dma_handle; u64 tmp; retry_alloc_baser: @@ -878,13 +880,26 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, order = get_order(GITS_BASER_PAGES_MAX * psz); } - base = (void *)devm_get_free_pages(&its->dev, GFP_KERNEL | __GFP_ZERO, - order); - if (!base) + base = dmam_alloc_coherent(&its->dev, + PAGE_ORDER_TO_SIZE(order), + &dma_handle, + GFP_KERNEL | __GFP_ZERO); + + if (!base && order >= MAX_ORDER) { + order = MAX_ORDER - 1; + dev_warn(&its->dev, "Device Table too large, reduce ids %u->%u, no CMA memory available\n", + its->device_ids, + ilog2(PAGE_ORDER_TO_SIZE(order) / (int)esz)); + goto retry_alloc_baser; + } + + if (!base) { + dev_err(&its->dev, "Failed to allocate device table\n"); return -ENOMEM; + } retry_baser: - val = (virt_to_phys(base) | + val = (dma_handle | (type << GITS_BASER_TYPE_SHIFT) | ((esz - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | ((alloc_pages - 1) << GITS_BASER_PAGES_SHIFT) | @@ -925,29 +940,28 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, goto retry_baser; } - if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) { - /* - * Page size didn't stick. Let's try a smaller - * size and retry. If we reach 4K, then - * something is horribly wrong... - */ - devm_free_pages(&its->dev, (unsigned long)base); - baser->base = NULL; - - switch (psz) { - case SZ_16K: - psz = SZ_4K; - goto retry_alloc_baser; - case SZ_64K: - psz = SZ_16K; - goto retry_alloc_baser; + if (val != tmp) { + dmam_free_coherent(&its->dev, PAGE_ORDER_TO_SIZE(order), + base, dma_handle); + + if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) { + /* + * Page size didn't stick. Let's try a smaller + * size and retry. If we reach 4K, then + * something is horribly wrong... + */ + switch (psz) { + case SZ_16K: + psz = SZ_4K; + goto retry_alloc_baser; + case SZ_64K: + psz = SZ_16K; + goto retry_alloc_baser; + } } - } - if (val != tmp) { dev_err(&its->dev, "%s doesn't stick: %llx %llx\n", its_base_type_string[type], val, tmp); - devm_free_pages(&its->dev, (unsigned long)base); return -ENXIO; } @@ -1005,12 +1019,6 @@ static bool its_parse_baser_device(struct its_node *its, struct its_baser *baser * feature is not supported by hardware. */ new_order = max_t(u32, get_order(esz << ids), new_order); - if (new_order >= MAX_ORDER) { - new_order = MAX_ORDER - 1; - ids = ilog2(PAGE_ORDER_TO_SIZE(new_order) / (int)esz); - dev_warn(&its->dev, "Device Table too large, reduce ids %u->%u\n", - its->device_ids, ids); - } *order = new_order; @@ -1716,6 +1724,14 @@ static int __init its_init_one(struct its_node *its) return err; } + /* + * Setup dma_ops to be used with dmam_alloc_coherent() for its + * device table allocation. Since the device table is + * exclusively used by the device only we can mark this mem as + * coherent. + */ + arch_setup_dma_ops(&its->dev, 0, 0, NULL, true); + its_base = devm_ioremap(&its->dev, its->phys_base, its->phys_size); if (!its_base) { dev_warn(&its->dev, "Unable to map ITS registers\n");