Skip to content

Commit b402521

Browse files
committed
[CORE] First-cut implementation of real-time clock device framework.
Signed-off-by: Anup Patel <[email protected]>
1 parent 8fb5553 commit b402521

File tree

9 files changed

+533
-3
lines changed

9 files changed

+533
-3
lines changed

arch/arm/configs/beagle-defconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Automatically generated make config: don't edit
33
# Project: Xvisor (eXtensible Versatile hypervISOR)
44
# Version: 0.1.1
5-
# Mon Feb 6 12:20:09 2012
5+
# Mon Feb 6 14:03:48 2012
66
#
77
# CONFIG_SMP is not set
88
CONFIG_ARCH_ARM=y
@@ -44,6 +44,7 @@ CONFIG_MAX_VCPU_COUNT=8
4444
CONFIG_MAX_GUEST_COUNT=2
4545
CONFIG_VGPA2REG_CACHE_SIZE=8
4646
CONFIG_VAPOOL_SIZE=8
47+
# CONFIG_RTC is not set
4748
# CONFIG_BLOCK is not set
4849
# CONFIG_NET is not set
4950
# CONFIG_PROFILE is not set

arch/arm/configs/pb-a8-defconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Automatically generated make config: don't edit
33
# Project: Xvisor (eXtensible Versatile hypervISOR)
44
# Version: 0.1.1
5-
# Mon Feb 6 12:19:28 2012
5+
# Mon Feb 6 14:03:20 2012
66
#
77
# CONFIG_SMP is not set
88
CONFIG_ARCH_ARM=y
@@ -44,6 +44,7 @@ CONFIG_MAX_VCPU_COUNT=8
4444
CONFIG_MAX_GUEST_COUNT=2
4545
CONFIG_VGPA2REG_CACHE_SIZE=8
4646
CONFIG_VAPOOL_SIZE=8
47+
# CONFIG_RTC is not set
4748
# CONFIG_BLOCK is not set
4849
# CONFIG_NET is not set
4950
# CONFIG_PROFILE is not set

arch/mips/configs/qemu-mips-defconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Automatically generated make config: don't edit
33
# Project: Xvisor (eXtensible Versatile hypervISOR)
44
# Version: 0.1.1
5-
# Mon Feb 6 12:21:33 2012
5+
# Mon Feb 6 14:04:15 2012
66
#
77
# CONFIG_SMP is not set
88
# CONFIG_ARCH_ARM is not set
@@ -29,6 +29,7 @@ CONFIG_MAX_VCPU_COUNT=8
2929
CONFIG_MAX_GUEST_COUNT=2
3030
CONFIG_VGPA2REG_CACHE_SIZE=8
3131
CONFIG_VAPOOL_SIZE=8
32+
# CONFIG_RTC is not set
3233
# CONFIG_BLOCK is not set
3334
# CONFIG_NET is not set
3435
# CONFIG_PROFILE is not set

core/include/rtc/vmm_rtcdev.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) 2012 Anup Patel.
3+
* All rights reserved.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2, or (at your option)
8+
* any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+
*
19+
* @file vmm_rtcdev.h
20+
* @version 1.0
21+
* @author Anup Patel ([email protected])
22+
* @brief Real-Time Clock Device framework header
23+
*/
24+
25+
#ifndef __VMM_RTCDEV_H_
26+
#define __VMM_RTCDEV_H_
27+
28+
#include <vmm_types.h>
29+
#include <vmm_spinlocks.h>
30+
#include <vmm_devdrv.h>
31+
#include <rtc/vmm_rtclib.h>
32+
33+
#define VMM_RTCDEV_CLASS_NAME "rtc"
34+
#define VMM_RTCDEV_CLASS_IPRIORITY 1
35+
36+
struct vmm_rtcdev;
37+
38+
typedef int (*vmm_rtcdev_set_time_t) (struct vmm_rtcdev * rdev,
39+
struct vmm_rtc_time * tm);
40+
41+
typedef int (*vmm_rtcdev_get_time_t) (struct vmm_rtcdev * rdev,
42+
struct vmm_rtc_time * tm);
43+
44+
struct vmm_rtcdev {
45+
char name[32];
46+
struct vmm_device *dev;
47+
vmm_rtcdev_set_time_t set_time;
48+
vmm_rtcdev_get_time_t get_time;
49+
void *priv;
50+
};
51+
52+
/** Set time in a rtc device */
53+
int vmm_rtcdev_set_time(struct vmm_rtcdev * rdev,
54+
struct vmm_rtc_time * tm);
55+
56+
/** Get time from a rtc device */
57+
int vmm_rtcdev_get_time(struct vmm_rtcdev * rdev,
58+
struct vmm_rtc_time * tm);
59+
60+
/** Register rtc device to device driver framework */
61+
int vmm_rtcdev_register(struct vmm_rtcdev * rdev);
62+
63+
/** Unregister rtc device from device driver framework */
64+
int vmm_rtcdev_unregister(struct vmm_rtcdev * rdev);
65+
66+
/** Find a rtc device in device driver framework */
67+
struct vmm_rtcdev *vmm_rtcdev_find(const char *name);
68+
69+
/** Get rtc device with given number */
70+
struct vmm_rtcdev *vmm_rtcdev_get(int num);
71+
72+
/** Count number of rtc devices */
73+
u32 vmm_rtcdev_count(void);
74+
75+
#endif /* __VMM_RTCDEV_H_ */

