s->pt.source = PTSRC_isa;
}
+/* RTC mediator for HVM hardware domain. */
+static int hw_rtc_io(int dir, unsigned int port, unsigned int size,
+ uint32_t *val)
+{
+ if ( dir == IOREQ_READ )
+ *val = ~0;
+
+ if ( size != 1 )
+ {
+ gdprintk(XENLOG_WARNING, "bad RTC access size (%u)\n", size);
+ return X86EMUL_OKAY;
+ }
+
+ if ( dir == IOREQ_WRITE )
+ rtc_guest_write(port, *val);
+ else
+ *val = rtc_guest_read(port);
+
+ return X86EMUL_OKAY;
+}
+
void rtc_init(struct domain *d)
{
RTCState *s = domain_vrtc(d);
if ( !has_vrtc(d) )
+ {
+ if ( is_hardware_domain(d) )
+ /* Hardware domain gets mediated access to the physical RTC. */
+ register_portio_handler(d, RTC_PORT(0), 2, hw_rtc_io);
return;
+ }
spin_lock_init(&s->lock);
{
sub_data = pv_pit_handler(port, 0, 0);
}
- else if ( port == RTC_PORT(0) )
+ else if ( port == RTC_PORT(0) || port == RTC_PORT(1) )
{
- sub_data = currd->arch.cmos_idx;
- }
- else if ( (port == RTC_PORT(1)) &&
- ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)) )
- {
- unsigned long flags;
-
- spin_lock_irqsave(&rtc_lock, flags);
- outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));
- sub_data = inb(RTC_PORT(1));
- spin_unlock_irqrestore(&rtc_lock, flags);
+ sub_data = rtc_guest_read(port);
}
else if ( (port == 0xcf8) && (bytes == 4) )
{
{
pv_pit_handler(port, (uint8_t)data, 1);
}
- else if ( port == RTC_PORT(0) )
- {
- currd->arch.cmos_idx = data;
- }
- else if ( (port == RTC_PORT(1)) &&
- ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)) )
+ else if ( port == RTC_PORT(0) || port == RTC_PORT(1) )
{
- unsigned long flags;
-
- if ( pv_rtc_handler )
- pv_rtc_handler(currd->arch.cmos_idx & 0x7f, data);
- spin_lock_irqsave(&rtc_lock, flags);
- outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));
- outb(data, RTC_PORT(1));
- spin_unlock_irqrestore(&rtc_lock, flags);
+ rtc_guest_write(port, data);
}
else if ( (port == 0xcf8) && (bytes == 4) )
{
#include <xen/keyhandler.h>
#include <xen/guest_access.h>
#include <asm/io.h>
+#include <asm/iocap.h>
#include <asm/msr.h>
#include <asm/mpspec.h>
#include <asm/processor.h>
return mktime(rtc.year, rtc.mon, rtc.day, rtc.hour, rtc.min, rtc.sec);
}
+/* Helpers for guest accesses to the physical RTC. */
+unsigned int rtc_guest_read(unsigned int port)
+{
+ const struct domain *currd = current->domain;
+ unsigned long flags;
+ unsigned int data = ~0;
+
+ switch ( port )
+ {
+ case RTC_PORT(0):
+ /*
+ * All PV domains (and PVH dom0) are allowed to read the latched value
+ * of the first RTC port, as there's no access to the physical IO
+ * ports.
+ */
+ data = currd->arch.cmos_idx;
+ break;
+
+ case RTC_PORT(1):
+ if ( !ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)) )
+ break;
+ spin_lock_irqsave(&rtc_lock, flags);
+ outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));
+ data = inb(RTC_PORT(1));
+ spin_unlock_irqrestore(&rtc_lock, flags);
+ break;
+
+ default:
+ ASSERT_UNREACHABLE();
+ }
+
+ return data;
+}
+
+void rtc_guest_write(unsigned int port, unsigned int data)
+{
+ struct domain *currd = current->domain;
+ unsigned long flags;
+
+ switch ( port )
+ {
+ case RTC_PORT(0):
+ /*
+ * All PV domains (and PVH dom0) are allowed to write to the latched
+ * value of the first RTC port, as there's no access to the physical IO
+ * ports.
+ */
+ currd->arch.cmos_idx = data;
+ break;
+
+ case RTC_PORT(1):
+ if ( !ioports_access_permitted(currd, RTC_PORT(0), RTC_PORT(1)) )
+ break;
+ spin_lock_irqsave(&rtc_lock, flags);
+ outb(currd->arch.cmos_idx & 0x7f, RTC_PORT(0));
+ outb(data, RTC_PORT(1));
+ spin_unlock_irqrestore(&rtc_lock, flags);
+ break;
+
+ default:
+ ASSERT_UNREACHABLE();
+ }
+}
+
static unsigned long get_wallclock_time(void)
{
#ifdef CONFIG_XEN_GUEST
#define RTC_IRQ 8
+unsigned int rtc_guest_read(unsigned int port);
+void rtc_guest_write(unsigned int port, unsigned int data);
+
#endif /* _ASM_MC146818RTC_H */