arch/riscv/kernel/sbi.c
Source file repositories/reference/linux-study-clean/arch/riscv/kernel/sbi.c
File Facts
- System
- Linux kernel
- Corpus path
arch/riscv/kernel/sbi.c- Extension
.c- Size
- 19144 bytes
- Lines
- 710
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/init.hlinux/mm.hlinux/pm.hlinux/reboot.hasm/sbi.hasm/smp.hasm/tlbflush.h
Detected Declarations
struct fwft_set_reqfunction __sbi_v01_cpumask_to_hartmaskfunction BITS_PER_LONGfunction sbi_console_putcharfunction sbi_console_getcharfunction sbi_shutdownfunction __sbi_set_timer_v01function __sbi_send_ipi_v01function __sbi_rfence_v01function sbi_set_power_offfunction __sbi_set_timer_v01function __sbi_send_ipi_v01function __sbi_rfence_v01function sbi_set_power_offfunction __sbi_send_ipi_v02function __sbi_rfence_v02_callfunction __sbi_rfence_v02function for_each_cpufunction cpu_sbi_fwft_setfunction sbi_fwft_setfunction sbi_fwft_set_cpumaskfunction sbi_set_timerfunction sbi_send_ipifunction sbi_remote_fence_ifunction sbi_remote_sfence_vma_asidfunction sbi_remote_hfence_gvmafunction sbi_remote_hfence_gvma_vmidfunction sbi_remote_hfence_vvmafunction sbi_remote_hfence_vvma_asidfunction sbi_srst_resetfunction sbi_srst_rebootfunction sbi_srst_power_offfunction sbi_probe_extensionfunction sbi_get_spec_versionfunction sbi_get_firmware_idfunction sbi_get_firmware_versionfunction sbi_get_mvendoridfunction sbi_get_marchidfunction sbi_get_mimpidfunction sbi_debug_console_writefunction sbi_debug_console_readfunction sbi_initexport sbi_spec_versionexport sbi_console_putcharexport sbi_console_getcharexport sbi_shutdownexport sbi_send_ipiexport sbi_remote_fence_i
Annotated Snippet
struct fwft_set_req {
u32 feature;
unsigned long value;
unsigned long flags;
atomic_t error;
};
static void cpu_sbi_fwft_set(void *arg)
{
struct fwft_set_req *req = arg;
int ret;
ret = sbi_fwft_set(req->feature, req->value, req->flags);
if (ret)
atomic_set(&req->error, ret);
}
/**
* sbi_fwft_set() - Set a feature on the local hart
* @feature: The feature ID to be set
* @value: The feature value to be set
* @flags: FWFT feature set flags
*
* Return: 0 on success, appropriate linux error code otherwise.
*/
int sbi_fwft_set(u32 feature, unsigned long value, unsigned long flags)
{
struct sbiret ret;
if (!sbi_fwft_supported)
return -EOPNOTSUPP;
ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET,
feature, value, flags, 0, 0, 0);
return sbi_err_map_linux_errno(ret.error);
}
/**
* sbi_fwft_set_cpumask() - Set a feature for the specified cpumask
* @mask: CPU mask of cpus that need the feature to be set
* @feature: The feature ID to be set
* @value: The feature value to be set
* @flags: FWFT feature set flags
*
* Return: 0 on success, appropriate linux error code otherwise.
*/
int sbi_fwft_set_cpumask(const cpumask_t *mask, u32 feature,
unsigned long value, unsigned long flags)
{
struct fwft_set_req req = {
.feature = feature,
.value = value,
.flags = flags,
.error = ATOMIC_INIT(0),
};
if (!sbi_fwft_supported)
return -EOPNOTSUPP;
if (feature & SBI_FWFT_GLOBAL_FEATURE_BIT)
return -EINVAL;
on_each_cpu_mask(mask, cpu_sbi_fwft_set, &req, 1);
return atomic_read(&req.error);
}
/**
* sbi_set_timer() - Program the timer for next timer event.
* @stime_value: The value after which next timer event should fire.
*
* Return: None.
*/
void sbi_set_timer(uint64_t stime_value)
{
__sbi_set_timer(stime_value);
}
/**
* sbi_send_ipi() - Send an IPI to any hart.
* @cpu: Logical id of the target CPU.
*/
void sbi_send_ipi(unsigned int cpu)
{
__sbi_send_ipi(cpu);
}
EXPORT_SYMBOL(sbi_send_ipi);
/**
Annotation
- Immediate include surface: `linux/bits.h`, `linux/init.h`, `linux/mm.h`, `linux/pm.h`, `linux/reboot.h`, `asm/sbi.h`, `asm/smp.h`, `asm/tlbflush.h`.
- Detected declarations: `struct fwft_set_req`, `function __sbi_v01_cpumask_to_hartmask`, `function BITS_PER_LONG`, `function sbi_console_putchar`, `function sbi_console_getchar`, `function sbi_shutdown`, `function __sbi_set_timer_v01`, `function __sbi_send_ipi_v01`, `function __sbi_rfence_v01`, `function sbi_set_power_off`.
- Atlas domain: Architecture Layer / arch/riscv.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.