Skip to content

Commit

Permalink
rtc: Move RTC function prototypes to their own header
Browse files Browse the repository at this point in the history
softmmu/rtc.c defines two public functions: qemu_get_timedate() and
qemu_timedate_diff().  Currently we keep the prototypes for these in
qemu-common.h, but most files don't need them.  Move them to their
own header, a new include/sysemu/rtc.h.

Since the C files using these two functions did not need to include
qemu-common.h for any other reason, we can remove those include lines
when we add the include of the new rtc.h.

The license for the .h file follows that of the softmmu/rtc.c
where both the functions are defined.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
  • Loading branch information
pm215 committed Jan 28, 2022
1 parent 617dff0 commit 2f93d8b
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 25 deletions.
2 changes: 1 addition & 1 deletion hw/arm/omap1.c
Expand Up @@ -21,7 +21,6 @@
#include "qemu/error-report.h"
#include "qemu/main-loop.h"
#include "qapi/error.h"
#include "qemu-common.h"
#include "cpu.h"
#include "exec/address-spaces.h"
#include "hw/hw.h"
Expand All @@ -35,6 +34,7 @@
#include "sysemu/qtest.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
#include "sysemu/rtc.h"
#include "qemu/range.h"
#include "hw/sysbus.h"
#include "qemu/cutils.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/arm/pxa2xx.c
Expand Up @@ -8,7 +8,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/error-report.h"
#include "qemu/module.h"
#include "qapi/error.h"
Expand All @@ -27,6 +26,7 @@
#include "chardev/char-fe.h"
#include "sysemu/blockdev.h"
#include "sysemu/qtest.h"
#include "sysemu/rtc.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
#include "qom/object.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/arm/strongarm.c
Expand Up @@ -28,7 +28,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "cpu.h"
#include "hw/irq.h"
#include "hw/qdev-properties.h"
Expand All @@ -41,6 +40,7 @@
#include "chardev/char-fe.h"
#include "chardev/char-serial.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "hw/ssi/ssi.h"
#include "qapi/error.h"
#include "qemu/cutils.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/misc/mac_via.c
Expand Up @@ -16,7 +16,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "migration/vmstate.h"
#include "hw/sysbus.h"
#include "hw/irq.h"
Expand All @@ -30,6 +29,7 @@
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "sysemu/block-backend.h"
#include "sysemu/rtc.h"
#include "trace.h"
#include "qemu/log.h"

Expand Down
2 changes: 1 addition & 1 deletion hw/misc/macio/cuda.c
Expand Up @@ -24,7 +24,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/ppc/mac.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
Expand All @@ -34,6 +33,7 @@
#include "qapi/error.h"
#include "qemu/timer.h"
#include "sysemu/runstate.h"
#include "sysemu/rtc.h"
#include "qapi/error.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/misc/macio/pmu.c
Expand Up @@ -29,7 +29,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/ppc/mac.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
Expand All @@ -41,6 +40,7 @@
#include "qapi/error.h"
#include "qemu/timer.h"
#include "sysemu/runstate.h"
#include "sysemu/rtc.h"
#include "qapi/error.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/ppc/spapr_rtc.c
Expand Up @@ -26,9 +26,9 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/timer.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "hw/ppc/spapr.h"
#include "migration/vmstate.h"
#include "qapi/error.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/allwinner-rtc.c
Expand Up @@ -23,9 +23,9 @@
#include "migration/vmstate.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu-common.h"
#include "hw/qdev-properties.h"
#include "hw/rtc/allwinner-rtc.h"
#include "sysemu/rtc.h"
#include "trace.h"

/* RTC registers */
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/aspeed_rtc.c
Expand Up @@ -7,11 +7,11 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/rtc/aspeed_rtc.h"
#include "migration/vmstate.h"
#include "qemu/log.h"
#include "qemu/timer.h"
#include "sysemu/rtc.h"

#include "trace.h"

Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/ds1338.c
Expand Up @@ -11,12 +11,12 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/i2c/i2c.h"
#include "migration/vmstate.h"
#include "qemu/bcd.h"
#include "qemu/module.h"
#include "qom/object.h"
#include "sysemu/rtc.h"

/* Size of NVRAM including both the user-accessible area and the
* secondary register area.
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/exynos4210_rtc.c
Expand Up @@ -26,7 +26,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "hw/sysbus.h"
Expand All @@ -39,6 +38,7 @@

#include "hw/arm/exynos4210.h"
#include "qom/object.h"
#include "sysemu/rtc.h"

#define DEBUG_RTC 0

Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/goldfish_rtc.c
Expand Up @@ -20,7 +20,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/rtc/goldfish_rtc.h"
#include "migration/vmstate.h"
#include "hw/irq.h"
Expand All @@ -29,6 +28,7 @@
#include "qemu/bitops.h"
#include "qemu/timer.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "qemu/cutils.h"
#include "qemu/log.h"

Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/m41t80.c
Expand Up @@ -8,13 +8,13 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/timer.h"
#include "qemu/bcd.h"
#include "hw/i2c/i2c.h"
#include "qom/object.h"
#include "sysemu/rtc.h"

#define TYPE_M41T80 "m41t80"
OBJECT_DECLARE_SIMPLE_TYPE(M41t80State, M41T80)
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/m48t59.c
Expand Up @@ -24,12 +24,12 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/irq.h"
#include "hw/qdev-properties.h"
#include "hw/rtc/m48t59.h"
#include "qemu/timer.h"
#include "sysemu/runstate.h"
#include "sysemu/rtc.h"
#include "sysemu/sysemu.h"
#include "hw/sysbus.h"
#include "qapi/error.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/mc146818rtc.c
Expand Up @@ -23,7 +23,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/cutils.h"
#include "qemu/module.h"
#include "qemu/bcd.h"
Expand All @@ -36,6 +35,7 @@
#include "sysemu/replay.h"
#include "sysemu/reset.h"
#include "sysemu/runstate.h"
#include "sysemu/rtc.h"
#include "hw/rtc/mc146818rtc.h"
#include "hw/rtc/mc146818rtc_regs.h"
#include "migration/vmstate.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/pl031.c
Expand Up @@ -12,14 +12,14 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/rtc/pl031.h"
#include "migration/vmstate.h"
#include "hw/irq.h"
#include "hw/qdev-properties.h"
#include "hw/sysbus.h"
#include "qemu/timer.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
#include "qemu/module.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/twl92230.c
Expand Up @@ -20,13 +20,13 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/timer.h"
#include "hw/i2c/i2c.h"
#include "hw/irq.h"
#include "migration/qemu-file-types.h"
#include "migration/vmstate.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "qemu/bcd.h"
#include "qemu/module.h"
#include "qom/object.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/xlnx-zynqmp-rtc.c
Expand Up @@ -25,7 +25,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/sysbus.h"
#include "hw/register.h"
#include "qemu/bitops.h"
Expand All @@ -34,6 +33,7 @@
#include "hw/irq.h"
#include "qemu/cutils.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"
#include "trace.h"
#include "hw/rtc/xlnx-zynqmp-rtc.h"
#include "migration/vmstate.h"
Expand Down
2 changes: 1 addition & 1 deletion hw/s390x/tod-tcg.c
Expand Up @@ -9,14 +9,14 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qapi/error.h"
#include "hw/s390x/tod.h"
#include "qemu/timer.h"
#include "qemu/cutils.h"
#include "qemu/module.h"
#include "cpu.h"
#include "tcg/tcg_s390x.h"
#include "sysemu/rtc.h"

static void qemu_s390_tod_get(const S390TODState *td, S390TOD *tod,
Error **errp)
Expand Down
2 changes: 1 addition & 1 deletion hw/scsi/megasas.c
Expand Up @@ -19,11 +19,11 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "hw/pci/pci.h"
#include "hw/qdev-properties.h"
#include "sysemu/dma.h"
#include "sysemu/block-backend.h"
#include "sysemu/rtc.h"
#include "hw/pci/msi.h"
#include "hw/pci/msix.h"
#include "qemu/iov.h"
Expand Down
3 changes: 0 additions & 3 deletions include/qemu-common.h
Expand Up @@ -26,9 +26,6 @@
int qemu_main(int argc, char **argv, char **envp);
#endif

void qemu_get_timedate(struct tm *tm, int offset);
int qemu_timedate_diff(struct tm *tm);

void *qemu_oom_check(void *ptr);

ssize_t qemu_write_full(int fd, const void *buf, size_t count)
Expand Down
58 changes: 58 additions & 0 deletions include/sysemu/rtc.h
@@ -0,0 +1,58 @@
/*
* RTC configuration and clock read
*
* Copyright (c) 2003-2021 QEMU contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef SYSEMU_RTC_H
#define SYSEMU_RTC_H

/**
* qemu_get_timedate: Get the current RTC time
* @tm: struct tm to fill in with RTC time
* @offset: offset in seconds to adjust the RTC time by before
* converting to struct tm format.
*
* This function fills in @tm with the current RTC time, as adjusted
* by @offset (for example, if @offset is 3600 then the returned time/date
* will be one hour further ahead than the current RTC time).
*
* The usual use is by RTC device models, which should call this function
* to find the time/date value that they should return to the guest
* when it reads the RTC registers.
*
* The behaviour of the clock whose value this function returns will
* depend on the -rtc command line option passed by the user.
*/
void qemu_get_timedate(struct tm *tm, int offset);

/**
* qemu_timedate_diff: Return difference between a struct tm and the RTC
* @tm: struct tm containing the date/time to compare against
*
* Returns the difference in seconds between the RTC clock time
* and the date/time specified in @tm. For example, if @tm specifies
* a timestamp one hour further ahead than the current RTC time
* then this function will return 3600.
*/
int qemu_timedate_diff(struct tm *tm);

#endif
2 changes: 1 addition & 1 deletion net/dump.c
Expand Up @@ -23,7 +23,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "clients.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
Expand All @@ -33,6 +32,7 @@
#include "qapi/visitor.h"
#include "net/filter.h"
#include "qom/object.h"
#include "sysemu/rtc.h"

typedef struct DumpState {
int64_t start_ts;
Expand Down
2 changes: 1 addition & 1 deletion softmmu/rtc.c
Expand Up @@ -23,7 +23,6 @@
*/

#include "qemu/osdep.h"
#include "qemu-common.h"
#include "qemu/cutils.h"
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
Expand All @@ -33,6 +32,7 @@
#include "qom/object.h"
#include "sysemu/replay.h"
#include "sysemu/sysemu.h"
#include "sysemu/rtc.h"

static enum {
RTC_BASE_UTC,
Expand Down

0 comments on commit 2f93d8b

Please sign in to comment.