14
14
#define ACRN_DBG_IOMMU LOG_INFO
15
15
#define DMAR_FAULT_LOOP_MAX 10
16
16
#else
17
- #define ACRN_DBG_IOMMU 6
17
+ #define ACRN_DBG_IOMMU 6U
18
18
#endif
19
19
20
20
/* set an appropriate bus limitation when iommu init,
21
21
* to reduce memory & time cost
22
22
*/
23
- #define IOMMU_INIT_BUS_LIMIT (0xf )
23
+ #define IOMMU_INIT_BUS_LIMIT (0xfU )
24
24
25
25
#define PAGE_MASK (0xFFFUL)
26
26
#define LEVEL_WIDTH 9U
@@ -124,7 +124,7 @@ struct dmar_drhd_rt {
124
124
125
125
uint64_t cap ;
126
126
uint64_t ecap ;
127
- uint64_t gcmd ; /* sw cache value of global cmd register */
127
+ uint32_t gcmd ; /* sw cache value of global cmd register */
128
128
129
129
uint32_t irq ;
130
130
struct dev_handler_node * dmar_irq_node ;
@@ -166,7 +166,7 @@ static uint32_t dmar_hdrh_unit_count;
166
166
* domain id 0 is reserved,
167
167
* bit0 --> domain id 0, ..., bit63 --> domain id 63
168
168
*/
169
- static uint32_t max_domain_id = 63 ;
169
+ static uint32_t max_domain_id = 63U ;
170
170
static uint64_t domain_bitmap ;
171
171
static spinlock_t domain_lock ;
172
172
static struct iommu_domain * host_domain ;
@@ -182,7 +182,7 @@ static void register_hrhd_units(void)
182
182
uint32_t i ;
183
183
184
184
for (i = 0U ; i < info -> drhd_count ; i ++ ) {
185
- drhd_rt = calloc (1 , sizeof (struct dmar_drhd_rt ));
185
+ drhd_rt = calloc (1U , sizeof (struct dmar_drhd_rt ));
186
186
ASSERT (drhd_rt != NULL , "" );
187
187
drhd_rt -> drhd = & info -> drhd_units [i ];
188
188
dmar_register_hrhd (drhd_rt );
@@ -198,8 +198,8 @@ static uint64_t iommu_read64(struct dmar_drhd_rt *dmar_uint, uint32_t offset)
198
198
{
199
199
uint64_t value ;
200
200
201
- value = mmio_read_long (HPA2HVA (dmar_uint -> drhd -> reg_base_addr + offset + 4 ));
202
- value = value << 32 ;
201
+ value = mmio_read_long (HPA2HVA (dmar_uint -> drhd -> reg_base_addr + offset + 4U ));
202
+ value = value << 32U ;
203
203
value = value | mmio_read_long (HPA2HVA (dmar_uint -> drhd -> reg_base_addr +
204
204
offset ));
205
205
@@ -217,11 +217,11 @@ static void iommu_write64(struct dmar_drhd_rt *dmar_uint, uint32_t offset,
217
217
{
218
218
uint32_t temp ;
219
219
220
- temp = value ;
220
+ temp = ( uint32_t ) value ;
221
221
mmio_write_long (temp , HPA2HVA (dmar_uint -> drhd -> reg_base_addr + offset ));
222
222
223
- temp = value >> 32 ;
224
- mmio_write_long (temp , HPA2HVA (dmar_uint -> drhd -> reg_base_addr + offset + 4 ));
223
+ temp = ( uint32_t )( value >> 32U ) ;
224
+ mmio_write_long (temp , HPA2HVA (dmar_uint -> drhd -> reg_base_addr + offset + 4U ));
225
225
}
226
226
227
227
/* flush cache when root table, context table updated */
@@ -313,7 +313,7 @@ static void dmar_uint_show_capability(struct dmar_drhd_rt *dmar_uint)
313
313
314
314
static inline uint8_t width_to_level (uint32_t width )
315
315
{
316
- return (( width - 12U ) + (LEVEL_WIDTH )- 1U ) / (LEVEL_WIDTH );
316
+ return (uint8_t )((( width - 12U ) + (LEVEL_WIDTH )- 1U ) / (LEVEL_WIDTH ) );
317
317
}
318
318
319
319
static inline uint8_t width_to_agaw (uint32_t width )
@@ -387,15 +387,15 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint)
387
387
388
388
dmar_uint -> cap = iommu_read64 (dmar_uint , DMAR_CAP_REG );
389
389
dmar_uint -> ecap = iommu_read64 (dmar_uint , DMAR_ECAP_REG );
390
- dmar_uint -> gcmd = iommu_read64 (dmar_uint , DMAR_GCMD_REG );
390
+ dmar_uint -> gcmd = iommu_read32 (dmar_uint , DMAR_GCMD_REG );
391
391
392
392
dmar_uint -> cap_msagaw = dmar_uint_get_msagw (dmar_uint );
393
393
394
394
dmar_uint -> cap_num_fault_regs =
395
395
iommu_cap_num_fault_regs (dmar_uint -> cap );
396
396
dmar_uint -> cap_fault_reg_offset =
397
397
iommu_cap_fault_reg_offset (dmar_uint -> cap );
398
- dmar_uint -> ecap_iotlb_offset = iommu_ecap_iro (dmar_uint -> ecap ) * 16 ;
398
+ dmar_uint -> ecap_iotlb_offset = iommu_ecap_iro (dmar_uint -> ecap ) * 16U ;
399
399
400
400
#if DBG_IOMMU
401
401
pr_info ("version:0x%x, cap:0x%llx, ecap:0x%llx" ,
@@ -411,11 +411,11 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint)
411
411
#endif
412
412
413
413
/* check capability */
414
- if ((iommu_cap_super_page_val (dmar_uint -> cap ) & 0x1UL ) == 0 ) {
414
+ if ((iommu_cap_super_page_val (dmar_uint -> cap ) & 0x1U ) == 0U ) {
415
415
dev_dbg (ACRN_DBG_IOMMU , "dmar uint doesn't support 2MB page!" );
416
416
}
417
417
418
- if ((iommu_cap_super_page_val (dmar_uint -> cap ) & 0x2UL ) == 0 ) {
418
+ if ((iommu_cap_super_page_val (dmar_uint -> cap ) & 0x2U ) == 0U ) {
419
419
dev_dbg (ACRN_DBG_IOMMU , "dmar uint doesn't support 1GB page!" );
420
420
}
421
421
@@ -450,7 +450,7 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint)
450
450
451
451
dmar_hdrh_unit_count ++ ;
452
452
453
- if ((dmar_uint -> gcmd & DMA_GCMD_TE ) != 0 ) {
453
+ if ((dmar_uint -> gcmd & DMA_GCMD_TE ) != 0U ) {
454
454
dmar_disable_translation (dmar_uint );
455
455
}
456
456
}
@@ -498,7 +498,7 @@ static uint8_t alloc_domain_id(void)
498
498
*/
499
499
for (i = 1U ; i < 64U ; i ++ ) {
500
500
mask = (1UL << i );
501
- if ((domain_bitmap & mask ) == 0 ) {
501
+ if ((domain_bitmap & mask ) == 0UL ) {
502
502
domain_bitmap |= mask ;
503
503
break ;
504
504
}
@@ -518,7 +518,7 @@ static void free_domain_id(uint16_t dom_id)
518
518
519
519
static struct iommu_domain * create_host_domain (void )
520
520
{
521
- struct iommu_domain * domain = calloc (1 , sizeof (struct iommu_domain ));
521
+ struct iommu_domain * domain = calloc (1U , sizeof (struct iommu_domain ));
522
522
523
523
ASSERT (domain != NULL , "" );
524
524
domain -> is_host = true;
@@ -539,7 +539,7 @@ static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint)
539
539
}
540
540
541
541
IOMMU_LOCK (dmar_uint );
542
- iommu_write64 (dmar_uint , DMAR_GCMD_REG ,
542
+ iommu_write32 (dmar_uint , DMAR_GCMD_REG ,
543
543
dmar_uint -> gcmd | DMA_GCMD_WBF );
544
544
545
545
/* read lower 32 bits to check */
@@ -589,7 +589,7 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint,
589
589
590
590
static void dmar_invalid_context_cache_global (struct dmar_drhd_rt * dmar_uint )
591
591
{
592
- dmar_invalid_context_cache (dmar_uint , 0 , 0 , 0 , DMAR_CIRG_GLOBAL );
592
+ dmar_invalid_context_cache (dmar_uint , 0U , 0U , 0U , DMAR_CIRG_GLOBAL );
593
593
}
594
594
595
595
static void dmar_invalid_iotlb (struct dmar_drhd_rt * dmar_uint ,
@@ -600,7 +600,7 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
600
600
* if hardware doesn't support it, will be ignored by hardware
601
601
*/
602
602
uint64_t cmd = DMA_IOTLB_IVT | DMA_IOTLB_DR | DMA_IOTLB_DW ;
603
- uint64_t addr = 0 ;
603
+ uint64_t addr = 0UL ;
604
604
uint32_t status ;
605
605
606
606
switch (iirg ) {
@@ -626,9 +626,9 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
626
626
iommu_write64 (dmar_uint , dmar_uint -> ecap_iotlb_offset , addr );
627
627
}
628
628
629
- iommu_write64 (dmar_uint , dmar_uint -> ecap_iotlb_offset + 8 , cmd );
629
+ iommu_write64 (dmar_uint , dmar_uint -> ecap_iotlb_offset + 8U , cmd );
630
630
/* read upper 32bits to check */
631
- DMAR_WAIT_COMPLETION (dmar_uint -> ecap_iotlb_offset + 12 ,
631
+ DMAR_WAIT_COMPLETION (dmar_uint -> ecap_iotlb_offset + 12U ,
632
632
(status & DMA_IOTLB_IVT_32 ) == 0U , status );
633
633
IOMMU_UNLOCK (dmar_uint );
634
634
@@ -645,7 +645,7 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
645
645
*/
646
646
static void dmar_invalid_iotlb_global (struct dmar_drhd_rt * dmar_uint )
647
647
{
648
- dmar_invalid_iotlb (dmar_uint , 0 , 0 , 0 , 0 , DMAR_IIRG_GLOBAL );
648
+ dmar_invalid_iotlb (dmar_uint , 0U , 0UL , 0U , false , DMAR_IIRG_GLOBAL );
649
649
}
650
650
651
651
static void dmar_set_root_table (struct dmar_drhd_rt * dmar_uint )
@@ -678,12 +678,12 @@ static void dmar_fault_event_mask(struct dmar_drhd_rt *dmar_uint)
678
678
static void dmar_fault_event_unmask (struct dmar_drhd_rt * dmar_uint )
679
679
{
680
680
IOMMU_LOCK (dmar_uint );
681
- iommu_write32 (dmar_uint , DMAR_FECTL_REG , 0 );
681
+ iommu_write32 (dmar_uint , DMAR_FECTL_REG , 0U );
682
682
IOMMU_UNLOCK (dmar_uint );
683
683
}
684
684
685
685
static void dmar_fault_msi_write (struct dmar_drhd_rt * dmar_uint ,
686
- uint8_t vector )
686
+ uint32_t vector )
687
687
{
688
688
uint32_t data ;
689
689
uint32_t addr_low ;
@@ -780,8 +780,8 @@ static int dmar_fault_handler(int irq, void *data)
780
780
while (dma_fsts_ppf (fsr )) {
781
781
loop ++ ;
782
782
index = dma_fsts_fri (fsr );
783
- record_reg_offset = dmar_uint -> cap_fault_reg_offset
784
- + index * 16 ;
783
+ record_reg_offset = ( uint32_t ) dmar_uint -> cap_fault_reg_offset
784
+ + index * 16U ;
785
785
if (index >= dmar_uint -> cap_num_fault_regs ) {
786
786
dev_dbg (ACRN_DBG_IOMMU , "%s: invalid FR Index" ,
787
787
__func__ );
@@ -790,7 +790,7 @@ static int dmar_fault_handler(int irq, void *data)
790
790
791
791
/* read 128-bit fault recording register */
792
792
record [0 ] = iommu_read64 (dmar_uint , record_reg_offset );
793
- record [1 ] = iommu_read64 (dmar_uint , record_reg_offset + 8 );
793
+ record [1 ] = iommu_read64 (dmar_uint , record_reg_offset + 8U );
794
794
795
795
dev_dbg (ACRN_DBG_IOMMU , "%s: record[%d] @0x%x: 0x%llx, 0x%llx" ,
796
796
__func__ , index , record_reg_offset ,
@@ -800,7 +800,7 @@ static int dmar_fault_handler(int irq, void *data)
800
800
801
801
/* write to clear */
802
802
iommu_write64 (dmar_uint , record_reg_offset , record [0 ]);
803
- iommu_write64 (dmar_uint , record_reg_offset + 8 , record [1 ]);
803
+ iommu_write64 (dmar_uint , record_reg_offset + 8U , record [1 ]);
804
804
805
805
#ifdef DMAR_FAULT_LOOP_MAX
806
806
if (loop > DMAR_FAULT_LOOP_MAX ) {
@@ -1147,8 +1147,8 @@ int assign_iommu_device(struct iommu_domain *domain, uint8_t bus,
1147
1147
1148
1148
/* TODO: check if the device assigned */
1149
1149
1150
- remove_iommu_device (host_domain , 0 , bus , devfun );
1151
- add_iommu_device (domain , 0 , bus , devfun );
1150
+ remove_iommu_device (host_domain , 0U , bus , devfun );
1151
+ add_iommu_device (domain , 0U , bus , devfun );
1152
1152
return 0 ;
1153
1153
}
1154
1154
@@ -1161,8 +1161,8 @@ int unassign_iommu_device(struct iommu_domain *domain, uint8_t bus,
1161
1161
1162
1162
/* TODO: check if the device assigned */
1163
1163
1164
- remove_iommu_device (domain , 0 , bus , devfun );
1165
- add_iommu_device (host_domain , 0 , bus , devfun );
1164
+ remove_iommu_device (domain , 0U , bus , devfun );
1165
+ add_iommu_device (host_domain , 0U , bus , devfun );
1166
1166
return 0 ;
1167
1167
}
1168
1168
@@ -1295,7 +1295,7 @@ void init_iommu(void)
1295
1295
1296
1296
for (bus = 0U ; bus <= IOMMU_INIT_BUS_LIMIT ; bus ++ ) {
1297
1297
for (devfun = 0U ; devfun <= 255U ; devfun ++ ) {
1298
- add_iommu_device (host_domain , 0 ,
1298
+ add_iommu_device (host_domain , 0U ,
1299
1299
(uint8_t )bus , (uint8_t )devfun );
1300
1300
}
1301
1301
}
0 commit comments