Skip to content

Commit 8784329

Browse files
ref: Replace hardcoded booleans with named macros
This commit updates mainly memory and bitmap operations to use named macros like MEM_FREE_PAGES, MEM_PPAGES_ALIGNED, and BITMAP_SET instead of raw boolean values. Signed-off-by: David Cerdeira <[email protected]>
1 parent f8c4561 commit 8784329

File tree

17 files changed

+72
-43
lines changed

17 files changed

+72
-43
lines changed

src/arch/armv8/armv8-a/smmuv2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ ssize_t smmu_alloc_ctxbnk(void)
182182
{
183183
spin_lock(&smmu.ctx_lock);
184184
/* Find a free context bank. */
185-
ssize_t nth = bitmap_find_nth(smmu.ctxbank_bitmap, smmu.ctx_num, 1, 0, false);
185+
ssize_t nth = bitmap_find_nth(smmu.ctxbank_bitmap, smmu.ctx_num, 1, 0, BITMAP_NOT_SET);
186186
if (nth >= 0) {
187187
bitmap_set(smmu.ctxbank_bitmap, (size_t)nth);
188188
}
@@ -247,7 +247,7 @@ ssize_t smmu_alloc_sme(void)
247247
{
248248
spin_lock(&smmu.sme_lock);
249249
/* Find a free sme. */
250-
ssize_t nth = bitmap_find_nth(smmu.sme_bitmap, smmu.sme_num, 1, 0, false);
250+
ssize_t nth = bitmap_find_nth(smmu.sme_bitmap, smmu.sme_num, 1, 0, BITMAP_NOT_SET);
251251
if (nth >= 0) {
252252
bitmap_set(smmu.sme_bitmap, (size_t)nth);
253253
}

src/arch/armv8/armv8-r/mpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static mpid_t mpu_entry_allocate(void)
7676
{
7777
mpid_t reg_num = INVALID_MPID;
7878
reg_num = (mpid_t)bitmap_find_nth(cpu()->arch.profile.mpu.allocated_entries,
79-
MPU_ARCH_MAX_NUM_ENTRIES, 1, 0, false);
79+
MPU_ARCH_MAX_NUM_ENTRIES, 1, 0, BITMAP_NOT_SET);
8080

8181
bitmap_set(cpu()->arch.profile.mpu.allocated_entries, reg_num);
8282

src/arch/armv8/armv8-r/vmm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ void vmm_arch_profile_init()
2929

3030
timer_freq = timer_ctl->CNTDIF0;
3131

32-
mem_unmap(&cpu()->as, (vaddr_t)timer_ctl, sizeof(struct generic_timer_cntctrl), false);
32+
mem_unmap(&cpu()->as, (vaddr_t)timer_ctl, sizeof(struct generic_timer_cntctrl),
33+
MEM_DONT_FREE_PAGES);
3334
}
3435

3536
cpu_sync_barrier(&cpu_glb_sync);

src/arch/armv8/inc/arch/vgic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ struct vgic_priv {
7171
struct vgic_int interrupts[GIC_CPU_PRIV];
7272
};
7373

74+
#define VGIC_GICR_ACCESS true
75+
#define VGIC_NO_GICR_ACCESS false
76+
7477
void vgic_init(struct vm* vm, const struct vgic_dscrp* vgic_dscrp);
7578
void vgic_cpu_init(struct vcpu* vcpu);
7679
void vgic_set_hw(struct vm* vm, irqid_t id);

src/arch/armv8/vgic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ bool vgicd_emul_handler(struct emul_access* acc)
968968

969969
if (vgic_check_reg_alignment(acc, handler_info)) {
970970
spin_lock(&cpu()->vcpu->vm->arch.vgicd.lock);
971-
handler_info->reg_access(acc, handler_info, false, cpu()->vcpu->id);
971+
handler_info->reg_access(acc, handler_info, VGIC_NO_GICR_ACCESS, cpu()->vcpu->id);
972972
spin_unlock(&cpu()->vcpu->vm->arch.vgicd.lock);
973973
return true;
974974
} else {

src/arch/armv8/vgicv2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ void vgic_init(struct vm* vm, const struct vgic_dscrp* vgic_dscrp)
155155
(vaddr_t)platform.arch.gic.gicv_addr, n);
156156

157157
size_t vgic_int_size = vm->arch.vgicd.int_num * sizeof(struct vgic_int);
158-
vm->arch.vgicd.interrupts = mem_alloc_page(NUM_PAGES(vgic_int_size), SEC_HYP_VM, false);
158+
vm->arch.vgicd.interrupts =
159+
mem_alloc_page(NUM_PAGES(vgic_int_size), SEC_HYP_VM, MEM_PPAGES_NOT_ALIGNED);
159160
if (vm->arch.vgicd.interrupts == NULL) {
160161
ERROR("failed to alloc vgic");
161162
}

src/arch/armv8/vgicv3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static bool vgicr_emul_handler(struct emul_access* acc)
276276
struct vcpu* vcpu =
277277
vgicr_id == cpu()->vcpu->id ? cpu()->vcpu : vm_get_vcpu(cpu()->vcpu->vm, vgicr_id);
278278
spin_lock(&vcpu->arch.vgic_priv.vgicr.lock);
279-
handler_info->reg_access(acc, handler_info, true, vgicr_id);
279+
handler_info->reg_access(acc, handler_info, VGIC_GICR_ACCESS, vgicr_id);
280280
spin_unlock(&vcpu->arch.vgic_priv.vgicr.lock);
281281
return true;
282282
} else {
@@ -331,7 +331,8 @@ void vgic_init(struct vm* vm, const struct vgic_dscrp* vgic_dscrp)
331331
vm->arch.vgicd.lock = SPINLOCK_INITVAL;
332332

333333
size_t vgic_int_size = vm->arch.vgicd.int_num * sizeof(struct vgic_int);
334-
vm->arch.vgicd.interrupts = mem_alloc_page(NUM_PAGES(vgic_int_size), SEC_HYP_VM, false);
334+
vm->arch.vgicd.interrupts =
335+
mem_alloc_page(NUM_PAGES(vgic_int_size), SEC_HYP_VM, MEM_PPAGES_NOT_ALIGNED);
335336
if (vm->arch.vgicd.interrupts == NULL) {
336337
ERROR("failed to alloc vgic");
337338
}

src/arch/riscv/iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void rv_iommu_init(void)
274274

275275
// Allocate memory for FQ (aligned to 4kiB)
276276
vaddr_t fq_vaddr = (vaddr_t)mem_alloc_page(NUM_PAGES(sizeof(struct fq_entry) * FQ_N_ENTRIES),
277-
SEC_HYP_GLOBAL, true);
277+
SEC_HYP_GLOBAL, MEM_PPAGES_ALIGNED);
278278
memset((void*)fq_vaddr, 0, sizeof(struct fq_entry) * FQ_N_ENTRIES);
279279
rv_iommu.hw.fq = (struct fq_entry*)fq_vaddr;
280280

@@ -302,7 +302,7 @@ static void rv_iommu_init(void)
302302

303303
// Allocate a page of memory (aligned) for the DDT
304304
vaddr_t ddt_vaddr = (vaddr_t)mem_alloc_page(NUM_PAGES(sizeof(struct ddt_entry) * DDT_N_ENTRIES),
305-
SEC_HYP_GLOBAL, true);
305+
SEC_HYP_GLOBAL, MEM_PPAGES_ALIGNED);
306306
// Clear entries
307307
memset((void*)ddt_vaddr, 0, sizeof(struct ddt_entry) * DDT_N_ENTRIES);
308308
rv_iommu.hw.ddt = (struct ddt_entry*)ddt_vaddr;

src/core/inc/mem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ struct shmem {
5555
spinlock_t lock;
5656
};
5757

58+
#define MEM_PPAGES_ALIGNED true
59+
#define MEM_PPAGES_NOT_ALIGNED false
60+
61+
#define MEM_FREE_PAGES true
62+
#define MEM_DONT_FREE_PAGES false
63+
5864
static inline struct ppages mem_ppages_get(paddr_t base, size_t num_pages)
5965
{
6066
return (struct ppages){ .colors = 0, .base = base, .num_pages = num_pages };

src/core/mem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ bool pp_alloc(struct page_pool* pool, size_t num_pages, bool aligned, struct ppa
8888
*/
8989
for (size_t i = 0; i < 2 && !ok; i++) {
9090
while (pool->free != 0) {
91-
ssize_t bit = bitmap_find_consec(pool->bitmap, pool->num_pages, curr, num_pages, false);
91+
ssize_t bit =
92+
bitmap_find_consec(pool->bitmap, pool->num_pages, curr, num_pages, BITMAP_NOT_SET);
9293

9394
if (bit < 0) {
9495
/**

0 commit comments

Comments
 (0)