cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Anonymous
Not applicable
8,526 Views

Custom peripheral drivers with the git.xilinx.com kernel

I have a simple custom peripheral that I would like to control from linux running on the powerpc in a Virtex-4 part.  I am using the linux kernel from git.xilinx.com, and the device-tree MLD, as described in http://xilinx.wikidot.com/obsolete-powerpc-linux.  (Incidentally, if those are the obsolete directions, wouldn't it be nice to have a link pointing to some that are not obsolete?)  What is the preferred way of creating a driver for this peripheral and getting it into the kernel?

 

Using the device-tree MLD, XPS seems to generate a driver that is the same as that generated for standalone.  This driver will not compile into the linux kernel, presumably because it's not designed for the linux kernel.  Following the steps in http://www.xilinx.com/support/documentation/application_notes/xapp1129.pdf page 6 results in a kernel that will not build.

 

What's the intended way to make this happen?  Will XPS generate the driver I need, or do I need to write it by hand?

 

Thanks,

--John

 

 

0 Kudos
17 Replies
Anonymous
Not applicable
8,512 Views

The only thing that will be generated by the XPS toolflow (using a custom .mld) is the .dts.  Linux drivers are not automatically generated for a custom peripheral.

 

Terry

 

0 Kudos
linnj
Xilinx Employee
Xilinx Employee
8,509 Views
Registered: ‎09-10-2008

There is a page for the non-obsolete directions.  It's linked into the top menu for powerpc Linux.

 

http://xilinx.wikidot.com/powerpc-linux

 

Maybe there's something I'm still missing with your question.

 

With regards to how to do a driver, it's the normal standard Linux way.  You create a driver just like you would for any powerpc processor in Linux.  The only thing unique to Xilinx in that way is the device tree generator tries to help you generate the device tree from the xps project, but it's not intended to meet all your custom needs.  You can also edit the device tree by hand.

 

XPS does not generate a driver for Linux.  I'm not sure on custom peripherals for stand alone as I don't do much work in that area.

 

Can you give more specifics on the build error you get using the app note?  I think if there was just another post about that recently and it won't build because the kernel in the git tree has been updated to a later kernel version.  It seems like the ethernet driver needs a small change for the newer kernel.

 

You definitely have to know Linux well to do all this as it's not meant to help those without Linux knowledge.  We recommend those to start with a Linux distribution rather than trying to roll your own as there's considerable ramp up to be productive rolling your own, that's why distributions like MontaVista exist.

 

Thanks.

0 Kudos
Anonymous
Not applicable
8,483 Views

Thanks for the replies.  You have answered my questions. 

 

My confusion stems from my relative inexperience with EDK and writing Linux drivers.  XPS is able to generate standalone driver code for custom peripherals, just allowing simple register and memory access, so I supposed that it might be able to do the same for Linux.  As you've clarified, it doesn't.  Sounds like I need to read up on writing device drivers in Linux.

 

I believe my problem with kernel compilation and the app note was that I had copied the standalone driver code into the kernel source tree instead of the example code associated with the app note.  Naturally, this fails.

 

With regards to MontaVista - would using their distribution help me at all when it comes to drivers for my custom peripheral?  I'm under the impression that it wouldn't help in that respect.  Since I've already got the git.xilinx.com kernel working with buildroot, and I'll have to write a driver in either case, I don't see a reason to switch at this point.

 

Thanks again for the help,

 

--John

 

 

0 Kudos
linnj
Xilinx Employee
Xilinx Employee
8,480 Views
Registered: ‎09-10-2008

I don't think XPS really generates a full driver, maybe a shell of a driver that you can start from, but I'm no expert there as it's not my area.

 

Sounds like you're making progress.  You're right that a distribution won't help you write a device driver.  The bigger deal is learning how to debug the kernel and drivers as you write them.  They might provide better infrastructure as a distribution to help in that area (like kgdb support).

 

Good luck, you've got some learning ahead of you, but it's possible.

 

0 Kudos
mamisadegh2
Observer
Observer
8,382 Views
Registered: ‎06-15-2010

Hi

 

Just my personal experience,

 

I developed all of the required drivers myself.

Yes, XPS generates some sort of stand alone driver containing a set of functions for initialization and management of each specific peripheral, however, my experience of working with these drivers shows me that one should not waste his time even trying to use them in the Linux driver.

 

I believe if you develope the entire source code yourself, you will reach your target in a shorter time and with a higher level of reliability. Do not trust on xilinx generated driver source code !!!!

 

I have planned to write a document describing how to develope drivers for custom peripherals for Xilinx Embedded System. In fact it is completely true that Linux drivers can have some kind of template. it is not required for one person to know the details of the driver architecture. The developer will just make modifications to the template to generate the required functionality. modifications will be easy and straight forward.

 

Mohammad Sadegh Sadri.

0 Kudos
molmich86
Visitor
Visitor
8,319 Views
Registered: ‎06-22-2010

hey,

 

at the moment I try to  run Linux on the powerpc (ml507-Baord) and the next step will be, to write something from Linux over PLB to my IP. Can you tell me what I need for communikation from Linux over PLB to my IP.

 


0 Kudos
jpl@xiphos.ca
Adventurer
Adventurer
8,303 Views
Registered: ‎10-28-2007

Gidday there,

 

The simplest way to get access from Linux code to peripheral logic is to use mmap to get a handle on the physical memory from a user space application.  Here is some example code:

 

 

  int iSystemMemFd;
  volatile unsigned int * vpuiPeripheralMemory;
  unsigned int uiLocalVariable;

  //  Open memory device
  if ((iSystemMemFd = open("/dev/mem",O_RDWR))<0) {
    printf("Error opening /dev/mem. %s\n",strerror(errno));
    return -1;
  }

