UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer classic037
Observer
11,095 Views
Registered: ‎03-09-2016

VDMA frame buffer in Linux application

Hi

 

I use Petalinux 15.04 version

 

We will try to use to get the Frame buffer of VDMA0 and VDMA1.

 

MY code.

 

vdma0 0x10000000

vdma1 0x18000000

 

#define VDMA0_BASE_ADDRESS 0x10000000
#define VDMA1_BASE_ADDRESS 0x18000000


#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE - 1)

 

main () {

...

 .....

 

//ddr test
int memfd;
void *mapped_base, *mapped_dev_base;
off_t dev_base = VDMA1_BASE_ADDRESS;
void* vdmaframe;

 

//ddr test
memfd = open("/dev/mem", O_RDWR | O_SYNC);
if (memfd == -1) {
printf("Can't open /dev/mem.\n");
exit(0);
}
printf("/dev/mem opened.\n");


mapped_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, dev_base & ~MAP_MASK);
if (mapped_base == (void *) -1) {
printf("Can't map the memory to user space.\n");
exit(0);
}

printf("Memory mapped at address %p.\n", mapped_base);


memcpy(vdmaframe, mapped_base, sizeof(mapped_base));

Segmentation fault occurs in this part.
//mapped_dev_base = mapped_base + (dev_base & MAP_MASK);

 

Do not mmap to import the data to a specific address?

 

How can bring Famedata of 0x10000000 0x18000000 or if?

 

Please guide thank you.

 

0 Kudos
8 Replies
Explorer
Explorer
11,009 Views
Registered: ‎11-22-2015

Re: VDMA frame buffer in Linux application

 

I don't understand what you are trying to do?  Is BASE_ADDRESS the address of the vmda controllers register space or is it the physical address of a buffer allocated in the kernel?

 

jeff

0 Kudos
Observer classic037
Observer
10,992 Views
Registered: ‎03-09-2016

Re: VDMA frame buffer in Linux application

dear jeff

 

Sorry. base address is 43010000

The camera frame data of vdma,  I would like to put in a buffer.

 

#include <dt-bindings/media/xilinx-vip.h>


/*
* Python input
*/
&amba {

axi_vdma_1: axivdma@43010000 {
compatible = "xlnx,axi-vdma-1.00.a";
reg = <0x43010000 0x10000>;
xlnx,flush-fsync = <1>;
xlnx,num-fstores = <1>;
#dma-cells = <1>;

dma-s2mmchannel@43010030 {
compatible = "xlnx,axi-vdma-s2mm-channel";
interrupt-parent = <&intc>;
interrupts = <0 30 4>;
xlnx,datawidth = <0x40>;
};
};

python_spi0: spi@43c40000 {
compatible = "xlnx,python-spi-3.1";
reg = <0x43c40000 0x1000>;
status = "okay";
clocks = <&clkc 15>;
clock-names = "ref_clk";
num-cs = <1>;
#address-cells = <1>;
#size-cells = <0>;

python1300_sensor_0: python1300_sensor@0 {
compatible = "onsemi,python1300-1.00.a";
reg = <0>;
spi-max-frequency = <100000>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
xlnx,video-format = <XVIP_VF_MONO_SENSOR>;
xlnx,cfa-pattern = "rggb";
xlnx,video-width = <8>;
python_sensor_source: endpoint {
remote-endpoint = <&python_rxif_sink>;
};
};
};
};
};

python1300_rxif_0: python1300_rxif@43c20000 {
compatible = "xlnx,v-python1300-rxif-3.1";
reg = <0x43c20000 0x10000>;
clocks = <&clkc 16>;

regv18-gpios = <&pca9554_0 0 0>;
regv33-gpios = <&pca9554_0 1 0>;
regvpix-gpios = <&pca9554_0 2 0>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
xlnx,video-format = <XVIP_VF_MONO_SENSOR>;
xlnx,cfa-pattern = "rggb";
xlnx,video-width = <8>;
python_rxif_sink: endpoint {
remote-endpoint = <&python_sensor_source>;
};
};

port@1 {
reg = <1>;
xlnx,video-format = <XVIP_VF_MONO_SENSOR>;
xlnx,cfa-pattern = "rggb";
xlnx,video-width = <8>;
python_rxif_source: endpoint {
remote-endpoint = <&cfa0_in>;
};
};
};
};

cfa_0: cfa@43c30000 {
compatible = "xlnx,v-cfa-7.0";
reg = <0x43c30000 0x10000>;
clocks = <&clkc 16>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
xlnx,video-format = <XVIP_VF_MONO_SENSOR>;
xlnx,cfa-pattern = "rggb";
xlnx,video-width = <8>;

cfa0_in: endpoint {
remote-endpoint = <&python_rxif_source>;
};
};
port@1 {
reg = <1>;
xlnx,video-format = <XVIP_VF_RBG>;
xlnx,video-width = <8>;

cfa0_out: endpoint {
remote-endpoint = <&rgb2yuv0_in>;
};
};
};
};

rgb2yuv_0: rgb2yuv@43c50000 {
compatible = "xlnx,v-rgb2yuv-7.1";
reg = <0x43c50000 0x10000>;
clocks = <&clkc 16>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
xlnx,video-format = <XVIP_VF_RBG>;
xlnx,video-width = <8>;

rgb2yuv0_in: endpoint {
remote-endpoint = <&cfa0_out>;
};
};
port@1 {
reg = <1>;
xlnx,video-format = <XVIP_VF_YUV_444>;
xlnx,video-width = <8>;

rgb2yuv0_out: endpoint {
remote-endpoint = <&cresample0_in>;
};
};
};
};

cresample_0: cresample@43c90000 {
compatible = "xlnx,v-cresample-4.0";
reg = <0x43c90000 0x10000>;
clocks = <&clkc 16>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
xlnx,video-format = <XVIP_VF_YUV_444>;
xlnx,video-width = <8>;

cresample0_in: endpoint {
remote-endpoint = <&rgb2yuv0_out>;
};
};
port@1 {
reg = <1>;
xlnx,video-format = <XVIP_VF_YUV_422>;
xlnx,video-width = <8>;

cresample0_out: endpoint {
remote-endpoint = <&vcap1_sink>;
};
};
};
};

video_cap_1 {
compatible = "xlnx,video";
dmas = <&axi_vdma_1 1>;
dma-names = "port0";

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
direction = "input";
vpipe-names = "python1300";
vcap1_sink: endpoint {
remote-endpoint = <&cresample0_out>;
};
};
};
};


};

 

#include <dt-bindings/media/xilinx-vip.h>

/*
* TGP input
*/
&amba {

vtc_1: vtc@43cb0000 {
compatible = "xlnx,v-tc-6.1";
reg = <0x43cb0000 0x10000>;
clocks = <&osc_0>;
xlnx,generator;
};

tpg_0: tpg@43c00000 {
compatible = "xlnx,v-tpg-7.0";
reg = <0x43c00000 0x10000>;
clocks = <&clkc 16>;
xlnx,vtc = <&vtc_1>;

reset-gpios = <&gpio0 54 1>;

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;

xlnx,video-format = <XVIP_VF_YUV_422>;
xlnx,video-width = <8>;

tpg_out: endpoint {
remote-endpoint = <&vcap_in>;
};
};
};
};

axi_vdma_0: axivdma@43000000 {
compatible = "xlnx,axi-vdma-1.00.a";
reg = <0x43000000 0x10000>;

xlnx,flush-fsync = <1>;
xlnx,num-fstores = <1>;

#dma-cells = <1>;

dma-s2mmchannel@43000030 {
compatible = "xlnx,axi-vdma-s2mm-channel";
interrupt-parent = <&intc>;
interrupts = <0 33 4>;
xlnx,datawidth = <0x40>;
};
};

video_cap_0 {
compatible = "xlnx,video";
dmas = <&axi_vdma_0 1>;
dma-names = "port0";

ports {
#address-cells = <1>;
#size-cells = <0>;

port@0 {
reg = <0>;
direction = "input";
vcap_in: endpoint {
remote-endpoint = <&tpg_out>;
};
};
};
};
};

 

 

 

 

0 Kudos
Explorer
Explorer
10,944 Views
Registered: ‎11-22-2015

Re: VDMA frame buffer in Linux application

 

Hi,

 

 So where are you getting the physical address of the frame buffer you are mmapping?  Even though the mmap function is passing the memory may be in use somewhere else unless you reserve it somehow.

 

jeff

0 Kudos
Observer classic037
Observer
10,934 Views
Registered: ‎03-09-2016

Re: VDMA frame buffer in Linux application

dear jeff

 

So where are you getting the physical address of the frame buffer you are mmapping? 

- you mean the base address? 

I am a standalone base was used vdma1 (0x18000000) and vdma0 (0x10000000) but do not know whether to use any address in petalinux base.

 

It can be utilized to v4l2 Maybe to get the buffer?

using the following API functions?

 

