All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] rtdm_iomap_to_user question
@ 2007-05-10 18:16 Zhang, Haobo
  2007-05-10 21:39 ` Jan Kiszka
  0 siblings, 1 reply; 6+ messages in thread
From: Zhang, Haobo @ 2007-05-10 18:16 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

Hi,

I am currently working on a project which is running on a PowerPC
platform. In my rtdm driver, I use "rtdm_iomap_to_user" to map a few I/O
memory locations to be accessed from my application. All the function
calls seem to work (no error code returned). But my application fails to
use these pointers to manipulate any I/O. Is there any restrictions I
have to be aware in order to use those mapped I/O mem? I am new to
xenomai. I would really appreciate any help to this. 

Best Regards,
Haobo Zhang



[-- Attachment #2: Type: text/html, Size: 1051 bytes --]

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

* Re: [Xenomai-help] rtdm_iomap_to_user question
  2007-05-10 18:16 [Xenomai-help] rtdm_iomap_to_user question Zhang, Haobo
@ 2007-05-10 21:39 ` Jan Kiszka
  2007-05-11  4:39   ` Zhang, Haobo
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kiszka @ 2007-05-10 21:39 UTC (permalink / raw)
  To: Zhang, Haobo; +Cc: xenomai, stelian

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

Zhang, Haobo wrote:
> Hi,
> 
> I am currently working on a project which is running on a PowerPC
> platform. In my rtdm driver, I use "rtdm_iomap_to_user" to map a few I/O
> memory locations to be accessed from my application. All the function
> calls seem to work (no error code returned). But my application fails to
> use these pointers to manipulate any I/O. Is there any restrictions I
> have to be aware in order to use those mapped I/O mem? I am new to
> xenomai. I would really appreciate any help to this. 

Maybe you can post code or relevant code snippets so that we can have a
look. As I personally haven't work with this particular service yet, I
put Stelian in CC who contributed it and might already have some
suggestion. But, again, code talks much more.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

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

* Re: [Xenomai-help] rtdm_iomap_to_user question
  2007-05-10 21:39 ` Jan Kiszka
@ 2007-05-11  4:39   ` Zhang, Haobo
  2007-05-11 16:22     ` Jan Kiszka
  0 siblings, 1 reply; 6+ messages in thread
From: Zhang, Haobo @ 2007-05-11  4:39 UTC (permalink / raw)
  To: jan.kiszka; +Cc: xenomai, stelian

Hi Jan,

Thank you so much for your reply!

In my driver, I wrote:

int map_io( struct gpiodrv_context *dev_context, rtdm_user_info_t
*user_info, struct MAPPED_IO *io )
{
	int ret;

	if ((dev_context == 0) || (user_info == 0) || (io == 0))
		return -EFAULT;

	if (dev_context->mapped_user_info != 0)
	{
		if ((ret = gpio_unmap_io( dev_context )) != 0)
			return ret;
	}

	dev_context->mapped_user_info = user_info;

	ret = rtdm_iomap_to_user( user_info, MPC52xx_PA(
MPC52xx_GPIO_WKUP_OFFSET + 0x0C ),
		1, PROT_READ | PROT_WRITE, (void
**)&(io->gpio_heart_beat), NULL, NULL );
	
	if (ret != 0)
		goto __ERROR;
	else
		dev_context->mapped_heart_beat = (void
*)io->gpio_heart_beat;

	return 0;

__ERROR:

	gpio_unmap_io( dev_context );
	return ret;
} 

In the application, I wrote:

int main(int argc, char *argv[]) 
{
	int dev_gpio;
	struct MAPPED_IO gpio;

	signal(SIGTERM, clean_exit);	
	signal(SIGINT, clean_exit);	
	
	mlockall( MCL_CURRENT | MCL_FUTURE );

	rt_task_shadow( &mainapp, "mainapp", 1, 0 );

	dev_gpio = rt_dev_open( "gpio", 0 );
	if (dev_gpio < 0)
	{
		return -1;
	}
	
	gpio.gpio_heart_beat = NULL;

	if (rt_dev_ioctl( dev_gpio, 1, &gpio ) != 0)
	{
		return -1;
	}

	gpio.gpio_heart_beat[0] = 0x01;

	...
}

I also tried another way by opening "/dev/mem" and then using "mmap" to
map the I/O memory addresses in the application. It worked! 
I am very curious about why "rtdm_iomap_to_user" did not work for me. 

Thanks,
Haobo