#define PERIPH_MEM_SIZE 4096
#define PERIPH_MEM_BASE 0xa0000000
// Map the memory vpuiPeripheralMemory = (unsigned int *)mmap(0,PERIPH_MEM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, iSystemMemFd, PERIPH_MEM_BASE); // Make sure the mmap succeeded if ((void*)-1 == vpuiPeripheralMemory) { printf("Error mapping memory. %s\n",strerror(errno)); close(iSystemFd); } // Write a 32-bit integer to the peripheral vpuiPeripheralMemory[0] = 0xcafebabe; // Read some data from the peripheral uiLocalVariable = vpuiPeripheralMemory[0];

 

 

Read the man page of mmap for more details, and make sure that you use the 'volatile' definition for the mapped memory.  The PERIPH_MEM_BASE must use the physical memory address.

 

Joshua

0 Kudos
Anonymous
Not applicable
8,294 Views

Why is it important to use 'volatile' in the definition?

0 Kudos
jpl@xiphos.ca
Adventurer
Adventurer
8,292 Views
Registered: ‎10-28-2007

As far as I understand it, this will ensure that the compiler will inform the O/S that memory pointed to by this variable should not be cached.  Otherwise, you will never actually read or write the memory space of your device.

 

Joshua

0 Kudos
Anonymous
Not applicable
6,948 Views

The peripheral isn't in cacheable memory space.

 

The volatile keyword tells the compiler not to optimize out the memory access. It's typically used in embedded software when you're accessing hardware - when you read or write to a particular address, you want to make SURE the access happens.   If you don't use volatile, the compiler may optimize out consecutive read/write accesses to the same address and break your software.

 

Terry

 

0 Kudos
molmich86
Visitor
Visitor
6,924 Views
Registered: ‎06-22-2010

in your example you use mmap, but I use the PLB-Bus for kommunikation from my-Ip and powerpc, do you meen, I can't use PBL in Linux and have to change my PBL-Interface?

0 Kudos
jpl@xiphos.ca
Adventurer
Adventurer
6,917 Views
Registered: ‎10-28-2007

If your PLB device is accessible from the powerpc, then this implies it has a physical address.

 

The function, mmap(), simply allows you to get access to a physical address space from a user space program.

 

You should not need to change your PLB interface.

 

Joshua

0 Kudos
molmich86
Visitor
Visitor
6,908 Views
Registered: ‎06-22-2010

But for example the PLB interface on powerpc have such function "write_reg, read_reg", and this function wait so long until the data are ready and write/read-Flag is 1.

 

but how can I see when I can read/write data with mmap???

 

 

0 Kudos
mamisadegh2
Observer
Observer
6,905 Views
Registered: ‎06-15-2010

Personally, I have developed some kernel mode drivers for my custom peripherals.

 

My custom peripherals connect to PLB the same as you molmich.

 

I have studied and learned how to develop a simple kernel mode driver to communicate with my device.

it is very easy. If you read the "Linux Device Drivers" book revision 3, up to the end of chapter 3 , I promise you, you will be able to develop a driver capable of communicating with your hardware.

 

on the other hand, the solution provided using mmap is in my idea great. 

I believe this is a very good technique so that you can test and gain access to your hardware in a short period of time in your Linux OS.

 

personally I have never used mmap, and I wonder, how can we handle interrupts or how can we use some capabilities like i/o controls, sysfs and so using this technique.

 

basically you should be able to do all of the required task using mmap techniqu. because it allows you to have the same Input Output operations as when you develope a stand alone code in your EDK program.

 

so here, I think you can implement your required funtion using mmap technique easily. just make a loop in whcih you check the read or write flag continuously, when it changed to 1 perform the main read or write operation. as you see, mmap has given us the capabilitiy of direct access to memory area, this is great, because we can do every thing we want the same as a stand alone system.

 

Mohammad Sadegh Sadri.

0 Kudos
molmich86
Visitor
Visitor
6,890 Views
Registered: ‎06-22-2010

I find this exapmle:

http://www.xilinx.com/support/documentation/application_notes/xapp1129.pdf

 

ist it the right way? I my design is my IP not locatLinkt, has it to be one?

0 Kudos
mamisadegh2
Observer
Observer
6,880 Views
Registered: ‎06-15-2010

Dear Molmich

 

I do not believe this application note is a good starting point.

All we want to do is to develope a simple driver for our custom IP connected to PLB. Our device is mainly a simple character device. Later we can add interrupt handling to it and then other options.

 

personally I believe the documents provided in this web site are really valuable : http://free-electrons.com/docs/

 

have a look at them.

And also have a look at the book "Linux device drivers".

 

Again I note that the solution based on using "mmap" can be really handy, and if you focus on it, I believe you may be able to do all of the required tasks. this way, it is not needed to learn writing a new driver from beginning.

 

Regards

Mohammad Sadegh Sadri.

0 Kudos
coldwarcomms
Observer
Observer
6,753 Views
Registered: ‎01-16-2010

Hey,

 

If anyone is still interested in a character device driver for PLB peripherals generated in XPS, check out our kernel tree at http://fpga.ce.rit.edu. If you clone the repository, the PLB driver code is in drivers/char/rit_fifo. Or, take a look at commit dc6e624835b2b23eca696aee13e5d49fa2e0531d for the driver sources. I can put up some public documentation if people are interested in using it.

 

-Nick

0 Kudos