LCOV - code coverage report
Current view: top level - core - time-utils.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 18 18 100.0 %
Date: 2024-09-10 18:37:41 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Converts an OPAL formatted datetime into a struct tm. We ignore microseconds
       4                 :            :  * as Linux doesn't use them anyway.
       5                 :            :  *
       6                 :            :  *  |      year       | month |   mday   |
       7                 :            :  *  +------------------------------------+
       8                 :            :  *  |  hour  | minute | secs  | reserved |
       9                 :            :  *  +------------------------------------+
      10                 :            :  *  |             microseconds           |
      11                 :            :  *
      12                 :            :  * Copyright 2013-2014 IBM Corp.
      13                 :            :  */
      14                 :            : 
      15                 :            : #include <time-utils.h>
      16                 :            : 
      17                 :          1 : void datetime_to_tm(uint32_t y_m_d, uint64_t h_m_s_m, struct tm *tm)
      18                 :            : {
      19                 :            :         uint32_t x;
      20                 :            : 
      21                 :          1 :         tm->tm_year = bcd_byte(y_m_d, 3) * 100 + bcd_byte(y_m_d, 2);
      22                 :          1 :         tm->tm_mon = bcd_byte(y_m_d, 1) - 1;
      23                 :          1 :         tm->tm_mday = bcd_byte(y_m_d, 0);
      24                 :            : 
      25                 :          1 :         x = h_m_s_m >> 32;
      26                 :          1 :         tm->tm_hour = bcd_byte(x, 3);
      27                 :          1 :         tm->tm_min = bcd_byte(x, 2);
      28                 :          1 :         tm->tm_sec = bcd_byte(x, 1);
      29                 :          1 : }
      30                 :            : 
      31                 :            : /*
      32                 :            :  * The OPAL API is defined as returned a u64 of a similar
      33                 :            :  * format to the FSP message; the 32-bit date field is
      34                 :            :  * in the format:
      35                 :            :  *
      36                 :            :  * |      year        | month |   mday   |
      37                 :            :  *
      38                 :            :  * ... and the 64-bit time field is in the format
      39                 :            :  *
      40                 :            :  * |  hour  | minutes | secs  | millisec |
      41                 :            :  * | -------------------------------------
      42                 :            :  * |        millisec          | reserved |
      43                 :            :  *
      44                 :            :  * We simply ignore the microseconds/milliseconds for now
      45                 :            :  * as I don't quite understand why the OPAL API defines that
      46                 :            :  * it needs 6 digits for the milliseconds :-) I suspect the
      47                 :            :  * doc got that wrong and it's supposed to be micro but
      48                 :            :  * let's ignore it.
      49                 :            :  *
      50                 :            :  * Note that Linux doesn't use nor set the ms field anyway.
      51                 :            :  */
      52                 :          1 : void tm_to_datetime(struct tm *tm, uint32_t *y_m_d, uint64_t *h_m_s_m)
      53                 :            : {
      54                 :            :         uint64_t h_m_s;
      55                 :          1 :         *y_m_d = int_to_bcd4(tm->tm_year) << 16 |
      56                 :          1 :                  int_to_bcd2(tm->tm_mon + 1) << 8 |
      57                 :          1 :                  int_to_bcd2(tm->tm_mday);
      58                 :            : 
      59                 :          1 :         h_m_s = int_to_bcd2(tm->tm_hour) << 24 |
      60                 :          1 :                 int_to_bcd2(tm->tm_min) << 16 |
      61                 :          1 :                 int_to_bcd2(tm->tm_sec) << 8;
      62                 :            : 
      63                 :          1 :         *h_m_s_m = h_m_s << 32;
      64                 :          1 : }

Generated by: LCOV version 1.14