xref: /qemu/include/hw/intc/arm_gicv3_its_common.h (revision 017b2e7363629302da8ea5274e828bc8a8908a73)
1386ce3c7SPavel Fedin /*
2386ce3c7SPavel Fedin  * ITS support for ARM GICv3
3386ce3c7SPavel Fedin  *
4386ce3c7SPavel Fedin  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5386ce3c7SPavel Fedin  * Written by Pavel Fedin
6386ce3c7SPavel Fedin  *
7386ce3c7SPavel Fedin  * This program is free software; you can redistribute it and/or modify
8386ce3c7SPavel Fedin  * it under the terms of the GNU General Public License as published by
9386ce3c7SPavel Fedin  * the Free Software Foundation, either version 2 of the License, or
10386ce3c7SPavel Fedin  * (at your option) any later version.
11386ce3c7SPavel Fedin  *
12386ce3c7SPavel Fedin  * This program is distributed in the hope that it will be useful,
13386ce3c7SPavel Fedin  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14386ce3c7SPavel Fedin  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15386ce3c7SPavel Fedin  * GNU General Public License for more details.
16386ce3c7SPavel Fedin  *
17386ce3c7SPavel Fedin  * You should have received a copy of the GNU General Public License along
18386ce3c7SPavel Fedin  * with this program; if not, see <http://www.gnu.org/licenses/>.
19386ce3c7SPavel Fedin  */
20386ce3c7SPavel Fedin 
21386ce3c7SPavel Fedin #ifndef QEMU_ARM_GICV3_ITS_COMMON_H
22386ce3c7SPavel Fedin #define QEMU_ARM_GICV3_ITS_COMMON_H
23386ce3c7SPavel Fedin 
24386ce3c7SPavel Fedin #include "hw/sysbus.h"
25386ce3c7SPavel Fedin #include "hw/intc/arm_gicv3_common.h"
26db1015e9SEduardo Habkost #include "qom/object.h"
27386ce3c7SPavel Fedin 
2818f6290aSShashi Mallela #define TYPE_ARM_GICV3_ITS "arm-gicv3-its"
2918f6290aSShashi Mallela 
30386ce3c7SPavel Fedin #define ITS_CONTROL_SIZE 0x10000
31386ce3c7SPavel Fedin #define ITS_TRANS_SIZE   0x10000
32386ce3c7SPavel Fedin #define ITS_SIZE         (ITS_CONTROL_SIZE + ITS_TRANS_SIZE)
33386ce3c7SPavel Fedin 
34cddafd8fSEric Auger #define GITS_CTLR        0x0
35cddafd8fSEric Auger #define GITS_IIDR        0x4
3618f6290aSShashi Mallela #define GITS_TYPER       0x8
37cddafd8fSEric Auger #define GITS_CBASER      0x80
38cddafd8fSEric Auger #define GITS_CWRITER     0x88
39cddafd8fSEric Auger #define GITS_CREADR      0x90
40cddafd8fSEric Auger #define GITS_BASER       0x100
41cddafd8fSEric Auger 
4218f6290aSShashi Mallela #define GITS_TRANSLATER  0x0040
4318f6290aSShashi Mallela 
441b08e436SShashi Mallela typedef struct {
451b08e436SShashi Mallela     bool indirect;
461b08e436SShashi Mallela     uint16_t entry_sz;
471b08e436SShashi Mallela     uint32_t page_sz;
4880dcd37fSPeter Maydell     uint32_t num_entries;
491b08e436SShashi Mallela     uint64_t base_addr;
501b08e436SShashi Mallela } TableDesc;
511b08e436SShashi Mallela 
521b08e436SShashi Mallela typedef struct {
5380dcd37fSPeter Maydell     uint32_t num_entries;
541b08e436SShashi Mallela     uint64_t base_addr;
551b08e436SShashi Mallela } CmdQDesc;
561b08e436SShashi Mallela 
57386ce3c7SPavel Fedin struct GICv3ITSState {
58386ce3c7SPavel Fedin     SysBusDevice parent_obj;
59386ce3c7SPavel Fedin 
60386ce3c7SPavel Fedin     MemoryRegion iomem_main;
61386ce3c7SPavel Fedin     MemoryRegion iomem_its_cntrl;
62386ce3c7SPavel Fedin     MemoryRegion iomem_its_translation;
63386ce3c7SPavel Fedin 
64386ce3c7SPavel Fedin     GICv3State *gicv3;
65386ce3c7SPavel Fedin 
66386ce3c7SPavel Fedin     int dev_fd; /* kvm device fd if backed by kvm vgic support */
67386ce3c7SPavel Fedin     uint64_t gits_translater_gpa;
68386ce3c7SPavel Fedin     bool translater_gpa_known;
69386ce3c7SPavel Fedin 
70386ce3c7SPavel Fedin     /* Registers */
71386ce3c7SPavel Fedin     uint32_t ctlr;
72cddafd8fSEric Auger     uint32_t iidr;
7318f6290aSShashi Mallela     uint64_t typer;
74386ce3c7SPavel Fedin     uint64_t cbaser;
75386ce3c7SPavel Fedin     uint64_t cwriter;
76386ce3c7SPavel Fedin     uint64_t creadr;
77386ce3c7SPavel Fedin     uint64_t baser[8];
78386ce3c7SPavel Fedin 
791b08e436SShashi Mallela     TableDesc  dt;
801b08e436SShashi Mallela     TableDesc  ct;
8150d84584SPeter Maydell     TableDesc  vpet;
821b08e436SShashi Mallela     CmdQDesc   cq;
831b08e436SShashi Mallela 
84386ce3c7SPavel Fedin     Error *migration_blocker;
85386ce3c7SPavel Fedin };
86386ce3c7SPavel Fedin 
87386ce3c7SPavel Fedin typedef struct GICv3ITSState GICv3ITSState;
88386ce3c7SPavel Fedin 
8918f6290aSShashi Mallela void gicv3_its_init_mmio(GICv3ITSState *s, const MemoryRegionOps *ops,
9018f6290aSShashi Mallela                    const MemoryRegionOps *tops);
91386ce3c7SPavel Fedin 
927c087bd3SPeter Maydell /*
937c087bd3SPeter Maydell  * The ITS should call this when it is realized to add itself
947c087bd3SPeter Maydell  * to its GIC's list of connected ITSes.
957c087bd3SPeter Maydell  */
gicv3_add_its(GICv3State * s,DeviceState * its)967c087bd3SPeter Maydell static inline void gicv3_add_its(GICv3State *s, DeviceState *its)
977c087bd3SPeter Maydell {
987c087bd3SPeter Maydell     g_ptr_array_add(s->itslist, its);
997c087bd3SPeter Maydell }
1007c087bd3SPeter Maydell 
1013851af45SPeter Maydell /*
1023851af45SPeter Maydell  * The ITS can use this for operations that must be performed on
1033851af45SPeter Maydell  * every ITS connected to the same GIC that it is
1043851af45SPeter Maydell  */
gicv3_foreach_its(GICv3State * s,GFunc func,void * opaque)1053851af45SPeter Maydell static inline void gicv3_foreach_its(GICv3State *s, GFunc func, void *opaque)
1063851af45SPeter Maydell {
1073851af45SPeter Maydell     g_ptr_array_foreach(s->itslist, func, opaque);
1083851af45SPeter Maydell }
1093851af45SPeter Maydell 
110386ce3c7SPavel Fedin #define TYPE_ARM_GICV3_ITS_COMMON "arm-gicv3-its-common"
111db1015e9SEduardo Habkost typedef struct GICv3ITSCommonClass GICv3ITSCommonClass;
1128110fa1dSEduardo Habkost DECLARE_OBJ_CHECKERS(GICv3ITSState, GICv3ITSCommonClass,
1138110fa1dSEduardo Habkost                      ARM_GICV3_ITS_COMMON, TYPE_ARM_GICV3_ITS_COMMON)
114386ce3c7SPavel Fedin 
115386ce3c7SPavel Fedin struct GICv3ITSCommonClass {
116386ce3c7SPavel Fedin     /*< private >*/
117386ce3c7SPavel Fedin     SysBusDeviceClass parent_class;
118386ce3c7SPavel Fedin     /*< public >*/
119386ce3c7SPavel Fedin 
120386ce3c7SPavel Fedin     int (*send_msi)(GICv3ITSState *s, uint32_t data, uint16_t devid);
121386ce3c7SPavel Fedin     void (*pre_save)(GICv3ITSState *s);
122386ce3c7SPavel Fedin     void (*post_load)(GICv3ITSState *s);
123386ce3c7SPavel Fedin };
124386ce3c7SPavel Fedin 
125*0c40daf0SPhilippe Mathieu-Daudé /**
126*0c40daf0SPhilippe Mathieu-Daudé  * its_class_name:
127*0c40daf0SPhilippe Mathieu-Daudé  *
128*0c40daf0SPhilippe Mathieu-Daudé  * Return the ITS class name to use depending on whether KVM acceleration
129*0c40daf0SPhilippe Mathieu-Daudé  * and KVM CAP_SIGNAL_MSI are supported
130*0c40daf0SPhilippe Mathieu-Daudé  *
131*0c40daf0SPhilippe Mathieu-Daudé  * Returns: class name to use or NULL
132*0c40daf0SPhilippe Mathieu-Daudé  */
133*0c40daf0SPhilippe Mathieu-Daudé const char *its_class_name(void);
134386ce3c7SPavel Fedin 
135386ce3c7SPavel Fedin #endif
136