Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1774045rwi; Wed, 19 Oct 2022 15:24:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+RXAPYQpTM9jABsMN9nyISWqfKbUKSPECAaQQMyvcYinxuUQMGW33TF+7HVhZrfxlDZ1c X-Received: by 2002:a17:907:168c:b0:78d:8b6c:a209 with SMTP id hc12-20020a170907168c00b0078d8b6ca209mr9059377ejc.185.1666218277495; Wed, 19 Oct 2022 15:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666218277; cv=none; d=google.com; s=arc-20160816; b=aTyvhQGfV6T+HHZVIj4YHPiuFS7HyORrTpX/R8W2qXZUBrYqbgR3Fr8ft6oz1hguw1 MxXzOrgngI5UEKFTLl9ZAJxeWwrUZENAwH6bUyY2Ueg3GAZ1R7caQhSlU3VJrF860898 Hl4gbeQko8VCwomw2u7oCmvrk/J8IZeOgomVn14ay8EWlZ+2u8MvCOV2DQ3IwioV3vBQ jAF7quM+YFEoZo5hF65cipE1EHqyVbCZ9lo+ACJvuNkk3l68wTcfu+/WUgnXJ0ujj1Uq IDyV+upAMRlIS/R/o4LHCIHTZ5R/DQfh7MtYleTPQcVBTcn8DfO5cl60AdkbyUQbnTwu wVWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+tnzQJseoXg0993O/jYRru0Ddht5bYo8gE2zFXRgP2o=; b=pVjv4NRjh0dRxdzPWRgBpvBtq6fyUpJctzbpFOZ/s6zQNn1ldPAmKZ/9VRGjAgS0Wn NOebT+5HUqZh3WIN6nqV18uoH2DmB3tXGpXvKy5oHIhqFmSSOAhdJ8zOh66pPyQnd2pW iT6L4G2drmXJVjel867l9s7lHIY+ApoOgG28ZhHBW8vNuY72JR7aI4Lr+yxiwK8MBMIe EHCB/MIMgqUceLg6lz0yh+vC5fGVNwkJ+8ydHI+GPaJ/Kwj+5hH8uGSe2NNTZFbNlJjz 2lsYCC1/pzBMDja8aCcAQEg8wTjySQNsS3bGFZVBUK3nXl6QBuDnoFLmEKxOf8qqP17e sXAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ePupxn0z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd16-20020a1709069b9000b0078e54eda758si12332667ejc.611.2022.10.19.15.24.11; Wed, 19 Oct 2022 15:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ePupxn0z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230461AbiJSWC6 (ORCPT + 99 others); Wed, 19 Oct 2022 18:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbiJSWCz (ORCPT ); Wed, 19 Oct 2022 18:02:55 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C761BFBBA; Wed, 19 Oct 2022 15:02:54 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id f11so31305207wrm.6; Wed, 19 Oct 2022 15:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+tnzQJseoXg0993O/jYRru0Ddht5bYo8gE2zFXRgP2o=; b=ePupxn0zNCvRCwps62nYVtsb1ZuBj23fKYYGb68vZHgB3Rh99LYV4+IAj6cfZWtnmb Nhr8l3KQ1qj/nzsP/yU4yLNY8NK6KJztGk+XJ/Y0jAB9n1xDfWvC6rT4Ii4cUomKsdBg fl7NUQl/PiRLnCSmbmDp+URxNESLdS1c+WtKz6toPomXjGN21RUfJ79durQiClsZqVih 7EoENcTji7lEVPZHYQYGVvFGsRY46psYoTaq0kSkiv0oL88TM+vKVJ5IuYLOUUVLiHda EEH1Z3uaK8RM89b0qe/36Ddgk+f6RhhlJYlObN8sjrUqCw1Hmn2CwghMaVVhhJqAw3Vf lF2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+tnzQJseoXg0993O/jYRru0Ddht5bYo8gE2zFXRgP2o=; b=fdsvQdCUyfATyv5WtJSmIYFl4kQpuokScNYMLffUHnjGAUj7FW2X8GFQoZqx4RmmL0 ymgsXexPqhPsOA9kEbPbkqNlJNYm6OunzQtObORytiN8ztvB3lBmGmldywYe/ZHtNQjr j3yWnjgaXmhougSOPKUvsHqlzO2wGTbDk2WFitteCd8YxQxAXMwikDZ0PzicjAWTTGWj gkoXtOgFmGb9CNhu+abRqj5KzIiIBoPOQw62T6jNVaGcoKOlUy/Gm1iFZJS3XWNbztk/ qPJDQvN36gks3gqDxVXZ4D10LFE/lyR6C1IF3H0xQ4FSX2L8J0/X4bO8ro7Y00E3fydh Hwvw== X-Gm-Message-State: ACrzQf2Z8l6q7H3vOKZCgJJSkKQdm8IPMrQ09uLOpwHtwK9FkYrq9GAR V6TT6D43rLmXn8bewizhewY= X-Received: by 2002:a5d:4c44:0:b0:22e:3503:41bf with SMTP id n4-20020a5d4c44000000b0022e350341bfmr6690210wrt.0.1666216972763; Wed, 19 Oct 2022 15:02:52 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2501:c701:d8c7:b527:b960:aa04]) by smtp.gmail.com with ESMTPSA id m7-20020a5d6247000000b0022c906ffedasm14807824wrv.70.2022.10.19.15.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 15:02:52 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Geert Uytterhoeven , Magnus Damm , Rob Herring , Krzysztof Kozlowski , Heiko Stuebner , Conor Dooley , Guo Ren Cc: Nick Desaulniers , Nathan Chancellor , Atish Patra , Anup Patel , Andrew Jones , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [RFC PATCH v3 0/2] AX45MP: Add support to non-coherent DMA Date: Wed, 19 Oct 2022 23:02:40 +0100 Message-Id: <20221019220242.4746-1-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lad Prabhakar Hi All, On the Andes AX45MP core, cache coherency is a specification option so it may not be supported. In this case DMA will fail. To get around with this issue this patch series does the below: 1] Andes AX45MP core has a Programmable Physical Memory Attributes (PMA) block that allows dynamic adjustment of memory attributes in the runtime. It contains a configurable amount of PMA entries implemented as CSR registers to control the attributes of memory locations in interest. PMA regions are passed from the l2 node which are configured as non-cacheable + bufferable with the SBI call. l2cache: cache-controller@13400000 { .... andestech,pma-regions = <0x0 0x58000000 0x0 0x08000000 0x0 (AX45MP_PMACFG_ETYP_NAPOT | AX45MP_PMACFG_MTYP_MEM_NON_CACHE_BUF)>; .... }; 2] We provide callbacks to synchronize specific content between memory and cache. - arch_sync_dma_for_device() - arch_sync_dma_for_cpu() Below are the configs that are enabled: - DMA_GLOBAL_POOL - RISCV_DMA_NONCOHERENT 3] We reserve the shared DMA pool, so the DMA memory requests go through this pool: reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges; reserved: linux,cma@58000000 { compatible = "shared-dma-pool"; no-map; linux,dma-default; reg = <0x0 0x58000000 0x0 0x08000000>; }; }; Below is the L2 cache DT node: l2cache: cache-controller@13400000 { compatible = "andestech,ax45mp-cache", "cache"; cache-size = <0x40000>; cache-line-size = <64>; cache-sets = <1024>; cache-unified; reg = <0x0 0x13400000 0x0 0x100000>; andestech,pma-regions = <0x0 0x58000000 0x0 0x08000000 0x0 (AX45MP_PMACFG_ETYP_NAPOT | AX45MP_PMACFG_MTYP_MEM_NON_CACHE_BUF)>; andestech,inst-prefetch = <0x3>; andestech,data-prefetch = <0x3>; andestech,tag-ram-ctl = /bits/ 8 <0x1 0x0>; andestech,data-ram-ctl = /bits/ 8 <0x1 0x0>; interrupts = ; }; Due to the above approach custom SBI calls have been implemented. The above implementation is in preparation for adding support for Renesas RZ/Five SoC which uses the AX45MP core. As with the above approach the kernel image might not be generic so that it can be used on other platforms, so sending it as an RFC (without DT binding patches). OpenSBI implementation isn't upstreamed yet, public repo for access is available at [0]. [0] https://github.com/renesas-rz/rz_opensbi/tree/work/OpenSBI-PMA RFC v2-> RFC v3 * Fixed review comments pointed by Conor * Move DT binding into cache folder * Fixed DT binding check issue * Added andestech,ax45mp-cache.h header file * Now passing the flags for the PMA setup as part of andestech,pma-regions property. * Added andestech,inst/data-prefetch and andestech,tag/data-ram-ctl properties to configure the L2 cache. * Registered the cache driver as platform driver RFC v1-> RFC v2 * Moved out the code from arc/riscv to drivers/soc/renesas * Now handling the PMA setup as part of the L2 cache * Now making use of dma-noncoherent.c instead SoC specific implementation. * Dropped arch_dma_alloc() and arch_dma_free() * Switched to RISCV_DMA_NONCOHERENT * Included DT binding doc RFC v2: https://patchwork.kernel.org/project/linux-renesas-soc/cover/20221003223222.448551-1-prabhakar.mahadev-lad.rj@bp.renesas.com/ RFC v1: https://patchwork.kernel.org/project/linux-renesas-soc/cover/20220906102154.32526-1-prabhakar.mahadev-lad.rj@bp.renesas.com/ Sending this as an RFC as CONFIG_ERRATA_THEAD_CMO/CONFIG_AX45MP_L2_CACHE is used for determining the CMO to call it would better if we could do this runtime instead. Cheers, Prabhakar Lad Prabhakar (2): dt-bindings: cache: r9a07g043f-l2-cache: Add DT binding documentation for L2 cache controller soc: renesas: Add L2 cache management for RZ/Five SoC .../cache/andestech,ax45mp-cache.yaml | 125 +++++ arch/riscv/include/asm/cacheflush.h | 8 + arch/riscv/include/asm/errata_list.h | 2 + arch/riscv/mm/dma-noncoherent.c | 20 + drivers/soc/renesas/Kconfig | 5 + drivers/soc/renesas/Makefile | 4 + drivers/soc/renesas/rzf/Kconfig | 6 + drivers/soc/renesas/rzf/Makefile | 3 + drivers/soc/renesas/rzf/ax45mp_cache.c | 431 ++++++++++++++++++ drivers/soc/renesas/rzf/ax45mp_sbi.h | 29 ++ .../cache/andestech,ax45mp-cache.h | 38 ++ 11 files changed, 671 insertions(+) create mode 100644 Documentation/devicetree/bindings/cache/andestech,ax45mp-cache.yaml create mode 100644 drivers/soc/renesas/rzf/Kconfig create mode 100644 drivers/soc/renesas/rzf/Makefile create mode 100644 drivers/soc/renesas/rzf/ax45mp_cache.c create mode 100644 drivers/soc/renesas/rzf/ax45mp_sbi.h create mode 100644 include/dt-bindings/cache/andestech,ax45mp-cache.h -- 2.25.1