From patchwork Mon Jan 22 05:04:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?J=2E_Neusch=C3=A4fer?= X-Patchwork-Id: 864145 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zPzry1bzMz9s7M for ; Mon, 22 Jan 2018 16:05:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751121AbeAVFEn (ORCPT ); Mon, 22 Jan 2018 00:04:43 -0500 Received: from mout.gmx.net ([212.227.17.20]:52264 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbeAVFEk (ORCPT ); Mon, 22 Jan 2018 00:04:40 -0500 Received: from localhost.localdomain ([88.153.6.51]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0Mhdex-1eQTph1xtT-00Mqbc; Mon, 22 Jan 2018 06:04:26 +0100 From: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= To: linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?q?Jonathan_Neusch=C3=A4fer?= , Albert Herranz , Tom Lendacky , Borislav Petkov , Brijesh Singh , Thomas Gleixner Subject: [PATCH v2 1/6] resource: Extend the PPC32 reserved memory hack Date: Mon, 22 Jan 2018 06:04:06 +0100 Message-Id: <20180122050411.32460-2-j.neuschaefer@gmx.net> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180122050411.32460-1-j.neuschaefer@gmx.net> References: <20180122050411.32460-1-j.neuschaefer@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K0:vTHIJJXWQJuMqm7WTzeOWf00hH8opX7HjobMki9Y4ZZjgST5I5l PYiiM+e9u6cOELN+4tRZlD5y2xhq50f3LeJuvS+kVDWu+Xh+3MiLrcMuRLfLHN2moB+nkFU uTDM76Pxnh7Wxh027tOO5jYkN2avH8gSyUMj08bnJK2FExGE1ZXVwoPrx18USpptCENq6xI BgZZKyVDJaYYGWGK28HqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:pUapvkcc5sA=:J8CbC+vU+/buwACMqPPEC/ 72Mg5rPtkaXEVWLjir7oVOpVU4oo4pnrX8kVMvzcIRyO06jWk4VrArAV7EV4aLvdxyz9ua2FI duCZPcWrjDmS7vKh0h0Z/1rqkLHrSIbcGvWvuOOVQKDKkqS1uOfLf/z/FgfmraffC611cxm3L OID2qOQ/kv4EBtztXHEqfo2/I23SOBM9WrR0Z9l81iLolaN05Psoam+BHAPKOCZ0nf02QpoEd lQQCxD3y52oRBF3xUXESa0Zx4SNwRIj1RLF0fyqHkcHBTsCiTRw/cgI6uROALMj0ebjOHwccT dDn8l4nhBI3u21sgTuwNYVeC220c/s0QRPMK/GP5zQQFT8FUFu9e56Qt7f/xSNUlSE0UpKqZY PBQYGrJkM8HWqGdQIST9BuPpsm9aRzA2qtcHk8SwmzhsTXHoFbrp2t3TuZvUnAiVSvsBc2ief bcnjgoJ92xKc6QXR/sx+pH+tUMW8fowECfmbocD4rbT3iJr4bHaVSCsPRyOQrbmjUO8QrO7SW uXXn78C87QrSKPujbfuuztdv4rCf33xz8K2Czdl4GQo4gLFCniSK+P72Om1PkQ9A7Zm+UJqGF j4CIA+EF9wwMdxq7a21s/cZh2zBwHIyDcXET0uqt0oSea8v+7b41/6P3vHvJhxcFuVG9MAnFj ss2h8dGIzd+28mc6E1qugGuTgJru5cknngc2piRGVJDKCDSJlPqoBzXA5Yvgv1pyKHk9xncfc E5c8HUnO2POO7YlmxIdGEtjPJutx+F01ODQof2dr+XpnI7hYyFa1SjAQChu2jZbToQiBU9rhX ievdiXzZWI4yGSPtZ7Vb3B9pbEYh5rgKECGFMVlGz0jlf/qSi0= Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org On the Nintendo Wii, there are two ranges of physical memory, and MMIO in between, but Linux on ppc32 doesn't support discontiguous memory. Therefore a hack was introduced in commit c5df7f775148 ("powerpc: allow ioremap within reserved memory regions") and commit de32400dd26e ("wii: use both mem1 and mem2 as ram"): - Treat the area from the start of the first memory area (MEM1) to the end of the second (MEM2) as one big memory area, but mark the part that doesn't belong to MEM1 or MEM2 as reserved. - Only on the Wii, allow ioremap to be used on reserved memory. This hack, however, doesn't account for the "resource"-based API in kernel/resource.c, because __request_region performs its own checks. Extend the hack to kernel/resource.c, to allow more drivers to allocate their MMIO regions on the Wii. Signed-off-by: Jonathan Neuschäfer Cc: Albert Herranz --- v2: - CC Albert Herranz, who introduced this hack in 2009. --- kernel/resource.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index 54ba6de3757c..bb3d329329da 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1134,6 +1134,24 @@ resource_size_t resource_alignment(struct resource *res) static DECLARE_WAIT_QUEUE_HEAD(muxed_resource_wait); +/* + * On some ppc32 platforms (Nintendo Wii), reserved memory is used to work + * around the fact that Linux doesn't support discontiguous memory (all memory + * is treated as one large area with holes punched in it), and reserved memory + * is allowed to be allocated. + */ +#ifdef CONFIG_PPC32 +static bool conflict_ignored(struct resource *conflict) +{ + extern int __allow_ioremap_reserved; + + return __allow_ioremap_reserved && + (conflict->flags & IORESOURCE_SYSRAM); +} +#else +static bool conflict_ignored(struct resource *conflict) { return false; } +#endif + /** * __request_region - create a new busy resource region * @parent: parent resource descriptor @@ -1166,8 +1184,9 @@ struct resource * __request_region(struct resource *parent, res->desc = parent->desc; conflict = __request_resource(parent, res); - if (!conflict) + if (!conflict || conflict_ignored(conflict)) break; + if (conflict != parent) { if (!(conflict->flags & IORESOURCE_BUSY)) { parent = conflict;