Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2003 |
| 6 | * Gleb Natapov <gnatapov@mrv.com> |
| 7 | * |
| 8 | * (C) Copyright 2007 |
| 9 | * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com. |
| 10 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <asm/processor.h> |
| 16 | #include <asm/irq.h> |
| 17 | |
| 18 | /* Implemented by SPARC CPUs */ |
| 19 | extern int interrupt_init_cpu(void); |
| 20 | extern void timer_interrupt_cpu(void *arg); |
| 21 | extern int timer_interrupt_init_cpu(void); |
| 22 | |
| 23 | int intLock(void) |
| 24 | { |
| 25 | unsigned int pil; |
| 26 | |
| 27 | pil = get_pil(); |
| 28 | |
| 29 | /* set PIL to 15 ==> no pending interrupts will interrupt CPU */ |
| 30 | set_pil(15); |
| 31 | |
| 32 | return pil; |
| 33 | } |
| 34 | |
| 35 | void intUnlock(int oldLevel) |
| 36 | { |
| 37 | set_pil(oldLevel); |
| 38 | } |
| 39 | |
| 40 | void enable_interrupts(void) |
| 41 | { |
| 42 | set_pil(0); /* enable all interrupts */ |
| 43 | } |
| 44 | |
| 45 | int disable_interrupts(void) |
| 46 | { |
| 47 | return intLock(); |
| 48 | } |
| 49 | |
| 50 | int interrupt_init(void) |
| 51 | { |
| 52 | int ret; |
| 53 | |
| 54 | /* call cpu specific function from $(CPU)/interrupts.c */ |
| 55 | ret = interrupt_init_cpu(); |
| 56 | |
| 57 | /* enable global interrupts */ |
| 58 | enable_interrupts(); |
| 59 | |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | /* timer interrupt/overflow counter */ |
| 64 | static volatile ulong timestamp = 0; |
| 65 | |
| 66 | /* regs can not be used here! regs is actually the pointer given in |
| 67 | * irq_install_handler |
| 68 | */ |
| 69 | void timer_interrupt(struct pt_regs *regs) |
| 70 | { |
| 71 | /* call cpu specific function from $(CPU)/interrupts.c */ |
| 72 | timer_interrupt_cpu((void *)regs); |
| 73 | |
| 74 | timestamp++; |
| 75 | } |
| 76 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 77 | ulong get_timer(ulong base) |
| 78 | { |
| 79 | return (timestamp - base); |
| 80 | } |
| 81 | |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 82 | void timer_interrupt_init(void) |
| 83 | { |
| 84 | int irq; |
| 85 | |
Graeme Russ | 139d6cf | 2011-07-15 02:19:44 +0000 | [diff] [blame] | 86 | timestamp = 0; |
Daniel Hellstrom | 9d7c6b2 | 2008-03-28 09:47:00 +0100 | [diff] [blame] | 87 | |
| 88 | irq = timer_interrupt_init_cpu(); |
| 89 | |
| 90 | if (irq < 0) { |
| 91 | /* cpu specific code handled the interrupt registration it self */ |
| 92 | return; |
| 93 | } |
| 94 | /* register interrupt handler for timer */ |
| 95 | irq_install_handler(irq, (void (*)(void *))timer_interrupt, NULL); |
| 96 | } |