All of lore.kernel.org
 help / color / mirror / Atom feed
* Enable_fiq for ARM timer on rpi zero?
@ 2020-04-19 12:59 s.achterop
  2020-04-26 13:55 ` Sietse Achterop
  0 siblings, 1 reply; 2+ messages in thread
From: s.achterop @ 2020-04-19 12:59 UTC (permalink / raw)
  To: linux-arm-kernel

   Hello List,

I'm having trouble with using FIQ interrupts with the ARM timer on raspberypi zero, (BCM2835 chip).
The main problem is that I don't know which argument to use for the enable_fiq function.
Where can I find this information?

As far as I can see the ARM timer is not used in a regular kernel, so I assume that if I start the timer myself
and set the fiq to that timer it should work.
And, that can be done with either the enable_fiq(x) or directly writing 0xC0 to the FIQ control register.
Am I wrong here?

I created a simplified version of my driver, not much more than the minimal driver plus the fiq stuff.
In the init function I added a bit of code to monitor what happens after enable_fig is called.
It shows the working of the timer; the FIQ is not called so it seems.
The code can be found in
    https://github.com/SietseAchterop/Batradio/blob/master/batradio_module/fiqtest_2.c

Please find below the complete module-init function and the handler assember code.
Apart from a pure guess (I have tried several values) of the argument of enable_fiq() I really can't find anything wrong with it.

In drivers/irqchip/irq-bcm2835.c I found code about integrating the fiq handling together with the irq code,
But it still is unclear which value I need to enable_fiq.

   Thanks in advance,
      Sietse

====== init_bat
int init_bat(void)
{
   int ret;
   struct pt_regs regs;

   irqtimer = (uint32_t *) ioremap(IRQTIMER_BASE, IRQTIMER_SIZE);
   if (irqtimer == NULL) {
     printk("ioremap: irqtimer error!\n");
     return -ENOMEM;
   }

   // directly set ARM timer registers
   TIMCNTR = 0x0000000;   // stop timer
   TIMLOAD = 100000-1;    // load value
   TIMCINT = 0;           // clear interrupt

   ret = claim_fiq(&bat_fh);
   if (ret) {
     printk("batradio: claim_fiq failed.\n");
     return ret;
   }

   set_fiq_handler(&batradio_handler, &batradio_handler_end - &batradio_handler);

   regs.ARM_r8  = (long)0;
   regs.ARM_r9  = (long)irqtimer;
   regs.ARM_r10 = (long)0;
   set_fiq_regs(&regs);

   TIMCNTR = 0x000000A2;   // start timer with interrupt, 23 bit counter
   //IRQFIQ = 0xC0;         // timer interrupt to fiq directly via register
   enable_fiq(0);

   ret = 10;
   while (ret) {
     get_fiq_regs(&regs);
     printk("timer %d, raw int pending %x, count %ld\n", TIMVAL, RAWINT, regs.ARM_r10);
     msleep(1);
     ret--;
   }

   printk(KERN_INFO "  Installed batradio module... \n");
   return 0;
}


======  batradio fiq handler (clear interrupt and increment r10)
	.text
	.global batradio_handler
	.global batradio_handler_end

batradio_handler:
	str	r8, [r9, #0x40C]	// TIMCINT = 0
	add	r10, r10, #1
	subs	pc, lr, #4
	.align
batradio_handler_end:

======   snippet from /var/log/kern.log

Apr 19 10:19:55 raspberrypi kernel: [  578.943318] timer 99609, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  578.967638] timer 87461, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  578.996511] timer 73024, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  579.026264] timer 49371, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  579.056274] timer 25365, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  579.086249] timer 1385, raw int pending 0, count 0
Apr 19 10:19:55 raspberrypi kernel: [  579.116236] timer 77396, raw int pending 1, count 0
Apr 19 10:19:55 raspberrypi kernel: [  579.146262] timer 53373, raw int pending 1, count 0
Apr 19 10:19:56 raspberrypi kernel: [  579.176294] timer 29350, raw int pending 1, count 0
Apr 19 10:19:56 raspberrypi kernel: [  579.206174] timer 5444, raw int pending 1, count 0
Apr 19 10:19:56 raspberrypi kernel: [  579.236151]   Installed batradio module...



==== after a modprobe/rmmod cycle I also get the following. Probably due to the wrong argument to enable_fiq.

Apr 19 10:19:55 raspberrypi kernel: [  578.942556] ------------[ cut here ]------------
Apr 19 10:19:55 raspberrypi kernel: [  578.942624] WARNING: CPU: 0 PID: 1520 at kernel/irq/manage.c:576 __enable_irq+0x58/0x7c
Apr 19 10:19:55 raspberrypi kernel: [  578.942632] Unbalanced enable for IRQ 72
        .....
Apr 19 10:19:55 raspberrypi kernel: [  578.942797] CPU: 0 PID: 1520 Comm: modprobe Tainted: G        WC O      4.19.108+ #1
Apr 19 10:19:55 raspberrypi kernel: [  578.942804] Hardware name: BCM2835
Apr 19 10:19:55 raspberrypi kernel: [  578.942851] [<c00184f8>] (unwind_backtrace) from [<c0015064>] (show_stack+0x20/0x24)
Apr 19 10:19:55 raspberrypi kernel: [  578.942879] [<c0015064>] (show_stack) from [<c0753394>] (dump_stack+0x20/0x28)
Apr 19 10:19:55 raspberrypi kernel: [  578.942918] [<c0753394>] (dump_stack) from [<c0025b58>] (__warn.part.3+0xb8/0xe0)
Apr 19 10:19:55 raspberrypi kernel: [  578.942943] [<c0025b58>] (__warn.part.3) from [<c0025bec>] (warn_slowpath_fmt+0x6c/0x90)
Apr 19 10:19:55 raspberrypi kernel: [  578.942970] [<c0025bec>] (warn_slowpath_fmt) from [<c00722dc>] (__enable_irq+0x58/0x7c)
Apr 19 10:19:55 raspberrypi kernel: [  578.942993] [<c00722dc>] (__enable_irq) from [<c0072350>] (enable_irq+0x50/0xa4)
Apr 19 10:19:55 raspberrypi kernel: [  578.943015] [<c0072350>] (enable_irq) from [<c0016168>] (enable_fiq+0x38/0x40)
Apr 19 10:19:55 raspberrypi kernel: [  578.943059] [<c0016168>] (enable_fiq) from [<bf6610b4>] (init_module+0xb4/0x164 [batradio])
Apr 19 10:19:55 raspberrypi kernel: [  578.943125] [<bf6610b4>] (init_module [batradio]) from [<c000ae8c>] (do_one_initcall+0x4c/0x234)
Apr 19 10:19:55 raspberrypi kernel: [  578.943163] [<c000ae8c>] (do_one_initcall) from [<c00a7898>] (do_init_module+0x6c/0x1f8)
Apr 19 10:19:55 raspberrypi kernel: [  578.943187] [<c00a7898>] (do_init_module) from [<c00a9cdc>] (load_module+0x21ec/0x24cc)
Apr 19 10:19:55 raspberrypi kernel: [  578.943210] [<c00a9cdc>] (load_module) from [<c00aa1f8>] (sys_finit_module+0xcc/0xec)
Apr 19 10:19:55 raspberrypi kernel: [  578.943234] [<c00aa1f8>] (sys_finit_module) from [<c0009000>] (ret_fast_syscall+0x0/0x28)
        ....
Apr 19 10:19:55 raspberrypi kernel: [  578.943302] ---[ end trace 8bc89e3729ce1265 ]---


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Enable_fiq for ARM timer on rpi zero?
  2020-04-19 12:59 Enable_fiq for ARM timer on rpi zero? s.achterop
@ 2020-04-26 13:55 ` Sietse Achterop
  0 siblings, 0 replies; 2+ messages in thread
