arch/loongarch/kernel/kdebugfs.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/kdebugfs.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/kdebugfs.c- Extension
.c- Size
- 4032 bytes
- Lines
- 169
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/export.hlinux/debugfs.hlinux/kstrtox.hasm/loongarch.h
Detected Declarations
function set_sfb_statefunction sfb_readfunction sfb_writefunction set_tso_statefunction tso_readfunction tso_writefunction arch_kdebugfs_initexport arch_debugfs_dir
Annotated Snippet
static const struct file_operations sfb_fops = {
.read = sfb_read,
.write = sfb_write,
.open = simple_open,
.llseek = default_llseek
};
#define LDSTORDER_NLD_NST 0x0 /* 000 = No Load No Store */
#define LDSTORDER_ALD_NST 0x1 /* 001 = All Load No Store */
#define LDSTORDER_SLD_NST 0x3 /* 011 = Same Load No Store */
#define LDSTORDER_NLD_AST 0x4 /* 100 = No Load All Store */
#define LDSTORDER_ALD_AST 0x5 /* 101 = All Load All Store */
#define LDSTORDER_SLD_AST 0x7 /* 111 = Same Load All Store */
static char *tso_hints[] = {
"No Load No Store",
"All Load No Store",
"Invalid Config",
"Same Load No Store",
"No Load All Store",
"All Load All Store",
"Invalid Config",
"Same Load All Store"
};
static void set_tso_state(void *info)
{
int val = *(int *)info << CSR_LDSTORDER_SHIFT;
csr_xchg32(val, CSR_LDSTORDER_MASK, LOONGARCH_CSR_IMPCTL1);
}
static ssize_t tso_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
int s, state;
char str[240];
state = (csr_read32(LOONGARCH_CSR_IMPCTL1) & CSR_LDSTORDER_MASK) >> CSR_LDSTORDER_SHIFT;
s = snprintf(str, sizeof(str), "Boot State: %d (%s)\n"
"Current State: %d (%s)\n\n"
"Available States:\n"
"0 (%s)\t" "1 (%s)\t" "3 (%s)\n"
"4 (%s)\t" "5 (%s)\t" "7 (%s)\n",
tso_state, tso_hints[tso_state], state, tso_hints[state],
tso_hints[0], tso_hints[1], tso_hints[3], tso_hints[4], tso_hints[5], tso_hints[7]);
if (*ppos >= s)
return 0;
s -= *ppos;
s = min_t(u32, s, count);
if (copy_to_user(buf, &str[*ppos], s))
return -EFAULT;
*ppos += s;
return s;
}
static ssize_t tso_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int state;
if (kstrtoint_from_user(buf, count, 10, &state))
return -EFAULT;
switch (state) {
case 0: case 1: case 3:
case 4: case 5: case 7:
on_each_cpu(set_tso_state, &state, 1);
break;
default:
return -EINVAL;
}
return count;
}
static const struct file_operations tso_fops = {
.read = tso_read,
.write = tso_write,
.open = simple_open,
.llseek = default_llseek
};
static int __init arch_kdebugfs_init(void)
{
unsigned int config = read_cpucfg(LOONGARCH_CPUCFG3);
Annotation
- Immediate include surface: `linux/init.h`, `linux/export.h`, `linux/debugfs.h`, `linux/kstrtox.h`, `asm/loongarch.h`.
- Detected declarations: `function set_sfb_state`, `function sfb_read`, `function sfb_write`, `function set_tso_state`, `function tso_read`, `function tso_write`, `function arch_kdebugfs_init`, `export arch_debugfs_dir`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.