Skip to contentSkip to conversation

acpi ec_sys: Export fields of all regions from the EC to debugfs readable

PATCH In review Thomas Renninger 2 participants 5 messages Jul 30, 2010 – Aug 4, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi ec_sys: Export fields of all regions from the EC to debugfs readable

From the /sys/kernel/debug/ec/*/io file userspace can read and write EC byte wise.
This patch introduces /sys/kernel/debug/ec/*/fields/* which exports all fields of an Embedded Controller.
This has several advantages:
- Shows defined EC registers (not as dangerous as accessing arbitrary ones)
- Reads are done through the ACPI layer and may get accessed differently than reading blank bytes (burst mode).
- People do not have to read the DSDT.dsl to map register names to EC fields

The patch has two unresolved isses:
- Unfortunately write access does not work for fields, acpica is missing this capablity.
- All EC region fields (also SystemMemory, IO, etc.) are shown which may not result in EC access. Ideally only the EC region fields are shown. -> again acpica does not let us differ this.

---
 Documentation/ABI/testing/debugfs-ec |   33 ++++++++-
 drivers/acpi/ec_sys.c                |  141 +++++++++++++++++++++++++++++++--
 drivers/acpi/internal.h              |    3 +
 3 files changed, 166 insertions(+), 11 deletions(-)
Documentation/ABI/testing/debugfs-ec +31 -2
index 6546115..799ffd5 100644
@@ -1,14 +1,18 @@
-What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io}
+What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io,field/*}
 Date:		July 2010
 Contact:	Thomas Renninger <[email protected]>
 Description:
 
+files: gpe, use_global_lock
+---------------------------
 General information like which GPE is assigned to the EC and whether
 the global lock should get used.
-Knowing the EC GPE one can watch the amount of HW events related to
+Knowing the EC GPE, one can watch the amount of HW events related to
 the EC here (XY -> GPE number from /sys/kernel/debug/ec/*/gpe):
 /sys/firmware/acpi/interrupts/gpeXY
 
+file: io
+--------
 The io file is binary and a userspace tool located here:
 ftp://ftp.suse.com/pub/people/trenn/sources/ec/
 should get used to read out the 256 Embedded Controller registers
@@ -18,3 +22,28 @@ CAUTION: Do not write to the Embedded Controller if you don't know
 what you are doing! Rebooting afterwards also is a good idea.
 This can influence the way your machine is cooled and fans may
 not get switched on again after you did a wrong write.
+
+files: fields/*
+---------------
+
+Shows EC register fields as defined in the EmbeddedController object of the DSDT
+Reads are done through the ACPI layer and may get accessed differently than
+reading blank bytes through the io file (e.g. with burst mode enabled).
+People can read the DSDT.dsl to map register names to EC fields, but with the
+names displayed this should not be necessary anymore.
+
+Typical EC region definition:
+                    OperationRegion (ECRM, EmbeddedControl, 0x00, 0xFF)
+                    Field (ECRM, ByteAcc, NoLock, Preserve)
+                    {
+                        S0PW,   32,
+                        S0CT,   32,
+                                Offset (0x80),
+                        FNSW,   1,
+                        ...
+                    }
+
+Reading /sys/../ec/*/fields/SOPW will read the first 4 bytes of the EC and
+display it.
+Reading ../FNSW will read one byte at offset 0x80 and mask out 7 bits and
+return a bit value.
drivers/acpi/ec_sys.c +132 -9

184 lines not on this page · raw message

drivers/acpi/internal.h +3 -0
index 8ae2726..14d1bab 100644
@@ -64,6 +64,9 @@ struct acpi_ec {
 	struct transaction *curr;
 	spinlock_t curr_lock;
 	struct sys_device sysdev;
+#if defined CONFIG_ACPI_EC_DEBUGFS || defined CONFIG_ACPI_EC_DEBUGFS_MODULE
+	struct dentry *field_dir;
+#endif
 };
 
 extern struct acpi_ec *first_ec;
Signature · 1 line
1.6.3
#1 lore raw

drivers/acpi/ec_sys.c MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may " · line 50

