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!

Reply

help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Observer
Posts: 31
Registered: ‎08-28-2009

help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

My Linux-kernel-newbie question pertains to Linux UserIO (UIO) based user mode device driver access to memory mapped PL devices.

 

I have Linaro Ubuntu Linux running on my ZedBoard. For starters I followed the directions here: http://wiki.analog.com/resources/tools-software/linux-drivers/platforms/...

 

I have also built a new Zynq system config with just one peripheral (a simple counter) in PL -- no display controller etc. I am able to read and write that counter from a standalone C program.

 

I am also able to boot Ubuntu Linux on that config. I changed my devicetree.dtb so it configures no (zero) PL based peripherals. It comes up nicely, network works, SD works, etc. It has no frame buffer / display but I can still get a GUI via remote desktop  (by installing and running xrdp/xvnc). The nice thing about this set-up is I don't waste any PL on an extraneous display controller, etc. And I can travel and do GUI Zynq Linux development with just a laptop and the ZedBoard.

 

Running Linux, I am also able to talk to my counter peripheral directly, e.g. by opening /dev/mem, mmaping a view of memory on my counter's physical address, and reading and writing that. It works well. But it is hack. I hate opening /dev/mem. And it won't help when/if I start trying to send interrupts to my app.

 

I read about Linux UIO here: http://www.petalogix.com/support/kb/uio_howto That seems ideal for this device. Then my Linux app would simply open /dev/uio0 (for example), mmap a view on it, and wait for interrupts by reading from it.

 

UNfortunately I haven't been able to get UIO working. I edited my kernel configuration and enabled devices uio, uio_pdrv, uio_pdrv_genirq, and rebuilt it.

 

I also edited my devicetree .dts to add:

cnt0: cnt@7c800000 {

  #address-cells = <1>;

  #size-cells = <1>;

  compatible = "generic-uio", "uio", "uio_pdrv";

  reg = <0x7c800000 0x1000>;

};

 

When I boot this system, I see:

1. No uio device console message at boot time.

2. No /dev/uio0 (should I mknod it manually?)

3. /sys/class/uio exists, but is empty.

4. /proc/devices includes the uio device

 

I imagine my .dts is foobar but various tweaks of it do not improve the situation. I am going to dig into the kernel sources to see how the devicetree is processed but I was wondering:

1. Do you use UIO to write user-model device drivers?

2. Or do you prefer some other approach?

3. What should my DTS look like to enable UIO to a memory mapped device control register?

4. Do you have to manually mknod an entry for it in /dev/uio[0123]?

