cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
petervuto
Observer
Observer
2,140 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
msteveb0
Visitor
Visitor
2,749 Views
Registered: ‎05-07-2014

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.

View solution in original post

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

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.

View solution in original post

jrhtech
Voyager
Voyager
2,092 Views
Registered: ‎10-04-2017

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.

petervuto
Observer
Observer
2,076 Views
Registered: ‎07-08-2017
Thanks folks!
0 Kudos