All of lore.kernel.org
 help / color / mirror / Atom feed
* What's the purpose of subsys_interface in linux/device.h?
@ 2016-12-15 15:16 Perr Zhang
       [not found] ` <CAJ1xhMUbt7+eEYGjoBkAGY+_ehN1UqkWM-sRp3mn8_ss7+jebA@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Perr Zhang @ 2016-12-15 15:16 UTC (permalink / raw)
  To: kernelnewbies

Hi, I am reading the code here: device_add()->bus_probe_device()
the source code of bus_probe_device() is:

void bus_probe_device(struct device *dev)
{
        struct bus_type *bus = dev->bus;
        struct subsys_interface *sif;
        ......
        mutex_lock(&bus->p->mutex);
        list_for_each_entry(sif, &bus->p->interfaces, node)
                if (sif->add_dev)
                        sif->add_dev(dev, sif);
        mutex_unlock(&bus->p->mutex);
}
location: http://lxr.free-electrons.com/source/drivers/base/bus.c#L543

Problem:
I have already read the relational code of struct subsys_interface, and can't
figure out the purpose of struce subsys_interface and its method add_dev()

Thank you,

--
Perr

^ permalink raw reply	[flat|nested] 2+ messages in thread

* What's the purpose of subsys_interface in linux/device.h?
       [not found]   ` <159066c42b2.f4142d4027504.6385011432858010451@zoho.com>
@ 2016-12-16 10:44     ` Alexander Kapshuk
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Kapshuk @ 2016-12-16 10:44 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Dec 16, 2016 at 8:57 AM, Perr Zhang <strongbox8@zoho.com> wrote:
>  ---- On Fri, 16 Dec 2016 00:26:24 +0800 Alexander Kapshuk <alexander.kapshuk@gmail.com> wrote ----
>  >
>  > Having looked at the pieces of source code below, it appears that
>  > subsys_interface is the means to expose specific functionality of a
>  > subsystem/class of devices, as the commentary below states.
>  > include/linux/device.h:331,350
>  > /**
>  >  * struct subsys_interface - interfaces to device functions
>  >  * @name:       name of the device function
>  >  * @subsys:     subsytem of the devices to attach to
>  >  * @node:       the list of functions registered at the subsystem
>  >  * @add_dev:    device hookup to device function handler
>  >  * @remove_dev: device hookup to device function handler
>  >  *
>  >  * Simple interfaces attached to a subsystem. Multiple interfaces can
>  >  * attach to a subsystem and its devices. Unlike drivers, they do not
>  >  * exclusively claim or control devices. Interfaces usually represent
>  >  * a specific functionality of a subsystem/class of devices.
>  >  */
>  > struct subsys_interface {
>  > const char *name;
>  > struct bus_type *subsys;
>  > struct list_head node;
>  > int (*add_dev)(struct device *dev, struct subsys_interface *sif);
>  > void (*remove_dev)(struct device *dev, struct subsys_interface *sif);
>  > };
>  >
>  > Here's sample usage:
>  > arch/tile/kernel/sysfs.c:211,216
>  > static struct subsys_interface hv_stats_interface = {
>  > .name = "hv_stats",
>  > .subsys = &cpu_subsys,
>  > .add_dev = hv_stats_device_add,
>  > .remove_dev = hv_stats_device_remove,
>  > };
>  >
>  > And the add_dev method, whose main purpose seems to be creating a
>  > sysfs file for a particular device:
>  > arch/tile/kernel/sysfs.c:189,199
>  > static int hv_stats_device_add(struct device *dev, struct subsys_interface *sif)
>  > {
>  > int err, cpu = dev->id;
>  >
>  > if (!cpu_online(cpu))
>  > return 0;
>  >
>  > err = sysfs_create_file(&dev->kobj, &dev_attr_hv_stats.attr);
>  >
>  > return err;
>  > }
>  >
>  > Here's an example of the hv_stats_interface being registered with the subsystem:
>  > arch/tile/kernel/sysfs.c:261
>  > err = subsys_interface_register(&hv_stats_interface);
>  >
>  > Hopefully, other members of this list will offer a better informed
>  > explanation than that given here.
>
> Sorry for sending email repeatedly.
> I have also read the code:
> device_add() ->  bus_add_device() -> device_add_attrs(bus, dev) -> device_create_file(dev, &bus->dev_attrs[i])
> Since the attribute file/functionality could be added through bus->dev_attrs, why not to do it in this way?
>

My understanding is that an interface is like a protocol that has been
put in place to enable a particular set of functions within a given
subsystem or device model.

I am sending a copy of this email to the list as well, so you can
hopefully get a better informed reply to your query.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-16 10:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-15 15:16 What's the purpose of subsys_interface in linux/device.h? Perr Zhang
     [not found] ` <CAJ1xhMUbt7+eEYGjoBkAGY+_ehN1UqkWM-sRp3mn8_ss7+jebA@mail.gmail.com>
     [not found]   ` <159066c42b2.f4142d4027504.6385011432858010451@zoho.com>
2016-12-16 10:44     ` Alexander Kapshuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.