[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [xen master] x86/vRTC: move and tidy convert_hour() and {to,from}_bcd()
commit 60576722d0523122ce34c81b91fd1eafac8f7f5f Author: Jan Beulich <jbeulich@xxxxxxxx> AuthorDate: Fri Jul 21 08:31:09 2023 +0200 Commit: Jan Beulich <jbeulich@xxxxxxxx> CommitDate: Fri Jul 21 08:31:09 2023 +0200 x86/vRTC: move and tidy convert_hour() and {to,from}_bcd() This is to avoid the need for forward declarations, which in turn addresses a violation of MISRA C:2012 Rule 8.3 ("All declarations of an object or function shall use the same names and type qualifiers"). While doing so, - drop inline (leaving the decision to the compiler), - add const, - add unsigned, - correct style. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> Acked-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx> --- xen/arch/x86/hvm/rtc.c | 67 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/xen/arch/x86/hvm/rtc.c b/xen/arch/x86/hvm/rtc.c index c1ab6c7d58..206b4296e9 100644 --- a/xen/arch/x86/hvm/rtc.c +++ b/xen/arch/x86/hvm/rtc.c @@ -58,8 +58,6 @@ enum rtc_mode { static void rtc_copy_date(RTCState *s); static void rtc_set_time(RTCState *s); -static inline int from_bcd(RTCState *s, int a); -static inline int convert_hour(RTCState *s, int hour); static void rtc_update_irq(RTCState *s) { @@ -246,6 +244,40 @@ static void cf_check rtc_update_timer2(void *opaque) spin_unlock(&s->lock); } +static unsigned int to_bcd(const RTCState *s, unsigned int a) +{ + if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) + return a; + + return ((a / 10) << 4) | (a % 10); +} + +static unsigned int from_bcd(const RTCState *s, unsigned int a) +{ + if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) + return a; + + return ((a >> 4) * 10) + (a & 0x0f); +} + +/* + * Hours in 12 hour mode are in 1-12 range, not 0-11. So we need convert it + * before use. + */ +static unsigned int convert_hour(const RTCState *s, unsigned int raw) +{ + unsigned int hour = from_bcd(s, raw & 0x7f); + + if ( !(s->hw.cmos_data[RTC_REG_B] & RTC_24H) ) + { + hour %= 12; + if ( raw & 0x80 ) + hour += 12; + } + + return hour; +} + /* handle alarm timer */ static void alarm_timer_update(RTCState *s) { @@ -541,37 +573,6 @@ static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data) return 1; } -static inline int to_bcd(RTCState *s, int a) -{ - if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) - return a; - else - return ((a / 10) << 4) | (a % 10); -} - -static inline int from_bcd(RTCState *s, int a) -{ - if ( s->hw.cmos_data[RTC_REG_B] & RTC_DM_BINARY ) - return a; - else - return ((a >> 4) * 10) + (a & 0x0f); -} - -/* Hours in 12 hour mode are in 1-12 range, not 0-11. - * So we need convert it before using it*/ -static inline int convert_hour(RTCState *s, int raw) -{ - int hour = from_bcd(s, raw & 0x7f); - - if (!(s->hw.cmos_data[RTC_REG_B] & RTC_24H)) - { - hour %= 12; - if (raw & 0x80) - hour += 12; - } - return hour; -} - static void rtc_set_time(RTCState *s) { struct tm *tm = &s->current_tm; -- generated by git-patchbot for /home/xen/git/xen.git#master
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |