Commit graph

1032586 commits

Author SHA1 Message Date
Emil Renner Berthing
75a0e10400 [NOT-FOR-UPSTREAM] Add build instructions
For convenience this also adds a small beaglev_defconfig and the
firmware needed for the brcmfmac driver along with the signed regulatory
database.

The firmware is from the linux-firmware repo and the regulatory database
from the wireless-regdb Fedora package.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Drew Fustini <drew@beagleboard.org>
2021-09-26 16:04:40 +02:00
TekkamanV
eeadab3e90 [NOT-FOR-UPSTREAM] riscv: Add starfive jh7100 starlight fedora defconfig
Signed-off-by: TekkamanV <tekkamanv@starfivetech.com>
2021-09-26 16:04:39 +02:00
Emil Renner Berthing
67d76a9cfd riscv: dts: Add early A1 variant of the BeagleV Starlight board
This is an early version of the BeagleV Starlight board that has GPIO63
wired up to tell the PMIC to reset the whole board rather than just the
ethernet phy as it does on the later versions sent out as part of the
BeagleV beta program.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:39 +02:00
TekkamanV
59af5e130d riscv: dts: Add JH7100 and BeagleV Starlight support
Based on the device tree in https://github.com/starfive-tech/u-boot/
with contributions from:
yanhong.wang <yanhong.wang@starfivetech.com>
Huan.Feng <huan.feng@starfivetech.com>
ke.zhu <ke.zhu@starfivetech.com>
yiming.li <yiming.li@starfivetech.com>
jack.zhu <jack.zhu@starfivetech.com>
Samin Guo <samin.guo@starfivetech.com>
Chenjieqin <Jessica.Chen@starfivetech.com>
bo.li <bo.li@starfivetech.com>

Rearranged, cleanups, fixes, TPS65086 and pins added by Emil.
Cleanups, fixes, LED and clocks added by Geert.
Cleanups and GPIO fixes from Drew.
Thermal zone added by Stephen.
PWM pins added by Jianlong.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Stephen L Arnold <nerdboy@gentoo.org>
Signed-off-by: Drew Fustini <drew@beagleboard.org>
Signed-off-by: Jianlong Huang <jianlong.huang@starfivetech.com>
2021-09-26 16:04:39 +02:00
Atish Patra
6ee7a7055a RISC-V: Support non-coherent DMA operations
** Do not upstream **

This is hacky fix just for testing. The actual patch would read the
RISCV_UNCACHED_OFFSET from the DT for only the non-coherent devices.
All other devices on beagleV and all other platform should just set
dma_default_coherent to true.

[Emil: remove spurious whitespace and fix format string warning]

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:39 +02:00
Emil Renner Berthing
2ade246c15 spi: cadence-quadspi: Allow compilation on RISC-V
This IP is also used on the StarFive JH7100 riscv64 SoC and presumably
also the upcoming JH7110 SoC.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:39 +02:00
Farzad Farshchi
29e676e7fa nvdla: add NVDLA driver
Additional update from Prashant Gaikwad <pgaikwad@nvidia.com>
Adapted for Linux 5.13 and the BeagleV Starlight board by
<cybergaszcz@gmail.com>
2021-09-26 16:04:39 +02:00
Geert Uytterhoeven
1aaa011e7e video: fbdev: starfive: Use round_up() instead of _ALIGN_UP()
_ALIGN_UP() is being removed by commit efcec32fe8 ("riscv: Cleanup
unused functions") in riscv/for-next:

    drivers/video/fbdev/starfive/starfive_displayer.c: In function ‘of_parse_wr_cmd’:
    drivers/video/fbdev/starfive/starfive_displayer.c:616:27: error: implicit declaration of function ‘_ALIGN_UP’ [-Werror=implic
    it-function-declaration]
      616 |  dev_cmds->cmds = kzalloc(_ALIGN_UP(alloc_bytes, 4), GFP_KERNEL);
	  |                           ^~~~~~~~~

Just use roundup() instead.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:39 +02:00
Geert Uytterhoeven
585a2ab3d2 video: fbdev: starfive: Fix frame buffer reserved memory resource conflict
starfive,vpp-lcdc 12000000.sfivefb: can't request region for resource [mem 0xfb000000-0xfcffffff]
    starfive,vpp-lcdc 12000000.sfivefb: Fail to allocate video RAM
    starfive,vpp-lcdc 12000000.sfivefb: starfive fb init fail
    starfive,vpp-lcdc 12000000.sfivefb: fb info init FAIL
    starfive,vpp-lcdc: probe of 12000000.sfivefb failed with error -16

devm_ioremap_resource() calls devm_request_mem_region(), which fails as
the reserved memory for the frame buffer is already present in the
resource list, cfr. /proc/iomem:

    fb000000-fcffffff : Reserved

Fix this by mapping the frame buffer memory using devm_ioremap().

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:39 +02:00
Geert Uytterhoeven
0d2bbd1e52 video: fbdev: starfive: FB_STARFIVE_HDMI_TDA998X depends on DRM_FBDEV_EMULATION
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L0 ':
tda998x.c:(.text+0x51c): undefined reference to `drm_encoder_cleanup'
riscv64-linux-gnu-ld: tda998x.c:(.text+0x534): undefined reference to `drm_encoder_cleanup'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L75':
tda998x.c:(.text+0x564): undefined reference to `drm_of_find_possible_crtcs'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `tda998x_encoder_destroy':
tda998x.c:(.text+0x58a): undefined reference to `drm_encoder_init'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `tda998x_bind':
tda998x.c:(.text+0x5b2): undefined reference to `drm_bridge_attach'
riscv64-linux-gnu-ld: tda998x.c:(.text+0x5c0): undefined reference to `drm_encoder_cleanup'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L0 ':
tda998x.c:(.text+0x692): undefined reference to `drm_bridge_remove'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L124':
tda998x.c:(.text+0x904): undefined reference to `hdmi_infoframe_pack'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L135':
tda998x.c:(.text+0x9e8): undefined reference to `drm_connector_cleanup'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L0 ':
tda998x.c:(.text+0xa00): undefined reference to `drm_connector_cleanup'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L143':
tda998x.c:(.text+0xa56): undefined reference to `drm_connector_init'
riscv64-linux-gnu-ld: tda998x.c:(.text+0xa66): undefined reference to `drm_connector_attach_encoder'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `tda998x_bridge_detach':
tda998x.c:(.text+0xa8a): undefined reference to `__drm_err'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L189':
tda998x.c:(.text+0xd16): undefined reference to `drm_do_get_edid'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L0 ':
tda998x.c:(.text+0xd34): undefined reference to `drm_connector_update_edid_property'
riscv64-linux-gnu-ld: tda998x.c:(.text+0xd4e): undefined reference to `drm_add_edid_modes'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L165':
tda998x.c:(.text+0xd5a): undefined reference to `drm_detect_monitor_audio'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L0 ':
tda998x.c:(.text+0xfb0): undefined reference to `__drm_dbg'
riscv64-linux-gnu-ld: tda998x.c:(.text+0x108a): undefined reference to `drm_kms_helper_hotplug_event'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L283':
tda998x.c:(.text+0x1844): undefined reference to `drm_hdmi_avi_infoframe_from_display_mode'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.L361':
tda998x.c:(.text+0x2078): undefined reference to `drm_bridge_add'
riscv64-linux-gnu-ld: drivers/video/fbdev/starfive/tda998x.o: in function `.LANCHOR0':
tda998x.c:(.rodata+0x90): undefined reference to `drm_helper_connector_dpms'
riscv64-linux-gnu-ld: tda998x.c:(.rodata+0x98): undefined reference to `drm_atomic_helper_connector_reset'
riscv64-linux-gnu-ld: tda998x.c:(.rodata+0xb0): undefined reference to `drm_helper_probe_single_connector_modes'
riscv64-linux-gnu-ld: tda998x.c:(.rodata+0xd8): undefined reference to `drm_atomic_helper_connector_duplicate_state'
riscv64-linux-gnu-ld: tda998x.c:(.rodata+0xe0): undefined reference to `drm_atomic_helper_connector_destroy_state'

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:38 +02:00
Qing Zhao
830f2a86e8 video: fbdev: starfive: fix fb bug about HDMI display 2021-09-26 16:04:38 +02:00
Stephen L Arnold
3c9983174f video: fbdev: starfive: fix modpost build error (missing license)
Signed-off-by: Stephen L Arnold <nerdboy@gentoo.org>
2021-09-26 16:04:38 +02:00
Emil Renner Berthing
123f7ec82c video: fbdev: starfive: improve error handling
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:38 +02:00
Emil Renner Berthing
f8aadf9b30 video: fbdev: starfive: fix compiler warnings
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:38 +02:00
jack.zhu
0c90600daa video: fbdev: starfive: workaround for unavailable pointer of dtb
Fix sf_fb_map_video_memory in starfive_fb.c
2021-09-26 16:04:38 +02:00
jack.zhu
461413540d video: fbdev: starfive: update fb driver 2021-09-26 16:04:38 +02:00
TekkamanV
89b831a8fe media: starfive: Remove MODULE_SUPPORTED_DEVICE macro call
This macro was never implemented and completely removed upstream.

Signed-off-by: TekkamanV <tekkamanv@starfivetech.com>
2021-09-26 16:04:38 +02:00
jack.zhu
44c811818c drivers/video/fbdev and drivers/media/platform: starfive drivers added
1, add ov5640&sc2235 drivers, update stf_isp
2, add MIPI/CSI/DSI drivers for VIC7100
2021-09-26 16:04:37 +02:00
Matteo Croce
d48768da73 net: stmmac: use GFP_DMA32
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
2021-09-26 16:04:37 +02:00
Tom
d1672a46bd net: stmmac: Configure gtxclk based on speed 2021-09-26 16:04:37 +02:00
Geert Uytterhoeven
31764b3dcd drivers/dma: dw-axi-dmac-starfive: Remove calls specific to ARM64 ACPI
iort_dma_setup() is being removed by commit db59e1b6e4 ("ACPI:
arm64: Move DMA setup operations out of IORT") in iommu/next:

    drivers/dma/dw-axi-dmac-starfive/starfive_dmaengine_memcpy.c: In function ‘dw_dma_async_
    do_memcpy’:
    drivers/dma/dw-axi-dmac-starfive/starfive_dmaengine_memcpy.c:152:2: error: implicit decl
    aration of function ‘iort_dma_setup’ [-Werror=implicit-function-declaration]
      152 |  iort_dma_setup(dma_dev, &dma_addr, &dma_size);
	  |  ^~~~~~~~~~~~~~
    drivers/dma/dw-axi-dmac-starfive/starfive_dmaengine_memcpy.c:153:8: warning: assignment to ‘const struct iommu_ops *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
      153 |  iommu = iort_iommu_configure_id(dma_dev, NULL);
	  |        ^
    drivers/dma/dw-axi-dmac-starfive/starfive_dmaengine_memcpy.c: In function ‘dw_dma_memcpy_raw’:
    drivers/dma/dw-axi-dmac-starfive/starfive_dmaengine_memcpy.c:223:8: warning: assignment to ‘const struct iommu_ops *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
      223 |  iommu = iort_iommu_configure_id(dma_dev, NULL);
	  |        ^

iort_dma_setup() and iort_iommu_configure_id() are part of the ARM64
ACPI implementation.  As CONFIG_ACPI_IORT cannot be enabled on RISC-V,
they were dummies anyway, so these calls can just be removed.

[Emil: remove unused local variables too]

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
Boot-tested, but the affected code paths were not exercised.
2021-09-26 16:04:37 +02:00
Michael Scott
971173b9d1 drivers/dma: Fix VIC7100 dw-axi-dmac-platform driver addition
Descriptor management was simplified with commit:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef6fb2d6f1abd56cc067c694253ea362159b5ac3

Code added to dw-axi-dmac-platform driver due to VIC7100 Cache Coherency
issues needed follow those changes.

Signed-off-by: Michael Scott <mike@foundries.io>
2021-09-26 16:04:37 +02:00
Tom
09bc355ef1 drivers/dma: Add dw-axi-dmac-starfive driver for JH7100 2021-09-26 16:04:37 +02:00
yiming.li
4f49a36502 drivers/pwm/pwm-sifive-ptc: Clear PWM CNTR
Clear CNTR of PWM after setting period & duty_cycle
2021-09-26 16:04:37 +02:00
Chenjieqin
429cf9fe32 drivers/pwm: Add SiFive PWM PTC driver 2021-09-26 16:04:36 +02:00
Samin Guo
da09ea8c05 drivers/tty/serial/8250: update driver for JH7100 2021-09-26 16:04:36 +02:00
Tom
8778e98f2c riscv: Add StarFive JH7100 support 2021-09-26 16:04:36 +02:00
Atish Patra
b1108f5977 sifive/sifive_l2_cache: Align the address to cache line
[Emil: fix suggested by Geert Uytterhoeven <geert@linux-m68k.org>]

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:36 +02:00
Geert Uytterhoeven
28e5304536 sifive/sifive_l2_cache: Print a backtrace on out-of-range flushes
This makes it easier to find out which driver passes a wrong address
range.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:36 +02:00
Tom
578236e1ab sifive/sifive_l2_cache: Add disabling IRQ option (workaround) 2021-09-26 16:04:36 +02:00
Tom
53a0235d5b sifive/sifive_l2_cache: Add Starfive support 2021-09-26 16:04:36 +02:00
Tom
8af79592c8 sifive/sifive_l2_cache: Add sifive_l2_flush64_range function 2021-09-26 16:04:36 +02:00
Huan Feng
e0eaabbcc5 drivers/hw_random: Add StarFive JH7100 Random Number Generator driver 2021-09-26 16:04:35 +02:00
Geert Uytterhoeven
8fe491d7eb [WIP] dt-bindings: dma: dw-axi-dmac: Increase DMA channel limit to 16
The first DMAC instance in the StarFive JH7100 SoC supports 16 DMA
channels.

FIXME Given there are more changes to the driver than just increasing
      DMAC_MAX_CHANNELS, we probably need a new compatible value, too.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:35 +02:00
Emil Renner Berthing
408ba9a892 hwmon: (sfctemp) Add StarFive JH7100 temperature sensor
Register definitions and conversion constants based on sfctemp driver by
Samin in the StarFive 5.10 kernel.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Samin Guo <samin.guo@starfivetech.com>
2021-09-26 16:04:35 +02:00
Emil Renner Berthing
18bdb7db30 dt-bindings: hwmon: add starfive,jh7100-temp bindings
Add bindings for the temperature sensor on the StarFive JH7100 SoC.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Reviewed-by: Rob Herring <robh@kernel.org>
2021-09-26 16:04:35 +02:00
Emil Renner Berthing
c2f03e8aa7 pinctrl: starfive: Reset pinmux settings
Current u-boot doesn't seem to take into account that some GPIOs are
configured as inputs/outputs of certain peripherals on power-up. This
means it ends up configuring some GPIOs as inputs to more than one
peripheral which the documentation explicitly says is illegal. Similarly
it also ends up configuring more than one GPIO as output of the same
peripheral. While not explicitly mentioned by the documentation this
also seems like a bad idea.

The easiest way to remedy this mess is to just disconnect all GPIOs from
peripherals and have our pinmux configuration set everything up
properly. This, however, means that we'd disconnect the serial console
from its pins for a while, so add a device tree property to keep
certain GPIOs from being reset.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:35 +02:00
Emil Renner Berthing
565e1446b5 pinctrl: starfive: Add pinctrl driver for the JH7100 SoC
This adds a combined pinctrl and gpio driver for the StarFive Ltd.
JH7100 RISC-V SoC [1].

For each "GPIO" there are two registers for configuring the output and
output enable signals, which may come from other peripherals, and
controlling the GPIOs from software amounts to setting these signals
to constant 0 or constant 1. In other words the same registers are used
for both pinmuxing and controlling the GPIOs, which makes it easier to
combine the pinctrl and gpio driver in one.

The gpio code is adapted from the gpio driver in the vendor tree written
by Huan Feng with cleanups and fixes by Drew and me.

[1] https://github.com/starfive-tech/beaglev_doc

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Huan Feng <huan.feng@starfivetech.com>
Signed-off-by: Drew Fustini <drew@beagleboard.org>
2021-09-26 16:04:35 +02:00
Emil Renner Berthing
ae384415b6 dt-bindings: pinctrl: add starfive,jh7100-pinctrl bindings
Add bindings for the pin controller on the StarFive JH7100 SoC [1].

[1] https://github.com/starfive-tech/beaglev_doc

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:35 +02:00
Geert Uytterhoeven
c88b77f77a [WIP] clk: starfive: Add preliminary JH7100 Clock Generator Driver
Add a preliminary driver for the StarFive JH7100 Clock Generator,
based on work by Ahmad Fatoum for Barebox.

Functional differences compared to the Barebox driver:
  - Addition of starfive_clk_pll_mult(), to make the PLL outputs
    reasonable,
  - Add temporary overrides for critical clocks (uart, i2c, spi) until
    we get the clock tree right, so we don't have to keep dummy clocks
    like uartclk and hs_uartclk in the DTS.

This driver sets clk_ignore_unused, else the system locks up when all
clocks deemed unused are disabled.

To be updated when the documentation becomes available.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:35 +02:00
Geert Uytterhoeven
025a84df2b [NOT-FOR-UPSTREAM] clk: Make clk_ignore_unused public
Make clk_ignore_unused public, so the StarFive JH7100 Clock Generator
driver can set the flag.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:34 +02:00
Geert Uytterhoeven
25dfb314a1 [WIP] dt-bindings: clock: starfive: Add preliminary JH7100 bindings
Add preliminary Device Tree bindings for the StarFive JH7100 Clock
Generator.

To be verified against documentation when it becomes available.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:34 +02:00
Geert Uytterhoeven
ef65dd6ac2 [WIP] dt-bindings: reset: starfive: Add JH7100 Reset Definitions
Add all resets for the StarFive JH7100 Reset Controller.

Based on work by Ahmad Fatoum for Barebox, with "JH7100_" prefixes added
to all definitions.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:34 +02:00
Geert Uytterhoeven
8236f12d45 [WIP] dt-bindings: clock: starfive: Add JH7100 Clock Definitions
Add all clock outputs for the StarFive JH7100 Clock Generator.

Based on work by Ahmad Fatoum for Barebox, with "JH7100_" prefixes added
to all definitions.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
2021-09-26 16:04:34 +02:00
Matteo Croce
37d30c0222 riscv: use the generic string routines
Use the generic routines which handle alignment properly.

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
2021-09-26 16:04:34 +02:00
Matteo Croce
d12854a0f8 lib/string: optimized memset
The generic memset is defined as a byte at time write.  This is always
safe, but it's slower than a 4 byte or even 8 byte write.

Write a generic memset which fills the data one byte at time until the
destination is aligned, then fills using the largest size allowed, and
finally fills the remaining data one byte at time.

On a RISC-V machine the speed goes from 140 Mb/s to 241 Mb/s, and this the
binary size increase according to bloat-o-meter:

Function     old     new   delta
memset        32     148    +116

Link: https://lkml.kernel.org/r/20210702123153.14093-4-mcroce@linux.microsoft.com
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David Laight <David.Laight@aculab.com>
Cc: Drew Fustini <drew@beagleboard.org>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Guo Ren <guoren@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nick Kossifidis <mick@ics.forth.gr>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
2021-09-26 16:04:34 +02:00
Matteo Croce
77fe306feb lib/string: optimized memmove
When the destination buffer is before the source one, or when the buffers
doesn't overlap, it's safe to use memcpy() instead, which is optimized to
use a bigger data size possible.

This "optimization" only covers a common case.  In future, proper code
which does the same thing as memcpy() does but backwards can be done.

Link: https://lkml.kernel.org/r/20210702123153.14093-3-mcroce@linux.microsoft.com
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David Laight <David.Laight@aculab.com>
Cc: Drew Fustini <drew@beagleboard.org>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Guo Ren <guoren@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Nick Kossifidis <mick@ics.forth.gr>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
2021-09-26 16:04:34 +02:00
Matteo Croce
c33f0843e9 lib/string: optimized memcpy
Patch series "lib/string: optimized mem* functions", v2.

Rewrite the generic mem{cpy,move,set} so that memory is accessed with the
widest size possible, but without doing unaligned accesses.

This was originally posted as C string functions for RISC-V[1], but as
there was no specific RISC-V code, it was proposed for the generic
lib/string.c implementation.

Tested on RISC-V and on x86_64 by undefining __HAVE_ARCH_MEM{CPY,SET,MOVE}
and HAVE_EFFICIENT_UNALIGNED_ACCESS.

These are the performances of memcpy() and memset() of a RISC-V machine on
a 32 mbyte buffer:

memcpy:
original aligned:	 75 Mb/s
original unaligned:	 75 Mb/s
new aligned:		114 Mb/s
new unaligned:		107 Mb/s

memset:
original aligned:	140 Mb/s
original unaligned:	140 Mb/s
new aligned:		241 Mb/s
new unaligned:		241 Mb/s

The size increase is negligible:

$ scripts/bloat-o-meter vmlinux.orig vmlinux
add/remove: 0/0 grow/shrink: 4/1 up/down: 427/-6 (421)
Function                                     old     new   delta
memcpy                                        29     351    +322
memset                                        29     117     +88
strlcat                                       68      78     +10
strlcpy                                       50      57      +7
memmove                                       56      50      -6
Total: Before=8556964, After=8557385, chg +0.00%

These functions will be used for RISC-V initially.

[1] https://lore.kernel.org/linux-riscv/20210617152754.17960-1-mcroce@linux.microsoft.com/

This patch (of 3):

Rewrite the generic memcpy() to copy a word at time, without generating
unaligned accesses.

The procedure is made of three steps: First copy data one byte at time
until the destination buffer is aligned to a long boundary.  Then copy the
data one long at time shifting the current and the next long to compose a
long at every cycle.  Finally, copy the remainder one byte at time.

This is the improvement on RISC-V:

original aligned:	 75 Mb/s
original unaligned:	 75 Mb/s
new aligned:		114 Mb/s
new unaligned:		107 Mb/s

and this the binary size increase according to bloat-o-meter:

Function     old     new   delta
memcpy        36     324    +288

Link: https://lkml.kernel.org/r/20210702123153.14093-1-mcroce@linux.microsoft.com
Link: https://lkml.kernel.org/r/20210702123153.14093-2-mcroce@linux.microsoft.com
Signed-off-by: Matteo Croce <mcroce@microsoft.com>
Cc: Nick Kossifidis <mick@ics.forth.gr>
Cc: Guo Ren <guoren@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: David Laight <David.Laight@aculab.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Drew Fustini <drew@beagleboard.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
2021-09-26 16:04:34 +02:00
Xianting Tian
917c37e86b riscv: add ARCH_DMA_MINALIGN support
Introduce ARCH_DMA_MINALIGN to riscv arch.

Signed-off-by: Xianting Tian <xianting.tian@linux.alibaba.com>
2021-09-26 16:04:33 +02:00
Alexandre Ghiti
a3a944bf23 riscv: Flush current cpu icache before other cpus
On SiFive Unmatched, I recently fell onto the following BUG when booting:

[    0.000000] ftrace: allocating 36610 entries in 144 pages
[    0.000000] Oops - illegal instruction [#1]
[    0.000000] Modules linked in:
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.13.1+ #5
[    0.000000] Hardware name: SiFive HiFive Unmatched A00 (DT)
[    0.000000] epc : riscv_cpuid_to_hartid_mask+0x6/0xae
[    0.000000]  ra : __sbi_rfence_v02+0xc8/0x10a
[    0.000000] epc : ffffffff80007240 ra : ffffffff80009964 sp : ffffffff81803e10
[    0.000000]  gp : ffffffff81a1ea70 tp : ffffffff8180f500 t0 : ffffffe07fe30000
[    0.000000]  t1 : 0000000000000004 t2 : 0000000000000000 s0 : ffffffff81803e60
[    0.000000]  s1 : 0000000000000000 a0 : ffffffff81a22238 a1 : ffffffff81803e10
[    0.000000]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000
[    0.000000]  a5 : 0000000000000000 a6 : ffffffff8000989c a7 : 0000000052464e43
[    0.000000]  s2 : ffffffff81a220c8 s3 : 0000000000000000 s4 : 0000000000000000
[    0.000000]  s5 : 0000000000000000 s6 : 0000000200000100 s7 : 0000000000000001
[    0.000000]  s8 : ffffffe07fe04040 s9 : ffffffff81a22c80 s10: 0000000000001000
[    0.000000]  s11: 0000000000000004 t3 : 0000000000000001 t4 : 0000000000000008
[    0.000000]  t5 : ffffffcf04000808 t6 : ffffffe3ffddf188
[    0.000000] status: 0000000200000100 badaddr: 0000000000000000 cause: 0000000000000002
[    0.000000] [<ffffffff80007240>] riscv_cpuid_to_hartid_mask+0x6/0xae
[    0.000000] [<ffffffff80009474>] sbi_remote_fence_i+0x1e/0x26
[    0.000000] [<ffffffff8000b8f4>] flush_icache_all+0x12/0x1a
[    0.000000] [<ffffffff8000666c>] patch_text_nosync+0x26/0x32
[    0.000000] [<ffffffff8000884e>] ftrace_init_nop+0x52/0x8c
[    0.000000] [<ffffffff800f051e>] ftrace_process_locs.isra.0+0x29c/0x360
[    0.000000] [<ffffffff80a0e3c6>] ftrace_init+0x80/0x130
[    0.000000] [<ffffffff80a00f8c>] start_kernel+0x5c4/0x8f6
[    0.000000] ---[ end trace f67eb9af4d8d492b ]---
[    0.000000] Kernel panic - not syncing: Attempted to kill the idle task!
[    0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]---

While ftrace is looping over a list of addresses to patch, it always failed
when patching the same function: riscv_cpuid_to_hartid_mask. Looking at the
backtrace, the illegal instruction is encountered in this same function.
However, patch_text_nosync, after patching the instructions, calls
flush_icache_range. But looking at what happens in this function:

flush_icache_range -> flush_icache_all
                   -> sbi_remote_fence_i
                   -> __sbi_rfence_v02
                   -> riscv_cpuid_to_hartid_mask

The icache and dcache of the current cpu are never synchronized between the
patching of riscv_cpuid_to_hartid_mask and calling this same function.

So fix this by flushing the current cpu's icache before asking for the other
cpus to do the same.

Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
2021-09-26 16:04:05 +02:00