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