Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 2 | /* |
Adam Buchbinder | 446957b | 2016-02-24 10:51:11 -0800 | [diff] [blame] | 3 | * Common definitions across all variants of ICP and ICS interrupt |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 4 | * controllers. |
| 5 | */ |
| 6 | |
| 7 | #ifndef _XICS_H |
| 8 | #define _XICS_H |
| 9 | |
Michael Ellerman | cd85257 | 2011-04-14 22:31:58 +0000 | [diff] [blame] | 10 | #include <linux/interrupt.h> |
| 11 | |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 12 | #define XICS_IPI 2 |
| 13 | #define XICS_IRQ_SPURIOUS 0 |
| 14 | |
| 15 | /* Want a priority other than 0. Various HW issues require this. */ |
| 16 | #define DEFAULT_PRIORITY 5 |
| 17 | |
| 18 | /* |
Yong Zhang | a3a9f3b | 2011-10-21 23:56:27 +0000 | [diff] [blame] | 19 | * Mark IPIs as higher priority so we can take them inside interrupts |
| 20 | * FIXME: still true now? |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 21 | */ |
| 22 | #define IPI_PRIORITY 4 |
| 23 | |
| 24 | /* The least favored priority */ |
| 25 | #define LOWEST_PRIORITY 0xFF |
| 26 | |
| 27 | /* The number of priorities defined above */ |
| 28 | #define MAX_NUM_PRIORITIES 3 |
| 29 | |
| 30 | /* Native ICP */ |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 31 | #ifdef CONFIG_PPC_ICP_NATIVE |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 32 | extern int icp_native_init(void); |
Paul Mackerras | d6a4f70 | 2014-09-02 14:23:16 +1000 | [diff] [blame] | 33 | extern void icp_native_flush_interrupt(void); |
Suresh Warrier | ec13e9b | 2015-12-17 14:59:05 -0600 | [diff] [blame] | 34 | extern void icp_native_cause_ipi_rm(int cpu); |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 35 | #else |
| 36 | static inline int icp_native_init(void) { return -ENODEV; } |
| 37 | #endif |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 38 | |
| 39 | /* PAPR ICP */ |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 40 | #ifdef CONFIG_PPC_ICP_HV |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 41 | extern int icp_hv_init(void); |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 42 | #else |
| 43 | static inline int icp_hv_init(void) { return -ENODEV; } |
| 44 | #endif |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 45 | |
Benjamin Herrenschmidt | d743618 | 2016-07-08 16:37:08 +1000 | [diff] [blame] | 46 | #ifdef CONFIG_PPC_POWERNV |
| 47 | extern int icp_opal_init(void); |
Benjamin Herrenschmidt | 9b25671 | 2017-02-07 11:35:31 +1100 | [diff] [blame] | 48 | extern void icp_opal_flush_interrupt(void); |
Benjamin Herrenschmidt | d743618 | 2016-07-08 16:37:08 +1000 | [diff] [blame] | 49 | #else |
| 50 | static inline int icp_opal_init(void) { return -ENODEV; } |
| 51 | #endif |
| 52 | |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 53 | /* ICP ops */ |
| 54 | struct icp_ops { |
| 55 | unsigned int (*get_irq)(void); |
| 56 | void (*eoi)(struct irq_data *d); |
| 57 | void (*set_priority)(unsigned char prio); |
| 58 | void (*teardown_cpu)(void); |
| 59 | void (*flush_ipi)(void); |
| 60 | #ifdef CONFIG_SMP |
Nicholas Piggin | b866cc2 | 2017-04-13 20:16:21 +1000 | [diff] [blame] | 61 | void (*cause_ipi)(int cpu); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 62 | irq_handler_t ipi_action; |
| 63 | #endif |
| 64 | }; |
| 65 | |
| 66 | extern const struct icp_ops *icp_ops; |
| 67 | |
Benjamin Herrenschmidt | aa9c5ad | 2021-06-18 13:45:53 +1000 | [diff] [blame] | 68 | #ifdef CONFIG_PPC_ICS_NATIVE |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 69 | /* Native ICS */ |
| 70 | extern int ics_native_init(void); |
Benjamin Herrenschmidt | aa9c5ad | 2021-06-18 13:45:53 +1000 | [diff] [blame] | 71 | #else |
| 72 | static inline int ics_native_init(void) { return -ENODEV; } |
| 73 | #endif |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 74 | |
| 75 | /* RTAS ICS */ |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_PPC_ICS_RTAS |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 77 | extern int ics_rtas_init(void); |
Benjamin Herrenschmidt | 5c7c1e9 | 2011-09-19 17:45:02 +0000 | [diff] [blame] | 78 | #else |
| 79 | static inline int ics_rtas_init(void) { return -ENODEV; } |
| 80 | #endif |
| 81 | |
| 82 | /* HAL ICS */ |
| 83 | #ifdef CONFIG_PPC_POWERNV |
| 84 | extern int ics_opal_init(void); |
| 85 | #else |
| 86 | static inline int ics_opal_init(void) { return -ENODEV; } |
| 87 | #endif |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 88 | |
| 89 | /* ICS instance, hooked up to chip_data of an irq */ |
| 90 | struct ics { |
| 91 | struct list_head link; |
Cédric Le Goater | 248af24 | 2021-07-01 15:27:35 +0200 | [diff] [blame] | 92 | int (*check)(struct ics *ics, unsigned int hwirq); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 93 | void (*mask_unknown)(struct ics *ics, unsigned long vec); |
| 94 | long (*get_server)(struct ics *ics, unsigned long vec); |
Michael Ellerman | 5ca1237 | 2011-04-14 22:31:59 +0000 | [diff] [blame] | 95 | int (*host_match)(struct ics *ics, struct device_node *node); |
Cédric Le Goater | 248af24 | 2021-07-01 15:27:35 +0200 | [diff] [blame] | 96 | struct irq_chip *chip; |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 97 | char data[]; |
| 98 | }; |
| 99 | |
| 100 | /* Commons */ |
| 101 | extern unsigned int xics_default_server; |
| 102 | extern unsigned int xics_default_distrib_server; |
| 103 | extern unsigned int xics_interrupt_server_size; |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 104 | extern struct irq_domain *xics_host; |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 105 | |
| 106 | struct xics_cppr { |
| 107 | unsigned char stack[MAX_NUM_PRIORITIES]; |
| 108 | int index; |
| 109 | }; |
| 110 | |
| 111 | DECLARE_PER_CPU(struct xics_cppr, xics_cppr); |
| 112 | |
| 113 | static inline void xics_push_cppr(unsigned int vec) |
| 114 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 115 | struct xics_cppr *os_cppr = this_cpu_ptr(&xics_cppr); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 116 | |
| 117 | if (WARN_ON(os_cppr->index >= MAX_NUM_PRIORITIES - 1)) |
| 118 | return; |
| 119 | |
| 120 | if (vec == XICS_IPI) |
| 121 | os_cppr->stack[++os_cppr->index] = IPI_PRIORITY; |
| 122 | else |
| 123 | os_cppr->stack[++os_cppr->index] = DEFAULT_PRIORITY; |
| 124 | } |
| 125 | |
| 126 | static inline unsigned char xics_pop_cppr(void) |
| 127 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 128 | struct xics_cppr *os_cppr = this_cpu_ptr(&xics_cppr); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 129 | |
| 130 | if (WARN_ON(os_cppr->index < 1)) |
| 131 | return LOWEST_PRIORITY; |
| 132 | |
| 133 | return os_cppr->stack[--os_cppr->index]; |
| 134 | } |
| 135 | |
| 136 | static inline void xics_set_base_cppr(unsigned char cppr) |
| 137 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 138 | struct xics_cppr *os_cppr = this_cpu_ptr(&xics_cppr); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 139 | |
| 140 | /* we only really want to set the priority when there's |
| 141 | * just one cppr value on the stack |
| 142 | */ |
| 143 | WARN_ON(os_cppr->index != 0); |
| 144 | |
| 145 | os_cppr->stack[0] = cppr; |
| 146 | } |
| 147 | |
| 148 | static inline unsigned char xics_cppr_top(void) |
| 149 | { |
Christoph Lameter | 69111ba | 2014-10-21 15:23:25 -0500 | [diff] [blame] | 150 | struct xics_cppr *os_cppr = this_cpu_ptr(&xics_cppr); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 151 | |
| 152 | return os_cppr->stack[os_cppr->index]; |
| 153 | } |
| 154 | |
| 155 | DECLARE_PER_CPU_SHARED_ALIGNED(unsigned long, xics_ipi_message); |
| 156 | |
| 157 | extern void xics_init(void); |
| 158 | extern void xics_setup_cpu(void); |
| 159 | extern void xics_update_irq_servers(void); |
| 160 | extern void xics_set_cpu_giq(unsigned int gserver, unsigned int join); |
| 161 | extern void xics_mask_unknown_vec(unsigned int vec); |
| 162 | extern irqreturn_t xics_ipi_dispatch(int cpu); |
Michael Ellerman | a7f4ee1 | 2015-04-04 19:28:50 +1100 | [diff] [blame] | 163 | extern void xics_smp_probe(void); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 164 | extern void xics_register_ics(struct ics *ics); |
| 165 | extern void xics_teardown_cpu(void); |
| 166 | extern void xics_kexec_teardown_cpu(int secondary); |
| 167 | extern void xics_migrate_irqs_away(void); |
Gavin Shan | 137436c | 2013-04-25 19:20:59 +0000 | [diff] [blame] | 168 | extern void icp_native_eoi(struct irq_data *d); |
Benjamin Herrenschmidt | 880a3d6 | 2016-08-02 12:39:43 +1000 | [diff] [blame] | 169 | extern int xics_set_irq_type(struct irq_data *d, unsigned int flow_type); |
| 170 | extern int xics_retrigger(struct irq_data *data); |
Benjamin Herrenschmidt | 0b05ac6 | 2011-04-04 13:46:58 +1000 | [diff] [blame] | 171 | #ifdef CONFIG_SMP |
| 172 | extern int xics_get_irq_server(unsigned int virq, const struct cpumask *cpumask, |
| 173 | unsigned int strict_check); |
| 174 | #else |
| 175 | #define xics_get_irq_server(virq, cpumask, strict_check) (xics_default_server) |
| 176 | #endif |
| 177 | |
| 178 | |
| 179 | #endif /* _XICS_H */ |