Skip to contentSkip to conversation

MIPS: Make CP0 config registers readable via sysfs.

PATCH Superseded Steven J. Hill 2 participants 2 messages Dec 13, 2012 MIPS

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 MIPS: Make CP0 config registers readable via sysfs.

From: "Steven J. Hill" <[email protected]>

Allow reading of CP0 config registers via sysfs for each core in the system. The registers will show up in sysfs at the path:

/sys/devices/system/cpu/cpuX/configX

Only CP0 config registers 0 through 7 are currently supported.

---
 arch/mips/kernel/Makefile |    1 +
 arch/mips/kernel/sysfs.c  |   68 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 arch/mips/kernel/sysfs.c
arch/mips/kernel/Makefile +1 -0
index cc5eec6..0c3eb97 100644
@@ -97,6 +97,7 @@ obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o
 obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event_mipsxx.o
 
 obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o
+obj-y				+= sysfs.o
 
 ifeq ($(CONFIG_CPU_MIPS32), y)
 #
arch/mips/kernel/sysfs.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.7.9.5
Acked-by on v3 1/1
#1 lore raw
Quoted 2 lines · Steven J. Hill

From: "Steven J. Hill" <[email protected]>

Thanks Steven,

Quoted 6 lines

Allow reading of CP0 config registers via sysfs for each core in the system. The registers will show up in sysfs at the path:

/sys/devices/system/cpu/cpuX/configX

Only CP0 config registers 0 through 7 are currently supported.

That's not really a limitation, as those are the only ones that exist.

Quoted 2 lines

One small change below, but otherwise,

Quoted 40 lines
---
  arch/mips/kernel/Makefile |    1 +
  arch/mips/kernel/sysfs.c  |   68 +++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 69 insertions(+)

create mode 100644 arch/mips/kernel/sysfs.c

arch/mips/kernel/Makefile +1 -0
index cc5eec6..0c3eb97 100644
@@ -97,6 +97,7 @@ obj-$(CONFIG_PERF_EVENTS)	+= perf_event.o
  obj-$(CONFIG_HW_PERF_EVENTS)	+= perf_event_mipsxx.o
 
  obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o
+obj-y				+= sysfs.o
 
  ifeq ($(CONFIG_CPU_MIPS32), y)
  #
arch/mips/kernel/sysfs.c new file +16 -0
new file mode 100644
index 0000000..4f26349
@@ -0,0 +1,68 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2012 MIPS Technologies, Inc.  All rights reserved.
+ */
+#include <linux/init.h>
+#include <linux/string.h>
+#include <linux/cpu.h>
+#include <linux/percpu.h>
+
+#include <asm/page.h>
+
+/* Convenience macro */
+#define read_c0_config0()	read_c0_config()

arch/mips/kernel/sysfs.c line 26

Quoted 10 lines
arch/mips/kernel/sysfs.c new file +10 -0
+
+#define __BUILD_CP0_SYSFS(reg)					\
+static ssize_t show_config##reg(struct device *dev,		\
+		struct device_attribute *attr, char *buf)	\
+{								\
+	int n = snprintf(buf, PAGE_SIZE-2, "%x\n",		\
+		read_c0_config##reg());				\
+	return n;						\
+}								\
+static DEVICE_ATTR(config##reg, 0444, show_config##reg, NULL);

s/0444/S_IRUGO/

[...]

arch/mips/kernel/sysfs.c line 68

Quoted 2 lines
arch/mips/kernel/sysfs.c new file +1 -0
+late_initcall(mips_sysfs_registers);

Why late_initcall? I don't really have an objection, but unless there is a good reason, why not device_initcall?