ia64/xen-unstable

changeset 13035:9f09cbe84629

Merge with xen-ia64-unstable.hg
author kfraser@localhost.localdomain
date Thu Dec 14 18:22:58 2006 +0000 (2006-12-14)
parents 2fc3392d0889 4d2ae322ef02
children de7d7b223db2
files
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/fbfront/xenfb.c	Thu Dec 14 09:56:41 2006 -0700
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/fbfront/xenfb.c	Thu Dec 14 18:22:58 2006 +0000
     1.3 @@ -105,7 +105,6 @@ static int xenfb_queue_full(struct xenfb
     1.4  
     1.5  static void xenfb_update_screen(struct xenfb_info *info)
     1.6  {
     1.7 -	unsigned long flags;
     1.8  	int y1, y2, x1, x2;
     1.9  	struct xenfb_mapping *map;
    1.10  
    1.11 @@ -114,7 +113,7 @@ static void xenfb_update_screen(struct x
    1.12  	if (xenfb_queue_full(info))
    1.13  		return;
    1.14  
    1.15 -	spin_lock_irqsave(&info->mm_lock, flags);
    1.16 +	spin_lock(&info->mm_lock);
    1.17  
    1.18  	y1 = info->y1;
    1.19  	y2 = info->y2;
    1.20 @@ -131,7 +130,7 @@ static void xenfb_update_screen(struct x
    1.21  		map->faults = 0;
    1.22  	}
    1.23  
    1.24 -	spin_unlock_irqrestore(&info->mm_lock, flags);
    1.25 +	spin_unlock(&info->mm_lock);
    1.26  
    1.27  	xenfb_do_update(info, x1, y1, x2 - x1, y2 - y1);
    1.28  }
    1.29 @@ -214,11 +213,9 @@ static void __xenfb_refresh(struct xenfb
    1.30  static void xenfb_refresh(struct xenfb_info *info,
    1.31  			  int x1, int y1, int w, int h)
    1.32  {
    1.33 -	unsigned long flags;
    1.34 -
    1.35 -	spin_lock_irqsave(&info->mm_lock, flags);
    1.36 +	spin_lock(&info->mm_lock);
    1.37  	__xenfb_refresh(info, x1, y1, w, h);
    1.38 -	spin_unlock_irqrestore(&info->mm_lock, flags);
    1.39 +	spin_unlock(&info->mm_lock);
    1.40  }
    1.41  
    1.42  static void xenfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
    1.43 @@ -255,14 +252,13 @@ static void xenfb_vm_close(struct vm_are
    1.44  {
    1.45  	struct xenfb_mapping *map = vma->vm_private_data;
    1.46  	struct xenfb_info *info = map->info;
    1.47 -	unsigned long flags;
    1.48  
    1.49 -	spin_lock_irqsave(&info->mm_lock, flags);
    1.50 +	spin_lock(&info->mm_lock);
    1.51  	if (atomic_dec_and_test(&map->map_refs)) {
    1.52  		list_del(&map->link);
    1.53  		kfree(map);
    1.54  	}
    1.55 -	spin_unlock_irqrestore(&info->mm_lock, flags);
    1.56 +	spin_unlock(&info->mm_lock);
    1.57  }
    1.58  
    1.59  static struct page *xenfb_vm_nopage(struct vm_area_struct *vma,
    1.60 @@ -271,14 +267,13 @@ static struct page *xenfb_vm_nopage(stru
    1.61  	struct xenfb_mapping *map = vma->vm_private_data;
    1.62  	struct xenfb_info *info = map->info;
    1.63  	int pgnr = (vaddr - vma->vm_start) >> PAGE_SHIFT;
    1.64 -	unsigned long flags;
    1.65  	struct page *page;
    1.66  	int y1, y2;
    1.67  
    1.68  	if (pgnr >= info->nr_pages)
    1.69  		return NOPAGE_SIGBUS;
    1.70  
    1.71 -	spin_lock_irqsave(&info->mm_lock, flags);
    1.72 +	spin_lock(&info->mm_lock);
    1.73  	page = info->pages[pgnr];
    1.74  	get_page(page);
    1.75  	map->faults++;
    1.76 @@ -288,7 +283,7 @@ static struct page *xenfb_vm_nopage(stru
    1.77  	if (y2 > info->fb_info->var.yres)
    1.78  		y2 = info->fb_info->var.yres;
    1.79  	__xenfb_refresh(info, 0, y1, info->fb_info->var.xres, y2 - y1);
    1.80 -	spin_unlock_irqrestore(&info->mm_lock, flags);
    1.81 +	spin_unlock(&info->mm_lock);
    1.82  
    1.83  	if (type)
    1.84  		*type = VM_FAULT_MINOR;
    1.85 @@ -305,7 +300,6 @@ static struct vm_operations_struct xenfb
    1.86  static int xenfb_mmap(struct fb_info *fb_info, struct vm_area_struct *vma)
    1.87  {
    1.88  	struct xenfb_info *info = fb_info->par;
    1.89 -	unsigned long flags;
    1.90  	struct xenfb_mapping *map;
    1.91  	int map_pages;
    1.92  
    1.93 @@ -329,9 +323,9 @@ static int xenfb_mmap(struct fb_info *fb
    1.94  	map->info = info;
    1.95  	atomic_set(&map->map_refs, 1);
    1.96  
    1.97 -	spin_lock_irqsave(&info->mm_lock, flags);
    1.98 +	spin_lock(&info->mm_lock);
    1.99  	list_add(&map->link, &info->mappings);
   1.100 -	spin_unlock_irqrestore(&info->mm_lock, flags);
   1.101 +	spin_unlock(&info->mm_lock);
   1.102  
   1.103  	vma->vm_ops = &xenfb_vm_ops;
   1.104  	vma->vm_flags |= (VM_DONTEXPAND | VM_RESERVED);
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Dec 14 09:56:41 2006 -0700
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Dec 14 18:22:58 2006 +0000
     2.3 @@ -525,6 +525,8 @@ static void backend_changed(struct xenbu
     2.4  		break;
     2.5  
     2.6  	case XenbusStateInitWait:
     2.7 +		if (dev->state != XenbusStateInitialising)
     2.8 +			break;
     2.9  		if (network_connect(netdev) != 0)
    2.10  			break;
    2.11  		xenbus_switch_state(dev, XenbusStateConnected);
    2.12 @@ -532,6 +534,8 @@ static void backend_changed(struct xenbu
    2.13  		break;
    2.14  
    2.15  	case XenbusStateClosing:
    2.16 +		if (dev->state == XenbusStateClosed)
    2.17 +			break;
    2.18  		netfront_closing(dev);
    2.19  		break;
    2.20  	}
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Thu Dec 14 09:56:41 2006 -0700
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Thu Dec 14 18:22:58 2006 +0000
     3.3 @@ -487,6 +487,8 @@ int xenbus_probe_node(struct xen_bus_typ
     3.4  	if (!xendev)
     3.5  		return -ENOMEM;
     3.6  
     3.7 +	xendev->state = XenbusStateInitialising;
     3.8 +
     3.9  	/* Copy the strings into the extra space. */
    3.10  
    3.11  	tmpstring = (char *)(xendev + 1);
     4.1 --- a/tools/Makefile	Thu Dec 14 09:56:41 2006 -0700
     4.2 +++ b/tools/Makefile	Thu Dec 14 18:22:58 2006 +0000
     4.3 @@ -36,7 +36,7 @@ all: check
     4.4  	$(MAKE) ioemu
     4.5  
     4.6  .PHONY: install
     4.7 -install: check
     4.8 +install: check_install
     4.9  	@set -e; for subdir in $(SUBDIRS-y); do \
    4.10  		$(MAKE) -C $$subdir $@; \
    4.11  	done
    4.12 @@ -58,6 +58,10 @@ distclean: clean
    4.13  check:
    4.14  	$(MAKE) -C check
    4.15  
    4.16 +.PHONY: check_install
    4.17 +check_install: check
    4.18 +	$(MAKE) -C check install
    4.19 +
    4.20  .PHONY: check_clean
    4.21  check_clean:
    4.22  	$(MAKE) -C check clean
     5.1 --- a/tools/check/check_crypto_lib	Thu Dec 14 09:56:41 2006 -0700
     5.2 +++ b/tools/check/check_crypto_lib	Thu Dec 14 18:22:58 2006 +0000
     5.3 @@ -1,11 +1,14 @@
     5.4 -#!/bin/bash
     5.5 +#!/bin/sh
     5.6  # CHECK-BUILD CHECK-INSTALL
     5.7  
     5.8 -function error {
     5.9 -    echo
    5.10 -    echo "  *** Check for crypto library FAILED"
    5.11 -    exit 1
    5.12 -}
    5.13 +RC=0
    5.14  
    5.15  set -e
    5.16 -ldconfig -p | grep -q libcrypto.so || error
    5.17 +ldconfig -v 2>&1 | grep -q libcrypto.so || RC=1
    5.18 +
    5.19 +if test ${RC} -ne 0; then
    5.20 +        echo
    5.21 +        echo " *** Check for crypto library FAILED"
    5.22 +fi
    5.23 +
    5.24 +exit ${RC}
     6.1 --- a/tools/check/check_openssl_devel	Thu Dec 14 09:56:41 2006 -0700
     6.2 +++ b/tools/check/check_openssl_devel	Thu Dec 14 18:22:58 2006 +0000
     6.3 @@ -1,11 +1,14 @@
     6.4 -#!/bin/bash
     6.5 +#!/bin/sh
     6.6  # CHECK-BUILD
     6.7  
     6.8 -function error {
     6.9 -    echo
    6.10 -    echo "  *** Check for openssl headers FAILED"
    6.11 -    exit 1
    6.12 -}
    6.13 +RC=0
    6.14  
    6.15  set -e
    6.16 -[ -e /usr/include/openssl/md5.h ] || error
    6.17 +test -r /usr/include/openssl/md5.h || RC=1 
    6.18 +
    6.19 +if test ${RC} -ne 0; then
    6.20 +	echo
    6.21 +	echo " *** Check for openssl headers FAILED"
    6.22 +fi
    6.23 +
    6.24 +exit ${RC}
     7.1 --- a/tools/check/check_python	Thu Dec 14 09:56:41 2006 -0700
     7.2 +++ b/tools/check/check_python	Thu Dec 14 18:22:58 2006 +0000
     7.3 @@ -3,7 +3,10 @@
     7.4  
     7.5  RC=0
     7.6  
     7.7 -python -V 2>&1 | cut -d ' ' -f 2 | grep -q '^2.[2345]' || RC=1
     7.8 +python -c '
     7.9 +import sys
    7.10 +sys.exit(sys.version_info[0] < 2 or sys.version_info[1] < 2)
    7.11 +' || RC=1
    7.12  
    7.13  if test ${RC} -ne 0; then
    7.14  	echo
     8.1 --- a/tools/check/check_python_devel	Thu Dec 14 09:56:41 2006 -0700
     8.2 +++ b/tools/check/check_python_devel	Thu Dec 14 18:22:58 2006 +0000
     8.3 @@ -1,4 +1,4 @@
     8.4 -#!/bin/bash
     8.5 +#!/bin/sh
     8.6  # CHECK-BUILD
     8.7  
     8.8  function error {
     8.9 @@ -7,10 +7,19 @@ function error {
    8.10      exit 1
    8.11  }
    8.12  
    8.13 +RC=0
    8.14 +
    8.15  python -c '
    8.16  import os.path, sys
    8.17  for p in sys.path:
    8.18  	if os.path.exists(p + "/config/Makefile"):
    8.19  		sys.exit(0)
    8.20  sys.exit(1)
    8.21 -' || error
    8.22 +' || RC=1 
    8.23 +
    8.24 +if test ${RC} -ne 0; then
    8.25 +	echo
    8.26 +	echo " *** Check for python development environment FAILED"
    8.27 +fi
    8.28 +
    8.29 +exit ${RC}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/check/check_python_xml	Thu Dec 14 18:22:58 2006 +0000
     9.3 @@ -0,0 +1,8 @@
     9.4 +#!/bin/sh
     9.5 +# CHECK-INSTALL
     9.6 +
     9.7 +python -c 'import xml.dom.minidom' 2>/dev/null || {
     9.8 +    echo
     9.9 +    echo "  *** Check for python-xml package FAILED"
    9.10 +    exit 1
    9.11 +}
    10.1 --- a/tools/check/check_udev	Thu Dec 14 09:56:41 2006 -0700
    10.2 +++ b/tools/check/check_udev	Thu Dec 14 18:22:58 2006 +0000
    10.3 @@ -1,16 +1,33 @@
    10.4 -#!/bin/bash
    10.5 +#!/bin/sh
    10.6  # CHECK-INSTALL
    10.7  
    10.8 -function error {
    10.9 -   echo
   10.10 -   echo '  *** Check for udev/hotplug FAILED'
   10.11 -   exit 1
   10.12 -}
   10.13 -[ -x "$(which udevinfo)" ] && \
   10.14 -  UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
   10.15 +RC=0
   10.16  
   10.17 -if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then
   10.18 -  exit 0
   10.19 +case ${OS} in
   10.20 +OpenBSD|NetBSD|FreeBSD)
   10.21 +	TOOL="vnconfig"
   10.22 +	which ${TOOL} 1>/dev/null 2>&1 || RC=1
   10.23 +	;;
   10.24 +Linux)
   10.25 +	TOOL="udevinfo"
   10.26 +	test -x "$(which ${TOOL})" && \
   10.27 +		UDEV_VERSION=$(${TOOL} -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/')
   10.28 +	if test -n "${UDEV_VERSION}" -a ${UDEV_VERSION} -ge 059; then
   10.29 +		RC=0
   10.30 +	else
   10.31 +		TOOL="hotplug"
   10.32 +		which ${TOOL} 1>/dev/null 2>&1 || RC=1
   10.33 +	fi
   10.34 +	;;
   10.35 +*)
   10.36 +	TOOL=""
   10.37 +	echo "Unknown OS" && RC=1
   10.38 +	;;
   10.39 +esac
   10.40 +
   10.41 +if test ${RC} -ne 0; then
   10.42 +	echo
   10.43 +	echo ' *** Check for ${TOOL} FAILED'
   10.44  fi
   10.45  
   10.46 -which hotplug 1>/dev/null 2>&1 || error
   10.47 +exit ${RC}
    11.1 --- a/tools/check/check_x11_devel	Thu Dec 14 09:56:41 2006 -0700
    11.2 +++ b/tools/check/check_x11_devel	Thu Dec 14 18:22:58 2006 +0000
    11.3 @@ -1,11 +1,15 @@
    11.4 -#!/bin/bash
    11.5 +#!/bin/sh
    11.6  # CHECK-BUILD
    11.7  
    11.8 -function error {
    11.9 -    echo
   11.10 -    echo "  *** Check for x11 headers FAILED"
   11.11 -    exit 1
   11.12 -}
   11.13 +RC=0
   11.14  
   11.15  set -e
   11.16 -[ -e /usr/include/X11/keysymdef.h ] || error
   11.17 +test -r /usr/include/X11/keysymdef.h || \
   11.18 +test -r /usr/X11R6/include/X11/keysymdef.h || RC=1
   11.19 +
   11.20 +if test ${RC} -ne 0; then
   11.21 +	echo
   11.22 +	echo " *** Check for x11 headers FAILED"
   11.23 +fi
   11.24 +
   11.25 +exit ${RC}
    12.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Thu Dec 14 09:56:41 2006 -0700
    12.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Thu Dec 14 18:22:58 2006 +0000
    12.3 @@ -441,7 +441,7 @@ void cpu_physical_memory_rw(target_phys_
    12.4      uint32_t val;
    12.5  
    12.6  #if defined(__i386__) || defined(__x86_64__)
    12.7 -    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    12.8 +    static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
    12.9      pthread_mutex_lock(&mutex);
   12.10  #endif
   12.11  
    13.1 --- a/tools/python/xen/xm/main.py	Thu Dec 14 09:56:41 2006 -0700
    13.2 +++ b/tools/python/xen/xm/main.py	Thu Dec 14 18:22:58 2006 +0000
    13.3 @@ -709,7 +709,7 @@ def xm_vcpu_list(args):
    13.4          dominfo = map(server.xend.domain.getVCPUInfo, doms)
    13.5  
    13.6      print '%-32s %3s %5s %5s %5s %9s %s' % \
    13.7 -          ('Name', 'ID', 'VCPUs', 'CPU', 'State', 'Time(s)', 'CPU Affinity')
    13.8 +          ('Name', 'ID', 'VCPU', 'CPU', 'State', 'Time(s)', 'CPU Affinity')
    13.9  
   13.10      format = '%(name)-32s %(domid)3d %(number)5d %(c)5s %(s)5s ' \
   13.11               ' %(cpu_time)8.1f %(cpumap)s'
    14.1 --- a/xen/arch/x86/crash.c	Thu Dec 14 09:56:41 2006 -0700
    14.2 +++ b/xen/arch/x86/crash.c	Thu Dec 14 18:22:58 2006 +0000
    14.3 @@ -28,6 +28,7 @@
    14.4  #include <asm/hvm/hvm.h>
    14.5  
    14.6  static atomic_t waiting_for_crash_ipi;
    14.7 +static unsigned int crashing_cpu;
    14.8  
    14.9  static int crash_nmi_callback(struct cpu_user_regs *regs, int cpu)
   14.10  {
   14.11 @@ -39,7 +40,7 @@ static int crash_nmi_callback(struct cpu
   14.12          return 1;
   14.13      local_irq_disable();
   14.14  
   14.15 -    machine_crash_save_cpu();
   14.16 +    kexec_crash_save_cpu();
   14.17      disable_local_APIC();
   14.18      atomic_dec(&waiting_for_crash_ipi);
   14.19      hvm_disable();
   14.20 @@ -67,6 +68,8 @@ static void nmi_shootdown_cpus(void)
   14.21  {
   14.22      unsigned long msecs;
   14.23  
   14.24 +    crashing_cpu = smp_processor_id();
   14.25 +
   14.26      atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
   14.27      /* Would it be better to replace the trap vector here? */
   14.28      set_nmi_callback(crash_nmi_callback);
   14.29 @@ -86,18 +89,10 @@ static void nmi_shootdown_cpus(void)
   14.30      disable_local_APIC();
   14.31  }
   14.32  
   14.33 -static void crash_save_xen_notes(void)
   14.34 +void machine_crash_shutdown(void)
   14.35  {
   14.36      crash_xen_info_t *info;
   14.37  
   14.38 -    info = machine_crash_save_info();
   14.39 -
   14.40 -    info->dom0_pfn_to_mfn_frame_list_list = \
   14.41 -        dom0->shared_info->arch.pfn_to_mfn_frame_list_list;
   14.42 -}
   14.43 -
   14.44 -void machine_crash_shutdown(void)
   14.45 -{
   14.46      local_irq_disable();
   14.47  
   14.48      nmi_shootdown_cpus();
   14.49 @@ -106,7 +101,9 @@ void machine_crash_shutdown(void)
   14.50  
   14.51      hvm_disable();
   14.52  
   14.53 -    crash_save_xen_notes();
   14.54 +    info = kexec_crash_save_info();
   14.55 +    info->dom0_pfn_to_mfn_frame_list_list =
   14.56 +        dom0->shared_info->arch.pfn_to_mfn_frame_list_list;
   14.57  }
   14.58  
   14.59  /*
    15.1 --- a/xen/arch/x86/domain.c	Thu Dec 14 09:56:41 2006 -0700
    15.2 +++ b/xen/arch/x86/domain.c	Thu Dec 14 18:22:58 2006 +0000
    15.3 @@ -136,6 +136,10 @@ int vcpu_initialise(struct vcpu *v)
    15.4  
    15.5      pae_l3_cache_init(&v->arch.pae_l3_cache);
    15.6  
    15.7 +    /* This should move to arch_domain_create(). */
    15.8 +    if ( !is_idle_domain(d) && (v->vcpu_id == 0) )
    15.9 +        pit_init(v, cpu_khz);
   15.10 +
   15.11      if ( is_hvm_domain(d) )
   15.12      {
   15.13          if ( (rc = hvm_vcpu_initialise(v)) != 0 )
    16.1 --- a/xen/arch/x86/hvm/hvm.c	Thu Dec 14 09:56:41 2006 -0700
    16.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Dec 14 18:22:58 2006 +0000
    16.3 @@ -222,7 +222,6 @@ int hvm_vcpu_initialise(struct vcpu *v)
    16.4  
    16.5      init_timer(&platform->pl_time.periodic_tm.timer,
    16.6                 pt_timer_fn, v, v->processor);
    16.7 -    pit_init(v, cpu_khz);
    16.8      rtc_init(v, RTC_PORT(0), RTC_IRQ);
    16.9      pmtimer_init(v, ACPI_PM_TMR_BLK_ADDRESS);
   16.10  
    17.1 --- a/xen/arch/x86/hvm/i8254.c	Thu Dec 14 09:56:41 2006 -0700
    17.2 +++ b/xen/arch/x86/hvm/i8254.c	Thu Dec 14 18:22:58 2006 +0000
    17.3 @@ -184,13 +184,19 @@ void pit_time_fired(struct vcpu *v, void
    17.4  
    17.5  static inline void pit_load_count(PITChannelState *s, int val)
    17.6  {
    17.7 -    u32   period;
    17.8 +    u32 period;
    17.9 +    PITChannelState *ch0 =
   17.10 +        &current->domain->arch.hvm_domain.pl_time.vpit.channels[0];
   17.11 +
   17.12      if (val == 0)
   17.13          val = 0x10000;
   17.14      s->count_load_time = hvm_get_clock(s->vcpu);
   17.15      s->count = val;
   17.16      period = DIV_ROUND((val * 1000000000ULL), PIT_FREQ);
   17.17  
   17.18 +    if (s != ch0)
   17.19 +        return;
   17.20 +
   17.21  #ifdef DEBUG_PIT
   17.22      printk("HVM_PIT: pit-load-counter(%p), count=0x%x, period=%uns mode=%d, load_time=%lld\n",
   17.23              s,
   17.24 @@ -419,13 +425,12 @@ static void speaker_ioport_write(void *o
   17.25  
   17.26  static uint32_t speaker_ioport_read(void *opaque, uint32_t addr)
   17.27  {
   17.28 -    int out;
   17.29      PITState *pit = opaque;
   17.30 -    out = pit_get_out(pit, 2, hvm_get_clock(pit->channels[2].vcpu));
   17.31 -    pit->dummy_refresh_clock ^= 1;
   17.32 -
   17.33 -    return (pit->speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) |
   17.34 -      (pit->dummy_refresh_clock << 4);
   17.35 +    int out = pit_get_out(pit, 2, hvm_get_clock(pit->channels[2].vcpu));
   17.36 +    /* Refresh clock toggles at about 15us. We approximate as 2^14ns. */
   17.37 +    unsigned int refresh_clock = ((unsigned int)NOW() >> 14) & 1;
   17.38 +    return ((pit->speaker_data_on << 1) | pit_get_gate(pit, 2) |
   17.39 +            (out << 5) | refresh_clock << 4);
   17.40  }
   17.41  
   17.42  static int handle_speaker_io(ioreq_t *p)
   17.43 @@ -439,7 +444,7 @@ static int handle_speaker_io(ioreq_t *p)
   17.44          printk("HVM_SPEAKER:wrong SPEAKER IO!\n");
   17.45          return 1;
   17.46      }
   17.47 -    
   17.48 +
   17.49      if (p->dir == 0) {/* write */
   17.50          speaker_ioport_write(vpit, p->addr, p->data);
   17.51      } else if (p->dir == 1) {/* read */
   17.52 @@ -448,3 +453,21 @@ static int handle_speaker_io(ioreq_t *p)
   17.53  
   17.54      return 1;
   17.55  }
   17.56 +
   17.57 +int pv_pit_handler(int port, int data, int write)
   17.58 +{
   17.59 +    ioreq_t ioreq = {
   17.60 +        .size = 1,
   17.61 +        .type = IOREQ_TYPE_PIO,
   17.62 +        .addr = port,
   17.63 +        .dir  = write ? 0 : 1,
   17.64 +        .data = write ? data : 0,
   17.65 +    };
   17.66 +
   17.67 +    if (port == 0x61)
   17.68 +        handle_speaker_io(&ioreq);
   17.69 +    else
   17.70 +        handle_pit_io(&ioreq);
   17.71 +
   17.72 +    return !write ? ioreq.data : 0;
   17.73 +}
    18.1 --- a/xen/arch/x86/traps.c	Thu Dec 14 09:56:41 2006 -0700
    18.2 +++ b/xen/arch/x86/traps.c	Thu Dec 14 18:22:58 2006 +0000
    18.3 @@ -59,6 +59,7 @@
    18.4  #include <asm/debugger.h>
    18.5  #include <asm/msr.h>
    18.6  #include <asm/x86_emulate.h>
    18.7 +#include <asm/hvm/vpt.h>
    18.8  
    18.9  /*
   18.10   * opt_nmi: one of 'ignore', 'dom0', or 'fatal'.
   18.11 @@ -1035,18 +1036,7 @@ static inline int admin_io_okay(
   18.12      return ioports_access_permitted(v->domain, port, port + bytes - 1);
   18.13  }
   18.14  
   18.15 -static inline int guest_inb_okay(
   18.16 -    unsigned int port, struct vcpu *v, struct cpu_user_regs *regs)
   18.17 -{
   18.18 -    /*
   18.19 -     * Allow read access to port 0x61. Bit 4 oscillates with period 30us, and
   18.20 -     * so it is often used for timing loops in BIOS code. This hack can go
   18.21 -     * away when we have separate read/write permission rangesets.
   18.22 -     * Note that we could emulate bit 4 instead of directly reading port 0x61,
   18.23 -     * but there's not really a good reason to do so.
   18.24 -     */
   18.25 -    return (admin_io_okay(port, 1, v, regs) || (port == 0x61));
   18.26 -}
   18.27 +#define guest_inb_okay(_p, _d, _r) admin_io_okay(_p, 1, _d, _r)
   18.28  #define guest_inw_okay(_p, _d, _r) admin_io_okay(_p, 2, _d, _r)
   18.29  #define guest_inl_okay(_p, _d, _r) admin_io_okay(_p, 4, _d, _r)
   18.30  #define guest_outb_okay(_p, _d, _r) admin_io_okay(_p, 1, _d, _r)
   18.31 @@ -1141,7 +1131,10 @@ static int emulate_privileged_op(struct 
   18.32              switch ( op_bytes )
   18.33              {
   18.34              case 1:
   18.35 -                data = (u8)(guest_inb_okay(port, v, regs) ? inb(port) : ~0);
   18.36 +                /* emulate PIT counter 2 */
   18.37 +                data = (u8)(guest_inb_okay(port, v, regs) ? inb(port) : 
   18.38 +                       ((port == 0x42 || port == 0x43 || port == 0x61) ?
   18.39 +                       pv_pit_handler(port, 0, 0) : ~0)); 
   18.40                  break;
   18.41              case 2:
   18.42                  data = (u16)(guest_inw_okay(port, v, regs) ? inw(port) : ~0);
   18.43 @@ -1176,6 +1169,8 @@ static int emulate_privileged_op(struct 
   18.44              case 1:
   18.45                  if ( guest_outb_okay(port, v, regs) )
   18.46                      outb((u8)data, port);
   18.47 +                else if ( port == 0x42 || port == 0x43 || port == 0x61 )
   18.48 +                    pv_pit_handler(port, data, 1);
   18.49                  break;
   18.50              case 2:
   18.51                  if ( guest_outw_okay(port, v, regs) )
   18.52 @@ -1240,6 +1235,11 @@ static int emulate_privileged_op(struct 
   18.53          case 1:
   18.54              if ( guest_inb_okay(port, v, regs) )
   18.55                  io_emul(regs);
   18.56 +            else if ( port == 0x42 || port == 0x43 || port == 0x61 )
   18.57 +            {
   18.58 +                regs->eax &= ~0xffUL;
   18.59 +                regs->eax |= pv_pit_handler(port, 0, 0);
   18.60 +            } 
   18.61              else
   18.62                  regs->eax |= (u8)~0;
   18.63              break;
   18.64 @@ -1277,6 +1277,8 @@ static int emulate_privileged_op(struct 
   18.65          case 1:
   18.66              if ( guest_outb_okay(port, v, regs) )
   18.67                  io_emul(regs);
   18.68 +            else if ( port == 0x42 || port == 0x43 || port == 0x61 )
   18.69 +                pv_pit_handler(port, regs->eax, 1);
   18.70              break;
   18.71          case 2:
   18.72              if ( guest_outw_okay(port, v, regs) )
   18.73 @@ -1665,7 +1667,7 @@ static void unknown_nmi_error(unsigned c
   18.74          printk("Uhhuh. NMI received for unknown reason %02x.\n", reason);
   18.75          printk("Dazed and confused, but trying to continue\n");
   18.76          printk("Do you have a strange power saving mode enabled?\n");
   18.77 -        machine_crash_kexec();
   18.78 +        kexec_crash();
   18.79      }
   18.80  }
   18.81  
    19.1 --- a/xen/common/kexec.c	Thu Dec 14 09:56:41 2006 -0700
    19.2 +++ b/xen/common/kexec.c	Thu Dec 14 18:22:58 2006 +0000
    19.3 @@ -24,7 +24,6 @@
    19.4  
    19.5  DEFINE_PER_CPU (crash_note_t, crash_notes);
    19.6  cpumask_t crash_saved_cpus;
    19.7 -int crashing_cpu;
    19.8  
    19.9  xen_kexec_image_t kexec_image[KEXEC_IMAGE_NR];
   19.10  
   19.11 @@ -58,38 +57,34 @@ custom_param("crashkernel", parse_crashk
   19.12  
   19.13  static void one_cpu_only(void)
   19.14  {
   19.15 -   /* Only allow the first cpu to continue - force other cpus to spin */
   19.16 +    /* Only allow the first cpu to continue - force other cpus to spin */
   19.17      if ( test_and_set_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags) )
   19.18 -    {
   19.19 -        while (1);
   19.20 -    }
   19.21 +        for ( ; ; ) ;
   19.22  }
   19.23  
   19.24 -/* Save the registers in the per-cpu crash note buffer */
   19.25 -
   19.26 -void machine_crash_save_cpu(void)
   19.27 +/* Save the registers in the per-cpu crash note buffer. */
   19.28 +void kexec_crash_save_cpu(void)
   19.29  {
   19.30      int cpu = smp_processor_id();
   19.31      crash_note_t *cntp;
   19.32  
   19.33 -    if ( !cpu_test_and_set(cpu, crash_saved_cpus) )
   19.34 -    {
   19.35 -        cntp = &per_cpu(crash_notes, cpu);
   19.36 -        elf_core_save_regs(&cntp->core.desc.desc.pr_reg,
   19.37 -                           &cntp->xen_regs.desc.desc);
   19.38 +    if ( cpu_test_and_set(cpu, crash_saved_cpus) )
   19.39 +        return;
   19.40 +
   19.41 +    cntp = &per_cpu(crash_notes, cpu);
   19.42 +    elf_core_save_regs(&cntp->core.desc.desc.pr_reg,
   19.43 +                       &cntp->xen_regs.desc.desc);
   19.44  
   19.45 -        /* setup crash "CORE" note */
   19.46 -        setup_crash_note(cntp, core, CORE_STR, CORE_STR_LEN, NT_PRSTATUS);
   19.47 +    /* Set up crash "CORE" note. */
   19.48 +    setup_crash_note(cntp, core, CORE_STR, CORE_STR_LEN, NT_PRSTATUS);
   19.49  
   19.50 -        /* setup crash note "Xen", XEN_ELFNOTE_CRASH_REGS */
   19.51 -        setup_crash_note(cntp, xen_regs, XEN_STR, XEN_STR_LEN,
   19.52 -                         XEN_ELFNOTE_CRASH_REGS);
   19.53 -    }
   19.54 +    /* Set up crash note "Xen", XEN_ELFNOTE_CRASH_REGS. */
   19.55 +    setup_crash_note(cntp, xen_regs, XEN_STR, XEN_STR_LEN,
   19.56 +                     XEN_ELFNOTE_CRASH_REGS);
   19.57  }
   19.58  
   19.59 -/* Setup the single Xen specific info crash note */
   19.60 -
   19.61 -crash_xen_info_t *machine_crash_save_info(void)
   19.62 +/* Set up the single Xen-specific-info crash note. */
   19.63 +crash_xen_info_t *kexec_crash_save_info(void)
   19.64  {
   19.65      int cpu = smp_processor_id();
   19.66      crash_note_t *cntp;
   19.67 @@ -99,7 +94,7 @@ crash_xen_info_t *machine_crash_save_inf
   19.68  
   19.69      cntp = &per_cpu(crash_notes, cpu);
   19.70  
   19.71 -    /* setup crash note "Xen", XEN_ELFNOTE_CRASH_INFO */
   19.72 +    /* Set up crash note "Xen", XEN_ELFNOTE_CRASH_INFO. */
   19.73      setup_crash_note(cntp, xen_info, XEN_STR, XEN_STR_LEN,
   19.74                       XEN_ELFNOTE_CRASH_INFO);
   19.75  
   19.76 @@ -117,45 +112,34 @@ crash_xen_info_t *machine_crash_save_inf
   19.77      return info;
   19.78  }
   19.79  
   19.80 -void machine_crash_kexec(void)
   19.81 +void kexec_crash(void)
   19.82  {
   19.83      int pos;
   19.84 -    xen_kexec_image_t *image;
   19.85 +
   19.86 +    pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
   19.87 +    if ( !test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
   19.88 +        return;
   19.89  
   19.90      one_cpu_only();
   19.91 -
   19.92 -    machine_crash_save_cpu();
   19.93 -    crashing_cpu = smp_processor_id();
   19.94 -
   19.95 +    kexec_crash_save_cpu();
   19.96      machine_crash_shutdown();
   19.97  
   19.98 -    pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
   19.99 +    machine_kexec(&kexec_image[KEXEC_IMAGE_CRASH_BASE + pos]);
  19.100  
  19.101 -    if ( test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
  19.102 -    {
  19.103 -        image = &kexec_image[KEXEC_IMAGE_CRASH_BASE + pos];
  19.104 -        machine_kexec(image); /* Does not return */
  19.105 -    }
  19.106 +    BUG();
  19.107  }
  19.108  
  19.109  static void do_crashdump_trigger(unsigned char key)
  19.110  {
  19.111 -    int pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
  19.112 -    if ( test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
  19.113 -    {
  19.114 -        printk("'%c' pressed -> triggering crashdump\n", key);
  19.115 -        machine_crash_kexec();
  19.116 -    }
  19.117 -    else
  19.118 -    {
  19.119 -        printk("'%c' pressed -> no crash kernel loaded -- not triggering crashdump\n", key);
  19.120 -    }
  19.121 +    printk("'%c' pressed -> triggering crashdump\n", key);
  19.122 +    kexec_crash();
  19.123 +    printk(" * no crash kernel loaded!\n");
  19.124  }
  19.125  
  19.126  static __init int register_crashdump_trigger(void)
  19.127  {
  19.128 -	register_keyhandler('C', do_crashdump_trigger, "trigger a crashdump");
  19.129 -	return 0;
  19.130 +    register_keyhandler('C', do_crashdump_trigger, "trigger a crashdump");
  19.131 +    return 0;
  19.132  }
  19.133  __initcall(register_crashdump_trigger);
  19.134  
  19.135 @@ -303,7 +287,7 @@ static int kexec_exec(XEN_GUEST_HANDLE(v
  19.136          machine_reboot_kexec(image); /* Does not return */
  19.137          break;
  19.138      case KEXEC_TYPE_CRASH:
  19.139 -        machine_crash_kexec(); /* Does not return */
  19.140 +        kexec_crash(); /* Does not return */
  19.141          break;
  19.142      }
  19.143  
    20.1 --- a/xen/common/page_alloc.c	Thu Dec 14 09:56:41 2006 -0700
    20.2 +++ b/xen/common/page_alloc.c	Thu Dec 14 18:22:58 2006 +0000
    20.3 @@ -136,7 +136,6 @@ static void map_alloc(unsigned long firs
    20.4      }
    20.5  }
    20.6  
    20.7 -
    20.8  static void map_free(unsigned long first_page, unsigned long nr_pages)
    20.9  {
   20.10      unsigned long start_off, end_off, curr_idx, end_idx;
   20.11 @@ -171,6 +170,8 @@ static void map_free(unsigned long first
   20.12   * BOOT-TIME ALLOCATOR
   20.13   */
   20.14  
   20.15 +static unsigned long first_valid_mfn = ~0UL;
   20.16 +
   20.17  /* Initialise allocator to handle up to @max_page pages. */
   20.18  paddr_t init_boot_allocator(paddr_t bitmap_start)
   20.19  {
   20.20 @@ -203,6 +204,8 @@ void init_boot_pages(paddr_t ps, paddr_t
   20.21      if ( pe <= ps )
   20.22          return;
   20.23  
   20.24 +    first_valid_mfn = min_t(unsigned long, ps >> PAGE_SHIFT, first_valid_mfn);
   20.25 +
   20.26      map_free(ps >> PAGE_SHIFT, (pe - ps) >> PAGE_SHIFT);
   20.27  
   20.28      /* Check new pages against the bad-page list. */
   20.29 @@ -256,16 +259,17 @@ unsigned long alloc_boot_pages_at(unsign
   20.30  
   20.31  unsigned long alloc_boot_pages(unsigned long nr_pfns, unsigned long pfn_align)
   20.32  {
   20.33 -    unsigned long pg, i = 0;
   20.34 +    unsigned long pg;
   20.35  
   20.36 -    for ( pg = 0; (pg + nr_pfns) < max_page; pg += pfn_align )
   20.37 +    pg = first_valid_mfn & ~(pfn_align-1);
   20.38 +    while ( (pg + nr_pfns) < max_page )
   20.39      {
   20.40 -        i = alloc_boot_pages_at(nr_pfns, pg);
   20.41 -        if (i != 0)
   20.42 +        if ( alloc_boot_pages_at(nr_pfns, pg) != 0 )
   20.43              break;
   20.44 +        pg += pfn_align;
   20.45      }
   20.46  
   20.47 -    return i;
   20.48 +    return pg;
   20.49  }
   20.50  
   20.51  
   20.52 @@ -291,7 +295,7 @@ static DEFINE_SPINLOCK(heap_lock);
   20.53  void end_boot_allocator(void)
   20.54  {
   20.55      unsigned long i, j, k;
   20.56 -    int curr_free = 0, next_free = 0;
   20.57 +    int curr_free, next_free;
   20.58  
   20.59      memset(avail, 0, sizeof(avail));
   20.60  
   20.61 @@ -301,7 +305,9 @@ void end_boot_allocator(void)
   20.62                  INIT_LIST_HEAD(&heap[i][j][k]);
   20.63  
   20.64      /* Pages that are free now go to the domain sub-allocator. */
   20.65 -    for ( i = 0; i < max_page; i++ )
   20.66 +    if ( (curr_free = next_free = !allocated_in_map(first_valid_mfn)) )
   20.67 +        map_alloc(first_valid_mfn, 1);
   20.68 +    for ( i = first_valid_mfn; i < max_page; i++ )
   20.69      {
   20.70          curr_free = next_free;
   20.71          next_free = !allocated_in_map(i+1);
   20.72 @@ -324,7 +330,7 @@ void end_boot_allocator(void)
   20.73  void init_heap_pages(
   20.74      unsigned int zone, struct page_info *pg, unsigned long nr_pages)
   20.75  {
   20.76 -    unsigned int nid_curr,nid_prev;
   20.77 +    unsigned int nid_curr, nid_prev;
   20.78      unsigned long i;
   20.79  
   20.80      ASSERT(zone < NR_ZONES);
   20.81 @@ -478,37 +484,37 @@ void free_heap_pages(
   20.82  void scrub_heap_pages(void)
   20.83  {
   20.84      void *p;
   20.85 -    unsigned long pfn;
   20.86 +    unsigned long mfn;
   20.87  
   20.88      printk("Scrubbing Free RAM: ");
   20.89  
   20.90 -    for ( pfn = 0; pfn < max_page; pfn++ )
   20.91 +    for ( mfn = first_valid_mfn; mfn < max_page; mfn++ )
   20.92      {
   20.93          /* Every 100MB, print a progress dot. */
   20.94 -        if ( (pfn % ((100*1024*1024)/PAGE_SIZE)) == 0 )
   20.95 +        if ( (mfn % ((100*1024*1024)/PAGE_SIZE)) == 0 )
   20.96              printk(".");
   20.97  
   20.98          process_pending_timers();
   20.99  
  20.100          /* Quick lock-free check. */
  20.101 -        if ( allocated_in_map(pfn) )
  20.102 +        if ( allocated_in_map(mfn) )
  20.103              continue;
  20.104  
  20.105          spin_lock_irq(&heap_lock);
  20.106  
  20.107          /* Re-check page status with lock held. */
  20.108 -        if ( !allocated_in_map(pfn) )
  20.109 +        if ( !allocated_in_map(mfn) )
  20.110          {
  20.111 -            if ( IS_XEN_HEAP_FRAME(mfn_to_page(pfn)) )
  20.112 +            if ( IS_XEN_HEAP_FRAME(mfn_to_page(mfn)) )
  20.113              {
  20.114 -                p = page_to_virt(mfn_to_page(pfn));
  20.115 +                p = page_to_virt(mfn_to_page(mfn));
  20.116                  memguard_unguard_range(p, PAGE_SIZE);
  20.117                  clear_page(p);
  20.118                  memguard_guard_range(p, PAGE_SIZE);
  20.119              }
  20.120              else
  20.121              {
  20.122 -                p = map_domain_page(pfn);
  20.123 +                p = map_domain_page(mfn);
  20.124                  clear_page(p);
  20.125                  unmap_domain_page(p);
  20.126              }
    21.1 --- a/xen/drivers/char/console.c	Thu Dec 14 09:56:41 2006 -0700
    21.2 +++ b/xen/drivers/char/console.c	Thu Dec 14 18:22:58 2006 +0000
    21.3 @@ -866,7 +866,7 @@ void panic(const char *fmt, ...)
    21.4  
    21.5      debugger_trap_immediate();
    21.6  
    21.7 -    machine_crash_kexec();
    21.8 +    kexec_crash();
    21.9  
   21.10      if ( opt_noreboot )
   21.11      {
    22.1 --- a/xen/include/asm-x86/hvm/vpt.h	Thu Dec 14 09:56:41 2006 -0700
    22.2 +++ b/xen/include/asm-x86/hvm/vpt.h	Thu Dec 14 18:22:58 2006 +0000
    22.3 @@ -54,7 +54,6 @@ typedef struct PITChannelState {
    22.4  typedef struct PITState {
    22.5      PITChannelState channels[3];
    22.6      int speaker_data_on;
    22.7 -    int dummy_refresh_clock;
    22.8  } PITState;
    22.9  
   22.10  #define RTC_SIZE 14
   22.11 @@ -125,6 +124,7 @@ extern void pickup_deactive_ticks(struct
   22.12  extern struct periodic_time *create_periodic_time(
   22.13      u32 period, char irq, char one_shot, time_cb *cb, void *data);
   22.14  extern void destroy_periodic_time(struct periodic_time *pt);
   22.15 +int pv_pit_handler(int port, int data, int write);
   22.16  void pit_init(struct vcpu *v, unsigned long cpu_khz);
   22.17  void rtc_init(struct vcpu *v, int base, int irq);
   22.18  void rtc_deinit(struct domain *d);
    23.1 --- a/xen/include/xen/kexec.h	Thu Dec 14 09:56:41 2006 -0700
    23.2 +++ b/xen/include/xen/kexec.h	Thu Dec 14 18:22:58 2006 +0000
    23.3 @@ -5,8 +5,6 @@
    23.4  #include <asm/percpu.h>
    23.5  #include <xen/elfcore.h>
    23.6  
    23.7 -extern int crashing_cpu;
    23.8 -
    23.9  typedef struct xen_kexec_reserve {
   23.10      unsigned long size;
   23.11      unsigned long start;
   23.12 @@ -27,9 +25,9 @@ int machine_kexec_load(int type, int slo
   23.13  void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image);
   23.14  void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
   23.15  void machine_reboot_kexec(xen_kexec_image_t *image);
   23.16 -void machine_crash_kexec(void);
   23.17 -void machine_crash_save_cpu(void);
   23.18 -crash_xen_info_t *machine_crash_save_info(void);
   23.19 +void kexec_crash(void);
   23.20 +void kexec_crash_save_cpu(void);
   23.21 +crash_xen_info_t *kexec_crash_save_info(void);
   23.22  void machine_crash_shutdown(void);
   23.23  
   23.24  #endif /* __XEN_KEXEC_H__ */