Quoted 9 lines · On Fri, 30 Jul 2010 17:47:04 +0200 Thomas Renninger <[email protected]> wrote:
drivers/acpi/ec_sys.c +6 -1
-static int acpi_ec_open_io(struct inode *i, struct file *f)
+static int acpi_ec_open(struct inode *i, struct file *f)
 {
 	f->private_data = i->i_private;
+	if (mutex_trylock(&ec_fs_lock))
+		return 0;
+	else
+		return -EBUSY;
+}

Well that sucks - a userspace interface which is _designed_ to randomly and rarely fail?

An application tries to open the thing and gets -EBUSY, what's it supposed to do? Sleep and try again? Crash and dump core?

Also the code's uncommented, so the reader has no clue why a trylock was used. There are very few circumstances where any trylock can acceptably be left uncommented.

afacit we can use mutex_lock() here and the implementation would be heaps better.

#2 lore raw
Quoted 16 lines · Andrew Morton

On Fri, 30 Jul 2010 17:47:04 +0200

drivers/acpi/ec_sys.c MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may " · line 50

Quoted 9 lines · Thomas Renninger
drivers/acpi/ec_sys.c +6 -1
-static int acpi_ec_open_io(struct inode *i, struct file *f)
+static int acpi_ec_open(struct inode *i, struct file *f)
 {
 	f->private_data = i->i_private;
+	if (mutex_trylock(&ec_fs_lock))
+		return 0;
+	else
+		return -EBUSY;
+}

Well that sucks - a userspace interface which is _designed_ to randomly and rarely fail?

Quoted 2 lines

An application tries to open the thing and gets -EBUSY, what's it supposed to do? Sleep and try again? Crash and dump core?

This is a debug interface nobody should rely on or use in real applications. There should only exist one app which dumps the EC or write modify single bytes/fields and this one shouldn't be called twice in parallel. My idea was: if someone accesses this file simultaneously, something is wrong in userspace and it's even safer...

On the other hand side, the ec.c code should already parallelize register accesses and the whole lock should not be needed at all.
Someone might want to check whether the locks
in ec.c really do what they should and could use this as a stress test if the lock is simply removed.

Quoted 1 line

Also the code's uncommented,

/* Only allow one user to access any EC io/field file at a time */ static DEFINE_MUTEX(ec_fs_lock);

Quoted 6 lines

so the reader has no clue why a trylock
was used. There are very few circumstances where any trylock can acceptably be left uncommented.

afacit we can use mutex_lock() here and the implementation would be heaps better.

Not sure it really matters. But removing it altogether might be even better. Waiting for some more comments...

Thomas

#3 lore raw

PATCH 1/1 acpi ec_sys: Export fields of all regions from the EC to debugfs readable (v2)

In reply to Andrew Morton
Quoted 1 line

From the /sys/kernel/debug/ec/*/io file userspace can read and write EC byte

wise.
This patch introduces /sys/kernel/debug/ec/*/fields/* which exports all fields of an Embedded Controller.
This has several advantages:
- Shows defined EC registers (not as dangerous as accessing arbitrary ones)
- Reads are done through the ACPI layer and may get accessed differently than reading blank bytes (burst mode).
- People do not have to read the DSDT.dsl to map register names to EC fields

The patch has two unresolved isses:
- Unfortunately write access does not work for fields, acpica is missing this capablity.
- All EC region fields (also SystemMemory, IO, etc.) are shown which may not result in EC access. Ideally only the EC region fields are shown. -> again acpica does not let us differ this.

Recent changes (v2):
- Return -EPERM if process has not CAP_SYS_RAWIO capability
- Do allow parallel access to EC files for stress testing ec.c driver (instead of returning -EBUSY which was brought up akpm)
- Minor change in Kconfig description
Do not mention that EC is only accessed via ACPI interpreted code which is not true for some native laptop driver hacks.
- Fix write_support file creation: mode and .write callback function, both must be set (or removed) appropriately.

---
 Documentation/ABI/testing/debugfs-ec |   38 +++++++++-
 drivers/acpi/Kconfig                 |    6 +-
 drivers/acpi/ec_sys.c                |  131 +++++++++++++++++++++++++++++++---
 drivers/acpi/internal.h              |    3 +
 4 files changed, 163 insertions(+), 15 deletions(-)
Documentation/ABI/testing/debugfs-ec +36 -2
index 6546115..6bd5222 100644
@@ -1,14 +1,21 @@
-What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io}
+What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io,field/*}
 Date:		July 2010
 Contact:	Thomas Renninger <[email protected]>
 Description:
 
+files: gpe, use_global_lock
+---------------------------
+
 General information like which GPE is assigned to the EC and whether
 the global lock should get used.
-Knowing the EC GPE one can watch the amount of HW events related to
+Knowing the EC GPE, one can watch the amount of HW events related to
 the EC here (XY -> GPE number from /sys/kernel/debug/ec/*/gpe):
 /sys/firmware/acpi/interrupts/gpeXY
 
+
+file: io
+--------
+
 The io file is binary and a userspace tool located here:
 ftp://ftp.suse.com/pub/people/trenn/sources/ec/
 should get used to read out the 256 Embedded Controller registers
@@ -18,3 +25,30 @@ CAUTION: Do not write to the Embedded Controller if you don't know
 what you are doing! Rebooting afterwards also is a good idea.
 This can influence the way your machine is cooled and fans may
 not get switched on again after you did a wrong write.
+
+
+files: fields/*
+---------------
+
+Shows EC register fields as defined in the EmbeddedController object of the
+DSDT.
+Reads are done through the ACPI layer and may get accessed differently than
+reading blank bytes through the io file (e.g. with burst mode enabled).
+People can read the DSDT.dsl to map register names to EC fields, but with the
+names displayed this should not be necessary anymore.
+
+Typical EC region definition:
+                    OperationRegion (ECRM, EmbeddedControl, 0x00, 0xFF)
+                    Field (ECRM, ByteAcc, NoLock, Preserve)
+                    {
+                        S0PW,   32,
+                        S0CT,   32,
+                                Offset (0x80),
+                        FNSW,   1,
+                        ...
+                    }
+
+Reading /sys/../ec/*/fields/SOPW will read the first 4 bytes of the EC and
+display it.
+Reading /sys/../ec/*/fields/FNSW will read one byte at offset 0x80 and mask out
+ 7 bits and return a bit value (FNSW is defined as a one bit field).
drivers/acpi/Kconfig +3 -3
index 08e0140..490eeef 100644
@@ -116,9 +116,9 @@ config ACPI_EC_DEBUGFS
 	  some seconds.
 	  An Embedded Controller typically is available on laptops and reads
 	  sensor values like battery state and temperature.
-	  The kernel accesses the EC through ACPI parsed code provided by BIOS
-	  tables. This option allows to access the EC directly without ACPI
-	  code being involved.
+	  This option allows to access the EC directly without ACPI code being
+	  involved (io file) or by calling the ACPI interpreter and access EC
+	  ACPI field objects (field files, read-only).
 	  Thus this option is a debug option that helps to write ACPI drivers
 	  and can be used to identify ACPI code or EC firmware bugs.
 
drivers/acpi/ec_sys.c +121 -10

173 lines not on this page · raw message

drivers/acpi/internal.h +3 -0
index 8ae2726..14d1bab 100644
@@ -64,6 +64,9 @@ struct acpi_ec {
 	struct transaction *curr;
 	spinlock_t curr_lock;
 	struct sys_device sysdev;
+#if defined CONFIG_ACPI_EC_DEBUGFS || defined CONFIG_ACPI_EC_DEBUGFS_MODULE
+	struct dentry *field_dir;
+#endif
 };
 
 extern struct acpi_ec *first_ec;
Signature · 1 line
1.6.3
#4 lore raw

PATCH 1/1 acpi ec_sys: Export fields of all regions from the EC to debugfs readable (v3)

From the /sys/kernel/debug/ec/*/io file userspace can read and write EC byte wise.
This patch introduces /sys/kernel/debug/ec/*/fields/* which exports all fields of an Embedded Controller.
This has several advantages:
- Shows defined EC registers (not as dangerous as accessing arbitrary ones)
- Reads are done through the ACPI layer and may get accessed differently than reading blank bytes (burst mode).
- People do not have to read the DSDT.dsl to map register names to EC fields

The patch has two unresolved isses:
- Unfortunately write access does not work for fields, acpica is missing this capablity.
- All EC region fields (also SystemMemory, IO, etc.) are shown which may not result in EC access. Ideally only the EC region fields are shown. -> again acpica does not let us differ this.

Recent changes (v2):
- Return -EPERM if process has not CAP_SYS_RAWIO capability
- Do allow parallel access to EC files for stress testing ec.c driver (instead of returning -EBUSY which was brought up akpm)
- Minor change in Kconfig description
Do not mention that EC is only accessed via ACPI interpreted code which is not true for some native laptop driver hacks.
- Fix write_support file creation: mode and .write callback function, both must be set (or removed) appropriately.

(v3)
- Fix: ‘acpi_ec_open’ warning: control reaches end of non-void function compiler warning

---
 Documentation/ABI/testing/debugfs-ec |   38 +++++++++-
 drivers/acpi/Kconfig                 |    6 +-
 drivers/acpi/ec_sys.c                |  133 +++++++++++++++++++++++++++++++---
 drivers/acpi/internal.h              |    3 +
 4 files changed, 165 insertions(+), 15 deletions(-)
Documentation/ABI/testing/debugfs-ec +36 -2
index 6546115..6bd5222 100644
@@ -1,14 +1,21 @@
-What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io}
+What:		/sys/kernel/debug/ec/*/{gpe,use_global_lock,io,field/*}
 Date:		July 2010
 Contact:	Thomas Renninger <[email protected]>
 Description:
 
+files: gpe, use_global_lock
+---------------------------
+
 General information like which GPE is assigned to the EC and whether
 the global lock should get used.
-Knowing the EC GPE one can watch the amount of HW events related to
+Knowing the EC GPE, one can watch the amount of HW events related to
 the EC here (XY -> GPE number from /sys/kernel/debug/ec/*/gpe):
 /sys/firmware/acpi/interrupts/gpeXY
 
