blob: bbda635fc7b521ede7e8fab866cfcee27d13edba [file] [log] [blame]
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +01001/*
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 Jiecfdfb812018-01-22 16:25:35 +000036#include <platform/interrupt.h>
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050037#include <sof/trace.h>
38#include <sof/debug.h>
39#include <sof/lock.h>
Rander Wangb9fc3f52018-05-10 13:32:24 +080040#include <sof/list.h>
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010041
Keyon Jiecfdfb812018-01-22 16:25:35 +000042#define trace_irq(__e) trace_event(TRACE_CLASS_IRQ, __e)
43#define trace_irq_error(__e) trace_error(TRACE_CLASS_IRQ, __e)
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010044
Rander Wangb9fc3f52018-05-10 13:32:24 +080045struct irq_desc {
46 /* irq must be first for constructor */
47 int irq; /* logical IRQ number */
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010048
Rander Wangb9fc3f52018-05-10 13:32:24 +080049 /* handler is optional for constructor */
Keyon Jiecfdfb812018-01-22 16:25:35 +000050 void (*handler)(void *arg);
51 void *handler_arg;
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010052
Rander Wangb9fc3f52018-05-10 13:32:24 +080053 /* to identify interrupt with the same IRQ */
54 int id;
Keyon Jiecfdfb812018-01-22 16:25:35 +000055 spinlock_t lock;
Rander Wangb9fc3f52018-05-10 13:32:24 +080056 uint32_t enabled_count;
57
58 /* to link to other irq_desc */
59 struct list_item irq_list;
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010060
Keyon Jiecfdfb812018-01-22 16:25:35 +000061 uint32_t num_children;
Rander Wangb9fc3f52018-05-10 13:32:24 +080062 struct list_item child[PLATFORM_IRQ_CHILDREN];
Keyon Jiecfdfb812018-01-22 16:25:35 +000063};
64
65int interrupt_register(uint32_t irq,
66 void(*handler)(void *arg), void *arg);
67void interrupt_unregister(uint32_t irq);
68uint32_t interrupt_enable(uint32_t irq);
69uint32_t interrupt_disable(uint32_t irq);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010070
71static inline void interrupt_set(int irq)
72{
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050073 arch_interrupt_set(SOF_IRQ_NUMBER(irq));
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010074}
75
76static inline void interrupt_clear(int irq)
77{
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050078 arch_interrupt_clear(SOF_IRQ_NUMBER(irq));
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010079}
80
81static inline uint32_t interrupt_global_disable(void)
82{
83 return arch_interrupt_global_disable();
84}
85
86static inline void interrupt_global_enable(uint32_t flags)
87{
88 arch_interrupt_global_enable(flags);
89}
90
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010091#endif