2004-04-12 20:34:35

by Michael Hunold

[permalink] [raw]
Subject: Problems adding sysfs support to dvb subsystem

Hello all,

I'm currently trying to add proper sysfs support to the dvb subsystem,
but I'm stuck because I don't know if I'm on the right way. 8-(

From the docs and existing drivers I read so far I concluded that
adding a new class via class_register(&dvb_class) is the way to go.

With this I get:
/sys/class/dvb/

Now there can be several dvb adapters present in the system, each of
this adapter can have several "subsystems" (video decoder, audio
decoder, frontend ("tuner"), ...)

New adapters register themselves via dvb_register_adapter() and if this
was succesfull, they register their subsystems via dvb_register_device().

What I'd like to have is something like this, so I can add attributes to
the frontend for example:
/sys/class/dvb/adapter0/frontend0/

I wasn't able to find a driver that provides this simple "hierarchical"
order, so I did some experiments with little luck.

Creating this hierarchical order manually (like for "devfs") didn't
work, I get
> find: /sys/class/dvb/adapter0/frontend0: No such file or directory
errors upon access:

> sprintf((void*)&dvbdev->class_device.class_id, "adapter%d/%s%d",
adap->num, dnames[type], id);
> class_device_register(&dvbdev->class_device);

I then tried to find a way to first use class_device_register() with
adapter0 (which works of course), and then with class_device_register()
again with frontend0, but obviously I cannot connect these two
instances, because adapter doesn't have a "struct device" where I can
point the class_device.dev entry from frontend0 to... 8-(

I'd really appreciate if somebody could give me some design hints or
point me to some documentation that would help me out.

Thanks!
Michael.


2004-04-12 21:21:43

by Stephen Hemminger

[permalink] [raw]
Subject: Re: Problems adding sysfs support to dvb subsystem

On Mon, 12 Apr 2004 22:34:35 +0200
Michael Hunold <[email protected]> wrote:

> Hello all,
>
> I'm currently trying to add proper sysfs support to the dvb subsystem,
> but I'm stuck because I don't know if I'm on the right way. 8-(
>
> From the docs and existing drivers I read so far I concluded that
> adding a new class via class_register(&dvb_class) is the way to go.
>
> With this I get:
> /sys/class/dvb/
>
> Now there can be several dvb adapters present in the system, each of
> this adapter can have several "subsystems" (video decoder, audio
> decoder, frontend ("tuner"), ...)

The sysfs directory layout is a logical representation of the underlying
data structures in the kernel. Each directory (with exception of attribute
groups) has a 1:1 relation ship with a kobject.


> New adapters register themselves via dvb_register_adapter() and if this
> was succesfull, they register their subsystems via dvb_register_device().
>
> What I'd like to have is something like this, so I can add attributes to
> the frontend for example:
> /sys/class/dvb/adapter0/frontend0/

Is there a dvb_adapter structure and a separate dvb_frontend
structure? Are you prepared to ref count and dynamically allocate both
of them?

>
> I wasn't able to find a driver that provides this simple "hierarchical"
> order, so I did some experiments with little luck.
>
> Creating this hierarchical order manually (like for "devfs") didn't
> work, I get
> > find: /sys/class/dvb/adapter0/frontend0: No such file or directory
> errors upon access:
>
> > sprintf((void*)&dvbdev->class_device.class_id, "adapter%d/%s%d",
> adap->num, dnames[type], id);
> > class_device_register(&dvbdev->class_device);
>
> I then tried to find a way to first use class_device_register() with
> adapter0 (which works of course), and then with class_device_register()
> again with frontend0, but obviously I cannot connect these two
> instances, because adapter doesn't have a "struct device" where I can
> point the class_device.dev entry from frontend0 to... 8-(
>
> I'd really appreciate if somebody could give me some design hints or
> point me to some documentation that would help me out.
>
> Thanks!
> Michael.
>

You could use attribute groups if all you want to do is provide some
logical breakout of attributes inside one kobject. That is what I did
to put the wireless and netstat elements in different directories for the
network devices.

Stephen Hemminger mailto:[email protected]
Open Source Development Lab http://developer.osdl.org/shemminger

2004-04-12 21:42:55

by Greg KH

[permalink] [raw]
Subject: Re: Problems adding sysfs support to dvb subsystem

On Mon, Apr 12, 2004 at 10:34:35PM +0200, Michael Hunold wrote:
>
> What I'd like to have is something like this, so I can add attributes to
> the frontend for example:
> /sys/class/dvb/adapter0/frontend0/
>
> I wasn't able to find a driver that provides this simple "hierarchical"
> order, so I did some experiments with little luck.
>
> Creating this hierarchical order manually (like for "devfs") didn't
> work, I get
> > find: /sys/class/dvb/adapter0/frontend0: No such file or directory
> errors upon access:
>
> > sprintf((void*)&dvbdev->class_device.class_id, "adapter%d/%s%d",
> adap->num, dnames[type], id);
> > class_device_register(&dvbdev->class_device);

No, you can't create subdirectories directly by just adding a '/' to the
name of the class device, sorry. You will have to create a kobject for
the directory, and create the attributes in that kobject, like
networking did.

Yeah, it's a bit of a pain, but creating subdirectories in an easy
manner is on the TODO list for the driver core for 2.7.

If you want to get up and running quickly, which would not require you
to fix up any lifetime rules for your dvb drivers, you could implement
the class_simple interface, like a lot of other driver subsystems
currently are doing, and then in 2.7 convert over to a proper driver
model conversion. I say this as I am only guessing as to what your
lifetime rules are for your dvb devices and drivers...

Hope this helps,

greg k-h