Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp866309imu; Thu, 20 Dec 2018 06:36:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/XrulFqX65cqVSSa5J4EjwUQRbBZzAx0hgmdMu/YgGioTXco+LNE+Ucx2vUQnt7qfajmndl X-Received: by 2002:a63:34c3:: with SMTP id b186mr6535550pga.184.1545316586770; Thu, 20 Dec 2018 06:36:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545316586; cv=none; d=google.com; s=arc-20160816; b=ti4Bn/TTvIOiy4LrFbQXmUS8qBXahyaewJVDSt2et4O+Y+omlwQmZdJe3eyEbElJn+ 5D/LVoDUGRU+MIAIWoExeKdkPRe6/6uOG0uy9UKjkcwW2BHZCB5lL0gdjqfCwKb00Tra HV6DCHfhQOvR/7lKNyFnzCgINFJvuZ6it57JTS46HK5ioozFlp5LBvp6u4k6OHzQedW9 i7KYR3iKhKOPhxKGxkXdGaS5/PFvduA9ef+tQ5MDffjDbuA5AGpUs6QwICbmr3TBLZ8j mItIQArVb/q6hx8aPtCdhfkuxdJ20l11xe09vdC/oTxXFK2HdvLI4owbyQtyIVStLKIO pFHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6UCWf6ih9KF3ALXi2Q+IX5sWvFA6xU3IPtt8xhVmnhM=; b=eeGlG/tobMdw90fCQSrDkxRuAthI4KQCZsmkF/j9EVwUeVczApaq2xUFIbjPyUy2aE c3ZlI3nmC91lVeVnLMXu6eXz/Sj9WT8bKeHnVNig3VQWAhgCMRhMKIvAJZ9rMtqg7Nn/ q4XM2aSYB6/gxWbIzvyO3nksyj4M+D9mh+H1AfK1Ly+ivp6aJWXY3HMFesHsywc8S+5B vImcKi0+B7FiKwrH6CFQx6+76XgxrjVwcpty3p10B0jlvWidzGFm/WwREh1TTzVMpt+m u9OUm7GU8scYQK2P+GHPnXxTveGKiejPPKvhtmh/NeZ+DPJXT9GaV1ScFZPM11e6o3gW +dsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nnE0EIcA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q19si2002696pfh.138.2018.12.20.06.36.07; Thu, 20 Dec 2018 06:36:26 -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=@kernel.org header.s=default header.b=nnE0EIcA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387393AbeLTJlY (ORCPT + 99 others); Thu, 20 Dec 2018 04:41:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:59284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731737AbeLTJYB (ORCPT ); Thu, 20 Dec 2018 04:24:01 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A8EC62177B; Thu, 20 Dec 2018 09:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545297840; bh=aQEeZVcWaZoSnRdDZJ9pvup3QYAQgBon9uWnOz9b24Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nnE0EIcAN801gmAobhV5wqo5aEWfHJHzlmEcclOfMtPegNKEKNqEVA7f0h4TXjsFl lcHBXk7zD7dkk92E7ZVimdOoH2pG2qZbBuwSKmTGfmwdkrDW3ADaXc4nwFPoKUkAz4 DrGYAzWW2CRsF0gSFC5vn+vHYtJ5VTm9fBszGo0U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Brodkin , Joao Pinto , David Laight , Vitor Soares , Jose Abreu , Vineet Gupta , Sasha Levin Subject: [PATCH 4.9 36/61] ARC: io.h: Implement reads{x}()/writes{x}() Date: Thu, 20 Dec 2018 10:18:36 +0100 Message-Id: <20181220085845.204666405@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220085843.743900603@linuxfoundation.org> References: <20181220085843.743900603@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 10d443431dc2bb733cf7add99b453e3fb9047a2e ] Some ARC CPU's do not support unaligned loads/stores. Currently, generic implementation of reads{b/w/l}()/writes{b/w/l}() is being used with ARC. This can lead to misfunction of some drivers as generic functions do a plain dereference of a pointer that can be unaligned. Let's use {get/put}_unaligned() helpers instead of plain dereference of pointer in order to fix. The helpers allow to get and store data from an unaligned address whilst preserving the CPU internal alignment. According to [1], the use of these helpers are costly in terms of performance so we added an initial check for a buffer already aligned so that the usage of the helpers can be avoided, when possible. [1] Documentation/unaligned-memory-access.txt Cc: Alexey Brodkin Cc: Joao Pinto Cc: David Laight Tested-by: Vitor Soares Signed-off-by: Jose Abreu Signed-off-by: Vineet Gupta Signed-off-by: Sasha Levin --- arch/arc/include/asm/io.h | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h index c22b181e8206..2f39d9b3886e 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_ISA_ARCV2 #include @@ -94,6 +95,42 @@ static inline u32 __raw_readl(const volatile void __iomem *addr) return w; } +/* + * {read,write}s{b,w,l}() repeatedly access the same IO address in + * native endianness in 8-, 16-, 32-bit chunks {into,from} memory, + * @count times + */ +#define __raw_readsx(t,f) \ +static inline void __raw_reads##f(const volatile void __iomem *addr, \ + void *ptr, unsigned int count) \ +{ \ + bool is_aligned = ((unsigned long)ptr % ((t) / 8)) == 0; \ + u##t *buf = ptr; \ + \ + if (!count) \ + return; \ + \ + /* Some ARC CPU's don't support unaligned accesses */ \ + if (is_aligned) { \ + do { \ + u##t x = __raw_read##f(addr); \ + *buf++ = x; \ + } while (--count); \ + } else { \ + do { \ + u##t x = __raw_read##f(addr); \ + put_unaligned(x, buf++); \ + } while (--count); \ + } \ +} + +#define __raw_readsb __raw_readsb +__raw_readsx(8, b) +#define __raw_readsw __raw_readsw +__raw_readsx(16, w) +#define __raw_readsl __raw_readsl +__raw_readsx(32, l) + #define __raw_writeb __raw_writeb static inline void __raw_writeb(u8 b, volatile void __iomem *addr) { @@ -126,6 +163,35 @@ static inline void __raw_writel(u32 w, volatile void __iomem *addr) } +#define __raw_writesx(t,f) \ +static inline void __raw_writes##f(volatile void __iomem *addr, \ + const void *ptr, unsigned int count) \ +{ \ + bool is_aligned = ((unsigned long)ptr % ((t) / 8)) == 0; \ + const u##t *buf = ptr; \ + \ + if (!count) \ + return; \ + \ + /* Some ARC CPU's don't support unaligned accesses */ \ + if (is_aligned) { \ + do { \ + __raw_write##f(*buf++, addr); \ + } while (--count); \ + } else { \ + do { \ + __raw_write##f(get_unaligned(buf++), addr); \ + } while (--count); \ + } \ +} + +#define __raw_writesb __raw_writesb +__raw_writesx(8, b) +#define __raw_writesw __raw_writesw +__raw_writesx(16, w) +#define __raw_writesl __raw_writesl +__raw_writesx(32, l) + /* * MMIO can also get buffered/optimized in micro-arch, so barriers needed * Based on ARM model for the typical use case @@ -141,10 +207,16 @@ static inline void __raw_writel(u32 w, volatile void __iomem *addr) #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; }) +#define readsb(p,d,l) ({ __raw_readsb(p,d,l); __iormb(); }) +#define readsw(p,d,l) ({ __raw_readsw(p,d,l); __iormb(); }) +#define readsl(p,d,l) ({ __raw_readsl(p,d,l); __iormb(); }) #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); }) #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); }) #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); }) +#define writesb(p,d,l) ({ __iowmb(); __raw_writesb(p,d,l); }) +#define writesw(p,d,l) ({ __iowmb(); __raw_writesw(p,d,l); }) +#define writesl(p,d,l) ({ __iowmb(); __raw_writesl(p,d,l); }) /* * Relaxed API for drivers which can handle barrier ordering themselves -- 2.19.1