1. 29 Jun, 2023 9 commits
    • WANG Xuerui's avatar
      LoongArch: Tweak CFLAGS for Clang compatibility · 38b10b26
      WANG Xuerui authored
      Now the arch code is mostly ready for LLVM/Clang consumption, it is time
      to re-organize the CFLAGS a little to actually enable the LLVM build.
      Namely, all -G0 switches from CFLAGS are removed, and -mexplicit-relocs
      and -mdirect-extern-access are now wrapped with cc-option (with the
      related asm/percpu.h definition guarded against toolchain combos that
      are known to not work).
      
      A build with !RELOCATABLE && !MODULE is confirmed working within a QEMU
      environment; support for the two features are currently blocked on
      LLVM/Clang, and will come later.
      
      Why -G0 can be removed:
      
      In GCC, -G stands for "small data threshold", that instructs the
      compiler to put data smaller than the specified threshold in a dedicated
      "small data" section (called .sdata on LoongArch and several other
      arches).
      
      However, benefiting from this would require ABI cooperation, which is
      not the case for LoongArch; and current GCC behave the same whether -G0
      (equal to disabling this optimization) is given or not. So, remove -G0
      from CFLAGS altogether for one less thing to care about. This also
      benefits LLVM/Clang compatibility where the -G switch is not supported.
      
      Why -mexplicit-relocs can now be conditionally applied without
      regressions:
      
      Originally -mexplicit-relocs is unconditionally added to CFLAGS in case
      of CONFIG_AS_HAS_EXPLICIT_RELOCS, because not having it (i.e. old GCC +
      new binutils) would not work: modules will have R_LARCH_ABS_* relocs
      inside, but given the rarity of such toolchain combo in the wild, it may
      not be worthwhile to support it, so support for such relocs in modules
      were not added back when explicit relocs support was upstreamed, and
      -mexplicit-relocs is unconditionally added to fail the build early.
      
      Now that Clang compatibility is desired, given Clang is behaving like
      -mexplicit-relocs from day one but without support for the CLI flag, we
      must ensure the flag is not passed in case of Clang. However, explicit
      compiler flavor checks can be more brittle than feature detection: in
      this case what actually matters is support for __attribute__((model))
      when building modules. Given neither older GCC nor current Clang support
      this attribute, probing for the attribute support and #error'ing out
      would allow proper UX without checking for Clang, and also automatically
      work when Clang support for the attribute is to be added in the future.
      
      Why -mdirect-extern-access is now conditionally applied:
      
      This is actually a nice-to-have optimization that can reduce GOT
      accesses, but not having it is harmless either. Because Clang does not
      support the option currently, but might do so in the future, conditional
      application via cc-option ensures compatibility with both current and
      future Clang versions.
      
      Suggested-by: Xi Ruoyao <xry111@xry111.site> # cc-option changes
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      38b10b26
    • WANG Xuerui's avatar
      LoongArch: Simplify the invtlb wrappers · 83d8b389
      WANG Xuerui authored
      The invtlb instruction has been supported by upstream LoongArch
      toolchains from day one, so ditch the raw opcode trickery and just use
      plain inline asm for it.
      
      While at it, also make the invtlb asm statements barriers, for proper
      modeling of the side effects. The functions are also marked as
      __always_inline instead of just "inline", because they cannot work at
      all if not inlined: the op argument will not be compile-time const in
      that case, thus failing to satisfy the "i" constraint.
      
      The signature of the other more specific invtlb wrappers contain unused
      arguments right now, but these are not removed right away in order for
      the patch to be focused. In the meantime, assertions are added to ensure
      no accidental misuse happens before the refactor. (The more specific
      wrappers cannot re-use the generic invtlb wrapper, because the ISA
      manual says $zero shall be used in case a particular op does not take
      the respective argument: re-using the generic wrapper would mean losing
      control over the register usage.)
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      83d8b389
    • WANG Xuerui's avatar
      LoongArch: Make the CPUCFG&CSR ops simple aliases of compiler built-ins · 53a4858c
      WANG Xuerui authored
      In addition to less visual clutter, this also makes Clang happy
      regarding the const-ness of arguments. In the original approach, all
      Clang gets to see is the incoming arguments whose const-ness cannot be
      proven without first being inlined; so Clang errors out here while GCC
      is fine.
      
      While at it, tweak several printk format strings because the return type
      of csr_read64 becomes effectively unsigned long, instead of unsigned
      long long.
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      53a4858c
    • WANG Xuerui's avatar
      LoongArch: Prepare for assemblers with proper FCSR class support · 38bb46f9
      WANG Xuerui authored
      The GNU assembler (as of 2.40) mis-treats FCSR operands as GPRs, but
      the LLVM IAS does not. Probe for this and refer to FCSRs as "$fcsrNN"
      if support is present.
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      38bb46f9
    • WANG Rui's avatar
      LoongArch: extable: Also recognize ABI names of registers · 24da0249
      WANG Rui authored
      When the kernel is compiled with LLVM, the register names being handled
      during exception fixup building are ABI names instead of bare $rNN
      style. Add mapping for the ABI names for LLVM compatibility.
      Signed-off-by: default avatarWANG Rui <wangrui@loongson.cn>
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      24da0249
    • WANG Rui's avatar
      LoongArch: Calculate various sizes in the linker script · 414cefc7
      WANG Rui authored
      Taking the address delta between symbols in different sections is not
      supported by the LLVM IAS. Instead, do this in the linker script, so
      the same data can be properly referenced in assembly.
      Signed-off-by: default avatarWANG Rui <wangrui@loongson.cn>
      Signed-off-by: default avatarWANG Xuerui <git@xen0n.name>
      [chenhuacai: Fix build with !CONFIG_EFI_STUB]
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      414cefc7
    • WANG Rui's avatar
      LoongArch: Add guard for the larch_insn_gen_xxx functions · 0d03e9dc
      WANG Rui authored
      Add guard for the larch_insn_gen_xxx functions to verify whether the
      immediate operand is within the acceptable range.
      Signed-off-by: default avatarWANG Rui <wangrui@loongson.cn>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      0d03e9dc
    • Dan Carpenter's avatar
      LoongArch: Delete unnecessary debugfs checking · d7c24960
      Dan Carpenter authored
      Debugfs functions are not supposed to be checked for errors.  This
      is sort of unusual but it is described in the comments for the
      debugfs_create_dir() function.  Also debugfs_create_dir() can never
      return NULL.
      Reviewed-by: default avatarWANG Xuerui <git@xen0n.name>
      Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      d7c24960
    • Huacai Chen's avatar
      LoongArch: Set CPU#0 as the io master for FDT · 872b368b
      Huacai Chen authored
      ACPI systems set io masters by parsing ACPI MADT, FDT systems have no
      MADT so we explicitly set CPU#0 as the io master. Otherwise CPU#0 will
      be considered as hotpluggable.
      Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
      872b368b
  2. 27 Jun, 2023 1 commit
  3. 25 Jun, 2023 5 commits
  4. 23 Jun, 2023 21 commits
  5. 22 Jun, 2023 4 commits