Skip to content

Commit 3f56835

Browse files
orzelmichalJulien Grall
authored andcommitted
arm/time,vtimer: Get rid of READ/WRITE_SYSREG32
AArch64 registers are 64bit whereas AArch32 registers are 32bit or 64bit. MSR/MRS are expecting 64bit values thus we should get rid of helpers READ/WRITE_SYSREG32 in favour of using READ/WRITE_SYSREG. We should also use register_t type when reading sysregs which can correspond to uint64_t or uint32_t. Even though many AArch64 registers have upper 32bit reserved it does not mean that they can't be widen in the future. Modify type of vtimer structure's member: ctl to register_t. Add macro CNTFRQ_MASK containing mask for timer clock frequency field of CNTFRQ_EL0 register. Modify CNTx_CTL_* macros to return unsigned long instead of unsigned int as ctl is now of type register_t. Signed-off-by: Michal Orzel <[email protected]> Acked-by: Julien Grall <[email protected]>
1 parent 86faae5 commit 3f56835

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

xen/arch/arm/time.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void __init preinit_xen_time(void)
145145
preinit_acpi_xen_time();
146146

147147
if ( !cpu_khz )
148-
cpu_khz = READ_SYSREG32(CNTFRQ_EL0) / 1000;
148+
cpu_khz = (READ_SYSREG(CNTFRQ_EL0) & CNTFRQ_MASK) / 1000;
149149

150150
res = platform_init_time();
151151
if ( res )
@@ -205,13 +205,13 @@ int reprogram_timer(s_time_t timeout)
205205

206206
if ( timeout == 0 )
207207
{
208-
WRITE_SYSREG32(0, CNTHP_CTL_EL2);
208+
WRITE_SYSREG(0, CNTHP_CTL_EL2);
209209
return 1;
210210
}
211211

212212
deadline = ns_to_ticks(timeout) + boot_count;
213213
WRITE_SYSREG64(deadline, CNTHP_CVAL_EL2);
214-
WRITE_SYSREG32(CNTx_CTL_ENABLE, CNTHP_CTL_EL2);
214+
WRITE_SYSREG(CNTx_CTL_ENABLE, CNTHP_CTL_EL2);
215215
isb();
216216

217217
/* No need to check for timers in the past; the Generic Timer fires
@@ -223,23 +223,23 @@ int reprogram_timer(s_time_t timeout)
223223
static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
224224
{
225225
if ( irq == (timer_irq[TIMER_HYP_PPI]) &&
226-
READ_SYSREG32(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
226+
READ_SYSREG(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
227227
{
228228
perfc_incr(hyp_timer_irqs);
229229
/* Signal the generic timer code to do its work */
230230
raise_softirq(TIMER_SOFTIRQ);
231231
/* Disable the timer to avoid more interrupts */
232-
WRITE_SYSREG32(0, CNTHP_CTL_EL2);
232+
WRITE_SYSREG(0, CNTHP_CTL_EL2);
233233
}
234234

235235
if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) &&
236-
READ_SYSREG32(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
236+
READ_SYSREG(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
237237
{
238238
perfc_incr(phys_timer_irqs);
239239
/* Signal the generic timer code to do its work */
240240
raise_softirq(TIMER_SOFTIRQ);
241241
/* Disable the timer to avoid more interrupts */
242-
WRITE_SYSREG32(0, CNTP_CTL_EL0);
242+
WRITE_SYSREG(0, CNTP_CTL_EL0);
243243
}
244244
}
245245

@@ -260,8 +260,8 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
260260

261261
perfc_incr(virt_timer_irqs);
262262

263-
current->arch.virt_timer.ctl = READ_SYSREG32(CNTV_CTL_EL0);
264-
WRITE_SYSREG32(current->arch.virt_timer.ctl | CNTx_CTL_MASK, CNTV_CTL_EL0);
263+
current->arch.virt_timer.ctl = READ_SYSREG(CNTV_CTL_EL0);
264+
WRITE_SYSREG(current->arch.virt_timer.ctl | CNTx_CTL_MASK, CNTV_CTL_EL0);
265265
vgic_inject_irq(current->domain, current, current->arch.virt_timer.irq, true);
266266
}
267267

@@ -297,9 +297,9 @@ void init_timer_interrupt(void)
297297
/* Sensible defaults */
298298
WRITE_SYSREG64(0, CNTVOFF_EL2); /* No VM-specific offset */
299299
/* Do not let the VMs program the physical timer, only read the physical counter */
300-
WRITE_SYSREG32(CNTHCTL_EL2_EL1PCTEN, CNTHCTL_EL2);
301-
WRITE_SYSREG32(0, CNTP_CTL_EL0); /* Physical timer disabled */
302-
WRITE_SYSREG32(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */
300+
WRITE_SYSREG(CNTHCTL_EL2_EL1PCTEN, CNTHCTL_EL2);
301+
WRITE_SYSREG(0, CNTP_CTL_EL0); /* Physical timer disabled */
302+
WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */
303303
isb();
304304

305305
request_irq(timer_irq[TIMER_HYP_PPI], 0, timer_interrupt,
@@ -320,8 +320,8 @@ void init_timer_interrupt(void)
320320
*/
321321
static void deinit_timer_interrupt(void)
322322
{
323-
WRITE_SYSREG32(0, CNTP_CTL_EL0); /* Disable physical timer */
324-
WRITE_SYSREG32(0, CNTHP_CTL_EL2); /* Disable hypervisor's timer */
323+
WRITE_SYSREG(0, CNTP_CTL_EL0); /* Disable physical timer */
324+
WRITE_SYSREG(0, CNTHP_CTL_EL2); /* Disable hypervisor's timer */
325325
isb();
326326

327327
release_irq(timer_irq[TIMER_HYP_PPI], NULL);

xen/arch/arm/vtimer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ void virt_timer_save(struct vcpu *v)
138138
{
139139
ASSERT(!is_idle_vcpu(v));
140140

141-
v->arch.virt_timer.ctl = READ_SYSREG32(CNTV_CTL_EL0);
142-
WRITE_SYSREG32(v->arch.virt_timer.ctl & ~CNTx_CTL_ENABLE, CNTV_CTL_EL0);
141+
v->arch.virt_timer.ctl = READ_SYSREG(CNTV_CTL_EL0);
142+
WRITE_SYSREG(v->arch.virt_timer.ctl & ~CNTx_CTL_ENABLE, CNTV_CTL_EL0);
143143
v->arch.virt_timer.cval = READ_SYSREG64(CNTV_CVAL_EL0);
144144
if ( (v->arch.virt_timer.ctl & CNTx_CTL_ENABLE) &&
145145
!(v->arch.virt_timer.ctl & CNTx_CTL_MASK))
@@ -159,7 +159,7 @@ void virt_timer_restore(struct vcpu *v)
159159

160160
WRITE_SYSREG64(v->domain->arch.virt_timer_base.offset, CNTVOFF_EL2);
161161
WRITE_SYSREG64(v->arch.virt_timer.cval, CNTV_CVAL_EL0);
162-
WRITE_SYSREG32(v->arch.virt_timer.ctl, CNTV_CTL_EL0);
162+
WRITE_SYSREG(v->arch.virt_timer.ctl, CNTV_CTL_EL0);
163163
}
164164

165165
static bool vtimer_cntp_ctl(struct cpu_user_regs *regs, uint32_t *r, bool read)
@@ -347,7 +347,7 @@ bool vtimer_emulate(struct cpu_user_regs *regs, union hsr hsr)
347347
}
348348

349349
static void vtimer_update_irq(struct vcpu *v, struct vtimer *vtimer,
350-
uint32_t vtimer_ctl)
350+
register_t vtimer_ctl)
351351
{
352352
bool level;
353353

@@ -389,7 +389,7 @@ void vtimer_update_irqs(struct vcpu *v)
389389
* but this requires reworking the arch timer to implement this.
390390
*/
391391
vtimer_update_irq(v, &v->arch.virt_timer,
392-
READ_SYSREG32(CNTV_CTL_EL0) & ~CNTx_CTL_MASK);
392+
READ_SYSREG(CNTV_CTL_EL0) & ~CNTx_CTL_MASK);
393393

394394
/* For the physical timer we rely on our emulated state. */
395395
vtimer_update_irq(v, &v->arch.phys_timer, v->arch.phys_timer.ctl);

xen/include/asm-arm/domain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct vtimer {
3636
struct vcpu *v;
3737
int irq;
3838
struct timer timer;
39-
uint32_t ctl;
39+
register_t ctl;
4040
uint64_t cval;
4141
};
4242

xen/include/asm-arm/processor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,12 @@ extern register_t __cpu_logical_map[];
485485

486486
/* Timer control registers */
487487
#define CNTx_CTL_ENABLE (1u<<0) /* Enable timer */
488-
#define CNTx_CTL_MASK (1u<<1) /* Mask IRQ */
488+
#define CNTx_CTL_MASK (1ul<<1) /* Mask IRQ */
489489
#define CNTx_CTL_PENDING (1u<<2) /* IRQ pending */
490490

491+
/* Timer frequency mask */
492+
#define CNTFRQ_MASK GENMASK(31, 0)
493+
491494
/* Exception Vector offsets */
492495
/* ... ARM32 */
493496
#define VECTOR32_RST 0

0 commit comments

Comments
 (0)