blob: 309b4d65b74fa728d3acaf358c5685e5949a4612 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Copyright 2016,2017 IBM Corporation.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 */
5#ifndef _ASM_POWERPC_XIVE_H
6#define _ASM_POWERPC_XIVE_H
7
Olivier Deprez157378f2022-04-04 15:47:50 +02008#include <asm/opal-api.h>
9
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010#define XIVE_INVALID_VP 0xffffffff
11
12#ifdef CONFIG_PPC_XIVE
13
14/*
15 * Thread Interrupt Management Area (TIMA)
16 *
17 * This is a global MMIO region divided in 4 pages of varying access
18 * permissions, providing access to per-cpu interrupt management
19 * functions. It always identifies the CPU doing the access based
20 * on the PowerBus initiator ID, thus we always access via the
21 * same offset regardless of where the code is executing
22 */
23extern void __iomem *xive_tima;
David Brazdil0f672f62019-12-10 10:32:29 +000024extern unsigned long xive_tima_os;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025
26/*
27 * Offset in the TM area of our current execution level (provided by
28 * the backend)
29 */
30extern u32 xive_tima_offset;
31
32/*
33 * Per-irq data (irq_get_handler_data for normal IRQs), IPIs
34 * have it stored in the xive_cpu structure. We also cache
35 * for normal interrupts the current target CPU.
36 *
37 * This structure is setup by the backend for each interrupt.
38 */
39struct xive_irq_data {
40 u64 flags;
41 u64 eoi_page;
42 void __iomem *eoi_mmio;
43 u64 trig_page;
44 void __iomem *trig_mmio;
45 u32 esb_shift;
46 int src_chip;
47 u32 hw_irq;
48
49 /* Setup/used by frontend */
50 int target;
David Brazdil0f672f62019-12-10 10:32:29 +000051 /*
52 * saved_p means that there is a queue entry for this interrupt
53 * in some CPU's queue (not including guest vcpu queues), even
54 * if P is not set in the source ESB.
55 * stale_p means that there is no queue entry for this interrupt
56 * in some CPU's queue, even if P is set in the source ESB.
57 */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000058 bool saved_p;
David Brazdil0f672f62019-12-10 10:32:29 +000059 bool stale_p;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000060};
61#define XIVE_IRQ_FLAG_STORE_EOI 0x01
62#define XIVE_IRQ_FLAG_LSI 0x02
63#define XIVE_IRQ_FLAG_SHIFT_BUG 0x04
64#define XIVE_IRQ_FLAG_MASK_FW 0x08
65#define XIVE_IRQ_FLAG_EOI_FW 0x10
66#define XIVE_IRQ_FLAG_H_INT_ESB 0x20
67
68/* Special flag set by KVM for excalation interrupts */
69#define XIVE_IRQ_NO_EOI 0x80
70
71#define XIVE_INVALID_CHIP_ID -1
72
73/* A queue tracking structure in a CPU */
74struct xive_q {
75 __be32 *qpage;
76 u32 msk;
77 u32 idx;
78 u32 toggle;
79 u64 eoi_phys;
80 u32 esc_irq;
81 atomic_t count;
82 atomic_t pending_count;
David Brazdil0f672f62019-12-10 10:32:29 +000083 u64 guest_qaddr;
84 u32 guest_qshift;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085};
86
87/* Global enable flags for the XIVE support */
88extern bool __xive_enabled;
89
90static inline bool xive_enabled(void) { return __xive_enabled; }
91
Olivier Deprez157378f2022-04-04 15:47:50 +020092bool xive_spapr_init(void);
93bool xive_native_init(void);
94void xive_smp_probe(void);
95int xive_smp_prepare_cpu(unsigned int cpu);
96void xive_smp_setup_cpu(void);
97void xive_smp_disable_cpu(void);
98void xive_teardown_cpu(void);
99void xive_shutdown(void);
100void xive_flush_interrupt(void);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000101
102/* xmon hook */
Olivier Deprez157378f2022-04-04 15:47:50 +0200103void xmon_xive_do_dump(int cpu);
104int xmon_xive_get_irq_config(u32 hw_irq, struct irq_data *d);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000105
106/* APIs used by KVM */
Olivier Deprez157378f2022-04-04 15:47:50 +0200107u32 xive_native_default_eq_shift(void);
108u32 xive_native_alloc_vp_block(u32 max_vcpus);
109void xive_native_free_vp_block(u32 vp_base);
110int xive_native_populate_irq_data(u32 hw_irq,
111 struct xive_irq_data *data);
112void xive_cleanup_irq_data(struct xive_irq_data *xd);
113void xive_native_free_irq(u32 irq);
114int xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000115
Olivier Deprez157378f2022-04-04 15:47:50 +0200116int xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio,
117 __be32 *qpage, u32 order, bool can_escalate);
118void xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000119
Olivier Deprez157378f2022-04-04 15:47:50 +0200120void xive_native_sync_source(u32 hw_irq);
121void xive_native_sync_queue(u32 hw_irq);
122bool is_xive_irq(struct irq_chip *chip);
123int xive_native_enable_vp(u32 vp_id, bool single_escalation);
124int xive_native_disable_vp(u32 vp_id);
125int xive_native_get_vp_info(u32 vp_id, u32 *out_cam_id, u32 *out_chip_id);
126bool xive_native_has_single_escalation(void);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000127
Olivier Deprez157378f2022-04-04 15:47:50 +0200128int xive_native_get_queue_info(u32 vp_id, uint32_t prio,
129 u64 *out_qpage,
130 u64 *out_qsize,
131 u64 *out_qeoi_page,
132 u32 *out_escalate_irq,
133 u64 *out_qflags);
David Brazdil0f672f62019-12-10 10:32:29 +0000134
Olivier Deprez157378f2022-04-04 15:47:50 +0200135int xive_native_get_queue_state(u32 vp_id, uint32_t prio, u32 *qtoggle,
136 u32 *qindex);
137int xive_native_set_queue_state(u32 vp_id, uint32_t prio, u32 qtoggle,
138 u32 qindex);
139int xive_native_get_vp_state(u32 vp_id, u64 *out_state);
140bool xive_native_has_queue_state_support(void);
141extern u32 xive_native_alloc_irq_on_chip(u32 chip_id);
142
143static inline u32 xive_native_alloc_irq(void)
144{
145 return xive_native_alloc_irq_on_chip(OPAL_XIVE_ANY_CHIP);
146}
David Brazdil0f672f62019-12-10 10:32:29 +0000147
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000148#else
149
150static inline bool xive_enabled(void) { return false; }
151
152static inline bool xive_spapr_init(void) { return false; }
153static inline bool xive_native_init(void) { return false; }
154static inline void xive_smp_probe(void) { }
155static inline int xive_smp_prepare_cpu(unsigned int cpu) { return -EINVAL; }
156static inline void xive_smp_setup_cpu(void) { }
157static inline void xive_smp_disable_cpu(void) { }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000158static inline void xive_shutdown(void) { }
159static inline void xive_flush_interrupt(void) { }
160
161static inline u32 xive_native_alloc_vp_block(u32 max_vcpus) { return XIVE_INVALID_VP; }
162static inline void xive_native_free_vp_block(u32 vp_base) { }
163
164#endif
165
166#endif /* _ASM_POWERPC_XIVE_H */