hwmon class driver registration with a device number
PATCH 1/1 hwmon class driver registration with a device number
This patch adds a way to register a hwmon class driver with a device number rather than the default MK_DEV(0,0). This would help in creating required "dev" file under sysfs which in turn can be used in populating /dev tree during bootup (helpful to driver which want to show up a char interface along with sysfs).
--- drivers/hwmon/hwmon.c | 28 ++++++++++++++++++++++------ include/linux/hwmon.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-)
drivers/hwmon/hwmon.c +22 -6
@@ -31,15 +31,17 @@ static DEFINE_IDR(hwmon_idr);static DEFINE_SPINLOCK (idr_lock);/** -* hwmon_device_register - register w/ hwmon -* @dev: the device to register +* hwmon_device_register_numbered - register hwmon class dev +* with specific device number. +* @dev: Device to register. +* @dev_id: device number to register. * -* hwmon_device_unregister() must be called when the device is no -* longer needed. +* hwmon_device_unregister() must be called when the device +* is no longer needed. * * Returns the pointer to the new device. */ -struct device *hwmon_device_register (struct device *dev) +struct device *hwmon_device_register_numbered (struct device *dev,dev_t dev_id) {struct device *hwdev;int id, err;
@@ -58,7 +60,7 @@ again:return ERR_PTR (err); id = id &MAX_ID_MASK ; - hwdev =device_create (hwmon_class, dev,MKDEV (0 ,0 ),NULL , + hwdev =device_create (hwmon_class, dev, dev_id,NULL ,HWMON_ID_FORMAT , id);if (IS_ERR (hwdev)) {
@@ -71,6 +73,20 @@ again: }/** +* hwmon_device_register - register w/ hwmon +* @dev: the device to register +* +* hwmon_device_unregister() must be called when the device is no +* longer needed. +* +* Returns the pointer to the new device. +*/ +struct device *hwmon_device_register (struct device *dev) +{ +return hwmon_device_register_numbered (dev,MK_DEV (0 ,0 )); +} + +/** * hwmon_device_unregister - removes the previously registered class device * * @dev: the class device to destroy
include/linux/hwmon.h +1 -0
@@ -16,6 +16,7 @@#include <linux/device.h> +struct device *hwmon_device_register_numbered (struct device *dev,dev_t dev_id);struct device *hwmon_device_register (struct device *dev);void hwmon_device_unregister (struct device *dev);
Signature · 1 line
1.7.4.1
Quoted 8 lines · Himanshu Chauhan
This patch adds a way to register a hwmon class driver with a device number rather than the default
MK_DEV(0,0). This would help in creating required "dev" file under sysfs which in turn can be used in populating /dev tree during bootup (helpful to driver which want to show up a char interface along with sysfs).Signed-off-by Himanshu Chauhan <[email protected]>
hwmon patches should be sent to [email protected].
I can not comment on the merits of your patch. Unless I am missing something, which may well be since I only spent a couple of minutes on it, other device classes don't seem to provide a similar API, so I don't know if or why it would make sense for hwmon. Maybe a driver which wants to register a character device interface should do so independently of hwmon.
On the technical side, EXPORT_SYMBOL is missing.
Guenter
Quoted 67 lines
--- drivers/hwmon/hwmon.c | 28 ++++++++++++++++++++++------ include/linux/hwmon.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-)drivers/hwmon/hwmon.c +22
-6@@ -31,15 +31,17 @@ static DEFINE_IDR(hwmon_idr);static DEFINE_SPINLOCK (idr_lock);/** -* hwmon_device_register - register w/ hwmon -* @dev: the device to register +* hwmon_device_register_numbered - register hwmon class dev +* with specific device number. +* @dev: Device to register. +* @dev_id: device number to register. * -* hwmon_device_unregister() must be called when the device is no -* longer needed. +* hwmon_device_unregister() must be called when the device +* is no longer needed. * * Returns the pointer to the new device. */ -struct device *hwmon_device_register (struct device *dev) +struct device *hwmon_device_register_numbered (struct device *dev,dev_t dev_id) {struct device *hwdev;int id, err;@@ -58,7 +60,7 @@ again:return ERR_PTR (err); id = id &MAX_ID_MASK ; - hwdev =device_create (hwmon_class, dev,MKDEV (0 ,0 ),NULL , + hwdev =device_create (hwmon_class, dev, dev_id,NULL ,HWMON_ID_FORMAT , id);if (IS_ERR (hwdev)) {@@ -71,6 +73,20 @@ again: }/** +* hwmon_device_register - register w/ hwmon +* @dev: the device to register +* +* hwmon_device_unregister() must be called when the device is no +* longer needed. +* +* Returns the pointer to the new device. +*/ +struct device *hwmon_device_register (struct device *dev) +{ +return hwmon_device_register_numbered (dev,MK_DEV (0 ,0 )); +} + +/** * hwmon_device_unregister - removes the previously registered class device * * @dev: the class device to destroy include/linux/hwmon.h +0
-0
include/linux/hwmon.h line 22
Quoted 7 lines
include/linux/hwmon.h +1
-0@@ -16,6 +16,7 @@#include <linux/device.h> +struct device *hwmon_device_register_numbered (struct device *dev,dev_t dev_id);struct device *hwmon_device_register (struct device *dev);void hwmon_device_unregister (struct device *dev);
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 6 lines · Himanshu Chauhan
This patch adds a way to register a hwmon class driver with a device number rather than the default
MK_DEV(0,0). This would help in creating required "dev" file under sysfs which in turn can be used in populating /dev tree during bootup (helpful to driver which want to show up a char interface along with sysfs).
How do you later remove a device created with this new interface? As it is, I think the existing calls will fail, right?
greg k-h
Hi,
Quoted 7 lines
I can not comment on the merits of your patch. Unless I am missing something, which may well be since I only spent a couple of minutes on it, other device classes don't seem to provide a similar API, so I don't know if or why it would make sense for hwmon. Maybe a driver which wants to register a character device interface should do so independently of hwmon.
The idea here is to sit in the same class directory as of hwmon. Devices registered with this interface will have "dev" under, for example, /sys/class/hwmon/hwmon0/dev. To do the same inside the driver will be a bit more involved than a call.
In my opinion other classes should also have similar interfaces.
Quoted 2 lines
On the technical side,
EXPORT_SYMBOLis missing.
I will take care of that.
Regards
Himanshu
Hi Greg,
Quoted 4 lines
How do you later remove a device created with this new interface? As it is, I think the existing calls will fail, right?
If I have not missed out anything from hwmon_device_unregister(), it shouldn't fail. Why did you point that out?
-Himanshu
Quoted 10 lines · Himanshu Chauhan
Hi,
Quoted 7 lines
I can not comment on the merits of your patch. Unless I am missing something, which may well be since I only spent a couple of minutes on it, other device classes don't seem to provide a similar API, so I don't know if or why it would make sense for hwmon. Maybe a driver which wants to register a character device interface should do so independently of hwmon.
Quoted 7 lines
The idea here is to sit in the same class directory as of hwmon. Devices registered with this interface will have "dev" under, for example,
/sys/class/hwmon/hwmon0/dev. To do the same inside the driver will be a bit more involved than a call.In my opinion other classes should also have similar interfaces.
I think you'll have to spend some more time and effort explaining the "what for".
Apparently no other device class needs this functionality so far, yet you suggest that such an interface should exist for all device classes. But you do so without explanation, or in other words without use case.
I for my part have no idea what you would use or need this new interface for, and if there would be other less intrusive means to accomplish the same goal. And I would want to see really good reasons to make a change like this.
Specifically looking at the hwmon subsystem, you are expected to use the lm-sensors library to access all hwmon attributes. So I would expect your explanation to include exactly what you want to accomplish and why, details why you believe that you can not use the lm-sensors library, why you believe that the current infrastructure does not provide the means you need to accomplish your goals, and why you think that the existing infrastructure can not be modified to let you accomplish what you want to do without such a - from a conceptual perspective - substantial change.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
I am purposely removing kernelnewbies from the CC list, as it seems quite irrelevant for this discussion.
Quoted 16 lines · Guenter Roeck
Quoted 15 lines · Himanshu Chauhan
Hi,
Quoted 7 lines
I can not comment on the merits of your patch. Unless I am missing something, which may well be since I only spent a couple of minutes on it, other device classes don't seem to provide a similar API, so I don't know if or why it would make sense for hwmon. Maybe a driver which wants to register a character device interface should do so independently of hwmon.
The idea here is to sit in the same class directory as of hwmon. Devices registered with this interface will have "dev" under, for example,
/sys/class/hwmon/hwmon0/dev. To do the same inside the driver will be a bit more involved than a call.
Quoted 6 lines
Quoted 2 lines
In my opinion other classes should also have similar interfaces.
I think you'll have to spend some more time and effort explaining the "what for".
Apparently no other device class needs this functionality so far, yet you suggest that such an interface should exist for all device classes.
Actually a lot of class devices do have a device node:
$ ls -1 /sys/class/*/*/dev | wc -l 252 This includes block, drm, dvb, input, msr, sound and tty class devices, to name just a few. But this isn't the problem. All these are documented in Documentation/devices.txt, and have a properly defined API. There is no such thing for hwmon devices at this point.
Quoted 1 line
But you do so without explanation, or in other words without use case.
This is indeed the key point. Creating a device node is pointless without a standard API to make use of it. So Himanshu will have to document that first.
Quoted 3 lines
I for my part have no idea what you would use or need this new interface for, and if there would be other less intrusive means to accomplish the same goal. And I would want to see really good reasons to make a change like this.
Another good point.
Quoted 7 lines
Specifically looking at the hwmon subsystem, you are expected to use the lm-sensors library to access all hwmon attributes. So I would expect your explanation to include exactly what you want to accomplish and why, details why you believe that you can not use the lm-sensors library, why you believe that the current infrastructure does not provide the means you need to accomplish your goals, and why you think that the existing infrastructure can not be modified to let you accomplish what you want to do without such a - from a conceptual perspective - substantial change.
I again agree. Which means that Himanshu is still 3 steps away from getting his patch accepted:
* Explaining why the current sysfs interface is insufficient and can't be fixed.
* Getting official device node numbers registered for hwmon use.
* Defining an API for these device nodes.
Before then, there's no point in resending this patch, it will be rejected.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 24 lines · Jean Delvare
I am purposely removing kernelnewbies from the CC list, as it seems quite irrelevant for this discussion.
Quoted 20 lines · Guenter Roeck
Quoted 10 lines · Himanshu Chauhan
Hi,
Quoted 7 lines
I can not comment on the merits of your patch. Unless I am missing something, which may well be since I only spent a couple of minutes on it, other device classes don't seem to provide a similar API, so I don't know if or why it would make sense for hwmon. Maybe a driver which wants to register a character device interface should do so independently of hwmon.
Quoted 7 lines
The idea here is to sit in the same class directory as of hwmon. Devices registered with this interface will have "dev" under, for example,
/sys/class/hwmon/hwmon0/dev. To do the same inside the driver will be a bit more involved than a call.In my opinion other classes should also have similar interfaces.
I think you'll have to spend some more time and effort explaining the "what for".
Quoted 8 lines
Quoted 2 lines
Apparently no other device class needs this functionality so far, yet you suggest that such an interface should exist for all device classes.
Actually a lot of class devices do have a device node:
$ ls -1 /sys/class/*/*/dev | wc -l 252 This includes block, drm, dvb, input, msr, sound and tty class devices, to name just a few. But this isn't the problem. All these are
I meant instances where the major/minor device number is passed to the class registration function.
Having said that, I realize there are instances where the _minor_ device number is passed to the class registration function (eg for misc devices). In that case, though, misc_register() checks if the asked for minor device already exists, and retains the option to generate a dynamic minor device. This is different here, where the proposal is to pass both major and minor device number to the registration function.
Maybe there are instances where both major and minor device number are passed; as I mentioned before, I did not spend that much time on it. But you are right - that isn't the point anyway.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 1 line · Jean Delvare
Thanks Jean for summing up the questions :)
Quoted 4 lines
I again agree. Which means that Himanshu is still 3 steps away from getting his patch accepted:
* Explaining why the current sysfs interface is insufficient and can't be fixed.
AFAIK, the current sysfs interface is to read standard attributes from the device. My reasoning is:
1. This will give hwmon devices to have their "dev" in their sysfs folder as like other classes and in turn be visible in /dev by mdev or udev.
2. Implementing IOCTL if required. I know that kernel hackers believe they are "backdoors" and "can't be done right" but sometimes there isn't any get away with them. I don't know when their support will be completely removed. Rather, I see that instead of deprecation, new IOCTL vectors like compat_ioctl have been introduced.
Quoted 1 line
* Getting official device node numbers registered for hwmon use.
Jean, as long as drivers get major device numbers on the fly, I don't think this is a requirement. Isn't it?
Quoted 1 line
* Defining an API for these device nodes.
My idea is just this:
1. Get a major number from kernel on the fly.
2. During probing, for each device, call "hwmon_device_register_numbered" and let mdev create a /dev node for it. I don't say that this interface be imposed on drivers. If they want they can still call "hwmon_device_register" if they don't want to implement standard ioctl, read, write calls.
Quoted 3 lines
Before then, there's no point in resending this patch, it will be rejected.
Thanks for reviewing. These are my thoughts. If you guys think the reasoning isn't strong enough to get this in mainline, I am happy to accept that :) At least I know what can get rejected for sure and I am happy to build a stack of rejected patches for that. :)
-Himanshu
Quoted 2 lines
AFAIK, the current sysfs interface is to read standard attributes from the device. My reasoning is:
and any other attributes.
Quoted 2 lines
1. This will give hwmon devices to have their "dev" in their sysfs folder as like other classes and in turn be visible in /dev by mdev or udev.
Well there is in theory no reason a device shouldn't do that, but most sysfs devices don't need to so making it generic seems odd.
Quoted 5 lines
2. Implementing IOCTL if required. I know that kernel hackers believe they are "backdoors" and "can't be done right" but sometimes there isn't any get away with them. I don't know when their support will be completely removed. Rather, I see that instead of deprecation, new IOCTL vectors like
compat_ioctlhave been introduced.
Certain things need ioctl, in fact some problems are *very* hard to solve any other way: transactional updates (changing a set of fields at once all or none), and query/response data being two.
Quoted 4 lines
2. During probing, for each device, call "
hwmon_device_register_numbered" and let mdev create a /dev node for it. I don't say that this interface be imposed on drivers. If they want they can still call "hwmon_device_register" if they don't want to implement standard ioctl, read, write calls.
I guess I don't see why a device that is more than just a monitoring interface can't allocate a misc device or similar if it needs one.
For the more complex cases take a look at drivers/staging/iio also.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 4 lines · Alan Cox
I guess I don't see why a device that is more than just a monitoring interface can't allocate a misc device or similar if it needs one.
Hi Alan,
For a device, for example, /sys/class/hwmon/hwmon0/dev, mdev will create hwmon0 named device in /dev. User space apps will access the device with the same name, i.e. /dev/hwmon0. If a driver registers with hwmon class and with miscellaneous as well, two entries with same name will be created under /sys; causing conflict. hwmon will create hwmon%d, you don't have control over that. So the driver has to make sure that it gives the same device a different name. Why? Doesn't make sense. If you want to have hwmon device and still want to have char interface, isn't doing it all at one place more sensible?
May be this interface is not a necessity but it does provides a flexible way of achieving what I am talking about.
-Himanshu
Quoted 11 lines · Guenter Roeck
Having said that, I realize there are instances where the _minor_ device number is passed to the class registration function (eg for misc devices). In that case, though,
misc_register()checks if the asked for minor device already exists, and retains the option to generate a dynamic minor device. This is different here, where the proposal is to pass both major and minor device number to the registration function.Maybe there are instances where both major and minor device number are passed; as I mentioned before, I did not spend that much time on it. But you are right - that isn't the point anyway.
If misc and other classes can create nodes based on device numbers that are passed to them, why is it a problem for hwmon? Why does hwmon creates devices with MKDEV(0,0)? I am still not getting the point.
-Himanshu
Quoted 8 lines · Himanshu Chauhan
Hi Greg,
Quoted 4 lines
How do you later remove a device created with this new interface? As it is, I think the existing calls will fail, right?
If I have not missed out anything from
hwmon_device_unregister(), it shouldn't fail. Why did you point that out?
If you create a device with a call to device_create() with a dev_t set, it is usually cleaned up with a call to device_destroy(), but you are right, a simple call to device_unregister() will still work properly.
So nevermind, sorry for the noise.
What you do need to determine is if this is a device node you really want to be creating in this manner, as it is a new user/kernel API, right?
greg k-h
Quoted 7 lines · Greg KH
Quoted 6 lines · Himanshu Chauhan
Hi Greg,
Quoted 4 lines
How do you later remove a device created with this new interface? As it is, I think the existing calls will fail, right?
Quoted 9 lines
Quoted 2 lines
If I have not missed out anything from
hwmon_device_unregister(), it shouldn't fail. Why did you point that out?If you create a device with a call to
device_create()with adev_tset, it is usually cleaned up with a call todevice_destroy(), but you are right, a simple call todevice_unregister()will still work properly.So nevermind, sorry for the noise.
Not entirely noise. Since the new registration call is not exported in the patch, any code using it won't be compilable as module, which in turn means that hwmon_device_unregister() was never called.
So while we know that it _should_ work, we also know that it was not tested.
Quoted 4 lines
What you do need to determine is if this is a device node you really want to be creating in this manner, as it is a new user/kernel API, right?
And why, and what for.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 1 line · Guenter Roeck
And why, and what for.
The initial idea of posting to kernelnewbies was to get a hint on how the patch would be taken as. I wanted to know if developers will like the idea behind it or not. I guess, Guenter is not convinced with any of my reasoning. I am willing to clean it up further only if I get a positive hint. But it doesn't seem to be going anywhere.
Thanks Guenter, Alan, and Greg for taking your time and reviewing it.
Greg: To answer your last question, if this was taken positively, I was thinking of having functionality similar to misc device registration.
-Himanshu
Quoted 9 lines · Himanshu Chauhan
Quoted 1 line · Guenter Roeck
And why, and what for.
The initial idea of posting to kernelnewbies was to get a hint on how the patch would be taken as. I wanted to know if developers will like the idea behind it or not. I guess, Guenter is not convinced with any of my reasoning. I am willing to clean it up further only if I get a positive hint. But it doesn't seem to be going anywhere.
Quoted 4 lines
Thanks Guenter, Alan, and Greg for taking your time and reviewing it.
Greg: To answer your last question, if this was taken positively, I was thinking of having functionality similar to misc device registration.
But why? What is that device node going to be used for? Who would be using it in userspace and where would it be tied into in the kernel?
still confused,
greg k-h
Quoted 10 lines · Greg KH
Quoted 9 lines · Himanshu Chauhan
Quoted 1 line · Guenter Roeck
And why, and what for.
The initial idea of posting to kernelnewbies was to get a hint on how the patch would be taken as. I wanted to know if developers will like the idea behind it or not. I guess, Guenter is not convinced with any of my reasoning. I am willing to clean it up further only if I get a positive hint. But it doesn't seem to be going anywhere.
Quoted 8 lines
Quoted 4 lines
Thanks Guenter, Alan, and Greg for taking your time and reviewing it.
Greg: To answer your last question, if this was taken positively, I was thinking of having functionality similar to misc device registration.
But why? What is that device node going to be used for? Who would be using it in userspace and where would it be tied into in the kernel?
The device node, as I said earlier, can be used for doing IOCTLS. In user space, applications that manage and monitor system environment will need to use this interface for querying the sensor's location, for example. In side the kernel, the driver that is driving the particular hardware sensor can register a char interface for all this and then register with hwmon with the same major/minor for usual sysfs export of data.
-Himanshu
Quoted 19 lines · Himanshu Chauhan
Quoted 10 lines · Greg KH
Quoted 9 lines · Himanshu Chauhan
Quoted 1 line · Guenter Roeck
And why, and what for.
The initial idea of posting to kernelnewbies was to get a hint on how the patch would be taken as. I wanted to know if developers will like the idea behind it or not. I guess, Guenter is not convinced with any of my reasoning. I am willing to clean it up further only if I get a positive hint. But it doesn't seem to be going anywhere.
Quoted 8 lines
Quoted 4 lines
Thanks Guenter, Alan, and Greg for taking your time and reviewing it.
Greg: To answer your last question, if this was taken positively, I was thinking of having functionality similar to misc device registration.
But why? What is that device node going to be used for? Who would be using it in userspace and where would it be tied into in the kernel?
Quoted 6 lines
The device node, as I said earlier, can be used for doing IOCTLS. In user space, applications that manage and monitor system environment will need to use this interface for querying the sensor's location, for example. In side the kernel, the driver that is driving the particular hardware sensor can register a char interface for all this and then register with hwmon with the same major/minor for usual sysfs export of data.
If location is useful info why not propose a sysfs interface for it?
Quoted 13 lines · Himanshu Chauhan
Quoted 12 lines · Greg KH
Quoted 11 lines · Himanshu Chauhan
Quoted 1 line · Guenter Roeck
And why, and what for.
The initial idea of posting to kernelnewbies was to get a hint on how the patch would be taken as. I wanted to know if developers will like the idea behind it or not. I guess, Guenter is not convinced with any of my reasoning. I am willing to clean it up further only if I get a positive hint. But it doesn't seem to be going anywhere.
Thanks Guenter, Alan, and Greg for taking your time and reviewing it.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Greg: To answer your last question, if this was taken positively, I was thinking of having functionality similar to misc device registration.
But why? What is that device node going to be used for? Who would be using it in userspace and where would it be tied into in the kernel?
The device node, as I said earlier, can be used for doing IOCTLS.
It can? Which ones? New ones you want to propose? If so, why use an ioctl?
Quoted 6 lines
In user space, applications that manage and monitor system environment will need to use this interface for querying the sensor's location, for example. In side the kernel, the driver that is driving the particular hardware sensor can register a char interface for all this and then register with hwmon with the same major/minor for usual sysfs export of data.
So you are creating a new user/kernel api here, right? If so, you need to document it in Documentation/API and we need to be able to approve that BEFORE we could ever accept the creation of new device nodes like this, that at the moment, do not do anything.
In other words, you need to prove you need a new ioctl interface before you can get a patch accepted that implements this.
greg k-h