3333#include "vgic.h"
3434#include "vgic-mmio.h"
3535
36+ static int vgic_its_save_tables_v0 (struct vgic_its * its );
37+ static int vgic_its_restore_tables_v0 (struct vgic_its * its );
38+ static int vgic_its_commit_v0 (struct vgic_its * its );
39+
3640/*
3741 * Creates a new (reference to a) struct vgic_irq for a given LPI.
3842 * If this LPI is already mapped on another ITS, we increase its refcount
@@ -123,6 +127,50 @@ struct its_ite {
123127 u32 event_id ;
124128};
125129
130+ /**
131+ * struct vgic_its_abi - ITS abi ops and settings
132+ * @cte_esz: collection table entry size
133+ * @dte_esz: device table entry size
134+ * @ite_esz: interrupt translation table entry size
135+ * @save tables: save the ITS tables into guest RAM
136+ * @restore_tables: restore the ITS internal structs from tables
137+ * stored in guest RAM
138+ * @commit: initialize the registers which expose the ABI settings,
139+ * especially the entry sizes
140+ */
141+ struct vgic_its_abi {
142+ int cte_esz ;
143+ int dte_esz ;
144+ int ite_esz ;
145+ int (* save_tables )(struct vgic_its * its );
146+ int (* restore_tables )(struct vgic_its * its );
147+ int (* commit )(struct vgic_its * its );
148+ };
149+
150+ static const struct vgic_its_abi its_table_abi_versions [] = {
151+ [0 ] = {.cte_esz = 8 , .dte_esz = 8 , .ite_esz = 8 ,
152+ .save_tables = vgic_its_save_tables_v0 ,
153+ .restore_tables = vgic_its_restore_tables_v0 ,
154+ .commit = vgic_its_commit_v0 ,
155+ },
156+ };
157+
158+ #define NR_ITS_ABIS ARRAY_SIZE(its_table_abi_versions)
159+
160+ inline const struct vgic_its_abi * vgic_its_get_abi (struct vgic_its * its )
161+ {
162+ return & its_table_abi_versions [its -> abi_rev ];
163+ }
164+
165+ int vgic_its_set_abi (struct vgic_its * its , int rev )
166+ {
167+ const struct vgic_its_abi * abi ;
168+
169+ its -> abi_rev = rev ;
170+ abi = vgic_its_get_abi (its );
171+ return abi -> commit (its );
172+ }
173+
126174/*
127175 * Find and returns a device in the device table for an ITS.
128176 * Must be called with the its_lock mutex held.
@@ -364,6 +412,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
364412 struct vgic_its * its ,
365413 gpa_t addr , unsigned int len )
366414{
415+ const struct vgic_its_abi * abi = vgic_its_get_abi (its );
367416 u64 reg = GITS_TYPER_PLPIS ;
368417
369418 /*
@@ -376,6 +425,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
376425 */
377426 reg |= 0x0f << GITS_TYPER_DEVBITS_SHIFT ;
378427 reg |= 0x0f << GITS_TYPER_IDBITS_SHIFT ;
428+ reg |= GIC_ENCODE_SZ (abi -> ite_esz , 4 ) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT ;
379429
380430 return extract_bytes (reg , addr & 7 , len );
381431}
@@ -1268,6 +1318,7 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
12681318 gpa_t addr , unsigned int len ,
12691319 unsigned long val )
12701320{
1321+ const struct vgic_its_abi * abi = vgic_its_get_abi (its );
12711322 u64 entry_size , device_type ;
12721323 u64 reg , * regptr , clearbits = 0 ;
12731324
@@ -1278,12 +1329,12 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
12781329 switch (BASER_INDEX (addr )) {
12791330 case 0 :
12801331 regptr = & its -> baser_device_table ;
1281- entry_size = 8 ;
1332+ entry_size = abi -> dte_esz ;
12821333 device_type = GITS_BASER_TYPE_DEVICE ;
12831334 break ;
12841335 case 1 :
12851336 regptr = & its -> baser_coll_table ;
1286- entry_size = 8 ;
1337+ entry_size = abi -> cte_esz ;
12871338 device_type = GITS_BASER_TYPE_COLLECTION ;
12881339 clearbits = GITS_BASER_INDIRECT ;
12891340 break ;
@@ -1425,7 +1476,6 @@ static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its)
14251476 (GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb) | \
14261477 GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner) | \
14271478 GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable) | \
1428- ((8ULL - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | \
14291479 GITS_BASER_PAGE_SIZE_64K)
14301480
14311481#define INITIAL_PROPBASER_VALUE \
@@ -1465,7 +1515,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
14651515
14661516 dev -> private = its ;
14671517
1468- return 0 ;
1518+ return vgic_its_set_abi ( its , NR_ITS_ABIS - 1 ) ;
14691519}
14701520
14711521static void vgic_its_destroy (struct kvm_device * kvm_dev )
@@ -1592,6 +1642,41 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,
15921642 return ret ;
15931643}
15941644
1645+ /**
1646+ * vgic_its_save_tables_v0 - Save the ITS tables into guest ARM
1647+ * according to v0 ABI
1648+ */
1649+ static int vgic_its_save_tables_v0 (struct vgic_its * its )
1650+ {
1651+ return - ENXIO ;
1652+ }
1653+
1654+ /**
1655+ * vgic_its_restore_tables_v0 - Restore the ITS tables from guest RAM
1656+ * to internal data structs according to V0 ABI
1657+ *
1658+ */
1659+ static int vgic_its_restore_tables_v0 (struct vgic_its * its )
1660+ {
1661+ return - ENXIO ;
1662+ }
1663+
1664+ static int vgic_its_commit_v0 (struct vgic_its * its )
1665+ {
1666+ const struct vgic_its_abi * abi ;
1667+
1668+ abi = vgic_its_get_abi (its );
1669+ its -> baser_coll_table &= ~GITS_BASER_ENTRY_SIZE_MASK ;
1670+ its -> baser_device_table &= ~GITS_BASER_ENTRY_SIZE_MASK ;
1671+
1672+ its -> baser_coll_table |= (GIC_ENCODE_SZ (abi -> cte_esz , 5 )
1673+ << GITS_BASER_ENTRY_SIZE_SHIFT );
1674+
1675+ its -> baser_device_table |= (GIC_ENCODE_SZ (abi -> dte_esz , 5 )
1676+ << GITS_BASER_ENTRY_SIZE_SHIFT );
1677+ return 0 ;
1678+ }
1679+
15951680static int vgic_its_has_attr (struct kvm_device * dev ,
15961681 struct kvm_device_attr * attr )
15971682{
0 commit comments