Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp566824imu; Thu, 20 Dec 2018 01:29:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/X4lvVM2o/Ixcs5vfVBQDqGuMhVuPhT0PCjjTryFz07o0/SFNpjv4asBrc2dq/+jXho+TIY X-Received: by 2002:a65:6542:: with SMTP id a2mr22204747pgw.389.1545298197434; Thu, 20 Dec 2018 01:29:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545298197; cv=none; d=google.com; s=arc-20160816; b=leIygq7r8mg6WaZ/JQsMBEMH1fJxAaRUmSyiHMdszJafN5qrjVFQbprsZfxFgtkyd8 Td8hCPl9CFPKJQTbJ6BEWi2TERoMQa7oPNdleGmk35yKSCKlY4+lCAUCqupE/eX4ZG8a j7/ClBgmqc7Hn0CRajpQCz+AxBlAXG++MpHEmQx+1zjCxXfszA9+qgntqN8PQlKZm4Xm MVUxkfuuZ4VZjSV2Vw1sEmzvRu15GKaaE400llj9EKHuvjExCfr5FmNBmW9R/4rtbVUT IcORWgNE749tgAd/h0s8+ZTTzLlcvQJoqWbhlBsW3NfCKRwOM1h0vhJSY/KxURPT3L/N +jWg== 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=ipvOxxMPBmAdvjx9L0QChz37KdncaIFvPHckonsdhTY=; b=tetVHhcGaLRQQqsiZYziv3+AIotHFh+dNYr+hzJ/EiqVSg1YHd5Wk+foMDm77J1cSS sFed+1e7f8a6nHNpq2+qjJJ9ucJfpZ+TBHYeMJoS+nHo7unH9Qu2b6rqyy5wt+vmV8s2 JvF/jQ7oekq/9g2ecebD7F5VCbrsDBmTJmSY58fzzf7BzIeLxzwjO4YC1Jq6C0vCBAoG wHUGBE1KGYQhAp7ytYnfmkmXaXWpEFdS1ELhiwfEu2oBnEponbCmkYbpYAzW4teQR/fk qvEPje7+pbDDrHjHNymX/IBA7VXF/ULwNsp4CmUqI9p3LoS1p50oXRpGECLc84IAg2zw VJkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pF6fnJW3; 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 y20si17504938plp.415.2018.12.20.01.29.42; Thu, 20 Dec 2018 01:29:57 -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=pF6fnJW3; 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 S1732221AbeLTJ1C (ORCPT + 99 others); Thu, 20 Dec 2018 04:27:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:60572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731273AbeLTJ1B (ORCPT ); Thu, 20 Dec 2018 04:27: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 E2B4320656; Thu, 20 Dec 2018 09:26:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545298020; bh=YX8DqdQRIveJEcF/psgOC1gdWViQsvKbl8WFVCzCpB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pF6fnJW3a4yM5A1OlBvM+VjMNfwYTS7sw8+X9KKwDEM7AESqsuOsvg2xpe122RoHZ 8edpJLFm4YDLVtnK2hE0p2UmXul7hxR1S9SnlxmbdPgOfshqivj99n3YsyCvixI9l3 7DY3+ht4fdrSPNAVeIlsgDOL3ZGQzkmKiREJWFmQ= 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.14 42/72] ARC: io.h: Implement reads{x}()/writes{x}() Date: Thu, 20 Dec 2018 10:18:41 +0100 Message-Id: <20181220085924.006773709@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220085922.332225035@linuxfoundation.org> References: <20181220085922.332225035@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.14-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