From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752696AbdKIHMs (ORCPT ); Thu, 9 Nov 2017 02:12:48 -0500 Received: from mail-vk0-f67.google.com ([209.85.213.67]:46184 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752549AbdKIHMq (ORCPT ); Thu, 9 Nov 2017 02:12:46 -0500 X-Google-Smtp-Source: ABhQp+RFmwnxkuM4VVTuTju6UGY7uYC0xV739TRLQZZAnbEUws0gK5e/+EV4SIU3NJspVCWJdmAZRXqxLoBVasvhAas= MIME-Version: 1.0 In-Reply-To: References: <763e6a252de1ad8ccd28344fd0676ae2f92f796d.1510118606.git.green.hu@gmail.com> From: Greentime Hu Date: Thu, 9 Nov 2017 15:12:05 +0800 Message-ID: Subject: Re: [PATCH 13/31] nds32: DMA mapping API To: Arnd Bergmann Cc: Greentime , Linux Kernel Mailing List , linux-arch , Thomas Gleixner , Jason Cooper , Marc Zyngier , Rob Herring , Networking , Vincent Chen , deanbo422@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2017-11-08 17:09 GMT+08:00 Arnd Bergmann : > On Wed, Nov 8, 2017 at 6:55 AM, Greentime Hu wrote: > >> +static void consistent_sync(void *vaddr, size_t size, int direction) >> +{ >> + unsigned long start = (unsigned long)vaddr; >> + unsigned long end = start + size; >> + >> + switch (direction) { >> + case DMA_FROM_DEVICE: /* invalidate only */ >> + cpu_dma_inval_range(start, end); >> + break; >> + case DMA_TO_DEVICE: /* writeback only */ >> + cpu_dma_wb_range(start, end); >> + break; >> + case DMA_BIDIRECTIONAL: /* writeback and invalidate */ >> + cpu_dma_wbinval_range(start, end); >> + break; >> + default: >> + BUG(); >> + } >> +} > >> + >> +static void >> +nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, >> + size_t size, enum dma_data_direction dir) >> +{ >> + consistent_sync((void *)dma_to_virt(dev, handle), size, dir); >> +} >> + >> +static void >> +nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, >> + size_t size, enum dma_data_direction dir) >> +{ >> + consistent_sync((void *)dma_to_virt(dev, handle), size, dir); >> +} > > You do the same cache operations for _to_cpu and _to_device, which > usually works, > but is more expensive than you need. It's better to take the ownership into > account and only do what you need. > Thanks. Like this? static void nds32_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { consistent_sync((void *)dma_to_virt(dev, handle), size, DMA_FROM_DEVICE); } static void nds32_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { consistent_sync((void *)dma_to_virt(dev, handle), size, DMA_TO_DEVICE); }