* [Xenomai-help] Passing data from device init to open function
@ 2007-10-10 11:37 Johan Borkhuis
2007-10-11 7:25 ` Johan Borkhuis
0 siblings, 1 reply; 4+ messages in thread
From: Johan Borkhuis @ 2007-10-10 11:37 UTC (permalink / raw)
To: Xenomai-help
Hello,
I am facing the following problem. During device initialization I am
filling a structure with device specific data. This structure is
provided to the Linux driver using pci_set_drvdata. Now I want my
Xenomai driver to have access to this data as well.
I am planning to use the dev_private area for this, and have it contain
a pointer to the same structure. The rtdm_dev_context structure is only
available after the open call and not in the device init function. So I
am searching for a safe way to transfer data from the device init
function to the open function.
Is there a way to transfer data from the device init function to the
open (or other) functions in such a way that it is possible to have
multiple devices that can be opened multiple times?
Kind regards,
Johan Borkhuis
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Passing data from device init to open function
2007-10-10 11:37 [Xenomai-help] Passing data from device init to open function Johan Borkhuis
@ 2007-10-11 7:25 ` Johan Borkhuis
2007-10-11 13:51 ` Jan Kiszka
0 siblings, 1 reply; 4+ messages in thread
From: Johan Borkhuis @ 2007-10-11 7:25 UTC (permalink / raw)
To: Xenomai-help
[-- Attachment #1: Type: text/plain, Size: 1528 bytes --]
This is something I try to avoid (replying to my own messages), but I'll
do it this time.
Johan Borkhuis wrote:
> Hello,
>
> I am facing the following problem. During device initialization I am
> filling a structure with device specific data. This structure is
> provided to the Linux driver using pci_set_drvdata. Now I want my
> Xenomai driver to have access to this data as well.
>
I made a fix for the problem I described, but I would also like to
propose a change to the rtdm_device structure.
What I did to solve this problem is add the following statement to my
device initialization function (the PCI probe function) after the
pci_set_drvdata:
MyDevice *unit;
....
pci_set_drvdata(dev, unit);
my_rtdm_device.device_id = (int)dev;
In my ops-functions I can now use the following statement to access the
device data:
int myrtdm_open_nrt(struct rtdm_dev_context *context,
rtdm_user_info_t *user_info,
int oflags)
{
MyDevice *unit = pci_get_drvdata((struct pci_dev
*)context->device->device_id);
This does work, but only as long as sizeof(int) == sizeof(<pointer>),
which is true on 32 bit systems, but not on 64 bit systems. So I would
like to add an extra pointer field to the rtdm_device structure,
pointing to some device-data to allow this to work on both 32 and 64 bit
systems.
I attached a diff-file containing a patch to rtdm_driver.h that makes
this change.
Kind regards,
Johan Borkhuis
[-- Attachment #2: xeno.diff --]
[-- Type: text/plain, Size: 597 bytes --]
diff -u -r org/xenomai-2.3.2/include/rtdm/rtdm_driver.h xenomai-2.3.2/include/rtdm/rtdm_driver.h
--- org/xenomai-2.3.2/include/rtdm/rtdm_driver.h 2007-02-19 15:09:49.000000000 +0100
+++ xenomai-2.3.2/include/rtdm/rtdm_driver.h 2007-10-11 09:15:36.000000000 +0200
@@ -428,6 +428,9 @@
/** Driver definable device ID */
int device_id;
+ /** Driver definable device data */
+ void *device_data;
+
/** Data stored by RTDM inside a registered device (internal use only) */
struct rtdm_dev_reserved reserved;
};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Passing data from device init to open function
2007-10-11 7:25 ` Johan Borkhuis
@ 2007-10-11 13:51 ` Jan Kiszka
2007-10-12 7:38 ` Johan Borkhuis
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2007-10-11 13:51 UTC (permalink / raw)
To: Johan Borkhuis; +Cc: Xenomai-help
Johan Borkhuis wrote:
> This is something I try to avoid (replying to my own messages), but I'll
> do it this time.
>
> Johan Borkhuis wrote:
>> Hello,
>>
>> I am facing the following problem. During device initialization I am
>> filling a structure with device specific data. This structure is
>> provided to the Linux driver using pci_set_drvdata. Now I want my
>> Xenomai driver to have access to this data as well.
>>
>
> I made a fix for the problem I described, but I would also like to
> propose a change to the rtdm_device structure.
>
> What I did to solve this problem is add the following statement to my
> device initialization function (the PCI probe function) after the
> pci_set_drvdata:
>
> MyDevice *unit;
> ....
> pci_set_drvdata(dev, unit);
> my_rtdm_device.device_id = (int)dev;
>
> In my ops-functions I can now use the following statement to access the
> device data:
>
> int myrtdm_open_nrt(struct rtdm_dev_context *context,
> rtdm_user_info_t *user_info,
> int oflags)
> {
> MyDevice *unit = pci_get_drvdata((struct pci_dev
> *)context->device->device_id);
>
> This does work, but only as long as sizeof(int) == sizeof(<pointer>),
> which is true on 32 bit systems, but not on 64 bit systems. So I would
> like to add an extra pointer field to the rtdm_device structure,
> pointing to some device-data to allow this to work on both 32 and 64 bit
> systems.
>
> I attached a diff-file containing a patch to rtdm_driver.h that makes
> this change.
Hmm, that's what we had in an early RTDM version, but the more common
use-case turned out to be
per_device_data = my_per_device_data[device->device_id];
where my_per_device_data is a global variable, typical a data structure
containing all the required per-device information.
Anyway, as you are adding this field, not replacing the ID with it, I
think I'm going to merge this.
Thanks,
Jan
--
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Xenomai-help] Passing data from device init to open function
2007-10-11 13:51 ` Jan Kiszka
@ 2007-10-12 7:38 ` Johan Borkhuis
0 siblings, 0 replies; 4+ messages in thread
From: Johan Borkhuis @ 2007-10-12 7:38 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Xenomai-help
Jan Kiszka wrote:
>> This does work, but only as long as sizeof(int) == sizeof(<pointer>),
>> which is true on 32 bit systems, but not on 64 bit systems. So I would
>> like to add an extra pointer field to the rtdm_device structure,
>> pointing to some device-data to allow this to work on both 32 and 64 bit
>> systems.
>>
> Hmm, that's what we had in an early RTDM version, but the more common
> use-case turned out to be
>
> per_device_data = my_per_device_data[device->device_id];
>
> where my_per_device_data is a global variable, typical a data structure
> containing all the required per-device information.
>
I considered that as well. The main problem is that you have to
statically allocate the memory based on the maximum number of devices
you want to support, and I prefer to allocate the memory for each
available device.
> Anyway, as you are adding this field, not replacing the ID with it, I
> think I'm going to merge this.
>
One should have a very good reason to replace or remove a field in a
system-structure, and this is just an addition to the structure, so no
real need to replace anything.
Thanks.
Kind regards,
Johan Borkhuis
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-12 7:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-10 11:37 [Xenomai-help] Passing data from device init to open function Johan Borkhuis
2007-10-11 7:25 ` Johan Borkhuis
2007-10-11 13:51 ` Jan Kiszka
2007-10-12 7:38 ` Johan Borkhuis
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.