Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506AbdHHMXs (ORCPT ); Tue, 8 Aug 2017 08:23:48 -0400 Received: from mail-by2nam01on0084.outbound.protection.outlook.com ([104.47.34.84]:36256 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752412AbdHHMXo (ORCPT ); Tue, 8 Aug 2017 08:23:44 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Robert.Richter@cavium.com; From: Robert Richter To: Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: Shanker Donthineni , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Robert Richter 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 Content-Type: text/plain 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+FYLHVmOigJhsyM7IofJSghPb2yx3oIrDfm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RAoZuQnWvAHAnQ/r0ANUf0ZyLt1kXS1+rMPUDmbdXaD8mGjM/ve/ZiQl/T9WKSA4R0VQV8GQZgM1zTs64FEIUoaYosUcrD4Ts6jLi/algufrtRVN433hjeVPzUPXX+pKP1MaodrLLs1AtKwrXa8TrFhZNL5AhNUd4UsoCzGPG/ZBOSx/HGoCYyXSnlvZ+i0oQCiIzBOjFCQm1yMeewhJRd/J+6jXnIJbV4qzsrz6iOTfGZmWVMi3aDQReBpwj9qV3oca;4:EliUYrYMPeiL+Q3ZYslmtD7EgfUpBCwE9ZBjvPp+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; 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?72YRKJfPDCTI95na7C1zxkwf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+mI3SRQWQIOsTO49Ut2aBjtI0PrYwJytvqTQS8A6Oj2umjily8LBbRhz6iP0rs7LnQ8w1uhJyXrfUvRgQ+KXCpBK3NAuRItZVXcQ5hSb/3zvo8L5vCSg4FMgCFg==;5:xOkhuN2kMnUpBeH/aqejIPPVtpeIzQwASsORP6ETiISnfjScnyGHlCHcnLWiKTr6r6ybQKTjy78nM4azNbJqDoJzdMEw0xnaktk6Ynbb+c3qassBivYkrOc9r7/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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4246 Lines: 141 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"); -- 2.11.0