[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x86/vRTC: move and tidy convert_hour() and {to,from}_bcd()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 20 Jul 2023 09:11:10 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OjeOukCp0k3daKKrD7pGpG70FVirYbBKiZlD/ku4tRI=; b=jqQL7ZyiHpnOOv22MK6WIrvMbcsfJF5DLi45+T+ZFNqmqTldQcYMcSum2yiPKTca2V9ZZTl/YkFZ1qnameC+mNsnghg7aCS26IND7H8u+mZjhNxyyO+gBhrRkZxPy+qNB3Wn26tLc2MQIERTU8J4xCdZor6MvWinIoPNpomNiWq7XN8LdKkXgj45VugwiW4IBSIyi/XkEOX8ML4BN2wmt46u4qfZqLMjfaUQPskN2JxBoaHsKFunHzW9FJWNIZfw8vlg5HuKXSsTBNLlTOcJL+diUQxyjoRtcwT89hFnYFWCBNIGwjXKsIJ3v5vGD5lhrHyJU2dxjERTrYYlhjHFFQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gbcoTjpxPWGkE39TTubxurx/Fj2TrLMRpM2OUrG61Kvp/g+6haHxb4iWNnescCLok5Vw3pIA+wG8vBOt/6BU8NZvNYlyTza+MshFzVB07IGzAKZ5E7AHmkYuXGSBp0f0o8dbCJPGPRvwxRntazl56VuvaJrCNZlY4pEUSZRVDES9RLPoPXVptctJhyKffv4Gs81fZ7B4V4h/nvO8LoHIBPOemXd42IARJwLra9GRegWKNrbCeY6Evk6DS63Lq6DHnrni6uJe3xHFWT3+e6Bm7LPoJSggf/Cfi9Rs6rVyo1I3NBI617uFdAvheA318Vk1LvyZMrnIO/xvHpKMq9gtbQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Federico Serafini <federico.serafini@xxxxxxxxxxx>
  • Delivery-date: Thu, 20 Jul 2023 07:11:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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>

--- 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(v
     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
     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;



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.