Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3415043yba; Mon, 29 Apr 2019 01:45:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuxi06GuD60HLdrmkIj7jRNXEObjRuHaKb1lAES1mNOTDdwR5X3uwMixTWl93ZMUcjWcyA X-Received: by 2002:a17:902:4501:: with SMTP id m1mr3937590pld.302.1556527550710; Mon, 29 Apr 2019 01:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556527550; cv=none; d=google.com; s=arc-20160816; b=OHnF3YOXXX+aDvuqR95n2evtPPGl+Ib/ybg5KutG93Mqbej5+C04n5kUHQGvq51In3 jvBd1ZtZRjuK3uK697QOGTGvPx/e0BYuKKNWIPsaweUaPEujkFaGBscrQUtO6VXlCYSR viZdR7s08J9772HW//oqwU/MiclbuO5Z0beHqs9myX4+t3HdrToKM6avMhElPtLrTCJi zbUbQFNSQ6X/Wc4tHdX6paLkBig8vHKaIDpkMpzVPdZW0T37faoKy3c27I0wdWsptCLG 4xSXER94DtQ3PVTfyRSNBATZ7zbeZtgVX3RsuVjbju8JMF520Xn8lWc8Mln0l03B42j9 PHOw== 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 :in-reply-to:references:mime-version; bh=78rUnBseUCRNDTyzCPYVzt3BL6FP4S0tsket8VgvgJY=; b=KO6DTNRcwwDwHBF1Uk0DL/VOhEInAE/qE84Wntldo4cXflI32vWkNBa4umk6m++ZJk wIz5M/q/J52YqI3TXGJWuQwbWdiqW8agLRMnsD4DpF68La+VrtijYzNlwWV0XIXn86a0 wkDdl5vpVkgJ3pgE6zilkudB8ooLEZc9T+7AquAN3QwAkOXDwYh0H+x94SoiI+7y+l0H AjsZYmf2EjKk64+50Q7ITvTebqrXSqigaDDZ9p0zPMFok6CXbknihSgIuXH0loWm1Dbx qMf8rwyC7fIYyn7/8t6942xdiviXaZBNtwQxg5xnlWZGbdIyw19+znAwnnoUqi7NdO7K ffrg== ARC-Authentication-Results: i=1; mx.google.com; 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 l10si23804366pgg.536.2019.04.29.01.45.34; Mon, 29 Apr 2019 01:45:50 -0700 (PDT) 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; 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 S1727695AbfD2Iog (ORCPT + 99 others); Mon, 29 Apr 2019 04:44:36 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:44071 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727480AbfD2Iof (ORCPT ); Mon, 29 Apr 2019 04:44:35 -0400 Received: by mail-vs1-f68.google.com with SMTP id j184so5399619vsd.11; Mon, 29 Apr 2019 01:44:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=78rUnBseUCRNDTyzCPYVzt3BL6FP4S0tsket8VgvgJY=; b=F/AvorzKayNnyXt/wT/i7v3gv4mYhQ20KpzAoG3eWOqE54xwXW/p+6rnLhm1DzxjAi DQMLA7MehHnrvrj4iJoyR2d6EGXtmZxlLas6bvsts+BLxXJhxWRUKv4tsLgCcKg0RDsx 0GQLwMoMv18WMspOM0Ryssi/bcHTHtccNR9dvvqciTYyaaxqkpzyQPPZ1qZWjvRnRE70 SHm/joQOtpfRYRBsDc3UjxVOuPsfzdU+VN+E35NxL1zJtJns2G18tp7XbSxTb+zWjXji X1X+/iAqrZWbrfkQE2KWReI9lT8r72L1cL7aCt1GHhnrNxdik5S2rL8CgtHrLbPT73zh IvNw== X-Gm-Message-State: APjAAAWuTPaJvUz2YMZgmFbMEZ5VN4au1Z7Ia1KwnUekeDkBzZvDDDNg 1Pzv0bVdM9lhEEzz8Ztb8Bes4Fcxs5Kf1ZEBsd8= X-Received: by 2002:a67:7d58:: with SMTP id y85mr1818528vsc.96.1556527474287; Mon, 29 Apr 2019 01:44:34 -0700 (PDT) MIME-Version: 1.0 References: <20190427153222.GA9613@jerusalem> <20190427202150.GB9613@jerusalem> In-Reply-To: From: Geert Uytterhoeven Date: Mon, 29 Apr 2019 10:44:22 +0200 Message-ID: Subject: Re: endianness swapped To: Greg Ungerer Cc: Arnd Bergmann , Angelo Dureghello , Logan Gunthorpe , Thomas Gleixner , Kate Stewart , Philippe Ombredanne , Greg KH , "Linux/m68k" , Linux-Arch , Linux Kernel Mailing List 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 Hi Greg, On Sun, Apr 28, 2019 at 3:59 PM Greg Ungerer wrote: > On 28/4/19 7:21 pm, Arnd Bergmann wrote: > > On Sun, Apr 28, 2019 at 10:46 AM Geert Uytterhoeven > > wrote: > >> On Sat, Apr 27, 2019 at 10:22 PM Angelo Dureghello wrote: > >>> On Sat, Apr 27, 2019 at 05:32:22PM +0200, Angelo Dureghello wrote: > >>>> as you may know, i am working on mcf5441x. > >>>> Sorry for not following carefully all the threads, but from a certain > >>>> kernel version (likely 4.19 or near there), seems ioread32be > >>>> reads the bytes swapped in endianness (mcf-edma dma driver not working > >>>> anymore). > >>>> > >>>> Has there been a change about this in the architecture I/O access ? > >>>> How should i proceed now ? Fixing the DMA driver read/write, or what ? > >> > >>> looks like the reason of my ioread32be now swapped is: > >>> > >>> https://patchwork.kernel.org/patch/10766673/ > >>> > >>> Trying to figure out what to do now. > >> > >> This is commit aecc787c06f4300f ("iomap: Use non-raw io functions for > >> io{read|write}XXbe"): > >> > >> --- a/lib/iomap.c > >> +++ b/lib/iomap.c > >> @@ -65,8 +65,8 @@ static void bad_io_access(unsigned long port, const > >> char *access) > >> #endif > >> > >> #ifndef mmio_read16be > >> -#define mmio_read16be(addr) be16_to_cpu(__raw_readw(addr)) > >> -#define mmio_read32be(addr) be32_to_cpu(__raw_readl(addr)) > >> +#define mmio_read16be(addr) swab16(readw(addr)) > >> +#define mmio_read32be(addr) swab32(readl(addr)) > >> #endif > >> > >> unsigned int ioread8(void __iomem *addr) > >> @@ -106,8 +106,8 @@ EXPORT_SYMBOL(ioread32be); > >> #endif > >> > >> #ifndef mmio_write16be > >> -#define mmio_write16be(val,port) __raw_writew(be16_to_cpu(val),port) > >> -#define mmio_write32be(val,port) __raw_writel(be32_to_cpu(val),port) > >> +#define mmio_write16be(val,port) writew(swab16(val),port) > >> +#define mmio_write32be(val,port) writel(swab32(val),port) > >> > >> On big endian, the raw accessors are assumed to be non-swapping, > >> while non-raw accessors are assumed to be swapping. > >> The latter is not true for Coldfire internal registers, cfr. > >> arch/m68k/include/asm/io_no.h: > >> static inline u16 readw(const volatile void __iomem *addr) > >> { > >> if (cf_internalio(addr)) > >> return __raw_readw(addr); > >> return __le16_to_cpu(__raw_readw(addr)); > >> } > >> > >> Orthogonal to how Coldfire's read[wl]() should be fixed, I find it a bit > >> questionable to swap data twice on big endian architectures. > > > > I would expect that the compiler is capable of detecting a double > > swap and optimize it out. Even if it can't, there are not that many > > instances of io{read,write}{16,32}be in the kernel, so the increase > > in kernel image size from a double swap should be limited to a > > few extra instructions, and the runtime overhead should be > > negligible compared to the bus access. Probably the overhead is not negligible on old m68k... > >> Fortunately we can avoid that by defining our own > >> mmio_{read,write}{16,32}be()... > > Makes sense. I've just sent a patch to do that, as a fix for v5.1 or v5.2. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds