WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] x86: allow Dom0 to drive PC speaker

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] x86: allow Dom0 to drive PC speaker
From: "Jan Beulich" <jbeulich@xxxxxxxxxx>
Date: Thu, 23 Aug 2007 14:48:13 +0100
Delivery-date: Thu, 23 Aug 2007 06:48:34 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
.. as long as Xen doesn't itself make use of PIT channel 2.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2007-08-08/xen/arch/x86/domain_build.c
===================================================================
--- 2007-08-08.orig/xen/arch/x86/domain_build.c 2007-08-07 15:00:27.000000000 
+0200
+++ 2007-08-08/xen/arch/x86/domain_build.c      2007-08-23 11:42:20.000000000 
+0200
@@ -967,6 +967,8 @@ int __init construct_dom0(
     rc |= ioports_deny_access(dom0, 0xA0, 0xA1);
     /* Interval Timer (PIT). */
     rc |= ioports_deny_access(dom0, 0x40, 0x43);
+    if ( !using_pit )
+        rc |= ioports_permit_access(dom0, 0x42, 0x42);
     /* PIT Channel 2 / PC Speaker Control. */
     rc |= ioports_deny_access(dom0, 0x61, 0x61);
     /* Command-line I/O ranges. */
Index: 2007-08-08/xen/arch/x86/hvm/i8254.c
===================================================================
--- 2007-08-08.orig/xen/arch/x86/hvm/i8254.c    2007-06-18 08:34:29.000000000 
+0200
+++ 2007-08-08/xen/arch/x86/hvm/i8254.c 2007-08-23 11:47:42.000000000 +0200
@@ -592,20 +592,49 @@ static int handle_speaker_io(ioreq_t *p)
     return 1;
 }
 
+#include <io_ports.h>
+
 int pv_pit_handler(int port, int data, int write)
 {
     ioreq_t ioreq = {
         .size = 1,
         .type = IOREQ_TYPE_PIO,
         .addr = port,
-        .dir  = write ? 0 : 1,
-        .data = write ? data : 0,
+        .dir  = write ? IOREQ_WRITE : IOREQ_READ,
+        .data = data
     };
 
     if ( port == 0x61 )
+    {
+        if ( !using_pit && current->domain->domain_id == 0 )
+        {
+            if ( !write )
+                return inb(0x61);
+            outb((inb(0x61) & ~3) | (data & 3), 0x61);
+            return 0;
+        }
         handle_speaker_io(&ioreq);
+    }
     else
+    {
+        if ( !using_pit && current->domain->domain_id == 0 &&
+             port == PIT_MODE && write )
+        {
+            switch ( data & 0xc0 )
+            {
+                case 0xc0: /* read back */
+                    outb(data & 0xf8, PIT_MODE);
+                    if ( !(data & 0x07) )
+                        return 0;
+                    data &= ~0x08;
+                    break;
+                case 0x80: /* counter 2 latch */
+                    outb(data, PIT_MODE);
+                    return 0;
+            }
+        }
         handle_pit_io(&ioreq);
+    }
 
     return !write ? ioreq.data : 0;
 }
Index: 2007-08-08/xen/arch/x86/time.c
===================================================================
--- 2007-08-08.orig/xen/arch/x86/time.c 2007-06-15 14:05:46.000000000 +0200
+++ 2007-08-08/xen/arch/x86/time.c      2007-08-23 11:33:37.000000000 +0200
@@ -38,6 +38,7 @@ string_param("clocksource", opt_clocksou
 #define EPOCH MILLISECS(1000)
 
 unsigned long cpu_khz;  /* CPU clock frequency in kHz. */
+int using_pit;
 unsigned long hpet_address;
 DEFINE_SPINLOCK(rtc_lock);
 volatile unsigned long jiffies;
@@ -177,7 +178,6 @@ static u64 init_pit_and_calibrate_tsc(vo
     unsigned long count;
 
     /* Set PIT channel 0 to HZ Hz. */
-#define CLOCK_TICK_RATE 1193180 /* crystal freq (Hz) */
 #define LATCH (((CLOCK_TICK_RATE)+(HZ/2))/HZ)
     outb_p(0x34, PIT_MODE);        /* binary, mode 2, LSB/MSB, ch 0 */
     outb_p(LATCH & 0xff, PIT_CH0); /* LSB */
@@ -308,6 +308,7 @@ static void init_pit(struct platform_tim
     pts->frequency = CLOCK_TICK_RATE;
     pts->read_counter = read_pit_count;
     pts->counter_bits = 16;
+    using_pit = 1;
 }
 
 /************************************************************
Index: 2007-08-08/xen/include/asm-x86/time.h
===================================================================
--- 2007-08-08.orig/xen/include/asm-x86/time.h  2007-06-15 14:05:46.000000000 
+0200
+++ 2007-08-08/xen/include/asm-x86/time.h       2007-08-23 11:37:34.000000000 
+0200
@@ -4,6 +4,8 @@
 
 #include <asm/msr.h>
 
+extern int using_pit;
+
 extern void calibrate_tsc_bp(void);
 extern void calibrate_tsc_ap(void);
 




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] x86: allow Dom0 to drive PC speaker, Jan Beulich <=