linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Device tree node to major/minor?
@ 2012-11-20 22:23 Simon Glass
  2012-11-20 22:32 ` Grant Likely
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-11-20 22:23 UTC (permalink / raw)
  To: lk; +Cc: Devicetree Discuss, Che-liang Chiou

Hi,

I hope this is a stupid question with an easy answer, but I cannot find it.

I have a device tree node for an mmc block device and I want to use
that block device from another driver. I have a phandle which lets me
get the node of the mmc device, but I am not sure how to convert that
into a block_device. In order to do so, I think I need a major/minor
number. Of course the phandle might in fact point to a SCSI driver and
I want that to work correctly also.

I imagine I might be able to search through the wonders of sysfs in
user space, but is there a better way?

Thanks,
Simon

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

* Re: Device tree node to major/minor?
  2012-11-20 22:23 Device tree node to major/minor? Simon Glass
@ 2012-11-20 22:32 ` Grant Likely
  2012-11-20 23:48   ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2012-11-20 22:32 UTC (permalink / raw)
  To: Simon Glass; +Cc: lk, Devicetree Discuss, Che-liang Chiou

On Tue, Nov 20, 2012 at 10:23 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi,
>
> I hope this is a stupid question with an easy answer, but I cannot find it.
>
> I have a device tree node for an mmc block device and I want to use
> that block device from another driver. I have a phandle which lets me
> get the node of the mmc device, but I am not sure how to convert that
> into a block_device. In order to do so, I think I need a major/minor
> number. Of course the phandle might in fact point to a SCSI driver and
> I want that to work correctly also.
>
> I imagine I might be able to search through the wonders of sysfs in
> user space, but is there a better way?

Do you /want/ to do it from userspace? What is your use case? Mounting
the rootfs?

