Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754412AbdCFPmZ (ORCPT ); Mon, 6 Mar 2017 10:42:25 -0500 Received: from mail-by2nam03on0040.outbound.protection.outlook.com ([104.47.42.40]:19422 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753090AbdCFPmQ (ORCPT ); Mon, 6 Mar 2017 10:42:16 -0500 Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=cavium.com; From: Robert Richter To: Marc Zyngier Cc: Thomas Gleixner , Jason Cooper , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Robert Richter Subject: [PATCH v2 8/8] irqchip, gicv3-its, cma: Use CMA for allocation of large device tables Date: Mon, 6 Mar 2017 13:57:39 +0100 Message-Id: <20170306125739.19445-9-rrichter@cavium.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170306125739.19445-1-rrichter@cavium.com> References: <20170306125739.19445-1-rrichter@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [92.224.60.20] X-ClientProxiedBy: VI1PR0501CA0018.eurprd05.prod.outlook.com (10.172.9.156) To SN1PR07MB2351.namprd07.prod.outlook.com (10.169.127.17) X-MS-Office365-Filtering-Correlation-Id: 4c60f7c0-a41e-46b9-bae9-08d464908652 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:SN1PR07MB2351; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2351;3:kXrc7KNP1DoYh1Joauf3IYnvapN56A1RmoDfQ33uT4Is+cn8BKxfZ6tVPcwX/Lsh/+ecRXNHcchZX/Ks68pBbdtRmD9ao02kN4kQ864c6L5R4tEjST7oF9y5YX39QeXbI//B5SlXic8BRSYgNmm4wOv6utVRtb/pF52RfMhaobEgOruKx4DblPZUHanJIKgPGCLv3X1x0WypmSAz4ZH+FCghluNWrEQIer/OuV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UB4kyknSWz26r04EcQuEo/K0B2j8I8XUGJcwRZZzEQh8JAKm8i+btecL9Sue/vbGdG2w5ft1DpJLTth1g8486pfxra20LwT6KMpGr8I8brhE5nk7cGSqra+tXV7y4TznzIAUzAPHAGgipOx7l3T0w761Cot1Udac6CzZViLqH8HB6YbnOOlQy244ZnqRmrwZvIMRwMWDM3W2VP7zB0CR1weMf6MJtGokb1EwjtTaO3fsgJ7ElKBWAUOefBf67FMNNFxOCG+TAi3/Nr+Esx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123558025)(20161123560025)(6072148);SRVR:SN1PR07MB2351;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB2351; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2351;4:hOK6ORUm5triLouJRNNyCHa5xlXVcA4IIgH7JZi8TXwzqtkaXu5dNW1t1R5xqGyW8eQT8/aYaVvj2kpEZ3SEoA6WUozB8fPeZup6r9mhmseE6iaA1625C753/sN+vF4DYPu8GXyj7F7Lk/mqlmehDNhcS5sw0+XucPw8jbfGdz2Tz9W9MXI/Pnl7z5vb9/ZUhvhvBTAj0nAow1UwxzB6z1q9Se/D04hM1hnHP5yoDU38zI9Fi1fdyFdJO8ECBG8Onv4+Z7Oh72fqBQW4WK5XNsMjigSj53/gNpnYde4snNUCTqEuXZqL7jvDf18sBV6wwrxQMHWMMjTcnkUacmJzTKXrz4Uz9V+WO293PVThHvEx2ETuTNj4maA0a1af2FLJU5xTrAmKUZMlgU/XzZ3W++xaYMQsqbMLJca2jjXcxPwuCgtsZVm+PI/66j+/joRLKUEe4WC2DgTzlEk1UgtECOa+oFely0RCBP1GAJl5cbvDLoln4lQqRGbSW14TAbgXglTdXmkJYKjSiwmFIGHJXYYcEguQb4PThjad+eO/IXAU2QJu4oxIMemAA2ypXKsx8FcCvCIbd29VvozZ9C3nVqX6+uHVHtY52igj4Adrz3Y= X-Forefront-PRVS: 0238AEEDB0 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(7916002)(39450400003)(6116002)(3846002)(2906002)(76176999)(7736002)(1076002)(47776003)(5003940100001)(6506006)(25786008)(6486002)(66066001)(92566002)(5660300001)(305945005)(4326008)(33646002)(50986999)(81166006)(6666003)(50226002)(6916009)(48376002)(42186005)(53936002)(54906002)(6512007)(50466002)(189998001)(36756003)(38730400002)(110136004)(8676002)(2950100002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB2351;H:rric.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2351;23:5xPNDGSGyFfs3Fnwd17hK+KcbcSwnci0854LH1jjCtK1NN7fJIgGZPCsSW14oIZJYFaZnFbkruDla2T+aFmkm+Q2UmF6ORezypQbgGxO5D7f2dcaDfS5baELM7HecxqRTpnTwWaAC2TbG4CaoZqSuVoCjnTe7ZWu+Yb5QhwrgQrIyXdiayNby1dCVH9trSB9MMk21gCyujTBdqiXUmcGXLeFJ71oHAdbmNEy4oPNbsqg28suhl8uWx6JG+Wf8hHqsHaTbzu5rzjUR9G4LCqQ4HQjsHG5+RfOY34EFp0InM6YrzcpJuw+tirnQNn+XyNxdpZLmabC94qR4HAlxhJzYvYO09wJFcqwr8CJyEhwBqbHF5a2do90EIjh3TAFkd6ansbFvqYoR0gyFVZKxdmVLGpetPh85vr3Bo3Re1i5ExAbP8qfVZStn3XUPS2Uuwo0Lb9c/kRmxs3IahCVQ27oISltI8eY/xlCe9M/4eoMkF8gKLtInIXB5XvSrisHLHV4aMxulM9Cd5jT/5lK/c/QMEZFy+ybz86NxFZZ13OAb1g9AP66IdWVurd6DUfwUUTTA6Awldv3yZgsQA1khyxYrhCG8wti6GPuRn51Xmd1tGFpgZHvlluVr9XL/m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DiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB2351;7:u8AJrgTh5AM0cY1kNb+LjQE+lnkuakFwHc1YsCL0k7lYf+hm5cE/9E+S8BCGulZ3rl8gGEVLrWgR8hng3WUWctJe3FQJr0P4heHAVC9VBjz+hc3JWjvG+JtjUrqQxX09yEhhijhdREVPSN+yJxvsMNmeriAiYJfAXZDYTvVo4FQvwX+tCsCCo2I+HoWp0jJEpimm4cZkwQzWYJycAAai5Ts5QoEGEnjU4+iGL1bm9XmrzvBXkSQEW9cYjvxyCUJHJLeK9LcKq3KwIoGzI8C0OmD1Tsmd0mOf23B1fAFEqaBCIIO2qx4dJ+uktTy30wkWMU1p08mkqAybBwBr4A42jg== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2017 12:58:44.4281 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2351 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4086 Lines: 136 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 | 69 +++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 6625b3a505f0..6d293a0165b0 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -864,6 +865,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: @@ -876,13 +878,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) | @@ -923,29 +938,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; } @@ -1003,12 +1017,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; @@ -1698,6 +1706,9 @@ static int __init its_init_one(struct its_node *its) return err; } + /* Setup dma_ops for dmam_alloc_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