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> |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 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" |
Dmitry V. Levin | 5d7812a | 2016-05-25 15:59:27 +0000 | [diff] [blame] | 30 | |
| 31 | #include DEF_MPERS_TYPE(struct_rtc_pll_info) |
| 32 | |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 33 | #include <linux/ioctl.h> |
| 34 | #include <linux/rtc.h> |
| 35 | |
Dmitry V. Levin | 5d7812a | 2016-05-25 15:59:27 +0000 | [diff] [blame] | 36 | typedef struct rtc_pll_info struct_rtc_pll_info; |
| 37 | |
| 38 | #include MPERS_DEFS |
| 39 | |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 40 | static void |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 41 | print_rtc_time(struct tcb *tcp, const struct rtc_time *rt) |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 42 | { |
| 43 | tprintf("{tm_sec=%d, tm_min=%d, tm_hour=%d, " |
| 44 | "tm_mday=%d, tm_mon=%d, tm_year=%d, ", |
| 45 | rt->tm_sec, rt->tm_min, rt->tm_hour, |
| 46 | rt->tm_mday, rt->tm_mon, rt->tm_year); |
| 47 | if (!abbrev(tcp)) |
| 48 | tprintf("tm_wday=%d, tm_yday=%d, tm_isdst=%d}", |
| 49 | rt->tm_wday, rt->tm_yday, rt->tm_isdst); |
| 50 | else |
| 51 | tprints("...}"); |
| 52 | } |
| 53 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 54 | static void |
| 55 | decode_rtc_time(struct tcb *tcp, const long addr) |
| 56 | { |
| 57 | struct rtc_time rt; |
| 58 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 59 | if (!umove_or_printaddr(tcp, addr, &rt)) |
| 60 | print_rtc_time(tcp, &rt); |
| 61 | } |
| 62 | |
| 63 | static void |
| 64 | decode_rtc_wkalrm(struct tcb *tcp, const long addr) |
| 65 | { |
| 66 | struct rtc_wkalrm wk; |
| 67 | |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 68 | if (!umove_or_printaddr(tcp, addr, &wk)) { |
Dmitry V. Levin | 7e3a381 | 2016-05-25 15:28:23 +0000 | [diff] [blame] | 69 | tprintf("{enabled=%d, pending=%d, time=", wk.enabled, wk.pending); |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 70 | print_rtc_time(tcp, &wk.time); |
| 71 | tprints("}"); |
| 72 | } |
| 73 | } |
| 74 | |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 75 | static void |
| 76 | decode_rtc_pll_info(struct tcb *tcp, const long addr) |
| 77 | { |
Dmitry V. Levin | 5d7812a | 2016-05-25 15:59:27 +0000 | [diff] [blame] | 78 | struct_rtc_pll_info pll; |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 79 | |
| 80 | if (!umove_or_printaddr(tcp, addr, &pll)) |
| 81 | tprintf("{pll_ctrl=%d, pll_value=%d, pll_max=%d, pll_min=%d" |
| 82 | ", pll_posmult=%d, pll_negmult=%d, pll_clock=%ld}", |
| 83 | 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] | 84 | pll.pll_posmult, pll.pll_negmult, (long) pll.pll_clock); |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Dmitry V. Levin | 5d7812a | 2016-05-25 15:59:27 +0000 | [diff] [blame] | 87 | MPERS_PRINTER_DECL(int, rtc_ioctl, struct tcb *tcp, |
| 88 | const unsigned int code, const long arg) |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 89 | { |
| 90 | switch (code) { |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 91 | case RTC_ALM_READ: |
| 92 | case RTC_RD_TIME: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 93 | if (entering(tcp)) |
| 94 | return 0; |
Dmitry V. Levin | e0b5e91 | 2016-05-25 07:37:44 +0000 | [diff] [blame] | 95 | /* fall through */ |
| 96 | case RTC_ALM_SET: |
| 97 | case RTC_SET_TIME: |
| 98 | tprints(", "); |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 99 | decode_rtc_time(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 100 | break; |
| 101 | case RTC_IRQP_SET: |
| 102 | case RTC_EPOCH_SET: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 103 | tprintf(", %lu", arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 104 | break; |
| 105 | case RTC_IRQP_READ: |
| 106 | case RTC_EPOCH_READ: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 107 | if (entering(tcp)) |
| 108 | return 0; |
| 109 | tprints(", "); |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 110 | printnum_ulong(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 111 | break; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 112 | case RTC_WKALM_RD: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 113 | if (entering(tcp)) |
| 114 | return 0; |
Dmitry V. Levin | e0b5e91 | 2016-05-25 07:37:44 +0000 | [diff] [blame] | 115 | /* fall through */ |
| 116 | case RTC_WKALM_SET: |
| 117 | tprints(", "); |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 118 | decode_rtc_wkalrm(tcp, arg); |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 119 | break; |
Dmitry V. Levin | 3adf229 | 2016-05-25 07:43:15 +0000 | [diff] [blame] | 120 | case RTC_PLL_GET: |
| 121 | if (entering(tcp)) |
| 122 | return 0; |
| 123 | /* fall through */ |
| 124 | case RTC_PLL_SET: |
| 125 | tprints(", "); |
| 126 | decode_rtc_pll_info(tcp, arg); |
| 127 | break; |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 128 | #ifdef RTC_VL_READ |
| 129 | case RTC_VL_READ: |
| 130 | if (entering(tcp)) |
| 131 | return 0; |
| 132 | tprints(", "); |
| 133 | printnum_int(tcp, arg, "%d"); |
| 134 | break; |
| 135 | #endif |
Dmitry V. Levin | 6085825 | 2016-05-25 07:44:19 +0000 | [diff] [blame] | 136 | case RTC_AIE_ON: |
| 137 | case RTC_AIE_OFF: |
| 138 | case RTC_UIE_ON: |
| 139 | case RTC_UIE_OFF: |
| 140 | case RTC_PIE_ON: |
| 141 | case RTC_PIE_OFF: |
| 142 | case RTC_WIE_ON: |
| 143 | case RTC_WIE_OFF: |
| 144 | #ifdef RTC_VL_CLR |
| 145 | case RTC_VL_CLR: |
| 146 | #endif |
| 147 | /* no args */ |
| 148 | break; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 149 | default: |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 150 | return RVAL_DECODED; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 151 | } |
Dmitry V. Levin | 97317d9 | 2015-07-04 15:07:35 +0300 | [diff] [blame] | 152 | |
| 153 | return RVAL_DECODED | 1; |
Dmitry V. Levin | 746db06 | 2015-07-04 08:56:21 +0000 | [diff] [blame] | 154 | } |