Export valuable System-on-Chip information to user-space via sysfs
cover Export valuable System-on-Chip information to user-space via sysfs
This patch-set is based on Maxime Coquelin's <[email protected]> previous attempts. All advice has been taken and this is the resultant work. The main points taken into consideration are:
* Ability to support multiple SoCs on any one device
* Each SoC is registered as a _real_ device
Documentation/ABI/testing/sysfs-devices-soc | 16 +++++
arch/arm/mach-ux500/Kconfig | 1 + arch/arm/mach-ux500/id.c | 96 +++++++++++++++++++++++++++ drivers/base/Kconfig | 3 + drivers/base/Makefile | 1 + drivers/base/soc.c | 96 +++++++++++++++++++++++++++ include/linux/sys_soc.h | 29 ++++++++ 7 files changed, 242 insertions(+), 0 deletions(-)
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
--- drivers/base/Kconfig | 3 + drivers/base/Makefile | 1 + drivers/base/soc.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sys_soc.h | 29 +++++++++++ 4 files changed, 160 insertions(+), 0 deletions(-) create mode 100644 drivers/base/soc.c create mode 100644 include/linux/sys_soc.h
drivers/base/Kconfig +3 -0
@@ -168,6 +168,9 @@ config SYS_HYPERVISOR bool default n +config SYS_SOC + bool + config ARCH_NO_SYSDEV_OPS bool ---help---
drivers/base/Makefile +1 -0
@@ -18,6 +18,7 @@ ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o endif obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o +obj-$(CONFIG_SYS_SOC) += soc.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
drivers/base/soc.c new file +127 -0
127 lines not on this page · raw message
include/linux/sys_soc.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) ST-Ericsson SA 2011 +* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/ +#ifndef __SYS_SOC_H +#define __SYS_SOC_H + +#include <linux/kobject.h> +#include <linux/device.h> + +#define MAX_SOCS 8 + +/** +* soc_device_register - register SoC as a device +* @soc_attrs: Multiple arrays of sysfs file attributes +* @num_socs: Amount of SoCs we're attempting to register +*/ +int soc_device_register (struct device_attribute *soc_attrs[], +int num_socs); +/** +* soc_device_unregister - unregister SoC as a device +* @soc_attrs: Multiple arrays of sysfs file attributes +* @num_socs: Amount of SoCs we're attempting to register +*/ +void soc_device_unregister (struct device_attribute *soc_attrs[], +int num_socs); + +#endif /* __SYS_SOC_H */
Signature · 1 line
1.7.4.1
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Hi Lee,
Quoted 2 lines · Lee Jones
Signed-off-by Lee Jones <[email protected]>---
This definitely needs a changelog, explaining what the code is there for, and why you chose this interface and not the alternatives we discussed earlier.
drivers/base/soc.c line 6
Quoted 12 lines
drivers/base/soc.c new file +6
-0@@ -0,0 +1,127 @@ +/* +* Copyright (C) ST-Ericsson SA 2011 +* +* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/
(I believe this would be Copyright Linaro Ltd, not ST-Ericsson SA, but better ask internally in ST-Ericsson about what your rules are)
drivers/base/soc.c line 16
Quoted 2 lines
drivers/base/soc.c new file +2
-0+struct device *parent_soc; +struct device *soc[MAX_SOCS ];
The array should not be needed here, you can simply iterate all soc devices using device_for_each_child() if required.
Global variables should really not have such generic names. Better make all variables static and make sure that the code using them can at there properly.
drivers/base/soc.c line 10
Quoted 2 lines
drivers/base/soc.c new file +2
-0+int __init soc_device_register (struct device_attribute *soc_attrs[], +int soc_count)
This needs to return the soc device, otherwise there is nothing that a platform can do with the device.
Passing the soc_count the way you do won't work when you have different SoCs, so better require the user to call the register function repeatedly.
I think a nicer interface would be to pass a data structure into it with the data you always want to export, and then have the soc core create the necessary attributes, instead of requiring every user to duplicate that code.
A possible interface might be
struct soc_device {
const char *machine;
const char *family;
/* ... */
struct device dev;
};struct soc_device *soc_device_register(const char *machine, const char *family);
For the nonstandard attributes, I would recommend having the individual drivers call device_create_file, in order to discourage the use of device specific attribute names.
Quoted 8 lines
include/linux/sys_soc.h new file +2
-0@@ -0,0 +1,29 @@ +/* +* Copyright (C) ST-Ericsson SA 2011
include/linux/sys_soc.h line 12
Quoted 10 lines
include/linux/sys_soc.h new file +10
-0+* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/ +#ifndef __SYS_SOC_H +#define __SYS_SOC_H + +#include <linux/kobject.h> +#include <linux/device.h> + +#define MAX_SOCS 8
No need to hardcode the maximum.
Arnd
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Hi Arnd,
Quoted 7 lines · Lee Jones
Quoted 2 lines
Signed-off-by Lee Jones <[email protected]>---
This definitely needs a changelog, explaining what the code is there for, and why you chose this interface and not the alternatives we discussed earlier.
No problem.
Quoted 7 lines
Quoted 7 lines
drivers/base/soc.c new file +1
-0@@ -0,0 +1,127 @@ +/*
Quoted 8 lines
drivers/base/soc.c line 6
Quoted 5 lines
drivers/base/soc.c new file +5
-0+* Copyright (C) ST-Ericsson SA 2011 +* +* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/ (I believe this would be Copyright Linaro Ltd, not ST-Ericsson SA, but better ask internally in ST-Ericsson about what your rules are)
We've had internal discussions about this. I believe this is the correct thing to do. The Copyright should stay with ST-Ericsson.
Quoted 5 lines
drivers/base/soc.c line 16
Quoted 2 lines
drivers/base/soc.c new file +2
-0+struct device *parent_soc; +struct device *soc[MAX_SOCS ];The array should not be needed here, you can simply iterate all soc devices using
device_for_each_child()if required.
Joy, another re-write.
(I think you are correct however)
Quoted 3 lines
Global variables should really not have such generic names. Better make all variables static and make sure that the code using them can at there properly.
Agreed.
Quoted 5 lines
drivers/base/soc.c line 10
Quoted 2 lines
drivers/base/soc.c new file +2
-0+int __init soc_device_register (struct device_attribute *soc_attrs[], +int soc_count)This needs to return the soc device, otherwise there is nothing that a platform can do with the device.
What do you think the platform would want to do with the device?
Quoted 2 lines
Passing the
soc_countthe way you do won't work when you have different SoCs,
Why won't the platform know how many SoCs are on a given platform?
Quoted 1 line
so better require the user to call the register function repeatedly.
... and if it truly doesn't know, how will it know how many times to call the register function?
Quoted 5 lines
I think a nicer interface would be to pass a data structure into it with the data you always want to export, and then have the soc core create the necessary attributes, instead of requiring every user to duplicate that code.
Quoted 8 lines
A possible interface might be
struct soc_device { const char *machine; const char *family; /* ... */ struct device dev; };
Either way, the probing functions would have to be called in order to populate the structure. Why is using the struct device_attribute show|store callbacks to call them a bad thing to do in this case?
Quoted 5 lines
struct
soc_device*soc_device_register(const char *machine, const char *family);For the nonstandard attributes, I would recommend having the individual drivers call
device_create_file, in order to discourage the use of device specific attribute names.
I'm not entirely sure what you mean here. I'm assuming you mean calling device_create_file from platform code once the device has been registered and a pointer passed back. If that's the case then surely the driver could set the attribute names to _any_ value still?
I really like the:
struct device_attribute soc_one_attrs[] = {
__ATTR(machine, S_IRUGO, ux500_get_machine, NULL),
__ATTR(family, S_IRUGO, ux500_get_family, NULL),
__ATTR(soc_id, S_IRUGO, ux500_get_soc_id, NULL),
/* ... */
__ATTR_NULL,
};... interface. I think it's neat, and easy to read. Are you suggesting I should remove this altogether and replace it with passing const arguments for common attributes and insisting the platform code calls device_create_file for all non-standard ones? If so, if you would be kind enough to explain why this is better, I'd appreciate it.
Quoted 12 lines
Quoted 12 lines
include/linux/sys_soc.h new file +6
-0@@ -0,0 +1,29 @@ +/* +* Copyright (C) ST-Ericsson SA 2011 +* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/ +#ifndef __SYS_SOC_H
Quoted 8 lines
include/linux/sys_soc.h line 12
Quoted 6 lines
include/linux/sys_soc.h new file +6
-0+#define __SYS_SOC_H + +#include <linux/kobject.h> +#include <linux/device.h> + +#define MAX_SOCS 8No need to hardcode the maximum.
No problem.
Kind regards,
Lee
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Quoted 16 lines · Lee Jones
Quoted 7 lines
Quoted 7 lines
drivers/base/soc.c new file +1
-0@@ -0,0 +1,127 @@ +/* Quoted 8 lines
drivers/base/soc.c line 6
Quoted 5 lines
drivers/base/soc.c new file +5
-0+* Copyright (C) ST-Ericsson SA 2011 +* +* Author: Lee Jones <[email protected]> for ST-Ericsson. +* License terms: GNU General Public License (GPL), version 2 +*/ (I believe this would be Copyright Linaro Ltd, not ST-Ericsson SA, but better ask internally in ST-Ericsson about what your rules are)
Quoted 2 lines
We've had internal discussions about this. I believe this is the correct thing to do. The Copyright should stay with ST-Ericsson.
Ok, in that case, I'd suggest you use your ST-Ericsson address for Signed-off-by and the author statement above.
Quoted 7 lines
Quoted 5 lines
drivers/base/soc.c line 8
Quoted 2 lines
drivers/base/soc.c new file +2
-0+int __init soc_device_register (struct device_attribute *soc_attrs[], +int soc_count)This needs to return the soc device, otherwise there is nothing that a platform can do with the device.
What do you think the platform would want to do with the device?
Add the child devices, or add more attributes.
Quoted 9 lines
Quoted 2 lines
Passing the
soc_countthe way you do won't work when you have different SoCs,Why won't the platform know how many SoCs are on a given platform?
Quoted 1 line
so better require the user to call the register function repeatedly.
... and if it truly doesn't know, how will it know how many times to call the register function?
You could have a platform that has several SOCs, some of which are optional, E.g. one SoC for that contains the main CPU, and then another SOC of a different vendor plugged into an external bus.
Quoted 14 lines
Quoted 5 lines
I think a nicer interface would be to pass a data structure into it with the data you always want to export, and then have the soc core create the necessary attributes, instead of requiring every user to duplicate that code.
Quoted 8 lines
A possible interface might be
struct soc_device { const char *machine; const char *family; /* ... */ struct device dev; };
Quoted 3 lines
Either way, the probing functions would have to be called in order to populate the structure. Why is using the struct
device_attributeshow|store callbacks to call them a bad thing to do in this case?
Code is more complex than data, and we want to have the complexity in a central location, not copied over all subarchitectures. When you use a flattened device tree, the strings can simply point to properties of the root device, so there would be very little to do other than assign them.
Quoted 9 lines
Quoted 5 lines
struct
soc_device*soc_device_register(const char *machine, const char *family);For the nonstandard attributes, I would recommend having the individual drivers call
device_create_file, in order to discourage the use of device specific attribute names.I'm not entirely sure what you mean here. I'm assuming you mean calling
device_create_filefrom platform code once the device has been registered and a pointer passed back.
Right.
Quoted 13 lines
If that's the case then surely the
driver could set the attribute names to _any_ value still?I really like the:
struct device_attribute soc_one_attrs[] = { __ATTR(machine, S_IRUGO, ux500_get_machine, NULL), __ATTR(family, S_IRUGO, ux500_get_family, NULL), __ATTR(soc_id, S_IRUGO, ux500_get_soc_id, NULL), /* ... */ __ATTR_NULL, };
Quoted 5 lines
... interface. I think it's neat, and easy to read. Are you suggesting I should remove this altogether and replace it with passing const arguments for common attributes and insisting the platform code calls
device_create_filefor all non-standard ones? If so, if you would be kind enough to explain why this is better, I'd appreciate it.
I would prefer to standardise the attributes as much as possible. Ideally, all SOCs should export the same set of attributes, and in no case should there be multiple SOCs that have the same attribute name but with a slightly different interface (e.g. one writable, or one root-only readable), or the same contents in attributes of different names.
The best way to ensure this is to give less flexiblity to the person implementing the individual SOC code. All attributes that are documented to be available across SOCs can simply be automatically created and filled with the data provided by the platform.
Having interfaces specific to one SOC should be the absolute exception, so I'd try to make that as hard as possible.
Arnd
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Hi Arnd,
</snip>
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
(I believe this would be Copyright Linaro Ltd, not ST-Ericsson SA, but better ask internally in ST-Ericsson about what your rules are)
We've had internal discussions about this. I believe this is the correct thing to do. The Copyright should stay with ST-Ericsson.
Ok, in that case, I'd suggest you use your ST-Ericsson address for Signed-off-by and the author statement above.
I'm not an ST-Ericsson employee, thus do not have an associated address.
I work for Linaro, currently on assignment to ST-Ericsson.
</snip>
Quoted 6 lines
I would prefer to standardise the attributes as much as possible. Ideally, all SOCs should export the same set of attributes, and in no case should there be multiple SOCs that have the same attribute name but with a slightly different interface (e.g. one writable, or one root-only readable), or the same contents in attributes of different names.
Quoted 7 lines
The best way to ensure this is to give less flexiblity to the person implementing the individual SOC code. All attributes that are documented to be available across SOCs can simply be automatically created and filled with the data provided by the platform.
Having interfaces specific to one SOC should be the absolute exception, so I'd try to make that as hard as possible.
Well your word overrides mine.
I'll completely rewrite the driver again. It may be some time before it's complete (post-UDS/LDS), as I have a lot on 'till then. I would like to see this to the end though, so leave it with me.
Kind regards,
Lee
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Quoted 10 lines · Lee Jones
Hi Arnd,
</snip>
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
(I believe this would be Copyright Linaro Ltd, not ST-Ericsson SA, but better ask internally in ST-Ericsson about what your rules are)
We've had internal discussions about this. I believe this is the correct thing to do. The Copyright should stay with ST-Ericsson.
Quoted 6 lines
Quoted 2 lines
Ok, in that case, I'd suggest you use your ST-Ericsson address for Signed-off-by and the author statement above.
I'm not an ST-Ericsson employee, thus do not have an associated address.
I work for Linaro, currently on assignment to ST-Ericsson.
It was my understanding gained last week was that Linaro is a separate organization, and that while folk are working for Linaro, stuff they create belongs to Linaro and not the company whose office they happen to be sitting in.
I also thought Linaro was supposed to be an organization for solving the _common_ problems being experienced by each member organization, rather than being a contracting house to any one particular organization. Am I mistaken?
PATCH 1/3 Framework for exporting System-on-Chip information via sysfs
Hi Russell,
Quoted 12 lines
Quoted 6 lines
Quoted 2 lines
Ok, in that case, I'd suggest you use your ST-Ericsson address for Signed-off-by and the author statement above.
I'm not an ST-Ericsson employee, thus do not have an associated address.
I work for Linaro, currently on assignment to ST-Ericsson.
It was my understanding gained last week was that Linaro is a separate organization, and that while folk are working for Linaro, stuff they create belongs to Linaro and not the company whose office they happen to be sitting in.
Quoted 4 lines
I also thought Linaro was supposed to be an organization for solving the _common_ problems being experienced by each member organization, rather than being a contracting house to any one particular organization. Am I mistaken?
You are not mistaken for the most part. However, you are referring to the engineering work carried out by the engineers contained in the Linaro Working Groups. The role I occupy within the company is slightly different. I lead a group of individuals called a "Landing Team". There are currently four of these within Linaro; ST-Ericsson (mine), Texas Instruments, Samsung and Freescale, with a view on increasing that number over the upcoming months. The Landing Team's main purpose is to upstream as much code as possible for a previously specified SoC, in our case the u8500. How the Landing Team spends their time is my responsibility and as such (unless Linaro or ST-Ericsson management have a special request) is depicted by me.
With regards to the Copyright label, I will endeavor to find a definitive answer. We came to the conclusion of "Written by Linaro for ST-Ericsson" some time ago in a Landing Team meeting we held some months ago. If you or Arnd see this as an issue clearly we need to have more meetings and involve more senior people from Linaro to chase a conclusive answer.
Thanks for your time and input Russell and Arnd, it is appreciated.
Kind regards,
Lee Jones
Team Lead, Linaro ST-Ericsson Landing Team
PATCH 2/3 mach-ux500: export System-on-Chip information via sysfs
In reply to Lee Jones--- arch/arm/mach-ux500/Kconfig | 1 + arch/arm/mach-ux500/id.c | 96 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 0 deletions(-)
arch/arm/mach-ux500/Kconfig +1 -0
@@ -25,6 +25,7 @@ config MACH_U8500 bool "U8500 Development platform" depends on UX500_SOC_DB8500 select TPS6105X + select SYS_SOC help Include support for the mop500 development platform.
arch/arm/mach-ux500/id.c +96 -0
111 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Arnd Bergmann
NAKPATCH 2/3 mach-ux500: export System-on-Chip information via sysfs
Quoted 6 lines · Lee Jones
Signed-off-by Lee Jones <[email protected]>--- arch/arm/mach-ux500/Kconfig | 1 + arch/arm/mach-ux500/id.c | 96 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 0 deletions(-)
NAK
As I explained in one or more of the previous email exchanges, the SoC device really needs to represent the SoC, we don't just create random crap in sysfs in order to stick attributes there.
You have to make sure that all devices that are part of the soc on ux500 are children of the soc device. Please list the contents of /sys/devices/platform and /sys/devices/soc/*/ in your changelog, before and after the patch is applied.
Arnd
PATCH 3/3 Add documenation for new sysfs devices/soc functionallity
In reply to Lee Jones--- Documentation/ABI/testing/sysfs-devices-soc | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-soc
Documentation/ABI/testing/sysfs-devices-soc new file +16 -0
@@ -0,0 +1,16 @@ +What: /sys/devices/soc +Date: April 2011 +contact: Lee Jones <[email protected]> +Description: + The /sys/devices/soc directory contains a sub-directory for each + System-on-Chip (SoC) device on a running platform. Information + regarding each SoC can be obtained by reading sysfs files. This + functionallity is only available if implemented by the platform. + This directory contains two kinds of attributes: + - Common attributes: + * machine: the name of the machine (e.g. Ux500). + * family: the family name of the SoC (e.g. DB8500). + - SoC-specific attributes: + * SoC vendor declared, such as serial and rev numbers. +Users: + Any platform dependent user-space applications or profiling tools.
Signature · 1 line
1.7.4.1
PATCH 3/3 Add documenation for new sysfs devices/soc functionallity
Quoted 5 lines · Lee Jones
Signed-off-by Lee Jones <[email protected]>--- Documentation/ABI/testing/sysfs-devices-soc | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-soc
Looks good, but the patch is missing a changelog. I wouldn't bother splitting it out, just merge this patch with the first one in the series.
Arnd