2 * linux/arch/arm/kernel/sysfs.c
4 * Copyright (C) 2008 Mans Rullgard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/cpu.h>
13 #include <linux/sysdev.h>
17 #define SETBITS(val, bits, new) \
23 #define SHOW_REG(name, opc1, crn, crm, opc2) \
24 static ssize_t name##_show(struct sys_device *dev, \
25 struct sysdev_attribute *attr, \
29 asm ("mrc p15,"#opc1", %0,"#crn","#crm","#opc2 : "=r"(val)); \
30 return snprintf(buf, PAGE_SIZE, "%08x\n", val); \
33 #define STORE_REG(name, opc1, crn, crm, opc2, bits) \
34 static ssize_t name##_store(struct sys_device *dev, \
35 struct sysdev_attribute *attr, \
36 const char *buf, size_t size) \
39 unsigned new = simple_strtoul(buf, &end, 0); \
45 asm ("mrc p15,"#opc1", %0,"#crn","#crm","#opc2 : "=r"(val)); \
46 SETBITS(val, bits, new); \
47 asm ("mcr p15,"#opc1", %0,"#crn","#crm","#opc2 :: "r"(val)); \
52 #define RD_REG(name, opc1, crn, crm, opc2) \
53 SHOW_REG(name, opc1, crn, crm, opc2) \
54 static SYSDEV_ATTR(name, S_IRUGO|S_IWUSR, name##_show, NULL)
56 #define RDWR_REG(name, opc1, crn, crm, opc2, bits) \
57 SHOW_REG(name, opc1, crn, crm, opc2) \
58 STORE_REG(name, opc1, crn, crm, opc2, bits) \
59 static SYSDEV_ATTR(name, S_IRUGO|S_IWUSR, name##_show, name##_store)
61 RDWR_REG(control, 0, c1, c0, 0, 0x802);
63 SHOW_REG(aux_ctl, 0, c1, c0, 1)
65 #ifdef CONFIG_ARCH_OMAP34XX
66 static ssize_t aux_ctl_store(struct sys_device *dev,
67 struct sysdev_attribute *attr,
68 const char *buf, size_t size)
71 unsigned new = simple_strtoul(buf, &end, 0);
77 asm ("mrc p15, 0, %0, c1, c0, 1" : "=r"(val));
78 SETBITS(val, 0xff8, new);
80 asm ("mov r0, %0 \n\t"
83 :: "r"(val) : "r0", "r12");
87 #define AUX_WR S_IWUSR
89 #define aux_ctl_store NULL
93 static SYSDEV_ATTR(aux_control, S_IRUGO|AUX_WR, aux_ctl_show, aux_ctl_store);
95 SHOW_REG(l2_aux_ctl, 1, c9, c0, 2)
97 #ifdef CONFIG_ARCH_OMAP34XX
98 static ssize_t l2_aux_ctl_store(struct sys_device *dev,
99 struct sysdev_attribute *attr,
100 const char *buf, size_t size)
103 unsigned new = simple_strtoul(buf, &end, 0);
109 asm ("mrc p15, 1, %0, c9, c0, 2" : "=r"(val));
110 SETBITS(val, 0xbc00000, new);
111 asm ("mov r0, %0 \n\t"
114 :: "r"(val) : "r0", "r12");
118 #define L2AUX_WR S_IWUSR
120 #define l2_aux_ctl_store NULL
124 static SYSDEV_ATTR(l2_aux_control, S_IRUGO|L2AUX_WR,
125 l2_aux_ctl_show, l2_aux_ctl_store);
127 RDWR_REG(pmon_pmnc, 0, c9, c12, 0, 0x3f)
128 RDWR_REG(pmon_cntens, 0, c9, c12, 1, 0x8000000f)
129 RDWR_REG(pmon_cntenc, 0, c9, c12, 2, 0x8000000f)
130 RDWR_REG(pmon_ccnt, 0, c9, c13, 0, 0xffffffff)
131 RDWR_REG(pmon_useren, 0, c9, c14, 0, 1)
133 #define REG_ATTR(sysdev, name) \
135 int err = sysfs_create_file(&sysdev->kobj, &name.attr); \
139 static int __init cpu_sysfs_init(void)
141 struct sys_device *sysdev;
144 for_each_possible_cpu(cpu) {
145 sysdev = get_cpu_sysdev(cpu);
146 REG_ATTR(sysdev, attr_control);
147 REG_ATTR(sysdev, attr_aux_control);
148 REG_ATTR(sysdev, attr_l2_aux_control);
149 REG_ATTR(sysdev, attr_pmon_pmnc);
150 REG_ATTR(sysdev, attr_pmon_cntens);
151 REG_ATTR(sysdev, attr_pmon_cntenc);
152 REG_ATTR(sysdev, attr_pmon_ccnt);
153 REG_ATTR(sysdev, attr_pmon_useren);
158 device_initcall(cpu_sysfs_init);