Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1265432pxb; Wed, 10 Feb 2021 04:29:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEk+QP+gj5WcW4YkjXnwHc0/DGh5EWlhJda5A1rOhK1QXwzHBsbqZb/oCGlr/d5lINk14A X-Received: by 2002:a17:906:7d97:: with SMTP id v23mr2622448ejo.222.1612960160362; Wed, 10 Feb 2021 04:29:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612960160; cv=none; d=google.com; s=arc-20160816; b=QubyRzph2OzWAsHvNJ0WynxnJ2uuoPPCdI6ViOzEFOYoc0YvjGJes/84uiGnP3KUE8 b8EerwTj1jPEvkW3PZ5/r51QstvGURQ/bv8ZO08Ee2rsV1PQTemGxL9TuJAkjqbOzwVr 1RpiJr3mZBSpUU/EtCK3zZMlyFFiLaI/U3ZF+RS+G6oJ307Wr1W+74AjauIRsXeBNacq gEG6pzCOvx3TUEpnREpft9vkQCI1Zox4yvYPGsurqI5flp8UX0LAsQcD9YNqJDckpqm8 hAjCKn57bm/aq/D7mgkVDujEpH1Pjwa5ObBSxxQrYIx04X7yvTHIi+UeEa5VecivHMef 5/SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=kHJIZb+40/MTRwj7eItyHS40RSdZ/3IUHJnFAMyNnn8=; b=fNt42KZ/9HpzWq18lA+nj/N+D/wxgMlGOYcfA78PgCaLd5A5Bhmr6JPjt3WLOkgjN5 e8wAdE7+R1Gb4sVNxGpqCuccUYFAYJRVPUyRhJoDOk484Qbt7BhR1OJW0RaOwxHq434s 7KX1+cUtAYb5i+2pRh7BnmwSmPLatX/u802bGfY5p+d1Dp+X3D8/FgVXhQZhsd8PV4Ue qbw8H4E0D7imroCm9leqmYn234sKdxIS5OMTo/2Jqkfzgm+Z2hGr3i0tUczuTRX3dMFh phxgr3aaE69EVmDxdsAEgHq9PF+GtoT9sl0UOE0Vvoj2/lOZcsSg5ZpKRb0y/p6Birvk hTDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b2si1216928edr.426.2021.02.10.04.28.56; Wed, 10 Feb 2021 04:29:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231886AbhBJM2D (ORCPT + 99 others); Wed, 10 Feb 2021 07:28:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbhBJMZD (ORCPT ); Wed, 10 Feb 2021 07:25:03 -0500 Received: from mail.marcansoft.com (marcansoft.com [IPv6:2a01:298:fe:f::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0688C06174A; Wed, 10 Feb 2021 04:24:22 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: marcan@marcan.st) by mail.marcansoft.com (Postfix) with ESMTPSA id 8CBC341FA3; Wed, 10 Feb 2021 12:24:18 +0000 (UTC) To: Will Deacon Cc: SoC Team , Linux ARM , Marc Zyngier , Rob Herring , "linux-kernel@vger.kernel.org" , DTML , Olof Johansson , Arnd Bergmann , Mark Kettenis References: <20210204203951.52105-1-marcan@marcan.st> <20210204203951.52105-14-marcan@marcan.st> From: Hector Martin Subject: Re: [PATCH 13/18] arm64: ioremap: use nGnRnE mappings on platforms that require it Message-ID: <475f7586-cabf-1169-8800-cdd2c012a5a6@marcan.st> Date: Wed, 10 Feb 2021 21:24:15 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Will, I'm pulling you in at Marc's suggestion. Do you have an opinion on what the better solution to this problem is? The executive summary is that Apple SoCs require nGnRnE memory mappings for MMIO, except for PCI space which uses nGnRE. ARM64 currently uses nGnRE everywhere. Solutions discussed in this thread and elsewhere include: 1. Something similar to the current hacky patch (which isn't really intended as a real solution...); change ioremap to default to nGnRnE using some kind of platform-level flag in the DT, then figure out how to get the PCI drivers to bypass that. This requires changing almost every PCI driver, since most of them use plain ioremap(). 2. A per-device DT property that tells of_address_to_resource to set a flag in the struct resource, which is then used by devm_ioremap_resource/of_iomap to pick a new ioremap_ variant for nGnRnE (introduce ioremap_np() for nonposted?) (PCI would work with this inasmuch as it would not support it, and thus fall back to the current nGnRE default, which is correct for PCI...). This requires changing DT-binding drivers that we depend on to not use plain ioremap() (if any do so), but that is a finite subset (unlike PCI which involves potentially every driver, because thunderbolt). 3. Encode the mapping type in the address of child devices, either abusing the high bits of the reg or introducing an extra DT cell there, introduce a new OF bus type that strips those away via a ranges mapping and sets flags in the struct resource, similar to what the PCI bus does with its 3-cell ranges, then do as (2) above and make devm_ioremap_resource/of_iomap use it: On 09/02/2021 07.57, Arnd Bergmann wrote: > #define MAP_NONPOSTED 0x80000000 > > arm-io { /* name for adt, should be changed */ > compatible = "apple,m1-internal-bus"; > #address-cells = <2>; /* or maybe <3> if we want */ > #size-cells = <2>; > ranges = > /* on-chip MMIO */ > <(MAP_NONPOSTED | 0x2) 0x0 0x2 0x0 0x1 0x0>, > > /* first PCI: 2GB control, 4GB memory space */ > <(MAP_NONPOSTED | 0x3) 0x80000000 0x3 0x80000000 0x0 0x80000000>, > <0x4 0x0 0x4 0x0 0x1 0x0>, [...] > The MAP_NONPOSTED flag then gets interpreted by the .translate() and > .get_flags() callbacks of "struct of_bus" in the kernel, where it is put into > a "struct resource" flag, and interpreted when the resource gets mapped. > > The PCI host controller nests inside of the node above, and (in theory) > uses the same trick to distinguish between prefetchable and non-prefetchable > memory, except in practice this is handled in device drivers that already > know whether to call ioremap() or ioremap_wc(). 4. Introduce a new top-level DT element in the style of reserved-memory, that describes address ranges and the mapping type to use. This could be implemented entirely in arch code, having arm64's ioremap look up the address in a structure populated from this. As an additional wrinkle, earlycon is almost certainly going to need a special path to handle this very early, before OF stuff is available; it also uses fixmap instead of ioremap, which has its own idea about what type of mapping to use. -- Hector Martin (marcan@marcan.st) Public Key: https://mrcn.st/pub