core/include/rtc/vmm_rtclib.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (c) 2012 Anup Patel.
3+
* All rights reserved.
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2, or (at your option)
8+
* any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+
*
19+
* @file vmm_rtclib.h
20+
* @version 1.0
21+
* @author Anup Patel ([email protected])
22+
* @brief Real-Time Clock Library header
23+
*/
24+
25+
#ifndef __VMM_RTCLIB_H_
26+
#define __VMM_RTCLIB_H_
27+
28+
#include <vmm_types.h>
29+
30+
struct vmm_rtc_time {
31+
int tm_sec;
32+
int tm_min;
33+
int tm_hour;
34+
int tm_mday;
35+
int tm_mon;
36+
int tm_year;
37+
int tm_wday;
38+
int tm_yday;
39+
int tm_isdst;
40+
};
41+
42+
/**
43+
* Check if given year is a leap year.
44+
*/
45+
bool vmm_rtc_is_leap_year(unsigned int year);
46+
47+
/**
48+
* The number of days in the month.
49+
*/
50+
unsigned int vmm_rtc_month_days(unsigned int month, unsigned int year);
51+
52+
/**
53+
* The number of days since January 1. (0 to 365)
54+
*/
55+
unsigned int vmm_rtc_year_days(unsigned int day,
56+
unsigned int month, unsigned int year);
57+
58+
/**
59+
* Check whether vmm_rtc_time instance represents a valid date/time.
60+
*/
61+
bool vmm_rtc_valid_tm(struct vmm_rtc_time *tm);
62+
63+
/**
64+
* Convert Gregorian date to seconds since 01-01-1970 00:00:00.
65+
*/
66+
void vmm_rtc_tm_to_time(struct vmm_rtc_time *tm, unsigned long *time);
67+
68+
/**
69+
* Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
70+
*/
71+
void vmm_rtc_time_to_tm(unsigned long time, struct vmm_rtc_time *tm);
72+
73+
#endif /* __VMM_RTCLIB_H_ */

core/openconf.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ config CONFIG_VAPOOL_SIZE
8080
help
8181
Specify the virtual address pool size in mega bytes.
8282
83+
config CONFIG_RTC
84+
bool "Enable Real-Time Clock Subsystem"
85+
default n
86+
help
87+
Enable real-time clock support for Xvisor.
88+
8389
config CONFIG_BLOCK
8490
bool "Enable Block Device Subsystem"
8591
default n

core/rtc/objects.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#/**
2+
# Copyright (c) 2012 Anup Patel.
3+
# All rights reserved.
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 2, or (at your option)
8+
# any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18+
#
19+
# @file objects.mk
20+
# @version 1.0
21+
# @author Anup Patel ([email protected])
22+
# @brief list of core objects to be build
23+
# */
24+
25+
core-objs-$(CONFIG_RTC)+= rtc/vmm_rtclib.o
26+
core-objs-$(CONFIG_RTC)+= rtc/vmm_rtcdev.o
27+

0 commit comments

Comments
 (0)