kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Sadanand Warrier <sadanandwarrier@gmail.com>
Cc: Kernelnewbies@kernelnewbies.org
Subject: Re: syfs question
Date: Wed, 26 Feb 2020 18:54:45 +0100	[thread overview]
Message-ID: <20200226175445.GB273509@kroah.com> (raw)
In-Reply-To: <CADJuq2wY77zcPWBdHKw17Z0pVgqaAg1uUfBTpv98wvDD3iK=yA@mail.gmail.com>

On Wed, Feb 26, 2020 at 10:15:43AM -0500, Sadanand Warrier wrote:
> If I call device_create with a existing class the device lands up in
> /sys/devices/virtual.

Yes, think of that as a "class device" (we used to have them as a
separate structure, now we don't).

> Using device_add I could populate the parent of the device and leave
> the class empty or provide a class and get the device to be created in
> the parent directory.

I don't understand what you mean here.

> What exactly is the significance of the" /sys/devices/virtual"  directory?
> Is this meant to carry devices of a specific type say something that is
> divorced from actual hardware?

Yes.  These are devices that do not have a "real" device backing them,
they are "virtual" devices in that the kernel creates them usually
because it needs a way for userspace to interact with the device.

A good example of this are tty "devices".  They are attached to a "real"
device in the system (pci, usb, platform, etc.) but the tty device
itself is just there to provide the common interaction with userspace
that userspace expects.

> Secondly a device created under /sys/devices/virtual has a uevent file that
> is populated like this.
> 
> -bash-4.2$ cat uevent
> MAJOR=13
> MINOR=63
> DEVNAME=input/mice

Nice device.

> -bash-4.2$
> 
> A device in a specific PCI slot has something like this instead..
> -bash-4.2$ cat
> /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.3/net/eth1/uevent
> INTERFACE=eth1
> IFINDEX=3
> 
> How is this file populated? Is it done by udev or is this done via a kernel
> call?

The uevent file is not written to (well, it can, but that does something
different), it is read from to show what the attributes that are set
when the uevent happens for that device.  It is populated by the
bus or class for that device by a bus/class specific callback to that
driver.

Have you read the LDD3 chapter on the driver model for the kernel?  It's
a bit out of date (well, really out of date), but the basics should
still be semi-relevant and might answer some of your questions here.

hope this helps,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2020-02-26 17:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 15:15 syfs question Sadanand Warrier
2020-02-26 17:54 ` Greg KH [this message]
2020-02-27 14:41   ` Sadanand Warrier
2020-02-28 12:37     ` Greg KH
2020-02-28 17:29       ` Sadanand Warrier

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=20200226175445.GB273509@kroah.com \
    --to=greg@kroah.com \
    --cc=Kernelnewbies@kernelnewbies.org \
    --cc=sadanandwarrier@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).