From mbianchi@Foveal.com  Sun Jul  9 23:32:19 2006
From: mbianchi@Foveal.com (M Bianchi)
Date: Sun Jul  9 23:32:29 2006
Subject: [pxc] PXC strangeness on Mandriva 2006.0
Message-ID: <20060709173218.A5696@Foveal.com>

I've been having trouble bringing up 2  PXC200AL  framegrabbers up on an
 Intel D949GNT  mother board with Celeron 2.53GHz processor under
 Mandriva 2006.0 (kernel 2.6.12-12mdk)  and  pxc-snapshot-051124 .

As installed, the Mandriva code configured and issues  modprobe  to install the
video4linux drivers:
	bt878
	bttv
	btcx_risc
etc.

If I  modprobe -r bt878  I could then run  pxc_live  and such for one
framegrabber, but no matter what I do, I cannot get  pxc_live  to open the
a second framegrabber:

    $ pxc_load
    $ pxc_live /dev/pxc0pgm &	# works
    	./pxc_live: using "/dev/pxc0pgm" to acquire data
    $ pxc_live /dev/pxc1pgm
    ./pxc_live: using "/dev/pxc1pgm" to acquire data
    Error in startup script: couldn't open "/dev/pxc1pgm": not enough memory
        while executing
    "open $devicefile r"
        invoked from within
    "set keepopen [open $devicefile r]"
        (file "./pxc_live" line 82)

     #  opposite order
     $ pxc_live /dev/pxc1pgm &	# works
    	./pxc_live: using "/dev/pxc1pgm" to acquire data
     $ pxc_live /dev/pxc0pgm	# complains about not enough memory

I thought maybe the bt878, etc. modules might have messed up the settings on
the cards, so I commented out the references to bt878 and bttv in
		/etc/modules
		/etc/modprob.conf
and rebooted.  Now 
	$ pxc_live /dev/pxc0pgm
does not present any information.  The processes  cp  and  wish  just hang.
	$ pxc_show
gives the same behaviour;  just hangs.

If I issue the following sequence:
	pxc_unload
	modprobe bt878
	modprobe -r bt878
	pxc_load
	pxc_live /dev/pxc0pgm

I once again get a live video image.  And again, running
  pxc_live /dev/pxc1pgm   complains about not enough memory.

I did a  make DEBUG=y  but that did not provide any additional information,
either in the shell or in  /var/log/messages .

I kept moving the   mem=xxxM  parameter lower and lower, but that had no
effect.  I'm now about 20 MBytes below what  /proc/meminfo  reported when there
was no  mem=xxxM  parameter.

BTW,  pxc_live /dev/pxc0Hpgm  give a large image so I'm guessing that when I do
 pxc_live /dev/pxc0pgm  and get a small image that two of them should be able
to fit because 2*smallpicture is only 0.5*largepicture.

Any suggestions on how to proceed?


-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085	call to arrange Fax

 MBianchi@Foveal.com
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com
From mbianchi@Foveal.com  Mon Jul 10 20:14:37 2006
From: mbianchi@Foveal.com (M Bianchi)
Date: Mon Jul 10 20:14:48 2006
Subject: [pxc] Re: PXC strangeness on Mandriva 2006.0
In-Reply-To: <20060709173218.A5696@Foveal.com>
References: <20060709173218.A5696@Foveal.com>
Message-ID: <20060710141437.A7963@Foveal.com>

On Sun, Jul 09, 2006 at 05:32:19PM -0400, M Bianchi wrote:
> I've been having trouble bringing up 2  PXC200AL  framegrabbers up on an
>  Intel D949GNT  mother board with Celeron 2.53GHz processor under
>  Mandriva 2006.0 (kernel 2.6.12-12mdk)  and  pxc-snapshot-051124 .
> 	:
> 	:

I have found half the problem.

By putting  printk()  calls at all the
	return -ENOMEM;

lines I found that the one that was returning was in  dma.c .

