Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Intel Corporation |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * * Neither the name of the Intel Corporation nor the |
| 13 | * names of its contributors may be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> |
| 29 | */ |
| 30 | |
| 31 | #ifndef __INCLUDE_INTERRUPT__ |
| 32 | #define __INCLUDE_INTERRUPT__ |
| 33 | |
| 34 | #include <stdint.h> |
| 35 | #include <arch/interrupt.h> |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 36 | #include <platform/interrupt.h> |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 37 | #include <sof/trace.h> |
| 38 | #include <sof/debug.h> |
| 39 | #include <sof/lock.h> |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 40 | #include <sof/list.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 41 | |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 42 | #define trace_irq(__e) trace_event(TRACE_CLASS_IRQ, __e) |
| 43 | #define trace_irq_error(__e) trace_error(TRACE_CLASS_IRQ, __e) |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 44 | |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 45 | struct irq_desc { |
| 46 | /* irq must be first for constructor */ |
| 47 | int irq; /* logical IRQ number */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 48 | |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 49 | /* handler is optional for constructor */ |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 50 | void (*handler)(void *arg); |
| 51 | void *handler_arg; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 52 | |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 53 | /* to identify interrupt with the same IRQ */ |
| 54 | int id; |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 55 | spinlock_t lock; |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 56 | uint32_t enabled_count; |
| 57 | |
| 58 | /* to link to other irq_desc */ |
| 59 | struct list_item irq_list; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 60 | |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 61 | uint32_t num_children; |
Rander Wang | b9fc3f5 | 2018-05-10 13:32:24 +0800 | [diff] [blame] | 62 | struct list_item child[PLATFORM_IRQ_CHILDREN]; |
Keyon Jie | cfdfb81 | 2018-01-22 16:25:35 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | int interrupt_register(uint32_t irq, |
| 66 | void(*handler)(void *arg), void *arg); |
| 67 | void interrupt_unregister(uint32_t irq); |
| 68 | uint32_t interrupt_enable(uint32_t irq); |
| 69 | uint32_t interrupt_disable(uint32_t irq); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 70 | |
| 71 | static inline void interrupt_set(int irq) |
| 72 | { |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 73 | arch_interrupt_set(SOF_IRQ_NUMBER(irq)); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static inline void interrupt_clear(int irq) |
| 77 | { |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 78 | arch_interrupt_clear(SOF_IRQ_NUMBER(irq)); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline uint32_t interrupt_global_disable(void) |
| 82 | { |
| 83 | return arch_interrupt_global_disable(); |
| 84 | } |
| 85 | |
| 86 | static inline void interrupt_global_enable(uint32_t flags) |
| 87 | { |
| 88 | arch_interrupt_global_enable(flags); |
| 89 | } |
| 90 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 91 | #endif |