162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2016,2017 IBM Corporation. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci#ifndef _ASM_POWERPC_XIVE_H 662306a36Sopenharmony_ci#define _ASM_POWERPC_XIVE_H 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <asm/opal-api.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#define XIVE_INVALID_VP 0xffffffff 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifdef CONFIG_PPC_XIVE 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* 1562306a36Sopenharmony_ci * Thread Interrupt Management Area (TIMA) 1662306a36Sopenharmony_ci * 1762306a36Sopenharmony_ci * This is a global MMIO region divided in 4 pages of varying access 1862306a36Sopenharmony_ci * permissions, providing access to per-cpu interrupt management 1962306a36Sopenharmony_ci * functions. It always identifies the CPU doing the access based 2062306a36Sopenharmony_ci * on the PowerBus initiator ID, thus we always access via the 2162306a36Sopenharmony_ci * same offset regardless of where the code is executing 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_ciextern void __iomem *xive_tima; 2462306a36Sopenharmony_ciextern unsigned long xive_tima_os; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * Offset in the TM area of our current execution level (provided by 2862306a36Sopenharmony_ci * the backend) 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ciextern u32 xive_tima_offset; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* 3362306a36Sopenharmony_ci * Per-irq data (irq_get_handler_data for normal IRQs), IPIs 3462306a36Sopenharmony_ci * have it stored in the xive_cpu structure. We also cache 3562306a36Sopenharmony_ci * for normal interrupts the current target CPU. 3662306a36Sopenharmony_ci * 3762306a36Sopenharmony_ci * This structure is setup by the backend for each interrupt. 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_cistruct xive_irq_data { 4062306a36Sopenharmony_ci u64 flags; 4162306a36Sopenharmony_ci u64 eoi_page; 4262306a36Sopenharmony_ci void __iomem *eoi_mmio; 4362306a36Sopenharmony_ci u64 trig_page; 4462306a36Sopenharmony_ci void __iomem *trig_mmio; 4562306a36Sopenharmony_ci u32 esb_shift; 4662306a36Sopenharmony_ci int src_chip; 4762306a36Sopenharmony_ci u32 hw_irq; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci /* Setup/used by frontend */ 5062306a36Sopenharmony_ci int target; 5162306a36Sopenharmony_ci /* 5262306a36Sopenharmony_ci * saved_p means that there is a queue entry for this interrupt 5362306a36Sopenharmony_ci * in some CPU's queue (not including guest vcpu queues), even 5462306a36Sopenharmony_ci * if P is not set in the source ESB. 5562306a36Sopenharmony_ci * stale_p means that there is no queue entry for this interrupt 5662306a36Sopenharmony_ci * in some CPU's queue, even if P is set in the source ESB. 5762306a36Sopenharmony_ci */ 5862306a36Sopenharmony_ci bool saved_p; 5962306a36Sopenharmony_ci bool stale_p; 6062306a36Sopenharmony_ci}; 6162306a36Sopenharmony_ci#define XIVE_IRQ_FLAG_STORE_EOI 0x01 6262306a36Sopenharmony_ci#define XIVE_IRQ_FLAG_LSI 0x02 6362306a36Sopenharmony_ci/* #define XIVE_IRQ_FLAG_SHIFT_BUG 0x04 */ /* P9 DD1.0 workaround */ 6462306a36Sopenharmony_ci/* #define XIVE_IRQ_FLAG_MASK_FW 0x08 */ /* P9 DD1.0 workaround */ 6562306a36Sopenharmony_ci/* #define XIVE_IRQ_FLAG_EOI_FW 0x10 */ /* P9 DD1.0 workaround */ 6662306a36Sopenharmony_ci#define XIVE_IRQ_FLAG_H_INT_ESB 0x20 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* Special flag set by KVM for excalation interrupts */ 6962306a36Sopenharmony_ci#define XIVE_IRQ_FLAG_NO_EOI 0x80 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define XIVE_INVALID_CHIP_ID -1 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* A queue tracking structure in a CPU */ 7462306a36Sopenharmony_cistruct xive_q { 7562306a36Sopenharmony_ci __be32 *qpage; 7662306a36Sopenharmony_ci u32 msk; 7762306a36Sopenharmony_ci u32 idx; 7862306a36Sopenharmony_ci u32 toggle; 7962306a36Sopenharmony_ci u64 eoi_phys; 8062306a36Sopenharmony_ci u32 esc_irq; 8162306a36Sopenharmony_ci atomic_t count; 8262306a36Sopenharmony_ci atomic_t pending_count; 8362306a36Sopenharmony_ci u64 guest_qaddr; 8462306a36Sopenharmony_ci u32 guest_qshift; 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* Global enable flags for the XIVE support */ 8862306a36Sopenharmony_ciextern bool __xive_enabled; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistatic inline bool xive_enabled(void) { return __xive_enabled; } 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cibool xive_spapr_init(void); 9362306a36Sopenharmony_cibool xive_native_init(void); 9462306a36Sopenharmony_civoid xive_smp_probe(void); 9562306a36Sopenharmony_ciint xive_smp_prepare_cpu(unsigned int cpu); 9662306a36Sopenharmony_civoid xive_smp_setup_cpu(void); 9762306a36Sopenharmony_civoid xive_smp_disable_cpu(void); 9862306a36Sopenharmony_civoid xive_teardown_cpu(void); 9962306a36Sopenharmony_civoid xive_shutdown(void); 10062306a36Sopenharmony_civoid xive_flush_interrupt(void); 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/* xmon hook */ 10362306a36Sopenharmony_civoid xmon_xive_do_dump(int cpu); 10462306a36Sopenharmony_ciint xmon_xive_get_irq_config(u32 hw_irq, struct irq_data *d); 10562306a36Sopenharmony_civoid xmon_xive_get_irq_all(void); 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* APIs used by KVM */ 10862306a36Sopenharmony_ciu32 xive_native_default_eq_shift(void); 10962306a36Sopenharmony_ciu32 xive_native_alloc_vp_block(u32 max_vcpus); 11062306a36Sopenharmony_civoid xive_native_free_vp_block(u32 vp_base); 11162306a36Sopenharmony_ciint xive_native_populate_irq_data(u32 hw_irq, 11262306a36Sopenharmony_ci struct xive_irq_data *data); 11362306a36Sopenharmony_civoid xive_cleanup_irq_data(struct xive_irq_data *xd); 11462306a36Sopenharmony_civoid xive_irq_free_data(unsigned int virq); 11562306a36Sopenharmony_civoid xive_native_free_irq(u32 irq); 11662306a36Sopenharmony_ciint xive_native_configure_irq(u32 hw_irq, u32 target, u8 prio, u32 sw_irq); 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ciint xive_native_configure_queue(u32 vp_id, struct xive_q *q, u8 prio, 11962306a36Sopenharmony_ci __be32 *qpage, u32 order, bool can_escalate); 12062306a36Sopenharmony_civoid xive_native_disable_queue(u32 vp_id, struct xive_q *q, u8 prio); 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_civoid xive_native_sync_source(u32 hw_irq); 12362306a36Sopenharmony_civoid xive_native_sync_queue(u32 hw_irq); 12462306a36Sopenharmony_cibool is_xive_irq(struct irq_chip *chip); 12562306a36Sopenharmony_ciint xive_native_enable_vp(u32 vp_id, bool single_escalation); 12662306a36Sopenharmony_ciint xive_native_disable_vp(u32 vp_id); 12762306a36Sopenharmony_ciint xive_native_get_vp_info(u32 vp_id, u32 *out_cam_id, u32 *out_chip_id); 12862306a36Sopenharmony_cibool xive_native_has_single_escalation(void); 12962306a36Sopenharmony_cibool xive_native_has_save_restore(void); 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ciint xive_native_get_queue_info(u32 vp_id, uint32_t prio, 13262306a36Sopenharmony_ci u64 *out_qpage, 13362306a36Sopenharmony_ci u64 *out_qsize, 13462306a36Sopenharmony_ci u64 *out_qeoi_page, 13562306a36Sopenharmony_ci u32 *out_escalate_irq, 13662306a36Sopenharmony_ci u64 *out_qflags); 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ciint xive_native_get_queue_state(u32 vp_id, uint32_t prio, u32 *qtoggle, 13962306a36Sopenharmony_ci u32 *qindex); 14062306a36Sopenharmony_ciint xive_native_set_queue_state(u32 vp_id, uint32_t prio, u32 qtoggle, 14162306a36Sopenharmony_ci u32 qindex); 14262306a36Sopenharmony_ciint xive_native_get_vp_state(u32 vp_id, u64 *out_state); 14362306a36Sopenharmony_cibool xive_native_has_queue_state_support(void); 14462306a36Sopenharmony_ciextern u32 xive_native_alloc_irq_on_chip(u32 chip_id); 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_cistatic inline u32 xive_native_alloc_irq(void) 14762306a36Sopenharmony_ci{ 14862306a36Sopenharmony_ci return xive_native_alloc_irq_on_chip(OPAL_XIVE_ANY_CHIP); 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#else 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cistatic inline bool xive_enabled(void) { return false; } 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cistatic inline bool xive_spapr_init(void) { return false; } 15662306a36Sopenharmony_cistatic inline bool xive_native_init(void) { return false; } 15762306a36Sopenharmony_cistatic inline void xive_smp_probe(void) { } 15862306a36Sopenharmony_cistatic inline int xive_smp_prepare_cpu(unsigned int cpu) { return -EINVAL; } 15962306a36Sopenharmony_cistatic inline void xive_smp_setup_cpu(void) { } 16062306a36Sopenharmony_cistatic inline void xive_smp_disable_cpu(void) { } 16162306a36Sopenharmony_cistatic inline void xive_shutdown(void) { } 16262306a36Sopenharmony_cistatic inline void xive_flush_interrupt(void) { } 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_cistatic inline u32 xive_native_alloc_vp_block(u32 max_vcpus) { return XIVE_INVALID_VP; } 16562306a36Sopenharmony_cistatic inline void xive_native_free_vp_block(u32 vp_base) { } 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci#endif 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci#endif /* _ASM_POWERPC_XIVE_H */ 170