Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1718832pxj; Wed, 19 May 2021 12:15:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySEDYeN5MdeOhuh/hq6qfU07WpHzxbyBcPdsKBKOJOMhYuQQs5HN2zlOYd2k2kMMxDhWH6 X-Received: by 2002:a17:906:edaf:: with SMTP id sa15mr718198ejb.174.1621451711637; Wed, 19 May 2021 12:15:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621451711; cv=none; d=google.com; s=arc-20160816; b=H0K0/k0TTATJQE8Csx8qsaAc3RYM/jfmg5jJz99CUnbuZBo0sor45tgvkHllar7UWm Op8sSVk2YnwCu+s9hm0178Upt72xrl/LzeuX9Ycog8yDfYMzHm44kiSc6bgNWQ8CQzgo 0Lv/lTkACtCW/Y3bNqq0waNDj0PBSy7hGZW9vmE6rt1HLZTbMj3zJhQS4py/AZOd3dU8 JZcQLTm6B3AILAmISPRqmDnNLesyL90AErsjdRwDwtlWGEzh1nAikuz0G1j1DwFgaEPk QoXe32PjPkhpnhLV4dB34MgOIZT0OCnqU+Mtyz5ZwmNFiZhviayMyjkycd7NIL9EAaFd olew== 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 :dkim-signature; bh=6XHzsiRXJ5wBHYKCT9/U4+eRxyTgk6Oc13fYA4HliIQ=; b=tHHkLWAHf+ARXllyvbpbWD7qcm6Y+WmByBFhu1Ppt5t7FnU10tVv/DIKxsn1xqoCz7 GdNRcySqn6YyCR5fu3RNvH7lPuWjgqmZiJdKpJkyG7B6NmSE7vCnNB+NPNb/UsT1MooR diB9LkeQPCpPS4OMyFAbUaGgTYrUptfxNnk0Z6OeD5lKtd6+kVuBFc6+M81cIqn2zrOP voyOQvhcgBcmiGc70ZRuNLX107G7EiJczQlkVQI5kyB7cMzaJL0iC5NQSzZSRUhPOC9e 7BNQyqDUYjECFpoCjoTcAv06EC0wqv4CbmwuDzeqZGsfKdTe1ayGLD866p3VmNhIbQUD husA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i7EKFQig; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id re15si503305ejb.120.2021.05.19.12.14.45; Wed, 19 May 2021 12:15:11 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i7EKFQig; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244696AbhESFGl (ORCPT + 99 others); Wed, 19 May 2021 01:06:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244371AbhESFGh (ORCPT ); Wed, 19 May 2021 01:06:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6B7A61355; Wed, 19 May 2021 05:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621400718; bh=FUR+kgZ+mw6mQw3yvdnnfad7YItNxZiYZYD2BKwK/SQ=; h=From:To:Cc:Subject:Date:From; b=i7EKFQigqGmUdb8wYjNQHOwKJkDxkY3IxJXsCMm/WnSs3Q3TgMcH4lt917hLkjtH+ 6L1kLdk9P5li0WQzsEsAzZ02qa9W3r9WGdsh8J4VSMU89257YxpBkzYM7qVSXLBvpp 2kIpk4Pu2cbOVb6sz2EvDUj3J0o5Am6Td9n2BMmSosbqFwVW+4O23BFXpk4wrS357Q Lw/TjRESwjTy9MkCBEprl0eIKkenIS8nBmy9FAlanquBC9dD7/Cr3ZMJBtxbmShTyJ c9o57+MKko2T8D9fNPZ6rS66E+U3rPpmQIHnTvj6xrY7ymyyyfl+E6p5DpjL2hGUGu fUKUd1DUMl/yQ== From: guoren@kernel.org To: guoren@kernel.org, anup.patel@wdc.com, palmerdabbelt@google.com, drew@beagleboard.org, hch@lst.de, wefu@redhat.com, lazyparser@gmail.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-sunxi@lists.linux.dev, Guo Ren Subject: [PATCH RFC 0/3] riscv: Add DMA_COHERENT support Date: Wed, 19 May 2021 05:04:13 +0000 Message-Id: <1621400656-25678-1-git-send-email-guoren@kernel.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guo Ren The RISC-V ISA doesn't yet specify how to query or modify PMAs, so let vendors define the custom properties of memory regions in PTE. This patchset helps SOC vendors to support their own custom interconnect coherent solution with PTE attributes. For example, allwinner D1[1] uses T-HEAD C906 as main processor, C906 has two modes in MMU: - Compatible mode, the same as the definitions in spec. - Enhanced mode, add custom DMA_COHERENT attribute bits in PTE which not mentioned in spec. Allwinner D1 needs the enhanced mode to support the DMA type device with non-coherent interconnect in its SOC. C906 uses BITS(63 - 59) as custom attribute bits in PTE. Here is the config example for Allwinner D1: CONFIG_RISCV_DMA_COHERENT=y CONFIG_RISCV_PAGE_DMA_MASK=0xf800000000000000 CONFIG_RISCV_PAGE_CACHE=0x7000000000000000 CONFIG_RISCV_PAGE_DMA_NONCACHE=0x8000000000000000 Link: https://linux-sunxi.org/D1 [1] Guo Ren (3): riscv: pgtable.h: Fixup _PAGE_CHG_MASK usage riscv: Add DMA_COHERENT for custom PTE attributes riscv: Add SYNC_DMA_FOR_CPU/DEVICE for DMA_COHERENT arch/riscv/Kconfig | 31 ++++++++++++++++++++++++++ arch/riscv/include/asm/pgtable-64.h | 8 ++++--- arch/riscv/include/asm/pgtable-bits.h | 13 ++++++++++- arch/riscv/include/asm/pgtable.h | 26 +++++++++++++++++----- arch/riscv/include/asm/sbi.h | 16 ++++++++++++++ arch/riscv/kernel/sbi.c | 19 ++++++++++++++++ arch/riscv/mm/Makefile | 4 ++++ arch/riscv/mm/dma-mapping.c | 41 +++++++++++++++++++++++++++++++++++ 8 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 arch/riscv/mm/dma-mapping.c -- 2.7.4