Regardless, userspace can monitor the uevents when devices are added
(that's what udev does) and watch for the full path of the node you
want in the uevent attribute. Then you can look for the child device
with the block major/minor numbers in it.

g.

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

* Re: Device tree node to major/minor?
  2012-11-20 22:32 ` Grant Likely
@ 2012-11-20 23:48   ` Simon Glass
  2012-11-21 15:47     ` Grant Likely
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-11-20 23:48 UTC (permalink / raw)
  To: Grant Likely; +Cc: lk, Devicetree Discuss, Che-liang Chiou

Hi Grant,

On Tue, Nov 20, 2012 at 2:32 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
> On Tue, Nov 20, 2012 at 10:23 PM, Simon Glass <sjg@chromium.org> wrote:
>> Hi,
>>
>> I hope this is a stupid question with an easy answer, but I cannot find it.
>>
>> I have a device tree node for an mmc block device and I want to use
>> that block device from another driver. I have a phandle which lets me
>> get the node of the mmc device, but I am not sure how to convert that
>> into a block_device. In order to do so, I think I need a major/minor
>> number. Of course the phandle might in fact point to a SCSI driver and
>> I want that to work correctly also.
>>
>> I imagine I might be able to search through the wonders of sysfs in
>> user space, but is there a better way?
>
> Do you /want/ to do it from userspace? What is your use case? Mounting
> the rootfs?

The use case is storing some raw data on a block device from within a
driver in the kernel. It is used to keep track of the verified boot
state.

>
> Regardless, userspace can monitor the uevents when devices are added
> (that's what udev does) and watch for the full path of the node you
> want in the uevent attribute. Then you can look for the child device
> with the block major/minor numbers in it.

So is there a way to do this entirely in the kernel ex post? It might
need to happen during kernel boot, before user space.

>
> g.

Thanks,
Simon

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

* Re: Device tree node to major/minor?
  2012-11-20 23:48   ` Simon Glass
@ 2012-11-21 15:47     ` Grant Likely
  2012-11-21 20:48       ` Simon Glass
  0 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2012-11-21 15:47 UTC (permalink / raw)
  To: Simon Glass; +Cc: lk, Devicetree Discuss, Che-liang Chiou

On Tue, 20 Nov 2012 15:48:24 -0800, Simon Glass <sjg@chromium.org> wrote:
> Hi Grant,
> 
> On Tue, Nov 20, 2012 at 2:32 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
> > On Tue, Nov 20, 2012 at 10:23 PM, Simon Glass <sjg@chromium.org> wrote:
> >> Hi,
> >>
> >> I hope this is a stupid question with an easy answer, but I cannot find it.
> >>
> >> I have a device tree node for an mmc block device and I want to use
> >> that block device from another driver. I have a phandle which lets me
> >> get the node of the mmc device, but I am not sure how to convert that
> >> into a block_device. In order to do so, I think I need a major/minor
> >> number. Of course the phandle might in fact point to a SCSI driver and
> >> I want that to work correctly also.
> >>
> >> I imagine I might be able to search through the wonders of sysfs in
> >> user space, but is there a better way?
> >
> > Do you /want/ to do it from userspace? What is your use case? Mounting
> > the rootfs?
> 
> The use case is storing some raw data on a block device from within a
> driver in the kernel. It is used to keep track of the verified boot
> state.
> 
> >
> > Regardless, userspace can monitor the uevents when devices are added
> > (that's what udev does) and watch for the full path of the node you
> > want in the uevent attribute. Then you can look for the child device
> > with the block major/minor numbers in it.
> 
> So is there a way to do this entirely in the kernel ex post? It might
> need to happen during kernel boot, before user space.

Yes, it is certainly doable within the kernel. First, you'll need to use
a notifier to get called back whenever a new device is created. Then
you'll need to look at the dev->of_node(->full_name) to see if it is the
node you actually want. You might need/want to resolve it from an alias
or something, but I presume you already have a way to find the
device_node before seaching for a struct device.

g.

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

* Re: Device tree node to major/minor?
  2012-11-21 15:47     ` Grant Likely
@ 2012-11-21 20:48       ` Simon Glass
  2012-11-21 23:07         ` Grant Likely
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-11-21 20:48 UTC (permalink / raw)
  To: Grant Likely; +Cc: lk, Devicetree Discuss, Che-liang Chiou

Hi Grant,

On Wed, Nov 21, 2012 at 7:47 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
> On Tue, 20 Nov 2012 15:48:24 -0800, Simon Glass <sjg@chromium.org> wrote:
>> Hi Grant,
>>
>> On Tue, Nov 20, 2012 at 2:32 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
>> > On Tue, Nov 20, 2012 at 10:23 PM, Simon Glass <sjg@chromium.org> wrote:
>> >> Hi,
>> >>
>> >> I hope this is a stupid question with an easy answer, but I cannot find it.
>> >>
>> >> I have a device tree node for an mmc block device and I want to use
>> >> that block device from another driver. I have a phandle which lets me
>> >> get the node of the mmc device, but I am not sure how to convert that
>> >> into a block_device. In order to do so, I think I need a major/minor
>> >> number. Of course the phandle might in fact point to a SCSI driver and
>> >> I want that to work correctly also.
>> >>
>> >> I imagine I might be able to search through the wonders of sysfs in
>> >> user space, but is there a better way?
>> >
>> > Do you /want/ to do it from userspace? What is your use case? Mounting
>> > the rootfs?
>>
>> The use case is storing some raw data on a block device from within a
>> driver in the kernel. It is used to keep track of the verified boot
>> state.
>>
>> >
>> > Regardless, userspace can monitor the uevents when devices are added
>> > (that's what udev does) and watch for the full path of the node you
>> > want in the uevent attribute. Then you can look for the child device
>> > with the block major/minor numbers in it.
>>
>> So is there a way to do this entirely in the kernel ex post? It might
>> need to happen during kernel boot, before user space.
>
> Yes, it is certainly doable within the kernel. First, you'll need to use
> a notifier to get called back whenever a new device is created. Then
> you'll need to look at the dev->of_node(->full_name) to see if it is the
> node you actually want. You might need/want to resolve it from an alias
> or something, but I presume you already have a way to find the
> device_node before seaching for a struct device.

OK thank you. Was hoping to find a simple way to find a block device
from a device tree node (yes I know the right one) but I suppose in
general this is impossible, since nodes may create more than one
device, and each has its own data structures leading to the block
device.

So it seems like a notifier is the best way. Thanks for looking at this Grant.

Regards,
Simon

>
> g.

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

* Re: Device tree node to major/minor?
  2012-11-21 20:48       ` Simon Glass
@ 2012-11-21 23:07         ` Grant Likely
  0 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2012-11-21 23:07 UTC (permalink / raw)
  To: Simon Glass; +Cc: lk, Devicetree Discuss, Che-liang Chiou

On Wed, Nov 21, 2012 at 8:48 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Grant,
>
> On Wed, Nov 21, 2012 at 7:47 AM, Grant Likely <grant.likely@secretlab.ca> wrote:
>> On Tue, 20 Nov 2012 15:48:24 -0800, Simon Glass <sjg@chromium.org> wrote:
>>> Hi Grant,
>>>
>>> On Tue, Nov 20, 2012 at 2:32 PM, Grant Likely <grant.likely@secretlab.ca> wrote:
>>> > On Tue, Nov 20, 2012 at 10:23 PM, Simon Glass <sjg@chromium.org> wrote:
>>> >> Hi,
>>> >>
>>> >> I hope this is a stupid question with an easy answer, but I cannot find it.
>>> >>
>>> >> I have a device tree node for an mmc block device and I want to use
>>> >> that block device from another driver. I have a phandle which lets me
>>> >> get the node of the mmc device, but I am not sure how to convert that
>>> >> into a block_device. In order to do so, I think I need a major/minor
>>> >> number. Of course the phandle might in fact point to a SCSI driver and
>>> >> I want that to work correctly also.
>>> >>
>>> >> I imagine I might be able to search through the wonders of sysfs in
>>> >> user space, but is there a better way?
>>> >
>>> > Do you /want/ to do it from userspace? What is your use case? Mounting
>>> > the rootfs?
>>>
>>> The use case is storing some raw data on a block device from within a
>>> driver in the kernel. It is used to keep track of the verified boot
>>> state.
>>>
>>> >
>>> > Regardless, userspace can monitor the uevents when devices are added
>>> > (that's what udev does) and watch for the full path of the node you
>>> > want in the uevent attribute. Then you can look for the child device
>>> > with the block major/minor numbers in it.
>>>
>>> So is there a way to do this entirely in the kernel ex post? It might
>>> need to happen during kernel boot, before user space.
>>
>> Yes, it is certainly doable within the kernel. First, you'll need to use
>> a notifier to get called back whenever a new device is created. Then
>> you'll need to look at the dev->of_node(->full_name) to see if it is the
>> node you actually want. You might need/want to resolve it from an alias
>> or something, but I presume you already have a way to find the
>> device_node before seaching for a struct device.
>
> OK thank you. Was hoping to find a simple way to find a block device
> from a device tree node (yes I know the right one) but I suppose in
> general this is impossible, since nodes may create more than one
> device, and each has its own data structures leading to the block
> device.
>
> So it seems like a notifier is the best way. Thanks for looking at this Grant.

It's certainly the least invasive way. Otherwise you need to hook into
the DT device creation code.

g.


--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

end of thread, other threads:[~2012-11-22 20:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-20 22:23 Device tree node to major/minor? Simon Glass
2012-11-20 22:32 ` Grant Likely
2012-11-20 23:48   ` Simon Glass
2012-11-21 15:47     ` Grant Likely
2012-11-21 20:48       ` Simon Glass
2012-11-21 23:07         ` Grant Likely

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).