Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com> |
| 3 | * Copyright (c) 2004 Dmitry V. Levin <ldv@altlinux.org> |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * 3. The name of the author may not be used to endorse or promote products |
| 15 | * derived from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | #include <linux/ioctl.h> |
| 31 | #include <linux/rtc.h> |
| 32 | |
| 33 | static void |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 34 | print_rtc_time(struct tcb *tcp, const struct rtc_time *rt) |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 35 | { |
| 36 | tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, " |
| 37 | "tm_mday=%d, tm_mon=%d, tm_year=%d, ", |
| 38 | rt->tm_sec, rt->tm_min, rt->tm_hour, |
| 39 | rt->tm_mday, rt->tm_mon, rt->tm_year); |
| 40 | if (!abbrev(tcp)) |
| 41 | tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}", |
| 42 | rt->tm_wday, rt->tm_yday, rt->tm_isdst); |
| 43 | else |
| 44 | tprints("...}"); |
| 45 | } |
| 46 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 47 | static void |
| 48 | decode_rtc_time(struct tcb *tcp, const long addr) |
| 49 | { |
| 50 | struct rtc_time rt; |
| 51 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 52 | if (!umove_or_printaddr(tcp, addr, &rt)) |
| 53 | print_rtc_time(tcp, &rt); |
| 54 | } |
| 55 | |
| 56 | static void |
| 57 | decode_rtc_wkalrm(struct tcb *tcp, const long addr) |
| 58 | { |
| 59 | struct rtc_wkalrm wk; |
| 60 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 61 | if (!umove_or_printaddr(tcp, addr, &wk)) { |
| 62 | tprintf("{enabled=%d, pending=%d, ", wk.enabled, wk.pending); |
| 63 | print_rtc_time(tcp, &wk.time); |
| 64 | tprints("}"); |
| 65 | } |
| 66 | } |
| 67 | |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 68 | static void |
| 69 | decode_rtc_pll_info(struct tcb *tcp, const long addr) |
| 70 | { |
| 71 | struct rtc_pll_info pll; |
| 72 | |
| 73 | if (!umove_or_printaddr(tcp, addr, &pll)) |
| 74 | tprintf("{pll_ctrl=%d, pll_value=%d, pll_max=%d, pll_min=%d" |
| 75 | ", pll_posmult=%d, pll_negmult=%d, pll_clock=%ld}", |
| 76 | pll.pll_ctrl, pll.pll_value, pll.pll_max, pll.pll_min, |
| 77 | pll.pll_posmult, pll.pll_negmult, pll.pll_clock); |
| 78 | } |
| 79 | |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 80 | int |
| 81 | rtc_ioctl(struct tcb *tcp, const unsigned int code, const long arg) |
| 82 | { |
| 83 | switch (code) { |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 84 | case RTC_ALM_READ: |
| 85 | case RTC_RD_TIME: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 86 | if (entering(tcp)) |
| 87 | return 0; |
Dmitry V. Levin | e0b5e91 | 2016-05-25 07:37:44 +0000 | [diff] [blame] | 88 | /* fall through */ |
| 89 | case RTC_ALM_SET: |
| 90 | case RTC_SET_TIME: |
| 91 | tprints(", "); |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 92 | decode_rtc_time(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 93 | break; |
| 94 | case RTC_IRQP_SET: |
| 95 | case RTC_EPOCH_SET: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 96 | tprintf(", %lu", arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 97 | break; |
| 98 | case RTC_IRQP_READ: |
| 99 | case RTC_EPOCH_READ: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 100 | if (entering(tcp)) |
| 101 | return 0; |
| 102 | tprints(", "); |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 103 | printnum_ulong(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 104 | break; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 105 | case RTC_WKALM_RD: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 106 | if (entering(tcp)) |
| 107 | return 0; |
Dmitry V. Levin | e0b5e91 | 2016-05-25 07:37:44 +0000 | [diff] [blame] | 108 | /* fall through */ |
| 109 | case RTC_WKALM_SET: |
| 110 | tprints(", "); |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 111 | decode_rtc_wkalrm(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 112 | break; |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 113 | case RTC_PLL_GET: |
| 114 | if (entering(tcp)) |
| 115 | return 0; |
| 116 | /* fall through */ |
| 117 | case RTC_PLL_SET: |
| 118 | tprints(", "); |
| 119 | decode_rtc_pll_info(tcp, arg); |
| 120 | break; |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 121 | #ifdef RTC_VL_READ |
| 122 | case RTC_VL_READ: |
| 123 | if (entering(tcp)) |
| 124 | return 0; |
| 125 | tprints(", "); |
| 126 | printnum_int(tcp, arg, "%d"); |
| 127 | break; |
| 128 | #endif |
Dmitry V. Levin | 6085825 | 2016-05-25 07:44:19 +0000 | [diff] [blame^] | 129 | case RTC_AIE_ON: |
| 130 | case RTC_AIE_OFF: |
| 131 | case RTC_UIE_ON: |
| 132 | case RTC_UIE_OFF: |
| 133 | case RTC_PIE_ON: |
| 134 | case RTC_PIE_OFF: |
| 135 | case RTC_WIE_ON: |
| 136 | case RTC_WIE_OFF: |
| 137 | #ifdef RTC_VL_CLR |
| 138 | case RTC_VL_CLR: |
| 139 | #endif |
| 140 | /* no args */ |
| 141 | break; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 142 | default: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 143 | return RVAL_DECODED; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 144 | } |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 145 | |
| 146 | return RVAL_DECODED | 1; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 147 | } |