arch/riscv/kernel/kernel_mode_vector.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/kernel_mode_vector.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/kernel_mode_vector.c- Extension
.c- Size
- 6011 bytes
- Lines
- 248
- Domain
- Architecture Layer
- Bucket
- arch/riscv
- 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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compiler.hlinux/irqflags.hlinux/percpu.hlinux/preempt.hlinux/types.hasm/vector.hasm/switch_to.hasm/simd.hasm/asm-prototypes.h
Detected Declarations
function Copyrightfunction riscv_v_startfunction riscv_v_stopfunction put_cpu_vector_contextfunction get_cpu_vector_contextfunction riscv_preempt_v_set_dirtyfunction riscv_preempt_v_reset_flagsfunction riscv_v_ctx_depth_incfunction riscv_v_ctx_depth_decfunction riscv_v_ctx_get_depthfunction riscv_v_stop_kernel_contextfunction riscv_v_start_kernel_contextfunction riscv_v_context_nesting_startfunction riscv_v_context_nesting_endfunction kernel_vector_beginfunction kernel_vector_endexport kernel_vector_beginexport kernel_vector_end
Annotated Snippet
if (riscv_preempt_v_dirty(current)) {
__riscv_v_vstate_save(kvstate, kvstate->datap);
riscv_preempt_v_clear_dirty(current);
}
riscv_preempt_v_set_restore(current);
return 0;
}
/* Transfer the ownership of V from user to kernel, then save */
riscv_v_start(RISCV_PREEMPT_V | RISCV_PREEMPT_V_DIRTY);
if (__riscv_v_vstate_check(task_pt_regs(current)->status, DIRTY)) {
uvstate = ¤t->thread.vstate;
__riscv_v_vstate_save(uvstate, uvstate->datap);
}
riscv_preempt_v_clear_dirty(current);
return 0;
}
/* low-level V context handling code, called with irq disabled */
asmlinkage void riscv_v_context_nesting_start(struct pt_regs *regs)
{
int depth;
if (!riscv_preempt_v_started(current))
return;
depth = riscv_v_ctx_get_depth();
if (depth == 0 && __riscv_v_vstate_check(regs->status, DIRTY))
riscv_preempt_v_set_dirty();
riscv_v_ctx_depth_inc();
}
asmlinkage void riscv_v_context_nesting_end(struct pt_regs *regs)
{
struct __riscv_v_ext_state *vstate = ¤t->thread.kernel_vstate;
u32 depth;
WARN_ON(!irqs_disabled());
if (!riscv_preempt_v_started(current))
return;
riscv_v_ctx_depth_dec();
depth = riscv_v_ctx_get_depth();
if (depth == 0) {
if (riscv_preempt_v_restore(current)) {
__riscv_v_vstate_restore(vstate, vstate->datap);
__riscv_v_vstate_clean(regs);
riscv_preempt_v_reset_flags();
}
}
}
#else
#define riscv_v_start_kernel_context(nested) (-ENOENT)
#define riscv_v_stop_kernel_context() (-ENOENT)
#endif /* CONFIG_RISCV_ISA_V_PREEMPTIVE */
/*
* kernel_vector_begin(): obtain the CPU vector registers for use by the calling
* context
*
* Must not be called unless may_use_simd() returns true.
* Task context in the vector registers is saved back to memory as necessary.
*
* A matching call to kernel_vector_end() must be made before returning from the
* calling context.
*
* The caller may freely use the vector registers until kernel_vector_end() is
* called.
*/
void kernel_vector_begin(void)
{
bool nested = false;
if (WARN_ON(!(has_vector() || has_xtheadvector())))
return;
BUG_ON(!may_use_simd());
if (riscv_v_start_kernel_context(&nested)) {
get_cpu_vector_context();
riscv_v_vstate_save(¤t->thread.vstate, task_pt_regs(current));
}
if (!nested)
riscv_v_vstate_set_restore(current, task_pt_regs(current));
riscv_v_enable();
}
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/irqflags.h`, `linux/percpu.h`, `linux/preempt.h`, `linux/types.h`, `asm/vector.h`, `asm/switch_to.h`, `asm/simd.h`.
- Detected declarations: `function Copyright`, `function riscv_v_start`, `function riscv_v_stop`, `function put_cpu_vector_context`, `function get_cpu_vector_context`, `function riscv_preempt_v_set_dirty`, `function riscv_preempt_v_reset_flags`, `function riscv_v_ctx_depth_inc`, `function riscv_v_ctx_depth_dec`, `function riscv_v_ctx_get_depth`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.