-----Original Message-----
From: jan.kiszka@domain.hid [mailto:jan.kiszka@domain.hid
Sent: May 10, 2007 5:40 PM
To: Zhang, Haobo
Cc: xenomai@xenomai.org; stelian@domain.hid
Subject: Re: [Xenomai-help] rtdm_iomap_to_user question

Zhang, Haobo wrote:
> Hi,
> 
> I am currently working on a project which is running on a PowerPC 
> platform. In my rtdm driver, I use "rtdm_iomap_to_user" to map a few 
> I/O memory locations to be accessed from my application. All the 
> function calls seem to work (no error code returned). But my 
> application fails to use these pointers to manipulate any I/O. Is 
> there any restrictions I have to be aware in order to use those mapped

> I/O mem? I am new to xenomai. I would really appreciate any help to
this.

Maybe you can post code or relevant code snippets so that we can have a
look. As I personally haven't work with this particular service yet, I
put Stelian in CC who contributed it and might already have some
suggestion. But, again, code talks much more.

Jan



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

* Re: [Xenomai-help] rtdm_iomap_to_user question
  2007-05-11  4:39   ` Zhang, Haobo
@ 2007-05-11 16:22     ` Jan Kiszka
  2007-05-12 23:15       ` Zhang, Haobo
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Kiszka @ 2007-05-11 16:22 UTC (permalink / raw)
  To: Zhang, Haobo; +Cc: xenomai, stelian

[-- Attachment #1: Type: text/plain, Size: 2455 bytes --]

Zhang, Haobo wrote:
> Hi Jan,
> 
> Thank you so much for your reply!
> 
> In my driver, I wrote:
> 
> int map_io( struct gpiodrv_context *dev_context, rtdm_user_info_t
> *user_info, struct MAPPED_IO *io )
> {
> 	int ret;
> 
> 	if ((dev_context == 0) || (user_info == 0) || (io == 0))
> 		return -EFAULT;
> 
> 	if (dev_context->mapped_user_info != 0)
> 	{
> 		if ((ret = gpio_unmap_io( dev_context )) != 0)
> 			return ret;
> 	}
> 
> 	dev_context->mapped_user_info = user_info;
> 
> 	ret = rtdm_iomap_to_user( user_info, MPC52xx_PA(
> MPC52xx_GPIO_WKUP_OFFSET + 0x0C ),
> 		1, PROT_READ | PROT_WRITE, (void
> **)&(io->gpio_heart_beat), NULL, NULL );

Hmm, hmm. Looking at our code and the kernel again I would say we should
catch non-page-aligned requests like this and document this pitfall better.

The mapping code always assumes page-alignment and rounds your physical
address down. So what likely happened here is that you got a mapping,
but with unexpected offset (gpio_heart_beat should point to MPC52xx_PA).

> 	
> 	if (ret != 0)
> 		goto __ERROR;
> 	else
> 		dev_context->mapped_heart_beat = (void
> *)io->gpio_heart_beat;
> 
> 	return 0;
> 
> __ERROR:
> 
> 	gpio_unmap_io( dev_context );
> 	return ret;
> } 
> 
> In the application, I wrote:
> 
> int main(int argc, char *argv[]) 
> {
> 	int dev_gpio;
> 	struct MAPPED_IO gpio;
> 
> 	signal(SIGTERM, clean_exit);	
> 	signal(SIGINT, clean_exit);	
> 	
> 	mlockall( MCL_CURRENT | MCL_FUTURE );
> 
> 	rt_task_shadow( &mainapp, "mainapp", 1, 0 );
> 
> 	dev_gpio = rt_dev_open( "gpio", 0 );
> 	if (dev_gpio < 0)
> 	{
> 		return -1;
> 	}
> 	
> 	gpio.gpio_heart_beat = NULL;
> 
> 	if (rt_dev_ioctl( dev_gpio, 1, &gpio ) != 0)
> 	{
> 		return -1;
> 	}
> 
> 	gpio.gpio_heart_beat[0] = 0x01;
> 
> 	...
> }
> 
> I also tried another way by opening "/dev/mem" and then using "mmap" to
> map the I/O memory addresses in the application. It worked! 
> I am very curious about why "rtdm_iomap_to_user" did not work for me. 

When you do precisely the same odd-numbered mapping via mmap on
/dev/mem, you do get the right address at gpio_heart_beat (check if the
start address ends with 0x0b0c)?

We either have to improve rtdm_iomap/mmap_to_user in this regard or
catch unaligned requests. Probably it's easier to catch it so that the
driver writer also realises that this is always about mapping full pages...

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 250 bytes --]

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

* Re: [Xenomai-help] rtdm_iomap_to_user question
  2007-05-11 16:22     ` Jan Kiszka
@ 2007-05-12 23:15       ` Zhang, Haobo
  2007-05-13 10:24         ` Jan Kiszka
  0 siblings, 1 reply; 6+ messages in thread
From: Zhang, Haobo @ 2007-05-12 23:15 UTC (permalink / raw)
  To: jan.kiszka; +Cc: xenomai, stelian

Thanks, Jan. It is fixed after I modified my code as you suggested.

Best Regards,
Haobo Zhang 

-----Original Message-----
From: jan.kiszka@domain.hid [mailto:jan.kiszka@domain.hid
Sent: May 11, 2007 12:22 PM
To: Zhang, Haobo
Cc: xenomai@xenomai.org; stelian@domain.hid
Subject: Re: [Xenomai-help] rtdm_iomap_to_user question

Zhang, Haobo wrote:
> Hi Jan,
> 
> Thank you so much for your reply!
> 
> In my driver, I wrote:
> 
> int map_io( struct gpiodrv_context *dev_context, rtdm_user_info_t 
> *user_info, struct MAPPED_IO *io ) {
> 	int ret;
> 
> 	if ((dev_context == 0) || (user_info == 0) || (io == 0))
> 		return -EFAULT;
> 
> 	if (dev_context->mapped_user_info != 0)
> 	{
> 		if ((ret = gpio_unmap_io( dev_context )) != 0)
> 			return ret;
> 	}
> 
> 	dev_context->mapped_user_info = user_info;
> 
> 	ret = rtdm_iomap_to_user( user_info, MPC52xx_PA( 
> MPC52xx_GPIO_WKUP_OFFSET + 0x0C ),
> 		1, PROT_READ | PROT_WRITE, (void
> **)&(io->gpio_heart_beat), NULL, NULL );

Hmm, hmm. Looking at our code and the kernel again I would say we should
catch non-page-aligned requests like this and document this pitfall
better.

The mapping code always assumes page-alignment and rounds your physical
address down. So what likely happened here is that you got a mapping,
but with unexpected offset (gpio_heart_beat should point to MPC52xx_PA).

> 	
> 	if (ret != 0)
> 		goto __ERROR;
> 	else
> 		dev_context->mapped_heart_beat = (void
*)io->gpio_heart_beat;
> 
> 	return 0;
> 
> __ERROR:
> 
> 	gpio_unmap_io( dev_context );
> 	return ret;
> }
> 
> In the application, I wrote:
> 
> int main(int argc, char *argv[])
> {
> 	int dev_gpio;
> 	struct MAPPED_IO gpio;
> 
> 	signal(SIGTERM, clean_exit);	
> 	signal(SIGINT, clean_exit);	
> 	
> 	mlockall( MCL_CURRENT | MCL_FUTURE );
> 
> 	rt_task_shadow( &mainapp, "mainapp", 1, 0 );
> 
> 	dev_gpio = rt_dev_open( "gpio", 0 );
> 	if (dev_gpio < 0)
> 	{
> 		return -1;
> 	}
> 	
> 	gpio.gpio_heart_beat = NULL;
> 
> 	if (rt_dev_ioctl( dev_gpio, 1, &gpio ) != 0)
> 	{
> 		return -1;
> 	}
> 
> 	gpio.gpio_heart_beat[0] = 0x01;
> 
> 	...
> }
> 
> I also tried another way by opening "/dev/mem" and then using "mmap" 
> to map the I/O memory addresses in the application. It worked!
> I am very curious about why "rtdm_iomap_to_user" did not work for me. 

When you do precisely the same odd-numbered mapping via mmap on
/dev/mem, you do get the right address at gpio_heart_beat (check if the
start address ends with 0x0b0c)?

We either have to improve rtdm_iomap/mmap_to_user in this regard or
catch unaligned requests. Probably it's easier to catch it so that the
driver writer also realises that this is always about mapping full
pages...

Jan



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

* Re: [Xenomai-help] rtdm_iomap_to_user question
  2007-05-12 23:15       ` Zhang, Haobo
@ 2007-05-13 10:24         ` Jan Kiszka
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Kiszka @ 2007-05-13 10:24 UTC (permalink / raw)
  To: Zhang, Haobo; +Cc: xenomai, stelian

[-- Attachment #1: Type: text/plain, Size: 3128 bytes --]

Zhang, Haobo wrote:
> Thanks, Jan. It is fixed after I modified my code as you suggested.

Good to hear. Now just please answer my question below related to
/dev/mem so that I can think about a generic solution for the
documentation or the code or rtdm_*map_to_user.

Jan

> 
> Best Regards,
> Haobo Zhang 
> 
> -----Original Message-----
> From: jan.kiszka@domain.hid [mailto:jan.kiszka@domain.hid
> Sent: May 11, 2007 12:22 PM
> To: Zhang, Haobo
> Cc: xenomai@xenomai.org; stelian@domain.hid
> Subject: Re: [Xenomai-help] rtdm_iomap_to_user question
> 
> Zhang, Haobo wrote:
>> Hi Jan,
>>
>> Thank you so much for your reply!
>>
>> In my driver, I wrote:
>>
>> int map_io( struct gpiodrv_context *dev_context, rtdm_user_info_t 
>> *user_info, struct MAPPED_IO *io ) {
>> 	int ret;
>>
>> 	if ((dev_context == 0) || (user_info == 0) || (io == 0))
>> 		return -EFAULT;
>>
>> 	if (dev_context->mapped_user_info != 0)
>> 	{
>> 		if ((ret = gpio_unmap_io( dev_context )) != 0)
>> 			return ret;
>> 	}
>>
>> 	dev_context->mapped_user_info = user_info;
>>
>> 	ret = rtdm_iomap_to_user( user_info, MPC52xx_PA( 
>> MPC52xx_GPIO_WKUP_OFFSET + 0x0C ),
>> 		1, PROT_READ | PROT_WRITE, (void
>> **)&(io->gpio_heart_beat), NULL, NULL );
> 
> Hmm, hmm. Looking at our code and the kernel again I would say we should
> catch non-page-aligned requests like this and document this pitfall
> better.
> 
> The mapping code always assumes page-alignment and rounds your physical
> address down. So what likely happened here is that you got a mapping,
> but with unexpected offset (gpio_heart_beat should point to MPC52xx_PA).
> 
>> 	
>> 	if (ret != 0)
>> 		goto __ERROR;
>> 	else
>> 		dev_context->mapped_heart_beat = (void
> *)io->gpio_heart_beat;
>> 	return 0;
>>
>> __ERROR:
>>
>> 	gpio_unmap_io( dev_context );
>> 	return ret;
>> }
>>
>> In the application, I wrote:
>>
>> int main(int argc, char *argv[])
>> {
>> 	int dev_gpio;
>> 	struct MAPPED_IO gpio;
>>
>> 	signal(SIGTERM, clean_exit);	
>> 	signal(SIGINT, clean_exit);	
>> 	
>> 	mlockall( MCL_CURRENT | MCL_FUTURE );
>>
>> 	rt_task_shadow( &mainapp, "mainapp", 1, 0 );
>>
>> 	dev_gpio = rt_dev_open( "gpio", 0 );
>> 	if (dev_gpio < 0)
>> 	{
>> 		return -1;
>> 	}
>> 	
>> 	gpio.gpio_heart_beat = NULL;
>>
>> 	if (rt_dev_ioctl( dev_gpio, 1, &gpio ) != 0)
>> 	{
>> 		return -1;
>> 	}
>>
>> 	gpio.gpio_heart_beat[0] = 0x01;
>>
>> 	...
>> }
>>
>> I also tried another way by opening "/dev/mem" and then using "mmap" 
>> to map the I/O memory addresses in the application. It worked!
>> I am very curious about why "rtdm_iomap_to_user" did not work for me. 
> 
> When you do precisely the same odd-numbered mapping via mmap on
> /dev/mem, you do get the right address at gpio_heart_beat (check if the
> start address ends with 0x0b0c)?
> 
> We either have to improve rtdm_iomap/mmap_to_user in this regard or
> catch unaligned requests. Probably it's easier to catch it so that the
> driver writer also realises that this is always about mapping full
> pages...
> 
> Jan
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

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

end of thread, other threads:[~2007-05-13 10:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-10 18:16 [Xenomai-help] rtdm_iomap_to_user question Zhang, Haobo
2007-05-10 21:39 ` Jan Kiszka
2007-05-11  4:39   ` Zhang, Haobo
2007-05-11 16:22     ` Jan Kiszka
2007-05-12 23:15       ` Zhang, Haobo
2007-05-13 10:24         ` Jan Kiszka

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.