arch/loongarch/kernel/cpu-probe.c

Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/cpu-probe.c

File Facts

System
Linux kernel
Corpus path
arch/loongarch/kernel/cpu-probe.c
Extension
.c
Size
10344 bytes
Lines
416
Domain
Architecture Layer
Bucket
arch/loongarch
Inferred role
Architecture Layer: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
/*
 * Processor capabilities determination functions.
 *
 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/ptrace.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <linux/stddef.h>
#include <linux/export.h>
#include <linux/printk.h>
#include <linux/uaccess.h>

#include <asm/cpu-features.h>
#include <asm/elf.h>
#include <asm/fpu.h>
#include <asm/loongarch.h>
#include <asm/pgtable-bits.h>
#include <asm/setup.h>

/* Hardware capabilities */
unsigned int elf_hwcap __read_mostly;
EXPORT_SYMBOL_GPL(elf_hwcap);

/*
 * Determine the FCSR mask for FPU hardware.
 */
static inline void cpu_set_fpu_fcsr_mask(struct cpuinfo_loongarch *c)
{
	unsigned long sr, mask, fcsr, fcsr0, fcsr1;

	fcsr = c->fpu_csr0;
	mask = FPU_CSR_ALL_X | FPU_CSR_ALL_E | FPU_CSR_ALL_S | FPU_CSR_RM;

	sr = read_csr_euen();
	enable_fpu();

	fcsr0 = fcsr & mask;
	write_fcsr(LOONGARCH_FCSR0, fcsr0);
	fcsr0 = read_fcsr(LOONGARCH_FCSR0);

	fcsr1 = fcsr | ~mask;
	write_fcsr(LOONGARCH_FCSR0, fcsr1);
	fcsr1 = read_fcsr(LOONGARCH_FCSR0);

	write_fcsr(LOONGARCH_FCSR0, fcsr);

	write_csr_euen(sr);

	c->fpu_mask = ~(fcsr0 ^ fcsr1) & ~mask;
}

/* simd = -1/0/128/256 */
static unsigned int simd = -1U;

static int __init cpu_setup_simd(char *str)
{
	get_option(&str, &simd);
	pr_info("Set SIMD width = %u\n", simd);

	return 0;
}

early_param("simd", cpu_setup_simd);

static int __init cpu_final_simd(void)
{
	struct cpuinfo_loongarch *c = &cpu_data[0];

	if (simd < 128) {
		c->options &= ~LOONGARCH_CPU_LSX;
		elf_hwcap &= ~HWCAP_LOONGARCH_LSX;
	}

	if (simd < 256) {
		c->options &= ~LOONGARCH_CPU_LASX;
		elf_hwcap &= ~HWCAP_LOONGARCH_LASX;
	}

	simd = 0;

	if (c->options & LOONGARCH_CPU_LSX)
		simd = 128;

	if (c->options & LOONGARCH_CPU_LASX)
		simd = 256;

Annotation

Implementation Notes