Skip to contentSkip to conversation

rtc emulation for xenU

PATCH New Ling, Xiaofeng 1 participant 1 message Oct 14, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtc emulation for xenU

There's an issue on x86_64 whereby booting an unpriv guest using a
kernel that has the RTC driver compiled in hangs when the rc scripts run
the command hwclock. The patch attached resolves the issue.
The patch adds a simple rtc emulation and also on i386, hwclock can get correct date when xenU enabled pirq binding, without this patch, hwclock read will timeout because of lack of update interrupt.

xen/arch/x86/domain.c +3 -1
diff -r 0845f66aa5d5 xen/arch/x86/domain.c
@@ -41,6 +41,7 @@
 #include <xen/kernel.h>
 #include <public/io/ioreq.h>
 #include <xen/multicall.h>
+#include <asm/x86_emulate.h>
 
 /* opt_noreboot: If true, machine will need manual reset on error. */
 static int opt_noreboot = 0;
@@ -286,7 +287,7 @@
 #endif
     
     (void)ptwr_init(d);
-    
+    (void)rtc_emu_init(d);
     shadow_lock_init(d);        
     INIT_LIST_HEAD(&d->arch.free_shadow_frames);
 }
@@ -995,6 +996,7 @@
     physdev_destroy_state(d);
 
     ptwr_destroy(d);
+    rtc_emu_destroy(d);
 
     /* Release device mappings of other domains */
     gnttab_release_dev_mappings(d->grant_table);
xen/arch/x86/time.c +73 -0

79 lines not on this page · raw message

xen/arch/x86/traps.c +14 -0
diff -r 0845f66aa5d5 xen/arch/x86/traps.c
@@ -785,8 +785,15 @@
     case 0xe5: /* IN imm8,%eax */
         port = insn_fetch(u8, 1, eip);
     exec_in:
+        if(v->domain->domain_id != 0)
+        {   
+            if(emulate_io_read(port, op_bytes, v, regs))
+                goto done;
+        }
         if ( !guest_io_okay(port, op_bytes, v, regs) )
+        {
             goto fail;
+        }
         switch ( op_bytes )
         {
         case 1:
@@ -814,8 +821,15 @@
     case 0xe7: /* OUT %eax,imm8 */
         port = insn_fetch(u8, 1, eip);
     exec_out:
+        if(v->domain->domain_id != 0)
+        {   
+            if(emulate_io_write(port, op_bytes, v, regs))
+                goto done;
+        }
         if ( !guest_io_okay(port, op_bytes, v, regs) )
+        {
             goto fail;
+        }
         switch ( op_bytes )
         {
         case 1:
xen/include/asm-x86/domain.h +1 -0
diff -r 0845f66aa5d5 xen/include/asm-x86/domain.h
@@ -65,6 +65,7 @@
 
     pagetable_t  phys_table;               /* guest 1:1 pagetable */
     struct virtual_platform_def vmx_platform;
+    void *cmos;      /* RTC emulation state*/
 } __cacheline_aligned;
 
 struct arch_vcpu
xen/include/asm-x86/time.h +15 -0
diff -r 0845f66aa5d5 xen/include/asm-x86/time.h
@@ -10,4 +10,19 @@
 struct domain;
 extern void init_domain_time(struct domain *d);
 
+struct tm
+{
+    int tm_sec;           /* Seconds. [0-60] (1 leap second) */
+    int tm_min;           /* Minutes. [0-59] */
+    int tm_hour;          /* Hours.   [0-23] */
+    int tm_mday;          /* Day.     [1-31] */
+    int tm_mon;           /* Month.   [0-11] */
+    int tm_year;          /* Year - 1900.  */
+    int tm_wday;          /* Day of week. [0-6] */
+    int tm_yday;          /* Days in year.[0-365] */
+    int tm_isdst;         /* DST.     [-1/0/1]*/
+};
+
+int gmtime (unsigned int time, struct tm *tp);
+
 #endif /* __X86_TIME_H__ */
xen/include/asm-x86/x86_emulate.h +10 -0
diff -r 0845f66aa5d5 xen/include/asm-x86/x86_emulate.h
@@ -166,4 +166,14 @@
 decode_register(
     u8 modrm_reg, struct cpu_user_regs *regs, int highbyte_regs);
 
+
+int emulate_io_write(unsigned int port, unsigned int bytes, 
+                struct vcpu *v, struct cpu_user_regs *regs );
+
+int emulate_io_read(unsigned int port, unsigned int bytes, 
+                struct vcpu *v, struct cpu_user_regs *regs );
+
+int rtc_emu_init(struct domain *d);
+void rtc_emu_destroy(struct domain *d);
+
 #endif /* __X86_EMULATE_H__ */
xen/arch/x86/rtc_emu.c new file +276 -0

276 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel