1 /* 2 * All ITS* defines are lifted from include/linux/irqchip/arm-gic-v3.h 3 * 4 * Copyright (C) 2020, Red Hat Inc, Eric Auger <eric.auger@redhat.com> 5 * 6 * This work is licensed under the terms of the GNU LGPL, version 2. 7 */ 8 #ifndef _ASMARM64_GIC_V3_ITS_H_ 9 #define _ASMARM64_GIC_V3_ITS_H_ 10 11 #ifndef _ASMARM_GIC_H_ 12 #error Do not directly include <asm/gic-v3-its.h>. Include <asm/gic.h> 13 #endif 14 15 struct its_typer { 16 unsigned int ite_size; 17 unsigned int eventid_bits; 18 unsigned int deviceid_bits; 19 unsigned int collid_bits; 20 bool pta; 21 bool phys_lpi; 22 bool virt_lpi; 23 }; 24 25 struct its_baser { 26 int index; 27 size_t psz; 28 int esz; 29 bool indirect; 30 void *table_addr; 31 }; 32 33 #define GITS_BASER_NR_REGS 8 34 #define GITS_MAX_DEVICES 8 35 #define GITS_MAX_COLLECTIONS 8 36 37 struct its_device { 38 u32 device_id; /* device ID */ 39 u32 nr_ites; /* Max Interrupt Translation Entries */ 40 void *itt; /* Interrupt Translation Table GVA */ 41 }; 42 43 struct its_collection { 44 u64 target_address; 45 u16 col_id; 46 }; 47 48 struct its_data { 49 void *base; 50 struct its_typer typer; 51 struct its_baser device_baser; 52 struct its_baser coll_baser; 53 struct its_cmd_block *cmd_base; 54 struct its_cmd_block *cmd_write; 55 struct its_device devices[GITS_MAX_DEVICES]; 56 u32 nr_devices; /* Allocated Devices */ 57 struct its_collection collections[GITS_MAX_COLLECTIONS]; 58 u16 nr_collections; /* Allocated Collections */ 59 }; 60 61 extern struct its_data its_data; 62 63 #define gicv3_its_base() (its_data.base) 64 65 #define GITS_CTLR 0x0000 66 #define GITS_IIDR 0x0004 67 #define GITS_TYPER 0x0008 68 #define GITS_CBASER 0x0080 69 #define GITS_CWRITER 0x0088 70 #define GITS_CREADR 0x0090 71 #define GITS_BASER 0x0100 72 73 #define GITS_TYPER_PLPIS BIT(0) 74 #define GITS_TYPER_VLPIS BIT(1) 75 #define GITS_TYPER_ITT_ENTRY_SIZE GENMASK_ULL(7, 4) 76 #define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4 77 #define GITS_TYPER_IDBITS GENMASK_ULL(12, 8) 78 #define GITS_TYPER_IDBITS_SHIFT 8 79 #define GITS_TYPER_DEVBITS GENMASK_ULL(17, 13) 80 #define GITS_TYPER_DEVBITS_SHIFT 13 81 #define GITS_TYPER_PTA BIT(19) 82 #define GITS_TYPER_CIDBITS GENMASK_ULL(35, 32) 83 #define GITS_TYPER_CIDBITS_SHIFT 32 84 #define GITS_TYPER_CIL BIT(36) 85 86 #define GITS_CTLR_ENABLE (1U << 0) 87 88 #define GITS_CBASER_VALID (1UL << 63) 89 90 #define GITS_BASER_VALID BIT(63) 91 #define GITS_BASER_INDIRECT BIT(62) 92 #define GITS_BASER_TYPE_SHIFT (56) 93 #define GITS_BASER_TYPE(r) (((r) >> GITS_BASER_TYPE_SHIFT) & 7) 94 #define GITS_BASER_ENTRY_SIZE_SHIFT (48) 95 #define GITS_BASER_ENTRY_SIZE(r) ((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1) 96 #define GITS_BASER_PAGE_SIZE_SHIFT (8) 97 #define GITS_BASER_PAGE_SIZE_4K (0UL << GITS_BASER_PAGE_SIZE_SHIFT) 98 #define GITS_BASER_PAGE_SIZE_16K (1UL << GITS_BASER_PAGE_SIZE_SHIFT) 99 #define GITS_BASER_PAGE_SIZE_64K (2UL << GITS_BASER_PAGE_SIZE_SHIFT) 100 #define GITS_BASER_PAGE_SIZE_MASK (3UL << GITS_BASER_PAGE_SIZE_SHIFT) 101 #define GITS_BASER_PAGES_MAX 256 102 #define GITS_BASER_PAGES_SHIFT (0) 103 #define GITS_BASER_NR_PAGES(r) (((r) & 0xff) + 1) 104 #define GITS_BASER_PHYS_ADDR_MASK 0xFFFFFFFFF000 105 #define GITS_BASER_TYPE_NONE 0 106 #define GITS_BASER_TYPE_DEVICE 1 107 #define GITS_BASER_TYPE_COLLECTION 4 108 109 /* 110 * ITS commands 111 */ 112 #define GITS_CMD_MAPD 0x08 113 #define GITS_CMD_MAPC 0x09 114 #define GITS_CMD_MAPTI 0x0a 115 #define GITS_CMD_MAPI 0x0b 116 #define GITS_CMD_MOVI 0x01 117 #define GITS_CMD_DISCARD 0x0f 118 #define GITS_CMD_INV 0x0c 119 #define GITS_CMD_MOVALL 0x0e 120 #define GITS_CMD_INVALL 0x0d 121 #define GITS_CMD_INT 0x03 122 #define GITS_CMD_CLEAR 0x04 123 #define GITS_CMD_SYNC 0x05 124 125 struct its_cmd_block { 126 u64 raw_cmd[4]; 127 }; 128 129 extern void its_parse_typer(void); 130 extern void its_init(void); 131 extern int its_baser_lookup(int i, struct its_baser *baser); 132 extern void its_enable_defaults(void); 133 extern struct its_device *its_create_device(u32 dev_id, int nr_ites); 134 extern struct its_collection *its_create_collection(u16 col_id, u32 target_pe); 135 136 extern void __its_send_mapd(struct its_device *dev, int valid, bool verbose); 137 extern void __its_send_mapc(struct its_collection *col, int valid, bool verbose); 138 extern void __its_send_mapti(struct its_device *dev, u32 irq_id, u32 event_id, 139 struct its_collection *col, bool verbose); 140 extern void __its_send_int(struct its_device *dev, u32 event_id, bool verbose); 141 extern void __its_send_inv(struct its_device *dev, u32 event_id, bool verbose); 142 extern void __its_send_discard(struct its_device *dev, u32 event_id, bool verbose); 143 extern void __its_send_clear(struct its_device *dev, u32 event_id, bool verbose); 144 extern void __its_send_invall(struct its_collection *col, bool verbose); 145 extern void __its_send_movi(struct its_device *dev, struct its_collection *col, 146 u32 id, bool verbose); 147 extern void __its_send_sync(struct its_collection *col, bool verbose); 148 149 #define its_send_mapd(dev, valid) __its_send_mapd(dev, valid, true) 150 #define its_send_mapc(col, valid) __its_send_mapc(col, valid, true) 151 #define its_send_mapti(dev, irqid, eventid, col) __its_send_mapti(dev, irqid, eventid, col, true) 152 #define its_send_int(dev, eventid) __its_send_int(dev, eventid, true) 153 #define its_send_inv(dev, eventid) __its_send_inv(dev, eventid, true) 154 #define its_send_discard(dev, eventid) __its_send_discard(dev, eventid, true) 155 #define its_send_clear(dev, eventid) __its_send_clear(dev, eventid, true) 156 #define its_send_invall(col) __its_send_invall(col, true) 157 #define its_send_movi(dev, col, id) __its_send_movi(dev, col, id, true) 158 #define its_send_sync(col) __its_send_sync(col, true) 159 160 #define its_send_mapd_nv(dev, valid) __its_send_mapd(dev, valid, false) 161 #define its_send_mapc_nv(col, valid) __its_send_mapc(col, valid, false) 162 #define its_send_mapti_nv(dev, irqid, eventid, col) __its_send_mapti(dev, irqid, eventid, col, false) 163 #define its_send_int_nv(dev, eventid) __its_send_int(dev, eventid, false) 164 #define its_send_inv_nv(dev, eventid) __its_send_inv(dev, eventid, false) 165 #define its_send_discard_nv(dev, eventid) __its_send_discard(dev, eventid, false) 166 #define its_send_clear_nv(dev, eventid) __its_send_clear(dev, eventidn false) 167 #define its_send_invall_nv(col) __its_send_invall(col, false) 168 #define its_send_movi_nv(dev, col, id) __its_send_movi(dev, col, id, false) 169 #define its_send_sync_nv(col) __its_send_sync(col, false) 170 171 extern struct its_device *its_get_device(u32 id); 172 extern struct its_collection *its_get_collection(u32 id); 173 174 #endif /* _ASMARM64_GIC_V3_ITS_H_ */ 175