KVM
Classes | Macros | Typedefs | Functions | Variables
vgic-its.c File Reference
#include <linux/cpu.h>
#include <linux/kvm.h>
#include <linux/kvm_host.h>
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/uaccess.h>
#include <linux/list_sort.h>
#include <linux/irqchip/arm-gic-v3.h>
#include <asm/kvm_emulate.h>
#include <asm/kvm_arm.h>
#include <asm/kvm_mmu.h>
#include "vgic.h"
#include "vgic-mmio.h"
Include dependency graph for vgic-its.c:

Go to the source code of this file.

Classes

struct  its_device
 
struct  its_collection
 
struct  its_ite
 
struct  vgic_translation_cache_entry
 
struct  vgic_its_abi
 

Macros

#define COLLECTION_NOT_MAPPED   ((u32)~0)
 
#define its_is_collection_mapped(coll)
 
#define ABI_0_ESZ   8
 
#define ESZ_MAX   ABI_0_ESZ
 
#define NR_ITS_ABIS   ARRAY_SIZE(its_table_abi_versions)
 
#define for_each_lpi_its(dev, ite, its)
 
#define GIC_LPI_OFFSET   8192
 
#define VITS_TYPER_IDBITS   16
 
#define VITS_TYPER_DEVBITS   16
 
#define VITS_DTE_MAX_DEVID_OFFSET   (BIT(14) - 1)
 
#define VITS_ITE_MAX_EVENTID_OFFSET   (BIT(16) - 1)
 
#define LPI_PROP_ENABLE_BIT(p)   ((p) & LPI_PROP_ENABLED)
 
#define LPI_PROP_PRIORITY(p)   ((p) & 0xfc)
 
#define its_cmd_get_command(cmd)   its_cmd_mask_field(cmd, 0, 0, 8)
 
#define its_cmd_get_deviceid(cmd)   its_cmd_mask_field(cmd, 0, 32, 32)
 
#define its_cmd_get_size(cmd)   (its_cmd_mask_field(cmd, 1, 0, 5) + 1)
 
#define its_cmd_get_id(cmd)   its_cmd_mask_field(cmd, 1, 0, 32)
 
#define its_cmd_get_physical_id(cmd)   its_cmd_mask_field(cmd, 1, 32, 32)
 
#define its_cmd_get_collection(cmd)   its_cmd_mask_field(cmd, 2, 0, 16)
 
#define its_cmd_get_ittaddr(cmd)   (its_cmd_mask_field(cmd, 2, 8, 44) << 8)
 
#define its_cmd_get_target_addr(cmd)   its_cmd_mask_field(cmd, 2, 16, 32)
 
#define its_cmd_get_validbit(cmd)   its_cmd_mask_field(cmd, 2, 63, 1)
 
#define ITS_CMD_BUFFER_SIZE(baser)   ((((baser) & 0xff) + 1) << 12)
 
#define ITS_CMD_SIZE   32
 
#define ITS_CMD_OFFSET(reg)   ((reg) & GENMASK(19, 5))
 
#define BASER_INDEX(addr)   (((addr) / sizeof(u64)) & 0x7)
 
#define GITS_BASER_RO_MASK   (GENMASK_ULL(52, 48) | GENMASK_ULL(58, 56))
 
#define REGISTER_ITS_DESC(off, rd, wr, length, acc)
 
#define REGISTER_ITS_DESC_UACCESS(off, rd, wr, uwr, length, acc)
 
#define LPI_DEFAULT_PCPU_CACHE_SIZE   16
 
#define INITIAL_BASER_VALUE
 
#define INITIAL_PROPBASER_VALUE
 

Typedefs

typedef int(* entry_fn_t) (struct vgic_its *its, u32 id, void *entry, void *opaque)
 

Functions

static int vgic_its_save_tables_v0 (struct vgic_its *its)
 
static int vgic_its_restore_tables_v0 (struct vgic_its *its)
 
static int vgic_its_commit_v0 (struct vgic_its *its)
 
static int update_lpi_config (struct kvm *kvm, struct vgic_irq *irq, struct kvm_vcpu *filter_vcpu, bool needs_inv)
 
static struct vgic_irqvgic_add_lpi (struct kvm *kvm, u32 intid, struct kvm_vcpu *vcpu)
 
const struct vgic_its_abivgic_its_get_abi (struct vgic_its *its)
 
static int vgic_its_set_abi (struct vgic_its *its, u32 rev)
 
static struct its_devicefind_its_device (struct vgic_its *its, u32 device_id)
 
static struct its_itefind_ite (struct vgic_its *its, u32 device_id, u32 event_id)
 
static struct its_collectionfind_collection (struct vgic_its *its, int coll_id)
 
int vgic_copy_lpi_list (struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr)
 
static int update_affinity (struct vgic_irq *irq, struct kvm_vcpu *vcpu)
 
static struct kvm_vcpu * collection_to_vcpu (struct kvm *kvm, struct its_collection *col)
 
static void update_affinity_ite (struct kvm *kvm, struct its_ite *ite)
 
static void update_affinity_collection (struct kvm *kvm, struct vgic_its *its, struct its_collection *coll)
 
static u32 max_lpis_propbaser (u64 propbaser)
 
static int its_sync_lpi_pending_table (struct kvm_vcpu *vcpu)
 
static unsigned long vgic_mmio_read_its_typer (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static unsigned long vgic_mmio_read_its_iidr (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static int vgic_mmio_uaccess_write_its_iidr (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_its_idregs (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static struct vgic_irq__vgic_its_check_cache (struct vgic_dist *dist, phys_addr_t db, u32 devid, u32 eventid)
 
static struct vgic_irqvgic_its_check_cache (struct kvm *kvm, phys_addr_t db, u32 devid, u32 eventid)
 
static void vgic_its_cache_translation (struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq *irq)
 
void vgic_its_invalidate_cache (struct kvm *kvm)
 
int vgic_its_resolve_lpi (struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq **irq)
 
struct vgic_itsvgic_msi_to_its (struct kvm *kvm, struct kvm_msi *msi)
 
static int vgic_its_trigger_msi (struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid)
 
int vgic_its_inject_cached_translation (struct kvm *kvm, struct kvm_msi *msi)
 
int vgic_its_inject_msi (struct kvm *kvm, struct kvm_msi *msi)
 
static void its_free_ite (struct kvm *kvm, struct its_ite *ite)
 
static u64 its_cmd_mask_field (u64 *its_cmd, int word, int shift, int size)
 
static int vgic_its_cmd_handle_discard (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_cmd_handle_movi (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static bool __is_visible_gfn_locked (struct vgic_its *its, gpa_t gpa)
 
static bool vgic_its_check_id (struct vgic_its *its, u64 baser, u32 id, gpa_t *eaddr)
 
static bool vgic_its_check_event_id (struct vgic_its *its, struct its_device *device, u32 event_id)
 
static int vgic_its_alloc_collection (struct vgic_its *its, struct its_collection **colp, u32 coll_id)
 
static void vgic_its_free_collection (struct vgic_its *its, u32 coll_id)
 
static struct its_itevgic_its_alloc_ite (struct its_device *device, struct its_collection *collection, u32 event_id)
 
static int vgic_its_cmd_handle_mapi (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static void vgic_its_free_device (struct kvm *kvm, struct its_device *device)
 
static void vgic_its_free_device_list (struct kvm *kvm, struct vgic_its *its)
 
static void vgic_its_free_collection_list (struct kvm *kvm, struct vgic_its *its)
 
static struct its_devicevgic_its_alloc_device (struct vgic_its *its, u32 device_id, gpa_t itt_addr, u8 num_eventid_bits)
 
static int vgic_its_cmd_handle_mapd (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_cmd_handle_mapc (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_cmd_handle_clear (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
int vgic_its_inv_lpi (struct kvm *kvm, struct vgic_irq *irq)
 
static int vgic_its_cmd_handle_inv (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
int vgic_its_invall (struct kvm_vcpu *vcpu)
 
static int vgic_its_cmd_handle_invall (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_cmd_handle_movall (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_cmd_handle_int (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static int vgic_its_handle_command (struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
 
static u64 vgic_sanitise_its_baser (u64 reg)
 
static u64 vgic_sanitise_its_cbaser (u64 reg)
 
static unsigned long vgic_mmio_read_its_cbaser (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_its_cbaser (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static void vgic_its_process_commands (struct kvm *kvm, struct vgic_its *its)
 
static void vgic_mmio_write_its_cwriter (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_its_cwriter (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static unsigned long vgic_mmio_read_its_creadr (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static int vgic_mmio_uaccess_write_its_creadr (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_its_baser (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_its_baser (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_its_ctlr (struct kvm *vcpu, struct vgic_its *its, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_its_ctlr (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
static void its_mmio_write_wi (struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
 
void vgic_enable_lpis (struct kvm_vcpu *vcpu)
 
static int vgic_register_its_iodev (struct kvm *kvm, struct vgic_its *its, u64 addr)
 
void vgic_lpi_translation_cache_init (struct kvm *kvm)
 
void vgic_lpi_translation_cache_destroy (struct kvm *kvm)
 
static int vgic_its_create (struct kvm_device *dev, u32 type)
 
static void vgic_its_destroy (struct kvm_device *kvm_dev)
 
static int vgic_its_has_attr_regs (struct kvm_device *dev, struct kvm_device_attr *attr)
 
static int vgic_its_attr_regs_access (struct kvm_device *dev, struct kvm_device_attr *attr, u64 *reg, bool is_write)
 
static u32 compute_next_devid_offset (struct list_head *h, struct its_device *dev)
 
static u32 compute_next_eventid_offset (struct list_head *h, struct its_ite *ite)
 
static int scan_its_table (struct vgic_its *its, gpa_t base, int size, u32 esz, int start_id, entry_fn_t fn, void *opaque)
 
static int vgic_its_save_ite (struct vgic_its *its, struct its_device *dev, struct its_ite *ite, gpa_t gpa, int ite_esz)
 
static int vgic_its_restore_ite (struct vgic_its *its, u32 event_id, void *ptr, void *opaque)
 
static int vgic_its_ite_cmp (void *priv, const struct list_head *a, const struct list_head *b)
 
static int vgic_its_save_itt (struct vgic_its *its, struct its_device *device)
 
static int vgic_its_restore_itt (struct vgic_its *its, struct its_device *dev)
 
static int vgic_its_save_dte (struct vgic_its *its, struct its_device *dev, gpa_t ptr, int dte_esz)
 
static int vgic_its_restore_dte (struct vgic_its *its, u32 id, void *ptr, void *opaque)
 
static int vgic_its_device_cmp (void *priv, const struct list_head *a, const struct list_head *b)
 
static int vgic_its_save_device_tables (struct vgic_its *its)
 
static int handle_l1_dte (struct vgic_its *its, u32 id, void *addr, void *opaque)
 
static int vgic_its_restore_device_tables (struct vgic_its *its)
 
static int vgic_its_save_cte (struct vgic_its *its, struct its_collection *collection, gpa_t gpa, int esz)
 
static int vgic_its_restore_cte (struct vgic_its *its, gpa_t gpa, int esz)
 
static int vgic_its_save_collection_table (struct vgic_its *its)
 
static int vgic_its_restore_collection_table (struct vgic_its *its)
 
static void vgic_its_reset (struct kvm *kvm, struct vgic_its *its)
 
static int vgic_its_has_attr (struct kvm_device *dev, struct kvm_device_attr *attr)
 
static int vgic_its_ctrl (struct kvm *kvm, struct vgic_its *its, u64 attr)
 
bool kvm_arch_allow_write_without_running_vcpu (struct kvm *kvm)
 
static int vgic_its_set_attr (struct kvm_device *dev, struct kvm_device_attr *attr)
 
static int vgic_its_get_attr (struct kvm_device *dev, struct kvm_device_attr *attr)
 
int kvm_vgic_register_its_device (void)
 

Variables

static const struct vgic_its_abi its_table_abi_versions []
 
static struct vgic_register_region its_registers []
 
static struct kvm_device_ops kvm_arm_vgic_its_ops
 

Macro Definition Documentation

◆ ABI_0_ESZ

#define ABI_0_ESZ   8

Definition at line 176 of file vgic-its.c.

◆ BASER_INDEX

#define BASER_INDEX (   addr)    (((addr) / sizeof(u64)) & 0x7)

Definition at line 1688 of file vgic-its.c.

◆ COLLECTION_NOT_MAPPED

#define COLLECTION_NOT_MAPPED   ((u32)~0)

Definition at line 128 of file vgic-its.c.

◆ ESZ_MAX

#define ESZ_MAX   ABI_0_ESZ

Definition at line 177 of file vgic-its.c.

◆ for_each_lpi_its

#define for_each_lpi_its (   dev,
  ite,
  its 
)
Value:
list_for_each_entry(dev, &(its)->device_list, dev_list) \
list_for_each_entry(ite, &(dev)->itt_head, ite_list)

Definition at line 244 of file vgic-its.c.

◆ GIC_LPI_OFFSET

#define GIC_LPI_OFFSET   8192

Definition at line 248 of file vgic-its.c.

◆ GITS_BASER_RO_MASK

#define GITS_BASER_RO_MASK   (GENMASK_ULL(52, 48) | GENMASK_ULL(58, 56))

Definition at line 1710 of file vgic-its.c.

◆ INITIAL_BASER_VALUE

#define INITIAL_BASER_VALUE
Value:
(GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb) | \
GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner) | \
GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable) | \
GITS_BASER_PAGE_SIZE_64K)

Definition at line 1941 of file vgic-its.c.

◆ INITIAL_PROPBASER_VALUE

#define INITIAL_PROPBASER_VALUE
Value:
(GIC_BASER_CACHEABILITY(GICR_PROPBASER, INNER, RaWb) | \
GIC_BASER_CACHEABILITY(GICR_PROPBASER, OUTER, SameAsInner) | \
GIC_BASER_SHAREABILITY(GICR_PROPBASER, InnerShareable))

Definition at line 1947 of file vgic-its.c.

◆ ITS_CMD_BUFFER_SIZE

#define ITS_CMD_BUFFER_SIZE (   baser)    ((((baser) & 0xff) + 1) << 12)

Definition at line 1582 of file vgic-its.c.

◆ its_cmd_get_collection

#define its_cmd_get_collection (   cmd)    its_cmd_mask_field(cmd, 2, 0, 16)

Definition at line 846 of file vgic-its.c.

◆ its_cmd_get_command

#define its_cmd_get_command (   cmd)    its_cmd_mask_field(cmd, 0, 0, 8)

Definition at line 841 of file vgic-its.c.

◆ its_cmd_get_deviceid

#define its_cmd_get_deviceid (   cmd)    its_cmd_mask_field(cmd, 0, 32, 32)

Definition at line 842 of file vgic-its.c.

◆ its_cmd_get_id

#define its_cmd_get_id (   cmd)    its_cmd_mask_field(cmd, 1, 0, 32)

Definition at line 844 of file vgic-its.c.

◆ its_cmd_get_ittaddr

#define its_cmd_get_ittaddr (   cmd)    (its_cmd_mask_field(cmd, 2, 8, 44) << 8)

Definition at line 847 of file vgic-its.c.

◆ its_cmd_get_physical_id

#define its_cmd_get_physical_id (   cmd)    its_cmd_mask_field(cmd, 1, 32, 32)

Definition at line 845 of file vgic-its.c.

◆ its_cmd_get_size

#define its_cmd_get_size (   cmd)    (its_cmd_mask_field(cmd, 1, 0, 5) + 1)

Definition at line 843 of file vgic-its.c.

◆ its_cmd_get_target_addr

#define its_cmd_get_target_addr (   cmd)    its_cmd_mask_field(cmd, 2, 16, 32)

Definition at line 848 of file vgic-its.c.

◆ its_cmd_get_validbit

#define its_cmd_get_validbit (   cmd)    its_cmd_mask_field(cmd, 2, 63, 1)

Definition at line 849 of file vgic-its.c.

◆ ITS_CMD_OFFSET

#define ITS_CMD_OFFSET (   reg)    ((reg) & GENMASK(19, 5))

Definition at line 1584 of file vgic-its.c.

◆ ITS_CMD_SIZE

#define ITS_CMD_SIZE   32

Definition at line 1583 of file vgic-its.c.

◆ its_is_collection_mapped

#define its_is_collection_mapped (   coll)
Value:
((coll) && \
((coll)->target_addr != COLLECTION_NOT_MAPPED))
#define COLLECTION_NOT_MAPPED
Definition: vgic-its.c:128

Definition at line 137 of file vgic-its.c.

◆ LPI_DEFAULT_PCPU_CACHE_SIZE

#define LPI_DEFAULT_PCPU_CACHE_SIZE   16

Definition at line 1901 of file vgic-its.c.

◆ LPI_PROP_ENABLE_BIT

#define LPI_PROP_ENABLE_BIT (   p)    ((p) & LPI_PROP_ENABLED)

Definition at line 271 of file vgic-its.c.

◆ LPI_PROP_PRIORITY

#define LPI_PROP_PRIORITY (   p)    ((p) & 0xfc)

Definition at line 272 of file vgic-its.c.

◆ NR_ITS_ABIS

#define NR_ITS_ABIS   ARRAY_SIZE(its_table_abi_versions)

Definition at line 190 of file vgic-its.c.

◆ REGISTER_ITS_DESC

#define REGISTER_ITS_DESC (   off,
  rd,
  wr,
  length,
  acc 
)
Value:
{ \
.reg_offset = off, \
.len = length, \
.access_flags = acc, \
.its_read = rd, \
.its_write = wr, \
}

Definition at line 1811 of file vgic-its.c.

◆ REGISTER_ITS_DESC_UACCESS

#define REGISTER_ITS_DESC_UACCESS (   off,
  rd,
  wr,
  uwr,
  length,
  acc 
)
Value:
{ \
.reg_offset = off, \
.len = length, \
.access_flags = acc, \
.its_read = rd, \
.its_write = wr, \
.uaccess_its_write = uwr, \
}

Definition at line 1820 of file vgic-its.c.

◆ VITS_DTE_MAX_DEVID_OFFSET

#define VITS_DTE_MAX_DEVID_OFFSET   (BIT(14) - 1)

Definition at line 252 of file vgic-its.c.

◆ VITS_ITE_MAX_EVENTID_OFFSET

#define VITS_ITE_MAX_EVENTID_OFFSET   (BIT(16) - 1)

Definition at line 253 of file vgic-its.c.

◆ VITS_TYPER_DEVBITS

#define VITS_TYPER_DEVBITS   16

Definition at line 251 of file vgic-its.c.

◆ VITS_TYPER_IDBITS

#define VITS_TYPER_IDBITS   16

Definition at line 250 of file vgic-its.c.

Typedef Documentation

◆ entry_fn_t

typedef int(* entry_fn_t) (struct vgic_its *its, u32 id, void *entry, void *opaque)

entry_fn_t - Callback called on a table entry restore path @its: its handle @id: id of the entry @entry: pointer to the entry @opaque: pointer to an opaque data

Return: < 0 on error, 0 if last element was identified, id offset to next element otherwise

Definition at line 2156 of file vgic-its.c.

Function Documentation

◆ __is_visible_gfn_locked()

static bool __is_visible_gfn_locked ( struct vgic_its its,
gpa_t  gpa 
)
static

Definition at line 911 of file vgic-its.c.

912 {
913  gfn_t gfn = gpa >> PAGE_SHIFT;
914  int idx;
915  bool ret;
916 
917  idx = srcu_read_lock(&its->dev->kvm->srcu);
918  ret = kvm_is_visible_gfn(its->dev->kvm, gfn);
919  srcu_read_unlock(&its->dev->kvm->srcu, idx);
920  return ret;
921 }
bool kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn)
Definition: kvm_main.c:2669
struct kvm_device * dev
Definition: arm_vgic.h:193
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __vgic_its_check_cache()

static struct vgic_irq* __vgic_its_check_cache ( struct vgic_dist dist,
phys_addr_t  db,
u32  devid,
u32  eventid 
)
static

Definition at line 557 of file vgic-its.c.

560 {
561  struct vgic_translation_cache_entry *cte;
562 
563  list_for_each_entry(cte, &dist->lpi_translation_cache, entry) {
564  /*
565  * If we hit a NULL entry, there is nothing after this
566  * point.
567  */
568  if (!cte->irq)
569  break;
570 
571  if (cte->db != db || cte->devid != devid ||
572  cte->eventid != eventid)
573  continue;
574 
575  /*
576  * Move this entry to the head, as it is the most
577  * recently used.
578  */
579  if (!list_is_first(&cte->entry, &dist->lpi_translation_cache))
580  list_move(&cte->entry, &dist->lpi_translation_cache);
581 
582  return cte->irq;
583  }
584 
585  return NULL;
586 }
struct list_head lpi_translation_cache
Definition: arm_vgic.h:282
Definition: vgic-its.c:148
phys_addr_t db
Definition: vgic-its.c:150
u32 eventid
Definition: vgic-its.c:152
struct list_head entry
Definition: vgic-its.c:149
u32 devid
Definition: vgic-its.c:151
struct vgic_irq * irq
Definition: vgic-its.c:153
Here is the caller graph for this function:

◆ collection_to_vcpu()

static struct kvm_vcpu* collection_to_vcpu ( struct kvm *  kvm,
struct its_collection col 
)
static

Definition at line 381 of file vgic-its.c.

383 {
384  return kvm_get_vcpu_by_id(kvm, col->target_addr);
385 }
Here is the caller graph for this function:

◆ compute_next_devid_offset()

static u32 compute_next_devid_offset ( struct list_head *  h,
struct its_device dev 
)
static

Definition at line 2119 of file vgic-its.c.

2121 {
2122  struct its_device *next;
2123  u32 next_offset;
2124 
2125  if (list_is_last(&dev->dev_list, h))
2126  return 0;
2127  next = list_next_entry(dev, dev_list);
2128  next_offset = next->device_id - dev->device_id;
2129 
2130  return min_t(u32, next_offset, VITS_DTE_MAX_DEVID_OFFSET);
2131 }
u32 device_id
Definition: vgic-its.c:125
struct list_head dev_list
Definition: vgic-its.c:119
#define VITS_DTE_MAX_DEVID_OFFSET
Definition: vgic-its.c:252
Here is the caller graph for this function:

◆ compute_next_eventid_offset()

static u32 compute_next_eventid_offset ( struct list_head *  h,
struct its_ite ite 
)
static

Definition at line 2133 of file vgic-its.c.

2134 {
2135  struct its_ite *next;
2136  u32 next_offset;
2137 
2138  if (list_is_last(&ite->ite_list, h))
2139  return 0;
2140  next = list_next_entry(ite, ite_list);
2141  next_offset = next->event_id - ite->event_id;
2142 
2143  return min_t(u32, next_offset, VITS_ITE_MAX_EVENTID_OFFSET);
2144 }
u32 event_id
Definition: vgic-its.c:145
struct list_head ite_list
Definition: vgic-its.c:141
#define VITS_ITE_MAX_EVENTID_OFFSET
Definition: vgic-its.c:253
Here is the caller graph for this function:

◆ find_collection()

static struct its_collection* find_collection ( struct vgic_its its,
int  coll_id 
)
static

Definition at line 259 of file vgic-its.c.

260 {
261  struct its_collection *collection;
262 
263  list_for_each_entry(collection, &its->collection_list, coll_list) {
264  if (coll_id == collection->collection_id)
265  return collection;
266  }
267 
268  return NULL;
269 }
struct list_head coll_list
Definition: vgic-its.c:131
u32 collection_id
Definition: vgic-its.c:133
struct list_head collection_list
Definition: arm_vgic.h:211
Here is the caller graph for this function:

◆ find_ite()

static struct its_ite* find_ite ( struct vgic_its its,
u32  device_id,
u32  event_id 
)
static

Definition at line 226 of file vgic-its.c.

228 {
229  struct its_device *device;
230  struct its_ite *ite;
231 
232  device = find_its_device(its, device_id);
233  if (device == NULL)
234  return NULL;
235 
236  list_for_each_entry(ite, &device->itt_head, ite_list)
237  if (ite->event_id == event_id)
238  return ite;
239 
240  return NULL;
241 }
struct list_head itt_head
Definition: vgic-its.c:122
static struct its_device * find_its_device(struct vgic_its *its, u32 device_id)
Definition: vgic-its.c:210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_its_device()

static struct its_device* find_its_device ( struct vgic_its its,
u32  device_id 
)
static

Definition at line 210 of file vgic-its.c.

211 {
212  struct its_device *device;
213 
214  list_for_each_entry(device, &its->device_list, dev_list)
215  if (device_id == device->device_id)
216  return device;
217 
218  return NULL;
219 }
struct list_head device_list
Definition: arm_vgic.h:210
Here is the caller graph for this function:

◆ handle_l1_dte()

static int handle_l1_dte ( struct vgic_its its,
u32  id,
void *  addr,
void *  opaque 
)
static

handle_l1_dte - callback used for L1 device table entries (2 stage case)

@its: its handle @id: index of the entry in the L1 table @addr: kernel VA @opaque: unused

L1 table entries are scanned by steps of 1 entry Return < 0 if error, 0 if last dte was found when scanning the L2 table, +1 otherwise (meaning next L1 entry must be scanned)

Definition at line 2493 of file vgic-its.c.

2495 {
2496  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2497  int l2_start_id = id * (SZ_64K / abi->dte_esz);
2498  u64 entry = *(u64 *)addr;
2499  int dte_esz = abi->dte_esz;
2500  gpa_t gpa;
2501  int ret;
2502 
2503  entry = le64_to_cpu(entry);
2504 
2505  if (!(entry & KVM_ITS_L1E_VALID_MASK))
2506  return 1;
2507 
2508  gpa = entry & KVM_ITS_L1E_ADDR_MASK;
2509 
2510  ret = scan_its_table(its, gpa, SZ_64K, dte_esz,
2511  l2_start_id, vgic_its_restore_dte, NULL);
2512 
2513  return ret;
2514 }
const struct vgic_its_abi * vgic_its_get_abi(struct vgic_its *its)
Definition: vgic-its.c:192
static int vgic_its_restore_dte(struct vgic_its *its, u32 id, void *ptr, void *opaque)
Definition: vgic-its.c:2390
static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz, int start_id, entry_fn_t fn, void *opaque)
Definition: vgic-its.c:2174
#define KVM_ITS_L1E_VALID_MASK
Definition: vgic.h:85
#define KVM_ITS_L1E_ADDR_MASK
Definition: vgic.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ its_cmd_mask_field()

static u64 its_cmd_mask_field ( u64 *  its_cmd,
int  word,
int  shift,
int  size 
)
static

Definition at line 836 of file vgic-its.c.

837 {
838  return (le64_to_cpu(its_cmd[word]) >> shift) & (BIT_ULL(size) - 1);
839 }
size_t size
Definition: gen-hyprel.c:133
Here is the caller graph for this function:

◆ its_free_ite()

static void its_free_ite ( struct kvm *  kvm,
struct its_ite ite 
)
static

Definition at line 821 of file vgic-its.c.

822 {
823  list_del(&ite->ite_list);
824 
825  /* This put matches the get in vgic_add_lpi. */
826  if (ite->irq) {
827  if (ite->irq->hw)
828  WARN_ON(its_unmap_vlpi(ite->irq->host_irq));
829 
830  vgic_put_irq(kvm, ite->irq);
831  }
832 
833  kfree(ite);
834 }
struct vgic_irq * irq
Definition: vgic-its.c:143
unsigned int host_irq
Definition: arm_vgic.h:143
bool hw
Definition: arm_vgic.h:140
void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic.c:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ its_mmio_write_wi()

static void its_mmio_write_wi ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1830 of file vgic-its.c.

1832 {
1833  /* Ignore */
1834 }

◆ its_sync_lpi_pending_table()

static int its_sync_lpi_pending_table ( struct kvm_vcpu *  vcpu)
static

Definition at line 434 of file vgic-its.c.

435 {
436  gpa_t pendbase = GICR_PENDBASER_ADDRESS(vcpu->arch.vgic_cpu.pendbaser);
437  struct vgic_irq *irq;
438  int last_byte_offset = -1;
439  int ret = 0;
440  u32 *intids;
441  int nr_irqs, i;
442  unsigned long flags;
443  u8 pendmask;
444 
445  nr_irqs = vgic_copy_lpi_list(vcpu->kvm, vcpu, &intids);
446  if (nr_irqs < 0)
447  return nr_irqs;
448 
449  for (i = 0; i < nr_irqs; i++) {
450  int byte_offset, bit_nr;
451 
452  byte_offset = intids[i] / BITS_PER_BYTE;
453  bit_nr = intids[i] % BITS_PER_BYTE;
454 
455  /*
456  * For contiguously allocated LPIs chances are we just read
457  * this very same byte in the last iteration. Reuse that.
458  */
459  if (byte_offset != last_byte_offset) {
460  ret = kvm_read_guest_lock(vcpu->kvm,
461  pendbase + byte_offset,
462  &pendmask, 1);
463  if (ret) {
464  kfree(intids);
465  return ret;
466  }
467  last_byte_offset = byte_offset;
468  }
469 
470  irq = vgic_get_irq(vcpu->kvm, NULL, intids[i]);
471  if (!irq)
472  continue;
473 
474  raw_spin_lock_irqsave(&irq->irq_lock, flags);
475  irq->pending_latch = pendmask & (1U << bit_nr);
476  vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
477  vgic_put_irq(vcpu->kvm, irq);
478  }
479 
480  kfree(intids);
481 
482  return ret;
483 }
struct kvm_vcpu * vcpu
Definition: arm_vgic.h:122
bool pending_latch
Definition: arm_vgic.h:135
raw_spinlock_t irq_lock
Definition: arm_vgic.h:118
int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr)
Definition: vgic-its.c:319
bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq, unsigned long flags)
Definition: vgic.c:336
struct vgic_irq * vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 intid)
Definition: vgic.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_arch_allow_write_without_running_vcpu()

bool kvm_arch_allow_write_without_running_vcpu ( struct kvm *  kvm)

Definition at line 2824 of file vgic-its.c.

2825 {
2826  struct vgic_dist *dist = &kvm->arch.vgic;
2827 
2828  return dist->table_write_in_progress;
2829 }
bool table_write_in_progress
Definition: arm_vgic.h:266
Here is the caller graph for this function:

◆ kvm_vgic_register_its_device()

int kvm_vgic_register_its_device ( void  )

Definition at line 2914 of file vgic-its.c.

2915 {
2917  KVM_DEV_TYPE_ARM_VGIC_ITS);
2918 }
int kvm_register_device_ops(const struct kvm_device_ops *ops, u32 type)
Definition: kvm_main.c:4742
static struct kvm_device_ops kvm_arm_vgic_its_ops
Definition: vgic-its.c:2905
Here is the caller graph for this function:

◆ max_lpis_propbaser()

static u32 max_lpis_propbaser ( u64  propbaser)
static

Definition at line 422 of file vgic-its.c.

423 {
424  int nr_idbits = (propbaser & 0x1f) + 1;
425 
426  return 1U << min(nr_idbits, INTERRUPT_ID_BITS_ITS);
427 }
#define INTERRUPT_ID_BITS_ITS
Definition: vgic.h:18
Here is the caller graph for this function:

◆ scan_its_table()

static int scan_its_table ( struct vgic_its its,
gpa_t  base,
int  size,
u32  esz,
int  start_id,
entry_fn_t  fn,
void *  opaque 
)
static

Definition at line 2174 of file vgic-its.c.

2176 {
2177  struct kvm *kvm = its->dev->kvm;
2178  unsigned long len = size;
2179  int id = start_id;
2180  gpa_t gpa = base;
2181  char entry[ESZ_MAX];
2182  int ret;
2183 
2184  memset(entry, 0, esz);
2185 
2186  while (true) {
2187  int next_offset;
2188  size_t byte_offset;
2189 
2190  ret = kvm_read_guest_lock(kvm, gpa, entry, esz);
2191  if (ret)
2192  return ret;
2193 
2194  next_offset = fn(its, id, entry, opaque);
2195  if (next_offset <= 0)
2196  return next_offset;
2197 
2198  byte_offset = next_offset * esz;
2199  if (byte_offset >= len)
2200  break;
2201 
2202  id += next_offset;
2203  gpa += byte_offset;
2204  len -= byte_offset;
2205  }
2206  return 1;
2207 }
static unsigned long base
Definition: early_alloc.c:15
#define ESZ_MAX
Definition: vgic-its.c:177
Here is the caller graph for this function:

◆ update_affinity()

static int update_affinity ( struct vgic_irq irq,
struct kvm_vcpu *  vcpu 
)
static

Definition at line 354 of file vgic-its.c.

355 {
356  int ret = 0;
357  unsigned long flags;
358 
359  raw_spin_lock_irqsave(&irq->irq_lock, flags);
360  irq->target_vcpu = vcpu;
361  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
362 
363  if (irq->hw) {
364  struct its_vlpi_map map;
365 
366  ret = its_get_vlpi(irq->host_irq, &map);
367  if (ret)
368  return ret;
369 
370  if (map.vpe)
371  atomic_dec(&map.vpe->vlpi_count);
372  map.vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
373  atomic_inc(&map.vpe->vlpi_count);
374 
375  ret = its_map_vlpi(irq->host_irq, &map);
376  }
377 
378  return ret;
379 }
struct kvm_vcpu * target_vcpu
Definition: arm_vgic.h:127
Here is the caller graph for this function:

◆ update_affinity_collection()

static void update_affinity_collection ( struct kvm *  kvm,
struct vgic_its its,
struct its_collection coll 
)
static

Definition at line 408 of file vgic-its.c.

410 {
411  struct its_device *device;
412  struct its_ite *ite;
413 
414  for_each_lpi_its(device, ite, its) {
415  if (ite->collection != coll)
416  continue;
417 
418  update_affinity_ite(kvm, ite);
419  }
420 }
struct its_collection * collection
Definition: vgic-its.c:144
#define for_each_lpi_its(dev, ite, its)
Definition: vgic-its.c:244
static void update_affinity_ite(struct kvm *kvm, struct its_ite *ite)
Definition: vgic-its.c:393
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_affinity_ite()

static void update_affinity_ite ( struct kvm *  kvm,
struct its_ite ite 
)
static

Definition at line 393 of file vgic-its.c.

394 {
395  struct kvm_vcpu *vcpu;
396 
398  return;
399 
400  vcpu = collection_to_vcpu(kvm, ite->collection);
401  update_affinity(ite->irq, vcpu);
402 }
static int update_affinity(struct vgic_irq *irq, struct kvm_vcpu *vcpu)
Definition: vgic-its.c:354
static struct kvm_vcpu * collection_to_vcpu(struct kvm *kvm, struct its_collection *col)
Definition: vgic-its.c:381
#define its_is_collection_mapped(coll)
Definition: vgic-its.c:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_lpi_config()

static int update_lpi_config ( struct kvm *  kvm,
struct vgic_irq irq,
struct kvm_vcpu *  filter_vcpu,
bool  needs_inv 
)
static

Definition at line 280 of file vgic-its.c.

282 {
283  u64 propbase = GICR_PROPBASER_ADDRESS(kvm->arch.vgic.propbaser);
284  u8 prop;
285  int ret;
286  unsigned long flags;
287 
288  ret = kvm_read_guest_lock(kvm, propbase + irq->intid - GIC_LPI_OFFSET,
289  &prop, 1);
290 
291  if (ret)
292  return ret;
293 
294  raw_spin_lock_irqsave(&irq->irq_lock, flags);
295 
296  if (!filter_vcpu || filter_vcpu == irq->target_vcpu) {
297  irq->priority = LPI_PROP_PRIORITY(prop);
298  irq->enabled = LPI_PROP_ENABLE_BIT(prop);
299 
300  if (!irq->hw) {
301  vgic_queue_irq_unlock(kvm, irq, flags);
302  return 0;
303  }
304  }
305 
306  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
307 
308  if (irq->hw)
309  return its_prop_update_vlpi(irq->host_irq, prop, needs_inv);
310 
311  return 0;
312 }
u8 priority
Definition: arm_vgic.h:150
u32 intid
Definition: arm_vgic.h:133
bool enabled
Definition: arm_vgic.h:139
#define LPI_PROP_ENABLE_BIT(p)
Definition: vgic-its.c:271
#define GIC_LPI_OFFSET
Definition: vgic-its.c:248
#define LPI_PROP_PRIORITY(p)
Definition: vgic-its.c:272
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_add_lpi()

static struct vgic_irq* vgic_add_lpi ( struct kvm *  kvm,
u32  intid,
struct kvm_vcpu *  vcpu 
)
static

Definition at line 39 of file vgic-its.c.

41 {
42  struct vgic_dist *dist = &kvm->arch.vgic;
43  struct vgic_irq *irq = vgic_get_irq(kvm, NULL, intid), *oldirq;
44  unsigned long flags;
45  int ret;
46 
47  /* In this case there is no put, since we keep the reference. */
48  if (irq)
49  return irq;
50 
51  irq = kzalloc(sizeof(struct vgic_irq), GFP_KERNEL_ACCOUNT);
52  if (!irq)
53  return ERR_PTR(-ENOMEM);
54 
55  INIT_LIST_HEAD(&irq->lpi_list);
56  INIT_LIST_HEAD(&irq->ap_list);
57  raw_spin_lock_init(&irq->irq_lock);
58 
59  irq->config = VGIC_CONFIG_EDGE;
60  kref_init(&irq->refcount);
61  irq->intid = intid;
62  irq->target_vcpu = vcpu;
63  irq->group = 1;
64 
65  raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
66 
67  /*
68  * There could be a race with another vgic_add_lpi(), so we need to
69  * check that we don't add a second list entry with the same LPI.
70  */
71  list_for_each_entry(oldirq, &dist->lpi_list_head, lpi_list) {
72  if (oldirq->intid != intid)
73  continue;
74 
75  /* Someone was faster with adding this LPI, lets use that. */
76  kfree(irq);
77  irq = oldirq;
78 
79  /*
80  * This increases the refcount, the caller is expected to
81  * call vgic_put_irq() on the returned pointer once it's
82  * finished with the IRQ.
83  */
84  vgic_get_irq_kref(irq);
85 
86  goto out_unlock;
87  }
88 
89  list_add_tail(&irq->lpi_list, &dist->lpi_list_head);
90  dist->lpi_list_count++;
91 
92 out_unlock:
93  raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
94 
95  /*
96  * We "cache" the configuration table entries in our struct vgic_irq's.
97  * However we only have those structs for mapped IRQs, so we read in
98  * the respective config data from memory here upon mapping the LPI.
99  *
100  * Should any of these fail, behave as if we couldn't create the LPI
101  * by dropping the refcount and returning the error.
102  */
103  ret = update_lpi_config(kvm, irq, NULL, false);
104  if (ret) {
105  vgic_put_irq(kvm, irq);
106  return ERR_PTR(ret);
107  }
108 
109  ret = vgic_v3_lpi_sync_pending_status(kvm, irq);
110  if (ret) {
111  vgic_put_irq(kvm, irq);
112  return ERR_PTR(ret);
113  }
114 
115  return irq;
116 }
@ VGIC_CONFIG_EDGE
Definition: arm_vgic.h:93
struct list_head lpi_list_head
Definition: arm_vgic.h:278
raw_spinlock_t lpi_list_lock
Definition: arm_vgic.h:277
int lpi_list_count
Definition: arm_vgic.h:279
struct list_head lpi_list
Definition: arm_vgic.h:119
struct list_head ap_list
Definition: arm_vgic.h:120
u8 group
Definition: arm_vgic.h:151
struct kref refcount
Definition: arm_vgic.h:141
enum vgic_irq_config config
Definition: arm_vgic.h:152
static int update_lpi_config(struct kvm *kvm, struct vgic_irq *irq, struct kvm_vcpu *filter_vcpu, bool needs_inv)
Definition: vgic-its.c:280
int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic-v3.c:305
static void vgic_get_irq_kref(struct vgic_irq *irq)
Definition: vgic.h:223
Here is the caller graph for this function:

◆ vgic_copy_lpi_list()

int vgic_copy_lpi_list ( struct kvm *  kvm,
struct kvm_vcpu *  vcpu,
u32 **  intid_ptr 
)

Definition at line 319 of file vgic-its.c.

320 {
321  struct vgic_dist *dist = &kvm->arch.vgic;
322  struct vgic_irq *irq;
323  unsigned long flags;
324  u32 *intids;
325  int irq_count, i = 0;
326 
327  /*
328  * There is an obvious race between allocating the array and LPIs
329  * being mapped/unmapped. If we ended up here as a result of a
330  * command, we're safe (locks are held, preventing another
331  * command). If coming from another path (such as enabling LPIs),
332  * we must be careful not to overrun the array.
333  */
334  irq_count = READ_ONCE(dist->lpi_list_count);
335  intids = kmalloc_array(irq_count, sizeof(intids[0]), GFP_KERNEL_ACCOUNT);
336  if (!intids)
337  return -ENOMEM;
338 
339  raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
340  list_for_each_entry(irq, &dist->lpi_list_head, lpi_list) {
341  if (i == irq_count)
342  break;
343  /* We don't need to "get" the IRQ, as we hold the list lock. */
344  if (vcpu && irq->target_vcpu != vcpu)
345  continue;
346  intids[i++] = irq->intid;
347  }
348  raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
349 
350  *intid_ptr = intids;
351  return i;
352 }
Here is the caller graph for this function:

◆ vgic_enable_lpis()

void vgic_enable_lpis ( struct kvm_vcpu *  vcpu)

Definition at line 1866 of file vgic-its.c.

1867 {
1868  if (!(vcpu->arch.vgic_cpu.pendbaser & GICR_PENDBASER_PTZ))
1870 }
static int its_sync_lpi_pending_table(struct kvm_vcpu *vcpu)
Definition: vgic-its.c:434
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_alloc_collection()

static int vgic_its_alloc_collection ( struct vgic_its its,
struct its_collection **  colp,
u32  coll_id 
)
static

Definition at line 1020 of file vgic-its.c.

1023 {
1024  struct its_collection *collection;
1025 
1026  collection = kzalloc(sizeof(*collection), GFP_KERNEL_ACCOUNT);
1027  if (!collection)
1028  return -ENOMEM;
1029 
1030  collection->collection_id = coll_id;
1031  collection->target_addr = COLLECTION_NOT_MAPPED;
1032 
1033  list_add_tail(&collection->coll_list, &its->collection_list);
1034  *colp = collection;
1035 
1036  return 0;
1037 }
Here is the caller graph for this function:

◆ vgic_its_alloc_device()

static struct its_device* vgic_its_alloc_device ( struct vgic_its its,
u32  device_id,
gpa_t  itt_addr,
u8  num_eventid_bits 
)
static

Definition at line 1190 of file vgic-its.c.

1193 {
1194  struct its_device *device;
1195 
1196  device = kzalloc(sizeof(*device), GFP_KERNEL_ACCOUNT);
1197  if (!device)
1198  return ERR_PTR(-ENOMEM);
1199 
1200  device->device_id = device_id;
1201  device->itt_addr = itt_addr;
1203  INIT_LIST_HEAD(&device->itt_head);
1204 
1205  list_add_tail(&device->dev_list, &its->device_list);
1206  return device;
1207 }
u32 num_eventid_bits
Definition: vgic-its.c:123
gpa_t itt_addr
Definition: vgic-its.c:124
Here is the caller graph for this function:

◆ vgic_its_alloc_ite()

static struct its_ite* vgic_its_alloc_ite ( struct its_device device,
struct its_collection collection,
u32  event_id 
)
static

Definition at line 1064 of file vgic-its.c.

1067 {
1068  struct its_ite *ite;
1069 
1070  ite = kzalloc(sizeof(*ite), GFP_KERNEL_ACCOUNT);
1071  if (!ite)
1072  return ERR_PTR(-ENOMEM);
1073 
1074  ite->event_id = event_id;
1075  ite->collection = collection;
1076 
1077  list_add_tail(&ite->ite_list, &device->itt_head);
1078  return ite;
1079 }
Here is the caller graph for this function:

◆ vgic_its_attr_regs_access()

static int vgic_its_attr_regs_access ( struct kvm_device *  dev,
struct kvm_device_attr *  attr,
u64 *  reg,
bool  is_write 
)
static

Definition at line 2049 of file vgic-its.c.

2052 {
2053  const struct vgic_register_region *region;
2054  struct vgic_its *its;
2055  gpa_t addr, offset;
2056  unsigned int len;
2057  int align, ret = 0;
2058 
2059  its = dev->private;
2060  offset = attr->attr;
2061 
2062  /*
2063  * Although the spec supports upper/lower 32-bit accesses to
2064  * 64-bit ITS registers, the userspace ABI requires 64-bit
2065  * accesses to all 64-bit wide registers. We therefore only
2066  * support 32-bit accesses to GITS_CTLR, GITS_IIDR and GITS ID
2067  * registers
2068  */
2069  if ((offset < GITS_TYPER) || (offset >= GITS_PIDR4))
2070  align = 0x3;
2071  else
2072  align = 0x7;
2073 
2074  if (offset & align)
2075  return -EINVAL;
2076 
2077  mutex_lock(&dev->kvm->lock);
2078 
2079  if (!lock_all_vcpus(dev->kvm)) {
2080  mutex_unlock(&dev->kvm->lock);
2081  return -EBUSY;
2082  }
2083 
2084  mutex_lock(&dev->kvm->arch.config_lock);
2085 
2086  if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) {
2087  ret = -ENXIO;
2088  goto out;
2089  }
2090 
2092  ARRAY_SIZE(its_registers),
2093  offset);
2094  if (!region) {
2095  ret = -ENXIO;
2096  goto out;
2097  }
2098 
2099  addr = its->vgic_its_base + offset;
2100 
2101  len = region->access_flags & VGIC_ACCESS_64bit ? 8 : 4;
2102 
2103  if (is_write) {
2104  if (region->uaccess_its_write)
2105  ret = region->uaccess_its_write(dev->kvm, its, addr,
2106  len, *reg);
2107  else
2108  region->its_write(dev->kvm, its, addr, len, *reg);
2109  } else {
2110  *reg = region->its_read(dev->kvm, its, addr, len);
2111  }
2112 out:
2113  mutex_unlock(&dev->kvm->arch.config_lock);
2114  unlock_all_vcpus(dev->kvm);
2115  mutex_unlock(&dev->kvm->lock);
2116  return ret;
2117 }
bool lock_all_vcpus(struct kvm *kvm)
Definition: arm.c:1773
void unlock_all_vcpus(struct kvm *kvm)
Definition: arm.c:1765
gpa_t vgic_its_base
Definition: arm_vgic.h:189
unsigned int access_flags
Definition: vgic-mmio.h:12
unsigned long(* its_read)(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-mmio.h:16
void(* its_write)(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio.h:22
int(* uaccess_its_write)(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio.h:31
static struct vgic_register_region its_registers[]
Definition: vgic-its.c:1836
const struct vgic_register_region * vgic_find_mmio_region(const struct vgic_register_region *regions, int nr_regions, unsigned int offset)
Definition: vgic-mmio.c:836
#define VGIC_ACCESS_64bit
Definition: vgic-mmio.h:41
#define IS_VGIC_ADDR_UNDEF(_x)
Definition: vgic.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cache_translation()

static void vgic_its_cache_translation ( struct kvm *  kvm,
struct vgic_its its,
u32  devid,
u32  eventid,
struct vgic_irq irq 
)
static

Definition at line 606 of file vgic-its.c.

609 {
610  struct vgic_dist *dist = &kvm->arch.vgic;
611  struct vgic_translation_cache_entry *cte;
612  unsigned long flags;
613  phys_addr_t db;
614 
615  /* Do not cache a directly injected interrupt */
616  if (irq->hw)
617  return;
618 
619  raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
620 
621  if (unlikely(list_empty(&dist->lpi_translation_cache)))
622  goto out;
623 
624  /*
625  * We could have raced with another CPU caching the same
626  * translation behind our back, so let's check it is not in
627  * already
628  */
629  db = its->vgic_its_base + GITS_TRANSLATER;
630  if (__vgic_its_check_cache(dist, db, devid, eventid))
631  goto out;
632 
633  /* Always reuse the last entry (LRU policy) */
634  cte = list_last_entry(&dist->lpi_translation_cache,
635  typeof(*cte), entry);
636 
637  /*
638  * Caching the translation implies having an extra reference
639  * to the interrupt, so drop the potential reference on what
640  * was in the cache, and increment it on the new interrupt.
641  */
642  if (cte->irq)
643  __vgic_put_lpi_locked(kvm, cte->irq);
644 
646 
647  cte->db = db;
648  cte->devid = devid;
649  cte->eventid = eventid;
650  cte->irq = irq;
651 
652  /* Move the new translation to the head of the list */
653  list_move(&cte->entry, &dist->lpi_translation_cache);
654 
655 out:
656  raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
657 }
static struct vgic_irq * __vgic_its_check_cache(struct vgic_dist *dist, phys_addr_t db, u32 devid, u32 eventid)
Definition: vgic-its.c:557
void __vgic_put_lpi_locked(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic.c:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_check_cache()

static struct vgic_irq* vgic_its_check_cache ( struct kvm *  kvm,
phys_addr_t  db,
u32  devid,
u32  eventid 
)
static

Definition at line 588 of file vgic-its.c.

590 {
591  struct vgic_dist *dist = &kvm->arch.vgic;
592  struct vgic_irq *irq;
593  unsigned long flags;
594 
595  raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
596 
597  irq = __vgic_its_check_cache(dist, db, devid, eventid);
598  if (irq)
599  vgic_get_irq_kref(irq);
600 
601  raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
602 
603  return irq;
604 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_check_event_id()

static bool vgic_its_check_event_id ( struct vgic_its its,
struct its_device device,
u32  event_id 
)
static

Definition at line 1001 of file vgic-its.c.

1003 {
1004  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
1005  int ite_esz = abi->ite_esz;
1006  gpa_t gpa;
1007 
1008  /* max table size is: BIT_ULL(device->num_eventid_bits) * ite_esz */
1009  if (event_id >= BIT_ULL(device->num_eventid_bits))
1010  return false;
1011 
1012  gpa = device->itt_addr + event_id * ite_esz;
1013  return __is_visible_gfn_locked(its, gpa);
1014 }
static bool __is_visible_gfn_locked(struct vgic_its *its, gpa_t gpa)
Definition: vgic-its.c:911
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_check_id()

static bool vgic_its_check_id ( struct vgic_its its,
u64  baser,
u32  id,
gpa_t *  eaddr 
)
static

Definition at line 930 of file vgic-its.c.

932 {
933  int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
934  u64 indirect_ptr, type = GITS_BASER_TYPE(baser);
935  phys_addr_t base = GITS_BASER_ADDR_48_to_52(baser);
936  int esz = GITS_BASER_ENTRY_SIZE(baser);
937  int index;
938 
939  switch (type) {
940  case GITS_BASER_TYPE_DEVICE:
941  if (id >= BIT_ULL(VITS_TYPER_DEVBITS))
942  return false;
943  break;
944  case GITS_BASER_TYPE_COLLECTION:
945  /* as GITS_TYPER.CIL == 0, ITS supports 16-bit collection ID */
946  if (id >= BIT_ULL(16))
947  return false;
948  break;
949  default:
950  return false;
951  }
952 
953  if (!(baser & GITS_BASER_INDIRECT)) {
954  phys_addr_t addr;
955 
956  if (id >= (l1_tbl_size / esz))
957  return false;
958 
959  addr = base + id * esz;
960 
961  if (eaddr)
962  *eaddr = addr;
963 
964  return __is_visible_gfn_locked(its, addr);
965  }
966 
967  /* calculate and check the index into the 1st level */
968  index = id / (SZ_64K / esz);
969  if (index >= (l1_tbl_size / sizeof(u64)))
970  return false;
971 
972  /* Each 1st level entry is represented by a 64-bit value. */
973  if (kvm_read_guest_lock(its->dev->kvm,
974  base + index * sizeof(indirect_ptr),
975  &indirect_ptr, sizeof(indirect_ptr)))
976  return false;
977 
978  indirect_ptr = le64_to_cpu(indirect_ptr);
979 
980  /* check the valid bit of the first level entry */
981  if (!(indirect_ptr & BIT_ULL(63)))
982  return false;
983 
984  /* Mask the guest physical address and calculate the frame number. */
985  indirect_ptr &= GENMASK_ULL(51, 16);
986 
987  /* Find the address of the actual entry */
988  index = id % (SZ_64K / esz);
989  indirect_ptr += index * esz;
990 
991  if (eaddr)
992  *eaddr = indirect_ptr;
993 
994  return __is_visible_gfn_locked(its, indirect_ptr);
995 }
#define VITS_TYPER_DEVBITS
Definition: vgic-its.c:251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_clear()

static int vgic_its_cmd_handle_clear ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1302 of file vgic-its.c.

1304 {
1305  u32 device_id = its_cmd_get_deviceid(its_cmd);
1306  u32 event_id = its_cmd_get_id(its_cmd);
1307  struct its_ite *ite;
1308 
1309 
1310  ite = find_ite(its, device_id, event_id);
1311  if (!ite)
1312  return E_ITS_CLEAR_UNMAPPED_INTERRUPT;
1313 
1314  ite->irq->pending_latch = false;
1315 
1316  if (ite->irq->hw)
1317  return irq_set_irqchip_state(ite->irq->host_irq,
1318  IRQCHIP_STATE_PENDING, false);
1319 
1320  return 0;
1321 }
#define its_cmd_get_deviceid(cmd)
Definition: vgic-its.c:842
#define its_cmd_get_id(cmd)
Definition: vgic-its.c:844
static struct its_ite * find_ite(struct vgic_its *its, u32 device_id, u32 event_id)
Definition: vgic-its.c:226
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_discard()

static int vgic_its_cmd_handle_discard ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 855 of file vgic-its.c.

857 {
858  u32 device_id = its_cmd_get_deviceid(its_cmd);
859  u32 event_id = its_cmd_get_id(its_cmd);
860  struct its_ite *ite;
861 
862  ite = find_ite(its, device_id, event_id);
863  if (ite && its_is_collection_mapped(ite->collection)) {
864  /*
865  * Though the spec talks about removing the pending state, we
866  * don't bother here since we clear the ITTE anyway and the
867  * pending state is a property of the ITTE struct.
868  */
870 
871  its_free_ite(kvm, ite);
872  return 0;
873  }
874 
875  return E_ITS_DISCARD_UNMAPPED_INTERRUPT;
876 }
void vgic_its_invalidate_cache(struct kvm *kvm)
Definition: vgic-its.c:659
static void its_free_ite(struct kvm *kvm, struct its_ite *ite)
Definition: vgic-its.c:821
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_int()

static int vgic_its_cmd_handle_int ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1456 of file vgic-its.c.

1458 {
1459  u32 msi_data = its_cmd_get_id(its_cmd);
1460  u64 msi_devid = its_cmd_get_deviceid(its_cmd);
1461 
1462  return vgic_its_trigger_msi(kvm, its, msi_devid, msi_data);
1463 }
static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid)
Definition: vgic-its.c:743
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_inv()

static int vgic_its_cmd_handle_inv ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1332 of file vgic-its.c.

1334 {
1335  u32 device_id = its_cmd_get_deviceid(its_cmd);
1336  u32 event_id = its_cmd_get_id(its_cmd);
1337  struct its_ite *ite;
1338 
1339 
1340  ite = find_ite(its, device_id, event_id);
1341  if (!ite)
1342  return E_ITS_INV_UNMAPPED_INTERRUPT;
1343 
1344  return vgic_its_inv_lpi(kvm, ite->irq);
1345 }
int vgic_its_inv_lpi(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic-its.c:1323
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_invall()

static int vgic_its_cmd_handle_invall ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1389 of file vgic-its.c.

1391 {
1392  u32 coll_id = its_cmd_get_collection(its_cmd);
1393  struct its_collection *collection;
1394  struct kvm_vcpu *vcpu;
1395 
1396  collection = find_collection(its, coll_id);
1397  if (!its_is_collection_mapped(collection))
1398  return E_ITS_INVALL_UNMAPPED_COLLECTION;
1399 
1400  vcpu = collection_to_vcpu(kvm, collection);
1401  vgic_its_invall(vcpu);
1402 
1403  return 0;
1404 }
#define its_cmd_get_collection(cmd)
Definition: vgic-its.c:846
static struct its_collection * find_collection(struct vgic_its *its, int coll_id)
Definition: vgic-its.c:259
int vgic_its_invall(struct kvm_vcpu *vcpu)
Definition: vgic-its.c:1355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_mapc()

static int vgic_its_cmd_handle_mapc ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1255 of file vgic-its.c.

1257 {
1258  u16 coll_id;
1259  struct its_collection *collection;
1260  bool valid;
1261 
1262  valid = its_cmd_get_validbit(its_cmd);
1263  coll_id = its_cmd_get_collection(its_cmd);
1264 
1265  if (!valid) {
1266  vgic_its_free_collection(its, coll_id);
1268  } else {
1269  struct kvm_vcpu *vcpu;
1270 
1271  vcpu = kvm_get_vcpu_by_id(kvm, its_cmd_get_target_addr(its_cmd));
1272  if (!vcpu)
1273  return E_ITS_MAPC_PROCNUM_OOR;
1274 
1275  collection = find_collection(its, coll_id);
1276 
1277  if (!collection) {
1278  int ret;
1279 
1280  if (!vgic_its_check_id(its, its->baser_coll_table,
1281  coll_id, NULL))
1282  return E_ITS_MAPC_COLLECTION_OOR;
1283 
1284  ret = vgic_its_alloc_collection(its, &collection,
1285  coll_id);
1286  if (ret)
1287  return ret;
1288  collection->target_addr = vcpu->vcpu_id;
1289  } else {
1290  collection->target_addr = vcpu->vcpu_id;
1291  update_affinity_collection(kvm, its, collection);
1292  }
1293  }
1294 
1295  return 0;
1296 }
u64 baser_coll_table
Definition: arm_vgic.h:197
#define its_cmd_get_validbit(cmd)
Definition: vgic-its.c:849
static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, gpa_t *eaddr)
Definition: vgic-its.c:930
static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id)
Definition: vgic-its.c:1039
static void update_affinity_collection(struct kvm *kvm, struct vgic_its *its, struct its_collection *coll)
Definition: vgic-its.c:408
#define its_cmd_get_target_addr(cmd)
Definition: vgic-its.c:848
static int vgic_its_alloc_collection(struct vgic_its *its, struct its_collection **colp, u32 coll_id)
Definition: vgic-its.c:1020
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_mapd()

static int vgic_its_cmd_handle_mapd ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1213 of file vgic-its.c.

1215 {
1216  u32 device_id = its_cmd_get_deviceid(its_cmd);
1217  bool valid = its_cmd_get_validbit(its_cmd);
1218  u8 num_eventid_bits = its_cmd_get_size(its_cmd);
1219  gpa_t itt_addr = its_cmd_get_ittaddr(its_cmd);
1220  struct its_device *device;
1221 
1222  if (!vgic_its_check_id(its, its->baser_device_table, device_id, NULL))
1223  return E_ITS_MAPD_DEVICE_OOR;
1224 
1225  if (valid && num_eventid_bits > VITS_TYPER_IDBITS)
1226  return E_ITS_MAPD_ITTSIZE_OOR;
1227 
1228  device = find_its_device(its, device_id);
1229 
1230  /*
1231  * The spec says that calling MAPD on an already mapped device
1232  * invalidates all cached data for this device. We implement this
1233  * by removing the mapping and re-establishing it.
1234  */
1235  if (device)
1236  vgic_its_free_device(kvm, device);
1237 
1238  /*
1239  * The spec does not say whether unmapping a not-mapped device
1240  * is an error, so we are done in any case.
1241  */
1242  if (!valid)
1243  return 0;
1244 
1245  device = vgic_its_alloc_device(its, device_id, itt_addr,
1247 
1248  return PTR_ERR_OR_ZERO(device);
1249 }
u64 baser_device_table
Definition: arm_vgic.h:196
static struct its_device * vgic_its_alloc_device(struct vgic_its *its, u32 device_id, gpa_t itt_addr, u8 num_eventid_bits)
Definition: vgic-its.c:1190
#define its_cmd_get_size(cmd)
Definition: vgic-its.c:843
#define VITS_TYPER_IDBITS
Definition: vgic-its.c:250
static void vgic_its_free_device(struct kvm *kvm, struct its_device *device)
Definition: vgic-its.c:1153
#define its_cmd_get_ittaddr(cmd)
Definition: vgic-its.c:847
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_mapi()

static int vgic_its_cmd_handle_mapi ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1085 of file vgic-its.c.

1087 {
1088  u32 device_id = its_cmd_get_deviceid(its_cmd);
1089  u32 event_id = its_cmd_get_id(its_cmd);
1090  u32 coll_id = its_cmd_get_collection(its_cmd);
1091  struct its_ite *ite;
1092  struct kvm_vcpu *vcpu = NULL;
1093  struct its_device *device;
1094  struct its_collection *collection, *new_coll = NULL;
1095  struct vgic_irq *irq;
1096  int lpi_nr;
1097 
1098  device = find_its_device(its, device_id);
1099  if (!device)
1100  return E_ITS_MAPTI_UNMAPPED_DEVICE;
1101 
1102  if (!vgic_its_check_event_id(its, device, event_id))
1103  return E_ITS_MAPTI_ID_OOR;
1104 
1105  if (its_cmd_get_command(its_cmd) == GITS_CMD_MAPTI)
1106  lpi_nr = its_cmd_get_physical_id(its_cmd);
1107  else
1108  lpi_nr = event_id;
1109  if (lpi_nr < GIC_LPI_OFFSET ||
1110  lpi_nr >= max_lpis_propbaser(kvm->arch.vgic.propbaser))
1111  return E_ITS_MAPTI_PHYSICALID_OOR;
1112 
1113  /* If there is an existing mapping, behavior is UNPREDICTABLE. */
1114  if (find_ite(its, device_id, event_id))
1115  return 0;
1116 
1117  collection = find_collection(its, coll_id);
1118  if (!collection) {
1119  int ret;
1120 
1121  if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
1122  return E_ITS_MAPC_COLLECTION_OOR;
1123 
1124  ret = vgic_its_alloc_collection(its, &collection, coll_id);
1125  if (ret)
1126  return ret;
1127  new_coll = collection;
1128  }
1129 
1130  ite = vgic_its_alloc_ite(device, collection, event_id);
1131  if (IS_ERR(ite)) {
1132  if (new_coll)
1133  vgic_its_free_collection(its, coll_id);
1134  return PTR_ERR(ite);
1135  }
1136 
1137  if (its_is_collection_mapped(collection))
1138  vcpu = collection_to_vcpu(kvm, collection);
1139 
1140  irq = vgic_add_lpi(kvm, lpi_nr, vcpu);
1141  if (IS_ERR(irq)) {
1142  if (new_coll)
1143  vgic_its_free_collection(its, coll_id);
1144  its_free_ite(kvm, ite);
1145  return PTR_ERR(irq);
1146  }
1147  ite->irq = irq;
1148 
1149  return 0;
1150 }
static struct vgic_irq * vgic_add_lpi(struct kvm *kvm, u32 intid, struct kvm_vcpu *vcpu)
Definition: vgic-its.c:39
static u32 max_lpis_propbaser(u64 propbaser)
Definition: vgic-its.c:422
#define its_cmd_get_command(cmd)
Definition: vgic-its.c:841
static struct its_ite * vgic_its_alloc_ite(struct its_device *device, struct its_collection *collection, u32 event_id)
Definition: vgic-its.c:1064
static bool vgic_its_check_event_id(struct vgic_its *its, struct its_device *device, u32 event_id)
Definition: vgic-its.c:1001
#define its_cmd_get_physical_id(cmd)
Definition: vgic-its.c:845
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_movall()

static int vgic_its_cmd_handle_movall ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1414 of file vgic-its.c.

1416 {
1417  struct kvm_vcpu *vcpu1, *vcpu2;
1418  struct vgic_irq *irq;
1419  u32 *intids;
1420  int irq_count, i;
1421 
1422  /* We advertise GITS_TYPER.PTA==0, making the address the vcpu ID */
1423  vcpu1 = kvm_get_vcpu_by_id(kvm, its_cmd_get_target_addr(its_cmd));
1424  vcpu2 = kvm_get_vcpu_by_id(kvm, its_cmd_mask_field(its_cmd, 3, 16, 32));
1425 
1426  if (!vcpu1 || !vcpu2)
1427  return E_ITS_MOVALL_PROCNUM_OOR;
1428 
1429  if (vcpu1 == vcpu2)
1430  return 0;
1431 
1432  irq_count = vgic_copy_lpi_list(kvm, vcpu1, &intids);
1433  if (irq_count < 0)
1434  return irq_count;
1435 
1436  for (i = 0; i < irq_count; i++) {
1437  irq = vgic_get_irq(kvm, NULL, intids[i]);
1438  if (!irq)
1439  continue;
1440 
1441  update_affinity(irq, vcpu2);
1442 
1443  vgic_put_irq(kvm, irq);
1444  }
1445 
1447 
1448  kfree(intids);
1449  return 0;
1450 }
static u64 its_cmd_mask_field(u64 *its_cmd, int word, int shift, int size)
Definition: vgic-its.c:836
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_cmd_handle_movi()

static int vgic_its_cmd_handle_movi ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 882 of file vgic-its.c.

884 {
885  u32 device_id = its_cmd_get_deviceid(its_cmd);
886  u32 event_id = its_cmd_get_id(its_cmd);
887  u32 coll_id = its_cmd_get_collection(its_cmd);
888  struct kvm_vcpu *vcpu;
889  struct its_ite *ite;
890  struct its_collection *collection;
891 
892  ite = find_ite(its, device_id, event_id);
893  if (!ite)
894  return E_ITS_MOVI_UNMAPPED_INTERRUPT;
895 
897  return E_ITS_MOVI_UNMAPPED_COLLECTION;
898 
899  collection = find_collection(its, coll_id);
900  if (!its_is_collection_mapped(collection))
901  return E_ITS_MOVI_UNMAPPED_COLLECTION;
902 
903  ite->collection = collection;
904  vcpu = collection_to_vcpu(kvm, collection);
905 
907 
908  return update_affinity(ite->irq, vcpu);
909 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_commit_v0()

static int vgic_its_commit_v0 ( struct vgic_its its)
static

Definition at line 2720 of file vgic-its.c.

2721 {
2722  const struct vgic_its_abi *abi;
2723 
2724  abi = vgic_its_get_abi(its);
2725  its->baser_coll_table &= ~GITS_BASER_ENTRY_SIZE_MASK;
2726  its->baser_device_table &= ~GITS_BASER_ENTRY_SIZE_MASK;
2727 
2728  its->baser_coll_table |= (GIC_ENCODE_SZ(abi->cte_esz, 5)
2729  << GITS_BASER_ENTRY_SIZE_SHIFT);
2730 
2731  its->baser_device_table |= (GIC_ENCODE_SZ(abi->dte_esz, 5)
2732  << GITS_BASER_ENTRY_SIZE_SHIFT);
2733  return 0;
2734 }
Here is the call graph for this function:

◆ vgic_its_create()

static int vgic_its_create ( struct kvm_device *  dev,
u32  type 
)
static

Definition at line 1952 of file vgic-its.c.

1953 {
1954  int ret;
1955  struct vgic_its *its;
1956 
1957  if (type != KVM_DEV_TYPE_ARM_VGIC_ITS)
1958  return -ENODEV;
1959 
1960  its = kzalloc(sizeof(struct vgic_its), GFP_KERNEL_ACCOUNT);
1961  if (!its)
1962  return -ENOMEM;
1963 
1964  mutex_lock(&dev->kvm->arch.config_lock);
1965 
1966  if (vgic_initialized(dev->kvm)) {
1967  ret = vgic_v4_init(dev->kvm);
1968  if (ret < 0) {
1969  mutex_unlock(&dev->kvm->arch.config_lock);
1970  kfree(its);
1971  return ret;
1972  }
1973 
1975  }
1976 
1977  mutex_init(&its->its_lock);
1978  mutex_init(&its->cmd_lock);
1979 
1980  /* Yep, even more trickery for lock ordering... */
1981 #ifdef CONFIG_LOCKDEP
1982  mutex_lock(&its->cmd_lock);
1983  mutex_lock(&its->its_lock);
1984  mutex_unlock(&its->its_lock);
1985  mutex_unlock(&its->cmd_lock);
1986 #endif
1987 
1989 
1990  INIT_LIST_HEAD(&its->device_list);
1991  INIT_LIST_HEAD(&its->collection_list);
1992 
1993  dev->kvm->arch.vgic.msis_require_devid = true;
1994  dev->kvm->arch.vgic.has_its = true;
1995  its->enabled = false;
1996  its->dev = dev;
1997 
1999  ((u64)GITS_BASER_TYPE_DEVICE << GITS_BASER_TYPE_SHIFT);
2001  ((u64)GITS_BASER_TYPE_COLLECTION << GITS_BASER_TYPE_SHIFT);
2002  dev->kvm->arch.vgic.propbaser = INITIAL_PROPBASER_VALUE;
2003 
2004  dev->private = its;
2005 
2006  ret = vgic_its_set_abi(its, NR_ITS_ABIS - 1);
2007 
2008  mutex_unlock(&dev->kvm->arch.config_lock);
2009 
2010  return ret;
2011 }
#define vgic_initialized(k)
Definition: arm_vgic.h:393
struct mutex cmd_lock
Definition: arm_vgic.h:200
bool enabled
Definition: arm_vgic.h:191
struct mutex its_lock
Definition: arm_vgic.h:209
static int vgic_its_set_abi(struct vgic_its *its, u32 rev)
Definition: vgic-its.c:197
#define INITIAL_PROPBASER_VALUE
Definition: vgic-its.c:1947
#define INITIAL_BASER_VALUE
Definition: vgic-its.c:1941
void vgic_lpi_translation_cache_init(struct kvm *kvm)
Definition: vgic-its.c:1903
#define NR_ITS_ABIS
Definition: vgic-its.c:190
int vgic_v4_init(struct kvm *kvm)
Definition: vgic-v4.c:239
#define VGIC_ADDR_UNDEF
Definition: vgic.h:14
Here is the call graph for this function:

◆ vgic_its_ctrl()

static int vgic_its_ctrl ( struct kvm *  kvm,
struct vgic_its its,
u64  attr 
)
static

Definition at line 2777 of file vgic-its.c.

2778 {
2779  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2780  int ret = 0;
2781 
2782  if (attr == KVM_DEV_ARM_VGIC_CTRL_INIT) /* Nothing to do */
2783  return 0;
2784 
2785  mutex_lock(&kvm->lock);
2786 
2787  if (!lock_all_vcpus(kvm)) {
2788  mutex_unlock(&kvm->lock);
2789  return -EBUSY;
2790  }
2791 
2792  mutex_lock(&kvm->arch.config_lock);
2793  mutex_lock(&its->its_lock);
2794 
2795  switch (attr) {
2796  case KVM_DEV_ARM_ITS_CTRL_RESET:
2797  vgic_its_reset(kvm, its);
2798  break;
2799  case KVM_DEV_ARM_ITS_SAVE_TABLES:
2800  ret = abi->save_tables(its);
2801  break;
2802  case KVM_DEV_ARM_ITS_RESTORE_TABLES:
2803  ret = abi->restore_tables(its);
2804  break;
2805  }
2806 
2807  mutex_unlock(&its->its_lock);
2808  mutex_unlock(&kvm->arch.config_lock);
2809  unlock_all_vcpus(kvm);
2810  mutex_unlock(&kvm->lock);
2811  return ret;
2812 }
int(* save_tables)(struct vgic_its *its)
Definition: vgic-its.c:171
int(* restore_tables)(struct vgic_its *its)
Definition: vgic-its.c:172
static void vgic_its_reset(struct kvm *kvm, struct vgic_its *its)
Definition: vgic-its.c:2736
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_destroy()

static void vgic_its_destroy ( struct kvm_device *  kvm_dev)
static

Definition at line 2013 of file vgic-its.c.

2014 {
2015  struct kvm *kvm = kvm_dev->kvm;
2016  struct vgic_its *its = kvm_dev->private;
2017 
2018  mutex_lock(&its->its_lock);
2019 
2020  vgic_its_free_device_list(kvm, its);
2022 
2023  mutex_unlock(&its->its_lock);
2024  kfree(its);
2025  kfree(kvm_dev);/* alloc by kvm_ioctl_create_device, free by .destroy */
2026 }
static struct miscdevice kvm_dev
Definition: kvm_main.c:5514
static void vgic_its_free_collection_list(struct kvm *kvm, struct vgic_its *its)
Definition: vgic-its.c:1181
static void vgic_its_free_device_list(struct kvm *kvm, struct vgic_its *its)
Definition: vgic-its.c:1172
Here is the call graph for this function:

◆ vgic_its_device_cmp()

static int vgic_its_device_cmp ( void *  priv,
const struct list_head *  a,
const struct list_head *  b 
)
static

Definition at line 2431 of file vgic-its.c.

2433 {
2434  struct its_device *deva = container_of(a, struct its_device, dev_list);
2435  struct its_device *devb = container_of(b, struct its_device, dev_list);
2436 
2437  if (deva->device_id < devb->device_id)
2438  return -1;
2439  else
2440  return 1;
2441 }
Here is the caller graph for this function:

◆ vgic_its_free_collection()

static void vgic_its_free_collection ( struct vgic_its its,
u32  coll_id 
)
static

Definition at line 1039 of file vgic-its.c.

1040 {
1041  struct its_collection *collection;
1042  struct its_device *device;
1043  struct its_ite *ite;
1044 
1045  /*
1046  * Clearing the mapping for that collection ID removes the
1047  * entry from the list. If there wasn't any before, we can
1048  * go home early.
1049  */
1050  collection = find_collection(its, coll_id);
1051  if (!collection)
1052  return;
1053 
1054  for_each_lpi_its(device, ite, its)
1055  if (ite->collection &&
1056  ite->collection->collection_id == coll_id)
1057  ite->collection = NULL;
1058 
1059  list_del(&collection->coll_list);
1060  kfree(collection);
1061 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_free_collection_list()

static void vgic_its_free_collection_list ( struct kvm *  kvm,
struct vgic_its its 
)
static

Definition at line 1181 of file vgic-its.c.

1182 {
1183  struct its_collection *cur, *temp;
1184 
1185  list_for_each_entry_safe(cur, temp, &its->collection_list, coll_list)
1186  vgic_its_free_collection(its, cur->collection_id);
1187 }
static unsigned long cur
Definition: early_alloc.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_free_device()

static void vgic_its_free_device ( struct kvm *  kvm,
struct its_device device 
)
static

Definition at line 1153 of file vgic-its.c.

1154 {
1155  struct its_ite *ite, *temp;
1156 
1157  /*
1158  * The spec says that unmapping a device with still valid
1159  * ITTEs associated is UNPREDICTABLE. We remove all ITTEs,
1160  * since we cannot leave the memory unreferenced.
1161  */
1162  list_for_each_entry_safe(ite, temp, &device->itt_head, ite_list)
1163  its_free_ite(kvm, ite);
1164 
1166 
1167  list_del(&device->dev_list);
1168  kfree(device);
1169 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_free_device_list()

static void vgic_its_free_device_list ( struct kvm *  kvm,
struct vgic_its its 
)
static

Definition at line 1172 of file vgic-its.c.

1173 {
1174  struct its_device *cur, *temp;
1175 
1176  list_for_each_entry_safe(cur, temp, &its->device_list, dev_list)
1177  vgic_its_free_device(kvm, cur);
1178 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_get_abi()

const struct vgic_its_abi* vgic_its_get_abi ( struct vgic_its its)
inline

Definition at line 192 of file vgic-its.c.

193 {
194  return &its_table_abi_versions[its->abi_rev];
195 }
u32 abi_rev
Definition: arm_vgic.h:206
static const struct vgic_its_abi its_table_abi_versions[]
Definition: vgic-its.c:179
Here is the caller graph for this function:

◆ vgic_its_get_attr()

static int vgic_its_get_attr ( struct kvm_device *  dev,
struct kvm_device_attr *  attr 
)
static

Definition at line 2871 of file vgic-its.c.

2873 {
2874  switch (attr->group) {
2875  case KVM_DEV_ARM_VGIC_GRP_ADDR: {
2876  struct vgic_its *its = dev->private;
2877  u64 addr = its->vgic_its_base;
2878  u64 __user *uaddr = (u64 __user *)(long)attr->addr;
2879  unsigned long type = (unsigned long)attr->attr;
2880 
2881  if (type != KVM_VGIC_ITS_ADDR_TYPE)
2882  return -ENODEV;
2883 
2884  if (copy_to_user(uaddr, &addr, sizeof(addr)))
2885  return -EFAULT;
2886  break;
2887  }
2888  case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
2889  u64 __user *uaddr = (u64 __user *)(long)attr->addr;
2890  u64 reg;
2891  int ret;
2892 
2893  ret = vgic_its_attr_regs_access(dev, attr, &reg, false);
2894  if (ret)
2895  return ret;
2896  return put_user(reg, uaddr);
2897  }
2898  default:
2899  return -ENXIO;
2900  }
2901 
2902  return 0;
2903 }
static int vgic_its_attr_regs_access(struct kvm_device *dev, struct kvm_device_attr *attr, u64 *reg, bool is_write)
Definition: vgic-its.c:2049

◆ vgic_its_handle_command()

static int vgic_its_handle_command ( struct kvm *  kvm,
struct vgic_its its,
u64 *  its_cmd 
)
static

Definition at line 1469 of file vgic-its.c.

1471 {
1472  int ret = -ENODEV;
1473 
1474  mutex_lock(&its->its_lock);
1475  switch (its_cmd_get_command(its_cmd)) {
1476  case GITS_CMD_MAPD:
1477  ret = vgic_its_cmd_handle_mapd(kvm, its, its_cmd);
1478  break;
1479  case GITS_CMD_MAPC:
1480  ret = vgic_its_cmd_handle_mapc(kvm, its, its_cmd);
1481  break;
1482  case GITS_CMD_MAPI:
1483  ret = vgic_its_cmd_handle_mapi(kvm, its, its_cmd);
1484  break;
1485  case GITS_CMD_MAPTI:
1486  ret = vgic_its_cmd_handle_mapi(kvm, its, its_cmd);
1487  break;
1488  case GITS_CMD_MOVI:
1489  ret = vgic_its_cmd_handle_movi(kvm, its, its_cmd);
1490  break;
1491  case GITS_CMD_DISCARD:
1492  ret = vgic_its_cmd_handle_discard(kvm, its, its_cmd);
1493  break;
1494  case GITS_CMD_CLEAR:
1495  ret = vgic_its_cmd_handle_clear(kvm, its, its_cmd);
1496  break;
1497  case GITS_CMD_MOVALL:
1498  ret = vgic_its_cmd_handle_movall(kvm, its, its_cmd);
1499  break;
1500  case GITS_CMD_INT:
1501  ret = vgic_its_cmd_handle_int(kvm, its, its_cmd);
1502  break;
1503  case GITS_CMD_INV:
1504  ret = vgic_its_cmd_handle_inv(kvm, its, its_cmd);
1505  break;
1506  case GITS_CMD_INVALL:
1507  ret = vgic_its_cmd_handle_invall(kvm, its, its_cmd);
1508  break;
1509  case GITS_CMD_SYNC:
1510  /* we ignore this command: we are in sync all of the time */
1511  ret = 0;
1512  break;
1513  }
1514  mutex_unlock(&its->its_lock);
1515 
1516  return ret;
1517 }
static int vgic_its_cmd_handle_inv(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1332
static int vgic_its_cmd_handle_clear(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1302
static int vgic_its_cmd_handle_movall(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1414
static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:855
static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1213
static int vgic_its_cmd_handle_mapc(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1255
static int vgic_its_cmd_handle_movi(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:882
static int vgic_its_cmd_handle_int(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1456
static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1085
static int vgic_its_cmd_handle_invall(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1389
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_has_attr()

static int vgic_its_has_attr ( struct kvm_device *  dev,
struct kvm_device_attr *  attr 
)
static

Definition at line 2749 of file vgic-its.c.

2751 {
2752  switch (attr->group) {
2753  case KVM_DEV_ARM_VGIC_GRP_ADDR:
2754  switch (attr->attr) {
2755  case KVM_VGIC_ITS_ADDR_TYPE:
2756  return 0;
2757  }
2758  break;
2759  case KVM_DEV_ARM_VGIC_GRP_CTRL:
2760  switch (attr->attr) {
2761  case KVM_DEV_ARM_VGIC_CTRL_INIT:
2762  return 0;
2763  case KVM_DEV_ARM_ITS_CTRL_RESET:
2764  return 0;
2765  case KVM_DEV_ARM_ITS_SAVE_TABLES:
2766  return 0;
2767  case KVM_DEV_ARM_ITS_RESTORE_TABLES:
2768  return 0;
2769  }
2770  break;
2771  case KVM_DEV_ARM_VGIC_GRP_ITS_REGS:
2772  return vgic_its_has_attr_regs(dev, attr);
2773  }
2774  return -ENXIO;
2775 }
static int vgic_its_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr)
Definition: vgic-its.c:2028
Here is the call graph for this function:

◆ vgic_its_has_attr_regs()

static int vgic_its_has_attr_regs ( struct kvm_device *  dev,
struct kvm_device_attr *  attr 
)
static

Definition at line 2028 of file vgic-its.c.

2030 {
2031  const struct vgic_register_region *region;
2032  gpa_t offset = attr->attr;
2033  int align;
2034 
2035  align = (offset < GITS_TYPER) || (offset >= GITS_PIDR4) ? 0x3 : 0x7;
2036 
2037  if (offset & align)
2038  return -EINVAL;
2039 
2041  ARRAY_SIZE(its_registers),
2042  offset);
2043  if (!region)
2044  return -ENXIO;
2045 
2046  return 0;
2047 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_inject_cached_translation()

int vgic_its_inject_cached_translation ( struct kvm *  kvm,
struct kvm_msi *  msi 
)

Definition at line 765 of file vgic-its.c.

766 {
767  struct vgic_irq *irq;
768  unsigned long flags;
769  phys_addr_t db;
770 
771  db = (u64)msi->address_hi << 32 | msi->address_lo;
772  irq = vgic_its_check_cache(kvm, db, msi->devid, msi->data);
773  if (!irq)
774  return -EWOULDBLOCK;
775 
776  raw_spin_lock_irqsave(&irq->irq_lock, flags);
777  irq->pending_latch = true;
778  vgic_queue_irq_unlock(kvm, irq, flags);
779  vgic_put_irq(kvm, irq);
780 
781  return 0;
782 }
static struct vgic_irq * vgic_its_check_cache(struct kvm *kvm, phys_addr_t db, u32 devid, u32 eventid)
Definition: vgic-its.c:588
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_inject_msi()

int vgic_its_inject_msi ( struct kvm *  kvm,
struct kvm_msi *  msi 
)

Definition at line 790 of file vgic-its.c.

791 {
792  struct vgic_its *its;
793  int ret;
794 
795  if (!vgic_its_inject_cached_translation(kvm, msi))
796  return 1;
797 
798  its = vgic_msi_to_its(kvm, msi);
799  if (IS_ERR(its))
800  return PTR_ERR(its);
801 
802  mutex_lock(&its->its_lock);
803  ret = vgic_its_trigger_msi(kvm, its, msi->devid, msi->data);
804  mutex_unlock(&its->its_lock);
805 
806  if (ret < 0)
807  return ret;
808 
809  /*
810  * KVM_SIGNAL_MSI demands a return value > 0 for success and 0
811  * if the guest has blocked the MSI. So we map any LPI mapping
812  * related error to that.
813  */
814  if (ret)
815  return 0;
816  else
817  return 1;
818 }
int vgic_its_inject_cached_translation(struct kvm *kvm, struct kvm_msi *msi)
Definition: vgic-its.c:765
struct vgic_its * vgic_msi_to_its(struct kvm *kvm, struct kvm_msi *msi)
Definition: vgic-its.c:708
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_inv_lpi()

int vgic_its_inv_lpi ( struct kvm *  kvm,
struct vgic_irq irq 
)

Definition at line 1323 of file vgic-its.c.

1324 {
1325  return update_lpi_config(kvm, irq, NULL, true);
1326 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_invalidate_cache()

void vgic_its_invalidate_cache ( struct kvm *  kvm)

Definition at line 659 of file vgic-its.c.

660 {
661  struct vgic_dist *dist = &kvm->arch.vgic;
662  struct vgic_translation_cache_entry *cte;
663  unsigned long flags;
664 
665  raw_spin_lock_irqsave(&dist->lpi_list_lock, flags);
666 
667  list_for_each_entry(cte, &dist->lpi_translation_cache, entry) {
668  /*
669  * If we hit a NULL entry, there is nothing after this
670  * point.
671  */
672  if (!cte->irq)
673  break;
674 
675  __vgic_put_lpi_locked(kvm, cte->irq);
676  cte->irq = NULL;
677  }
678 
679  raw_spin_unlock_irqrestore(&dist->lpi_list_lock, flags);
680 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_invall()

int vgic_its_invall ( struct kvm_vcpu *  vcpu)

vgic_its_invall - invalidate all LPIs targetting a given vcpu @vcpu: the vcpu for which the RD is targetted by an invalidation

Contrary to the INVALL command, this targets a RD instead of a collection, and we don't need to hold the its_lock, since no ITS is involved here.

Definition at line 1355 of file vgic-its.c.

1356 {
1357  struct kvm *kvm = vcpu->kvm;
1358  int irq_count, i = 0;
1359  u32 *intids;
1360 
1361  irq_count = vgic_copy_lpi_list(kvm, vcpu, &intids);
1362  if (irq_count < 0)
1363  return irq_count;
1364 
1365  for (i = 0; i < irq_count; i++) {
1366  struct vgic_irq *irq = vgic_get_irq(kvm, NULL, intids[i]);
1367  if (!irq)
1368  continue;
1369  update_lpi_config(kvm, irq, vcpu, false);
1370  vgic_put_irq(kvm, irq);
1371  }
1372 
1373  kfree(intids);
1374 
1375  if (vcpu->arch.vgic_cpu.vgic_v3.its_vpe.its_vm)
1376  its_invall_vpe(&vcpu->arch.vgic_cpu.vgic_v3.its_vpe);
1377 
1378  return 0;
1379 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_ite_cmp()

static int vgic_its_ite_cmp ( void *  priv,
const struct list_head *  a,
const struct list_head *  b 
)
static

Definition at line 2288 of file vgic-its.c.

2290 {
2291  struct its_ite *itea = container_of(a, struct its_ite, ite_list);
2292  struct its_ite *iteb = container_of(b, struct its_ite, ite_list);
2293 
2294  if (itea->event_id < iteb->event_id)
2295  return -1;
2296  else
2297  return 1;
2298 }
Here is the caller graph for this function:

◆ vgic_its_process_commands()

static void vgic_its_process_commands ( struct kvm *  kvm,
struct vgic_its its 
)
static

Definition at line 1587 of file vgic-its.c.

1588 {
1589  gpa_t cbaser;
1590  u64 cmd_buf[4];
1591 
1592  /* Commands are only processed when the ITS is enabled. */
1593  if (!its->enabled)
1594  return;
1595 
1596  cbaser = GITS_CBASER_ADDRESS(its->cbaser);
1597 
1598  while (its->cwriter != its->creadr) {
1599  int ret = kvm_read_guest_lock(kvm, cbaser + its->creadr,
1600  cmd_buf, ITS_CMD_SIZE);
1601  /*
1602  * If kvm_read_guest() fails, this could be due to the guest
1603  * programming a bogus value in CBASER or something else going
1604  * wrong from which we cannot easily recover.
1605  * According to section 6.3.2 in the GICv3 spec we can just
1606  * ignore that command then.
1607  */
1608  if (!ret)
1609  vgic_its_handle_command(kvm, its, cmd_buf);
1610 
1611  its->creadr += ITS_CMD_SIZE;
1612  if (its->creadr == ITS_CMD_BUFFER_SIZE(its->cbaser))
1613  its->creadr = 0;
1614  }
1615 }
u32 cwriter
Definition: arm_vgic.h:203
u32 creadr
Definition: arm_vgic.h:202
u64 cbaser
Definition: arm_vgic.h:201
#define ITS_CMD_SIZE
Definition: vgic-its.c:1583
static int vgic_its_handle_command(struct kvm *kvm, struct vgic_its *its, u64 *its_cmd)
Definition: vgic-its.c:1469
#define ITS_CMD_BUFFER_SIZE(baser)
Definition: vgic-its.c:1582
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_reset()

static void vgic_its_reset ( struct kvm *  kvm,
struct vgic_its its 
)
static

Definition at line 2736 of file vgic-its.c.

2737 {
2738  /* We need to keep the ABI specific field values */
2739  its->baser_coll_table &= ~GITS_BASER_VALID;
2740  its->baser_device_table &= ~GITS_BASER_VALID;
2741  its->cbaser = 0;
2742  its->creadr = 0;
2743  its->cwriter = 0;
2744  its->enabled = 0;
2745  vgic_its_free_device_list(kvm, its);
2747 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_resolve_lpi()

int vgic_its_resolve_lpi ( struct kvm *  kvm,
struct vgic_its its,
u32  devid,
u32  eventid,
struct vgic_irq **  irq 
)

Definition at line 682 of file vgic-its.c.

684 {
685  struct kvm_vcpu *vcpu;
686  struct its_ite *ite;
687 
688  if (!its->enabled)
689  return -EBUSY;
690 
691  ite = find_ite(its, devid, eventid);
692  if (!ite || !its_is_collection_mapped(ite->collection))
693  return E_ITS_INT_UNMAPPED_INTERRUPT;
694 
695  vcpu = collection_to_vcpu(kvm, ite->collection);
696  if (!vcpu)
697  return E_ITS_INT_UNMAPPED_INTERRUPT;
698 
699  if (!vgic_lpis_enabled(vcpu))
700  return -EBUSY;
701 
702  vgic_its_cache_translation(kvm, its, devid, eventid, ite->irq);
703 
704  *irq = ite->irq;
705  return 0;
706 }
static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq *irq)
Definition: vgic-its.c:606
bool vgic_lpis_enabled(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:238
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_collection_table()

static int vgic_its_restore_collection_table ( struct vgic_its its)
static

vgic_its_restore_collection_table - reads the collection table in guest memory and restores the ITS internal state. Requires the BASER registers to be restored before.

Definition at line 2653 of file vgic-its.c.

2654 {
2655  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2656  u64 baser = its->baser_coll_table;
2657  int cte_esz = abi->cte_esz;
2658  size_t max_size, read = 0;
2659  gpa_t gpa;
2660  int ret;
2661 
2662  if (!(baser & GITS_BASER_VALID))
2663  return 0;
2664 
2665  gpa = GITS_BASER_ADDR_48_to_52(baser);
2666 
2667  max_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
2668 
2669  while (read < max_size) {
2670  ret = vgic_its_restore_cte(its, gpa, cte_esz);
2671  if (ret <= 0)
2672  break;
2673  gpa += cte_esz;
2674  read += cte_esz;
2675  }
2676 
2677  if (ret > 0)
2678  return 0;
2679 
2680  if (ret < 0)
2681  vgic_its_free_collection_list(its->dev->kvm, its);
2682 
2683  return ret;
2684 }
static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)
Definition: vgic-its.c:2571
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_cte()

static int vgic_its_restore_cte ( struct vgic_its its,
gpa_t  gpa,
int  esz 
)
static

Definition at line 2571 of file vgic-its.c.

2572 {
2573  struct its_collection *collection;
2574  struct kvm *kvm = its->dev->kvm;
2575  u32 target_addr, coll_id;
2576  u64 val;
2577  int ret;
2578 
2579  BUG_ON(esz > sizeof(val));
2580  ret = kvm_read_guest_lock(kvm, gpa, &val, esz);
2581  if (ret)
2582  return ret;
2583  val = le64_to_cpu(val);
2584  if (!(val & KVM_ITS_CTE_VALID_MASK))
2585  return 0;
2586 
2587  target_addr = (u32)(val >> KVM_ITS_CTE_RDBASE_SHIFT);
2588  coll_id = val & KVM_ITS_CTE_ICID_MASK;
2589 
2590  if (target_addr != COLLECTION_NOT_MAPPED &&
2591  !kvm_get_vcpu_by_id(kvm, target_addr))
2592  return -EINVAL;
2593 
2594  collection = find_collection(its, coll_id);
2595  if (collection)
2596  return -EEXIST;
2597 
2598  if (!vgic_its_check_id(its, its->baser_coll_table, coll_id, NULL))
2599  return -EINVAL;
2600 
2601  ret = vgic_its_alloc_collection(its, &collection, coll_id);
2602  if (ret)
2603  return ret;
2604  collection->target_addr = target_addr;
2605  return 1;
2606 }
#define KVM_ITS_CTE_VALID_MASK
Definition: vgic.h:71
#define KVM_ITS_CTE_RDBASE_SHIFT
Definition: vgic.h:72
#define KVM_ITS_CTE_ICID_MASK
Definition: vgic.h:73
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_device_tables()

static int vgic_its_restore_device_tables ( struct vgic_its its)
static

vgic_its_restore_device_tables - Restore the device table and all ITT from guest RAM to internal data structs

Definition at line 2520 of file vgic-its.c.

2521 {
2522  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2523  u64 baser = its->baser_device_table;
2524  int l1_esz, ret;
2525  int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
2526  gpa_t l1_gpa;
2527 
2528  if (!(baser & GITS_BASER_VALID))
2529  return 0;
2530 
2531  l1_gpa = GITS_BASER_ADDR_48_to_52(baser);
2532 
2533  if (baser & GITS_BASER_INDIRECT) {
2534  l1_esz = GITS_LVL1_ENTRY_SIZE;
2535  ret = scan_its_table(its, l1_gpa, l1_tbl_size, l1_esz, 0,
2536  handle_l1_dte, NULL);
2537  } else {
2538  l1_esz = abi->dte_esz;
2539  ret = scan_its_table(its, l1_gpa, l1_tbl_size, l1_esz, 0,
2540  vgic_its_restore_dte, NULL);
2541  }
2542 
2543  /* scan_its_table returns +1 if all entries are invalid */
2544  if (ret > 0)
2545  ret = 0;
2546 
2547  if (ret < 0)
2548  vgic_its_free_device_list(its->dev->kvm, its);
2549 
2550  return ret;
2551 }
static int handle_l1_dte(struct vgic_its *its, u32 id, void *addr, void *opaque)
Definition: vgic-its.c:2493
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_dte()

static int vgic_its_restore_dte ( struct vgic_its its,
u32  id,
void *  ptr,
void *  opaque 
)
static

vgic_its_restore_dte - restore a device table entry

@its: its handle @id: device id the DTE corresponds to @ptr: kernel VA where the 8 byte DTE is located @opaque: unused

Return: < 0 on error, 0 if the dte is the last one, id offset to the next dte otherwise

Definition at line 2390 of file vgic-its.c.

2392 {
2393  struct its_device *dev;
2394  u64 baser = its->baser_device_table;
2395  gpa_t itt_addr;
2396  u8 num_eventid_bits;
2397  u64 entry = *(u64 *)ptr;
2398  bool valid;
2399  u32 offset;
2400  int ret;
2401 
2402  entry = le64_to_cpu(entry);
2403 
2404  valid = entry >> KVM_ITS_DTE_VALID_SHIFT;
2405  num_eventid_bits = (entry & KVM_ITS_DTE_SIZE_MASK) + 1;
2406  itt_addr = ((entry & KVM_ITS_DTE_ITTADDR_MASK)
2407  >> KVM_ITS_DTE_ITTADDR_SHIFT) << 8;
2408 
2409  if (!valid)
2410  return 1;
2411 
2412  /* dte entry is valid */
2413  offset = (entry & KVM_ITS_DTE_NEXT_MASK) >> KVM_ITS_DTE_NEXT_SHIFT;
2414 
2415  if (!vgic_its_check_id(its, baser, id, NULL))
2416  return -EINVAL;
2417 
2419  if (IS_ERR(dev))
2420  return PTR_ERR(dev);
2421 
2422  ret = vgic_its_restore_itt(its, dev);
2423  if (ret) {
2424  vgic_its_free_device(its->dev->kvm, dev);
2425  return ret;
2426  }
2427 
2428  return offset;
2429 }
static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)
Definition: vgic-its.c:2337
#define KVM_ITS_DTE_NEXT_SHIFT
Definition: vgic.h:80
#define KVM_ITS_DTE_SIZE_MASK
Definition: vgic.h:84
#define KVM_ITS_DTE_ITTADDR_SHIFT
Definition: vgic.h:82
#define KVM_ITS_DTE_ITTADDR_MASK
Definition: vgic.h:83
#define KVM_ITS_DTE_NEXT_MASK
Definition: vgic.h:81
#define KVM_ITS_DTE_VALID_SHIFT
Definition: vgic.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_ite()

static int vgic_its_restore_ite ( struct vgic_its its,
u32  event_id,
void *  ptr,
void *  opaque 
)
static

vgic_its_restore_ite - restore an interrupt translation entry @event_id: id used for indexing @ptr: pointer to the ITE entry @opaque: pointer to the its_device

Definition at line 2233 of file vgic-its.c.

2235 {
2236  struct its_device *dev = opaque;
2237  struct its_collection *collection;
2238  struct kvm *kvm = its->dev->kvm;
2239  struct kvm_vcpu *vcpu = NULL;
2240  u64 val;
2241  u64 *p = (u64 *)ptr;
2242  struct vgic_irq *irq;
2243  u32 coll_id, lpi_id;
2244  struct its_ite *ite;
2245  u32 offset;
2246 
2247  val = *p;
2248 
2249  val = le64_to_cpu(val);
2250 
2251  coll_id = val & KVM_ITS_ITE_ICID_MASK;
2253 
2254  if (!lpi_id)
2255  return 1; /* invalid entry, no choice but to scan next entry */
2256 
2257  if (lpi_id < VGIC_MIN_LPI)
2258  return -EINVAL;
2259 
2260  offset = val >> KVM_ITS_ITE_NEXT_SHIFT;
2261  if (event_id + offset >= BIT_ULL(dev->num_eventid_bits))
2262  return -EINVAL;
2263 
2264  collection = find_collection(its, coll_id);
2265  if (!collection)
2266  return -EINVAL;
2267 
2268  if (!vgic_its_check_event_id(its, dev, event_id))
2269  return -EINVAL;
2270 
2271  ite = vgic_its_alloc_ite(dev, collection, event_id);
2272  if (IS_ERR(ite))
2273  return PTR_ERR(ite);
2274 
2276  vcpu = kvm_get_vcpu_by_id(kvm, collection->target_addr);
2277 
2278  irq = vgic_add_lpi(kvm, lpi_id, vcpu);
2279  if (IS_ERR(irq)) {
2280  its_free_ite(kvm, ite);
2281  return PTR_ERR(irq);
2282  }
2283  ite->irq = irq;
2284 
2285  return offset;
2286 }
#define VGIC_MIN_LPI
Definition: arm_vgic.h:31
#define KVM_ITS_ITE_ICID_MASK
Definition: vgic.h:77
#define KVM_ITS_ITE_NEXT_SHIFT
Definition: vgic.h:74
#define KVM_ITS_ITE_PINTID_MASK
Definition: vgic.h:76
#define KVM_ITS_ITE_PINTID_SHIFT
Definition: vgic.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_itt()

static int vgic_its_restore_itt ( struct vgic_its its,
struct its_device dev 
)
static

vgic_its_restore_itt - restore the ITT of a device

@its: its handle @dev: device handle

Return 0 on success, < 0 on error

Definition at line 2337 of file vgic-its.c.

2338 {
2339  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2340  gpa_t base = dev->itt_addr;
2341  int ret;
2342  int ite_esz = abi->ite_esz;
2343  size_t max_size = BIT_ULL(dev->num_eventid_bits) * ite_esz;
2344 
2345  ret = scan_its_table(its, base, max_size, ite_esz, 0,
2346  vgic_its_restore_ite, dev);
2347 
2348  /* scan_its_table returns +1 if all ITEs are invalid */
2349  if (ret > 0)
2350  ret = 0;
2351 
2352  return ret;
2353 }
static int vgic_its_restore_ite(struct vgic_its *its, u32 event_id, void *ptr, void *opaque)
Definition: vgic-its.c:2233
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_restore_tables_v0()

static int vgic_its_restore_tables_v0 ( struct vgic_its its)
static

vgic_its_restore_tables_v0 - Restore the ITS tables from guest RAM to internal data structs according to V0 ABI

Definition at line 2706 of file vgic-its.c.

2707 {
2708  int ret;
2709 
2711  if (ret)
2712  return ret;
2713 
2714  ret = vgic_its_restore_device_tables(its);
2715  if (ret)
2716  vgic_its_free_collection_list(its->dev->kvm, its);
2717  return ret;
2718 }
static int vgic_its_restore_collection_table(struct vgic_its *its)
Definition: vgic-its.c:2653
static int vgic_its_restore_device_tables(struct vgic_its *its)
Definition: vgic-its.c:2520
Here is the call graph for this function:

◆ vgic_its_save_collection_table()

static int vgic_its_save_collection_table ( struct vgic_its its)
static

vgic_its_save_collection_table - Save the collection table into guest RAM

Definition at line 2612 of file vgic-its.c.

2613 {
2614  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2615  u64 baser = its->baser_coll_table;
2616  gpa_t gpa = GITS_BASER_ADDR_48_to_52(baser);
2617  struct its_collection *collection;
2618  u64 val;
2619  size_t max_size, filled = 0;
2620  int ret, cte_esz = abi->cte_esz;
2621 
2622  if (!(baser & GITS_BASER_VALID))
2623  return 0;
2624 
2625  max_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
2626 
2627  list_for_each_entry(collection, &its->collection_list, coll_list) {
2628  ret = vgic_its_save_cte(its, collection, gpa, cte_esz);
2629  if (ret)
2630  return ret;
2631  gpa += cte_esz;
2632  filled += cte_esz;
2633  }
2634 
2635  if (filled == max_size)
2636  return 0;
2637 
2638  /*
2639  * table is not fully filled, add a last dummy element
2640  * with valid bit unset
2641  */
2642  val = 0;
2643  BUG_ON(cte_esz > sizeof(val));
2644  ret = vgic_write_guest_lock(its->dev->kvm, gpa, &val, cte_esz);
2645  return ret;
2646 }
static int vgic_its_save_cte(struct vgic_its *its, struct its_collection *collection, gpa_t gpa, int esz)
Definition: vgic-its.c:2553
static int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa, const void *data, unsigned long len)
Definition: vgic.h:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_cte()

static int vgic_its_save_cte ( struct vgic_its its,
struct its_collection collection,
gpa_t  gpa,
int  esz 
)
static

Definition at line 2553 of file vgic-its.c.

2556 {
2557  u64 val;
2558 
2559  val = (1ULL << KVM_ITS_CTE_VALID_SHIFT |
2560  ((u64)collection->target_addr << KVM_ITS_CTE_RDBASE_SHIFT) |
2561  collection->collection_id);
2562  val = cpu_to_le64(val);
2563  return vgic_write_guest_lock(its->dev->kvm, gpa, &val, esz);
2564 }
#define KVM_ITS_CTE_VALID_SHIFT
Definition: vgic.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_device_tables()

static int vgic_its_save_device_tables ( struct vgic_its its)
static

vgic_its_save_device_tables - Save the device table and all ITT into guest RAM

L1/L2 handling is hidden by vgic_its_check_id() helper which directly returns the GPA of the device entry

Definition at line 2450 of file vgic-its.c.

2451 {
2452  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2453  u64 baser = its->baser_device_table;
2454  struct its_device *dev;
2455  int dte_esz = abi->dte_esz;
2456 
2457  if (!(baser & GITS_BASER_VALID))
2458  return 0;
2459 
2460  list_sort(NULL, &its->device_list, vgic_its_device_cmp);
2461 
2462  list_for_each_entry(dev, &its->device_list, dev_list) {
2463  int ret;
2464  gpa_t eaddr;
2465 
2466  if (!vgic_its_check_id(its, baser,
2467  dev->device_id, &eaddr))
2468  return -EINVAL;
2469 
2470  ret = vgic_its_save_itt(its, dev);
2471  if (ret)
2472  return ret;
2473 
2474  ret = vgic_its_save_dte(its, dev, eaddr, dte_esz);
2475  if (ret)
2476  return ret;
2477  }
2478  return 0;
2479 }
static int vgic_its_device_cmp(void *priv, const struct list_head *a, const struct list_head *b)
Definition: vgic-its.c:2431
static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, gpa_t ptr, int dte_esz)
Definition: vgic-its.c:2362
static int vgic_its_save_itt(struct vgic_its *its, struct its_device *device)
Definition: vgic-its.c:2300
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_dte()

static int vgic_its_save_dte ( struct vgic_its its,
struct its_device dev,
gpa_t  ptr,
int  dte_esz 
)
static

vgic_its_save_dte - Save a device table entry at a given GPA

@its: ITS handle @dev: ITS device @ptr: GPA

Definition at line 2362 of file vgic-its.c.

2364 {
2365  struct kvm *kvm = its->dev->kvm;
2366  u64 val, itt_addr_field;
2367  u32 next_offset;
2368 
2369  itt_addr_field = dev->itt_addr >> 8;
2370  next_offset = compute_next_devid_offset(&its->device_list, dev);
2371  val = (1ULL << KVM_ITS_DTE_VALID_SHIFT |
2372  ((u64)next_offset << KVM_ITS_DTE_NEXT_SHIFT) |
2373  (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) |
2374  (dev->num_eventid_bits - 1));
2375  val = cpu_to_le64(val);
2376  return vgic_write_guest_lock(kvm, ptr, &val, dte_esz);
2377 }
static u32 compute_next_devid_offset(struct list_head *h, struct its_device *dev)
Definition: vgic-its.c:2119
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_ite()

static int vgic_its_save_ite ( struct vgic_its its,
struct its_device dev,
struct its_ite ite,
gpa_t  gpa,
int  ite_esz 
)
static

vgic_its_save_ite - Save an interrupt translation entry at @gpa

Definition at line 2212 of file vgic-its.c.

2214 {
2215  struct kvm *kvm = its->dev->kvm;
2216  u32 next_offset;
2217  u64 val;
2218 
2219  next_offset = compute_next_eventid_offset(&dev->itt_head, ite);
2220  val = ((u64)next_offset << KVM_ITS_ITE_NEXT_SHIFT) |
2221  ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) |
2222  ite->collection->collection_id;
2223  val = cpu_to_le64(val);
2224  return vgic_write_guest_lock(kvm, gpa, &val, ite_esz);
2225 }
static u32 compute_next_eventid_offset(struct list_head *h, struct its_ite *ite)
Definition: vgic-its.c:2133
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_itt()

static int vgic_its_save_itt ( struct vgic_its its,
struct its_device device 
)
static

Definition at line 2300 of file vgic-its.c.

2301 {
2302  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2303  gpa_t base = device->itt_addr;
2304  struct its_ite *ite;
2305  int ret;
2306  int ite_esz = abi->ite_esz;
2307 
2308  list_sort(NULL, &device->itt_head, vgic_its_ite_cmp);
2309 
2310  list_for_each_entry(ite, &device->itt_head, ite_list) {
2311  gpa_t gpa = base + ite->event_id * ite_esz;
2312 
2313  /*
2314  * If an LPI carries the HW bit, this means that this
2315  * interrupt is controlled by GICv4, and we do not
2316  * have direct access to that state without GICv4.1.
2317  * Let's simply fail the save operation...
2318  */
2319  if (ite->irq->hw && !kvm_vgic_global_state.has_gicv4_1)
2320  return -EACCES;
2321 
2322  ret = vgic_its_save_ite(its, device, ite, gpa, ite_esz);
2323  if (ret)
2324  return ret;
2325  }
2326  return 0;
2327 }
struct vgic_global kvm_vgic_global_state
bool has_gicv4_1
Definition: arm_vgic.h:75
static int vgic_its_ite_cmp(void *priv, const struct list_head *a, const struct list_head *b)
Definition: vgic-its.c:2288
static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, struct its_ite *ite, gpa_t gpa, int ite_esz)
Definition: vgic-its.c:2212
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_save_tables_v0()

static int vgic_its_save_tables_v0 ( struct vgic_its its)
static

vgic_its_save_tables_v0 - Save the ITS tables into guest ARM according to v0 ABI

Definition at line 2690 of file vgic-its.c.

2691 {
2692  int ret;
2693 
2694  ret = vgic_its_save_device_tables(its);
2695  if (ret)
2696  return ret;
2697 
2698  return vgic_its_save_collection_table(its);
2699 }
static int vgic_its_save_collection_table(struct vgic_its *its)
Definition: vgic-its.c:2612
static int vgic_its_save_device_tables(struct vgic_its *its)
Definition: vgic-its.c:2450
Here is the call graph for this function:

◆ vgic_its_set_abi()

static int vgic_its_set_abi ( struct vgic_its its,
u32  rev 
)
static

Definition at line 197 of file vgic-its.c.

198 {
199  const struct vgic_its_abi *abi;
200 
201  its->abi_rev = rev;
202  abi = vgic_its_get_abi(its);
203  return abi->commit(its);
204 }
int(* commit)(struct vgic_its *its)
Definition: vgic-its.c:173
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_its_set_attr()

static int vgic_its_set_attr ( struct kvm_device *  dev,
struct kvm_device_attr *  attr 
)
static

Definition at line 2831 of file vgic-its.c.

2833 {
2834  struct vgic_its *its = dev->private;
2835  int ret;
2836 
2837  switch (attr->group) {
2838  case KVM_DEV_ARM_VGIC_GRP_ADDR: {
2839  u64 __user *uaddr = (u64 __user *)(long)attr->addr;
2840  unsigned long type = (unsigned long)attr->attr;
2841  u64 addr;
2842 
2843  if (type != KVM_VGIC_ITS_ADDR_TYPE)
2844  return -ENODEV;
2845 
2846  if (copy_from_user(&addr, uaddr, sizeof(addr)))
2847  return -EFAULT;
2848 
2849  ret = vgic_check_iorange(dev->kvm, its->vgic_its_base,
2850  addr, SZ_64K, KVM_VGIC_V3_ITS_SIZE);
2851  if (ret)
2852  return ret;
2853 
2854  return vgic_register_its_iodev(dev->kvm, its, addr);
2855  }
2856  case KVM_DEV_ARM_VGIC_GRP_CTRL:
2857  return vgic_its_ctrl(dev->kvm, its, attr->attr);
2858  case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: {
2859  u64 __user *uaddr = (u64 __user *)(long)attr->addr;
2860  u64 reg;
2861 
2862  if (get_user(reg, uaddr))
2863  return -EFAULT;
2864 
2865  return vgic_its_attr_regs_access(dev, attr, &reg, true);
2866  }
2867  }
2868  return -ENXIO;
2869 }
static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its, u64 addr)
Definition: vgic-its.c:1872
static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
Definition: vgic-its.c:2777
int vgic_check_iorange(struct kvm *kvm, phys_addr_t ioaddr, phys_addr_t addr, phys_addr_t alignment, phys_addr_t size)
Here is the call graph for this function:

◆ vgic_its_trigger_msi()

static int vgic_its_trigger_msi ( struct kvm *  kvm,
struct vgic_its its,
u32  devid,
u32  eventid 
)
static

Definition at line 743 of file vgic-its.c.

745 {
746  struct vgic_irq *irq = NULL;
747  unsigned long flags;
748  int err;
749 
750  err = vgic_its_resolve_lpi(kvm, its, devid, eventid, &irq);
751  if (err)
752  return err;
753 
754  if (irq->hw)
755  return irq_set_irqchip_state(irq->host_irq,
756  IRQCHIP_STATE_PENDING, true);
757 
758  raw_spin_lock_irqsave(&irq->irq_lock, flags);
759  irq->pending_latch = true;
760  vgic_queue_irq_unlock(kvm, irq, flags);
761 
762  return 0;
763 }
int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq **irq)
Definition: vgic-its.c:682
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_lpi_translation_cache_destroy()

void vgic_lpi_translation_cache_destroy ( struct kvm *  kvm)

Definition at line 1927 of file vgic-its.c.

1928 {
1929  struct vgic_dist *dist = &kvm->arch.vgic;
1930  struct vgic_translation_cache_entry *cte, *tmp;
1931 
1933 
1934  list_for_each_entry_safe(cte, tmp,
1935  &dist->lpi_translation_cache, entry) {
1936  list_del(&cte->entry);
1937  kfree(cte);
1938  }
1939 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_lpi_translation_cache_init()

void vgic_lpi_translation_cache_init ( struct kvm *  kvm)

Definition at line 1903 of file vgic-its.c.

1904 {
1905  struct vgic_dist *dist = &kvm->arch.vgic;
1906  unsigned int sz;
1907  int i;
1908 
1909  if (!list_empty(&dist->lpi_translation_cache))
1910  return;
1911 
1912  sz = atomic_read(&kvm->online_vcpus) * LPI_DEFAULT_PCPU_CACHE_SIZE;
1913 
1914  for (i = 0; i < sz; i++) {
1915  struct vgic_translation_cache_entry *cte;
1916 
1917  /* An allocation failure is not fatal */
1918  cte = kzalloc(sizeof(*cte), GFP_KERNEL_ACCOUNT);
1919  if (WARN_ON(!cte))
1920  break;
1921 
1922  INIT_LIST_HEAD(&cte->entry);
1923  list_add(&cte->entry, &dist->lpi_translation_cache);
1924  }
1925 }
#define LPI_DEFAULT_PCPU_CACHE_SIZE
Definition: vgic-its.c:1901
Here is the caller graph for this function:

◆ vgic_mmio_read_its_baser()

static unsigned long vgic_mmio_read_its_baser ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 1689 of file vgic-its.c.

1692 {
1693  u64 reg;
1694 
1695  switch (BASER_INDEX(addr)) {
1696  case 0:
1697  reg = its->baser_device_table;
1698  break;
1699  case 1:
1700  reg = its->baser_coll_table;
1701  break;
1702  default:
1703  reg = 0;
1704  break;
1705  }
1706 
1707  return extract_bytes(reg, addr & 7, len);
1708 }
#define BASER_INDEX(addr)
Definition: vgic-its.c:1688
unsigned long extract_bytes(u64 data, unsigned int offset, unsigned int num)
Definition: vgic-mmio-v3.c:22
Here is the call graph for this function:

◆ vgic_mmio_read_its_cbaser()

static unsigned long vgic_mmio_read_its_cbaser ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 1555 of file vgic-its.c.

1558 {
1559  return extract_bytes(its->cbaser, addr & 7, len);
1560 }
Here is the call graph for this function:

◆ vgic_mmio_read_its_creadr()

static unsigned long vgic_mmio_read_its_creadr ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 1654 of file vgic-its.c.

1657 {
1658  return extract_bytes(its->creadr, addr & 0x7, len);
1659 }
Here is the call graph for this function:

◆ vgic_mmio_read_its_ctlr()

static unsigned long vgic_mmio_read_its_ctlr ( struct kvm *  vcpu,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 1765 of file vgic-its.c.

1768 {
1769  u32 reg = 0;
1770 
1771  mutex_lock(&its->cmd_lock);
1772  if (its->creadr == its->cwriter)
1773  reg |= GITS_CTLR_QUIESCENT;
1774  if (its->enabled)
1775  reg |= GITS_CTLR_ENABLE;
1776  mutex_unlock(&its->cmd_lock);
1777 
1778  return reg;
1779 }

◆ vgic_mmio_read_its_cwriter()

static unsigned long vgic_mmio_read_its_cwriter ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 1647 of file vgic-its.c.

1650 {
1651  return extract_bytes(its->cwriter, addr & 0x7, len);
1652 }
Here is the call graph for this function:

◆ vgic_mmio_read_its_idregs()

static unsigned long vgic_mmio_read_its_idregs ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 530 of file vgic-its.c.

533 {
534  switch (addr & 0xffff) {
535  case GITS_PIDR0:
536  return 0x92; /* part number, bits[7:0] */
537  case GITS_PIDR1:
538  return 0xb4; /* part number, bits[11:8] */
539  case GITS_PIDR2:
540  return GIC_PIDR2_ARCH_GICv3 | 0x0b;
541  case GITS_PIDR4:
542  return 0x40; /* This is a 64K software visible page */
543  /* The following are the ID registers for (any) GIC. */
544  case GITS_CIDR0:
545  return 0x0d;
546  case GITS_CIDR1:
547  return 0xf0;
548  case GITS_CIDR2:
549  return 0x05;
550  case GITS_CIDR3:
551  return 0xb1;
552  }
553 
554  return 0;
555 }

◆ vgic_mmio_read_its_iidr()

static unsigned long vgic_mmio_read_its_iidr ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 507 of file vgic-its.c.

510 {
511  u32 val;
512 
513  val = (its->abi_rev << GITS_IIDR_REV_SHIFT) & GITS_IIDR_REV_MASK;
514  val |= (PRODUCT_ID_KVM << GITS_IIDR_PRODUCTID_SHIFT) | IMPLEMENTER_ARM;
515  return val;
516 }
#define IMPLEMENTER_ARM
Definition: vgic.h:12
#define PRODUCT_ID_KVM
Definition: vgic.h:11

◆ vgic_mmio_read_its_typer()

static unsigned long vgic_mmio_read_its_typer ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len 
)
static

Definition at line 485 of file vgic-its.c.

488 {
489  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
490  u64 reg = GITS_TYPER_PLPIS;
491 
492  /*
493  * We use linear CPU numbers for redistributor addressing,
494  * so GITS_TYPER.PTA is 0.
495  * Also we force all PROPBASER registers to be the same, so
496  * CommonLPIAff is 0 as well.
497  * To avoid memory waste in the guest, we keep the number of IDBits and
498  * DevBits low - as least for the time being.
499  */
500  reg |= GIC_ENCODE_SZ(VITS_TYPER_DEVBITS, 5) << GITS_TYPER_DEVBITS_SHIFT;
501  reg |= GIC_ENCODE_SZ(VITS_TYPER_IDBITS, 5) << GITS_TYPER_IDBITS_SHIFT;
502  reg |= GIC_ENCODE_SZ(abi->ite_esz, 4) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT;
503 
504  return extract_bytes(reg, addr & 7, len);
505 }
Here is the call graph for this function:

◆ vgic_mmio_uaccess_write_its_creadr()

static int vgic_mmio_uaccess_write_its_creadr ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1661 of file vgic-its.c.

1665 {
1666  u32 cmd_offset;
1667  int ret = 0;
1668 
1669  mutex_lock(&its->cmd_lock);
1670 
1671  if (its->enabled) {
1672  ret = -EBUSY;
1673  goto out;
1674  }
1675 
1676  cmd_offset = ITS_CMD_OFFSET(val);
1677  if (cmd_offset >= ITS_CMD_BUFFER_SIZE(its->cbaser)) {
1678  ret = -EINVAL;
1679  goto out;
1680  }
1681 
1682  its->creadr = cmd_offset;
1683 out:
1684  mutex_unlock(&its->cmd_lock);
1685  return ret;
1686 }
#define ITS_CMD_OFFSET(reg)
Definition: vgic-its.c:1584

◆ vgic_mmio_uaccess_write_its_iidr()

static int vgic_mmio_uaccess_write_its_iidr ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 518 of file vgic-its.c.

522 {
523  u32 rev = GITS_IIDR_REV(val);
524 
525  if (rev >= NR_ITS_ABIS)
526  return -EINVAL;
527  return vgic_its_set_abi(its, rev);
528 }
Here is the call graph for this function:

◆ vgic_mmio_write_its_baser()

static void vgic_mmio_write_its_baser ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1711 of file vgic-its.c.

1715 {
1716  const struct vgic_its_abi *abi = vgic_its_get_abi(its);
1717  u64 entry_size, table_type;
1718  u64 reg, *regptr, clearbits = 0;
1719 
1720  /* When GITS_CTLR.Enable is 1, we ignore write accesses. */
1721  if (its->enabled)
1722  return;
1723 
1724  switch (BASER_INDEX(addr)) {
1725  case 0:
1726  regptr = &its->baser_device_table;
1727  entry_size = abi->dte_esz;
1728  table_type = GITS_BASER_TYPE_DEVICE;
1729  break;
1730  case 1:
1731  regptr = &its->baser_coll_table;
1732  entry_size = abi->cte_esz;
1733  table_type = GITS_BASER_TYPE_COLLECTION;
1734  clearbits = GITS_BASER_INDIRECT;
1735  break;
1736  default:
1737  return;
1738  }
1739 
1740  reg = update_64bit_reg(*regptr, addr & 7, len, val);
1741  reg &= ~GITS_BASER_RO_MASK;
1742  reg &= ~clearbits;
1743 
1744  reg |= (entry_size - 1) << GITS_BASER_ENTRY_SIZE_SHIFT;
1745  reg |= table_type << GITS_BASER_TYPE_SHIFT;
1746  reg = vgic_sanitise_its_baser(reg);
1747 
1748  *regptr = reg;
1749 
1750  if (!(reg & GITS_BASER_VALID)) {
1751  /* Take the its_lock to prevent a race with a save/restore */
1752  mutex_lock(&its->its_lock);
1753  switch (table_type) {
1754  case GITS_BASER_TYPE_DEVICE:
1755  vgic_its_free_device_list(kvm, its);
1756  break;
1757  case GITS_BASER_TYPE_COLLECTION:
1759  break;
1760  }
1761  mutex_unlock(&its->its_lock);
1762  }
1763 }
static u64 vgic_sanitise_its_baser(u64 reg)
Definition: vgic-its.c:1519
#define GITS_BASER_RO_MASK
Definition: vgic-its.c:1710
u64 update_64bit_reg(u64 reg, unsigned int offset, unsigned int len, unsigned long val)
Definition: vgic-mmio-v3.c:29
Here is the call graph for this function:

◆ vgic_mmio_write_its_cbaser()

static void vgic_mmio_write_its_cbaser ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1562 of file vgic-its.c.

1565 {
1566  /* When GITS_CTLR.Enable is 1, this register is RO. */
1567  if (its->enabled)
1568  return;
1569 
1570  mutex_lock(&its->cmd_lock);
1571  its->cbaser = update_64bit_reg(its->cbaser, addr & 7, len, val);
1572  its->cbaser = vgic_sanitise_its_cbaser(its->cbaser);
1573  its->creadr = 0;
1574  /*
1575  * CWRITER is architecturally UNKNOWN on reset, but we need to reset
1576  * it to CREADR to make sure we start with an empty command buffer.
1577  */
1578  its->cwriter = its->creadr;
1579  mutex_unlock(&its->cmd_lock);
1580 }
static u64 vgic_sanitise_its_cbaser(u64 reg)
Definition: vgic-its.c:1537
Here is the call graph for this function:

◆ vgic_mmio_write_its_ctlr()

static void vgic_mmio_write_its_ctlr ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1781 of file vgic-its.c.

1784 {
1785  mutex_lock(&its->cmd_lock);
1786 
1787  /*
1788  * It is UNPREDICTABLE to enable the ITS if any of the CBASER or
1789  * device/collection BASER are invalid
1790  */
1791  if (!its->enabled && (val & GITS_CTLR_ENABLE) &&
1792  (!(its->baser_device_table & GITS_BASER_VALID) ||
1793  !(its->baser_coll_table & GITS_BASER_VALID) ||
1794  !(its->cbaser & GITS_CBASER_VALID)))
1795  goto out;
1796 
1797  its->enabled = !!(val & GITS_CTLR_ENABLE);
1798  if (!its->enabled)
1800 
1801  /*
1802  * Try to process any pending commands. This function bails out early
1803  * if the ITS is disabled or no commands have been queued.
1804  */
1805  vgic_its_process_commands(kvm, its);
1806 
1807 out:
1808  mutex_unlock(&its->cmd_lock);
1809 }
static void vgic_its_process_commands(struct kvm *kvm, struct vgic_its *its)
Definition: vgic-its.c:1587
Here is the call graph for this function:

◆ vgic_mmio_write_its_cwriter()

static void vgic_mmio_write_its_cwriter ( struct kvm *  kvm,
struct vgic_its its,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

Definition at line 1623 of file vgic-its.c.

1626 {
1627  u64 reg;
1628 
1629  if (!its)
1630  return;
1631 
1632  mutex_lock(&its->cmd_lock);
1633 
1634  reg = update_64bit_reg(its->cwriter, addr & 7, len, val);
1635  reg = ITS_CMD_OFFSET(reg);
1636  if (reg >= ITS_CMD_BUFFER_SIZE(its->cbaser)) {
1637  mutex_unlock(&its->cmd_lock);
1638  return;
1639  }
1640  its->cwriter = reg;
1641 
1642  vgic_its_process_commands(kvm, its);
1643 
1644  mutex_unlock(&its->cmd_lock);
1645 }
Here is the call graph for this function:

◆ vgic_msi_to_its()

struct vgic_its* vgic_msi_to_its ( struct kvm *  kvm,
struct kvm_msi *  msi 
)

Definition at line 708 of file vgic-its.c.

709 {
710  u64 address;
711  struct kvm_io_device *kvm_io_dev;
712  struct vgic_io_device *iodev;
713 
714  if (!vgic_has_its(kvm))
715  return ERR_PTR(-ENODEV);
716 
717  if (!(msi->flags & KVM_MSI_VALID_DEVID))
718  return ERR_PTR(-EINVAL);
719 
720  address = (u64)msi->address_hi << 32 | msi->address_lo;
721 
722  kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address);
723  if (!kvm_io_dev)
724  return ERR_PTR(-EINVAL);
725 
726  if (kvm_io_dev->ops != &kvm_io_gic_ops)
727  return ERR_PTR(-EINVAL);
728 
729  iodev = container_of(kvm_io_dev, struct vgic_io_device, dev);
730  if (iodev->iodev_type != IODEV_ITS)
731  return ERR_PTR(-EINVAL);
732 
733  return iodev->its;
734 }
@ IODEV_ITS
Definition: arm_vgic.h:172
struct kvm_io_device * kvm_io_bus_get_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr)
Definition: kvm_main.c:5989
const struct kvm_io_device_ops * ops
Definition: iodev.h:33
struct vgic_its * its
Definition: arm_vgic.h:179
enum iodev_type iodev_type
Definition: arm_vgic.h:182
struct kvm_io_device dev
Definition: arm_vgic.h:184
bool vgic_has_its(struct kvm *kvm)
Definition: vgic-mmio-v3.c:41
const struct kvm_io_device_ops kvm_io_gic_ops
Definition: vgic-mmio.c:1075
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_register_its_iodev()

static int vgic_register_its_iodev ( struct kvm *  kvm,
struct vgic_its its,
u64  addr 
)
static

Definition at line 1872 of file vgic-its.c.

1874 {
1875  struct vgic_io_device *iodev = &its->iodev;
1876  int ret;
1877 
1878  mutex_lock(&kvm->slots_lock);
1880  ret = -EBUSY;
1881  goto out;
1882  }
1883 
1884  its->vgic_its_base = addr;
1885  iodev->regions = its_registers;
1886  iodev->nr_regions = ARRAY_SIZE(its_registers);
1888 
1889  iodev->base_addr = its->vgic_its_base;
1890  iodev->iodev_type = IODEV_ITS;
1891  iodev->its = its;
1892  ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, iodev->base_addr,
1893  KVM_VGIC_V3_ITS_SIZE, &iodev->dev);
1894 out:
1895  mutex_unlock(&kvm->slots_lock);
1896 
1897  return ret;
1898 }
static void kvm_iodevice_init(struct kvm_io_device *dev, const struct kvm_io_device_ops *ops)
Definition: iodev.h:36
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, struct kvm_io_device *dev)
Definition: kvm_main.c:5897
const struct vgic_register_region * regions
Definition: arm_vgic.h:181
gpa_t base_addr
Definition: arm_vgic.h:176
struct vgic_io_device iodev
Definition: arm_vgic.h:192
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_sanitise_its_baser()

static u64 vgic_sanitise_its_baser ( u64  reg)
static

Definition at line 1519 of file vgic-its.c.

1520 {
1521  reg = vgic_sanitise_field(reg, GITS_BASER_SHAREABILITY_MASK,
1522  GITS_BASER_SHAREABILITY_SHIFT,
1524  reg = vgic_sanitise_field(reg, GITS_BASER_INNER_CACHEABILITY_MASK,
1525  GITS_BASER_INNER_CACHEABILITY_SHIFT,
1527  reg = vgic_sanitise_field(reg, GITS_BASER_OUTER_CACHEABILITY_MASK,
1528  GITS_BASER_OUTER_CACHEABILITY_SHIFT,
1530 
1531  /* We support only one (ITS) page size: 64K */
1532  reg = (reg & ~GITS_BASER_PAGE_SIZE_MASK) | GITS_BASER_PAGE_SIZE_64K;
1533 
1534  return reg;
1535 }
u64 vgic_sanitise_shareability(u64 field)
Definition: vgic-mmio-v3.c:370
u64 vgic_sanitise_inner_cacheability(u64 field)
Definition: vgic-mmio-v3.c:381
u64 vgic_sanitise_outer_cacheability(u64 field)
Definition: vgic-mmio-v3.c:393
u64 vgic_sanitise_field(u64 reg, u64 field_mask, int field_shift, u64(*sanitise_fn)(u64))
Definition: vgic-mmio-v3.c:404
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_sanitise_its_cbaser()

static u64 vgic_sanitise_its_cbaser ( u64  reg)
static

Definition at line 1537 of file vgic-its.c.

1538 {
1539  reg = vgic_sanitise_field(reg, GITS_CBASER_SHAREABILITY_MASK,
1540  GITS_CBASER_SHAREABILITY_SHIFT,
1542  reg = vgic_sanitise_field(reg, GITS_CBASER_INNER_CACHEABILITY_MASK,
1543  GITS_CBASER_INNER_CACHEABILITY_SHIFT,
1545  reg = vgic_sanitise_field(reg, GITS_CBASER_OUTER_CACHEABILITY_MASK,
1546  GITS_CBASER_OUTER_CACHEABILITY_SHIFT,
1548 
1549  /* Sanitise the physical address to be 64k aligned. */
1550  reg &= ~GENMASK_ULL(15, 12);
1551 
1552  return reg;
1553 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ its_registers

struct vgic_register_region its_registers[]
static
Initial value:
= {
REGISTER_ITS_DESC(GITS_CTLR,
REGISTER_ITS_DESC(GITS_TYPER,
REGISTER_ITS_DESC(GITS_CBASER,
REGISTER_ITS_DESC(GITS_CWRITER,
REGISTER_ITS_DESC(GITS_BASER,
REGISTER_ITS_DESC(GITS_IDREGS_BASE,
}
static unsigned long vgic_mmio_read_its_creadr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:1654
static void vgic_mmio_write_its_cbaser(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1562
static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:485
static unsigned long vgic_mmio_read_its_iidr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:507
static unsigned long vgic_mmio_read_its_ctlr(struct kvm *vcpu, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:1765
static void its_mmio_write_wi(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1830
static void vgic_mmio_write_its_baser(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1711
static void vgic_mmio_write_its_ctlr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1781
static unsigned long vgic_mmio_read_its_cbaser(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:1555
static void vgic_mmio_write_its_cwriter(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1623
#define REGISTER_ITS_DESC_UACCESS(off, rd, wr, uwr, length, acc)
Definition: vgic-its.c:1820
static unsigned long vgic_mmio_read_its_cwriter(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:1647
static int vgic_mmio_uaccess_write_its_creadr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:1661
static unsigned long vgic_mmio_read_its_baser(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:1689
static int vgic_mmio_uaccess_write_its_iidr(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-its.c:518
static unsigned long vgic_mmio_read_its_idregs(struct kvm *kvm, struct vgic_its *its, gpa_t addr, unsigned int len)
Definition: vgic-its.c:530
#define REGISTER_ITS_DESC(off, rd, wr, length, acc)
Definition: vgic-its.c:1811
#define VGIC_ACCESS_32bit
Definition: vgic-mmio.h:40

Definition at line 1830 of file vgic-its.c.

◆ its_table_abi_versions

const struct vgic_its_abi its_table_abi_versions[]
static
Initial value:
= {
[0] = {
.cte_esz = ABI_0_ESZ,
.dte_esz = ABI_0_ESZ,
.ite_esz = ABI_0_ESZ,
.save_tables = vgic_its_save_tables_v0,
.restore_tables = vgic_its_restore_tables_v0,
.commit = vgic_its_commit_v0,
},
}
#define ABI_0_ESZ
Definition: vgic-its.c:176
static int vgic_its_commit_v0(struct vgic_its *its)
Definition: vgic-its.c:2720
static int vgic_its_save_tables_v0(struct vgic_its *its)
Definition: vgic-its.c:2690
static int vgic_its_restore_tables_v0(struct vgic_its *its)
Definition: vgic-its.c:2706

Definition at line 39 of file vgic-its.c.

◆ kvm_arm_vgic_its_ops

struct kvm_device_ops kvm_arm_vgic_its_ops
static
Initial value:
= {
.name = "kvm-arm-vgic-its",
.create = vgic_its_create,
.destroy = vgic_its_destroy,
.set_attr = vgic_its_set_attr,
.get_attr = vgic_its_get_attr,
.has_attr = vgic_its_has_attr,
}
static int vgic_its_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
Definition: vgic-its.c:2749
static int vgic_its_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
Definition: vgic-its.c:2871
static int vgic_its_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr)
Definition: vgic-its.c:2831
static int vgic_its_create(struct kvm_device *dev, u32 type)
Definition: vgic-its.c:1952
static void vgic_its_destroy(struct kvm_device *kvm_dev)
Definition: vgic-its.c:2013

Definition at line 2871 of file vgic-its.c.