linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Huacai Chen <chenhuacai@gmail.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Huacai Chen <chenhuacai@loongson.cn>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Airlie <airlied@linux.ie>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-arch <linux-arch@vger.kernel.org>,
	Xuefeng Li <lixuefeng@loongson.cn>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH 12/19] LoongArch: Add misc common routines
Date: Fri, 23 Jul 2021 18:41:00 +0800	[thread overview]
Message-ID: <CAAhV-H6PDr=YZdc=2NJ6hceE7HoKB-WcUHi3GEgtfO8nbxOV3g@mail.gmail.com> (raw)
In-Reply-To: <CAK8P3a0+jk=09mGdnWu9c+JWkwDKM+ffv=QvJs2uMY7WOg85AQ@mail.gmail.com>

Hi, Arnd,

On Tue, Jul 6, 2021 at 6:22 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Tue, Jul 6, 2021 at 6:18 AM Huacai Chen <chenhuacai@loongson.cn> wrote:
>
> > +
> > +#ifdef ARCH_HAS_USABLE_BUILTIN_POPCOUNT
> > +
> > +#include <asm/types.h>
> > +
> > +static inline unsigned int __arch_hweight32(unsigned int w)
> > +{
> > +       return __builtin_popcount(w);
> > +}
>
> This looks like you incorrect copied it from MIPS: For a new architecture,
> you should know whether __builtin_popcount is usable or not.
Sorry, this is my fault.

