Author Topic: Zynq and device drivers in Linux for custom peripherals designed in VHDL  (Read 525 times)

0 Members and 1 Guest are viewing this topic.

Offline pascal_sweden

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: no
Does anybody here on the forum know a good book or course material about Zynq where they cover in depth the development of custom peripherals in VHDL and device drivers in C, whereby the custom peripherals are accessed in Linux on the ARM core in Zynq through a device driver?
 

Online OwO

  • Frequent Contributor
  • **
  • Posts: 957
  • Country: cn
  • RF Engineer @ OwOComm. Discord: スメグマ#2236
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #1 on: February 16, 2020, 12:29:15 pm »
I've done lots of custom peripherals but always resorted to a userspace driver (/dev/mem for memory access, /dev/uio* for interrupts). I would recommend keeping everything in userspace unless you must use a kernel facility (such as creating a block device or video device).
What kind of peripherals are we talking about? Do you need to transfer a lot of data?
Discord: スメグマ#2236
Email: OwOwOwOwO123@outlook.com
GitHub: gabriel-tenma-white
 

Online OwO

  • Frequent Contributor
  • **
  • Posts: 957
  • Country: cn
  • RF Engineer @ OwOComm. Discord: スメグマ#2236
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #2 on: February 16, 2020, 12:39:10 pm »
There are many many approaches to implementing any peripheral; it can range from just a memory mapped slave that your driver accesses, to using a DMA controller, to doing DMA directly (memory mapped master). How you might implement an accelerator will also differ completely from how you would implement a DMA device that receives data from an ADC. It's also up to you how to allocate memory, whether to use big contiguous allocations or implement scatter-gather in hardware. There are no "correct" approaches to this and it isn't something you can learn from a book. You have to start with a specific application in mind, evaluate all possibilities and look at the tradeoffs, then decide how you want to implement it. Do this enough times and you'll have a good grip on how to design peripherals.
Discord: スメグマ#2236
Email: OwOwOwOwO123@outlook.com
GitHub: gabriel-tenma-white
 

Offline pascal_sweden

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: no
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #3 on: February 16, 2020, 02:02:29 pm »
I am looking for a cookbook that covers design patterns and best practices for all the different use cases.
There must be only 10-15 different use cases in total, so it would be very feasible for the skilled engineer to come up with such a cookbook.
 

Offline ebastler

  • Super Contributor
  • ***
  • Posts: 3412
  • Country: de
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #4 on: February 16, 2020, 03:32:33 pm »
This sounds a bit like: "I don't know much about it, so it must be pretty straightforward."  8)

Seems that you are asking about two separate topics (peripheral design incl. hardware interfacing via DMA etc., and Linux kernel-mode driver design). I'm sure there are many books on each of these topics alone.

Having said that, a book/tutorial with a set of sample implementations might work, which may or may not be adaptable to whatever peripheral you have in mind. But if you want it tailored to the Zynq, on top of the somewhat specialized topic, that makes it a pretty narrow niche. A book author would probably find it difficult to justify the effort in view of the limited audience. Maybe Xilinx could come up with a few application notes, since they would benefit the most?
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 7050
  • Country: us
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #5 on: February 16, 2020, 03:59:51 pm »
I guess I would try my favorite technique:  Copy and Paste

Somewhere in the Linux world, there is a similar device working in an acceptable manner.  It's all open-source, go grab the code, figure out how it works and what needs to change to fit Zynq.  There must be a bazillion lines of code floating around on the Internet.


Every one in a while, Google turns something up:  search for 'zynq linux device drivers' and, voila' Xilinx has at least 3 videos on the topic.

Do the search...  You will find that Xilinx regularly submits kernel mode drivers.

There's a ton of information available via Google!  This isn't the first time the subject has come up!
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18910
  • Country: nl
    • NCT Developments
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #6 on: February 16, 2020, 07:02:41 pm »
Buying a book on Linux Device Drivers is a good start. In the end every device is controlled through a bunch of addresses in the memory map. And as rstofer wrote: with some basic knowlegde you can copy & paste an existing driver and mold into shape (or mimic an existing hardware device in VHDL).
« Last Edit: February 16, 2020, 07:04:18 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline pascal_sweden

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: no
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #7 on: February 16, 2020, 07:31:11 pm »
These are indeed 2 topics, but the whole point of my question is that there is no single book out there that covers this combination, while this combination is extremely relevant for MPSoC designs built around the Zynq FPGA.

This is where a book brings value. To collect and organize disparate information on the Internet and bring it together in one book that will be very useful to a big community.

