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 petervuto
Observer
1,392 Views
Registered: ‎07-08-2017

Accessing physical memory from an interrupt handler

Jump to solution

Hey guys. I'm writing a kernel module for a design in the PL. Sometimes the PL sends an interrupt to the PS, and I need to respond by reading some data from the PL and maybe telling it to deassert the interrupt by writing to the usual 0x43c000.. control area. 

 

How do I write to a physical address like 0x43c00000 from an interrupt handler?

 

In non-atomic kernel code, I've accomplished all such communication with the PL by calling ioremap() on the relevant physical address and then iowrite/ioreading it. In the interrupt handler however, as soon as I call the ioremap_nocache(), I get an ugly kernel panic - https://pastebin.com/D84vgc5v . That stack trace ends at __get_vm_area_node, and googling for that function I got to http://elixir.free-electrons.com/linux/v4.0/source/mm/vmalloc.c#L1308, where on line 1315 there's the ominous 

BUG_ON(in_interrupt());

I assume that ioremap uses vmalloc in the background, and thus ioremap_nocache() is not what I should be using? But what then?

 

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Visitor msteveb0
Visitor
2,001 Views
Registered: ‎05-07-2014

Re: Accessing physical memory from an interrupt handler

Jump to solution

If you check many of the Linux kernel drivers you will see a common pattern of doing an ioremap() (or equivalent) in the probe function, and then the rest of the driver, including the irq handler can access the control registers through that mapping.

3 Replies
Highlighted
Visitor msteveb0
Visitor
2,002 Views
Registered: ‎05-07-2014

Re: Accessing physical memory from an interrupt handler

Jump to solution

If you check many of the Linux kernel drivers you will see a common pattern of doing an ioremap() (or equivalent) in the probe function, and then the rest of the driver, including the irq handler can access the control registers through that mapping.

Adventurer
Adventurer
1,344 Views
Registered: ‎10-04-2017

Re: Accessing physical memory from an interrupt handler

Jump to solution

ioremap maps a physical address to virtual address so that it can be accessed.  I wouldn't think that this requires any vmalloc calls since there is no any allocation going on but clearly is something that can't be called from interrupt context.  However, as mentioned by @msteveb0 you generally call  ioremap earlier in the driver  and often save the address in a global that can be easily accessed from the interrupt handler.

Observer petervuto
Observer
1,328 Views
Registered: ‎07-08-2017

Re: Accessing physical memory from an interrupt handler

Jump to solution
Thanks folks!
0 Kudos