Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
From: Greg KH <greg@kroah.com>
To: Pelle Windestam <Pelle.Windestam@tagmaster.com>
Cc: "kernelnewbies@kernelnewbies.org" <kernelnewbies@kernelnewbies.org>
Subject: Re: Accessing rpmsg_device in sysfs attribute functions
Date: Tue, 24 Mar 2020 13:31:02 +0100
Message-ID: <20200324123102.GB2348009@kroah.com> (raw)
In-Reply-To: <a8357c5f3c4c4f29a7c5105b0306cd47@tagmaster.com>

On Tue, Mar 24, 2020 at 12:02:15PM +0000, Pelle Windestam wrote:
> > On Tue, Mar 24, 2020 at 05:34:44AM +0000, Pelle Windestam wrote:
> > > 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:
> > 
> > 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.

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
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24  5:34 Pelle Windestam
2020-03-24  6:31 ` Greg KH
2020-03-24  9:49   ` Martin Kaiser
2020-03-24 10:23     ` Greg KH
2020-03-24 12:02   ` Pelle Windestam
2020-03-24 12:31     ` Greg KH [this message]
2020-03-24 13:05       ` Pelle Windestam
2020-03-24 13:15         ` Greg KH
2020-03-24 13:35           ` Pelle Windestam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200324123102.GB2348009@kroah.com \
    --to=greg@kroah.com \
    --cc=Pelle.Windestam@tagmaster.com \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git