5. Do you have to do anything to set up /sys/class/uio/* ?

 

Thank you for any pointers.

Scholar
Posts: 335
Registered: ‎05-28-2012

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

I usually use just mmap of /dev/mem or a loadable module. This UIO thing sounds intriguing. Looks like the /dev/mem approach with some extra stuff for interrupts.

 

The Xilinx GIT and the mainline UIO code don't seem to have much device tree support. Linaro likely has a similar lack of device tree support. Perhaps the PetaLogix kernel has implemented complete device tree support. You might have to add a platform device to your board file.

 

Visitor
Posts: 3
Registered: ‎08-02-2012

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Hello,

I have exactly the same problem.
Have you been able to solve it?
I need to resolve this. Maybe we can help each other.

 

My email is pegroseo@gmail.com or pedro.duran@alumnos.usm.cl

 

Regards

Visitor
Posts: 3
Registered: ‎08-02-2012

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

I mean I saw this link: http://www.petalogix.com/support/kb/uio_howto and I did all it is there.
but then when boot linux on my atlys board there's nothing in /sys/class/uio so I can't use any application which calls to my peripherals, I tried with /dev/mem and everything works good but i read it's not a good idea to use it. it's a better idea to development with User IO. Please anybody! I'm stuck

 

Regards

Visitor
Posts: 23
Registered: ‎05-13-2008

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

The last time I checked the Xilinx Kernel did not have dts support for uio (yet). So you have to write a kernel module for uio. I attached mine to this post.

Explorer
Posts: 134
Registered: ‎03-23-2009

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

[ Edited ]

Hi,

 

I'm having the same issue. I have petalinux installed, and I'm using a ML605 board with a custom hardware platform that contains two GPIOs, one connected to the 8 LEDS and another to the Position LEDS of the board. I followed the tutorial in lab_1_5 from the Lab Documents & Presentations section at:

http://www.xilinx.com/university/workshops/embedded-linux-microblaze/. I am able to toggle the LEDS when I used the virtual memory file of the system and the xilinx modules, I tested it with the first half of lab_1_5 and the gpio_demo.

 

I setup the kernel to have the Userspace I/O drivers, I loading the module with modprobe, then listed the modules with lsmod, the following is the output with lsmod: 

$lsmod

uio 6009 0 - Live 0xf005d000

 

My first question is: what is the value "0xf005d000"? I assume it is some address? But nothing in my dts file has this address in any device ranges. Can this be an issue?

 

The following is a snippet of my dts file. Note that I changed the label of the device label@XXXX, and changed the compatible to include "generic-uio" and "uio". I originally had "generic-uio", but it didn't work and I added "uio" but it still doesn't work.

		leds_8bits: leds@40020000 {
			#gpio-cells = <2>;
			compatible="generic-uio","uio";
			gpio-controller ;
			reg = < 0x40020000 0x10000 >;
			xlnx,all-inputs = <0x0>;
			xlnx,all-inputs-2 = <0x0>;
			xlnx,dout-default = <0x0>;
			xlnx,dout-default-2 = <0x0>;
			xlnx,family = "virtex6";
			xlnx,gpio-width = <0x8>;
			xlnx,gpio2-width = <0x20>;
			xlnx,instance = "LEDs_8Bits";
			xlnx,interrupt-present = <0x0>;
			xlnx,is-dual = <0x0>;
			xlnx,tri-default = <0xffffffff>;
			xlnx,tri-default-2 = <0xffffffff>;
		} ;
		leds_positions: leds0@40000000 {
			#gpio-cells = <2>;
			compatible="generic-uio","uio";
			gpio-controller ;
			reg = < 0x40000000 0x10000 >;
			xlnx,all-inputs = <0x0>;
			xlnx,all-inputs-2 = <0x0>;
			xlnx,dout-default = <0x0>;
			xlnx,dout-default-2 = <0x0>;
			xlnx,family = "virtex6";
			xlnx,gpio-width = <0x5>;
			xlnx,gpio2-width = <0x20>;
			xlnx,instance = "LEDs_Positions";
			xlnx,interrupt-present = <0x0>;
			xlnx,is-dual = <0x0>;
			xlnx,tri-default = <0xffffffff>;
			xlnx,tri-default-2 = <0xffffffff>;
		} ;

The module is present in: /lib/modules/3.6.0/kernel/drivers/uio/uio.ko .

 

The previous post by nxdefiant mentioned that Xilinx does not have support for uio. But as I just mentioned I do have it. So, the only conclusions I came up with is: the module is loaded in an area that the kernel does not have access to it, or the module is wrong.  If the module is incorrect/wrong, I can attempt to use the one posted by nxdefiant. But I am unafamiliar in creating a module in petalinux.

 

UPDATE: I am able to access the GPIO via the /dev/mem using the uio module.

 

Any suggestions or help would be appreciated. Thanks,

Explorer
Posts: 134
Registered: ‎03-23-2009

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Bump! :)

Visitor
Posts: 23
Registered: ‎05-13-2008

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Please note that I said that the Xilinx kernel doesn't have devicetree support for UIO yet*:

The UIO-Module is there, just no way to configure it with the dts file. Thats why I had to create the Module.

 

When using /dev/mem you are _not_ using UIO.

/dev/mem provides you with access to all physical memory which can be a security risk.

 

* The last time I checked was January, might be different now.

 

P.S: Yes I know this thread is a bit older, but it came up first on google for "zynq mmap".

Observer
Posts: 31
Registered: ‎08-28-2009

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Newbie
Posts: 1
Registered: ‎08-09-2013

Re: help with simple Zynq PL device access via Linux UIO-based user-mode device drivers

Has anyone tried uio with 14.5 or later?  I followed the instructions in the above blog and I can see the uio device, but any attempt to mmap it returns error 22 (invalid argument). 

 

I am able to map the memory with /dev/mem and it behaves as expected, just not with uio, but I can't really use /dev/mem because I need interrupt support.