>
> > +static inline unsigned long __xchg(volatile void *ptr, unsigned long x,
> > +                                  int size)
> > +{
> > +       switch (size) {
> > +       case 1:
> > +       case 2:
> > +               return __xchg_small(ptr, x, size);
>
> If there is no native sub-word xchg(), then better make this BUILD_BUG(),
> see the riscv implementation.
>
> > +
> > +static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
> > +                                     unsigned long new, unsigned int size)
> > +{
> > +       switch (size) {
> > +       case 1:
> > +       case 2:
> > +               return __cmpxchg_small(ptr, old, new, size);
>
> Same here.
16bit cmpxchg is used by qspinlock. Yes, you suggest we should not use
qspinlock, but our test results show that ticket spinlock is even
worse... So, we want to keep cmpxchg_small() and qspinlock.

>
> > +++ b/arch/loongarch/include/asm/fb.h
> > @@ -0,0 +1,23 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Copyright (C) 2020-2021 Loongson Technology Corporation Limited
> > + */
> > +#ifndef _ASM_FB_H_
> > +#define _ASM_FB_H_
> > +
> > +#include <linux/fb.h>
> > +#include <linux/fs.h>
> > +#include <asm/page.h>
> > +
> > +static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma,
> > +                               unsigned long off)
> > +{
> > +       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
> > +}
>
> Do you have a writethrough or write-combine map type? noncached makes
> this slower than necessary.
OK, thanks, this writecombine will be used.

> > +/*
> > + * On LoongArch I/O ports are memory mapped, so we access them using normal
> > + * load/store instructions. loongarch_io_port_base is the virtual address to
> > + * which all ports are being mapped.  For sake of efficiency some code
> > + * assumes that this is an address that can be loaded with a single lui
> > + * instruction, so the lower 16 bits must be zero. Should be true on any
> > + * sane architecture; generic code does not use this assumption.
> > + */
> > +extern unsigned long loongarch_io_port_base;
> > +
> > +static inline void set_io_port_base(unsigned long base)
> > +{
> > +       loongarch_io_port_base = base;
> > +}
>
> If you are able to map this to a fixed virtual address (in fixmap or elsewhere),
> you can just use the asm-generic version.
OK, we will try the asm-generic version.

>
> > +/*
> > + * ISA I/O bus memory addresses are 1:1 with the physical address.
> > + */
> > +static inline unsigned long isa_virt_to_bus(volatile void *address)
> > +{
> > +       return virt_to_phys(address);
> > +}
> > +
> > +static inline void *isa_bus_to_virt(unsigned long address)
> > +{
> > +       return phys_to_virt(address);
> > +}
> > +/*
> > + * However PCI ones are not necessarily 1:1 and therefore these interfaces
> > + * are forbidden in portable PCI drivers.
> > + *
> > + * Allow them for x86 for legacy drivers, though.
> > + */
> > +#define virt_to_bus virt_to_phys
> > +#define bus_to_virt phys_to_virt
>
> As mentioned in another patch, these should not exist on new architectures.
OK, they will be removed.

>
> > +
> > +static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
> > +       unsigned long prot_val)
> > +{
> > +       /* This only works for !HIGHMEM currently */
>
> Do you support highmem? I would expect new architectures to no longer
> implement that. Just use a 64-bit kernel on systems with lots of ram.
Emmm, 64-bit kernel doesn't need highmem.

>
> > +#define ioremap(offset, size)                                  \
> > +       ioremap_prot((offset), (size), _CACHE_SUC)
> > +#define ioremap_uc ioremap
>
> Remove ioremap_uc(), it should never be called here.
It is used by lib/devres.c.

>
> > +/*
> > + * ioremap_wc     -   map bus memory into CPU space
> > + * @offset:    bus address of the memory
> > + * @size:      size of the resource to map
> > + *
> > + * ioremap_wc performs a platform specific sequence of operations to
> > + * make bus memory CPU accessible via the readb/readw/readl/writeb/
> > + * writew/writel functions and the other mmio helpers. The returned
> > + * address is not guaranteed to be usable directly as a virtual
> > + * address.
> > + *
> > + * This version of ioremap ensures that the memory is marked uncachable
> > + * but accelerated by means of write-combining feature. It is specifically
> > + * useful for PCIe prefetchable windows, which may vastly improve a
> > + * communications performance. If it was determined on boot stage, what
> > + * CPU CCA doesn't support WUC, the method shall fall-back to the
> > + * _CACHE_SUC option (see cpu_probe() method).
> > + */
> > +#define ioremap_wc(offset, size)                               \
> > +       ioremap_prot((offset), (size), boot_cpu_data.writecombine)
>
> It seems this is all copied from MIPS again. Are you sure you need to support
> both versions with a runtime conditional?
Emmm, this will be removed.

>
> > +#define __BUILD_MEMORY_SINGLE(pfx, bwlq, type)                         \
> > +                                                                       \
> > +static inline void pfx##write##bwlq(type val,                          \
> > +                                   volatile void __iomem *mem)         \
> > +{                                                                      \
>
> Please don't add another copy of these macros. Use the version from
> include/asm-generic, or modify it as needed if it doesn't quite work.
On Loongson platform, we should put a wmb() before MMIO write. The
generic readw()/readl()/outw()/outl() have wmb(), but the __raw
versions don't have. I want to know what is the design goal of the
__raw version, are they supposed to be used in scenarios that the
ordering needn't be cared?

>
> > diff --git a/arch/loongarch/include/asm/vga.h b/arch/loongarch/include/asm/vga.h
> > new file mode 100644
> > index 000000000000..eef95f2f837a
> > --- /dev/null
> > +++ b/arch/loongarch/include/asm/vga.h
> > @@ -0,0 +1,56 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * Access to VGA videoram
> > + *
> > + * Copyright (C) 2020-2021 Loongson Technology Corporation Limited
> > + */
>
> I think it would be better not to support VGA console, but to use the EFI
> framebuffer.
OK, this will be removed.

>
>
> > diff --git a/arch/loongarch/kernel/cmpxchg.c b/arch/loongarch/kernel/cmpxchg.c
> > new file mode 100644
> > index 000000000000..30f9f1ee4f0a
> > --- /dev/null
> > +++ b/arch/loongarch/kernel/cmpxchg.c
> > @@ -0,0 +1,100 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Author: Huacai Chen <chenhuacai@loongson.cn>
> > + * Copyright (C) 2020-2021 Loongson Technology Corporation Limited
> > + */
> > +
> > +#include <linux/bitops.h>
> > +#include <asm/cmpxchg.h>
> > +
> > +unsigned long __xchg_small(volatile void *ptr, unsigned long val, unsigned int size)
> > +{
>
> This file should not be there, I think you just copied it from the MIPS version.
>
> Which brings me to an important point: anything you copied from elsewhere
> is clearly not copyrighted by Loongson. I think you need to go through each
> file and update the copyright and author statements to reflect who actually
> wrote the code. At least you won't have to update this file if you remove it ;-)
>
>
>        Arnd

  parent reply	other threads:[~2021-07-23 10:41 UTC|newest]

Thread overview: 131+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06  4:18 [PATCH 00/19] arch: Add basic LoongArch support Huacai Chen
2021-07-06  4:18 ` [PATCH 01/19] LoongArch: Add elf-related definitions Huacai Chen
2021-07-06  4:18 ` [PATCH 02/19] LoongArch: Add writecombine support for drm Huacai Chen
2021-07-06  4:18 ` [PATCH 03/19] LoongArch: Add build infrastructure Huacai Chen
2021-07-06 10:12   ` Arnd Bergmann
2021-07-19  1:26     ` Huacai Chen
2021-07-19  7:43       ` Arnd Bergmann
2021-07-19 13:02         ` Huacai Chen
2021-07-06 10:35   ` Arnd Bergmann
2021-07-07  0:00   ` Randy Dunlap
2021-07-19  1:28     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 05/19] LoongArch: Add boot and setup routines Huacai Chen
2021-07-06 10:16   ` Arnd Bergmann
2021-07-27 11:53     ` Huacai Chen
2021-07-27 12:40       ` Arnd Bergmann
2021-07-27 12:51         ` Ard Biesheuvel
2021-07-27 13:14           ` Arnd Bergmann
2021-07-27 16:22             ` Ard Biesheuvel
2021-07-27 17:53               ` Arnd Bergmann
2021-07-28 10:24                 ` Huacai Chen
2021-07-06 10:55   ` Arnd Bergmann
2021-07-06  4:18 ` [PATCH 06/19] LoongArch: Add exception/interrupt handling Huacai Chen
2021-07-06 10:16   ` Arnd Bergmann
2021-07-06 10:56     ` Arnd Bergmann
2021-07-06 11:06   ` Peter Zijlstra
2021-07-07 13:56     ` Nicholas Piggin
2021-07-27 14:10       ` Peter Zijlstra
2021-07-27 15:08         ` Arnd Bergmann
2021-07-28 10:16           ` Huacai Chen
2021-07-28 12:23             ` Arnd Bergmann
2021-07-06  4:18 ` [PATCH 07/19] LoongArch: Add process management Huacai Chen
2021-07-06 10:16   ` Arnd Bergmann
2021-07-06 10:57     ` Arnd Bergmann
2021-07-06 11:09     ` Peter Zijlstra
2021-08-12 11:17       ` Huacai Chen
2021-08-12 12:29         ` Arnd Bergmann
2021-08-12 12:51           ` Huacai Chen
2021-07-06  4:18 ` [PATCH 08/19] LoongArch: Add memory management Huacai Chen
2021-07-06 10:16   ` Arnd Bergmann
2021-07-06 10:57     ` Arnd Bergmann
2021-08-12 11:20     ` Huacai Chen
2021-08-16  1:57   ` Guo Ren
2021-08-16  3:31     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 09/19] LoongArch: Add system call support Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 10:58     ` Arnd Bergmann
2021-07-07  4:24     ` Huacai Chen
2021-07-07  6:44       ` Arnd Bergmann
2021-07-07  7:00         ` Huacai Chen
2021-07-09  8:44         ` Huacai Chen
2021-07-06 13:51   ` Thomas Gleixner
2021-07-07  4:27     ` Huacai Chen
2021-08-12 12:40     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 10/19] LoongArch: Add signal handling support Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 10:59     ` Arnd Bergmann
2021-07-08 13:04     ` Huacai Chen
2021-07-08 13:23       ` Arnd Bergmann
2021-07-09  9:24         ` Huacai Chen
2021-07-09 10:22           ` Arnd Bergmann
2021-07-09 14:49             ` Eric W. Biederman
2021-07-09 15:59               ` Arnd Bergmann
2021-08-26 16:43   ` Xi Ruoyao
2021-08-27  4:23     ` Huacai Chen
2021-08-27  4:27       ` Xi Ruoyao
2021-07-06  4:18 ` [PATCH 11/19] LoongArch: Add elf and module support Huacai Chen
2021-07-06  4:18 ` [PATCH 12/19] LoongArch: Add misc common routines Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 11:00     ` Arnd Bergmann
2021-07-23 10:41     ` Huacai Chen [this message]
2021-07-23 11:43       ` Arnd Bergmann
2021-07-24 12:53         ` Huacai Chen
2021-07-06  4:18 ` [PATCH 13/19] LoongArch: Add some library functions Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 11:00     ` Arnd Bergmann
2021-08-12 11:22     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 14/19] LoongArch: Add 64-bit Loongson platform Huacai Chen
2021-07-06  4:18 ` [PATCH 15/19] LoongArch: Add PCI controller support Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 11:01     ` Arnd Bergmann
2021-08-12 11:29     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 16/19] LoongArch: Add VDSO and VSYSCALL support Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 11:02     ` Arnd Bergmann
2021-08-12 11:31     ` Huacai Chen
2021-07-06  4:18 ` [PATCH 17/19] LoongArch: Add multi-processor (SMP) support Huacai Chen
2021-07-06 10:17   ` Arnd Bergmann
2021-07-06 11:03     ` Arnd Bergmann
2021-07-06 11:32   ` Peter Zijlstra
2021-08-12 11:39     ` Huacai Chen
2021-07-06 11:56   ` Peter Zijlstra
2021-07-06 13:48   ` Peter Zijlstra
2021-08-12 11:41     ` Huacai Chen
2021-07-06 13:52   ` Peter Zijlstra
2021-07-06  4:18 ` [PATCH 18/19] LoongArch: Add Non-Uniform Memory Access (NUMA) support Huacai Chen
2021-07-06 10:18   ` Arnd Bergmann
2021-07-06 11:03     ` Arnd Bergmann
2021-08-12 11:46     ` Huacai Chen
2021-08-12 12:48       ` Arnd Bergmann
2021-07-06  4:18 ` [PATCH 19/19] LoongArch: Add Loongson-3 default config file Huacai Chen
2021-07-06 10:18   ` Arnd Bergmann
2021-07-06 11:04     ` Arnd Bergmann
2021-08-12 11:58     ` Huacai Chen
2021-08-12 12:50       ` Arnd Bergmann
2021-07-06 10:11 ` [PATCH 00/19] arch: Add basic LoongArch support Arnd Bergmann
2021-07-07  3:04   ` Huacai Chen
2021-07-07  7:28     ` Arnd Bergmann
2021-07-29 16:48       ` Huacai Chen
2021-07-30 20:50         ` Arnd Bergmann
2021-07-06 10:33 ` Arnd Bergmann
     [not found] ` <20210706041820.1536502-5-chenhuacai@loongson.cn>
