arch/loongarch/mm/tlbex.S

Source file repositories/reference/linux-study-clean/arch/loongarch/mm/tlbex.S

File Facts

System
Linux kernel
Corpus path
arch/loongarch/mm/tlbex.S
Extension
.S
Size
15174 bytes
Lines
647
Domain
Architecture Layer
Bucket
arch/loongarch
Inferred role
Architecture Layer: arch/loongarch
Status
atlas-only

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

#include <asm/asm.h>
#include <asm/loongarch.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#include <asm/regdef.h>
#include <asm/stackframe.h>

#define INVTLB_ADDR_GFALSE_AND_ASID	5

#define PTRS_PER_PGD_BITS	(PAGE_SHIFT - PTRLOG)
#define PTRS_PER_PUD_BITS	(PAGE_SHIFT - PTRLOG)
#define PTRS_PER_PMD_BITS	(PAGE_SHIFT - PTRLOG)
#define PTRS_PER_PTE_BITS	(PAGE_SHIFT - PTRLOG)

#ifdef CONFIG_32BIT
#define PTE_LL	ll.w
#define PTE_SC	sc.w
#else
#define PTE_LL	ll.d
#define PTE_SC	sc.d
#endif

	.macro tlb_do_page_fault, write
	SYM_CODE_START(tlb_do_page_fault_\write)
	UNWIND_HINT_UNDEFINED
	SAVE_ALL
	csrrd		a2, LOONGARCH_CSR_BADV
	move		a0, sp
	REG_S		a2, sp, PT_BVADDR
	li.w		a1, \write
	bl		do_page_fault
	RESTORE_ALL_AND_RET
	SYM_CODE_END(tlb_do_page_fault_\write)
	.endm

	tlb_do_page_fault 0
	tlb_do_page_fault 1

SYM_CODE_START(handle_tlb_protect)
	UNWIND_HINT_UNDEFINED
	BACKUP_T0T1
	SAVE_ALL
	move		a0, sp
	move		a1, zero
	csrrd		a2, LOONGARCH_CSR_BADV
	REG_S		a2, sp, PT_BVADDR
	la_abs		t0, do_page_fault
	jirl		ra, t0, 0
	RESTORE_ALL_AND_RET
SYM_CODE_END(handle_tlb_protect)

SYM_CODE_START(handle_tlb_load)
	UNWIND_HINT_UNDEFINED
	csrwr		t0, EXCEPTION_KS0
	csrwr		t1, EXCEPTION_KS1
	csrwr		ra, EXCEPTION_KS2

	/*
	 * The vmalloc handling is not in the hotpath.
	 */
	csrrd		t0, LOONGARCH_CSR_BADV
	bltz		t0, vmalloc_load
	csrrd		t1, LOONGARCH_CSR_PGDL

vmalloc_done_load:
	/* Get PGD offset in bytes */
#ifdef CONFIG_32BIT
	PTR_BSTRPICK	ra, t0, 31, PGDIR_SHIFT
#else
	PTR_BSTRPICK	ra, t0, PTRS_PER_PGD_BITS + PGDIR_SHIFT - 1, PGDIR_SHIFT

Annotation

Implementation Notes