Received: by 10.223.164.202 with SMTP id h10csp576465wrb; Wed, 8 Nov 2017 23:14:48 -0800 (PST) X-Google-Smtp-Source: ABhQp+QeIP07qT4gEOMezAYsl7mR9YjVgTNtqZkQKDGshf+39z6zTMWonIDT0sJgpDS8ytBDX/rj X-Received: by 10.99.4.11 with SMTP id 11mr923877pge.123.1510211688643; Wed, 08 Nov 2017 23:14:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510211688; cv=none; d=google.com; s=arc-20160816; b=FQCFtAtRAMcQdSTMJbzBnOn0+D2A0+O6ffA61aBBTbeuh29j20arjGEMRZa04h8aJE 2HMjToHG18Aa35Z8o8cEDD+LOtzHkfZ4r2wAfWYBNZ94ESorg/DkoVaUEO6VzQXcnLQ/ hyxZOmS2g1GRt49fFBPkzoyP+BeV/x7UitlZAx0qOODy6hEjiA9B6v1AfPcASabRtPIz dnwEGyA4LpQFrwQuWmWUQXc97QXKLzQQqzBcIhUG1S+WaTWojfie92+EBrHVQU70EyUb XF1byVubMUaK7xGqZoEPQzjCRSAKzL4AGwwrYPxHz+TJq4vuHMc+o/CO/jaRkYHE7ozc WPUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=9wuAZBcmLmPHvPucpFgVL08+Zh/aAR8JLFnqYusuUBI=; b=afWrIAUq5h2T77jd6LyZsF8OvoFIlBIY20WLIpqygVamQQ/JLTQ4BRsEnqu0yDKuYA p+9bRyJaO4Kw/7VW3iOXXc98WIxo/FOkP5fFpuT48v7fRW1QfSehW232aZdQ4ZUGd9sA ca4amqPNcXKZQ4UPln9wBIz7b00X4wC7XId8oLrB9gKvaMuaSJdjm4A0VFzgo81E0KXx LIkSfjbWQ5W1bC4ZKLuOiiMZsyqT+xSapSA7JzoRaSPdZdD2GGofKhkFo955waFuIMLv sQQTHd6wMxs5urflw5JoHwC4FeWjahYeNo4lo1E6x5fqVAhP2+f/3nhySTdz5u5qCAV+ 94qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mRVaXLkE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o28si5432786pgc.521.2017.11.08.23.14.37; Wed, 08 Nov 2017 23:14:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mRVaXLkE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752693AbdKIHMs (ORCPT + 82 others); 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 Received: by mail-vk0-f67.google.com with SMTP id k123so3358690vkb.3; Wed, 08 Nov 2017 23:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9wuAZBcmLmPHvPucpFgVL08+Zh/aAR8JLFnqYusuUBI=; b=mRVaXLkEb2+CMIQJn4H/j+3BExQiseOUTwl52IjLGWYBM3QB+gtHeU0yyiUOoW+tUd NGMozjW8NmZKYVYj5saGQILC9d3/crvdStP89PfFqYexZu5hzeOSvUzmsNjEeS4GpKzW wNp1rp/ebFMHVuYSx9Py+6cfUq/ttAYUOK5iPrqxSdQpPosFxmsENs4aLtKKl7rhwuyO mR0lxlct36WFONBvNLKvhSVMd0sVfPKy5e1+PiX0176giS7JT1XPm9wSzufxgb+SoP9k 4TU77nivw7I72soR+6swEc2Ec9xf0wO70HghdzfgQAIDlIhCQelwEzzl2FIDyDq8wwro oHDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9wuAZBcmLmPHvPucpFgVL08+Zh/aAR8JLFnqYusuUBI=; b=WWhaMThqYqwPUit4xvuafYqKtk/tD7sbhTXmRKfZmeeKrXvoQ+DlJAf+eWJnsjQ42U fRtFV5yaav1k2H2sO8VPUtH+Ex+vnw0uqhsztmTCVriDNK5cgIiVFVqv53uWOz58KG/H 4dhmdc4gT47H8zcLSwmtyW8ebwkCb+I5EOdBG289VPuZmpEHd2MSEnXMK6NgkTMzvSt0 X7L8vGzKib1C90yKDJHqSqEN/dygudQHXXmAe4V6gEuoxqOjeUUhHDzIm4eCgqHGhgoq Yv0kHsef/X3yBNe3dQWE0auBEsSACLQg4/r5Jio6DK3YyuUpcpc5xJ4U1yWMYU95aJgz mOuQ== X-Gm-Message-State: AJaThX5CBivYysEdOtVokG8RkNs50jDBLtOLa1bx8+8TLyaDyJR6+I71 Cj+Z0J21ft39jkoxAJtEw5zwU2w4sl0M1ygHN7Y= X-Received: by 10.31.170.142 with SMTP id t136mr2490472vke.198.1510211565589; Wed, 08 Nov 2017 23:12:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.62.8 with HTTP; Wed, 8 Nov 2017 23:12:05 -0800 (PST) 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 Precedence: bulk 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); } From 1583488447587600446@xxx Wed Nov 08 09:11:02 +0000 2017 X-GM-THRID: 1583483498158067382 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread