15 Commits
Author SHA1 Message Date
Huacai Chen 9c402f7e11 LoongArch: Prefer top-down allocation after arch_mem_init()
Currently we use bottom-up allocation after sparse_init(), the reason is
sparse_init() need a lot of memory, and bottom-up allocation may exhaust
precious low memory (below 4GB). On the other hand, SWIOTLB and CMA need
low memories for DMA32, so swiotlb_init() and dma_contiguous_reserve()
need bottom-up allocation.

Since swiotlb_init() and dma_contiguous_reserve() are both called in
arch_mem_init(), we no longer need bottom-up allocation after that. So
we set the allocation policy to top-down at the end of arch_mem_init(),
in order to avoid later memory allocations (such as KASAN) exhaust low
memory.

This solve at least two problems:
1. Some buggy BIOSes use 0xfd000000~0xfe000000 for secondary CPUs, but
   didn't reserve this range, which causes smpboot failures.
2. Some DMA32 devices, such as Loongson-DRM and OHCI, cannot work with
   KASAN enabled.

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-08-24 14:17:22 +08:00
Huacai Chen 0959661f0a LoongArch: Init acpi_gbl_use_global_lock to false
Init acpi_gbl_use_global_lock to false, in order to void error messages
during boot phase:

 ACPI Error: Could not enable GlobalLock event (20240827/evxfevnt-182)
 ACPI Error: No response from Global Lock hardware, disabling lock (20240827/evglock-59)

Fixes: 628c3bb40e9a8cefc0a6 ("LoongArch: Add boot and setup routines")
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:41:24 +08:00
Qiang Ma c29fa9ee04 LoongArch: Correct the calculation logic of thread_count
For thread_count, the current calculation method has a maximum of 255,
which may not be sufficient in the future. Therefore, we are correcting
it now.

Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]

[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf

Cc: stable@vger.kernel.org
Signed-off-by: Qiang Ma <maqianga@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2026-02-04 16:40:44 +08:00
maoxiaochuan 3205090d63 LoongArch: Consolidate max_pfn & max_low_pfn calculation
Now there 5 places which calculate max_pfn & max_low_pfn:
1. in fdt_setup() for FDT systems;
2. in memblock_init() for ACPI systems;
3. in init_numa_memory() for NUMA systems;
4. in arch_mem_init() to recalculate for "mem=" cmdline;
5. in paging_init() to recalculate for NUMA systems.

Since memblock_init() is called both for ACPI and FDT systems, move the
calculation out of the for_each_efi_memory_desc() loop can eliminate the
first case. The last case is very questionable (may be derived from the
MIPS/Loongson code) and breaks the "mem=" cmdline, so should be removed.
And then the NUMA version of paging_init() can be also eliminated.

After consolidation there are 3 places of calculation:
1. in memblock_init() for both ACPI and FDT systems;
2. in init_numa_memory() to recalculate for NUMA systems;
3. in arch_mem_init() to recalculate for the "mem=" cmdline.

For all cases the calculation is:
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);

Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-11-20 16:58:53 +08:00
Ming Wang 2420a975b0 LoongArch: Support mem=<size> kernel parameter
The LoongArch mem= parameter parser was previously limited to the
mem=<size>@<start> format. This was inconvenient for the common use
case of simply capping the total system memory, as it forced users to
manually specify a start address. It was also inconsistent with the
behavior on other architectures.

This patch enhances the parser in early_parse_mem() to also support the
more user-friendly mem=<size> format. The implementation now checks for
the presence of the '@' symbol to determine the user's intent:

- If mem=<size> is provided (no '@'), the kernel now calls
  memblock_enforce_memory_limit(). This trims memory from the top down
  to the specified size.
- If mem=<size>@<start> is provided, the original behavior is retained
  for backward compatibility. This allows for defining specific memory
  banks.

This change introduces an important usage rule reflected in the code's
comments: the mem=<size> format should only be specified once on the
kernel command line. It acts as a single, global cap on total memory. In
contrast, the mem=<size>@<start> format can be specified multiple times
to define several distinct memory regions.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-08-19 11:29:15 +08:00
GH Cao a7418fc11b feat: support CTCI 99pi-tf 2025-05-04 13:11:59 +08:00
ilikara 28986c7f2f Squashed commit of the following:
commit 36ff1f997966de5f83dffed9ad2c799634f9997d
Author: Ilikara <3435193369@qq.com>
Date:   Wed Apr 30 00:42:40 2025 +0800

    feat: remove unused code in 99pi wifi dts

commit 5d155e9fcb0adec13e022a83199e1fbf10ec5515
Author: ilikara <3435193369@qq.com>
Date:   Tue Apr 29 15:33:33 2025 +0800

    feat: add 99pi-wifi to boot_parm.h setup.c and rename 99pi's devicetree

commit 47888cd64c4aa54eaa23a346ef6ac08c73c23534
Merge: e89978dcc 2d8b839dd
Author: Ilikara <3435193369@qq.com>
Date:   Tue Apr 29 11:05:24 2025 +0800

    Merge branch 'master' into feat/99pai

commit e89978dccba5cfabb340b2b87456353b9d8763b7
Author: Ilikara <3435193369@qq.com>
Date:   Tue Apr 29 10:59:56 2025 +0800

    feat: use clocktree to get uart clock

commit 95f6d3dd313935f936ab9bf967ec0b2ed275c7d6
Merge: 459d4692f 881dbd52e
Author: Ilikara <3435193369@qq.com>
Date:   Sun Apr 20 00:08:53 2025 +0800

    Merge branch 'master' into feat/99pai

commit 459d4692f4e6d3e5890cf50211ca5f5ceaaa1e3e
Author: ilikara <3435193369@qq.com>
Date:   Tue Apr 8 07:12:19 2025 +0000

    build: support *make vmlinuz*

commit f11b0d1ceedf0eef6cc85bcb4ab21ac4027da525
Merge: 894f1392f 9bd4ef8ed
Author: ilikara <3435193369@qq.com>
Date:   Sun Apr 6 06:08:41 2025 +0000

    Merge branch 'master' into feat/99pai

commit 894f1392f8707c1fb092372fc8be58df4682f914
Merge: 8fad95d7d ff60a514f
Author: ilikara <3435193369@qq.com>
Date:   Fri Mar 28 08:49:41 2025 +0000

    Merge remote-tracking branch 'origin/master' into feat/99pai

commit 8fad95d7d6f1ec1f8c8b9ba8bb8ab89813eba5ff
Merge: a5752b0e4 6273342dd
Author: ilikara <3435193369@qq.com>
Date:   Fri Mar 14 14:17:50 2025 +0000

    Merge branch 'master' into feat/99pai

commit a5752b0e4788ed2b5189616c94f97967e92b394a
Author: ilikara <3435193369@qq.com>
Date:   Wed Mar 5 09:15:32 2025 +0000

    feat: update 99pai dts & config

commit f8b2a5fb938f55d77689a4332639009b2bb8c480
Merge: fdc292cbb d86346d04
Author: ilikara <3435193369@qq.com>
Date:   Tue Mar 4 08:00:21 2025 +0000

    Merge branch 'master' into feat/99pai

commit fdc292cbb95631ff16496b449dbac60f946e80d4
Merge: cfa4e13b2 924394055
Author: ilikara <3435193369@qq.com>
Date:   Sat Feb 22 15:59:49 2025 +0000

    Merge branch 'master' into feat/99pai

commit cfa4e13b293d0e540fbd86a742b10858dfc35305
Author: ilikara <3435193369@qq.com>
Date:   Thu Feb 20 16:15:36 2025 +0000

    fix: fix merge error

commit 5c743cf14fd853b65044c465742b8926f3d5821e
Merge: 34b5c4ced 0b45cc3a3
Author: ilikara <3435193369@qq.com>
Date:   Thu Feb 20 16:11:03 2025 +0000

    Merge branch 'master' into feat/99pai

commit 34b5c4ced86f98f657b0bf058627c883c90e274d
Author: ilikara <3435193369@qq.com>
Date:   Wed Feb 19 11:48:31 2025 +0000

    feat: support 99pai
2025-04-30 14:15:17 +08:00
maoxiaochuan 881dbd52e0 update to e7567cc18
1.Fix the issue of the SD card crashing due to repeated plugging and unplugging.
2.add init-polarity to support setup init pwm status
3.loongson2_thermal: update temperature formula
4.Fix alert/critical temperature to 75/105
5.Add alientek-2k300 support
2025-04-17 19:59:01 +08:00
maoxiaochuan 766b45b0e9 LoongArch: Set max_pfn with the PFN of the last page
The current max_pfn equals to zero. In this case, it causes user cannot
get some page information through /proc filesystem such as kpagecount.
The following message is displayed by stress-ng test suite with command
"stress-ng --verbose --physpage 1 -t 1".

 # stress-ng --verbose --physpage 1 -t 1
 stress-ng: error: [1691] physpage: cannot read page count for address 0x134ac000 in /proc/kpagecount, errno=22 (Invalid argument)
 stress-ng: error: [1691] physpage: cannot read page count for address 0x7ffff207c3a8 in /proc/kpagecount, errno=22 (Invalid argument)
 stress-ng: error: [1691] physpage: cannot read page count for address 0x134b0000 in /proc/kpagecount, errno=22 (Invalid argument)
 ...

After applying this patch, the kernel can pass the test.

 # stress-ng --verbose --physpage 1 -t 1
 stress-ng: debug: [1701] physpage: [1701] started (instance 0 on CPU 3)
 stress-ng: debug: [1701] physpage: [1701] exited (instance 0 on CPU 3)
 stress-ng: debug: [1700] physpage: [1701] terminated (success)

Cc: stable@vger.kernel.org  # 6.8+
Fixes: ff6c3d81f2e8 ("NUMA: optimize detection of memory with no node id assigned by firmware")
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-03-10 14:43:08 +08:00
maoxiaochuan 99f01b458e update to 19d7522c1
1.UTS_VERSION add git commit id
2.loongson_2k300_defconfig:Remove unused config
3.Code improvement
2025-03-04 11:56:15 +08:00
maoxiaochuan 9243940556 update to 4249c4342540b1
mmc:Remove unused code to avoid compile warning
loongson_2k300_defconfig:Don't builtin serio_xx
2025-02-21 10:22:11 +08:00
maoxiaochuan 1c67e978cf Update to 1ace04931c77df9
1. Add 2k300_gongkong board support
2025-02-20 10:02:07 +08:00
maoxiaochuan fc841ef35d Remove unused code 2025-02-14 23:25:39 +08:00
maoxiaochuan 7ffd18ab9d Update to 14fc3074cfe039
1. 添加带irq处理的gpio驱动
2. 龙芯2k系列添加mmc驱动支持
3. 添加看门狗驱动
4. dtb支持从command line中的board_name字段判断
5. 支持内存分布描述数据从固件传入的数据获取
6. 支持从bootcmdline获取ramdisk启动的地址和所用大小
7. 添加2k300的i2c总线驱动
8. 2k300使用新的spi 和 spi-io 驱动
9. CPU芯片温度传感器支持2k300的计算方式
10. 添加2k300的adc驱动
11. pwm: update default pwm freq to 50Mhz
12. loongson pwm 驱动支持dts使用clock-frequency形式声明频率
13. loongson pwm 确保disable时输出的电平为空闲电平
14. 2k300编译配置使能pwm leds功能
15. 2k300的gmac的phy-mode默认使用rgmii-id
16. 2k300先锋派设置YT8531的内部延迟
17. YT8531 phy 支持设置led的工作模式
18. LCD屏幕 支持cmdline的panel属性选择某一款板卡的dts配置,实现屏幕切换
19. 添加脚本用于快速选择板卡配置文件
20. 添加CAN驱动
21. 添加音频驱动
22. 优化OTG兼容性

Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
2025-02-13 16:03:32 +08:00
maoxiaochuan 8b074cffbf init src (linux-6.12.0) 2025-02-13 14:11:16 +08:00