Received: by 10.223.164.202 with SMTP id h10csp1225404wrb; Fri, 10 Nov 2017 00:14:53 -0800 (PST) X-Google-Smtp-Source: ABhQp+Q9FZpwm5RcSLQ23OkGvTbUP2JpRQwAuIwkuR/HldEZzESomwYtapzKqjKwhyAC7cfLo+q9 X-Received: by 10.159.203.133 with SMTP id ay5mr3301578plb.361.1510301693609; Fri, 10 Nov 2017 00:14:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510301693; cv=none; d=google.com; s=arc-20160816; b=F38H/51IclIr8/5KNq4oclp58Hj/qc93I+PhogEXK7wcNfj/5cMDPrOdZFopltHhv5 2jPZfAh+CiI9SShbrVrzfMmT7LVN/dBAOgpRIYHfzVLurc9N5xaLRl2ercZmc7NlW7+U cBTlgmbkLUBvdN6U5YBiNyaS1VOwclI2WG+Fto68WFkxv5eEkI1XxOmCSqch5zq2FDRN z0yKJbdhOQ1V8Q/EdeRwfFhjjpLBWghJiZfwcDJE9T3jooPskELsq5Z7gOzeftaHr5ox ldTKtQ78JZ3pIMw+Zj4KPPnxEDfw7aFUf5YLAAQp6qZahBe400K1RvGoDXmCeMPMvWGX 5Aew== 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=DQ89KKMISvhhNmW2YDSHPmic87ZPMD5y/s1TP4XgHbc=; b=m66ql2+UwmsTNvh1QlmxkvbgBQ4Afr8cig/agwySxCvQG1HQAo8c34xJ5biYEt8guB xN3fHh3V9j8YQTN7cWiwkrRVljztEd3CDiCcxBQIZKq4wUdbceVSMgBU2DqPSsDzIctI i8vj6FBRT9Nx/r6i+5tC5Zrn6GfHCjjSST/AICmOoySmBb52Otq3gd9nTnNo6YuADe9T c3e4XgdruneJdAa1U8nZUauPiSTZL0o8EFXjInFksvc9locuUq1HGFs8OPlFoeTHOVba 6losyaOLZCeqs/7jNEKdI7IkJ5h14nys2+PTyemf0dLGKFkpUDfDhJLh8s1PBHl3UcHn NpqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oidkTvFH; 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 l91si8120690plb.647.2017.11.10.00.14.41; Fri, 10 Nov 2017 00:14:53 -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=oidkTvFH; 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 S1751231AbdKJIN6 (ORCPT + 83 others); Fri, 10 Nov 2017 03:13:58 -0500 Received: from mail-ua0-f195.google.com ([209.85.217.195]:53649 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750793AbdKJINy (ORCPT ); Fri, 10 Nov 2017 03:13:54 -0500 Received: by mail-ua0-f195.google.com with SMTP id e10so3539514uah.10; Fri, 10 Nov 2017 00:13:54 -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=DQ89KKMISvhhNmW2YDSHPmic87ZPMD5y/s1TP4XgHbc=; b=oidkTvFHqwFaN+M8SKVPSZzkr7OhZaSBdx/6RAcS974YF36oZfgKoepfP7EkLM5z6k 2RUrANRGeK53YiX+sSomm70UQxCjxz56EPk3IbQu6GD2Puyg3RSCzHAze/bxkayNALfb 4ISJPIHdYvzGqAV89lWgqT9MxfTP43idH9dHZh82HNDAg5IuQ9DaLTyJkxxcMl0ntlrC POirmIJIOtFMBCaTGkh+U667h+r2S7YYX4L14XmWfjPfq+ElXHy0EhdDh7DM7lVEE7kb OqEbm+Hu8TcRoUy4mKDZlTLHkWLTpap8hu9ebZ8zM4mcot8s7oUGnxjvEDkR9v7y36Ju 2bzg== 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=DQ89KKMISvhhNmW2YDSHPmic87ZPMD5y/s1TP4XgHbc=; b=eLJLV7dS9yEy9ghkEEPoF4OSureQcWjf4fNyJIsRtmnJYQykdKK3VJvL402ZA+ubdr 3blmV64LbITNvkp9LjfdK8tLGzyPvFSgoibWUURVPOwqhadXUMACFtnQxqqRGIPj4EK/ lhEwcYUuLZv6it5sfaObWmq5L3VHosJEZ2WL+rZYmOH//Mk+zss2prmtBM/NtNyj24TG gr9Y6yrG3zRqxzaTy9OW31Vvp20ptJLLw/xyuImW43l94GJfPcqWz2G5PbfHeTPcuNcV 6DkK4JLiF+DsMmVWgcx9NUeD3wbPg56PC3n6tvbaWyfJPvTtMSC4UO8V0ldmSv9mXMyH JDBA== X-Gm-Message-State: AJaThX7vC7x6a0cr75VFZYDitXiy2ZoM/0JBDCmnx08C32xNtAY/VgPw dUij1txbALKAcY+LUssVdOgZ7Mh0nCKIIXkLxqQ= X-Received: by 10.176.83.206 with SMTP id l14mr2902385uaa.167.1510301633917; Fri, 10 Nov 2017 00:13:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.62.8 with HTTP; Fri, 10 Nov 2017 00:13:13 -0800 (PST) In-Reply-To: References: <763e6a252de1ad8ccd28344fd0676ae2f92f796d.1510118606.git.green.hu@gmail.com> From: Greentime Hu Date: Fri, 10 Nov 2017 16:13:13 +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-09 18:14 GMT+08:00 Arnd Bergmann : > On Thu, Nov 9, 2017 at 8:12 AM, Greentime Hu wrote: >> 2017-11-08 17:09 GMT+08:00 Arnd Bergmann : >>> On Wed, Nov 8, 2017 at 6:55 AM, Greentime Hu wrote: >>> > >>> 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. >>> >> 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); >> } > > No, it's more complicated than that. You need to pass both the direction of the > DMA transaction and the ownership to consistent_sync(), and then do the > correct cache maintenance operation for each of the six combinations. > > Which operation that is depends on the microarchitecture to some degree, > e.g. on machines that can load arbitrary cache lines during speculative > execution, you have to invalidate the caches during both > _for_device/FROM_DEVICE _for_cpu/FROM_DEVICE, while machines > without speculative execution can skip the second invalidation, they > only need to get rid of dirty cache lines before the DMA from device. > > Usually you don't have to do a writeback during _for_cpu, since there > are no dirty cache lines after the _for_device operation. > > It's not entirely clear what the correct behavior is for buffers that > are not cache line aligned, some architectures use wbinval instead > of inval for the _for_device/_FROM_DEVICE operation, on > any partial cache line, but you wouldn't want to do that on the > _for_cpu/_FROM_DEVICE operation. I get your point. I prefer to keep it that way because it will be a little bit complex. I will still study the code to see what I can improve in the next version patch. From 1583583132030966546@xxx Thu Nov 09 10:16:00 +0000 2017 X-GM-THRID: 1583483498158067382 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread