ppc/spapr: QOM'ify sPAPRRTCState
Also use an 'sPAPRRTCState' attribute under the sPAPR machine to hold the RTC object. Overall, these changes remove an unnecessary and implicit dependency on SysBus. Signed-off-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
3fa14fbe13
commit
147ff8079e
@ -1333,13 +1333,13 @@ static void spapr_create_nvram(sPAPRMachineState *spapr)
|
|||||||
|
|
||||||
static void spapr_rtc_create(sPAPRMachineState *spapr)
|
static void spapr_rtc_create(sPAPRMachineState *spapr)
|
||||||
{
|
{
|
||||||
DeviceState *dev = qdev_create(NULL, TYPE_SPAPR_RTC);
|
object_initialize(&spapr->rtc, sizeof(spapr->rtc), TYPE_SPAPR_RTC);
|
||||||
|
object_property_add_child(OBJECT(spapr), "rtc", OBJECT(&spapr->rtc),
|
||||||
qdev_init_nofail(dev);
|
&error_fatal);
|
||||||
spapr->rtc = dev;
|
object_property_set_bool(OBJECT(&spapr->rtc), true, "realized",
|
||||||
|
&error_fatal);
|
||||||
object_property_add_alias(qdev_get_machine(), "rtc-time",
|
object_property_add_alias(OBJECT(spapr), "rtc-time", OBJECT(&spapr->rtc),
|
||||||
OBJECT(spapr->rtc), "date", NULL);
|
"date", &error_fatal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns whether we want to use VGA or not */
|
/* Returns whether we want to use VGA or not */
|
||||||
@ -1377,7 +1377,7 @@ static int spapr_post_load(void *opaque, int version_id)
|
|||||||
* So when migrating from those versions, poke the incoming offset
|
* So when migrating from those versions, poke the incoming offset
|
||||||
* value into the RTC device */
|
* value into the RTC device */
|
||||||
if (version_id < 3) {
|
if (version_id < 3) {
|
||||||
err = spapr_rtc_import_offset(spapr->rtc, spapr->rtc_offset);
|
err = spapr_rtc_import_offset(&spapr->rtc, spapr->rtc_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
@ -422,7 +422,7 @@ static void spapr_init_maina(struct rtas_event_log_v6_maina *maina,
|
|||||||
maina->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_MAINA);
|
maina->hdr.section_id = cpu_to_be16(RTAS_LOG_V6_SECTION_ID_MAINA);
|
||||||
maina->hdr.section_length = cpu_to_be16(sizeof(*maina));
|
maina->hdr.section_length = cpu_to_be16(sizeof(*maina));
|
||||||
/* FIXME: section version, subtype and creator id? */
|
/* FIXME: section version, subtype and creator id? */
|
||||||
spapr_rtc_read(spapr->rtc, &tm, NULL);
|
spapr_rtc_read(&spapr->rtc, &tm, NULL);
|
||||||
year = tm.tm_year + 1900;
|
year = tm.tm_year + 1900;
|
||||||
maina->creation_date = cpu_to_be32((to_bcd(year / 100) << 24)
|
maina->creation_date = cpu_to_be32((to_bcd(year / 100) << 24)
|
||||||
| (to_bcd(year % 100) << 16)
|
| (to_bcd(year % 100) << 16)
|
||||||
|
@ -33,19 +33,8 @@
|
|||||||
#include "qapi-event.h"
|
#include "qapi-event.h"
|
||||||
#include "qemu/cutils.h"
|
#include "qemu/cutils.h"
|
||||||
|
|
||||||
#define SPAPR_RTC(obj) \
|
void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns)
|
||||||
OBJECT_CHECK(sPAPRRTCState, (obj), TYPE_SPAPR_RTC)
|
|
||||||
|
|
||||||
typedef struct sPAPRRTCState sPAPRRTCState;
|
|
||||||
struct sPAPRRTCState {
|
|
||||||
/*< private >*/
|
|
||||||
SysBusDevice parent_obj;
|
|
||||||
int64_t ns_offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
int64_t host_ns = qemu_clock_get_ns(rtc_clock);
|
||||||
int64_t guest_ns;
|
int64_t guest_ns;
|
||||||
time_t guest_s;
|
time_t guest_s;
|
||||||
@ -63,16 +52,12 @@ void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int spapr_rtc_import_offset(DeviceState *dev, int64_t legacy_offset)
|
int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t legacy_offset)
|
||||||
{
|
{
|
||||||
sPAPRRTCState *rtc;
|
if (!rtc) {
|
||||||
|
|
||||||
if (!dev) {
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc = SPAPR_RTC(dev);
|
|
||||||
|
|
||||||
rtc->ns_offset = legacy_offset * NANOSECONDS_PER_SECOND;
|
rtc->ns_offset = legacy_offset * NANOSECONDS_PER_SECOND;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -91,12 +76,7 @@ static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spapr->rtc) {
|
spapr_rtc_read(&spapr->rtc, &tm, &ns);
|
||||||
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, 0, RTAS_OUT_SUCCESS);
|
||||||
rtas_st(rets, 1, tm.tm_year + 1900);
|
rtas_st(rets, 1, tm.tm_year + 1900);
|
||||||
@ -113,7 +93,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
target_ulong args,
|
target_ulong args,
|
||||||
uint32_t nret, target_ulong rets)
|
uint32_t nret, target_ulong rets)
|
||||||
{
|
{
|
||||||
sPAPRRTCState *rtc;
|
sPAPRRTCState *rtc = &spapr->rtc;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
time_t new_s;
|
time_t new_s;
|
||||||
int64_t host_ns;
|
int64_t host_ns;
|
||||||
@ -123,11 +103,6 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spapr->rtc) {
|
|
||||||
rtas_st(rets, 0, RTAS_OUT_HW_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tm.tm_year = rtas_ld(args, 0) - 1900;
|
tm.tm_year = rtas_ld(args, 0) - 1900;
|
||||||
tm.tm_mon = rtas_ld(args, 1) - 1;
|
tm.tm_mon = rtas_ld(args, 1) - 1;
|
||||||
tm.tm_mday = rtas_ld(args, 2);
|
tm.tm_mday = rtas_ld(args, 2);
|
||||||
@ -144,8 +119,6 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
/* Generate a monitor event for the change */
|
/* Generate a monitor event for the change */
|
||||||
qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort);
|
qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort);
|
||||||
|
|
||||||
rtc = SPAPR_RTC(spapr->rtc);
|
|
||||||
|
|
||||||
host_ns = qemu_clock_get_ns(rtc_clock);
|
host_ns = qemu_clock_get_ns(rtc_clock);
|
||||||
|
|
||||||
rtc->ns_offset = (new_s * NANOSECONDS_PER_SECOND) - host_ns;
|
rtc->ns_offset = (new_s * NANOSECONDS_PER_SECOND) - host_ns;
|
||||||
@ -155,7 +128,7 @@ static void rtas_set_time_of_day(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
|||||||
|
|
||||||
static void spapr_rtc_qom_date(Object *obj, struct tm *current_tm, Error **errp)
|
static void spapr_rtc_qom_date(Object *obj, struct tm *current_tm, Error **errp)
|
||||||
{
|
{
|
||||||
spapr_rtc_read(DEVICE(obj), current_tm, NULL);
|
spapr_rtc_read(SPAPR_RTC(obj), current_tm, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spapr_rtc_realize(DeviceState *dev, Error **errp)
|
static void spapr_rtc_realize(DeviceState *dev, Error **errp)
|
||||||
@ -200,7 +173,7 @@ static void spapr_rtc_class_init(ObjectClass *oc, void *data)
|
|||||||
|
|
||||||
static const TypeInfo spapr_rtc_info = {
|
static const TypeInfo spapr_rtc_info = {
|
||||||
.name = TYPE_SPAPR_RTC,
|
.name = TYPE_SPAPR_RTC,
|
||||||
.parent = TYPE_SYS_BUS_DEVICE,
|
.parent = TYPE_DEVICE,
|
||||||
.instance_size = sizeof(sPAPRRTCState),
|
.instance_size = sizeof(sPAPRRTCState),
|
||||||
.class_init = spapr_rtc_class_init,
|
.class_init = spapr_rtc_class_init,
|
||||||
};
|
};
|
||||||
|
@ -20,6 +20,18 @@ typedef struct sPAPREventSource sPAPREventSource;
|
|||||||
|
|
||||||
#define SPAPR_TIMEBASE_FREQ 512000000ULL
|
#define SPAPR_TIMEBASE_FREQ 512000000ULL
|
||||||
|
|
||||||
|
#define TYPE_SPAPR_RTC "spapr-rtc"
|
||||||
|
|
||||||
|
#define SPAPR_RTC(obj) \
|
||||||
|
OBJECT_CHECK(sPAPRRTCState, (obj), TYPE_SPAPR_RTC)
|
||||||
|
|
||||||
|
typedef struct sPAPRRTCState sPAPRRTCState;
|
||||||
|
struct sPAPRRTCState {
|
||||||
|
/*< private >*/
|
||||||
|
DeviceState parent_obj;
|
||||||
|
int64_t ns_offset;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct sPAPRMachineClass sPAPRMachineClass;
|
typedef struct sPAPRMachineClass sPAPRMachineClass;
|
||||||
|
|
||||||
#define TYPE_SPAPR_MACHINE "spapr-machine"
|
#define TYPE_SPAPR_MACHINE "spapr-machine"
|
||||||
@ -58,7 +70,7 @@ struct sPAPRMachineState {
|
|||||||
QLIST_HEAD(, sPAPRPHBState) phbs;
|
QLIST_HEAD(, sPAPRPHBState) phbs;
|
||||||
struct sPAPRNVRAM *nvram;
|
struct sPAPRNVRAM *nvram;
|
||||||
ICSState *ics;
|
ICSState *ics;
|
||||||
DeviceState *rtc;
|
sPAPRRTCState rtc;
|
||||||
|
|
||||||
void *htab;
|
void *htab;
|
||||||
uint32_t htab_shift;
|
uint32_t htab_shift;
|
||||||
@ -629,11 +641,10 @@ struct sPAPRConfigureConnectorState {
|
|||||||
|
|
||||||
void spapr_ccs_reset_hook(void *opaque);
|
void spapr_ccs_reset_hook(void *opaque);
|
||||||
|
|
||||||
#define TYPE_SPAPR_RTC "spapr-rtc"
|
void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns);
|
||||||
#define TYPE_SPAPR_RNG "spapr-rng"
|
int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t legacy_offset);
|
||||||
|
|
||||||
void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns);
|
#define TYPE_SPAPR_RNG "spapr-rng"
|
||||||
int spapr_rtc_import_offset(DeviceState *dev, int64_t legacy_offset);
|
|
||||||
|
|
||||||
int spapr_rng_populate_dt(void *fdt);
|
int spapr_rng_populate_dt(void *fdt);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#ifndef XICS_H
|
#ifndef XICS_H
|
||||||
#define XICS_H
|
#define XICS_H
|
||||||
|
|
||||||
#include "hw/sysbus.h"
|
#include "hw/qdev.h"
|
||||||
|
|
||||||
#define XICS_IPI 0x2
|
#define XICS_IPI 0x2
|
||||||
#define XICS_BUID 0x1
|
#define XICS_BUID 0x1
|
||||||
|
Loading…
Reference in New Issue
Block a user