/* this function allocates all stuff for DMA */
int px_allocate_dma_and_program(Px_Dev *dev, int size, int nbufs, int prio)
{
    unsigned long flags;
    unsigned long dmabuffer;
    void *dmaremap;
    Px_Buffer *b;
    int i, errors = 0;

    px_free_dma_and_program(dev);

    /* Our status should be "all or nothing". Therefore, allocate stuff
       first, and only if successful place stuff in dev */

    b = __vmalloc(nbufs * sizeof(Px_Buffer), prio,
        __pgprot (PROT_READ | PROT_WRITE));
    if (!b) return -ENOMEM;
    memset(b, 0, nbufs * sizeof(Px_Buffer));

    size = PAGE_ALIGN(size);
    dmabuffer = allocator_allocate_dma(size * nbufs, prio);
    PDEBUG("allocating: %i bufs, %i bytes each, got 0x%08lx\n", nbufs,
           size, dmabuffer);
    if (!dmabuffer) {
        vfree(b);
        return -ENOMEM;		//<<<<<<<<<<<<<<<<<
    }

The problem turns out that the first call to  px_allocate_dma_and_program()
for starting the first  pxc_live /dev/pxc0pgm  calls  allocator_allocate_dma()
with
	size	77824
	nbufs	215
	prio	208

Apparently that works the first time, but when running  pxc_live /dev/pxc1pgm
the call is made again, and that time  allocator_allocate_dma()  returns NULL
and  -ENOMEM  is returned.

Issuing   pxc_load buffers=6  prevents the problem.  ((Why 6?  I could not
quickly determine of the buffers were shared among all the framegrabber cards
or were allocated per card.  I was tired.))


The root cause is in  hardware.c .

/* This is called at the end of set_dma_parameters, and from ioctl() */
int px_prepare_device(Px_Dev *dev, int nbuf, int prio)
{
    int retval = 0;
    int size;

    /* no lock is held, as each called function locks by itself */
    px_acq_off(dev, 1);

    size = dev->xsize * dev->ysize * PX_PIXEL_SIZE(dev);
    /* If nbuf < 0, use size to get all available memory */
    if (nbuf < 0) {
        nbuf = allocator_get_size() / PAGE_ALIGN(size);		//<<<<<<<<<<<<
        printk(KERN_INFO PX_MSG "allocating %i buffers\n", nbuf);
    }

The assumption here is that if nbuf is < 0 (i.e. uninitialized) why not get as
many buffers as we can and use them all.  That works, but only for the first
device.  The second framegrabber card finds itself starved out of memory.

The older code (pxc-0.81), did not do this.



I still have the problem that the pxc_live and pxc_show applications do not
show any image when started after a reboot, BUT do work after
		modprobe bttv
		modprobe -r bttv tvaudio

Any insights or suggestions are welcome.

-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085	call to arrange Fax

 MBianchi@Foveal.com
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com
From wideopen@ecenet.com  Tue Jul 11 08:46:21 2006
From: wideopen@ecenet.com (Curt Wuollet)
Date: Tue Jul 11 06:52:19 2006
Subject: [pxc] Strobe Outputs
Message-ID: <44B3493D.506@ecenet.com>

Hi all

I am working towards getting the strobe outputs working in the driver.
I just need some sequential hours in a quiet place :^)  But first I thought
I'd ask if anyone has already done this. Also, when grabbing from the
pgm device, I get two fields that seem more separated in time than I
would expect.  In other words, my target is moving and there is a lot
of displacement between them. Is it possible they are from different
frames?  Or is that even meaningful?  I mostly need time to read code
and sort this out, but I thought I'd ask in the meantime.

Regards

cww

-- 
Franklin D. Roosevelt Wrote about that other famous monopoly in 1938:
"The liberty of a democracy is not safe if the people tolerate the growth of 
private power to a point where it becomes stronger than their democratic State
itself. That in it's essence, is Fascism - ownership of government by an 
individual, by a group or by any controlling private power." But the 
conviction of Standard Oil stood. Our government is already powerless
against today's monopoly. Only the people can prevail.

From rubini@gnudd.com  Tue Jul 11 08:24:36 2006
From: rubini@gnudd.com (Alessandro Rubini)
Date: Tue Jul 11 08:31:47 2006
Subject: [pxc] Strobe Outputs
In-Reply-To: <44B3493D.506@ecenet.com>
References: <44B3493D.506@ecenet.com> 
Message-ID: <20060711062436.GA22144@mail.gnudd.com>


Hello.

> I'd ask if anyone has already done this.

I don't think so. It was never contributed to me (nor asked as a feature).

> In other words, my target is moving and there is a lot
> of displacement between them. Is it possible they are from different
> frames?

No. Unless there is a serious bug somewhere, but I'm pretty sure this
is correct.  Most likely, your camera streams data as it receives it.
If you are sure your camera makes a snapshot of the whole image and
then stream it out over time, then the two fields may be swapped (and
that would be the serious software bug).  Actually, I never remember
if the first one is the odd or even field, but I'm pretty sure I've
sorted things out correctly, at least when implementing and testing
the trigger.

/alessandro
--
Alessandro Rubini, free software developer.
Device drivers, embedded systems, courses.
http://gnudd.com/ http://ar.linux.it/
From mbianchi@Foveal.com  Tue Jul 11 15:10:58 2006
From: mbianchi@Foveal.com (M Bianchi)
Date: Tue Jul 11 15:11:07 2006
Subject: [pxc] Re: PXC strangeness on Mandriva 2006.0
In-Reply-To: <20060710141437.A7963@Foveal.com>
References: <20060709173218.A5696@Foveal.com> <20060710141437.A7963@Foveal.com>
Message-ID: <20060711091058.A4382@Foveal.com>

On Mon, Jul 10, 2006 at 02:14:37PM -0400, M Bianchi wrote:
> On Sun, Jul 09, 2006 at 05:32:19PM -0400, M Bianchi wrote:
> > I've been having trouble bringing up 2  PXC200AL  framegrabbers up on an
> >  Intel D949GNT  mother board with Celeron 2.53GHz processor under
> >  Mandriva 2006.0 (kernel 2.6.12-12mdk)  and  pxc-snapshot-051124 .
> > 	:
> I still have the problem that the pxc_live and pxc_show applications do not
> show any image when started after a reboot, BUT do work after
> 		modprobe bttv
> 		modprobe -r bttv tvaudio
> 	:

I have some more insight to this issue.

First, I said the  modprobe  command lines incorrectly.  They should be
 		modprobe bt878
 		modprobe -r bt878 tvaudio

I notices something very strange.  When the machine first boots and the  bt878
related modudules are prevented from being loaded,  lspci(8)  reports the
framegrabbers:
	PCI slot 06:00.0	IRQ 10
	PCI slot 06:01.0	IRQ  9

and  cat /proc/interrupts  does not list them.  IRQ 9 is associated with the
 apci  module; IRQ 10 is not listed.

After  modprobe bt878  the IRQs become(!):
	PCI slot 06:00.0	IRQ 21
	PCI slot 06:01.0	IRQ 22	(yes, the IRQ order changes)

and  cat /proc/interrupts  lists them and there associated modules.
I've never seen the IRQs change like that!
Note that  /proc/interrupts  reports the IRQs even though no application is
running.

After
	modprobe -r bt878 tvaudio
	pxc_load buffers=3

lspci(8) lists the IRQs as 22 and 21, lsmod(8) lists the pxc module as loaded,
but  /proc/interrupts  does not list the IRQs.

Run  pxc_live  and then  /proc/interrupts  lists the IRQ for the running
framegrabber;  stop  pxc_live  and  /proc/interrupts  does not.


There is a  setpci(8)  but I have not been able to convince myself that
changing the  INTERRUPT_LINE  field is changing the IRQ.  Changing
 INTERRUPT_LINE  causes byte  3c  (reported by  lspci -x ) to change BUT does
not change the IRQ reported by  lspci -v .

Clearly something in the bt878/bttv code is changing the IRQ, but i have not
yet tried to find it.  Also, without having another means to assign the IRQ
myself, I am not convinced that the IRQ is what is preventing  pxc.ko  from
returning data to the applications like  pxc_live .

Any suggestions?


Since there is now a workaround to get my applications to work, this is less
urgent than before, but I would like to understand what is preventing  pxc.ko
from working without the  bt878  module hack.

-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085	call to arrange Fax

 MBianchi@Foveal.com
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com
From mbianchi@Foveal.com  Tue Jul 11 17:10:09 2006
From: mbianchi@Foveal.com (M Bianchi)
Date: Tue Jul 11 17:10:17 2006
Subject: [pxc] Re: PXC strangeness on Mandriva 2006.0
In-Reply-To: <20060711091058.A4382@Foveal.com>
References: <20060709173218.A5696@Foveal.com> <20060710141437.A7963@Foveal.com>
	<20060711091058.A4382@Foveal.com>
Message-ID: <20060711111009.A5928@Foveal.com>

On Tue, Jul 11, 2006 at 09:10:58AM -0400, M Bianchi wrote:
> On Mon, Jul 10, 2006 at 02:14:37PM -0400, M Bianchi wrote:
> > On Sun, Jul 09, 2006 at 05:32:19PM -0400, M Bianchi wrote:
> > > I've been having trouble bringing up 2  PXC200AL  framegrabbers up on an
> > >  Intel D949GNT  mother board with Celeron 2.53GHz processor under
> > >  Mandriva 2006.0 (kernel 2.6.12-12mdk)  and  pxc-snapshot-051124 .
> > > 	:
> > I still have the problem that the pxc_live and pxc_show applications do not
> > show any image when started after a reboot, BUT do work after
> > 		modprobe bttv
> > 		modprobe -r bttv tvaudio
> > 	:
> Clearly something in the bt878/bttv code is changing the IRQ, but i have not
> yet tried to find it.  Also, without having another means to assign the IRQ
> myself, I am not convinced that the IRQ is what is preventing  pxc.ko  from
> returning data to the applications like  pxc_live .

Found it!

I tried adding a kernel parameter to the  kernel  line in  /boot/grub/menu.lst :
	pci=irqmask=0xFFF0
(This I found in  /usr/src/linux/Documentation/kernel-parameters.txt .)

Did not work.  Then tried:
	pci=irqmask=0x000F

Nope: the cards still came up on IRQs 10 and 9.

I then tried:
	pci=noacpi
Nope.

Then
	pci=routeirq

SUCCESS!  ((Now I know how the Italian football fans feel!))

 lspci -v  reports the IRQs as  21  and  22 , and  pxc_live  is happy.

I don't understand why IRQs 9 and 10 should be a problem, especially since 10
was not shared on my machine, but ...


To summarize:
  In  /boot/grub/menu.lst
	kernel (hd0,0)/vmlinuz-2.6.12-12mdk root=/dev/sda2 pci=routeirq	\
								mem=xxxM

  Somewhere in /etc/rc.d/rc*.d/FILENAME
	./pxc_load buffers=3


Suggestions:
	When no buffers are specified, try 3; report actual memory used.
	If that does not work, complain and try 2;
	No?  Complain and try 1;
	Then fail.
	The assumption that _all_ the unused memory belongs to pxc.ko is not
	reasonable.

	Add comments about IRQs, and  pci=routeirq  to documentation.



Alessandro,
	I'll hack the code and documents if you like.
								Mike

-- 
 Mike Bianchi
 Foveal Systems

 973 822-2085	call to arrange Fax

 MBianchi@Foveal.com
 http://www.AutoAuditorium.com
 http://www.FovealMounts.com
