Accessing rpmsg_device in sysfs attribute functions
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send various commands from user space in Linux to a secondary CPU (A Cortex M4). I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct rpmsg_device *" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register a rpmsg_driver in the init function:
register_rpmsg_driver(&pwm_rpmsg_driver);
the device_driver member of my rpmsg_driver struct has its groups member set to my driver attribute groups array:
static struct rpmsg_driver pwm_rpmsg_driver = {
.probe = pwm_rpmsg_probe,
.remove = pwm_rpmsg_remove,
.callback = pwm_rpmsg_cb,
.id_table = pwm_rpmsg_device_id_table,
.drv = {
.groups = driver_pwm_groups,
.name = "pwm_rpmsg",
},
};
My issue is that that I am not sure how to access the struct "rpmsg_device *" (i.e. from the probe() function) in the show/store functions for the sysfs attributes, which have a "struct device_driver *" argument:
static int pwm_rpmsg_probe(struct rpmsg_device *rpdev) /* rpmsg_device->ept is needed to send messages to the other CPU */
static ssize_t duty_cycle_store(struct device_driver *dev, const char *buf,
size_t count); /* Can I use the device_driver struct to somehow access the rpmsg_device? */
I am very much a novice when it comes to driver development, so I might be approaching this from a completely wrong direction. Any advice would be very much appreciated!
Thanks,
Pelle
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 18 lines · Pelle Windestam
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send various commands from user space in Linux to a secondary CPU (A Cortex M4). I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init function:
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups member set to my driver attribute groups array:
static structrpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};
Quoted 1 line
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from theprobe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*" argument:
That is because you have created a driver attribute, not a device attribute. Create device attributes and you should be fine, they bind to the device your driver is passed.
good luck!
greg k-h
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Greg,
Thus wrote Greg KH ([email protected]):
Quoted 3 lines
That is because you have created a driver attribute, not a device attribute. Create device attributes and you should be fine, they bind to the device your driver is passed.
could you point me to an example in the kernel tree where this is done correctly for a platform device?
I had a look at
http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
but I couldn't figure out how to create device attributes in a simple platform driver that binds to a platform device.
Thanks a lot for your help,
Martin
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 11 lines · Martin Kaiser
Hi Greg,
Thus wrote Greg KH ([email protected]):
Quoted 3 lines
That is because you have created a driver attribute, not a device attribute. Create device attributes and you should be fine, they bind to the device your driver is passed.
could you point me to an example in the kernel tree where this is done correctly for a platform device?
Quoted 6 lines
I had a look at
http://kroah.com/log/blog/2013/06/26/how-to-create-a-sysfs-file-correctly/
but I couldn't figure out how to create device attributes in a simple platform driver that binds to a platform device.
Look at commit d99995a4f0f1 ("Input: axp20x-pek - convert driver to use dev_groups") in the 5.4 kernel as an example of how to use the correct api here.
Hope this helps,
greg k-h
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 29 lines · Pelle Windestam
Quoted 3 lines
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send
various commands from user space in Linux to a secondary CPU (A Cortex M4). I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init function:Quoted 4 lines
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups memberset to my driver attribute groups array:
Quoted 11 lines
static struct
rpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};
Quoted 7 lines
Quoted 1 line
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from the
probe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*" argument:That is because you have created a driver attribute, not a device attribute. Create device attributes and you should be fine, they bind to the device your driver is passed.
Thanks! Changing them to device attributes was a breeze. Now I am slightly confused about the "struct device *" argument to the store/show functions. I was under the impression that this would be the "struct device" in the struct rpmsg_device, (which would let me get the struct rpmsg_device using container_of()?), but it appears to be some completely other device (by looking at the pointer address). I have tried searching the kernel code for similar example, but I have not found anything so far. It feels like I am stumbling a bit in the dark here, looking for my rpmsg_device.
//Pelle
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 37 lines · Pelle Windestam
Quoted 29 lines · Pelle Windestam
Quoted 3 lines
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send
various commands from user space in Linux to a secondary CPU (A Cortex M4). I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init function:Quoted 4 lines
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups memberset to my driver attribute groups array:
Quoted 11 lines
static struct
rpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};Quoted 7 lines
Quoted 1 line
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from the
probe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*" argument:That is because you have created a driver attribute, not a device attribute. Create device attributes and you should be fine, they bind to the device your driver is passed.
Quoted 9 lines
Thanks! Changing them to device attributes was a breeze. Now I am slightly confused about the "struct device *" argument to the store/show functions. I was under the impression that this would be the "struct device" in the struct
rpmsg_device, (which would let me get the structrpmsg_deviceusingcontainer_of()?), but it appears to be some completely other device (by looking at the pointer address). I have tried searching the kernel code for similar example, but I have not found anything so far. It feels like I am stumbling a bit in the dark here, looking for myrpmsg_device.
It's a bit hard to figure out what exactly you are doing here without a pointer to the code itself :)
Are you sure you aren't pointing the platform device accidentally?
thanks,
greg k-h
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 61 lines
From: Greg KH <[email protected]>
Sent: Tuesday, 24 March 2020 13:31
To: Pelle Windestam <[email protected]>
Cc: [email protected]
Subject: Re: Accessingrpmsg_devicein sysfs attribute functionsQuoted 6 lines · Pelle Windestam
Quoted 6 lines · Pelle Windestam
Quoted 4 lines
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send
various commands from user space in Linux to a secondary CPU (A Cortex
M4).
Quoted 27 lines
Quoted 27 lines
I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init
function:Quoted 5 lines
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups memberset to my driver attribute groups array:
Quoted 11 lines
static struct
rpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from the
probe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*" argument:That is because you have created a driver attribute, not a device
attribute.
Quoted 12 lines
Quoted 2 lines
Create device attributes and you should be fine, they bind to the device your driver is passed.
Thanks! Changing them to device attributes was a breeze. Now I am slightly confused about the "struct device *" argument to the store/show functions. I was under the impression that this would be the "struct device" in the struct
rpmsg_device, (which would let me get the structrpmsg_deviceusingcontainer_of()?), but it appears to be some completely other device (by looking at the pointer address). I have tried searching the kernel code for similar example, but I have not found anything so far. It feels like I am stumbling a bit in the dark here, looking for myrpmsg_device.
Quoted 8 lines
It's a bit hard to figure out what exactly you are doing here without a pointer to the code itself :)
Are you sure you aren't pointing the platform device accidentally?
thanks,
greg k-h
I suppose anything is possible 😊 Here is the actual code if you want to have a look:
https://gist.github.com/iceaway/9900a9c2dd221eb836c5acda49f5d688
//Pelle
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 64 lines · Pelle Windestam
Quoted 64 lines
From: Greg KH <[email protected]>
Sent: Tuesday, 24 March 2020 13:31
To: Pelle Windestam <[email protected]>
Cc: [email protected]
Subject: Re: Accessingrpmsg_devicein sysfs attribute functionsQuoted 6 lines · Pelle Windestam
Quoted 6 lines · Pelle Windestam
Quoted 4 lines
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send
various commands from user space in Linux to a secondary CPU (A Cortex
M4).
Quoted 27 lines
Quoted 27 lines
I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init
function:Quoted 5 lines
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups memberset to my driver attribute groups array:
Quoted 11 lines
static struct
rpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from the
probe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*" argument:That is because you have created a driver attribute, not a device
attribute.
Quoted 12 lines
Quoted 2 lines
Create device attributes and you should be fine, they bind to the device your driver is passed.
Thanks! Changing them to device attributes was a breeze. Now I am slightly confused about the "struct device *" argument to the store/show functions. I was under the impression that this would be the "struct device" in the struct
rpmsg_device, (which would let me get the structrpmsg_deviceusingcontainer_of()?), but it appears to be some completely other device (by looking at the pointer address). I have tried searching the kernel code for similar example, but I have not found anything so far. It feels like I am stumbling a bit in the dark here, looking for myrpmsg_device.It's a bit hard to figure out what exactly you are doing here without a pointer to the code itself :)
Quoted 8 lines
Quoted 5 lines
Are you sure you aren't pointing the platform device accidentally?
thanks,
greg k-h
I suppose anything is possible 😊 Here is the actual code if you want to have a look:
https://gist.github.com/iceaway/9900a9c2dd221eb836c5acda49f5d688
Odd, that "should" work. But the pwm core is strange, I suggest posting it to the pwm driver mailing list and asking for help there, as there might be some odd "wrapper" structures involved here as can be seen by the pwm core sysfs file accesses.
good luck!
greg k-h
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Quoted 81 lines
To: Pelle Windestam <[email protected]>
Cc: [email protected]
Subject: Re: Accessingrpmsg_devicein sysfs attribute functionsQuoted 42 lines · Pelle Windestam
Quoted 42 lines
From: Greg KH <[email protected]>
Sent: Tuesday, 24 March 2020 13:31
To: Pelle Windestam <[email protected]>
Cc: [email protected]
Subject: Re: Accessingrpmsg_devicein sysfs attribute functionsQuoted 7 lines · Pelle Windestam
Quoted 7 lines · Pelle Windestam
Quoted 4 lines
Hi,
I am trying to develop a simple driver for the rpmsg bus, in order to send
various commands from user space in Linux to a secondary CPU (A Cortex
M4).
Quoted 27 lines
Quoted 27 lines
I'm trying to keep things as simple as possible, so my idea was to create a driver that just has a few attributes which can be set in /sys which would trigger commands to be sent to the M4 CPU. I have the communication between the CPU:s up and running, but where I'm having trouble moving forward is how to access the "struct
rpmsg_device*" that I need in order to communicate with the endpoint for the M4 CPU from the store/show function of the sysfs attributes. What my driver does is to register arpmsg_driverin the init
function:Quoted 5 lines
register_rpmsg_driver(&pwm_rpmsg_driver);the
device_drivermember of myrpmsg_driverstruct has its groups memberset to my driver attribute groups array:
Quoted 11 lines
static struct
rpmsg_driverpwm_rpmsg_driver= {
.probe =pwm_rpmsg_probe,
.remove =pwm_rpmsg_remove,
.callback =pwm_rpmsg_cb,
.id_table =pwm_rpmsg_device_id_table,
.drv = {
.groups =driver_pwm_groups,
.name = "pwm_rpmsg",
},
};Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
My issue is that that I am not sure how to access the struct "
rpmsg_device*" (i.e. from the
probe()function) in the show/store functions for the sysfs attributes, which have a "structdevice_driver*"argument:
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
That is because you have created a driver attribute, not a device
attribute.
Quoted 3 lines
Quoted 2 lines
Create device attributes and you should be fine, they bind to the device your driver is passed.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Thanks! Changing them to device attributes was a breeze. Now I am slightly confused about the "struct device *" argument to the store/show functions. I was under the impression that this would be the "struct device" in the struct
rpmsg_device, (which would let me get the structrpmsg_deviceusingcontainer_of()?), but it appears to be some completely other device (by looking at the pointer address). I have tried searching the kernel code for similar example, but I have not found anything so far. It feels like I am stumbling a bit in the dark here, looking for my
rpmsg_device.Quoted 11 lines
Quoted 9 lines
It's a bit hard to figure out what exactly you are doing here without a pointer to the code itself :)
Are you sure you aren't pointing the platform device accidentally?
thanks,
greg k-h
I suppose anything is possible 😊 Here is the actual code if you want to
have a look:
Quoted 9 lines
Odd, that "should" work. But the pwm core is strange, I suggest posting it to the pwm driver mailing list and asking for help there, as there might be some odd "wrapper" structures involved here as can be seen by the pwm core sysfs file accesses.
good luck!
I do no think that the PWM subsystem actually has anything to do with it, I only have "pwm" in the name because it will control a PWM signal via the M4 CPU. Otherwise it's all via the rpmsg driver. Rpmsg does not seem to have a mailing list of its own.
I will do some more digging. Thanks for the help!
//Pelle
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies