Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4170062rwb; Tue, 6 Sep 2022 03:46:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6hYtnztyYg4TuEGUc2/GarnFZiPBLQvv3c77F+vpULc81U9ANjDKP+tJQCq0ivaV7UPoIz X-Received: by 2002:a63:1c9:0:b0:42c:254a:d15f with SMTP id 192-20020a6301c9000000b0042c254ad15fmr34807164pgb.468.1662461200047; Tue, 06 Sep 2022 03:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662461200; cv=none; d=google.com; s=arc-20160816; b=TyjeV3NYVhi5hKJC8qp/nxUDBMO5VlBJsJAMnEVOBE3w4/ELRFzVRZhpH6IVQ0Dx52 z5oTSoknfDFMDtWNWCmOlNeUkSuTNEsqIMH9iDOTJFW1www20CTvtfdI2pGydNnHQRuz Zmd4SLSDotMbZALnZgkUOn8iFypUVdXj5VOC7I8x7qxcJ4ctxaHj3/JdCbuPHZO9Vpfv t7OrFhDypLKVOn6/s/Hq30vWTsENMZ2P43oxTQ+BAkP23syHT76Fo//WRx7tgp081uhK pP75bdApaBOuwcJ83UH6+VbhP0mHIfVoFXbsoHu87CfOnL+aVGcuPBBxaKeWsL1p4j4t eYyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=KqW99sXBBlTdL7FVyr/+yRLxRm/WQVVOI3SmdzwPIqA=; b=YPcRIauHWIVof/6Bipnmi9AVzuImW8wM+7I2f+tu8Hpt4Vwc0zBnbT9jkXJn4Bla0l 767BsPmcdukWwKPT5+xbDwezKUZqztNtBVLGuQMBEwzeTX5BUfkfXPLy5U0qVU44FiLU oZfdmBIShqjYiA+TvKnM8yNnTEHmUV57CO8uyERQhRAEnHwfHiJoj+ieGKrIbmJkr3gm j2ov8syNtE6DPaP1YxsaK2DbzAfqSp+UYg3j31AH5zcb6mbtyhL56sCdhxOEh1+NAlQc +Xkeealj6sL3q8Yrd1sreFjxG8Vvd1BTJMsagmU81sYiCwdk0p70gmMorVEvZJzhoEWt Vacw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a170902cf4300b001731230937bsi9048035plg.142.2022.09.06.03.46.27; Tue, 06 Sep 2022 03:46:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=renesas.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232425AbiIFKXg (ORCPT + 99 others); Tue, 6 Sep 2022 06:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239482AbiIFKWz (ORCPT ); Tue, 6 Sep 2022 06:22:55 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DEFE87A51D; Tue, 6 Sep 2022 03:22:11 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.93,293,1654527600"; d="scan'208";a="133888032" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 06 Sep 2022 19:22:09 +0900 Received: from localhost.localdomain (unknown [10.226.36.204]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id B847841BDC42; Tue, 6 Sep 2022 19:22:05 +0900 (JST) From: Lad Prabhakar To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Atish Patra , Anup Patel , Geert Uytterhoeven , Conor Dooley , linux-riscv@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [RFC PATCH 0/2] AX45MP: Add support to non-coherent DMA Date: Tue, 6 Sep 2022 11:21:52 +0100 Message-Id: <20220906102154.32526-1-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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: 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 cpu core node which are configured as non-cacheable and non-bufferable with the SBI call. ax45mp: cpu@0 { compatible = "andestech,ax45mp", "riscv"; device_type = "cpu"; .... pma-regions = <0x0 0x00000000 0x0 0x14000000>, <0x0 0x20000000 0x0 0x10000000>, <0x0 0x58000000 0x0 0x08000000>; .... }; We provide callbacks to synchronize specific content between memory and cache. We allocate a global DMA coherent pool (which is marked as non-cached using PMA) so that DMA memory allocations happens from this pool and we implement the below callbacks: - arch_sync_dma_for_device() - arch_sync_dma_for_cpu() - arch_dma_alloc() - arch_dma_free() Below are the configs that are enabled: - DMA_GLOBAL_POOL - ARCH_HAS_SYNC_DMA_FOR_CPU - ARCH_HAS_SYNC_DMA_FOR_DEVICE 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>; }; 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 Cheers, Prabhakar Lad Prabhakar (2): riscv: vendors: andes: Add support to configure the PMA regions riscv: vendors: andes: Add support for non-cohernet dma arch/riscv/Kbuild | 2 + arch/riscv/include/asm/sbi.h | 1 + arch/riscv/vendors/Makefile | 3 + arch/riscv/vendors/andes/Makefile | 4 + arch/riscv/vendors/andes/ax45mp.c | 93 ++++++ arch/riscv/vendors/andes/ax45mp_cache.c | 296 ++++++++++++++++++ arch/riscv/vendors/andes/ax45mp_nocache_dma.c | 65 ++++ arch/riscv/vendors/andes/include/proc.h | 9 + arch/riscv/vendors/andes/include/sbi.h | 27 ++ 9 files changed, 500 insertions(+) create mode 100644 arch/riscv/vendors/Makefile create mode 100644 arch/riscv/vendors/andes/Makefile create mode 100644 arch/riscv/vendors/andes/ax45mp.c create mode 100644 arch/riscv/vendors/andes/ax45mp_cache.c create mode 100644 arch/riscv/vendors/andes/ax45mp_nocache_dma.c create mode 100644 arch/riscv/vendors/andes/include/proc.h create mode 100644 arch/riscv/vendors/andes/include/sbi.h -- 2.25.1