Lines Matching full:its
3 * GICv3 ITS emulation
28 static int vgic_its_save_tables_v0(struct vgic_its *its);
29 static int vgic_its_restore_tables_v0(struct vgic_its *its);
30 static int vgic_its_commit_v0(struct vgic_its *its);
36 * If this LPI is already mapped on another ITS, we increase its refcount
153 * struct vgic_its_abi - ITS abi ops and settings
157 * @save_tables: save the ITS tables into guest RAM
158 * @restore_tables: restore the ITS internal structs from tables
167 int (*save_tables)(struct vgic_its *its);
168 int (*restore_tables)(struct vgic_its *its);
169 int (*commit)(struct vgic_its *its);
188 inline const struct vgic_its_abi *vgic_its_get_abi(struct vgic_its *its) in vgic_its_get_abi() argument
190 return &its_table_abi_versions[its->abi_rev]; in vgic_its_get_abi()
193 static int vgic_its_set_abi(struct vgic_its *its, u32 rev) in vgic_its_set_abi() argument
197 its->abi_rev = rev; in vgic_its_set_abi()
198 abi = vgic_its_get_abi(its); in vgic_its_set_abi()
199 return abi->commit(its); in vgic_its_set_abi()
203 * Find and returns a device in the device table for an ITS.
206 static struct its_device *find_its_device(struct vgic_its *its, u32 device_id) in find_its_device() argument
210 list_for_each_entry(device, &its->device_list, dev_list) in find_its_device()
219 * Device ID/Event ID pair on an ITS.
222 static struct its_ite *find_ite(struct vgic_its *its, u32 device_id, in find_ite() argument
228 device = find_its_device(its, device_id); in find_ite()
240 #define for_each_lpi_its(dev, ite, its) \ argument
241 list_for_each_entry(dev, &(its)->device_list, dev_list) \
254 * Finds and returns a collection in the ITS collection table.
257 static struct its_collection *find_collection(struct vgic_its *its, int coll_id) in find_collection() argument
261 list_for_each_entry(collection, &its->collection_list, coll_list) { in find_collection()
346 * Promotes the ITS view of affinity of an ITTE (which redistributor this LPI
366 static void update_affinity_collection(struct kvm *kvm, struct vgic_its *its, in update_affinity_collection() argument
372 for_each_lpi_its(device, ite, its) { in update_affinity_collection()
437 struct vgic_its *its, in vgic_mmio_read_its_typer() argument
440 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_mmio_read_its_typer()
459 struct vgic_its *its, in vgic_mmio_read_its_iidr() argument
464 val = (its->abi_rev << GITS_IIDR_REV_SHIFT) & GITS_IIDR_REV_MASK; in vgic_mmio_read_its_iidr()
470 struct vgic_its *its, in vgic_mmio_uaccess_write_its_iidr() argument
478 return vgic_its_set_abi(its, rev); in vgic_mmio_uaccess_write_its_iidr()
482 struct vgic_its *its, in vgic_mmio_read_its_idregs() argument
524 return iodev->its; in __vgic_doorbell_to_its()
537 struct vgic_its *its; in vgic_its_check_cache() local
543 its = __vgic_doorbell_to_its(kvm, db); in vgic_its_check_cache()
544 if (IS_ERR(its)) in vgic_its_check_cache()
549 irq = xa_load(&its->translation_cache, cache_key); in vgic_its_check_cache()
558 static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its, in vgic_its_cache_translation() argument
573 lockdep_assert_held(&its->its_lock); in vgic_its_cache_translation()
581 old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT); in vgic_its_cache_translation()
586 static void vgic_its_invalidate_cache(struct vgic_its *its) in vgic_its_invalidate_cache() argument
588 struct kvm *kvm = its->dev->kvm; in vgic_its_invalidate_cache()
592 xa_for_each(&its->translation_cache, idx, irq) { in vgic_its_invalidate_cache()
593 xa_erase(&its->translation_cache, idx); in vgic_its_invalidate_cache()
601 struct vgic_its *its; in vgic_its_invalidate_all_caches() local
609 its = dev->private; in vgic_its_invalidate_all_caches()
610 vgic_its_invalidate_cache(its); in vgic_its_invalidate_all_caches()
616 int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its, in vgic_its_resolve_lpi() argument
622 if (!its->enabled) in vgic_its_resolve_lpi()
625 ite = find_ite(its, devid, eventid); in vgic_its_resolve_lpi()
636 vgic_its_cache_translation(kvm, its, devid, eventid, ite->irq); in vgic_its_resolve_lpi()
661 * Returns 0 on success, a positive error value for any ITS mapping
664 static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, in vgic_its_trigger_msi() argument
671 err = vgic_its_resolve_lpi(kvm, its, devid, eventid, &irq); in vgic_its_trigger_msi()
706 * Queries the KVM IO bus framework to get the ITS pointer from the given
713 struct vgic_its *its; in vgic_its_inject_msi() local
719 its = vgic_msi_to_its(kvm, msi); in vgic_its_inject_msi()
720 if (IS_ERR(its)) in vgic_its_inject_msi()
721 return PTR_ERR(its); in vgic_its_inject_msi()
723 mutex_lock(&its->its_lock); in vgic_its_inject_msi()
724 ret = vgic_its_trigger_msi(kvm, its, msi->devid, msi->data); in vgic_its_inject_msi()
725 mutex_unlock(&its->its_lock); in vgic_its_inject_msi()
776 static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_discard() argument
783 ite = find_ite(its, device_id, event_id); in vgic_its_cmd_handle_discard()
790 vgic_its_invalidate_cache(its); in vgic_its_cmd_handle_discard()
803 static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_movi() argument
813 ite = find_ite(its, device_id, event_id); in vgic_its_cmd_handle_movi()
820 collection = find_collection(its, coll_id); in vgic_its_cmd_handle_movi()
827 vgic_its_invalidate_cache(its); in vgic_its_cmd_handle_movi()
832 static bool __is_visible_gfn_locked(struct vgic_its *its, gpa_t gpa) in __is_visible_gfn_locked() argument
838 idx = srcu_read_lock(&its->dev->kvm->srcu); in __is_visible_gfn_locked()
839 ret = kvm_is_visible_gfn(its->dev->kvm, gfn); in __is_visible_gfn_locked()
840 srcu_read_unlock(&its->dev->kvm->srcu, idx); in __is_visible_gfn_locked()
851 static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, in vgic_its_check_id() argument
866 /* as GITS_TYPER.CIL == 0, ITS supports 16-bit collection ID */ in vgic_its_check_id()
885 return __is_visible_gfn_locked(its, addr); in vgic_its_check_id()
894 if (kvm_read_guest_lock(its->dev->kvm, in vgic_its_check_id()
915 return __is_visible_gfn_locked(its, indirect_ptr); in vgic_its_check_id()
922 static bool vgic_its_check_event_id(struct vgic_its *its, struct its_device *device, in vgic_its_check_event_id() argument
925 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_check_event_id()
934 return __is_visible_gfn_locked(its, gpa); in vgic_its_check_event_id()
938 * Add a new collection into the ITS collection table.
941 static int vgic_its_alloc_collection(struct vgic_its *its, in vgic_its_alloc_collection() argument
954 list_add_tail(&collection->coll_list, &its->collection_list); in vgic_its_alloc_collection()
960 static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) in vgic_its_free_collection() argument
971 collection = find_collection(its, coll_id); in vgic_its_free_collection()
975 for_each_lpi_its(device, ite, its) in vgic_its_free_collection()
1006 static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_mapi() argument
1019 device = find_its_device(its, device_id); in vgic_its_cmd_handle_mapi()
1023 if (!vgic_its_check_event_id(its, device, event_id)) in vgic_its_cmd_handle_mapi()
1035 if (find_ite(its, device_id, event_id)) in vgic_its_cmd_handle_mapi()
1038 collection = find_collection(its, coll_id); in vgic_its_cmd_handle_mapi()
1042 if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL)) in vgic_its_cmd_handle_mapi()
1045 ret = vgic_its_alloc_collection(its, &collection, coll_id); in vgic_its_cmd_handle_mapi()
1054 vgic_its_free_collection(its, coll_id); in vgic_its_cmd_handle_mapi()
1064 vgic_its_free_collection(its, coll_id); in vgic_its_cmd_handle_mapi()
1074 static void vgic_its_free_device(struct kvm *kvm, struct vgic_its *its, in vgic_its_free_device() argument
1087 vgic_its_invalidate_cache(its); in vgic_its_free_device()
1093 /* its lock must be held */
1094 static void vgic_its_free_device_list(struct kvm *kvm, struct vgic_its *its) in vgic_its_free_device_list() argument
1098 list_for_each_entry_safe(cur, temp, &its->device_list, dev_list) in vgic_its_free_device_list()
1099 vgic_its_free_device(kvm, its, cur); in vgic_its_free_device_list()
1102 /* its lock must be held */
1103 static void vgic_its_free_collection_list(struct kvm *kvm, struct vgic_its *its) in vgic_its_free_collection_list() argument
1107 list_for_each_entry_safe(cur, temp, &its->collection_list, coll_list) in vgic_its_free_collection_list()
1108 vgic_its_free_collection(its, cur->collection_id); in vgic_its_free_collection_list()
1112 static struct its_device *vgic_its_alloc_device(struct vgic_its *its, in vgic_its_alloc_device() argument
1127 list_add_tail(&device->dev_list, &its->device_list); in vgic_its_alloc_device()
1135 static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_mapd() argument
1144 if (!vgic_its_check_id(its, its->baser_device_table, device_id, NULL)) in vgic_its_cmd_handle_mapd()
1150 device = find_its_device(its, device_id); in vgic_its_cmd_handle_mapd()
1158 vgic_its_free_device(kvm, its, device); in vgic_its_cmd_handle_mapd()
1167 device = vgic_its_alloc_device(its, device_id, itt_addr, in vgic_its_cmd_handle_mapd()
1177 static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_mapc() argument
1188 vgic_its_free_collection(its, coll_id); in vgic_its_cmd_handle_mapc()
1189 vgic_its_invalidate_cache(its); in vgic_its_cmd_handle_mapc()
1197 collection = find_collection(its, coll_id); in vgic_its_cmd_handle_mapc()
1202 if (!vgic_its_check_id(its, its->baser_coll_table, in vgic_its_cmd_handle_mapc()
1206 ret = vgic_its_alloc_collection(its, &collection, in vgic_its_cmd_handle_mapc()
1213 update_affinity_collection(kvm, its, collection); in vgic_its_cmd_handle_mapc()
1224 static int vgic_its_cmd_handle_clear(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_clear() argument
1232 ite = find_ite(its, device_id, event_id); in vgic_its_cmd_handle_clear()
1254 static int vgic_its_cmd_handle_inv(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_inv() argument
1262 ite = find_ite(its, device_id, event_id); in vgic_its_cmd_handle_inv()
1274 * collection, and we don't need to hold the its_lock, since no ITS is
1307 static int vgic_its_cmd_handle_invall(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_invall() argument
1314 collection = find_collection(its, coll_id); in vgic_its_cmd_handle_invall()
1332 static int vgic_its_cmd_handle_movall(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_movall() argument
1360 vgic_its_invalidate_cache(its); in vgic_its_cmd_handle_movall()
1369 static int vgic_its_cmd_handle_int(struct kvm *kvm, struct vgic_its *its, in vgic_its_cmd_handle_int() argument
1375 return vgic_its_trigger_msi(kvm, its, msi_devid, msi_data); in vgic_its_cmd_handle_int()
1379 * This function is called with the its_cmd lock held, but the ITS data
1382 static int vgic_its_handle_command(struct kvm *kvm, struct vgic_its *its, in vgic_its_handle_command() argument
1387 mutex_lock(&its->its_lock); in vgic_its_handle_command()
1390 ret = vgic_its_cmd_handle_mapd(kvm, its, its_cmd); in vgic_its_handle_command()
1393 ret = vgic_its_cmd_handle_mapc(kvm, its, its_cmd); in vgic_its_handle_command()
1396 ret = vgic_its_cmd_handle_mapi(kvm, its, its_cmd); in vgic_its_handle_command()
1399 ret = vgic_its_cmd_handle_mapi(kvm, its, its_cmd); in vgic_its_handle_command()
1402 ret = vgic_its_cmd_handle_movi(kvm, its, its_cmd); in vgic_its_handle_command()
1405 ret = vgic_its_cmd_handle_discard(kvm, its, its_cmd); in vgic_its_handle_command()
1408 ret = vgic_its_cmd_handle_clear(kvm, its, its_cmd); in vgic_its_handle_command()
1411 ret = vgic_its_cmd_handle_movall(kvm, its, its_cmd); in vgic_its_handle_command()
1414 ret = vgic_its_cmd_handle_int(kvm, its, its_cmd); in vgic_its_handle_command()
1417 ret = vgic_its_cmd_handle_inv(kvm, its, its_cmd); in vgic_its_handle_command()
1420 ret = vgic_its_cmd_handle_invall(kvm, its, its_cmd); in vgic_its_handle_command()
1427 mutex_unlock(&its->its_lock); in vgic_its_handle_command()
1444 /* We support only one (ITS) page size: 64K */ in vgic_sanitise_its_baser()
1469 struct vgic_its *its, in vgic_mmio_read_its_cbaser() argument
1472 return extract_bytes(its->cbaser, addr & 7, len); in vgic_mmio_read_its_cbaser()
1475 static void vgic_mmio_write_its_cbaser(struct kvm *kvm, struct vgic_its *its, in vgic_mmio_write_its_cbaser() argument
1480 if (its->enabled) in vgic_mmio_write_its_cbaser()
1483 mutex_lock(&its->cmd_lock); in vgic_mmio_write_its_cbaser()
1484 its->cbaser = update_64bit_reg(its->cbaser, addr & 7, len, val); in vgic_mmio_write_its_cbaser()
1485 its->cbaser = vgic_sanitise_its_cbaser(its->cbaser); in vgic_mmio_write_its_cbaser()
1486 its->creadr = 0; in vgic_mmio_write_its_cbaser()
1491 its->cwriter = its->creadr; in vgic_mmio_write_its_cbaser()
1492 mutex_unlock(&its->cmd_lock); in vgic_mmio_write_its_cbaser()
1500 static void vgic_its_process_commands(struct kvm *kvm, struct vgic_its *its) in vgic_its_process_commands() argument
1505 /* Commands are only processed when the ITS is enabled. */ in vgic_its_process_commands()
1506 if (!its->enabled) in vgic_its_process_commands()
1509 cbaser = GITS_CBASER_ADDRESS(its->cbaser); in vgic_its_process_commands()
1511 while (its->cwriter != its->creadr) { in vgic_its_process_commands()
1512 int ret = kvm_read_guest_lock(kvm, cbaser + its->creadr, in vgic_its_process_commands()
1522 vgic_its_handle_command(kvm, its, cmd_buf); in vgic_its_process_commands()
1524 its->creadr += ITS_CMD_SIZE; in vgic_its_process_commands()
1525 if (its->creadr == ITS_CMD_BUFFER_SIZE(its->cbaser)) in vgic_its_process_commands()
1526 its->creadr = 0; in vgic_its_process_commands()
1534 * per ITS handling commands at a given time.
1536 static void vgic_mmio_write_its_cwriter(struct kvm *kvm, struct vgic_its *its, in vgic_mmio_write_its_cwriter() argument
1542 if (!its) in vgic_mmio_write_its_cwriter()
1545 mutex_lock(&its->cmd_lock); in vgic_mmio_write_its_cwriter()
1547 reg = update_64bit_reg(its->cwriter, addr & 7, len, val); in vgic_mmio_write_its_cwriter()
1549 if (reg >= ITS_CMD_BUFFER_SIZE(its->cbaser)) { in vgic_mmio_write_its_cwriter()
1550 mutex_unlock(&its->cmd_lock); in vgic_mmio_write_its_cwriter()
1553 its->cwriter = reg; in vgic_mmio_write_its_cwriter()
1555 vgic_its_process_commands(kvm, its); in vgic_mmio_write_its_cwriter()
1557 mutex_unlock(&its->cmd_lock); in vgic_mmio_write_its_cwriter()
1561 struct vgic_its *its, in vgic_mmio_read_its_cwriter() argument
1564 return extract_bytes(its->cwriter, addr & 0x7, len); in vgic_mmio_read_its_cwriter()
1568 struct vgic_its *its, in vgic_mmio_read_its_creadr() argument
1571 return extract_bytes(its->creadr, addr & 0x7, len); in vgic_mmio_read_its_creadr()
1575 struct vgic_its *its, in vgic_mmio_uaccess_write_its_creadr() argument
1582 mutex_lock(&its->cmd_lock); in vgic_mmio_uaccess_write_its_creadr()
1584 if (its->enabled) { in vgic_mmio_uaccess_write_its_creadr()
1590 if (cmd_offset >= ITS_CMD_BUFFER_SIZE(its->cbaser)) { in vgic_mmio_uaccess_write_its_creadr()
1595 its->creadr = cmd_offset; in vgic_mmio_uaccess_write_its_creadr()
1597 mutex_unlock(&its->cmd_lock); in vgic_mmio_uaccess_write_its_creadr()
1603 struct vgic_its *its, in vgic_mmio_read_its_baser() argument
1610 reg = its->baser_device_table; in vgic_mmio_read_its_baser()
1613 reg = its->baser_coll_table; in vgic_mmio_read_its_baser()
1625 struct vgic_its *its, in vgic_mmio_write_its_baser() argument
1629 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_mmio_write_its_baser()
1634 if (its->enabled) in vgic_mmio_write_its_baser()
1639 regptr = &its->baser_device_table; in vgic_mmio_write_its_baser()
1644 regptr = &its->baser_coll_table; in vgic_mmio_write_its_baser()
1665 mutex_lock(&its->its_lock); in vgic_mmio_write_its_baser()
1668 vgic_its_free_device_list(kvm, its); in vgic_mmio_write_its_baser()
1671 vgic_its_free_collection_list(kvm, its); in vgic_mmio_write_its_baser()
1674 mutex_unlock(&its->its_lock); in vgic_mmio_write_its_baser()
1679 struct vgic_its *its, in vgic_mmio_read_its_ctlr() argument
1684 mutex_lock(&its->cmd_lock); in vgic_mmio_read_its_ctlr()
1685 if (its->creadr == its->cwriter) in vgic_mmio_read_its_ctlr()
1687 if (its->enabled) in vgic_mmio_read_its_ctlr()
1689 mutex_unlock(&its->cmd_lock); in vgic_mmio_read_its_ctlr()
1694 static void vgic_mmio_write_its_ctlr(struct kvm *kvm, struct vgic_its *its, in vgic_mmio_write_its_ctlr() argument
1698 mutex_lock(&its->cmd_lock); in vgic_mmio_write_its_ctlr()
1701 * It is UNPREDICTABLE to enable the ITS if any of the CBASER or in vgic_mmio_write_its_ctlr()
1704 if (!its->enabled && (val & GITS_CTLR_ENABLE) && in vgic_mmio_write_its_ctlr()
1705 (!(its->baser_device_table & GITS_BASER_VALID) || in vgic_mmio_write_its_ctlr()
1706 !(its->baser_coll_table & GITS_BASER_VALID) || in vgic_mmio_write_its_ctlr()
1707 !(its->cbaser & GITS_CBASER_VALID))) in vgic_mmio_write_its_ctlr()
1710 its->enabled = !!(val & GITS_CTLR_ENABLE); in vgic_mmio_write_its_ctlr()
1711 if (!its->enabled) in vgic_mmio_write_its_ctlr()
1712 vgic_its_invalidate_cache(its); in vgic_mmio_write_its_ctlr()
1716 * if the ITS is disabled or no commands have been queued. in vgic_mmio_write_its_ctlr()
1718 vgic_its_process_commands(kvm, its); in vgic_mmio_write_its_ctlr()
1721 mutex_unlock(&its->cmd_lock); in vgic_mmio_write_its_ctlr()
1743 static void its_mmio_write_wi(struct kvm *kvm, struct vgic_its *its, in its_mmio_write_wi() argument
1785 static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its, in vgic_register_its_iodev() argument
1788 struct vgic_io_device *iodev = &its->iodev; in vgic_register_its_iodev()
1792 if (!IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) { in vgic_register_its_iodev()
1797 its->vgic_its_base = addr; in vgic_register_its_iodev()
1802 iodev->base_addr = its->vgic_its_base; in vgic_register_its_iodev()
1804 iodev->its = its; in vgic_register_its_iodev()
1827 struct vgic_its *its; in vgic_its_create() local
1832 its = kzalloc(sizeof(struct vgic_its), GFP_KERNEL_ACCOUNT); in vgic_its_create()
1833 if (!its) in vgic_its_create()
1842 kfree(its); in vgic_its_create()
1847 mutex_init(&its->its_lock); in vgic_its_create()
1848 mutex_init(&its->cmd_lock); in vgic_its_create()
1852 mutex_lock(&its->cmd_lock); in vgic_its_create()
1853 mutex_lock(&its->its_lock); in vgic_its_create()
1854 mutex_unlock(&its->its_lock); in vgic_its_create()
1855 mutex_unlock(&its->cmd_lock); in vgic_its_create()
1858 its->vgic_its_base = VGIC_ADDR_UNDEF; in vgic_its_create()
1860 INIT_LIST_HEAD(&its->device_list); in vgic_its_create()
1861 INIT_LIST_HEAD(&its->collection_list); in vgic_its_create()
1862 xa_init(&its->translation_cache); in vgic_its_create()
1866 its->enabled = false; in vgic_its_create()
1867 its->dev = dev; in vgic_its_create()
1869 its->baser_device_table = INITIAL_BASER_VALUE | in vgic_its_create()
1871 its->baser_coll_table = INITIAL_BASER_VALUE | in vgic_its_create()
1875 dev->private = its; in vgic_its_create()
1877 ret = vgic_its_set_abi(its, NR_ITS_ABIS - 1); in vgic_its_create()
1887 struct vgic_its *its = kvm_dev->private; in vgic_its_destroy() local
1889 mutex_lock(&its->its_lock); in vgic_its_destroy()
1891 vgic_its_free_device_list(kvm, its); in vgic_its_destroy()
1892 vgic_its_free_collection_list(kvm, its); in vgic_its_destroy()
1893 vgic_its_invalidate_cache(its); in vgic_its_destroy()
1894 xa_destroy(&its->translation_cache); in vgic_its_destroy()
1896 mutex_unlock(&its->its_lock); in vgic_its_destroy()
1897 kfree(its); in vgic_its_destroy()
1927 struct vgic_its *its; in vgic_its_attr_regs_access() local
1932 its = dev->private; in vgic_its_attr_regs_access()
1937 * 64-bit ITS registers, the userspace ABI requires 64-bit in vgic_its_attr_regs_access()
1959 if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) { in vgic_its_attr_regs_access()
1972 addr = its->vgic_its_base + offset; in vgic_its_attr_regs_access()
1978 ret = region->uaccess_its_write(dev->kvm, its, addr, in vgic_its_attr_regs_access()
1981 region->its_write(dev->kvm, its, addr, len, *reg); in vgic_its_attr_regs_access()
1983 *reg = region->its_read(dev->kvm, its, addr, len); in vgic_its_attr_regs_access()
2021 * @its: its handle
2029 typedef int (*entry_fn_t)(struct vgic_its *its, u32 id, void *entry,
2036 * @its: its handle
2048 static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, in scan_its_table() argument
2051 struct kvm *kvm = its->dev->kvm; in scan_its_table()
2068 next_offset = fn(its, id, entry, opaque); in scan_its_table()
2086 static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, in vgic_its_save_ite() argument
2089 struct kvm *kvm = its->dev->kvm; in vgic_its_save_ite()
2104 * @its: its handle
2109 static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, in vgic_its_restore_ite() argument
2114 struct kvm *kvm = its->dev->kvm; in vgic_its_restore_ite()
2140 collection = find_collection(its, coll_id); in vgic_its_restore_ite()
2144 if (!vgic_its_check_event_id(its, dev, event_id)) in vgic_its_restore_ite()
2176 static int vgic_its_save_itt(struct vgic_its *its, struct its_device *device) in vgic_its_save_itt() argument
2178 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_save_itt()
2198 ret = vgic_its_save_ite(its, device, ite, gpa, ite_esz); in vgic_its_save_itt()
2208 * @its: its handle
2213 static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev) in vgic_its_restore_itt() argument
2215 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_restore_itt()
2221 ret = scan_its_table(its, base, max_size, ite_esz, 0, in vgic_its_restore_itt()
2234 * @its: ITS handle
2235 * @dev: ITS device
2239 static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, in vgic_its_save_dte() argument
2242 struct kvm *kvm = its->dev->kvm; in vgic_its_save_dte()
2247 next_offset = compute_next_devid_offset(&its->device_list, dev); in vgic_its_save_dte()
2259 * @its: its handle
2267 static int vgic_its_restore_dte(struct vgic_its *its, u32 id, in vgic_its_restore_dte() argument
2271 u64 baser = its->baser_device_table; in vgic_its_restore_dte()
2292 if (!vgic_its_check_id(its, baser, id, NULL)) in vgic_its_restore_dte()
2295 dev = vgic_its_alloc_device(its, id, itt_addr, num_eventid_bits); in vgic_its_restore_dte()
2299 ret = vgic_its_restore_itt(its, dev); in vgic_its_restore_dte()
2301 vgic_its_free_device(its->dev->kvm, its, dev); in vgic_its_restore_dte()
2327 static int vgic_its_save_device_tables(struct vgic_its *its) in vgic_its_save_device_tables() argument
2329 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_save_device_tables()
2330 u64 baser = its->baser_device_table; in vgic_its_save_device_tables()
2337 list_sort(NULL, &its->device_list, vgic_its_device_cmp); in vgic_its_save_device_tables()
2339 list_for_each_entry(dev, &its->device_list, dev_list) { in vgic_its_save_device_tables()
2343 if (!vgic_its_check_id(its, baser, in vgic_its_save_device_tables()
2347 ret = vgic_its_save_itt(its, dev); in vgic_its_save_device_tables()
2351 ret = vgic_its_save_dte(its, dev, eaddr, dte_esz); in vgic_its_save_device_tables()
2361 * @its: its handle
2370 static int handle_l1_dte(struct vgic_its *its, u32 id, void *addr, in handle_l1_dte() argument
2373 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in handle_l1_dte()
2387 ret = scan_its_table(its, gpa, SZ_64K, dte_esz, in handle_l1_dte()
2397 static int vgic_its_restore_device_tables(struct vgic_its *its) in vgic_its_restore_device_tables() argument
2399 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_restore_device_tables()
2400 u64 baser = its->baser_device_table; in vgic_its_restore_device_tables()
2412 ret = scan_its_table(its, l1_gpa, l1_tbl_size, l1_esz, 0, in vgic_its_restore_device_tables()
2416 ret = scan_its_table(its, l1_gpa, l1_tbl_size, l1_esz, 0, in vgic_its_restore_device_tables()
2425 vgic_its_free_device_list(its->dev->kvm, its); in vgic_its_restore_device_tables()
2430 static int vgic_its_save_cte(struct vgic_its *its, in vgic_its_save_cte() argument
2440 return vgic_write_guest_lock(its->dev->kvm, gpa, &val, esz); in vgic_its_save_cte()
2444 * Restore a collection entry into the ITS collection table.
2448 static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz) in vgic_its_restore_cte() argument
2451 struct kvm *kvm = its->dev->kvm; in vgic_its_restore_cte()
2471 collection = find_collection(its, coll_id); in vgic_its_restore_cte()
2475 if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL)) in vgic_its_restore_cte()
2478 ret = vgic_its_alloc_collection(its, &collection, coll_id); in vgic_its_restore_cte()
2489 static int vgic_its_save_collection_table(struct vgic_its *its) in vgic_its_save_collection_table() argument
2491 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_save_collection_table()
2492 u64 baser = its->baser_coll_table; in vgic_its_save_collection_table()
2504 list_for_each_entry(collection, &its->collection_list, coll_list) { in vgic_its_save_collection_table()
2505 ret = vgic_its_save_cte(its, collection, gpa, cte_esz); in vgic_its_save_collection_table()
2521 ret = vgic_write_guest_lock(its->dev->kvm, gpa, &val, cte_esz); in vgic_its_save_collection_table()
2527 * in guest memory and restores the ITS internal state. Requires the
2530 static int vgic_its_restore_collection_table(struct vgic_its *its) in vgic_its_restore_collection_table() argument
2532 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_restore_collection_table()
2533 u64 baser = its->baser_coll_table; in vgic_its_restore_collection_table()
2547 ret = vgic_its_restore_cte(its, gpa, cte_esz); in vgic_its_restore_collection_table()
2558 vgic_its_free_collection_list(its->dev->kvm, its); in vgic_its_restore_collection_table()
2564 * vgic_its_save_tables_v0 - Save the ITS tables into guest ARM
2567 static int vgic_its_save_tables_v0(struct vgic_its *its) in vgic_its_save_tables_v0() argument
2571 ret = vgic_its_save_device_tables(its); in vgic_its_save_tables_v0()
2575 return vgic_its_save_collection_table(its); in vgic_its_save_tables_v0()
2579 * vgic_its_restore_tables_v0 - Restore the ITS tables from guest RAM
2583 static int vgic_its_restore_tables_v0(struct vgic_its *its) in vgic_its_restore_tables_v0() argument
2587 ret = vgic_its_restore_collection_table(its); in vgic_its_restore_tables_v0()
2591 ret = vgic_its_restore_device_tables(its); in vgic_its_restore_tables_v0()
2593 vgic_its_free_collection_list(its->dev->kvm, its); in vgic_its_restore_tables_v0()
2597 static int vgic_its_commit_v0(struct vgic_its *its) in vgic_its_commit_v0() argument
2601 abi = vgic_its_get_abi(its); in vgic_its_commit_v0()
2602 its->baser_coll_table &= ~GITS_BASER_ENTRY_SIZE_MASK; in vgic_its_commit_v0()
2603 its->baser_device_table &= ~GITS_BASER_ENTRY_SIZE_MASK; in vgic_its_commit_v0()
2605 its->baser_coll_table |= (GIC_ENCODE_SZ(abi->cte_esz, 5) in vgic_its_commit_v0()
2608 its->baser_device_table |= (GIC_ENCODE_SZ(abi->dte_esz, 5) in vgic_its_commit_v0()
2613 static void vgic_its_reset(struct kvm *kvm, struct vgic_its *its) in vgic_its_reset() argument
2616 its->baser_coll_table &= ~GITS_BASER_VALID; in vgic_its_reset()
2617 its->baser_device_table &= ~GITS_BASER_VALID; in vgic_its_reset()
2618 its->cbaser = 0; in vgic_its_reset()
2619 its->creadr = 0; in vgic_its_reset()
2620 its->cwriter = 0; in vgic_its_reset()
2621 its->enabled = 0; in vgic_its_reset()
2622 vgic_its_free_device_list(kvm, its); in vgic_its_reset()
2623 vgic_its_free_collection_list(kvm, its); in vgic_its_reset()
2654 static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr) in vgic_its_ctrl() argument
2656 const struct vgic_its_abi *abi = vgic_its_get_abi(its); in vgic_its_ctrl()
2670 mutex_lock(&its->its_lock); in vgic_its_ctrl()
2674 vgic_its_reset(kvm, its); in vgic_its_ctrl()
2677 ret = abi->save_tables(its); in vgic_its_ctrl()
2680 ret = abi->restore_tables(its); in vgic_its_ctrl()
2684 mutex_unlock(&its->its_lock); in vgic_its_ctrl()
2697 * dirty guest pages. When vgic/its tables are being saved, the backup
2711 struct vgic_its *its = dev->private; in vgic_its_set_attr() local
2726 ret = vgic_check_iorange(dev->kvm, its->vgic_its_base, in vgic_its_set_attr()
2731 return vgic_register_its_iodev(dev->kvm, its, addr); in vgic_its_set_attr()
2734 return vgic_its_ctrl(dev->kvm, its, attr->attr); in vgic_its_set_attr()
2753 struct vgic_its *its = dev->private; in vgic_its_get_attr() local
2754 u64 addr = its->vgic_its_base; in vgic_its_get_attr()
2783 .name = "kvm-arm-vgic-its",