I don´t understand why eblaster sees it as a niche.

In fact, the book could cover other MPSoC platforms as well, as long as the combination Device driver and VHDL peripheral is covered.

 

Offline filssavi

  • Frequent Contributor
  • **
  • Posts: 302
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #8 on: February 16, 2020, 07:51:51 pm »
The only book on the subject is the LDDD3 (Linux device driver developemeny third edition), it gives you the broad idea of how things work however it is hopelessly out of date in many areas DMA buffers in particular so take it with a cargo hold of salt


I have tried to go the “proper” way by doing the driver and all, but it is just a waste of time as you have to either freeze your kernel to a hopelessly outdated version, mainline your driver (which let’s face it will never happen) or keep tracking changes for the entire life of the project, as internal kernel API/ABI is not stable and subjected to routine unannounced breaking changes (see what happened to ZFS), my suggestion is unless you really need to access shared kernel resources (scheduling for example) jus use a UIO driver, and manage everything with a C/Cpp daemon running in the background

 
The following users thanked this post: Someone

Online nctnico

  • Super Contributor
  • ***
  • Posts: 18910
  • Country: nl
    • NCT Developments
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #9 on: February 16, 2020, 09:00:01 pm »
These are indeed 2 topics, but the whole point of my question is that there is no single book out there that covers this combination, while this combination is extremely relevant for MPSoC designs built around the Zynq FPGA.
Why would you combine these topics? There is hardware and there is a driver. This subject is as old as computers themselves. It seems to me you get tangled up with a CPU on an FPGA and think it is somehow different. But it isn't. You can apply the exact same techniques as if you where using a seperate processor with I/O peripherals attached to them. Given the flexibility of VHDL what you might need is a book on how to create I/O peripherals effectively and pros and cons between polling, interrupts and DMA.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline pascal_sweden

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: no
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #10 on: February 16, 2020, 10:05:23 pm »
You have a point! I was too focused on a dedicated cookbook for Zynq.

So about that general cookbook on how to create I/O peripherals effectively, with pros and cons between polling, interrupts and DMA.

How far should I go back in time to find a good, complete and easy to understand resource?
« Last Edit: February 16, 2020, 10:40:32 pm by pascal_sweden »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 7050
  • Country: us
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #11 on: February 16, 2020, 10:22:44 pm »
Why would you go farther back than ARM implementations?  Even this branch will go back a long way.
https://www.linux.com/tutorials/4-fine-linux-arm-distros/

 

Offline KE5FX

  • Super Contributor
  • ***
  • Posts: 1131
  • Country: us
    • KE5FX.COM
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #12 on: February 16, 2020, 10:48:24 pm »
You have a point! I was too focused on a dedicated cookbook for Zynq.

So about that general cookbook on how to create I/O peripherals effectively, with pros and cons between polling, interrupts and DMA.

How far should I go back in time to find a good, complete and easy to understand resource?

You might find Marco Gottardo's book interesting.  It's somewhat unconventionally put together, but it covers a lot of what you're asking about, in terms of Zynq-based peripheral design for use with Linux.
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 2081
  • Country: ro
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #13 on: February 17, 2020, 01:08:39 am »
After all, what is that end application you think will require a Zynq and custom peripherals?  Maybe can be done without all these.  Or is it just for learning purposes?

Offline BravoV

  • Super Contributor
  • ***
  • Posts: 6686
  • Country: 00
  • +++ ATH1
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #14 on: February 17, 2020, 01:35:42 am »
After all, what is that end application you think will require a Zynq and custom peripherals?  Maybe can be done without all these.  Or is it just for learning purposes?

I guess it has to do with his Owon scope, as it uses Zynq  ? :-//

-> https://www.eevblog.com/forum/testgear/why-doesnt-owon-hire-european-software-engineers-and-product-designers/

Offline blacksheeplogic

  • Frequent Contributor
  • **
  • Posts: 442
  • Country: nz
Re: Zynq and device drivers in Linux for custom peripherals designed in VHDL
« Reply #15 on: February 18, 2020, 05:25:55 am »
I've done lots of custom peripherals but always resorted to a userspace driver (/dev/mem for memory access, /dev/uio* for interrupts). I would recommend keeping everything in userspace unless you must use a kernel facility (such as creating a block device or video device).

Why? I find it quicker and easier to write a kernel device driver. For someone that's not done it before it's probably a little more to get you head around initially but theirs good examples and documentation out there particularly from the vendors.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf