All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] PCI Framegrabber real-time driver
@ 2006-01-11 18:55 Rodrigo Rosenfeld Rosas
  2006-01-11 19:48 ` Jan Kiszka
  0 siblings, 1 reply; 13+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2006-01-11 18:55 UTC (permalink / raw)
  To: xenomai

Hi,

I developed a v4l2 driver for my PCI framegrabber and I need to use it in my
real-time applications. I think I need to write a new one with real-time
constrainments. But I'm not sure of which API would be the best one for this
kind of driver.

I know about existence of RTDM, but I'm not sure if it is the best choice...

Let me explain how the driver works. It initializes the board with some PCI
writes on startup. It's passed to the kernel the parameter "mem=510M"
reserving 2Mb for use with the framegrabber through DMA access. I need a
continuous physic memory area and I can't get it through kmalloc or similar
functions. I map this memory in my programs in user space. So, I basically
need to write and read from PCI registers in the drive. But I don't know if
it should be better to develop the driver using some existing API or not
because I didn't find any API that applies to framegrabbers like v4l does on
Linux domain...

Please, what do you suggest about the design of my driver?

Thanks,

Rodrigo.

	

	
		
_______________________________________________________ 
Yahoo! doce lar. Faça do Yahoo! sua homepage. 
http://br.yahoo.com/homepageset.html 




^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [Xenomai-help] PCI Framegrabber real-time driver
@ 2006-01-13 15:11 Rodrigo Rosenfeld Rosas
  0 siblings, 0 replies; 13+ messages in thread
From: Rodrigo Rosenfeld Rosas @ 2006-01-13 15:11 UTC (permalink / raw)
  Cc: xenomai

>> >>>continuous physic memory area and I can't get it through kmalloc
>
>I did a quick check and I could easily allocate a 2MB contiguous,
>aligned buffer on my system using the following calls. (See DMA-
>mapping.txt in your kernel Documentation folder):
>
>struct pci_dev *p;
>
>...
>
>pci_set_master(p);
>pci_set_consistent_dma_mask(p, DMA_32BIT_MASK);
>pci_alloc_consistent(p, 2097152, &phys_ptr);
>
>...

I'll take a look on this approach, but I think that the other is more robust
because this one can fail if it does not find an contiguous block of 2Mb
(actually I'm using about 1,2M on my driver for now...) due to memory
fragmentation... I remember I tried this way some time before when I had
256Mb but could only alloc 512kb of contiguous memory (7 was the maximum
order I could get)... It seemed to me that the kernel has changed since
there. It was not possible to get an order superior to 8 and now I think the
default maximum is order 11... (PAGE_SIZE<<order) I think page size is 4kb
for x86.

>You can also get the irq line number here from p->irq . Use this for
>rtdm_irq_request().
>
>> >>>Please, what do you suggest about the design of my driver?
>
>1. Use RTDM and write a kernel module. It allows you to write a
>specific test program on it, which you can reuse later on every
>occasion where you need to know whether the driver or the program
>contains causes a problem. You can also shut an RTDM driver down
>manually if your RT program ever bails out 'ungracefully'.

Ok, I'm new to RTDM but I think I'll end up using it...

>2. Use 2 framebuffers and implement a ping-pong buffer, so that the
>grabber may fill in a second buffer while you're using the contents of
>number one. Avoid copying of the data.

There is an option, but it would increase the complexity of both the driver
and user code because the user should know what memory is in the turn... And
that is not the only way to avoid copying the data. I can run the acquires on
asyncronous way. The advantage of the ping-pong buffer is that I wouldn't
need to wait for a frame capture to complete (the board can do 30fps [frames
per second]) depending on how I design the driver... I'll think better on
this approach.

>3. Remember to use the PCI DMA API. It is the easiest way to guarantee
>that CPU L1/2 caching is not going to fool you some day. You do not
>want to mess yourself with MTRR and friends (?) on the CPU. (Something
>I think may be a serious issue when using tricks like the ones
>mentioned earlier.)

You are talking about specifying the mem option (is it the trick you
 mention)? Well I need to read more about this topic before discussing it
 with you. I do not know how this caching works nor MTRR...

>4. Use portable functions to access your PCI card, such as read[b/w/l]
>() and write[b/w/l]().

Yes, I already use them.

>Don't do *(unsigned int *)ptr = val. Where
>needed, use memory write barriers such as wmb(), to avoid instruction
>reordering by the compiler.

I forgot this when first designed my driver but I'll take a better look on
this. Do you know about what situations could take the code to be executed in
a different order? I mean, reads and writes to PCI registers could be done in
a different order then I've told to the driver?

>5. Don't catch interrupts that weren't meant for you. If your ISR gets
>called, check some status register of your card to see if it was the
>cause of the interrupt. If so, finish with return(RTDM_IRQ_ENABLE).
>Otherwise, return(RTDM_IRQ_PROPAGATE), so other handlers may catch it
>(and reset the possibly shared IRQ line, which is never going to be
>deasserted otherwise (== stuck)).

I think it is dangerous to share the interrupt with other non-rt drivers. If
the non-rt driver disables the interrupt for a while, the hard rt-driver will
give wrong result. Unless it was possible to not allow the interrupt to be
disabled by non-rt drivers, it is too dangerous to share the interrupt line.

>BTW, when specifying mem=510M, how would you access the range 510-512
>without causing a segmentation fault ?

Why should it cause a segmentation fault? The mem=510M parameter only informs
the kernel to not use that memory but it allows manual use of that memory by
a module or so. But kmalloc  won't alloc that memory.

Thank you Jeroen, you helped me a lot.

Best regards,
Rodrigo.

	

	
		
_______________________________________________________ 
Yahoo! doce lar. Faça do Yahoo! sua homepage. 
http://br.yahoo.com/homepageset.html 




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

end of thread, other threads:[~2006-01-17 14:33 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-11 18:55 [Xenomai-help] PCI Framegrabber real-time driver Rodrigo Rosenfeld Rosas
2006-01-11 19:48 ` Jan Kiszka
2006-01-11 21:21   ` Rodrigo Rosenfeld Rosas
2006-01-11 22:23     ` Gilles Chanteperdrix
2006-01-12 19:47       ` Rodrigo Rosenfeld Rosas
2006-01-11 22:31     ` Jan Kiszka
     [not found]       ` <1137032878.43c5beae139f5@domain.hid>
2006-01-12  9:29         ` Jan Kiszka
2006-01-13 14:24       ` Rodrigo Rosenfeld Rosas
2006-01-13 19:57         ` Jan Kiszka
2006-01-13 21:53           ` Rodrigo Rosenfeld Rosas
2006-01-13 22:29             ` Jan Kiszka
2006-01-17 14:33               ` Rodrigo Rosenfeld Rosas
  -- strict thread matches above, loose matches on Subject: below --
2006-01-13 15:11 Rodrigo Rosenfeld Rosas

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.