2021-07-06 10:16   ` [PATCH 04/19] LoongArch: Add common headers Arnd Bergmann
2021-08-12 11:05     ` Huacai Chen
2021-08-12 12:45       ` Arnd Bergmann
2021-08-13  3:30         ` Huacai Chen
2021-08-13  7:05           ` Arnd Bergmann
2021-08-13  8:14             ` Huacai Chen
2021-08-13  9:08               ` Arnd Bergmann
2021-08-14  2:50                 ` Huacai Chen
2021-08-15  8:56                   ` Arnd Bergmann
2021-08-16  4:10                     ` Huacai Chen
2021-08-18  9:38                       ` Arnd Bergmann
2021-08-20  4:00                         ` Huacai Chen
2021-08-20  7:55                           ` Arnd Bergmann
2021-08-21  8:16                             ` Huacai Chen
2021-07-06 10:54   ` Arnd Bergmann
2021-07-06 10:57   ` Peter Zijlstra
2021-07-06 11:23   ` Peter Zijlstra
2021-07-06 12:59     ` Arnd Bergmann
2021-07-06 13:20       ` Peter Zijlstra
2021-07-06 13:37       ` Peter Zijlstra
2021-07-06 11:59   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAhV-H6PDr=YZdc=2NJ6hceE7HoKB-WcUHi3GEgtfO8nbxOV3g@mail.gmail.com' \
    --to=chenhuacai@gmail.com \
    --cc=airlied@linux.ie \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=chenhuacai@loongson.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).