diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2015-02-06 14:55:51 +1100 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2015-03-09 14:59:58 +0100 |
commit | 28df36a13a3b0b792d9df64f8db8a392df5e0b35 (patch) | |
tree | 3727bc07ee13341dfff801c381b8d6afabf2ca67 /hw/ppc/spapr_rtc.c | |
parent | f01c5d84775cfc877dc0b537565a168d043394e9 (diff) |
pseries: Make the PAPR RTC a qdev device
At present the PAPR RTC isn't a "device" as such - it's accessed only via
firmware/hypervisor calls, and is handled in the sPAPR core code. This
becomes inconvenient as we extend it in various ways.
This patch makes the PAPR RTC a separate device in the qemu device model.
For now, the only piece of device state - the rtc_offset - is still kept in
the global sPAPREnvironment structure. That's clearly wrong, but leaving
it to be fixed in a following patch makes for a clearer separation between
the internal re-organization of the device, and the behavioural changes
(because the migration stream format needs to change slightly when the
offset is moved into the device's own state).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'hw/ppc/spapr_rtc.c')
-rw-r--r-- | hw/ppc/spapr_rtc.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c index d6c7a223f9..b9f4704784 100644 --- a/hw/ppc/spapr_rtc.c +++ b/hw/ppc/spapr_rtc.c @@ -30,13 +30,25 @@ #include "hw/ppc/spapr.h" #include "qapi-event.h" +#define SPAPR_RTC(obj) \ + OBJECT_CHECK(sPAPRRTCState, (obj), TYPE_SPAPR_RTC) + +typedef struct sPAPRRTCState sPAPRRTCState; +struct sPAPRRTCState { + /*< private >*/ + SysBusDevice parent_obj; +}; + #define NSEC_PER_SEC 1000000000LL -void spapr_rtc_read(sPAPREnvironment *spapr, struct tm *tm, uint32_t *ns) +void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns) { + sPAPRRTCState *rtc = SPAPR_RTC(dev); int64_t host_ns = qemu_clock_get_ns(rtc_clock); time_t guest_s; + assert(rtc); + guest_s = host_ns / NSEC_PER_SEC + spapr->rtc_offset; if (tm) { @@ -60,7 +72,12 @@ static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, return; } - spapr_rtc_read(spapr, &tm, &ns); + if (!spapr->rtc) { + rtas_st(rets, 0, RTAS_OUT_HW_ERROR); + return; + } + + spapr_rtc_read(spapr->rtc, &tm, &ns); rtas_st(rets, 0, RTAS_OUT_SUCCESS); rtas_st(rets, 1, tm.tm_year + 1900); @@ -86,6 +103,11 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, return; } + if (!spapr->rtc) { + rtas_st(rets, 0, RTAS_OUT_HW_ERROR); + return; + } + tm.tm_year = rtas_ld(args, 0) - 1900; tm.tm_mon = rtas_ld(args, 1) - 1; tm.tm_mday = rtas_ld(args, 2); @@ -109,7 +131,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr, rtas_st(rets, 0, RTAS_OUT_SUCCESS); } -void spapr_rtc_init(void) +static void spapr_rtc_realize(DeviceState *dev, Error **errp) { struct tm tm; time_t host_s; @@ -121,9 +143,30 @@ void spapr_rtc_init(void) host_s = mktimegm(&tm); rtc_ns = qemu_clock_get_ns(rtc_clock); spapr->rtc_offset = host_s - rtc_ns / NSEC_PER_SEC; +} + +static void spapr_rtc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = spapr_rtc_realize; spapr_rtas_register(RTAS_GET_TIME_OF_DAY, "get-time-of-day", rtas_get_time_of_day); spapr_rtas_register(RTAS_SET_TIME_OF_DAY, "set-time-of-day", rtas_set_time_of_day); } + +static const TypeInfo spapr_rtc_info = { + .name = TYPE_SPAPR_RTC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(sPAPRRTCState), + .class_size = sizeof(XICSStateClass), + .class_init = spapr_rtc_class_init, +}; + +static void spapr_rtc_register_types(void) +{ + type_register_static(&spapr_rtc_info); +} +type_init(spapr_rtc_register_types) |