xref: /qemu/include/hw/ppc/spapr_irq.h (revision 05289273c06de4bc6ece85a8bf672e588e34f36b)
182cffa2eSCédric Le Goater /*
282cffa2eSCédric Le Goater  * QEMU PowerPC sPAPR IRQ backend definitions
382cffa2eSCédric Le Goater  *
482cffa2eSCédric Le Goater  * Copyright (c) 2018, IBM Corporation.
582cffa2eSCédric Le Goater  *
682cffa2eSCédric Le Goater  * This code is licensed under the GPL version 2 or later. See the
782cffa2eSCédric Le Goater  * COPYING file in the top-level directory.
882cffa2eSCédric Le Goater  */
982cffa2eSCédric Le Goater 
1082cffa2eSCédric Le Goater #ifndef HW_SPAPR_IRQ_H
1182cffa2eSCédric Le Goater #define HW_SPAPR_IRQ_H
1282cffa2eSCédric Le Goater 
13ec150c7eSMarkus Armbruster #include "target/ppc/cpu-qom.h"
14ec150c7eSMarkus Armbruster 
1582cffa2eSCédric Le Goater /*
1682cffa2eSCédric Le Goater  * IRQ range offsets per device type
1782cffa2eSCédric Le Goater  */
18dcc345b6SCédric Le Goater #define SPAPR_IRQ_IPI        0x0
1982cffa2eSCédric Le Goater 
20ad8de986SDavid Gibson #define SPAPR_XIRQ_BASE      XICS_IRQ_BASE /* 0x1000 */
21ad8de986SDavid Gibson #define SPAPR_IRQ_EPOW       (SPAPR_XIRQ_BASE + 0x0000)
22ad8de986SDavid Gibson #define SPAPR_IRQ_HOTPLUG    (SPAPR_XIRQ_BASE + 0x0001)
23ad8de986SDavid Gibson #define SPAPR_IRQ_VIO        (SPAPR_XIRQ_BASE + 0x0100)  /* 256 VIO devices */
24ad8de986SDavid Gibson #define SPAPR_IRQ_PCI_LSI    (SPAPR_XIRQ_BASE + 0x0200)  /* 32+ PHBs devices */
25ad8de986SDavid Gibson 
26ad8de986SDavid Gibson /* Offset of the dynamic range covered by the bitmap allocator */
27ad8de986SDavid Gibson #define SPAPR_IRQ_MSI        (SPAPR_XIRQ_BASE + 0x0300)
28ad8de986SDavid Gibson 
29ad8de986SDavid Gibson #define SPAPR_NR_XIRQS       0x1000
30ad8de986SDavid Gibson #define SPAPR_NR_MSIS        (SPAPR_XIRQ_BASE + SPAPR_NR_XIRQS - SPAPR_IRQ_MSI)
3182cffa2eSCédric Le Goater 
32ce2918cbSDavid Gibson typedef struct SpaprMachineState SpaprMachineState;
3382cffa2eSCédric Le Goater 
34150e25f8SDavid Gibson typedef struct SpaprInterruptController SpaprInterruptController;
35150e25f8SDavid Gibson 
36150e25f8SDavid Gibson #define TYPE_SPAPR_INTC "spapr-interrupt-controller"
37150e25f8SDavid Gibson #define SPAPR_INTC(obj)                                     \
38150e25f8SDavid Gibson     INTERFACE_CHECK(SpaprInterruptController, (obj), TYPE_SPAPR_INTC)
39150e25f8SDavid Gibson #define SPAPR_INTC_CLASS(klass)                                     \
40150e25f8SDavid Gibson     OBJECT_CLASS_CHECK(SpaprInterruptControllerClass, (klass), TYPE_SPAPR_INTC)
41150e25f8SDavid Gibson #define SPAPR_INTC_GET_CLASS(obj)                                   \
42150e25f8SDavid Gibson     OBJECT_GET_CLASS(SpaprInterruptControllerClass, (obj), TYPE_SPAPR_INTC)
43150e25f8SDavid Gibson 
44150e25f8SDavid Gibson typedef struct SpaprInterruptControllerClass {
45150e25f8SDavid Gibson     InterfaceClass parent;
46ebd6be08SDavid Gibson 
4781106dddSDavid Gibson     int (*activate)(SpaprInterruptController *intc, Error **errp);
4881106dddSDavid Gibson     void (*deactivate)(SpaprInterruptController *intc);
4981106dddSDavid Gibson 
50ebd6be08SDavid Gibson     /*
51ebd6be08SDavid Gibson      * These methods will typically be called on all intcs, active and
52ebd6be08SDavid Gibson      * inactive
53ebd6be08SDavid Gibson      */
54ebd6be08SDavid Gibson     int (*cpu_intc_create)(SpaprInterruptController *intc,
55ebd6be08SDavid Gibson                             PowerPCCPU *cpu, Error **errp);
560b0e52b1SDavid Gibson     int (*claim_irq)(SpaprInterruptController *intc, int irq, bool lsi,
570b0e52b1SDavid Gibson                      Error **errp);
580b0e52b1SDavid Gibson     void (*free_irq)(SpaprInterruptController *intc, int irq);
597bcdbccaSDavid Gibson 
607bcdbccaSDavid Gibson     /* These methods should only be called on the active intc */
617bcdbccaSDavid Gibson     void (*set_irq)(SpaprInterruptController *intc, int irq, int val);
62328d8eb2SDavid Gibson     void (*print_info)(SpaprInterruptController *intc, Monitor *mon);
63*05289273SDavid Gibson     void (*dt)(SpaprInterruptController *intc, uint32_t nr_servers,
64*05289273SDavid Gibson                void *fdt, uint32_t phandle);
65150e25f8SDavid Gibson } SpaprInterruptControllerClass;
66150e25f8SDavid Gibson 
6781106dddSDavid Gibson void spapr_irq_update_active_intc(SpaprMachineState *spapr);
6881106dddSDavid Gibson 
69ebd6be08SDavid Gibson int spapr_irq_cpu_intc_create(SpaprMachineState *spapr,
70ebd6be08SDavid Gibson                               PowerPCCPU *cpu, Error **errp);
71328d8eb2SDavid Gibson void spapr_irq_print_info(SpaprMachineState *spapr, Monitor *mon);
72*05289273SDavid Gibson void spapr_irq_dt(SpaprMachineState *spapr, uint32_t nr_servers,
73*05289273SDavid Gibson                   void *fdt, uint32_t phandle);
74ebd6be08SDavid Gibson 
75ce2918cbSDavid Gibson void spapr_irq_msi_init(SpaprMachineState *spapr, uint32_t nr_msis);
76ce2918cbSDavid Gibson int spapr_irq_msi_alloc(SpaprMachineState *spapr, uint32_t num, bool align,
7782cffa2eSCédric Le Goater                         Error **errp);
78ce2918cbSDavid Gibson void spapr_irq_msi_free(SpaprMachineState *spapr, int irq, uint32_t num);
7982cffa2eSCédric Le Goater 
80ce2918cbSDavid Gibson typedef struct SpaprIrq {
81ad8de986SDavid Gibson     uint32_t    nr_xirqs;
82e39de895SCédric Le Goater     uint32_t    nr_msis;
83ca62823bSDavid Gibson     bool        xics;
84ca62823bSDavid Gibson     bool        xive;
85ef01ed9dSCédric Le Goater 
86ce2918cbSDavid Gibson     int (*post_load)(SpaprMachineState *spapr, int version_id);
87ce2918cbSDavid Gibson     void (*reset)(SpaprMachineState *spapr, Error **errp);
88ae805ea9SCédric Le Goater     void (*init_kvm)(SpaprMachineState *spapr, Error **errp);
89ce2918cbSDavid Gibson } SpaprIrq;
90ef01ed9dSCédric Le Goater 
91ce2918cbSDavid Gibson extern SpaprIrq spapr_irq_xics;
92ce2918cbSDavid Gibson extern SpaprIrq spapr_irq_xics_legacy;
93ce2918cbSDavid Gibson extern SpaprIrq spapr_irq_xive;
94ce2918cbSDavid Gibson extern SpaprIrq spapr_irq_dual;
95ef01ed9dSCédric Le Goater 
96ce2918cbSDavid Gibson void spapr_irq_init(SpaprMachineState *spapr, Error **errp);
97ce2918cbSDavid Gibson int spapr_irq_claim(SpaprMachineState *spapr, int irq, bool lsi, Error **errp);
98ce2918cbSDavid Gibson void spapr_irq_free(SpaprMachineState *spapr, int irq, int num);
99ce2918cbSDavid Gibson qemu_irq spapr_qirq(SpaprMachineState *spapr, int irq);
100ce2918cbSDavid Gibson int spapr_irq_post_load(SpaprMachineState *spapr, int version_id);
101ce2918cbSDavid Gibson void spapr_irq_reset(SpaprMachineState *spapr, Error **errp);
102ce2918cbSDavid Gibson int spapr_irq_get_phandle(SpaprMachineState *spapr, void *fdt, Error **errp);
103ef01ed9dSCédric Le Goater 
104ef01ed9dSCédric Le Goater /*
105ef01ed9dSCédric Le Goater  * XICS legacy routines
106ef01ed9dSCédric Le Goater  */
107ce2918cbSDavid Gibson int spapr_irq_find(SpaprMachineState *spapr, int num, bool align, Error **errp);
108ef01ed9dSCédric Le Goater #define spapr_irq_findone(spapr, errp) spapr_irq_find(spapr, 1, false, errp)
109ef01ed9dSCédric Le Goater 
11082cffa2eSCédric Le Goater #endif
111