void v4l2_queue_buffer1(struct v4l2_helper *dev, int index, int dbuf_fd)
{
struct v4l2_buffer buf;
int ret;

memset(&buf, 0, sizeof buf);
buf.type = dev->buf_type;
buf.index = index;
buf.memory = dev->mem_type;
if(dev->mem_type == V4L2_MEMORY_DMABUF) {
buf.m.fd = dbuf_fd;
}
debug_printf("Queue1: fd %d index %d flags 0x%x\n", buf.m.fd, buf.index, buf.flags);
ret = ioctl(dev->cam_fd, VIDIOC_QBUF, &buf);
ASSERT(ret, "VIDIOC_QBUF(index = %d) failed: %s\n", buf.index, ERRSTR);
}

void v4l2_queue_buffer2(struct v4l2_helper *dev, int index, int dbuf_fd)
{
struct v4l2_buffer buf;
int ret;

memset(&buf, 0, sizeof buf);
buf.type = dev->buf_type;
buf.memory = dev->mem_type;
buf.index = index;
buf.flags = dev->dq_buf.flags; // just put back the value from the dequeue buffer
buf.m.fd = dbuf_fd;

//debug_printf("Queue2: fd %d index %d flags 0x%x\n", buf.m.fd, buf.index, buf.flags);
ret = ioctl(dev->cam_fd, VIDIOC_QBUF, &buf);
ASSERT(ret, "VIDIOC_QBUF(index = %d) failed: %s\n", index, ERRSTR);
}

int v4l2_dequeue_buffer(struct v4l2_helper *dev)
{
struct v4l2_buffer *buf = &dev->dq_buf;
int ret;

buf->type = dev->buf_type;
buf->memory = dev->mem_type;
ret = ioctl(dev->cam_fd, VIDIOC_DQBUF, buf);
ASSERT(ret, "VIDIOC_DQBUF failed: %s\n", ERRSTR);
debug_buf("Dequeue: fd %d index %d flags 0x%x\n", buf->m.fd, buf->index, buf->flags);
return 0;
}

 

Currently, my state is a state that is looking at the camera frame of the PC monitor with HDMI using the QT to python1300 camera module.

 

So I want to send a QT buffer(v4l2) sprayed with a PC via ethernet.

 

Thank you.

 

 

 

0 Kudos
Explorer
Explorer
10,921 Views
Registered: ‎11-22-2015

Re: VDMA frame buffer in Linux application

 

Hello,

 

 Yes, those are the addresses I was asking about.   I have a kernel driver that allocates framebuffers that are used for VDMA.  Then my userspace app calls an ioctl that returns the  physical address of those buffers and that is the address that is used to mmap those framebuffers into userspace.

 

  I'm not clear on how you are controllering your VDMA so I can't understand how you getting these addresses.  Im not using V4L; however,  I do know there are ways to use either kernel buffers or userspace buffers in V4L apps so that you can avoid memory copies.

 

jeff

0 Kudos
Observer classic037
Observer
10,906 Views
Registered: ‎03-09-2016

Re: VDMA frame buffer in Linux application

dear jeff

 

A my app is made to test the driver with some commonly used IOCTL commands.
VIDIOC_QUERYCAP
VIDIOC_G_FMT
VIDIOC_S_FMT
VIDIOC_QBUF
VIDIOC_DQBUF
VIDIOC_STREAMON
VIDIOC_STREAMOFF


The app creates 3 display planes. One plane is created for the Python sensor image. One plane is created for TPG
image. The rest is the background plane. When the app starts, the Python sensor plane is moved from left to right
and then stop.

 

I vdma structure are shown in the following figure.

my.JPG

Pleae guide.

 

thank you.

 

 

0 Kudos
Explorer
Explorer
10,867 Views
Registered: ‎11-22-2015

Re: VDMA frame buffer in Linux application

 

Hello,

  Unfortunately, you have still not told me how you got those addresses.   These should be the physical address of the buffers in memory so I don't see how you could have a fixed address.   If you are using V4L, if you set the memory type to MMAP when doing QUERYBUF  ioctl and which will return a physical address that can be mmapped.

 

good luck,

jeff

0 Kudos
Explorer
Explorer
518 Views
Registered: ‎02-05-2008

Re: VDMA frame buffer in Linux application

Hi,

I am working with python-1300. It works well in bare-metal. I am trying to implement in linux. I do not see driver for this. Can you let me know where did you get "python1300-1.00.a" and "v-python1300-rxif-3.1" drivers?

 

N JOTHI

0 Kudos