+
+file: io
+--------
+
 The io file is binary and a userspace tool located here:
 ftp://ftp.suse.com/pub/people/trenn/sources/ec/
 should get used to read out the 256 Embedded Controller registers
@@ -18,3 +25,30 @@ CAUTION: Do not write to the Embedded Controller if you don't know
 what you are doing! Rebooting afterwards also is a good idea.
 This can influence the way your machine is cooled and fans may
 not get switched on again after you did a wrong write.
+
+
+files: fields/*
+---------------
+
+Shows EC register fields as defined in the EmbeddedController object of the
+DSDT.
+Reads are done through the ACPI layer and may get accessed differently than
+reading blank bytes through the io file (e.g. with burst mode enabled).
+People can read the DSDT.dsl to map register names to EC fields, but with the
+names displayed this should not be necessary anymore.
+
+Typical EC region definition:
+                    OperationRegion (ECRM, EmbeddedControl, 0x00, 0xFF)
+                    Field (ECRM, ByteAcc, NoLock, Preserve)
+                    {
+                        S0PW,   32,
+                        S0CT,   32,
+                                Offset (0x80),
+                        FNSW,   1,
+                        ...
+                    }
+
+Reading /sys/../ec/*/fields/SOPW will read the first 4 bytes of the EC and
+display it.
+Reading /sys/../ec/*/fields/FNSW will read one byte at offset 0x80 and mask out
+ 7 bits and return a bit value (FNSW is defined as a one bit field).
drivers/acpi/Kconfig +3 -3
index 08e0140..490eeef 100644
@@ -116,9 +116,9 @@ config ACPI_EC_DEBUGFS
 	  some seconds.
 	  An Embedded Controller typically is available on laptops and reads
 	  sensor values like battery state and temperature.
-	  The kernel accesses the EC through ACPI parsed code provided by BIOS
-	  tables. This option allows to access the EC directly without ACPI
-	  code being involved.
+	  This option allows to access the EC directly without ACPI code being
+	  involved (io file) or by calling the ACPI interpreter and access EC
+	  ACPI field objects (field files, read-only).
 	  Thus this option is a debug option that helps to write ACPI drivers
 	  and can be used to identify ACPI code or EC firmware bugs.
 
drivers/acpi/ec_sys.c +123 -10

175 lines not on this page · raw message

drivers/acpi/internal.h +3 -0
index 8ae2726..14d1bab 100644
@@ -64,6 +64,9 @@ struct acpi_ec {
 	struct transaction *curr;
 	spinlock_t curr_lock;
 	struct sys_device sysdev;
+#if defined CONFIG_ACPI_EC_DEBUGFS || defined CONFIG_ACPI_EC_DEBUGFS_MODULE
+	struct dentry *field_dir;
+#endif
 };
 
 extern struct acpi_ec *first_ec;
Signature · 6 lines
1.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html