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.

Dependency Surface

Detected Declarations

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

Implementation Notes