arch/x86/kernel/cpu/mtrr/if.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/cpu/mtrr/if.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/cpu/mtrr/if.c- Extension
.c- Size
- 9598 bytes
- Lines
- 424
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- 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/capability.hlinux/seq_file.hlinux/uaccess.hlinux/proc_fs.hlinux/ctype.hlinux/string.hlinux/slab.hlinux/init.hasm/mtrr.hmtrr.h
Detected Declarations
function mtrr_file_addfunction mtrr_file_delfunction mtrr_writefunction mtrr_ioctlfunction mtrr_closefunction mtrr_seq_showfunction mtrr_openfunction mtrr_if_init
Annotated Snippet
while (fcount[i] > 0) {
mtrr_del(i, 0, 0);
--fcount[i];
}
}
kfree(fcount);
FILE_FCOUNT(file) = NULL;
}
return single_release(ino, file);
}
static int mtrr_seq_show(struct seq_file *seq, void *offset)
{
char factor;
int i, max;
mtrr_type type;
unsigned long base, size;
max = num_var_ranges;
for (i = 0; i < max; i++) {
mtrr_if->get(i, &base, &size, &type);
if (size == 0) {
mtrr_usage_table[i] = 0;
continue;
}
if (size < (0x100000 >> PAGE_SHIFT)) {
/* less than 1MB */
factor = 'K';
size <<= PAGE_SHIFT - 10;
} else {
factor = 'M';
size >>= 20 - PAGE_SHIFT;
}
/* Base can be > 32bit */
seq_printf(seq, "reg%02i: base=0x%06lx000 (%5luMB), size=%5lu%cB, count=%d: %s\n",
i, base, base >> (20 - PAGE_SHIFT),
size, factor,
mtrr_usage_table[i], mtrr_attrib_to_str(type));
}
return 0;
}
static int mtrr_open(struct inode *inode, struct file *file)
{
if (!mtrr_if)
return -EIO;
if (!mtrr_if->get)
return -ENXIO;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
return single_open(file, mtrr_seq_show, NULL);
}
static const struct proc_ops mtrr_proc_ops = {
.proc_open = mtrr_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_write = mtrr_write,
.proc_ioctl = mtrr_ioctl,
#ifdef CONFIG_COMPAT
.proc_compat_ioctl = mtrr_ioctl,
#endif
.proc_release = mtrr_close,
};
static int __init mtrr_if_init(void)
{
struct cpuinfo_x86 *c = &boot_cpu_data;
if ((!cpu_has(c, X86_FEATURE_MTRR)) &&
(!cpu_has(c, X86_FEATURE_K6_MTRR)) &&
(!cpu_has(c, X86_FEATURE_CYRIX_ARR)) &&
(!cpu_has(c, X86_FEATURE_CENTAUR_MCR)))
return -ENODEV;
proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_proc_ops);
return 0;
}
arch_initcall(mtrr_if_init);
#endif /* CONFIG_PROC_FS */
Annotation
- Immediate include surface: `linux/capability.h`, `linux/seq_file.h`, `linux/uaccess.h`, `linux/proc_fs.h`, `linux/ctype.h`, `linux/string.h`, `linux/slab.h`, `linux/init.h`.
- Detected declarations: `function mtrr_file_add`, `function mtrr_file_del`, `function mtrr_write`, `function mtrr_ioctl`, `function mtrr_close`, `function mtrr_seq_show`, `function mtrr_open`, `function mtrr_if_init`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.