Skip to content

Commit c0b55cd

Browse files
Shawnshhlijinxia
authored andcommitted
HV:vtd:fix all integer related violations
Fix vtd.h and vtd.c all integer violations. Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent 4c941ed commit c0b55cd

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

hypervisor/arch/x86/vtd.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
#define ACRN_DBG_IOMMU LOG_INFO
1515
#define DMAR_FAULT_LOOP_MAX 10
1616
#else
17-
#define ACRN_DBG_IOMMU 6
17+
#define ACRN_DBG_IOMMU 6U
1818
#endif
1919

2020
/* set an appropriate bus limitation when iommu init,
2121
* to reduce memory & time cost
2222
*/
23-
#define IOMMU_INIT_BUS_LIMIT (0xf)
23+
#define IOMMU_INIT_BUS_LIMIT (0xfU)
2424

2525
#define PAGE_MASK (0xFFFUL)
2626
#define LEVEL_WIDTH 9U
@@ -124,7 +124,7 @@ struct dmar_drhd_rt {
124124

125125
uint64_t cap;
126126
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 */
128128

129129
uint32_t irq;
130130
struct dev_handler_node *dmar_irq_node;
@@ -166,7 +166,7 @@ static uint32_t dmar_hdrh_unit_count;
166166
* domain id 0 is reserved,
167167
* bit0 --> domain id 0, ..., bit63 --> domain id 63
168168
*/
169-
static uint32_t max_domain_id = 63;
169+
static uint32_t max_domain_id = 63U;
170170
static uint64_t domain_bitmap;
171171
static spinlock_t domain_lock;
172172
static struct iommu_domain *host_domain;
@@ -182,7 +182,7 @@ static void register_hrhd_units(void)
182182
uint32_t i;
183183

184184
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));
186186
ASSERT(drhd_rt != NULL, "");
187187
drhd_rt->drhd = &info->drhd_units[i];
188188
dmar_register_hrhd(drhd_rt);
@@ -198,8 +198,8 @@ static uint64_t iommu_read64(struct dmar_drhd_rt *dmar_uint, uint32_t offset)
198198
{
199199
uint64_t value;
200200

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;
203203
value = value | mmio_read_long(HPA2HVA(dmar_uint->drhd->reg_base_addr +
204204
offset));
205205

@@ -217,11 +217,11 @@ static void iommu_write64(struct dmar_drhd_rt *dmar_uint, uint32_t offset,
217217
{
218218
uint32_t temp;
219219

220-
temp = value;
220+
temp = (uint32_t)value;
221221
mmio_write_long(temp, HPA2HVA(dmar_uint->drhd->reg_base_addr + offset));
222222

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));
225225
}
226226

227227
/* flush cache when root table, context table updated */
@@ -313,7 +313,7 @@ static void dmar_uint_show_capability(struct dmar_drhd_rt *dmar_uint)
313313

314314
static inline uint8_t width_to_level(uint32_t width)
315315
{
316-
return ((width - 12U) + (LEVEL_WIDTH)-1U) / (LEVEL_WIDTH);
316+
return (uint8_t)(((width - 12U) + (LEVEL_WIDTH)-1U) / (LEVEL_WIDTH));
317317
}
318318

319319
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)
387387

388388
dmar_uint->cap = iommu_read64(dmar_uint, DMAR_CAP_REG);
389389
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);
391391

392392
dmar_uint->cap_msagaw = dmar_uint_get_msagw(dmar_uint);
393393

394394
dmar_uint->cap_num_fault_regs =
395395
iommu_cap_num_fault_regs(dmar_uint->cap);
396396
dmar_uint->cap_fault_reg_offset =
397397
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;
399399

400400
#if DBG_IOMMU
401401
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)
411411
#endif
412412