From: Sietse Achterop @ 2020-04-26 13:55 UTC (permalink / raw)
  To: linux-arm-kernel


Hello list,

On 4/19/20 2:59 PM, s.achterop@rug.nl wrote:
> I'm having trouble with using FIQ interrupts with the ARM timer on raspberypi zero, (BCM2835 chip).
> The main problem is that I don't know which argument to use for the enable_fiq function.
> Where can I find this information?
Code was at:
     https://github.com/SietseAchterop/Batradio/blob/master/batradio_module/fiqtest_2.c
							
I now am a little bit further and I now get some FIQ interrupts, but very irregular, and after some time
the system crashes.
I can see the irregularity because the fiq-handler toggles a LED.
I now do NOT use the claim_fiq function and also NOT the enable_fiq function.
I just, for the moment, assume that nothing else is using the ARM timer of FIQ.
And the FIQ is enabled by directly writing 0xC0 to the FIQ-control register.
Please find below the code-fragment from the init function of the driver and the fiq_handler.
irqtimer and gpiospi are set via ioremap and should be ok given the fact that it is working as
much as it does.
What am I doing wrong here?

    Thanks in advance,
        Sietse

PS. Or is there a better forum to ask. I did try the rpi forums, but no luck.

==== init function fragment

   regs.ARM_r8 = (long)gpiospi;
   regs.ARM_r9 = (long)irqtimer;
   regs.ARM_r10 = (long)0;        //batradio_data->fiq_base;
   set_fiq_regs(&regs);

   // start timer with interrupt
   TIMLOAD = 100000-1;
   TIMCINT = 0;
   TIMCNTR = 0x000000A2;
   // timer interrupt to fiq
   IRQFIQ = 0xC0;

=== fiq-handler

batradio_handler:
         stmdb sp!, {r6-r7}
         mov  r6, #0
         str r6, [r9, #0x40C]    // TIMCINT = 0 // clear interrupt

         mov r7, #0x2000         // 1 << 13, GPIO13
         add r10, r10, #1
         ands r6, r10, #0x0001   // set toggle speed
         bne off
         str r7, [r8, #40]       // led on
         ldmia sp!, {r6-r7}
         subs pc, lr, #4
off:    str r7, [r8, #28]       // led off
         ldmia sp!, {r6-r7}
         subs pc, lr, #4
batradio_handler_end:


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-26 13:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-19 12:59 Enable_fiq for ARM timer on rpi zero? s.achterop
2020-04-26 13:55 ` Sietse Achterop

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.