Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2972988imu; Thu, 29 Nov 2018 13:17:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/V127a7U+QVEJ3M0KYZIvuAoHamJirwV+UNmUGz9rHRrJToQId2iOviNZmy6im0Wbatrg8a X-Received: by 2002:aa7:8045:: with SMTP id y5mr2965154pfm.62.1543526249574; Thu, 29 Nov 2018 13:17:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543526249; cv=none; d=google.com; s=arc-20160816; b=LPHDtAAGuGeCFaLee4tPWPJOHArk/bMx9pRTWOYNmpHSK0CQMI+B68LQnpI1J1y7AR pVr4/nPjJYInBlQ8Dt2IUg40GkQHL+8v7GKVUjkITEBIr6Dem+tPqBiOCewslQIVPTqv lwxIfFfabEkTkW1U9QkBwWYWwXaYVlMIHWLvgeJECA2vkDorYkCU24Y4+Y/XbYVCRHUc zEWGC8vnqQarwM4sWqMSQAvEpAkDZTe0GH68w/kxBW2BLH8VtPAntPSdcZRXk93I0MVG HZ9HEeLiPzeQMH8zmeLtguCV9LJf5xZTlmeLfeQreZ4oNo1efOgmBHDWFTjSLxeJ00x9 tqsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:references:message-id:date :thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=gld24zbtjBC1EhWPZZCgpgaugbJ5JmJqzVSfZy5JM6M=; b=FvRXa2xUTw7D9T+5XShsnPmkVXtWMcsOxZYPgkXkYr6z4vEixF+xPCAFcTYcFluPVj T2/xFCjzuCzVs6a5esi61l4mlcwem/vtYtKu2BCgh/h4ow0yxOkcKw1lgjLY19wpYAg7 DOjHp+COja35ijgEUkrLKZFOc8/yHuUpbTT+0eF/0YOUYOvqjt1qYSUsI47eoIh1A+Tb wC9RYSUVPYUD8+66qXN75MeY8t2XoJ93ML9lMvmr4S/I574bUpWCQxLVHa1yJ8ri27ea 95VufOHmhPlan5ayWv9Oa0PCKikQHdtWi+gZTPwRH0m68CVdRHtbbp71PnaMYqHRy8HR nsFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=L1ecJF3C; 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=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si2974706pgi.387.2018.11.29.13.17.14; Thu, 29 Nov 2018 13:17:29 -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=@synopsys.com header.s=mail header.b=L1ecJF3C; 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=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726499AbeK3IXP (ORCPT + 99 others); Fri, 30 Nov 2018 03:23:15 -0500 Received: from us01smtprelay-2.synopsys.com ([198.182.60.111]:35924 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbeK3IXP (ORCPT ); Fri, 30 Nov 2018 03:23:15 -0500 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id CB19410C07B3; Thu, 29 Nov 2018 13:16:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1543526189; bh=jSWGDtnuZikYt/TErXicMXsZUhz6K+l15eXWL0s6+ho=; h=From:To:CC:Subject:Date:References:From; b=L1ecJF3CsbDIvopyVhbpG9n0pBM0Pwsjs94wDTyY5nQu2m0sOhGWIWEOWN/O7DThA /JH7EaN1G5E2K7HA0ddB2qbfpl8mRVC+gUimG9FWF9AYrqop8gdbb7L183nH7O//WU sTtf/6LfX3jJ0TkLdYrH20EJu7TLK7tZrvhGB/lbUyPmFtMsEXF9+dKSXaallDvcon c2i6XNAV/iCfLQQBDed6+nIXsNpuA5IZ3QryGlsqX8Kxr2R3TXcj3ab0ouvvO6YjJv n1s6iEJifrZzfwr7dFXGlBKbNELCi+p/mwx/tv9OcSHruZAzlyEwjeovJbLl7x4tDO xeH+KxiZ6DhKQ== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2-vip.internal.synopsys.com [10.12.239.238]) by mailhost.synopsys.com (Postfix) with ESMTP id 8352E3D85; Thu, 29 Nov 2018 13:16:29 -0800 (PST) Received: from US01WEMBX2.internal.synopsys.com ([fe80::e4b6:5520:9c0d:250b]) by US01WEHTC2.internal.synopsys.com ([10.12.239.237]) with mapi id 14.03.0415.000; Thu, 29 Nov 2018 13:16:29 -0800 From: Vineet Gupta To: Jose Abreu , "linux-snps-arc@lists.infradead.org" , "linux-kernel@vger.kernel.org" CC: Alexey Brodkin , Joao Pinto , Vitor Soares , David Laight Subject: Re: [PATCH v2] ARC: io.h: Implement reads{x}()/writes{x}() Thread-Topic: [PATCH v2] ARC: io.h: Implement reads{x}()/writes{x}() Thread-Index: AQHUh+/oo0RKKbidaU63fw0ncGEK7A== Date: Thu, 29 Nov 2018 21:16:29 +0000 Message-ID: References: <19fb2e394afcb073bbc109e432417fbbc03323f6.1543499759.git.joabreu@synopsys.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.144.199.104] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/29/18 6:29 AM, Jose Abreu wrote:=0A= > Some ARC CPU's do not support unaligned loads/stores. Currently, generic= =0A= > implementation of reads{b/w/l}()/writes{b/w/l}() is being used with ARC.= =0A= > This can lead to misfunction of some drivers as generic functions do a=0A= > plain dereference of a pointer that can be unaligned.=0A= >=0A= > Let's use {get/put}_unaligned() helper instead of plain dereference of=0A= > pointer in order to fix this. =0A= =0A= Please add a few lines of comment about what the accessor does in general -= maybe=0A= copy-paste from generic file if needed.=0A= =0A= > +#define __raw_readsx(t,f) \=0A= > +static inline void __raw_reads##f(const volatile void __iomem *addr, \= =0A= > + void *buffer, unsigned int count) \=0A= > +{ \=0A= > + if (count) { \=0A= =0A= Could you reduce 1 level of indentation by checking for !count and return.= =0A= =0A= > + const unsigned long bptr =3D (unsigned long)buffer; \=0A= > + u##t *buf =3D buffer; \=0A= > +\=0A= > + do { \=0A= > + u##t x =3D __raw_read##f(addr); \=0A= > +\=0A= > + /* Some ARC CPU's don't support unaligned accesses */ \=0A= > + if (bptr % ((t) / 8)) { \=0A= =0A= This math is loop invariant so instead of using bptr here, have something l= ike=0A= is_aligned =3D (unsigned long)buffer % ((t) / 8)) outside the loop. A reaso= nable=0A= compiler already does that but this one is easier on eyes.=0A= =0A= > + put_unaligned(x, buf++); \=0A= > + } else { \=0A= > + *buf++ =3D x; \=0A= > + } \=0A= > + } while (--count); \=0A= > + } \=0A= > +}=0A= =0A= Per your later post the compiler is doing the good job here, but sometimes = it=0A= might not. Adding a condition inside a loop is not a good idea in general. = Better=0A= to code the 2 loops seperately.=0A= =0A= > +=0A= > +#define __raw_readsb __raw_readsb=0A= > +__raw_readsx(8, b);=0A= =0A= The trailing ; is not needed=0A= =0A= > +#define __raw_readsw __raw_readsw=0A= > +__raw_readsx(16, w);=0A= > +#define __raw_readsl __raw_readsl=0A= > +__raw_readsx(32, l);=0A= =0A= > +=0A= > #define __raw_writeb __raw_writeb=0A= > static inline void __raw_writeb(u8 b, volatile void __iomem *addr)=0A= > {=0A= > @@ -126,6 +155,32 @@ static inline void __raw_writel(u32 w, volatile void= __iomem *addr)=0A= > =0A= > }=0A= > =0A= > +#define __raw_writesx(t,f) \=0A= > +static inline void __raw_writes##f(volatile void __iomem *addr, \=0A= > + const void *buffer, unsigned int count) \=0A= > +{ \=0A= > + if (count) { \=0A= > + const unsigned long bptr =3D (unsigned long)buffer; \=0A= > + const u##t *buf =3D buffer; \=0A= > +\=0A= > + do { \=0A= > + /* Some ARC CPU's don't support unaligned accesses */ \=0A= > + if (bptr % ((t) / 8)) { \=0A= > + __raw_write##f(get_unaligned(buf++), addr); \=0A= > + } else { \=0A= > + __raw_write##f(*buf++, addr); \=0A= > + } \=0A= > + } while (--count); \=0A= > + } \=0A= > +}=0A= =0A= Same as for read !=0A= =0A= > +=0A= > +#define __raw_writesb __raw_writesb=0A= > +__raw_writesx(8, b);=0A= > +#define __raw_writesw __raw_writesw=0A= > +__raw_writesx(16, w);=0A= > +#define __raw_writesl __raw_writesl=0A= > +__raw_writesx(32, l);=0A= =0A= Ditto !=0A= =0A=