From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jan Beulich" Subject: [PATCH] x86: allow Dom0 to drive PC speaker Date: Thu, 23 Aug 2007 14:48:13 +0100 Message-ID: <46CDAC3D.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org .. as long as Xen doesn't itself make use of PIT channel 2. Signed-off-by: Jan Beulich Index: 2007-08-08/xen/arch/x86/domain_build.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-08-08.orig/xen/arch/x86/domain_build.c 2007-08-07 15:00:27.0000000= 00 +0200 +++ 2007-08-08/xen/arch/x86/domain_build.c 2007-08-23 11:42:20.0000000= 00 +0200 @@ -967,6 +967,8 @@ int __init construct_dom0( rc |=3D ioports_deny_access(dom0, 0xA0, 0xA1); /* Interval Timer (PIT). */ rc |=3D ioports_deny_access(dom0, 0x40, 0x43); + if ( !using_pit ) + rc |=3D ioports_permit_access(dom0, 0x42, 0x42); /* PIT Channel 2 / PC Speaker Control. */ rc |=3D ioports_deny_access(dom0, 0x61, 0x61); /* Command-line I/O ranges. */ Index: 2007-08-08/xen/arch/x86/hvm/i8254.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-08-08.orig/xen/arch/x86/hvm/i8254.c 2007-06-18 08:34:29.0000000= 00 +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; } =20 +#include + int pv_pit_handler(int port, int data, int write) { ioreq_t ioreq =3D { .size =3D 1, .type =3D IOREQ_TYPE_PIO, .addr =3D port, - .dir =3D write ? 0 : 1, - .data =3D write ? data : 0, + .dir =3D write ? IOREQ_WRITE : IOREQ_READ, + .data =3D data }; =20 if ( port =3D=3D 0x61 ) + { + if ( !using_pit && current->domain->domain_id =3D=3D 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 =3D=3D 0 && + port =3D=3D PIT_MODE && write ) + { + switch ( data & 0xc0 ) + { + case 0xc0: /* read back */ + outb(data & 0xf8, PIT_MODE); + if ( !(data & 0x07) ) + return 0; + data &=3D ~0x08; + break; + case 0x80: /* counter 2 latch */ + outb(data, PIT_MODE); + return 0; + } + } handle_pit_io(&ioreq); + } =20 return !write ? ioreq.data : 0; } Index: 2007-08-08/xen/arch/x86/time.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 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) =20 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; =20 /* 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 =3D CLOCK_TICK_RATE; pts->read_counter =3D read_pit_count; pts->counter_bits =3D 16; + using_pit =3D 1; } =20 /************************************************************ Index: 2007-08-08/xen/include/asm-x86/time.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- 2007-08-08.orig/xen/include/asm-x86/time.h 2007-06-15 14:05:46.0000000= 00 +0200 +++ 2007-08-08/xen/include/asm-x86/time.h 2007-08-23 11:37:34.0000000= 00 +0200 @@ -4,6 +4,8 @@ =20 #include =20 +extern int using_pit; + extern void calibrate_tsc_bp(void); extern void calibrate_tsc_ap(void); =20