]>
Commit | Line | Data |
---|---|---|
12f42174 DG |
1 | /* |
2 | * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator | |
3 | * | |
4 | * RTAS Real Time Clock | |
5 | * | |
6 | * Copyright (c) 2010-2011 David Gibson, IBM Corporation. | |
7 | * Copyright 2014 David Gibson, Red Hat. | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
25 | * THE SOFTWARE. | |
26 | * | |
27 | */ | |
28 | #include "cpu.h" | |
29 | #include "hw/ppc/spapr.h" | |
30 | #include "qapi-event.h" | |
31 | ||
32 | static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, | |
33 | uint32_t token, uint32_t nargs, | |
34 | target_ulong args, | |
35 | uint32_t nret, target_ulong rets) | |
36 | { | |
37 | struct tm tm; | |
38 | ||
39 | if (nret != 8) { | |
40 | rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); | |
41 | return; | |
42 | } | |
43 | ||
44 | qemu_get_timedate(&tm, spapr->rtc_offset); | |
45 | ||
46 | rtas_st(rets, 0, RTAS_OUT_SUCCESS); | |
47 | rtas_st(rets, 1, tm.tm_year + 1900); | |
48 | rtas_st(rets, 2, tm.tm_mon + 1); | |
49 | rtas_st(rets, 3, tm.tm_mday); | |
50 | rtas_st(rets, 4, tm.tm_hour); | |
51 | rtas_st(rets, 5, tm.tm_min); | |
52 | rtas_st(rets, 6, tm.tm_sec); | |
53 | rtas_st(rets, 7, 0); /* we don't do nanoseconds */ | |
54 | } | |
55 | ||
56 | static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, | |
57 | uint32_t token, uint32_t nargs, | |
58 | target_ulong args, | |
59 | uint32_t nret, target_ulong rets) | |
60 | { | |
61 | struct tm tm; | |
62 | ||
63 | tm.tm_year = rtas_ld(args, 0) - 1900; | |
64 | tm.tm_mon = rtas_ld(args, 1) - 1; | |
65 | tm.tm_mday = rtas_ld(args, 2); | |
66 | tm.tm_hour = rtas_ld(args, 3); | |
67 | tm.tm_min = rtas_ld(args, 4); | |
68 | tm.tm_sec = rtas_ld(args, 5); | |
69 | ||
70 | /* Just generate a monitor event for the change */ | |
71 | qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort); | |
72 | spapr->rtc_offset = qemu_timedate_diff(&tm); | |
73 | ||
74 | rtas_st(rets, 0, RTAS_OUT_SUCCESS); | |
75 | } | |
76 | ||
77 | void spapr_rtc_init(void) | |
78 | { | |
79 | spapr_rtas_register(RTAS_GET_TIME_OF_DAY, "get-time-of-day", | |
80 | rtas_get_time_of_day); | |
81 | spapr_rtas_register(RTAS_SET_TIME_OF_DAY, "set-time-of-day", | |
82 | rtas_set_time_of_day); | |
83 | } |