118f6290aSShashi Mallela /* 218f6290aSShashi Mallela * ITS emulation for a GICv3-based system 318f6290aSShashi Mallela * 418f6290aSShashi Mallela * Copyright Linaro.org 2021 518f6290aSShashi Mallela * 618f6290aSShashi Mallela * Authors: 718f6290aSShashi Mallela * Shashi Mallela <shashi.mallela@linaro.org> 818f6290aSShashi Mallela * 918f6290aSShashi Mallela * This work is licensed under the terms of the GNU GPL, version 2 or (at your 1018f6290aSShashi Mallela * option) any later version. See the COPYING file in the top-level directory. 1118f6290aSShashi Mallela * 1218f6290aSShashi Mallela */ 1318f6290aSShashi Mallela 1418f6290aSShashi Mallela #include "qemu/osdep.h" 1518f6290aSShashi Mallela #include "qemu/log.h" 16195209d3SPeter Maydell #include "trace.h" 1718f6290aSShashi Mallela #include "hw/qdev-properties.h" 1818f6290aSShashi Mallela #include "hw/intc/arm_gicv3_its_common.h" 1918f6290aSShashi Mallela #include "gicv3_internal.h" 2018f6290aSShashi Mallela #include "qom/object.h" 2118f6290aSShashi Mallela #include "qapi/error.h" 2218f6290aSShashi Mallela 2318f6290aSShashi Mallela typedef struct GICv3ITSClass GICv3ITSClass; 2418f6290aSShashi Mallela /* This is reusing the GICv3ITSState typedef from ARM_GICV3_ITS_COMMON */ 2518f6290aSShashi Mallela DECLARE_OBJ_CHECKERS(GICv3ITSState, GICv3ITSClass, 2618f6290aSShashi Mallela ARM_GICV3_ITS, TYPE_ARM_GICV3_ITS) 2718f6290aSShashi Mallela 2818f6290aSShashi Mallela struct GICv3ITSClass { 2918f6290aSShashi Mallela GICv3ITSCommonClass parent_class; 3018f6290aSShashi Mallela void (*parent_reset)(DeviceState *dev); 3118f6290aSShashi Mallela }; 3218f6290aSShashi Mallela 33c694cb4cSShashi Mallela /* 34c694cb4cSShashi Mallela * This is an internal enum used to distinguish between LPI triggered 35c694cb4cSShashi Mallela * via command queue and LPI triggered via gits_translater write. 36c694cb4cSShashi Mallela */ 37c694cb4cSShashi Mallela typedef enum ItsCmdType { 38c694cb4cSShashi Mallela NONE = 0, /* internal indication for GITS_TRANSLATER write */ 39c694cb4cSShashi Mallela CLEAR = 1, 40c694cb4cSShashi Mallela DISCARD = 2, 41c694cb4cSShashi Mallela INTERRUPT = 3, 42c694cb4cSShashi Mallela } ItsCmdType; 43c694cb4cSShashi Mallela 444acf93e1SPeter Maydell typedef struct DTEntry { 454acf93e1SPeter Maydell bool valid; 464acf93e1SPeter Maydell unsigned size; 474acf93e1SPeter Maydell uint64_t ittaddr; 484acf93e1SPeter Maydell } DTEntry; 494acf93e1SPeter Maydell 50d37cf49bSPeter Maydell typedef struct CTEntry { 51d37cf49bSPeter Maydell bool valid; 52d37cf49bSPeter Maydell uint32_t rdbase; 53d37cf49bSPeter Maydell } CTEntry; 54d37cf49bSPeter Maydell 55244194feSPeter Maydell typedef struct ITEntry { 56244194feSPeter Maydell bool valid; 57244194feSPeter Maydell int inttype; 58244194feSPeter Maydell uint32_t intid; 59244194feSPeter Maydell uint32_t doorbell; 60244194feSPeter Maydell uint32_t icid; 61244194feSPeter Maydell uint32_t vpeid; 62244194feSPeter Maydell } ITEntry; 63244194feSPeter Maydell 64244194feSPeter Maydell 65ef011555SPeter Maydell /* 66ef011555SPeter Maydell * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options 67ef011555SPeter Maydell * if a command parameter is not correct. These include both "stall 68ef011555SPeter Maydell * processing of the command queue" and "ignore this command, and 69ef011555SPeter Maydell * keep processing the queue". In our implementation we choose that 70ef011555SPeter Maydell * memory transaction errors reading the command packet provoke a 71ef011555SPeter Maydell * stall, but errors in parameters cause us to ignore the command 72ef011555SPeter Maydell * and continue processing. 73ef011555SPeter Maydell * The process_* functions which handle individual ITS commands all 74ef011555SPeter Maydell * return an ItsCmdResult which tells process_cmdq() whether it should 75ef011555SPeter Maydell * stall or keep going. 76ef011555SPeter Maydell */ 77ef011555SPeter Maydell typedef enum ItsCmdResult { 78ef011555SPeter Maydell CMD_STALL = 0, 79ef011555SPeter Maydell CMD_CONTINUE = 1, 80ef011555SPeter Maydell } ItsCmdResult; 81ef011555SPeter Maydell 82*50d84584SPeter Maydell /* True if the ITS supports the GICv4 virtual LPI feature */ 83*50d84584SPeter Maydell static bool its_feature_virtual(GICv3ITSState *s) 84*50d84584SPeter Maydell { 85*50d84584SPeter Maydell return s->typer & R_GITS_TYPER_VIRTUAL_MASK; 86*50d84584SPeter Maydell } 87*50d84584SPeter Maydell 88c3c9a090SPeter Maydell static inline bool intid_in_lpi_range(uint32_t id) 89c3c9a090SPeter Maydell { 90c3c9a090SPeter Maydell return id >= GICV3_LPI_INTID_START && 91c3c9a090SPeter Maydell id < (1 << (GICD_TYPER_IDBITS + 1)); 92c3c9a090SPeter Maydell } 93c3c9a090SPeter Maydell 941b08e436SShashi Mallela static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz) 951b08e436SShashi Mallela { 961b08e436SShashi Mallela uint64_t result = 0; 971b08e436SShashi Mallela 981b08e436SShashi Mallela switch (page_sz) { 991b08e436SShashi Mallela case GITS_PAGE_SIZE_4K: 1001b08e436SShashi Mallela case GITS_PAGE_SIZE_16K: 1011b08e436SShashi Mallela result = FIELD_EX64(value, GITS_BASER, PHYADDR) << 12; 1021b08e436SShashi Mallela break; 1031b08e436SShashi Mallela 1041b08e436SShashi Mallela case GITS_PAGE_SIZE_64K: 1051b08e436SShashi Mallela result = FIELD_EX64(value, GITS_BASER, PHYADDRL_64K) << 16; 1061b08e436SShashi Mallela result |= FIELD_EX64(value, GITS_BASER, PHYADDRH_64K) << 48; 1071b08e436SShashi Mallela break; 1081b08e436SShashi Mallela 1091b08e436SShashi Mallela default: 1101b08e436SShashi Mallela break; 1111b08e436SShashi Mallela } 1121b08e436SShashi Mallela return result; 1131b08e436SShashi Mallela } 1141b08e436SShashi Mallela 115d050f80fSPeter Maydell static uint64_t table_entry_addr(GICv3ITSState *s, TableDesc *td, 116d050f80fSPeter Maydell uint32_t idx, MemTxResult *res) 117d050f80fSPeter Maydell { 118d050f80fSPeter Maydell /* 119d050f80fSPeter Maydell * Given a TableDesc describing one of the ITS in-guest-memory 120d050f80fSPeter Maydell * tables and an index into it, return the guest address 121d050f80fSPeter Maydell * corresponding to that table entry. 122d050f80fSPeter Maydell * If there was a memory error reading the L1 table of an 123d050f80fSPeter Maydell * indirect table, *res is set accordingly, and we return -1. 124d050f80fSPeter Maydell * If the L1 table entry is marked not valid, we return -1 with 125d050f80fSPeter Maydell * *res set to MEMTX_OK. 126d050f80fSPeter Maydell * 127d050f80fSPeter Maydell * The specification defines the format of level 1 entries of a 128d050f80fSPeter Maydell * 2-level table, but the format of level 2 entries and the format 129d050f80fSPeter Maydell * of flat-mapped tables is IMPDEF. 130d050f80fSPeter Maydell */ 131d050f80fSPeter Maydell AddressSpace *as = &s->gicv3->dma_as; 132d050f80fSPeter Maydell uint32_t l2idx; 133d050f80fSPeter Maydell uint64_t l2; 134d050f80fSPeter Maydell uint32_t num_l2_entries; 135d050f80fSPeter Maydell 136d050f80fSPeter Maydell *res = MEMTX_OK; 137d050f80fSPeter Maydell 138d050f80fSPeter Maydell if (!td->indirect) { 139d050f80fSPeter Maydell /* Single level table */ 140d050f80fSPeter Maydell return td->base_addr + idx * td->entry_sz; 141d050f80fSPeter Maydell } 142d050f80fSPeter Maydell 143d050f80fSPeter Maydell /* Two level table */ 144d050f80fSPeter Maydell l2idx = idx / (td->page_sz / L1TABLE_ENTRY_SIZE); 145d050f80fSPeter Maydell 146d050f80fSPeter Maydell l2 = address_space_ldq_le(as, 147d050f80fSPeter Maydell td->base_addr + (l2idx * L1TABLE_ENTRY_SIZE), 148d050f80fSPeter Maydell MEMTXATTRS_UNSPECIFIED, res); 149d050f80fSPeter Maydell if (*res != MEMTX_OK) { 150d050f80fSPeter Maydell return -1; 151d050f80fSPeter Maydell } 152d050f80fSPeter Maydell if (!(l2 & L2_TABLE_VALID_MASK)) { 153d050f80fSPeter Maydell return -1; 154d050f80fSPeter Maydell } 155d050f80fSPeter Maydell 156d050f80fSPeter Maydell num_l2_entries = td->page_sz / td->entry_sz; 157d050f80fSPeter Maydell return (l2 & ((1ULL << 51) - 1)) + (idx % num_l2_entries) * td->entry_sz; 158d050f80fSPeter Maydell } 159d050f80fSPeter Maydell 160d37cf49bSPeter Maydell /* 161d37cf49bSPeter Maydell * Read the Collection Table entry at index @icid. On success (including 162d37cf49bSPeter Maydell * successfully determining that there is no valid CTE for this index), 163d37cf49bSPeter Maydell * we return MEMTX_OK and populate the CTEntry struct @cte accordingly. 164d37cf49bSPeter Maydell * If there is an error reading memory then we return the error code. 165d37cf49bSPeter Maydell */ 166d37cf49bSPeter Maydell static MemTxResult get_cte(GICv3ITSState *s, uint16_t icid, CTEntry *cte) 167c694cb4cSShashi Mallela { 168c694cb4cSShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 169d37cf49bSPeter Maydell MemTxResult res = MEMTX_OK; 170d37cf49bSPeter Maydell uint64_t entry_addr = table_entry_addr(s, &s->ct, icid, &res); 171d37cf49bSPeter Maydell uint64_t cteval; 172c694cb4cSShashi Mallela 173d050f80fSPeter Maydell if (entry_addr == -1) { 174d37cf49bSPeter Maydell /* No L2 table entry, i.e. no valid CTE, or a memory error */ 175d37cf49bSPeter Maydell cte->valid = false; 176930f40e9SPeter Maydell goto out; 177c694cb4cSShashi Mallela } 178c694cb4cSShashi Mallela 179d37cf49bSPeter Maydell cteval = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, &res); 180d37cf49bSPeter Maydell if (res != MEMTX_OK) { 181930f40e9SPeter Maydell goto out; 182d37cf49bSPeter Maydell } 183d37cf49bSPeter Maydell cte->valid = FIELD_EX64(cteval, CTE, VALID); 184d37cf49bSPeter Maydell cte->rdbase = FIELD_EX64(cteval, CTE, RDBASE); 185930f40e9SPeter Maydell out: 186930f40e9SPeter Maydell if (res != MEMTX_OK) { 187930f40e9SPeter Maydell trace_gicv3_its_cte_read_fault(icid); 188930f40e9SPeter Maydell } else { 189930f40e9SPeter Maydell trace_gicv3_its_cte_read(icid, cte->valid, cte->rdbase); 190930f40e9SPeter Maydell } 191930f40e9SPeter Maydell return res; 192c694cb4cSShashi Mallela } 193c694cb4cSShashi Mallela 1947eb54267SPeter Maydell /* 1957eb54267SPeter Maydell * Update the Interrupt Table entry at index @evinted in the table specified 1967eb54267SPeter Maydell * by the dte @dte. Returns true on success, false if there was a memory 1977eb54267SPeter Maydell * access error. 1987eb54267SPeter Maydell */ 1994acf93e1SPeter Maydell static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, 2007eb54267SPeter Maydell const ITEntry *ite) 201c694cb4cSShashi Mallela { 202c694cb4cSShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 203c694cb4cSShashi Mallela MemTxResult res = MEMTX_OK; 204a1ce993dSPeter Maydell hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; 2057eb54267SPeter Maydell uint64_t itel = 0; 2067eb54267SPeter Maydell uint32_t iteh = 0; 207c694cb4cSShashi Mallela 208930f40e9SPeter Maydell trace_gicv3_its_ite_write(dte->ittaddr, eventid, ite->valid, 209930f40e9SPeter Maydell ite->inttype, ite->intid, ite->icid, 210930f40e9SPeter Maydell ite->vpeid, ite->doorbell); 211930f40e9SPeter Maydell 2127eb54267SPeter Maydell if (ite->valid) { 2137eb54267SPeter Maydell itel = FIELD_DP64(itel, ITE_L, VALID, 1); 2147eb54267SPeter Maydell itel = FIELD_DP64(itel, ITE_L, INTTYPE, ite->inttype); 2157eb54267SPeter Maydell itel = FIELD_DP64(itel, ITE_L, INTID, ite->intid); 2167eb54267SPeter Maydell itel = FIELD_DP64(itel, ITE_L, ICID, ite->icid); 2177eb54267SPeter Maydell itel = FIELD_DP64(itel, ITE_L, VPEID, ite->vpeid); 2187eb54267SPeter Maydell iteh = FIELD_DP32(iteh, ITE_H, DOORBELL, ite->doorbell); 219c694cb4cSShashi Mallela } 2207eb54267SPeter Maydell 2217eb54267SPeter Maydell address_space_stq_le(as, iteaddr, itel, MEMTXATTRS_UNSPECIFIED, &res); 222c694cb4cSShashi Mallela if (res != MEMTX_OK) { 223c694cb4cSShashi Mallela return false; 224c694cb4cSShashi Mallela } 2257eb54267SPeter Maydell address_space_stl_le(as, iteaddr + 8, iteh, MEMTXATTRS_UNSPECIFIED, &res); 2267eb54267SPeter Maydell return res == MEMTX_OK; 227c694cb4cSShashi Mallela } 228c694cb4cSShashi Mallela 229244194feSPeter Maydell /* 230244194feSPeter Maydell * Read the Interrupt Table entry at index @eventid from the table specified 231244194feSPeter Maydell * by the DTE @dte. On success, we return MEMTX_OK and populate the ITEntry 232244194feSPeter Maydell * struct @ite accordingly. If there is an error reading memory then we return 233244194feSPeter Maydell * the error code. 234244194feSPeter Maydell */ 235244194feSPeter Maydell static MemTxResult get_ite(GICv3ITSState *s, uint32_t eventid, 236244194feSPeter Maydell const DTEntry *dte, ITEntry *ite) 237c694cb4cSShashi Mallela { 238c694cb4cSShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 239244194feSPeter Maydell MemTxResult res = MEMTX_OK; 240244194feSPeter Maydell uint64_t itel; 241244194feSPeter Maydell uint32_t iteh; 242a1ce993dSPeter Maydell hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; 243c694cb4cSShashi Mallela 244244194feSPeter Maydell itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, &res); 245244194feSPeter Maydell if (res != MEMTX_OK) { 246930f40e9SPeter Maydell trace_gicv3_its_ite_read_fault(dte->ittaddr, eventid); 247244194feSPeter Maydell return res; 2482954b93fSPeter Maydell } 249c694cb4cSShashi Mallela 250244194feSPeter Maydell iteh = address_space_ldl_le(as, iteaddr + 8, MEMTXATTRS_UNSPECIFIED, &res); 251244194feSPeter Maydell if (res != MEMTX_OK) { 252930f40e9SPeter Maydell trace_gicv3_its_ite_read_fault(dte->ittaddr, eventid); 253244194feSPeter Maydell return res; 2542954b93fSPeter Maydell } 255c694cb4cSShashi Mallela 256244194feSPeter Maydell ite->valid = FIELD_EX64(itel, ITE_L, VALID); 257244194feSPeter Maydell ite->inttype = FIELD_EX64(itel, ITE_L, INTTYPE); 258244194feSPeter Maydell ite->intid = FIELD_EX64(itel, ITE_L, INTID); 259244194feSPeter Maydell ite->icid = FIELD_EX64(itel, ITE_L, ICID); 260244194feSPeter Maydell ite->vpeid = FIELD_EX64(itel, ITE_L, VPEID); 261244194feSPeter Maydell ite->doorbell = FIELD_EX64(iteh, ITE_H, DOORBELL); 262930f40e9SPeter Maydell trace_gicv3_its_ite_read(dte->ittaddr, eventid, ite->valid, 263930f40e9SPeter Maydell ite->inttype, ite->intid, ite->icid, 264930f40e9SPeter Maydell ite->vpeid, ite->doorbell); 265244194feSPeter Maydell return MEMTX_OK; 266c694cb4cSShashi Mallela } 267c694cb4cSShashi Mallela 2684acf93e1SPeter Maydell /* 2694acf93e1SPeter Maydell * Read the Device Table entry at index @devid. On success (including 2704acf93e1SPeter Maydell * successfully determining that there is no valid DTE for this index), 2714acf93e1SPeter Maydell * we return MEMTX_OK and populate the DTEntry struct accordingly. 2724acf93e1SPeter Maydell * If there is an error reading memory then we return the error code. 2734acf93e1SPeter Maydell */ 2744acf93e1SPeter Maydell static MemTxResult get_dte(GICv3ITSState *s, uint32_t devid, DTEntry *dte) 275c694cb4cSShashi Mallela { 2764acf93e1SPeter Maydell MemTxResult res = MEMTX_OK; 277c694cb4cSShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 2784acf93e1SPeter Maydell uint64_t entry_addr = table_entry_addr(s, &s->dt, devid, &res); 2794acf93e1SPeter Maydell uint64_t dteval; 280c694cb4cSShashi Mallela 281d050f80fSPeter Maydell if (entry_addr == -1) { 2824acf93e1SPeter Maydell /* No L2 table entry, i.e. no valid DTE, or a memory error */ 2834acf93e1SPeter Maydell dte->valid = false; 284930f40e9SPeter Maydell goto out; 285c694cb4cSShashi Mallela } 2864acf93e1SPeter Maydell dteval = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, &res); 2874acf93e1SPeter Maydell if (res != MEMTX_OK) { 288930f40e9SPeter Maydell goto out; 2894acf93e1SPeter Maydell } 2904acf93e1SPeter Maydell dte->valid = FIELD_EX64(dteval, DTE, VALID); 2914acf93e1SPeter Maydell dte->size = FIELD_EX64(dteval, DTE, SIZE); 2924acf93e1SPeter Maydell /* DTE word field stores bits [51:8] of the ITT address */ 2934acf93e1SPeter Maydell dte->ittaddr = FIELD_EX64(dteval, DTE, ITTADDR) << ITTADDR_SHIFT; 294930f40e9SPeter Maydell out: 295930f40e9SPeter Maydell if (res != MEMTX_OK) { 296930f40e9SPeter Maydell trace_gicv3_its_dte_read_fault(devid); 297930f40e9SPeter Maydell } else { 298930f40e9SPeter Maydell trace_gicv3_its_dte_read(devid, dte->valid, dte->size, dte->ittaddr); 299930f40e9SPeter Maydell } 300930f40e9SPeter Maydell return res; 301c694cb4cSShashi Mallela } 302c694cb4cSShashi Mallela 303c694cb4cSShashi Mallela /* 304c694cb4cSShashi Mallela * This function handles the processing of following commands based on 305c694cb4cSShashi Mallela * the ItsCmdType parameter passed:- 306c694cb4cSShashi Mallela * 1. triggering of lpi interrupt translation via ITS INT command 307c694cb4cSShashi Mallela * 2. triggering of lpi interrupt translation via gits_translater register 308c694cb4cSShashi Mallela * 3. handling of ITS CLEAR command 309c694cb4cSShashi Mallela * 4. handling of ITS DISCARD command 310c694cb4cSShashi Mallela */ 311b6f96009SPeter Maydell static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, 312b6f96009SPeter Maydell uint32_t eventid, ItsCmdType cmd) 313c694cb4cSShashi Mallela { 3148f809f69SPeter Maydell uint64_t num_eventids; 3154acf93e1SPeter Maydell DTEntry dte; 316d37cf49bSPeter Maydell CTEntry cte; 317244194feSPeter Maydell ITEntry ite; 318c694cb4cSShashi Mallela 3198b8bb014SPeter Maydell if (devid >= s->dt.num_entries) { 320b13148d9SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 321b13148d9SPeter Maydell "%s: invalid command attributes: devid %d>=%d", 3228b8bb014SPeter Maydell __func__, devid, s->dt.num_entries); 323b13148d9SPeter Maydell return CMD_CONTINUE; 324b13148d9SPeter Maydell } 325b13148d9SPeter Maydell 3264acf93e1SPeter Maydell if (get_dte(s, devid, &dte) != MEMTX_OK) { 327593a7cc2SPeter Maydell return CMD_STALL; 328c694cb4cSShashi Mallela } 3294acf93e1SPeter Maydell if (!dte.valid) { 330229c57b1SAlex Bennée qemu_log_mask(LOG_GUEST_ERROR, 331229c57b1SAlex Bennée "%s: invalid command attributes: " 3324acf93e1SPeter Maydell "invalid dte for %d\n", __func__, devid); 333593a7cc2SPeter Maydell return CMD_CONTINUE; 334c694cb4cSShashi Mallela } 335c694cb4cSShashi Mallela 3364acf93e1SPeter Maydell num_eventids = 1ULL << (dte.size + 1); 337b13148d9SPeter Maydell if (eventid >= num_eventids) { 338b13148d9SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 339b13148d9SPeter Maydell "%s: invalid command attributes: eventid %d >= %" 340b13148d9SPeter Maydell PRId64 "\n", 341b13148d9SPeter Maydell __func__, eventid, num_eventids); 342b13148d9SPeter Maydell return CMD_CONTINUE; 343b13148d9SPeter Maydell } 344b13148d9SPeter Maydell 345244194feSPeter Maydell if (get_ite(s, eventid, &dte, &ite) != MEMTX_OK) { 346be0ed8fbSPeter Maydell return CMD_STALL; 347be0ed8fbSPeter Maydell } 348be0ed8fbSPeter Maydell 349244194feSPeter Maydell if (!ite.valid || ite.inttype != ITE_INTTYPE_PHYSICAL) { 350be0ed8fbSPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 351be0ed8fbSPeter Maydell "%s: invalid command attributes: invalid ITE\n", 352be0ed8fbSPeter Maydell __func__); 353be0ed8fbSPeter Maydell return CMD_CONTINUE; 354be0ed8fbSPeter Maydell } 355be0ed8fbSPeter Maydell 356244194feSPeter Maydell if (ite.icid >= s->ct.num_entries) { 35758b88779SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 35858b88779SPeter Maydell "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", 359244194feSPeter Maydell __func__, ite.icid); 36058b88779SPeter Maydell return CMD_CONTINUE; 36158b88779SPeter Maydell } 36258b88779SPeter Maydell 363244194feSPeter Maydell if (get_cte(s, ite.icid, &cte) != MEMTX_OK) { 364be0ed8fbSPeter Maydell return CMD_STALL; 365be0ed8fbSPeter Maydell } 366d37cf49bSPeter Maydell if (!cte.valid) { 367be0ed8fbSPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 368d37cf49bSPeter Maydell "%s: invalid command attributes: invalid CTE\n", 369d37cf49bSPeter Maydell __func__); 370be0ed8fbSPeter Maydell return CMD_CONTINUE; 371be0ed8fbSPeter Maydell } 372be0ed8fbSPeter Maydell 373c694cb4cSShashi Mallela /* 374c694cb4cSShashi Mallela * Current implementation only supports rdbase == procnum 375c694cb4cSShashi Mallela * Hence rdbase physical address is ignored 376c694cb4cSShashi Mallela */ 377d37cf49bSPeter Maydell if (cte.rdbase >= s->gicv3->num_cpu) { 378593a7cc2SPeter Maydell return CMD_CONTINUE; 37917fb5e36SShashi Mallela } 38017fb5e36SShashi Mallela 38117fb5e36SShashi Mallela if ((cmd == CLEAR) || (cmd == DISCARD)) { 382244194feSPeter Maydell gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], ite.intid, 0); 38317fb5e36SShashi Mallela } else { 384244194feSPeter Maydell gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], ite.intid, 1); 38517fb5e36SShashi Mallela } 38617fb5e36SShashi Mallela 387c694cb4cSShashi Mallela if (cmd == DISCARD) { 3887eb54267SPeter Maydell ITEntry ite = {}; 389c694cb4cSShashi Mallela /* remove mapping from interrupt translation table */ 3907eb54267SPeter Maydell ite.valid = false; 3917eb54267SPeter Maydell return update_ite(s, eventid, &dte, &ite) ? CMD_CONTINUE : CMD_STALL; 392c694cb4cSShashi Mallela } 393593a7cc2SPeter Maydell return CMD_CONTINUE; 394c694cb4cSShashi Mallela } 3952a199036SPeter Maydell 396b6f96009SPeter Maydell static ItsCmdResult process_its_cmd(GICv3ITSState *s, const uint64_t *cmdpkt, 397b6f96009SPeter Maydell ItsCmdType cmd) 398c694cb4cSShashi Mallela { 399b6f96009SPeter Maydell uint32_t devid, eventid; 400b6f96009SPeter Maydell 401b6f96009SPeter Maydell devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; 402b6f96009SPeter Maydell eventid = cmdpkt[1] & EVENTID_MASK; 403e4050980SPeter Maydell switch (cmd) { 404e4050980SPeter Maydell case INTERRUPT: 405e4050980SPeter Maydell trace_gicv3_its_cmd_int(devid, eventid); 406e4050980SPeter Maydell break; 407e4050980SPeter Maydell case CLEAR: 408e4050980SPeter Maydell trace_gicv3_its_cmd_clear(devid, eventid); 409e4050980SPeter Maydell break; 410e4050980SPeter Maydell case DISCARD: 411e4050980SPeter Maydell trace_gicv3_its_cmd_discard(devid, eventid); 412e4050980SPeter Maydell break; 413e4050980SPeter Maydell default: 414e4050980SPeter Maydell g_assert_not_reached(); 415e4050980SPeter Maydell } 416b6f96009SPeter Maydell return do_process_its_cmd(s, devid, eventid, cmd); 417b6f96009SPeter Maydell } 418b6f96009SPeter Maydell 419b6f96009SPeter Maydell static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, 420b6f96009SPeter Maydell bool ignore_pInt) 421b6f96009SPeter Maydell { 422c694cb4cSShashi Mallela uint32_t devid, eventid; 423c694cb4cSShashi Mallela uint32_t pIntid = 0; 4248f809f69SPeter Maydell uint64_t num_eventids; 425c694cb4cSShashi Mallela uint16_t icid = 0; 4264acf93e1SPeter Maydell DTEntry dte; 4277eb54267SPeter Maydell ITEntry ite; 428c694cb4cSShashi Mallela 429b6f96009SPeter Maydell devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; 430b6f96009SPeter Maydell eventid = cmdpkt[1] & EVENTID_MASK; 431e4050980SPeter Maydell icid = cmdpkt[2] & ICID_MASK; 432c694cb4cSShashi Mallela 433b87fab1cSPeter Maydell if (ignore_pInt) { 434b87fab1cSPeter Maydell pIntid = eventid; 435e4050980SPeter Maydell trace_gicv3_its_cmd_mapi(devid, eventid, icid); 436b87fab1cSPeter Maydell } else { 437b6f96009SPeter Maydell pIntid = (cmdpkt[1] & pINTID_MASK) >> pINTID_SHIFT; 438e4050980SPeter Maydell trace_gicv3_its_cmd_mapti(devid, eventid, icid, pIntid); 439c694cb4cSShashi Mallela } 440c694cb4cSShashi Mallela 4418b8bb014SPeter Maydell if (devid >= s->dt.num_entries) { 442b13148d9SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 443b13148d9SPeter Maydell "%s: invalid command attributes: devid %d>=%d", 4448b8bb014SPeter Maydell __func__, devid, s->dt.num_entries); 445b13148d9SPeter Maydell return CMD_CONTINUE; 446b13148d9SPeter Maydell } 447b13148d9SPeter Maydell 4484acf93e1SPeter Maydell if (get_dte(s, devid, &dte) != MEMTX_OK) { 4490241f731SPeter Maydell return CMD_STALL; 450c694cb4cSShashi Mallela } 4514acf93e1SPeter Maydell num_eventids = 1ULL << (dte.size + 1); 452c694cb4cSShashi Mallela 453d7d359c4SPeter Maydell if (icid >= s->ct.num_entries) { 454c694cb4cSShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 455d7d359c4SPeter Maydell "%s: invalid ICID 0x%x >= 0x%x\n", 456d7d359c4SPeter Maydell __func__, icid, s->ct.num_entries); 457d7d359c4SPeter Maydell return CMD_CONTINUE; 458d7d359c4SPeter Maydell } 459d7d359c4SPeter Maydell 460d7d359c4SPeter Maydell if (!dte.valid) { 461d7d359c4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 462d7d359c4SPeter Maydell "%s: no valid DTE for devid 0x%x\n", __func__, devid); 463d7d359c4SPeter Maydell return CMD_CONTINUE; 464d7d359c4SPeter Maydell } 465d7d359c4SPeter Maydell 466d7d359c4SPeter Maydell if (eventid >= num_eventids) { 467d7d359c4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 468d7d359c4SPeter Maydell "%s: invalid event ID 0x%x >= 0x%" PRIx64 "\n", 469d7d359c4SPeter Maydell __func__, eventid, num_eventids); 470d7d359c4SPeter Maydell return CMD_CONTINUE; 471d7d359c4SPeter Maydell } 472d7d359c4SPeter Maydell 473c3c9a090SPeter Maydell if (!intid_in_lpi_range(pIntid)) { 474d7d359c4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 475d7d359c4SPeter Maydell "%s: invalid interrupt ID 0x%x\n", __func__, pIntid); 4760241f731SPeter Maydell return CMD_CONTINUE; 4770241f731SPeter Maydell } 4780241f731SPeter Maydell 479c694cb4cSShashi Mallela /* add ite entry to interrupt translation table */ 4807eb54267SPeter Maydell ite.valid = true; 4817eb54267SPeter Maydell ite.inttype = ITE_INTTYPE_PHYSICAL; 4827eb54267SPeter Maydell ite.intid = pIntid; 4837eb54267SPeter Maydell ite.icid = icid; 4847eb54267SPeter Maydell ite.doorbell = INTID_SPURIOUS; 4857eb54267SPeter Maydell ite.vpeid = 0; 4867eb54267SPeter Maydell return update_ite(s, eventid, &dte, &ite) ? CMD_CONTINUE : CMD_STALL; 487c694cb4cSShashi Mallela } 488c694cb4cSShashi Mallela 48906985cc3SPeter Maydell /* 49006985cc3SPeter Maydell * Update the Collection Table entry for @icid to @cte. Returns true 49106985cc3SPeter Maydell * on success, false if there was a memory access error. 49206985cc3SPeter Maydell */ 49306985cc3SPeter Maydell static bool update_cte(GICv3ITSState *s, uint16_t icid, const CTEntry *cte) 4947eca39e0SShashi Mallela { 4957eca39e0SShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 496d050f80fSPeter Maydell uint64_t entry_addr; 49706985cc3SPeter Maydell uint64_t cteval = 0; 4987eca39e0SShashi Mallela MemTxResult res = MEMTX_OK; 4997eca39e0SShashi Mallela 500930f40e9SPeter Maydell trace_gicv3_its_cte_write(icid, cte->valid, cte->rdbase); 501930f40e9SPeter Maydell 50206985cc3SPeter Maydell if (cte->valid) { 5037eca39e0SShashi Mallela /* add mapping entry to collection table */ 50406985cc3SPeter Maydell cteval = FIELD_DP64(cteval, CTE, VALID, 1); 50506985cc3SPeter Maydell cteval = FIELD_DP64(cteval, CTE, RDBASE, cte->rdbase); 5067eca39e0SShashi Mallela } 5077eca39e0SShashi Mallela 508d050f80fSPeter Maydell entry_addr = table_entry_addr(s, &s->ct, icid, &res); 5097eca39e0SShashi Mallela if (res != MEMTX_OK) { 510d050f80fSPeter Maydell /* memory access error: stall */ 5117eca39e0SShashi Mallela return false; 5127eca39e0SShashi Mallela } 513d050f80fSPeter Maydell if (entry_addr == -1) { 514d050f80fSPeter Maydell /* No L2 table for this index: discard write and continue */ 5157eca39e0SShashi Mallela return true; 5167eca39e0SShashi Mallela } 517d050f80fSPeter Maydell 51806985cc3SPeter Maydell address_space_stq_le(as, entry_addr, cteval, MEMTXATTRS_UNSPECIFIED, &res); 519d050f80fSPeter Maydell return res == MEMTX_OK; 5207eca39e0SShashi Mallela } 5217eca39e0SShashi Mallela 522b6f96009SPeter Maydell static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) 5237eca39e0SShashi Mallela { 5247eca39e0SShashi Mallela uint16_t icid; 52506985cc3SPeter Maydell CTEntry cte; 5267eca39e0SShashi Mallela 527b6f96009SPeter Maydell icid = cmdpkt[2] & ICID_MASK; 52884d43d2eSPeter Maydell cte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; 52984d43d2eSPeter Maydell if (cte.valid) { 53006985cc3SPeter Maydell cte.rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; 53106985cc3SPeter Maydell cte.rdbase &= RDBASE_PROCNUM_MASK; 53284d43d2eSPeter Maydell } else { 53384d43d2eSPeter Maydell cte.rdbase = 0; 53484d43d2eSPeter Maydell } 535e4050980SPeter Maydell trace_gicv3_its_cmd_mapc(icid, cte.rdbase, cte.valid); 5367eca39e0SShashi Mallela 53784d43d2eSPeter Maydell if (icid >= s->ct.num_entries) { 538c7ca3ad5SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, "ITS MAPC: invalid ICID 0x%x\n", icid); 53984d43d2eSPeter Maydell return CMD_CONTINUE; 54084d43d2eSPeter Maydell } 54184d43d2eSPeter Maydell if (cte.valid && cte.rdbase >= s->gicv3->num_cpu) { 5427eca39e0SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 543c7ca3ad5SPeter Maydell "ITS MAPC: invalid RDBASE %u\n", cte.rdbase); 544f6675196SPeter Maydell return CMD_CONTINUE; 5457eca39e0SShashi Mallela } 5467eca39e0SShashi Mallela 54706985cc3SPeter Maydell return update_cte(s, icid, &cte) ? CMD_CONTINUE : CMD_STALL; 5487eca39e0SShashi Mallela } 5497eca39e0SShashi Mallela 55022d62b08SPeter Maydell /* 55122d62b08SPeter Maydell * Update the Device Table entry for @devid to @dte. Returns true 55222d62b08SPeter Maydell * on success, false if there was a memory access error. 55322d62b08SPeter Maydell */ 55422d62b08SPeter Maydell static bool update_dte(GICv3ITSState *s, uint32_t devid, const DTEntry *dte) 5557eca39e0SShashi Mallela { 5567eca39e0SShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 557d050f80fSPeter Maydell uint64_t entry_addr; 55822d62b08SPeter Maydell uint64_t dteval = 0; 5597eca39e0SShashi Mallela MemTxResult res = MEMTX_OK; 5607eca39e0SShashi Mallela 561930f40e9SPeter Maydell trace_gicv3_its_dte_write(devid, dte->valid, dte->size, dte->ittaddr); 562930f40e9SPeter Maydell 56322d62b08SPeter Maydell if (dte->valid) { 5647eca39e0SShashi Mallela /* add mapping entry to device table */ 56522d62b08SPeter Maydell dteval = FIELD_DP64(dteval, DTE, VALID, 1); 56622d62b08SPeter Maydell dteval = FIELD_DP64(dteval, DTE, SIZE, dte->size); 56722d62b08SPeter Maydell dteval = FIELD_DP64(dteval, DTE, ITTADDR, dte->ittaddr); 5687eca39e0SShashi Mallela } 5697eca39e0SShashi Mallela 570d050f80fSPeter Maydell entry_addr = table_entry_addr(s, &s->dt, devid, &res); 5717eca39e0SShashi Mallela if (res != MEMTX_OK) { 572d050f80fSPeter Maydell /* memory access error: stall */ 5737eca39e0SShashi Mallela return false; 5747eca39e0SShashi Mallela } 575d050f80fSPeter Maydell if (entry_addr == -1) { 576d050f80fSPeter Maydell /* No L2 table for this index: discard write and continue */ 5777eca39e0SShashi Mallela return true; 5787eca39e0SShashi Mallela } 57922d62b08SPeter Maydell address_space_stq_le(as, entry_addr, dteval, MEMTXATTRS_UNSPECIFIED, &res); 580d050f80fSPeter Maydell return res == MEMTX_OK; 5817eca39e0SShashi Mallela } 5827eca39e0SShashi Mallela 583b6f96009SPeter Maydell static ItsCmdResult process_mapd(GICv3ITSState *s, const uint64_t *cmdpkt) 5847eca39e0SShashi Mallela { 5857eca39e0SShashi Mallela uint32_t devid; 58622d62b08SPeter Maydell DTEntry dte; 5877eca39e0SShashi Mallela 588b6f96009SPeter Maydell devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; 58922d62b08SPeter Maydell dte.size = cmdpkt[1] & SIZE_MASK; 59022d62b08SPeter Maydell dte.ittaddr = (cmdpkt[2] & ITTADDR_MASK) >> ITTADDR_SHIFT; 59122d62b08SPeter Maydell dte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; 5927eca39e0SShashi Mallela 593e4050980SPeter Maydell trace_gicv3_its_cmd_mapd(devid, dte.size, dte.ittaddr, dte.valid); 594e4050980SPeter Maydell 595d7d359c4SPeter Maydell if (devid >= s->dt.num_entries) { 5967eca39e0SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 597d7d359c4SPeter Maydell "ITS MAPD: invalid device ID field 0x%x >= 0x%x\n", 598d7d359c4SPeter Maydell devid, s->dt.num_entries); 599d7d359c4SPeter Maydell return CMD_CONTINUE; 600d7d359c4SPeter Maydell } 601d7d359c4SPeter Maydell 602d7d359c4SPeter Maydell if (dte.size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS)) { 603d7d359c4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 604d7d359c4SPeter Maydell "ITS MAPD: invalid size %d\n", dte.size); 60500d46e72SPeter Maydell return CMD_CONTINUE; 6067eca39e0SShashi Mallela } 6077eca39e0SShashi Mallela 60822d62b08SPeter Maydell return update_dte(s, devid, &dte) ? CMD_CONTINUE : CMD_STALL; 6097eca39e0SShashi Mallela } 6107eca39e0SShashi Mallela 611b6f96009SPeter Maydell static ItsCmdResult process_movall(GICv3ITSState *s, const uint64_t *cmdpkt) 612f6d1d9b4SPeter Maydell { 613f6d1d9b4SPeter Maydell uint64_t rd1, rd2; 614f6d1d9b4SPeter Maydell 615b6f96009SPeter Maydell rd1 = FIELD_EX64(cmdpkt[2], MOVALL_2, RDBASE1); 616b6f96009SPeter Maydell rd2 = FIELD_EX64(cmdpkt[3], MOVALL_3, RDBASE2); 617f6d1d9b4SPeter Maydell 618e4050980SPeter Maydell trace_gicv3_its_cmd_movall(rd1, rd2); 619e4050980SPeter Maydell 620f6d1d9b4SPeter Maydell if (rd1 >= s->gicv3->num_cpu) { 621f6d1d9b4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 622f6d1d9b4SPeter Maydell "%s: RDBASE1 %" PRId64 623f6d1d9b4SPeter Maydell " out of range (must be less than %d)\n", 624f6d1d9b4SPeter Maydell __func__, rd1, s->gicv3->num_cpu); 625f6d1d9b4SPeter Maydell return CMD_CONTINUE; 626f6d1d9b4SPeter Maydell } 627f6d1d9b4SPeter Maydell if (rd2 >= s->gicv3->num_cpu) { 628f6d1d9b4SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 629f6d1d9b4SPeter Maydell "%s: RDBASE2 %" PRId64 630f6d1d9b4SPeter Maydell " out of range (must be less than %d)\n", 631f6d1d9b4SPeter Maydell __func__, rd2, s->gicv3->num_cpu); 632f6d1d9b4SPeter Maydell return CMD_CONTINUE; 633f6d1d9b4SPeter Maydell } 634f6d1d9b4SPeter Maydell 635f6d1d9b4SPeter Maydell if (rd1 == rd2) { 636f6d1d9b4SPeter Maydell /* Move to same target must succeed as a no-op */ 637f6d1d9b4SPeter Maydell return CMD_CONTINUE; 638f6d1d9b4SPeter Maydell } 639f6d1d9b4SPeter Maydell 640f6d1d9b4SPeter Maydell /* Move all pending LPIs from redistributor 1 to redistributor 2 */ 641f6d1d9b4SPeter Maydell gicv3_redist_movall_lpis(&s->gicv3->cpu[rd1], &s->gicv3->cpu[rd2]); 642f6d1d9b4SPeter Maydell 643f6d1d9b4SPeter Maydell return CMD_CONTINUE; 644f6d1d9b4SPeter Maydell } 645f6d1d9b4SPeter Maydell 646b6f96009SPeter Maydell static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) 647961b4912SPeter Maydell { 648244194feSPeter Maydell uint32_t devid, eventid; 649244194feSPeter Maydell uint16_t new_icid; 650961b4912SPeter Maydell uint64_t num_eventids; 6514acf93e1SPeter Maydell DTEntry dte; 652d37cf49bSPeter Maydell CTEntry old_cte, new_cte; 653244194feSPeter Maydell ITEntry old_ite; 654961b4912SPeter Maydell 655b6f96009SPeter Maydell devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); 656b6f96009SPeter Maydell eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); 657b6f96009SPeter Maydell new_icid = FIELD_EX64(cmdpkt[2], MOVI_2, ICID); 658961b4912SPeter Maydell 659e4050980SPeter Maydell trace_gicv3_its_cmd_movi(devid, eventid, new_icid); 660e4050980SPeter Maydell 661961b4912SPeter Maydell if (devid >= s->dt.num_entries) { 662961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 663961b4912SPeter Maydell "%s: invalid command attributes: devid %d>=%d", 664961b4912SPeter Maydell __func__, devid, s->dt.num_entries); 665961b4912SPeter Maydell return CMD_CONTINUE; 666961b4912SPeter Maydell } 6674acf93e1SPeter Maydell if (get_dte(s, devid, &dte) != MEMTX_OK) { 668961b4912SPeter Maydell return CMD_STALL; 669961b4912SPeter Maydell } 670961b4912SPeter Maydell 6714acf93e1SPeter Maydell if (!dte.valid) { 672961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 673961b4912SPeter Maydell "%s: invalid command attributes: " 6744acf93e1SPeter Maydell "invalid dte for %d\n", __func__, devid); 675961b4912SPeter Maydell return CMD_CONTINUE; 676961b4912SPeter Maydell } 677961b4912SPeter Maydell 6784acf93e1SPeter Maydell num_eventids = 1ULL << (dte.size + 1); 679961b4912SPeter Maydell if (eventid >= num_eventids) { 680961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 681961b4912SPeter Maydell "%s: invalid command attributes: eventid %d >= %" 682961b4912SPeter Maydell PRId64 "\n", 683961b4912SPeter Maydell __func__, eventid, num_eventids); 684961b4912SPeter Maydell return CMD_CONTINUE; 685961b4912SPeter Maydell } 686961b4912SPeter Maydell 687244194feSPeter Maydell if (get_ite(s, eventid, &dte, &old_ite) != MEMTX_OK) { 688961b4912SPeter Maydell return CMD_STALL; 689961b4912SPeter Maydell } 690961b4912SPeter Maydell 691244194feSPeter Maydell if (!old_ite.valid || old_ite.inttype != ITE_INTTYPE_PHYSICAL) { 692961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 693961b4912SPeter Maydell "%s: invalid command attributes: invalid ITE\n", 694961b4912SPeter Maydell __func__); 695961b4912SPeter Maydell return CMD_CONTINUE; 696961b4912SPeter Maydell } 697961b4912SPeter Maydell 698244194feSPeter Maydell if (old_ite.icid >= s->ct.num_entries) { 699961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 700961b4912SPeter Maydell "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", 701244194feSPeter Maydell __func__, old_ite.icid); 702961b4912SPeter Maydell return CMD_CONTINUE; 703961b4912SPeter Maydell } 704961b4912SPeter Maydell 705961b4912SPeter Maydell if (new_icid >= s->ct.num_entries) { 706961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 707961b4912SPeter Maydell "%s: invalid command attributes: ICID 0x%x\n", 708961b4912SPeter Maydell __func__, new_icid); 709961b4912SPeter Maydell return CMD_CONTINUE; 710961b4912SPeter Maydell } 711961b4912SPeter Maydell 712244194feSPeter Maydell if (get_cte(s, old_ite.icid, &old_cte) != MEMTX_OK) { 713961b4912SPeter Maydell return CMD_STALL; 714961b4912SPeter Maydell } 715d37cf49bSPeter Maydell if (!old_cte.valid) { 716961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 717961b4912SPeter Maydell "%s: invalid command attributes: " 718d37cf49bSPeter Maydell "invalid CTE for old ICID 0x%x\n", 719244194feSPeter Maydell __func__, old_ite.icid); 720961b4912SPeter Maydell return CMD_CONTINUE; 721961b4912SPeter Maydell } 722961b4912SPeter Maydell 723d37cf49bSPeter Maydell if (get_cte(s, new_icid, &new_cte) != MEMTX_OK) { 724961b4912SPeter Maydell return CMD_STALL; 725961b4912SPeter Maydell } 726d37cf49bSPeter Maydell if (!new_cte.valid) { 727961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 728961b4912SPeter Maydell "%s: invalid command attributes: " 729d37cf49bSPeter Maydell "invalid CTE for new ICID 0x%x\n", 730d37cf49bSPeter Maydell __func__, new_icid); 731961b4912SPeter Maydell return CMD_CONTINUE; 732961b4912SPeter Maydell } 733961b4912SPeter Maydell 734d37cf49bSPeter Maydell if (old_cte.rdbase >= s->gicv3->num_cpu) { 735961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 736d37cf49bSPeter Maydell "%s: CTE has invalid rdbase 0x%x\n", 737d37cf49bSPeter Maydell __func__, old_cte.rdbase); 738961b4912SPeter Maydell return CMD_CONTINUE; 739961b4912SPeter Maydell } 740961b4912SPeter Maydell 741d37cf49bSPeter Maydell if (new_cte.rdbase >= s->gicv3->num_cpu) { 742961b4912SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 743d37cf49bSPeter Maydell "%s: CTE has invalid rdbase 0x%x\n", 744d37cf49bSPeter Maydell __func__, new_cte.rdbase); 745961b4912SPeter Maydell return CMD_CONTINUE; 746961b4912SPeter Maydell } 747961b4912SPeter Maydell 748d37cf49bSPeter Maydell if (old_cte.rdbase != new_cte.rdbase) { 749961b4912SPeter Maydell /* Move the LPI from the old redistributor to the new one */ 750d37cf49bSPeter Maydell gicv3_redist_mov_lpi(&s->gicv3->cpu[old_cte.rdbase], 751d37cf49bSPeter Maydell &s->gicv3->cpu[new_cte.rdbase], 752244194feSPeter Maydell old_ite.intid); 753961b4912SPeter Maydell } 754961b4912SPeter Maydell 755961b4912SPeter Maydell /* Update the ICID field in the interrupt translation table entry */ 7567eb54267SPeter Maydell old_ite.icid = new_icid; 7577eb54267SPeter Maydell return update_ite(s, eventid, &dte, &old_ite) ? CMD_CONTINUE : CMD_STALL; 758961b4912SPeter Maydell } 759961b4912SPeter Maydell 7607eca39e0SShashi Mallela /* 7617eca39e0SShashi Mallela * Current implementation blocks until all 7627eca39e0SShashi Mallela * commands are processed 7637eca39e0SShashi Mallela */ 7647eca39e0SShashi Mallela static void process_cmdq(GICv3ITSState *s) 7657eca39e0SShashi Mallela { 7667eca39e0SShashi Mallela uint32_t wr_offset = 0; 7677eca39e0SShashi Mallela uint32_t rd_offset = 0; 7687eca39e0SShashi Mallela uint32_t cq_offset = 0; 7697eca39e0SShashi Mallela AddressSpace *as = &s->gicv3->dma_as; 7707eca39e0SShashi Mallela uint8_t cmd; 77117fb5e36SShashi Mallela int i; 7727eca39e0SShashi Mallela 7738d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 7747eca39e0SShashi Mallela return; 7757eca39e0SShashi Mallela } 7767eca39e0SShashi Mallela 7777eca39e0SShashi Mallela wr_offset = FIELD_EX64(s->cwriter, GITS_CWRITER, OFFSET); 7787eca39e0SShashi Mallela 77980dcd37fSPeter Maydell if (wr_offset >= s->cq.num_entries) { 7807eca39e0SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 7817eca39e0SShashi Mallela "%s: invalid write offset " 7827eca39e0SShashi Mallela "%d\n", __func__, wr_offset); 7837eca39e0SShashi Mallela return; 7847eca39e0SShashi Mallela } 7857eca39e0SShashi Mallela 7867eca39e0SShashi Mallela rd_offset = FIELD_EX64(s->creadr, GITS_CREADR, OFFSET); 7877eca39e0SShashi Mallela 78880dcd37fSPeter Maydell if (rd_offset >= s->cq.num_entries) { 7897eca39e0SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 7907eca39e0SShashi Mallela "%s: invalid read offset " 7917eca39e0SShashi Mallela "%d\n", __func__, rd_offset); 7927eca39e0SShashi Mallela return; 7937eca39e0SShashi Mallela } 7947eca39e0SShashi Mallela 7957eca39e0SShashi Mallela while (wr_offset != rd_offset) { 796ef011555SPeter Maydell ItsCmdResult result = CMD_CONTINUE; 797b6f96009SPeter Maydell void *hostmem; 798b6f96009SPeter Maydell hwaddr buflen; 799b6f96009SPeter Maydell uint64_t cmdpkt[GITS_CMDQ_ENTRY_WORDS]; 800ef011555SPeter Maydell 8017eca39e0SShashi Mallela cq_offset = (rd_offset * GITS_CMDQ_ENTRY_SIZE); 802b6f96009SPeter Maydell 803b6f96009SPeter Maydell buflen = GITS_CMDQ_ENTRY_SIZE; 804b6f96009SPeter Maydell hostmem = address_space_map(as, s->cq.base_addr + cq_offset, 805b6f96009SPeter Maydell &buflen, false, MEMTXATTRS_UNSPECIFIED); 806b6f96009SPeter Maydell if (!hostmem || buflen != GITS_CMDQ_ENTRY_SIZE) { 807b6f96009SPeter Maydell if (hostmem) { 808b6f96009SPeter Maydell address_space_unmap(as, hostmem, buflen, false, 0); 809b6f96009SPeter Maydell } 810f0b4b2a2SPeter Maydell s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1); 811f0b4b2a2SPeter Maydell qemu_log_mask(LOG_GUEST_ERROR, 812f0b4b2a2SPeter Maydell "%s: could not read command at 0x%" PRIx64 "\n", 813f0b4b2a2SPeter Maydell __func__, s->cq.base_addr + cq_offset); 814f0b4b2a2SPeter Maydell break; 8157eca39e0SShashi Mallela } 816b6f96009SPeter Maydell for (i = 0; i < ARRAY_SIZE(cmdpkt); i++) { 817b6f96009SPeter Maydell cmdpkt[i] = ldq_le_p(hostmem + i * sizeof(uint64_t)); 818b6f96009SPeter Maydell } 819b6f96009SPeter Maydell address_space_unmap(as, hostmem, buflen, false, 0); 820f0b4b2a2SPeter Maydell 821b6f96009SPeter Maydell cmd = cmdpkt[0] & CMD_MASK; 8227eca39e0SShashi Mallela 823195209d3SPeter Maydell trace_gicv3_its_process_command(rd_offset, cmd); 824195209d3SPeter Maydell 8257eca39e0SShashi Mallela switch (cmd) { 8267eca39e0SShashi Mallela case GITS_CMD_INT: 827b6f96009SPeter Maydell result = process_its_cmd(s, cmdpkt, INTERRUPT); 8287eca39e0SShashi Mallela break; 8297eca39e0SShashi Mallela case GITS_CMD_CLEAR: 830b6f96009SPeter Maydell result = process_its_cmd(s, cmdpkt, CLEAR); 8317eca39e0SShashi Mallela break; 8327eca39e0SShashi Mallela case GITS_CMD_SYNC: 8337eca39e0SShashi Mallela /* 8347eca39e0SShashi Mallela * Current implementation makes a blocking synchronous call 8357eca39e0SShashi Mallela * for every command issued earlier, hence the internal state 8367eca39e0SShashi Mallela * is already consistent by the time SYNC command is executed. 8377eca39e0SShashi Mallela * Hence no further processing is required for SYNC command. 8387eca39e0SShashi Mallela */ 839e4050980SPeter Maydell trace_gicv3_its_cmd_sync(); 8407eca39e0SShashi Mallela break; 8417eca39e0SShashi Mallela case GITS_CMD_MAPD: 842b6f96009SPeter Maydell result = process_mapd(s, cmdpkt); 8437eca39e0SShashi Mallela break; 8447eca39e0SShashi Mallela case GITS_CMD_MAPC: 845b6f96009SPeter Maydell result = process_mapc(s, cmdpkt); 8467eca39e0SShashi Mallela break; 8477eca39e0SShashi Mallela case GITS_CMD_MAPTI: 848b6f96009SPeter Maydell result = process_mapti(s, cmdpkt, false); 8497eca39e0SShashi Mallela break; 8507eca39e0SShashi Mallela case GITS_CMD_MAPI: 851b6f96009SPeter Maydell result = process_mapti(s, cmdpkt, true); 8527eca39e0SShashi Mallela break; 8537eca39e0SShashi Mallela case GITS_CMD_DISCARD: 854b6f96009SPeter Maydell result = process_its_cmd(s, cmdpkt, DISCARD); 8557eca39e0SShashi Mallela break; 8567eca39e0SShashi Mallela case GITS_CMD_INV: 8577eca39e0SShashi Mallela case GITS_CMD_INVALL: 85817fb5e36SShashi Mallela /* 85917fb5e36SShashi Mallela * Current implementation doesn't cache any ITS tables, 86017fb5e36SShashi Mallela * but the calculated lpi priority information. We only 86117fb5e36SShashi Mallela * need to trigger lpi priority re-calculation to be in 86217fb5e36SShashi Mallela * sync with LPI config table or pending table changes. 86317fb5e36SShashi Mallela */ 864e4050980SPeter Maydell trace_gicv3_its_cmd_inv(); 86517fb5e36SShashi Mallela for (i = 0; i < s->gicv3->num_cpu; i++) { 86617fb5e36SShashi Mallela gicv3_redist_update_lpi(&s->gicv3->cpu[i]); 86717fb5e36SShashi Mallela } 8687eca39e0SShashi Mallela break; 869961b4912SPeter Maydell case GITS_CMD_MOVI: 870b6f96009SPeter Maydell result = process_movi(s, cmdpkt); 871961b4912SPeter Maydell break; 872f6d1d9b4SPeter Maydell case GITS_CMD_MOVALL: 873b6f96009SPeter Maydell result = process_movall(s, cmdpkt); 874f6d1d9b4SPeter Maydell break; 8757eca39e0SShashi Mallela default: 876e4050980SPeter Maydell trace_gicv3_its_cmd_unknown(cmd); 8777eca39e0SShashi Mallela break; 8787eca39e0SShashi Mallela } 879ef011555SPeter Maydell if (result == CMD_CONTINUE) { 8807eca39e0SShashi Mallela rd_offset++; 88180dcd37fSPeter Maydell rd_offset %= s->cq.num_entries; 8827eca39e0SShashi Mallela s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, OFFSET, rd_offset); 8837eca39e0SShashi Mallela } else { 884ef011555SPeter Maydell /* CMD_STALL */ 8857eca39e0SShashi Mallela s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1); 8867eca39e0SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 887ef011555SPeter Maydell "%s: 0x%x cmd processing failed, stalling\n", 888ef011555SPeter Maydell __func__, cmd); 8897eca39e0SShashi Mallela break; 8907eca39e0SShashi Mallela } 8917eca39e0SShashi Mallela } 8927eca39e0SShashi Mallela } 8937eca39e0SShashi Mallela 8941b08e436SShashi Mallela /* 8951b08e436SShashi Mallela * This function extracts the ITS Device and Collection table specific 8961b08e436SShashi Mallela * parameters (like base_addr, size etc) from GITS_BASER register. 8971b08e436SShashi Mallela * It is called during ITS enable and also during post_load migration 8981b08e436SShashi Mallela */ 8991b08e436SShashi Mallela static void extract_table_params(GICv3ITSState *s) 9001b08e436SShashi Mallela { 9011b08e436SShashi Mallela uint16_t num_pages = 0; 9021b08e436SShashi Mallela uint8_t page_sz_type; 9031b08e436SShashi Mallela uint8_t type; 9041b08e436SShashi Mallela uint32_t page_sz = 0; 9051b08e436SShashi Mallela uint64_t value; 9061b08e436SShashi Mallela 9071b08e436SShashi Mallela for (int i = 0; i < 8; i++) { 908e5487a41SPeter Maydell TableDesc *td; 909e5487a41SPeter Maydell int idbits; 910e5487a41SPeter Maydell 9111b08e436SShashi Mallela value = s->baser[i]; 9121b08e436SShashi Mallela 9131b08e436SShashi Mallela if (!value) { 9141b08e436SShashi Mallela continue; 9151b08e436SShashi Mallela } 9161b08e436SShashi Mallela 9171b08e436SShashi Mallela page_sz_type = FIELD_EX64(value, GITS_BASER, PAGESIZE); 9181b08e436SShashi Mallela 9191b08e436SShashi Mallela switch (page_sz_type) { 9201b08e436SShashi Mallela case 0: 9211b08e436SShashi Mallela page_sz = GITS_PAGE_SIZE_4K; 9221b08e436SShashi Mallela break; 9231b08e436SShashi Mallela 9241b08e436SShashi Mallela case 1: 9251b08e436SShashi Mallela page_sz = GITS_PAGE_SIZE_16K; 9261b08e436SShashi Mallela break; 9271b08e436SShashi Mallela 9281b08e436SShashi Mallela case 2: 9291b08e436SShashi Mallela case 3: 9301b08e436SShashi Mallela page_sz = GITS_PAGE_SIZE_64K; 9311b08e436SShashi Mallela break; 9321b08e436SShashi Mallela 9331b08e436SShashi Mallela default: 9341b08e436SShashi Mallela g_assert_not_reached(); 9351b08e436SShashi Mallela } 9361b08e436SShashi Mallela 9371b08e436SShashi Mallela num_pages = FIELD_EX64(value, GITS_BASER, SIZE) + 1; 9381b08e436SShashi Mallela 9391b08e436SShashi Mallela type = FIELD_EX64(value, GITS_BASER, TYPE); 9401b08e436SShashi Mallela 9411b08e436SShashi Mallela switch (type) { 9421b08e436SShashi Mallela case GITS_BASER_TYPE_DEVICE: 943e5487a41SPeter Maydell td = &s->dt; 944e5487a41SPeter Maydell idbits = FIELD_EX64(s->typer, GITS_TYPER, DEVBITS) + 1; 94562df780eSPeter Maydell break; 9461b08e436SShashi Mallela case GITS_BASER_TYPE_COLLECTION: 947e5487a41SPeter Maydell td = &s->ct; 9481b08e436SShashi Mallela if (FIELD_EX64(s->typer, GITS_TYPER, CIL)) { 949e5487a41SPeter Maydell idbits = FIELD_EX64(s->typer, GITS_TYPER, CIDBITS) + 1; 9501b08e436SShashi Mallela } else { 9511b08e436SShashi Mallela /* 16-bit CollectionId supported when CIL == 0 */ 952e5487a41SPeter Maydell idbits = 16; 9531b08e436SShashi Mallela } 9541b08e436SShashi Mallela break; 955*50d84584SPeter Maydell case GITS_BASER_TYPE_VPE: 956*50d84584SPeter Maydell td = &s->vpet; 957*50d84584SPeter Maydell /* 958*50d84584SPeter Maydell * For QEMU vPEIDs are always 16 bits. (GICv4.1 allows an 959*50d84584SPeter Maydell * implementation to implement fewer bits and report this 960*50d84584SPeter Maydell * via GICD_TYPER2.) 961*50d84584SPeter Maydell */ 962*50d84584SPeter Maydell idbits = 16; 963*50d84584SPeter Maydell break; 9641b08e436SShashi Mallela default: 965e5487a41SPeter Maydell /* 966e5487a41SPeter Maydell * GITS_BASER<n>.TYPE is read-only, so GITS_BASER_RO_MASK 967e5487a41SPeter Maydell * ensures we will only see type values corresponding to 968e5487a41SPeter Maydell * the values set up in gicv3_its_reset(). 969e5487a41SPeter Maydell */ 970e5487a41SPeter Maydell g_assert_not_reached(); 9711b08e436SShashi Mallela } 972e5487a41SPeter Maydell 973e5487a41SPeter Maydell memset(td, 0, sizeof(*td)); 974e5487a41SPeter Maydell /* 975e5487a41SPeter Maydell * If GITS_BASER<n>.Valid is 0 for any <n> then we will not process 976e5487a41SPeter Maydell * interrupts. (GITS_TYPER.HCC is 0 for this implementation, so we 977e5487a41SPeter Maydell * do not have a special case where the GITS_BASER<n>.Valid bit is 0 978e5487a41SPeter Maydell * for the register corresponding to the Collection table but we 979e5487a41SPeter Maydell * still have to process interrupts using non-memory-backed 980e5487a41SPeter Maydell * Collection table entries.) 981da4680ceSPeter Maydell * The specification makes it UNPREDICTABLE to enable the ITS without 982da4680ceSPeter Maydell * marking each BASER<n> as valid. We choose to handle these as if 983da4680ceSPeter Maydell * the table was zero-sized, so commands using the table will fail 984da4680ceSPeter Maydell * and interrupts requested via GITS_TRANSLATER writes will be ignored. 985da4680ceSPeter Maydell * This happens automatically by leaving the num_entries field at 986da4680ceSPeter Maydell * zero, which will be caught by the bounds checks we have before 987da4680ceSPeter Maydell * every table lookup anyway. 988e5487a41SPeter Maydell */ 989da4680ceSPeter Maydell if (!FIELD_EX64(value, GITS_BASER, VALID)) { 990e5487a41SPeter Maydell continue; 991e5487a41SPeter Maydell } 992e5487a41SPeter Maydell td->page_sz = page_sz; 993e5487a41SPeter Maydell td->indirect = FIELD_EX64(value, GITS_BASER, INDIRECT); 9949ae85431SPeter Maydell td->entry_sz = FIELD_EX64(value, GITS_BASER, ENTRYSIZE) + 1; 995e5487a41SPeter Maydell td->base_addr = baser_base_addr(value, page_sz); 996e5487a41SPeter Maydell if (!td->indirect) { 99780dcd37fSPeter Maydell td->num_entries = (num_pages * page_sz) / td->entry_sz; 998e5487a41SPeter Maydell } else { 99980dcd37fSPeter Maydell td->num_entries = (((num_pages * page_sz) / 1000e5487a41SPeter Maydell L1TABLE_ENTRY_SIZE) * 1001e5487a41SPeter Maydell (page_sz / td->entry_sz)); 1002e5487a41SPeter Maydell } 10038b8bb014SPeter Maydell td->num_entries = MIN(td->num_entries, 1ULL << idbits); 10041b08e436SShashi Mallela } 10051b08e436SShashi Mallela } 10061b08e436SShashi Mallela 10071b08e436SShashi Mallela static void extract_cmdq_params(GICv3ITSState *s) 10081b08e436SShashi Mallela { 10091b08e436SShashi Mallela uint16_t num_pages = 0; 10101b08e436SShashi Mallela uint64_t value = s->cbaser; 10111b08e436SShashi Mallela 10121b08e436SShashi Mallela num_pages = FIELD_EX64(value, GITS_CBASER, SIZE) + 1; 10131b08e436SShashi Mallela 10141b08e436SShashi Mallela memset(&s->cq, 0 , sizeof(s->cq)); 10151b08e436SShashi Mallela 1016da4680ceSPeter Maydell if (FIELD_EX64(value, GITS_CBASER, VALID)) { 101780dcd37fSPeter Maydell s->cq.num_entries = (num_pages * GITS_PAGE_SIZE_4K) / 10181b08e436SShashi Mallela GITS_CMDQ_ENTRY_SIZE; 10191b08e436SShashi Mallela s->cq.base_addr = FIELD_EX64(value, GITS_CBASER, PHYADDR); 10201b08e436SShashi Mallela s->cq.base_addr <<= R_GITS_CBASER_PHYADDR_SHIFT; 10211b08e436SShashi Mallela } 10221b08e436SShashi Mallela } 10231b08e436SShashi Mallela 10247e062b98SPeter Maydell static MemTxResult gicv3_its_translation_read(void *opaque, hwaddr offset, 10257e062b98SPeter Maydell uint64_t *data, unsigned size, 10267e062b98SPeter Maydell MemTxAttrs attrs) 10277e062b98SPeter Maydell { 10287e062b98SPeter Maydell /* 10297e062b98SPeter Maydell * GITS_TRANSLATER is write-only, and all other addresses 10307e062b98SPeter Maydell * in the interrupt translation space frame are RES0. 10317e062b98SPeter Maydell */ 10327e062b98SPeter Maydell *data = 0; 10337e062b98SPeter Maydell return MEMTX_OK; 10347e062b98SPeter Maydell } 10357e062b98SPeter Maydell 103618f6290aSShashi Mallela static MemTxResult gicv3_its_translation_write(void *opaque, hwaddr offset, 103718f6290aSShashi Mallela uint64_t data, unsigned size, 103818f6290aSShashi Mallela MemTxAttrs attrs) 103918f6290aSShashi Mallela { 1040c694cb4cSShashi Mallela GICv3ITSState *s = (GICv3ITSState *)opaque; 1041c694cb4cSShashi Mallela bool result = true; 1042c694cb4cSShashi Mallela 1043195209d3SPeter Maydell trace_gicv3_its_translation_write(offset, data, size, attrs.requester_id); 1044195209d3SPeter Maydell 1045c694cb4cSShashi Mallela switch (offset) { 1046c694cb4cSShashi Mallela case GITS_TRANSLATER: 10478d2d6dd9SPeter Maydell if (s->ctlr & R_GITS_CTLR_ENABLED_MASK) { 1048b6f96009SPeter Maydell result = do_process_its_cmd(s, attrs.requester_id, data, NONE); 1049c694cb4cSShashi Mallela } 1050c694cb4cSShashi Mallela break; 1051c694cb4cSShashi Mallela default: 1052c694cb4cSShashi Mallela break; 1053c694cb4cSShashi Mallela } 1054c694cb4cSShashi Mallela 1055c694cb4cSShashi Mallela if (result) { 105618f6290aSShashi Mallela return MEMTX_OK; 1057c694cb4cSShashi Mallela } else { 1058c694cb4cSShashi Mallela return MEMTX_ERROR; 1059c694cb4cSShashi Mallela } 106018f6290aSShashi Mallela } 106118f6290aSShashi Mallela 106218f6290aSShashi Mallela static bool its_writel(GICv3ITSState *s, hwaddr offset, 106318f6290aSShashi Mallela uint64_t value, MemTxAttrs attrs) 106418f6290aSShashi Mallela { 106518f6290aSShashi Mallela bool result = true; 10661b08e436SShashi Mallela int index; 106718f6290aSShashi Mallela 10681b08e436SShashi Mallela switch (offset) { 10691b08e436SShashi Mallela case GITS_CTLR: 10702f459cd1SShashi Mallela if (value & R_GITS_CTLR_ENABLED_MASK) { 10718d2d6dd9SPeter Maydell s->ctlr |= R_GITS_CTLR_ENABLED_MASK; 10721b08e436SShashi Mallela extract_table_params(s); 10731b08e436SShashi Mallela extract_cmdq_params(s); 10747eca39e0SShashi Mallela process_cmdq(s); 10752f459cd1SShashi Mallela } else { 10768d2d6dd9SPeter Maydell s->ctlr &= ~R_GITS_CTLR_ENABLED_MASK; 10771b08e436SShashi Mallela } 10781b08e436SShashi Mallela break; 10791b08e436SShashi Mallela case GITS_CBASER: 10801b08e436SShashi Mallela /* 10811b08e436SShashi Mallela * IMPDEF choice:- GITS_CBASER register becomes RO if ITS is 10821b08e436SShashi Mallela * already enabled 10831b08e436SShashi Mallela */ 10848d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 10851b08e436SShashi Mallela s->cbaser = deposit64(s->cbaser, 0, 32, value); 10861b08e436SShashi Mallela s->creadr = 0; 10871b08e436SShashi Mallela } 10881b08e436SShashi Mallela break; 10891b08e436SShashi Mallela case GITS_CBASER + 4: 10901b08e436SShashi Mallela /* 10911b08e436SShashi Mallela * IMPDEF choice:- GITS_CBASER register becomes RO if ITS is 10921b08e436SShashi Mallela * already enabled 10931b08e436SShashi Mallela */ 10948d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 10951b08e436SShashi Mallela s->cbaser = deposit64(s->cbaser, 32, 32, value); 10961b08e436SShashi Mallela s->creadr = 0; 10971b08e436SShashi Mallela } 10981b08e436SShashi Mallela break; 10991b08e436SShashi Mallela case GITS_CWRITER: 11001b08e436SShashi Mallela s->cwriter = deposit64(s->cwriter, 0, 32, 11011b08e436SShashi Mallela (value & ~R_GITS_CWRITER_RETRY_MASK)); 11027eca39e0SShashi Mallela if (s->cwriter != s->creadr) { 11037eca39e0SShashi Mallela process_cmdq(s); 11047eca39e0SShashi Mallela } 11051b08e436SShashi Mallela break; 11061b08e436SShashi Mallela case GITS_CWRITER + 4: 11071b08e436SShashi Mallela s->cwriter = deposit64(s->cwriter, 32, 32, value); 11081b08e436SShashi Mallela break; 11091b08e436SShashi Mallela case GITS_CREADR: 11101b08e436SShashi Mallela if (s->gicv3->gicd_ctlr & GICD_CTLR_DS) { 11111b08e436SShashi Mallela s->creadr = deposit64(s->creadr, 0, 32, 11121b08e436SShashi Mallela (value & ~R_GITS_CREADR_STALLED_MASK)); 11131b08e436SShashi Mallela } else { 11141b08e436SShashi Mallela /* RO register, ignore the write */ 11151b08e436SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 11161b08e436SShashi Mallela "%s: invalid guest write to RO register at offset " 11171b08e436SShashi Mallela TARGET_FMT_plx "\n", __func__, offset); 11181b08e436SShashi Mallela } 11191b08e436SShashi Mallela break; 11201b08e436SShashi Mallela case GITS_CREADR + 4: 11211b08e436SShashi Mallela if (s->gicv3->gicd_ctlr & GICD_CTLR_DS) { 11221b08e436SShashi Mallela s->creadr = deposit64(s->creadr, 32, 32, value); 11231b08e436SShashi Mallela } else { 11241b08e436SShashi Mallela /* RO register, ignore the write */ 11251b08e436SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 11261b08e436SShashi Mallela "%s: invalid guest write to RO register at offset " 11271b08e436SShashi Mallela TARGET_FMT_plx "\n", __func__, offset); 11281b08e436SShashi Mallela } 11291b08e436SShashi Mallela break; 11301b08e436SShashi Mallela case GITS_BASER ... GITS_BASER + 0x3f: 11311b08e436SShashi Mallela /* 11321b08e436SShashi Mallela * IMPDEF choice:- GITS_BASERn register becomes RO if ITS is 11331b08e436SShashi Mallela * already enabled 11341b08e436SShashi Mallela */ 11358d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 11361b08e436SShashi Mallela index = (offset - GITS_BASER) / 8; 11371b08e436SShashi Mallela 11380ffe88e6SPeter Maydell if (s->baser[index] == 0) { 11390ffe88e6SPeter Maydell /* Unimplemented GITS_BASERn: RAZ/WI */ 11400ffe88e6SPeter Maydell break; 11410ffe88e6SPeter Maydell } 11421b08e436SShashi Mallela if (offset & 7) { 11431b08e436SShashi Mallela value <<= 32; 11441b08e436SShashi Mallela value &= ~GITS_BASER_RO_MASK; 11451b08e436SShashi Mallela s->baser[index] &= GITS_BASER_RO_MASK | MAKE_64BIT_MASK(0, 32); 11461b08e436SShashi Mallela s->baser[index] |= value; 11471b08e436SShashi Mallela } else { 11481b08e436SShashi Mallela value &= ~GITS_BASER_RO_MASK; 11491b08e436SShashi Mallela s->baser[index] &= GITS_BASER_RO_MASK | MAKE_64BIT_MASK(32, 32); 11501b08e436SShashi Mallela s->baser[index] |= value; 11511b08e436SShashi Mallela } 11521b08e436SShashi Mallela } 11531b08e436SShashi Mallela break; 11541b08e436SShashi Mallela case GITS_IIDR: 11551b08e436SShashi Mallela case GITS_IDREGS ... GITS_IDREGS + 0x2f: 11561b08e436SShashi Mallela /* RO registers, ignore the write */ 11571b08e436SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 11581b08e436SShashi Mallela "%s: invalid guest write to RO register at offset " 11591b08e436SShashi Mallela TARGET_FMT_plx "\n", __func__, offset); 11601b08e436SShashi Mallela break; 11611b08e436SShashi Mallela default: 11621b08e436SShashi Mallela result = false; 11631b08e436SShashi Mallela break; 11641b08e436SShashi Mallela } 116518f6290aSShashi Mallela return result; 116618f6290aSShashi Mallela } 116718f6290aSShashi Mallela 116818f6290aSShashi Mallela static bool its_readl(GICv3ITSState *s, hwaddr offset, 116918f6290aSShashi Mallela uint64_t *data, MemTxAttrs attrs) 117018f6290aSShashi Mallela { 117118f6290aSShashi Mallela bool result = true; 11721b08e436SShashi Mallela int index; 117318f6290aSShashi Mallela 11741b08e436SShashi Mallela switch (offset) { 11751b08e436SShashi Mallela case GITS_CTLR: 11761b08e436SShashi Mallela *data = s->ctlr; 11771b08e436SShashi Mallela break; 11781b08e436SShashi Mallela case GITS_IIDR: 11791b08e436SShashi Mallela *data = gicv3_iidr(); 11801b08e436SShashi Mallela break; 11811b08e436SShashi Mallela case GITS_IDREGS ... GITS_IDREGS + 0x2f: 11821b08e436SShashi Mallela /* ID registers */ 118350a3a309SPeter Maydell *data = gicv3_idreg(offset - GITS_IDREGS, GICV3_PIDR0_ITS); 11841b08e436SShashi Mallela break; 11851b08e436SShashi Mallela case GITS_TYPER: 11861b08e436SShashi Mallela *data = extract64(s->typer, 0, 32); 11871b08e436SShashi Mallela break; 11881b08e436SShashi Mallela case GITS_TYPER + 4: 11891b08e436SShashi Mallela *data = extract64(s->typer, 32, 32); 11901b08e436SShashi Mallela break; 11911b08e436SShashi Mallela case GITS_CBASER: 11921b08e436SShashi Mallela *data = extract64(s->cbaser, 0, 32); 11931b08e436SShashi Mallela break; 11941b08e436SShashi Mallela case GITS_CBASER + 4: 11951b08e436SShashi Mallela *data = extract64(s->cbaser, 32, 32); 11961b08e436SShashi Mallela break; 11971b08e436SShashi Mallela case GITS_CREADR: 11981b08e436SShashi Mallela *data = extract64(s->creadr, 0, 32); 11991b08e436SShashi Mallela break; 12001b08e436SShashi Mallela case GITS_CREADR + 4: 12011b08e436SShashi Mallela *data = extract64(s->creadr, 32, 32); 12021b08e436SShashi Mallela break; 12031b08e436SShashi Mallela case GITS_CWRITER: 12041b08e436SShashi Mallela *data = extract64(s->cwriter, 0, 32); 12051b08e436SShashi Mallela break; 12061b08e436SShashi Mallela case GITS_CWRITER + 4: 12071b08e436SShashi Mallela *data = extract64(s->cwriter, 32, 32); 12081b08e436SShashi Mallela break; 12091b08e436SShashi Mallela case GITS_BASER ... GITS_BASER + 0x3f: 12101b08e436SShashi Mallela index = (offset - GITS_BASER) / 8; 12111b08e436SShashi Mallela if (offset & 7) { 12121b08e436SShashi Mallela *data = extract64(s->baser[index], 32, 32); 12131b08e436SShashi Mallela } else { 12141b08e436SShashi Mallela *data = extract64(s->baser[index], 0, 32); 12151b08e436SShashi Mallela } 12161b08e436SShashi Mallela break; 12171b08e436SShashi Mallela default: 12181b08e436SShashi Mallela result = false; 12191b08e436SShashi Mallela break; 12201b08e436SShashi Mallela } 122118f6290aSShashi Mallela return result; 122218f6290aSShashi Mallela } 122318f6290aSShashi Mallela 122418f6290aSShashi Mallela static bool its_writell(GICv3ITSState *s, hwaddr offset, 122518f6290aSShashi Mallela uint64_t value, MemTxAttrs attrs) 122618f6290aSShashi Mallela { 122718f6290aSShashi Mallela bool result = true; 12281b08e436SShashi Mallela int index; 122918f6290aSShashi Mallela 12301b08e436SShashi Mallela switch (offset) { 12311b08e436SShashi Mallela case GITS_BASER ... GITS_BASER + 0x3f: 12321b08e436SShashi Mallela /* 12331b08e436SShashi Mallela * IMPDEF choice:- GITS_BASERn register becomes RO if ITS is 12341b08e436SShashi Mallela * already enabled 12351b08e436SShashi Mallela */ 12368d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 12371b08e436SShashi Mallela index = (offset - GITS_BASER) / 8; 12380ffe88e6SPeter Maydell if (s->baser[index] == 0) { 12390ffe88e6SPeter Maydell /* Unimplemented GITS_BASERn: RAZ/WI */ 12400ffe88e6SPeter Maydell break; 12410ffe88e6SPeter Maydell } 12421b08e436SShashi Mallela s->baser[index] &= GITS_BASER_RO_MASK; 12431b08e436SShashi Mallela s->baser[index] |= (value & ~GITS_BASER_RO_MASK); 12441b08e436SShashi Mallela } 12451b08e436SShashi Mallela break; 12461b08e436SShashi Mallela case GITS_CBASER: 12471b08e436SShashi Mallela /* 12481b08e436SShashi Mallela * IMPDEF choice:- GITS_CBASER register becomes RO if ITS is 12491b08e436SShashi Mallela * already enabled 12501b08e436SShashi Mallela */ 12518d2d6dd9SPeter Maydell if (!(s->ctlr & R_GITS_CTLR_ENABLED_MASK)) { 12521b08e436SShashi Mallela s->cbaser = value; 12531b08e436SShashi Mallela s->creadr = 0; 12541b08e436SShashi Mallela } 12551b08e436SShashi Mallela break; 12561b08e436SShashi Mallela case GITS_CWRITER: 12571b08e436SShashi Mallela s->cwriter = value & ~R_GITS_CWRITER_RETRY_MASK; 12587eca39e0SShashi Mallela if (s->cwriter != s->creadr) { 12597eca39e0SShashi Mallela process_cmdq(s); 12607eca39e0SShashi Mallela } 12611b08e436SShashi Mallela break; 12621b08e436SShashi Mallela case GITS_CREADR: 12631b08e436SShashi Mallela if (s->gicv3->gicd_ctlr & GICD_CTLR_DS) { 12641b08e436SShashi Mallela s->creadr = value & ~R_GITS_CREADR_STALLED_MASK; 12651b08e436SShashi Mallela } else { 12661b08e436SShashi Mallela /* RO register, ignore the write */ 12671b08e436SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 12681b08e436SShashi Mallela "%s: invalid guest write to RO register at offset " 12691b08e436SShashi Mallela TARGET_FMT_plx "\n", __func__, offset); 12701b08e436SShashi Mallela } 12711b08e436SShashi Mallela break; 12721b08e436SShashi Mallela case GITS_TYPER: 12731b08e436SShashi Mallela /* RO registers, ignore the write */ 12741b08e436SShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 12751b08e436SShashi Mallela "%s: invalid guest write to RO register at offset " 12761b08e436SShashi Mallela TARGET_FMT_plx "\n", __func__, offset); 12771b08e436SShashi Mallela break; 12781b08e436SShashi Mallela default: 12791b08e436SShashi Mallela result = false; 12801b08e436SShashi Mallela break; 12811b08e436SShashi Mallela } 128218f6290aSShashi Mallela return result; 128318f6290aSShashi Mallela } 128418f6290aSShashi Mallela 128518f6290aSShashi Mallela static bool its_readll(GICv3ITSState *s, hwaddr offset, 128618f6290aSShashi Mallela uint64_t *data, MemTxAttrs attrs) 128718f6290aSShashi Mallela { 128818f6290aSShashi Mallela bool result = true; 12891b08e436SShashi Mallela int index; 129018f6290aSShashi Mallela 12911b08e436SShashi Mallela switch (offset) { 12921b08e436SShashi Mallela case GITS_TYPER: 12931b08e436SShashi Mallela *data = s->typer; 12941b08e436SShashi Mallela break; 12951b08e436SShashi Mallela case GITS_BASER ... GITS_BASER + 0x3f: 12961b08e436SShashi Mallela index = (offset - GITS_BASER) / 8; 12971b08e436SShashi Mallela *data = s->baser[index]; 12981b08e436SShashi Mallela break; 12991b08e436SShashi Mallela case GITS_CBASER: 13001b08e436SShashi Mallela *data = s->cbaser; 13011b08e436SShashi Mallela break; 13021b08e436SShashi Mallela case GITS_CREADR: 13031b08e436SShashi Mallela *data = s->creadr; 13041b08e436SShashi Mallela break; 13051b08e436SShashi Mallela case GITS_CWRITER: 13061b08e436SShashi Mallela *data = s->cwriter; 13071b08e436SShashi Mallela break; 13081b08e436SShashi Mallela default: 13091b08e436SShashi Mallela result = false; 13101b08e436SShashi Mallela break; 13111b08e436SShashi Mallela } 131218f6290aSShashi Mallela return result; 131318f6290aSShashi Mallela } 131418f6290aSShashi Mallela 131518f6290aSShashi Mallela static MemTxResult gicv3_its_read(void *opaque, hwaddr offset, uint64_t *data, 131618f6290aSShashi Mallela unsigned size, MemTxAttrs attrs) 131718f6290aSShashi Mallela { 131818f6290aSShashi Mallela GICv3ITSState *s = (GICv3ITSState *)opaque; 131918f6290aSShashi Mallela bool result; 132018f6290aSShashi Mallela 132118f6290aSShashi Mallela switch (size) { 132218f6290aSShashi Mallela case 4: 132318f6290aSShashi Mallela result = its_readl(s, offset, data, attrs); 132418f6290aSShashi Mallela break; 132518f6290aSShashi Mallela case 8: 132618f6290aSShashi Mallela result = its_readll(s, offset, data, attrs); 132718f6290aSShashi Mallela break; 132818f6290aSShashi Mallela default: 132918f6290aSShashi Mallela result = false; 133018f6290aSShashi Mallela break; 133118f6290aSShashi Mallela } 133218f6290aSShashi Mallela 133318f6290aSShashi Mallela if (!result) { 133418f6290aSShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 133518f6290aSShashi Mallela "%s: invalid guest read at offset " TARGET_FMT_plx 133618f6290aSShashi Mallela " size %u\n", __func__, offset, size); 1337195209d3SPeter Maydell trace_gicv3_its_badread(offset, size); 133818f6290aSShashi Mallela /* 133918f6290aSShashi Mallela * The spec requires that reserved registers are RAZ/WI; 134018f6290aSShashi Mallela * so use false returns from leaf functions as a way to 134118f6290aSShashi Mallela * trigger the guest-error logging but don't return it to 134218f6290aSShashi Mallela * the caller, or we'll cause a spurious guest data abort. 134318f6290aSShashi Mallela */ 134418f6290aSShashi Mallela *data = 0; 1345195209d3SPeter Maydell } else { 1346195209d3SPeter Maydell trace_gicv3_its_read(offset, *data, size); 134718f6290aSShashi Mallela } 134818f6290aSShashi Mallela return MEMTX_OK; 134918f6290aSShashi Mallela } 135018f6290aSShashi Mallela 135118f6290aSShashi Mallela static MemTxResult gicv3_its_write(void *opaque, hwaddr offset, uint64_t data, 135218f6290aSShashi Mallela unsigned size, MemTxAttrs attrs) 135318f6290aSShashi Mallela { 135418f6290aSShashi Mallela GICv3ITSState *s = (GICv3ITSState *)opaque; 135518f6290aSShashi Mallela bool result; 135618f6290aSShashi Mallela 135718f6290aSShashi Mallela switch (size) { 135818f6290aSShashi Mallela case 4: 135918f6290aSShashi Mallela result = its_writel(s, offset, data, attrs); 136018f6290aSShashi Mallela break; 136118f6290aSShashi Mallela case 8: 136218f6290aSShashi Mallela result = its_writell(s, offset, data, attrs); 136318f6290aSShashi Mallela break; 136418f6290aSShashi Mallela default: 136518f6290aSShashi Mallela result = false; 136618f6290aSShashi Mallela break; 136718f6290aSShashi Mallela } 136818f6290aSShashi Mallela 136918f6290aSShashi Mallela if (!result) { 137018f6290aSShashi Mallela qemu_log_mask(LOG_GUEST_ERROR, 137118f6290aSShashi Mallela "%s: invalid guest write at offset " TARGET_FMT_plx 137218f6290aSShashi Mallela " size %u\n", __func__, offset, size); 1373195209d3SPeter Maydell trace_gicv3_its_badwrite(offset, data, size); 137418f6290aSShashi Mallela /* 137518f6290aSShashi Mallela * The spec requires that reserved registers are RAZ/WI; 137618f6290aSShashi Mallela * so use false returns from leaf functions as a way to 137718f6290aSShashi Mallela * trigger the guest-error logging but don't return it to 137818f6290aSShashi Mallela * the caller, or we'll cause a spurious guest data abort. 137918f6290aSShashi Mallela */ 1380195209d3SPeter Maydell } else { 1381195209d3SPeter Maydell trace_gicv3_its_write(offset, data, size); 138218f6290aSShashi Mallela } 138318f6290aSShashi Mallela return MEMTX_OK; 138418f6290aSShashi Mallela } 138518f6290aSShashi Mallela 138618f6290aSShashi Mallela static const MemoryRegionOps gicv3_its_control_ops = { 138718f6290aSShashi Mallela .read_with_attrs = gicv3_its_read, 138818f6290aSShashi Mallela .write_with_attrs = gicv3_its_write, 138918f6290aSShashi Mallela .valid.min_access_size = 4, 139018f6290aSShashi Mallela .valid.max_access_size = 8, 139118f6290aSShashi Mallela .impl.min_access_size = 4, 139218f6290aSShashi Mallela .impl.max_access_size = 8, 139318f6290aSShashi Mallela .endianness = DEVICE_NATIVE_ENDIAN, 139418f6290aSShashi Mallela }; 139518f6290aSShashi Mallela 139618f6290aSShashi Mallela static const MemoryRegionOps gicv3_its_translation_ops = { 13977e062b98SPeter Maydell .read_with_attrs = gicv3_its_translation_read, 139818f6290aSShashi Mallela .write_with_attrs = gicv3_its_translation_write, 139918f6290aSShashi Mallela .valid.min_access_size = 2, 140018f6290aSShashi Mallela .valid.max_access_size = 4, 140118f6290aSShashi Mallela .impl.min_access_size = 2, 140218f6290aSShashi Mallela .impl.max_access_size = 4, 140318f6290aSShashi Mallela .endianness = DEVICE_NATIVE_ENDIAN, 140418f6290aSShashi Mallela }; 140518f6290aSShashi Mallela 140618f6290aSShashi Mallela static void gicv3_arm_its_realize(DeviceState *dev, Error **errp) 140718f6290aSShashi Mallela { 140818f6290aSShashi Mallela GICv3ITSState *s = ARM_GICV3_ITS_COMMON(dev); 140918f6290aSShashi Mallela int i; 141018f6290aSShashi Mallela 141118f6290aSShashi Mallela for (i = 0; i < s->gicv3->num_cpu; i++) { 141218f6290aSShashi Mallela if (!(s->gicv3->cpu[i].gicr_typer & GICR_TYPER_PLPIS)) { 141318f6290aSShashi Mallela error_setg(errp, "Physical LPI not supported by CPU %d", i); 141418f6290aSShashi Mallela return; 141518f6290aSShashi Mallela } 141618f6290aSShashi Mallela } 141718f6290aSShashi Mallela 141818f6290aSShashi Mallela gicv3_its_init_mmio(s, &gicv3_its_control_ops, &gicv3_its_translation_ops); 141918f6290aSShashi Mallela 142018f6290aSShashi Mallela /* set the ITS default features supported */ 1421764d6ba1SPeter Maydell s->typer = FIELD_DP64(s->typer, GITS_TYPER, PHYSICAL, 1); 142218f6290aSShashi Mallela s->typer = FIELD_DP64(s->typer, GITS_TYPER, ITT_ENTRY_SIZE, 142318f6290aSShashi Mallela ITS_ITT_ENTRY_SIZE - 1); 142418f6290aSShashi Mallela s->typer = FIELD_DP64(s->typer, GITS_TYPER, IDBITS, ITS_IDBITS); 142518f6290aSShashi Mallela s->typer = FIELD_DP64(s->typer, GITS_TYPER, DEVBITS, ITS_DEVBITS); 142618f6290aSShashi Mallela s->typer = FIELD_DP64(s->typer, GITS_TYPER, CIL, 1); 142718f6290aSShashi Mallela s->typer = FIELD_DP64(s->typer, GITS_TYPER, CIDBITS, ITS_CIDBITS); 142818f6290aSShashi Mallela } 142918f6290aSShashi Mallela 143018f6290aSShashi Mallela static void gicv3_its_reset(DeviceState *dev) 143118f6290aSShashi Mallela { 143218f6290aSShashi Mallela GICv3ITSState *s = ARM_GICV3_ITS_COMMON(dev); 143318f6290aSShashi Mallela GICv3ITSClass *c = ARM_GICV3_ITS_GET_CLASS(s); 143418f6290aSShashi Mallela 143518f6290aSShashi Mallela c->parent_reset(dev); 143618f6290aSShashi Mallela 143718f6290aSShashi Mallela /* Quiescent bit reset to 1 */ 143818f6290aSShashi Mallela s->ctlr = FIELD_DP32(s->ctlr, GITS_CTLR, QUIESCENT, 1); 143918f6290aSShashi Mallela 144018f6290aSShashi Mallela /* 144118f6290aSShashi Mallela * setting GITS_BASER0.Type = 0b001 (Device) 144218f6290aSShashi Mallela * GITS_BASER1.Type = 0b100 (Collection Table) 1443*50d84584SPeter Maydell * GITS_BASER2.Type = 0b010 (vPE) for GICv4 and later 144418f6290aSShashi Mallela * GITS_BASER<n>.Type,where n = 3 to 7 are 0b00 (Unimplemented) 144518f6290aSShashi Mallela * GITS_BASER<0,1>.Page_Size = 64KB 144618f6290aSShashi Mallela * and default translation table entry size to 16 bytes 144718f6290aSShashi Mallela */ 144818f6290aSShashi Mallela s->baser[0] = FIELD_DP64(s->baser[0], GITS_BASER, TYPE, 144918f6290aSShashi Mallela GITS_BASER_TYPE_DEVICE); 145018f6290aSShashi Mallela s->baser[0] = FIELD_DP64(s->baser[0], GITS_BASER, PAGESIZE, 145118f6290aSShashi Mallela GITS_BASER_PAGESIZE_64K); 145218f6290aSShashi Mallela s->baser[0] = FIELD_DP64(s->baser[0], GITS_BASER, ENTRYSIZE, 145318f6290aSShashi Mallela GITS_DTE_SIZE - 1); 145418f6290aSShashi Mallela 145518f6290aSShashi Mallela s->baser[1] = FIELD_DP64(s->baser[1], GITS_BASER, TYPE, 145618f6290aSShashi Mallela GITS_BASER_TYPE_COLLECTION); 145718f6290aSShashi Mallela s->baser[1] = FIELD_DP64(s->baser[1], GITS_BASER, PAGESIZE, 145818f6290aSShashi Mallela GITS_BASER_PAGESIZE_64K); 145918f6290aSShashi Mallela s->baser[1] = FIELD_DP64(s->baser[1], GITS_BASER, ENTRYSIZE, 146018f6290aSShashi Mallela GITS_CTE_SIZE - 1); 1461*50d84584SPeter Maydell 1462*50d84584SPeter Maydell if (its_feature_virtual(s)) { 1463*50d84584SPeter Maydell s->baser[2] = FIELD_DP64(s->baser[2], GITS_BASER, TYPE, 1464*50d84584SPeter Maydell GITS_BASER_TYPE_VPE); 1465*50d84584SPeter Maydell s->baser[2] = FIELD_DP64(s->baser[2], GITS_BASER, PAGESIZE, 1466*50d84584SPeter Maydell GITS_BASER_PAGESIZE_64K); 1467*50d84584SPeter Maydell s->baser[2] = FIELD_DP64(s->baser[2], GITS_BASER, ENTRYSIZE, 1468*50d84584SPeter Maydell GITS_VPE_SIZE - 1); 1469*50d84584SPeter Maydell } 147018f6290aSShashi Mallela } 147118f6290aSShashi Mallela 14721b08e436SShashi Mallela static void gicv3_its_post_load(GICv3ITSState *s) 14731b08e436SShashi Mallela { 14748d2d6dd9SPeter Maydell if (s->ctlr & R_GITS_CTLR_ENABLED_MASK) { 14751b08e436SShashi Mallela extract_table_params(s); 14761b08e436SShashi Mallela extract_cmdq_params(s); 14771b08e436SShashi Mallela } 14781b08e436SShashi Mallela } 14791b08e436SShashi Mallela 148018f6290aSShashi Mallela static Property gicv3_its_props[] = { 148118f6290aSShashi Mallela DEFINE_PROP_LINK("parent-gicv3", GICv3ITSState, gicv3, "arm-gicv3", 148218f6290aSShashi Mallela GICv3State *), 148318f6290aSShashi Mallela DEFINE_PROP_END_OF_LIST(), 148418f6290aSShashi Mallela }; 148518f6290aSShashi Mallela 148618f6290aSShashi Mallela static void gicv3_its_class_init(ObjectClass *klass, void *data) 148718f6290aSShashi Mallela { 148818f6290aSShashi Mallela DeviceClass *dc = DEVICE_CLASS(klass); 148918f6290aSShashi Mallela GICv3ITSClass *ic = ARM_GICV3_ITS_CLASS(klass); 14901b08e436SShashi Mallela GICv3ITSCommonClass *icc = ARM_GICV3_ITS_COMMON_CLASS(klass); 149118f6290aSShashi Mallela 149218f6290aSShashi Mallela dc->realize = gicv3_arm_its_realize; 149318f6290aSShashi Mallela device_class_set_props(dc, gicv3_its_props); 149418f6290aSShashi Mallela device_class_set_parent_reset(dc, gicv3_its_reset, &ic->parent_reset); 14951b08e436SShashi Mallela icc->post_load = gicv3_its_post_load; 149618f6290aSShashi Mallela } 149718f6290aSShashi Mallela 149818f6290aSShashi Mallela static const TypeInfo gicv3_its_info = { 149918f6290aSShashi Mallela .name = TYPE_ARM_GICV3_ITS, 150018f6290aSShashi Mallela .parent = TYPE_ARM_GICV3_ITS_COMMON, 150118f6290aSShashi Mallela .instance_size = sizeof(GICv3ITSState), 150218f6290aSShashi Mallela .class_init = gicv3_its_class_init, 150318f6290aSShashi Mallela .class_size = sizeof(GICv3ITSClass), 150418f6290aSShashi Mallela }; 150518f6290aSShashi Mallela 150618f6290aSShashi Mallela static void gicv3_its_register_types(void) 150718f6290aSShashi Mallela { 150818f6290aSShashi Mallela type_register_static(&gicv3_its_info); 150918f6290aSShashi Mallela } 151018f6290aSShashi Mallela 151118f6290aSShashi Mallela type_init(gicv3_its_register_types) 1512