413413
/* 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) {
415415
dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support 2MB page!");
416416
}
417417

418-
if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x2UL) == 0) {
418+
if ((iommu_cap_super_page_val(dmar_uint->cap) & 0x2U) == 0U) {
419419
dev_dbg(ACRN_DBG_IOMMU, "dmar uint doesn't support 1GB page!");
420420
}
421421

@@ -450,7 +450,7 @@ static void dmar_register_hrhd(struct dmar_drhd_rt *dmar_uint)
450450

451451
dmar_hdrh_unit_count++;
452452

453-
if ((dmar_uint->gcmd & DMA_GCMD_TE) != 0) {
453+
if ((dmar_uint->gcmd & DMA_GCMD_TE) != 0U) {
454454
dmar_disable_translation(dmar_uint);
455455
}
456456
}
@@ -498,7 +498,7 @@ static uint8_t alloc_domain_id(void)
498498
*/
499499
for (i = 1U; i < 64U; i++) {
500500
mask = (1UL << i);
501-
if ((domain_bitmap & mask) == 0) {
501+
if ((domain_bitmap & mask) == 0UL) {
502502
domain_bitmap |= mask;
503503
break;
504504
}
@@ -518,7 +518,7 @@ static void free_domain_id(uint16_t dom_id)
518518

519519
static struct iommu_domain *create_host_domain(void)
520520
{
521-
struct iommu_domain *domain = calloc(1, sizeof(struct iommu_domain));
521+
struct iommu_domain *domain = calloc(1U, sizeof(struct iommu_domain));
522522

523523
ASSERT(domain != NULL, "");
524524
domain->is_host = true;
@@ -539,7 +539,7 @@ static void dmar_write_buffer_flush(struct dmar_drhd_rt *dmar_uint)
539539
}
540540

541541
IOMMU_LOCK(dmar_uint);
542-
iommu_write64(dmar_uint, DMAR_GCMD_REG,
542+
iommu_write32(dmar_uint, DMAR_GCMD_REG,
543543
dmar_uint->gcmd | DMA_GCMD_WBF);
544544

545545
/* read lower 32 bits to check */
@@ -589,7 +589,7 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint,
589589

590590
static void dmar_invalid_context_cache_global(struct dmar_drhd_rt *dmar_uint)
591591
{
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);
593593
}
594594

595595
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,
600600
* if hardware doesn't support it, will be ignored by hardware
601601
*/
602602
uint64_t cmd = DMA_IOTLB_IVT | DMA_IOTLB_DR | DMA_IOTLB_DW;
603-
uint64_t addr = 0;
603+
uint64_t addr = 0UL;
604604
uint32_t status;
605605

606606
switch (iirg) {
@@ -626,9 +626,9 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
626626
iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset, addr);
627627
}
628628

629-
iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset + 8, cmd);
629+
iommu_write64(dmar_uint, dmar_uint->ecap_iotlb_offset + 8U, cmd);
630630
/* 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,
632632
(status & DMA_IOTLB_IVT_32) == 0U, status);
633633
IOMMU_UNLOCK(dmar_uint);
634634

@@ -645,7 +645,7 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
645645
*/
646646
static void dmar_invalid_iotlb_global(struct dmar_drhd_rt *dmar_uint)
647647
{
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);
649649
}
650650

651651
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)
678678
static void dmar_fault_event_unmask(struct dmar_drhd_rt *dmar_uint)
679679
{
680680
IOMMU_LOCK(dmar_uint);
681-
iommu_write32(dmar_uint, DMAR_FECTL_REG, 0);
681+
iommu_write32(dmar_uint, DMAR_FECTL_REG, 0U);
682682
IOMMU_UNLOCK(dmar_uint);
683683
}
684684

685685
static void dmar_fault_msi_write(struct dmar_drhd_rt *dmar_uint,
686-
uint8_t vector)
686+
uint32_t vector)
687687
{
688688
uint32_t data;
689689
uint32_t addr_low;
@@ -780,8 +780,8 @@ static int dmar_fault_handler(int irq, void *data)
780780
while (dma_fsts_ppf(fsr)) {
781781
loop++;
782782
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;
785785
if (index >= dmar_uint->cap_num_fault_regs) {
786786
dev_dbg(ACRN_DBG_IOMMU, "%s: invalid FR Index",
787787
__func__);
@@ -790,7 +790,7 @@ static int dmar_fault_handler(int irq, void *data)
790790

791791
/* read 128-bit fault recording register */
792792
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);
794794

795795
dev_dbg(ACRN_DBG_IOMMU, "%s: record[%d] @0x%x: 0x%llx, 0x%llx",
796796
__func__, index, record_reg_offset,
@@ -800,7 +800,7 @@ static int dmar_fault_handler(int irq, void *data)
800800

801801
/* write to clear */
802802
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]);
804804

805805
#ifdef DMAR_FAULT_LOOP_MAX
806806
if (loop > DMAR_FAULT_LOOP_MAX) {
@@ -1147,8 +1147,8 @@ int assign_iommu_device(struct iommu_domain *domain, uint8_t bus,
11471147

11481148
/* TODO: check if the device assigned */
11491149

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);
11521152
return 0;
11531153
}
11541154

@@ -1161,8 +1161,8 @@ int unassign_iommu_device(struct iommu_domain *domain, uint8_t bus,
11611161

11621162
/* TODO: check if the device assigned */
11631163

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);
11661166
return 0;
11671167
}
11681168

@@ -1295,7 +1295,7 @@ void init_iommu(void)
12951295

12961296
for (bus = 0U; bus <= IOMMU_INIT_BUS_LIMIT; bus++) {
12971297
for (devfun = 0U; devfun <= 255U; devfun++) {
1298-
add_iommu_device(host_domain, 0,
1298+
add_iommu_device(host_domain, 0U,
12991299
(uint8_t)bus, (uint8_t)devfun);
13001300
}
13011301
}

hypervisor/include/arch/x86/mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
#include <cpu.h>
138138

139139
/* Define cache line size (in bytes) */
140-
#define CACHE_LINE_SIZE 64
140+
#define CACHE_LINE_SIZE 64U
141141

142142
/* Size of all page structures for IA-32e */
143143
#define IA32E_STRUCT_SIZE MEM_4K

0 commit comments

Comments
 (0)