rmixl_intr.h revision 1.1.2.12 1 1.1.2.12 matt /* $NetBSD: rmixl_intr.h,v 1.1.2.12 2012/01/04 16:17:53 matt Exp $ */
2 1.1.2.3 cliff /*-
3 1.1.2.3 cliff * Copyright (c) 2010 The NetBSD Foundation, Inc.
4 1.1.2.3 cliff * All rights reserved.
5 1.1.2.3 cliff *
6 1.1.2.3 cliff * This code is derived from software contributed to The NetBSD Foundation
7 1.1.2.3 cliff * by Cliff Neighbors.
8 1.1.2.3 cliff *
9 1.1.2.3 cliff * Redistribution and use in source and binary forms, with or without
10 1.1.2.3 cliff * modification, are permitted provided that the following conditions
11 1.1.2.3 cliff * are met:
12 1.1.2.3 cliff * 1. Redistributions of source code must retain the above copyright
13 1.1.2.3 cliff * notice, this list of conditions and the following disclaimer.
14 1.1.2.3 cliff * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.3 cliff * notice, this list of conditions and the following disclaimer in the
16 1.1.2.3 cliff * documentation and/or other materials provided with the distribution.
17 1.1.2.3 cliff *
18 1.1.2.3 cliff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.1.2.3 cliff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.1.2.3 cliff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.1.2.3 cliff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.1.2.3 cliff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.1.2.3 cliff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.1.2.3 cliff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1.2.3 cliff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.1.2.3 cliff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.1.2.3 cliff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.1.2.3 cliff * POSSIBILITY OF SUCH DAMAGE.
29 1.1.2.3 cliff */
30 1.1.2.1 cliff
31 1.1.2.1 cliff #ifndef _MIPS_RMI_RMIXL_INTR_H_
32 1.1.2.1 cliff #define _MIPS_RMI_RMIXL_INTR_H_
33 1.1.2.1 cliff
34 1.1.2.6 cliff #ifdef _KERNEL_OPT
35 1.1.2.5 cliff #include "opt_multiprocessor.h"
36 1.1.2.6 cliff #endif
37 1.1.2.5 cliff
38 1.1.2.1 cliff /*
39 1.1.2.4 cliff * A 'vector' is bit number in EIRR/EIMR
40 1.1.2.9 matt * - IRT or non-IRT interrupts use vectors 8..63
41 1.1.2.9 matt * - vector or dynamically assigned (except for IPI and FMN)
42 1.1.2.1 cliff */
43 1.1.2.1 cliff #define NINTRVECS 64 /* bit width of the EIRR */
44 1.1.2.9 matt #define RMIXLP_NIRTS 160 /* #entries in Interrupt Redirection Table */
45 1.1.2.9 matt #define RMIXLR_NIRTS 32 /* #entries in Interrupt Redirection Table */
46 1.1.2.9 matt #define RMIXLS_NIRTS 32 /* #entries in Interrupt Redirection Table */
47 1.1.2.4 cliff
48 1.1.2.4 cliff /*
49 1.1.2.4 cliff * vectors (0 <= vec < 8) are CAUSE[8..15] (including softintrs and count/compare)
50 1.1.2.4 cliff */
51 1.1.2.4 cliff #define RMIXL_INTRVEC_IPI 8
52 1.1.2.12 matt
53 1.1.2.12 matt #define RMIXLP_IRT_PCIE_MSIX 46
54 1.1.2.1 cliff
55 1.1.2.1 cliff /*
56 1.1.2.1 cliff * iv_list and ref count manage sharing of each vector
57 1.1.2.1 cliff */
58 1.1.2.1 cliff typedef struct rmixl_intrhand {
59 1.1.2.9 matt LIST_ENTRY(rmixl_intrhand) ih_link;
60 1.1.2.1 cliff int (*ih_func)(void *);
61 1.1.2.1 cliff void *ih_arg;
62 1.1.2.9 matt bool ih_mpsafe; /* true if does not need kernel lock */
63 1.1.2.9 matt uint8_t ih_vec; /* vector is bit number in EIRR/EIMR */
64 1.1.2.1 cliff } rmixl_intrhand_t;
65 1.1.2.1 cliff
66 1.1.2.9 matt typedef struct rmixl_intrvec {
67 1.1.2.9 matt LIST_HEAD(, rmixl_intrhand) iv_hands;
68 1.1.2.9 matt TAILQ_ENTRY(rmixl_intrvec) iv_lruq_link;
69 1.1.2.9 matt rmixl_intrhand_t iv_intrhand;
70 1.1.2.9 matt uint8_t iv_ipl; /* interrupt priority */
71 1.1.2.9 matt } rmixl_intrvec_t;
72 1.1.2.9 matt
73 1.1.2.9 matt typedef TAILQ_HEAD(rmixl_intrvecq, rmixl_intrvec) rmixl_intrvecq_t;
74 1.1.2.9 matt
75 1.1.2.12 matt static inline int
76 1.1.2.12 matt rmixl_intr_deliver(int (*func)(void *), void *arg, bool mpsafe_p,
77 1.1.2.12 matt struct evcnt *ev, int ipl)
78 1.1.2.12 matt {
79 1.1.2.12 matt int rv;
80 1.1.2.12 matt #ifndef MULTIPROCESSOR
81 1.1.2.12 matt mpsafe_p = true;
82 1.1.2.12 matt #endif
83 1.1.2.12 matt if (mpsafe_p) {
84 1.1.2.12 matt rv = (*func)(arg);
85 1.1.2.12 matt } else {
86 1.1.2.12 matt KASSERTMSG(ipl == IPL_VM,
87 1.1.2.12 matt ("%s: %s: ipl (%d) != IPL_VM for KERNEL_LOCK",
88 1.1.2.12 matt __func__, ev->ev_name, ipl));
89 1.1.2.12 matt KERNEL_LOCK(1, NULL);
90 1.1.2.12 matt rv = (*func)(arg);
91 1.1.2.12 matt KERNEL_UNLOCK_ONE(NULL);
92 1.1.2.12 matt }
93 1.1.2.12 matt ev->ev_count++;
94 1.1.2.12 matt return rv;
95 1.1.2.12 matt }
96 1.1.2.12 matt
97 1.1.2.1 cliff /*
98 1.1.2.1 cliff * stuff exported from rmixl_spl.S
99 1.1.2.1 cliff */
100 1.1.2.1 cliff extern const struct splsw rmixl_splsw;
101 1.1.2.1 cliff extern uint64_t ipl_eimr_map[];
102 1.1.2.12 matt extern kmutex_t *rmixl_intr_lock;
103 1.1.2.1 cliff
104 1.1.2.11 matt void * rmixl_intr_establish(size_t /* irt */, int /* ipl */, int /* ist */,
105 1.1.2.9 matt int (*)(void *), void *, bool);
106 1.1.2.9 matt void rmixl_intr_disestablish(void *);
107 1.1.2.9 matt void * rmixl_vec_establish(size_t /* vec */, rmixl_intrhand_t *, int /* ipl */,
108 1.1.2.9 matt int (*)(void *), void *, bool);
109 1.1.2.9 matt void rmixl_vec_disestablish(void *);
110 1.1.2.12 matt size_t rmixl_intr_get_vec(int /* ipl */);
111 1.1.2.9 matt const char *
112 1.1.2.9 matt rmixl_intr_string(size_t);
113 1.1.2.9 matt const char *
114 1.1.2.9 matt rmixl_irt_string(size_t);
115 1.1.2.9 matt void rmixl_intr_init_cpu(struct cpu_info *);
116 1.1.2.9 matt void rmixl_intr_init_clk(void);
117 1.1.2.1 cliff #ifdef MULTIPROCESSOR
118 1.1.2.9 matt void rmixl_intr_init_ipi(void);
119 1.1.2.1 cliff #endif
120 1.1.2.1 cliff
121 1.1.2.10 matt void * gpio_intr_establish(size_t /* pin */, int /* ipl */, int /* ist */,
122 1.1.2.10 matt int (*)(void *), void *, bool);
123 1.1.2.10 matt
124 1.1.2.10 matt void gpio_intr_disestablish(void *);
125 1.1.2.1 cliff #endif /* _MIPS_RMI_RMIXL_INTR_H_ */
126