ia64/xen-unstable

changeset 7120:c7f58e86446f

Reindent grant-table kernel code and reserve first few
entries for tools use.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Sep 28 18:01:40 2005 +0100 (2005-09-28)
parents 1a82995a017c
children f9a806ba838a
files linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Wed Sep 28 17:51:24 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Wed Sep 28 18:01:40 2005 +0100
     1.3 @@ -1,13 +1,10 @@
     1.4  /******************************************************************************
     1.5   * gnttab.c
     1.6   * 
     1.7 - * Two sets of functionality:
     1.8 - * 1. Granting foreign access to our memory reservation.
     1.9 - * 2. Accessing others' memory reservations via grant references.
    1.10 - * (i.e., mechanisms for both sender and recipient of grant references)
    1.11 + * Granting foreign access to our memory reservation.
    1.12   * 
    1.13   * Copyright (c) 2005, Christopher Clark
    1.14 - * Copyright (c) 2004, K A Fraser
    1.15 + * Copyright (c) 2004-2005, K A Fraser
    1.16   */
    1.17  
    1.18  #include <linux/config.h>
    1.19 @@ -23,15 +20,15 @@
    1.20  #include <asm/synch_bitops.h>
    1.21  
    1.22  #if 1
    1.23 -#define ASSERT(_p) \
    1.24 -    if ( !(_p) ) { printk(KERN_ALERT"Assertion '%s': line %d, file %s\n", \
    1.25 -    #_p , __LINE__, __FILE__); *(int*)0=0; }
    1.26 +#define ASSERT(_p)							      \
    1.27 +	if ( !(_p) ) { printk(KERN_ALERT"Assertion '%s': line %d, file %s\n", \
    1.28 +	#_p , __LINE__, __FILE__); *(int*)0=0; }
    1.29  #else
    1.30  #define ASSERT(_p) ((void)0)
    1.31  #endif
    1.32  
    1.33 -#define WPRINTK(fmt, args...) \
    1.34 -    printk(KERN_WARNING "xen_grant: " fmt, ##args)
    1.35 +#define WPRINTK(fmt, args...)				\
    1.36 +	printk(KERN_WARNING "xen_grant: " fmt, ##args)
    1.37  
    1.38  
    1.39  EXPORT_SYMBOL(gnttab_grant_foreign_access);
    1.40 @@ -49,11 +46,14 @@ EXPORT_SYMBOL(gnttab_release_grant_refer
    1.41  EXPORT_SYMBOL(gnttab_grant_foreign_access_ref);
    1.42  EXPORT_SYMBOL(gnttab_grant_foreign_transfer_ref);
    1.43  
    1.44 +/* External tools reserve first few grant table entries. */
    1.45 +#define NR_RESERVED_ENTRIES 8
    1.46 +
    1.47  #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    1.48  #define GNTTAB_LIST_END (NR_GRANT_ENTRIES + 1)
    1.49  
    1.50  static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
    1.51 -static int gnttab_free_count = NR_GRANT_ENTRIES;
    1.52 +static int gnttab_free_count;
    1.53  static grant_ref_t gnttab_free_head;
    1.54  static spinlock_t gnttab_list_lock = SPIN_LOCK_UNLOCKED;
    1.55  
    1.56 @@ -64,22 +64,22 @@ static struct gnttab_free_callback *gntt
    1.57  static int
    1.58  get_free_entries(int count)
    1.59  {
    1.60 -    unsigned long flags;
    1.61 -    int ref;
    1.62 -    grant_ref_t head;
    1.63 -    spin_lock_irqsave(&gnttab_list_lock, flags);
    1.64 -    if (gnttab_free_count < count) {
    1.65 +	unsigned long flags;
    1.66 +	int ref;
    1.67 +	grant_ref_t head;
    1.68 +	spin_lock_irqsave(&gnttab_list_lock, flags);
    1.69 +	if (gnttab_free_count < count) {
    1.70 +		spin_unlock_irqrestore(&gnttab_list_lock, flags);
    1.71 +		return -1;
    1.72 +	}
    1.73 +	ref = head = gnttab_free_head;
    1.74 +	gnttab_free_count -= count;
    1.75 +	while (count-- > 1)
    1.76 +		head = gnttab_list[head];
    1.77 +	gnttab_free_head = gnttab_list[head];
    1.78 +	gnttab_list[head] = GNTTAB_LIST_END;
    1.79  	spin_unlock_irqrestore(&gnttab_list_lock, flags);
    1.80 -	return -1;
    1.81 -    }
    1.82 -    ref = head = gnttab_free_head;
    1.83 -    gnttab_free_count -= count;
    1.84 -    while (count-- > 1)
    1.85 -	head = gnttab_list[head];
    1.86 -    gnttab_free_head = gnttab_list[head];
    1.87 -    gnttab_list[head] = GNTTAB_LIST_END;
    1.88 -    spin_unlock_irqrestore(&gnttab_list_lock, flags);
    1.89 -    return ref;
    1.90 +	return ref;
    1.91  }
    1.92  
    1.93  #define get_free_entry() get_free_entries(1)
    1.94 @@ -87,38 +87,41 @@ get_free_entries(int count)
    1.95  static void
    1.96  do_free_callbacks(void)
    1.97  {
    1.98 -    struct gnttab_free_callback *callback = gnttab_free_callback_list, *next;
    1.99 -    gnttab_free_callback_list = NULL;
   1.100 -    while (callback) {
   1.101 -	next = callback->next;
   1.102 -	if (gnttab_free_count >= callback->count) {
   1.103 -	    callback->next = NULL;
   1.104 -	    callback->fn(callback->arg);
   1.105 -	} else {
   1.106 -	    callback->next = gnttab_free_callback_list;
   1.107 -	    gnttab_free_callback_list = callback;
   1.108 +	struct gnttab_free_callback *callback, *next;
   1.109 +
   1.110 +	callback = gnttab_free_callback_list;
   1.111 +	gnttab_free_callback_list = NULL;
   1.112 +
   1.113 +	while (callback != NULL) {
   1.114 +		next = callback->next;
   1.115 +		if (gnttab_free_count >= callback->count) {
   1.116 +			callback->next = NULL;
   1.117 +			callback->fn(callback->arg);
   1.118 +		} else {
   1.119 +			callback->next = gnttab_free_callback_list;
   1.120 +			gnttab_free_callback_list = callback;
   1.121 +		}
   1.122 +		callback = next;
   1.123  	}
   1.124 -	callback = next;
   1.125 -    }
   1.126  }
   1.127  
   1.128  static inline void
   1.129  check_free_callbacks(void)
   1.130  {
   1.131 -    if (unlikely(gnttab_free_callback_list))
   1.132 -	do_free_callbacks();
   1.133 +	if (unlikely(gnttab_free_callback_list))
   1.134 +		do_free_callbacks();
   1.135  }
   1.136  
   1.137  static void
   1.138  put_free_entry(grant_ref_t ref)
   1.139  {
   1.140 -    unsigned long flags;
   1.141 -    spin_lock_irqsave(&gnttab_list_lock, flags);
   1.142 -    gnttab_list[ref] = gnttab_free_head;
   1.143 -    gnttab_free_head = ref;
   1.144 -    gnttab_free_count++;
   1.145 -    check_free_callbacks();
   1.146 -    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.147 +	unsigned long flags;
   1.148 +	spin_lock_irqsave(&gnttab_list_lock, flags);
   1.149 +	gnttab_list[ref] = gnttab_free_head;
   1.150 +	gnttab_free_head = ref;
   1.151 +	gnttab_free_count++;
   1.152 +	check_free_callbacks();
   1.153 +	spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.154  }
   1.155  
   1.156  /*
   1.157 @@ -128,187 +131,189 @@ put_free_entry(grant_ref_t ref)
   1.158  int
   1.159  gnttab_grant_foreign_access(domid_t domid, unsigned long frame, int readonly)
   1.160  {
   1.161 -    int ref;
   1.162 +	int ref;
   1.163      
   1.164 -    if ( unlikely((ref = get_free_entry()) == -1) )
   1.165 -        return -ENOSPC;
   1.166 +	if (unlikely((ref = get_free_entry()) == -1))
   1.167 +		return -ENOSPC;
   1.168  
   1.169 -    shared[ref].frame = frame;
   1.170 -    shared[ref].domid = domid;
   1.171 -    wmb();
   1.172 -    shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly : 0);
   1.173 +	shared[ref].frame = frame;
   1.174 +	shared[ref].domid = domid;
   1.175 +	wmb();
   1.176 +	shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly : 0);
   1.177  
   1.178 -    return ref;
   1.179 +	return ref;
   1.180  }
   1.181  
   1.182  void
   1.183  gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
   1.184  				unsigned long frame, int readonly)
   1.185  {
   1.186 -    shared[ref].frame = frame;
   1.187 -    shared[ref].domid = domid;
   1.188 -    wmb();
   1.189 -    shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly : 0);
   1.190 +	shared[ref].frame = frame;
   1.191 +	shared[ref].domid = domid;
   1.192 +	wmb();
   1.193 +	shared[ref].flags = GTF_permit_access | (readonly ? GTF_readonly : 0);
   1.194  }
   1.195  
   1.196  
   1.197  int
   1.198  gnttab_query_foreign_access(grant_ref_t ref)
   1.199  {
   1.200 -    u16 nflags;
   1.201 +	u16 nflags;
   1.202  
   1.203 -    nflags = shared[ref].flags;
   1.204 +	nflags = shared[ref].flags;
   1.205  
   1.206 -    return ( nflags & (GTF_reading|GTF_writing) );
   1.207 +	return (nflags & (GTF_reading|GTF_writing));
   1.208  }
   1.209  
   1.210  void
   1.211  gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly)
   1.212  {
   1.213 -    u16 flags, nflags;
   1.214 +	u16 flags, nflags;
   1.215  
   1.216 -    nflags = shared[ref].flags;
   1.217 -    do {
   1.218 -        if ( (flags = nflags) & (GTF_reading|GTF_writing) )
   1.219 -            printk(KERN_ALERT "WARNING: g.e. still in use!\n");
   1.220 -    }
   1.221 -    while ( (nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) != flags );
   1.222 +	nflags = shared[ref].flags;
   1.223 +	do {
   1.224 +		if ( (flags = nflags) & (GTF_reading|GTF_writing) )
   1.225 +			printk(KERN_ALERT "WARNING: g.e. still in use!\n");
   1.226 +	}
   1.227 +	while ((nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) !=
   1.228 +	       flags);
   1.229  }
   1.230  
   1.231  void
   1.232  gnttab_end_foreign_access(grant_ref_t ref, int readonly)
   1.233  {
   1.234 -    gnttab_end_foreign_access_ref(ref, readonly);
   1.235 -    put_free_entry(ref);
   1.236 +	gnttab_end_foreign_access_ref(ref, readonly);
   1.237 +	put_free_entry(ref);
   1.238  }
   1.239  
   1.240  int
   1.241  gnttab_grant_foreign_transfer(domid_t domid)
   1.242  {
   1.243 -    int ref;
   1.244 +	int ref;
   1.245  
   1.246 -    if ( unlikely((ref = get_free_entry()) == -1) )
   1.247 -        return -ENOSPC;
   1.248 +	if (unlikely((ref = get_free_entry()) == -1))
   1.249 +		return -ENOSPC;
   1.250  
   1.251 -    shared[ref].frame = 0;
   1.252 -    shared[ref].domid = domid;
   1.253 -    wmb();
   1.254 -    shared[ref].flags = GTF_accept_transfer;
   1.255 +	shared[ref].frame = 0;
   1.256 +	shared[ref].domid = domid;
   1.257 +	wmb();
   1.258 +	shared[ref].flags = GTF_accept_transfer;
   1.259  
   1.260 -    return ref;
   1.261 +	return ref;
   1.262  }
   1.263  
   1.264  void
   1.265  gnttab_grant_foreign_transfer_ref(grant_ref_t ref, domid_t domid)
   1.266  {
   1.267 -    shared[ref].frame = 0;
   1.268 -    shared[ref].domid = domid;
   1.269 -    wmb();
   1.270 -    shared[ref].flags = GTF_accept_transfer;
   1.271 +	shared[ref].frame = 0;
   1.272 +	shared[ref].domid = domid;
   1.273 +	wmb();
   1.274 +	shared[ref].flags = GTF_accept_transfer;
   1.275  }
   1.276  
   1.277  unsigned long
   1.278  gnttab_end_foreign_transfer_ref(grant_ref_t ref)
   1.279  {
   1.280 -    unsigned long frame = 0;
   1.281 -    u16           flags;
   1.282 +	unsigned long frame = 0;
   1.283 +	u16           flags;
   1.284  
   1.285 -    flags = shared[ref].flags;
   1.286 +	flags = shared[ref].flags;
   1.287  
   1.288 -    /*
   1.289 -     * If a transfer is committed then wait for the frame address to appear.
   1.290 -     * Otherwise invalidate the grant entry against future use.
   1.291 -     */
   1.292 -    if ( likely(flags != GTF_accept_transfer) ||
   1.293 -         (synch_cmpxchg(&shared[ref].flags, flags, 0) != GTF_accept_transfer) )
   1.294 -        while ( unlikely((frame = shared[ref].frame) == 0) )
   1.295 -            cpu_relax();
   1.296 +	/*
   1.297 +	 * If a transfer is committed then wait for the frame address to
   1.298 +	 * appear. Otherwise invalidate the grant entry against future use.
   1.299 +	 */
   1.300 +	if (likely(flags != GTF_accept_transfer) ||
   1.301 +	    (synch_cmpxchg(&shared[ref].flags, flags, 0) !=
   1.302 +	     GTF_accept_transfer))
   1.303 +		while (unlikely((frame = shared[ref].frame) == 0))
   1.304 +			cpu_relax();
   1.305  
   1.306 -    return frame;
   1.307 +	return frame;
   1.308  }
   1.309  
   1.310  unsigned long
   1.311  gnttab_end_foreign_transfer(grant_ref_t ref)
   1.312  {
   1.313 -    unsigned long frame = gnttab_end_foreign_transfer_ref(ref);
   1.314 -    put_free_entry(ref);
   1.315 -    return frame;
   1.316 +	unsigned long frame = gnttab_end_foreign_transfer_ref(ref);
   1.317 +	put_free_entry(ref);
   1.318 +	return frame;
   1.319  }
   1.320  
   1.321  void
   1.322  gnttab_free_grant_reference(grant_ref_t ref)
   1.323  {
   1.324  
   1.325 -    put_free_entry(ref);
   1.326 +	put_free_entry(ref);
   1.327  }
   1.328  
   1.329  void
   1.330  gnttab_free_grant_references(grant_ref_t head)
   1.331  {
   1.332 -    grant_ref_t ref;
   1.333 -    unsigned long flags;
   1.334 -    int count = 1;
   1.335 -    if (head == GNTTAB_LIST_END)
   1.336 -	return;
   1.337 -    spin_lock_irqsave(&gnttab_list_lock, flags);
   1.338 -    ref = head;
   1.339 -    while (gnttab_list[ref] != GNTTAB_LIST_END) {
   1.340 -	ref = gnttab_list[ref];
   1.341 -	count++;
   1.342 -    }
   1.343 -    gnttab_list[ref] = gnttab_free_head;
   1.344 -    gnttab_free_head = head;
   1.345 -    gnttab_free_count += count;
   1.346 -    check_free_callbacks();
   1.347 -    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.348 +	grant_ref_t ref;
   1.349 +	unsigned long flags;
   1.350 +	int count = 1;
   1.351 +	if (head == GNTTAB_LIST_END)
   1.352 +		return;
   1.353 +	spin_lock_irqsave(&gnttab_list_lock, flags);
   1.354 +	ref = head;
   1.355 +	while (gnttab_list[ref] != GNTTAB_LIST_END) {
   1.356 +		ref = gnttab_list[ref];
   1.357 +		count++;
   1.358 +	}
   1.359 +	gnttab_list[ref] = gnttab_free_head;
   1.360 +	gnttab_free_head = head;
   1.361 +	gnttab_free_count += count;
   1.362 +	check_free_callbacks();
   1.363 +	spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.364  }
   1.365  
   1.366  int
   1.367  gnttab_alloc_grant_references(u16 count, grant_ref_t *head)
   1.368  {
   1.369 -    int h = get_free_entries(count);
   1.370 +	int h = get_free_entries(count);
   1.371  
   1.372 -    if (h == -1)
   1.373 -	return -ENOSPC;
   1.374 +	if (h == -1)
   1.375 +		return -ENOSPC;
   1.376  
   1.377 -    *head = h;
   1.378 +	*head = h;
   1.379  
   1.380 -    return 0;
   1.381 +	return 0;
   1.382  }
   1.383  
   1.384  int
   1.385  gnttab_claim_grant_reference(grant_ref_t *private_head)
   1.386  {
   1.387 -    grant_ref_t g = *private_head;
   1.388 -    if (unlikely(g == GNTTAB_LIST_END))
   1.389 -        return -ENOSPC;
   1.390 -    *private_head = gnttab_list[g];
   1.391 -    return g;
   1.392 +	grant_ref_t g = *private_head;
   1.393 +	if (unlikely(g == GNTTAB_LIST_END))
   1.394 +		return -ENOSPC;
   1.395 +	*private_head = gnttab_list[g];
   1.396 +	return g;
   1.397  }
   1.398  
   1.399  void
   1.400  gnttab_release_grant_reference(grant_ref_t *private_head, grant_ref_t  release)
   1.401  {
   1.402 -    gnttab_list[release] = *private_head;
   1.403 -    *private_head = release;
   1.404 +	gnttab_list[release] = *private_head;
   1.405 +	*private_head = release;
   1.406  }
   1.407  
   1.408  void
   1.409  gnttab_request_free_callback(struct gnttab_free_callback *callback,
   1.410  			     void (*fn)(void *), void *arg, u16 count)
   1.411  {
   1.412 -    unsigned long flags;
   1.413 -    spin_lock_irqsave(&gnttab_list_lock, flags);
   1.414 -    if (callback->next)
   1.415 -	goto out;
   1.416 -    callback->fn = fn;
   1.417 -    callback->arg = arg;
   1.418 -    callback->count = count;
   1.419 -    callback->next = gnttab_free_callback_list;
   1.420 -    gnttab_free_callback_list = callback;
   1.421 -    check_free_callbacks();
   1.422 +	unsigned long flags;
   1.423 +	spin_lock_irqsave(&gnttab_list_lock, flags);
   1.424 +	if (callback->next)
   1.425 +		goto out;
   1.426 +	callback->fn = fn;
   1.427 +	callback->arg = arg;
   1.428 +	callback->count = count;
   1.429 +	callback->next = gnttab_free_callback_list;
   1.430 +	gnttab_free_callback_list = callback;
   1.431 +	check_free_callbacks();
   1.432   out:
   1.433 -    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.434 +	spin_unlock_irqrestore(&gnttab_list_lock, flags);
   1.435  }
   1.436  
   1.437  /*
   1.438 @@ -323,79 +328,83 @@ static int
   1.439  grant_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
   1.440  	    unsigned long data)
   1.441  {
   1.442 -    int                     ret;
   1.443 -    privcmd_hypercall_t     hypercall;
   1.444 +	int                     ret;
   1.445 +	privcmd_hypercall_t     hypercall;
   1.446  
   1.447 -    /* XXX Need safety checks here if using for anything other
   1.448 -     *     than debugging */
   1.449 -    return -ENOSYS;
   1.450 +	/*
   1.451 +	 * XXX Need safety checks here if using for anything other
   1.452 +	 *     than debugging.
   1.453 +	 */
   1.454 +	return -ENOSYS;
   1.455  
   1.456 -    if ( cmd != IOCTL_PRIVCMD_HYPERCALL )
   1.457 -        return -ENOSYS;
   1.458 +	if ( cmd != IOCTL_PRIVCMD_HYPERCALL )
   1.459 +		return -ENOSYS;
   1.460  
   1.461 -    if ( copy_from_user(&hypercall, (void *)data, sizeof(hypercall)) )
   1.462 -        return -EFAULT;
   1.463 +	if ( copy_from_user(&hypercall, (void *)data, sizeof(hypercall)) )
   1.464 +		return -EFAULT;
   1.465  
   1.466 -    if ( hypercall.op != __HYPERVISOR_grant_table_op )
   1.467 -        return -ENOSYS;
   1.468 +	if ( hypercall.op != __HYPERVISOR_grant_table_op )
   1.469 +		return -ENOSYS;
   1.470  
   1.471 -    /* hypercall-invoking asm taken from privcmd.c */
   1.472 -    __asm__ __volatile__ (
   1.473 -        "pushl %%ebx; pushl %%ecx; pushl %%edx; pushl %%esi; pushl %%edi; "
   1.474 -        "movl  4(%%eax),%%ebx ;"
   1.475 -        "movl  8(%%eax),%%ecx ;"
   1.476 -        "movl 12(%%eax),%%edx ;"
   1.477 -        "movl 16(%%eax),%%esi ;"
   1.478 -        "movl 20(%%eax),%%edi ;"
   1.479 -        "movl   (%%eax),%%eax ;"
   1.480 -        TRAP_INSTR "; "
   1.481 -        "popl %%edi; popl %%esi; popl %%edx; popl %%ecx; popl %%ebx"
   1.482 -        : "=a" (ret) : "0" (&hypercall) : "memory" );
   1.483 +	/* hypercall-invoking asm taken from privcmd.c */
   1.484 +	__asm__ __volatile__ (
   1.485 +		"pushl %%ebx; pushl %%ecx; pushl %%edx; "
   1.486 +		"pushl %%esi; pushl %%edi; "
   1.487 +		"movl  4(%%eax),%%ebx ;"
   1.488 +		"movl  8(%%eax),%%ecx ;"
   1.489 +		"movl 12(%%eax),%%edx ;"
   1.490 +		"movl 16(%%eax),%%esi ;"
   1.491 +		"movl 20(%%eax),%%edi ;"
   1.492 +		"movl   (%%eax),%%eax ;"
   1.493 +		TRAP_INSTR "; "
   1.494 +		"popl %%edi; popl %%esi; popl %%edx; popl %%ecx; popl %%ebx"
   1.495 +		: "=a" (ret) : "0" (&hypercall) : "memory" );
   1.496  
   1.497 -    return ret;
   1.498 +	return ret;
   1.499  }
   1.500  
   1.501  static struct file_operations grant_file_ops = {
   1.502 -    ioctl:  grant_ioctl,
   1.503 +	ioctl:  grant_ioctl,
   1.504  };
   1.505  
   1.506  static int
   1.507  grant_read(char *page, char **start, off_t off, int count, int *eof,
   1.508  	   void *data)
   1.509  {
   1.510 -    int             len;
   1.511 -    unsigned int    i;
   1.512 -    grant_entry_t  *gt;
   1.513 +	int             len;
   1.514 +	unsigned int    i;
   1.515 +	grant_entry_t  *gt;
   1.516  
   1.517 -    gt = (grant_entry_t *)shared;
   1.518 -    len = 0;
   1.519 +	gt = (grant_entry_t *)shared;
   1.520 +	len = 0;
   1.521  
   1.522 -    for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   1.523 -        /* TODO: safety catch here until this can handle >PAGE_SIZE output */
   1.524 -        if (len > (PAGE_SIZE - 200))
   1.525 -        {
   1.526 -            len += sprintf( page + len, "Truncated.\n");
   1.527 -            break;
   1.528 -        }
   1.529 +	for (i = 0; i < NR_GRANT_ENTRIES; i++) {
   1.530 +		if (len > (PAGE_SIZE - 200)) {
   1.531 +			len += sprintf( page + len, "Truncated.\n");
   1.532 +			break;
   1.533 +		}
   1.534 +	}
   1.535  
   1.536 -        if ( gt[i].flags )
   1.537 -            len += sprintf( page + len,
   1.538 -                    "Grant: ref (0x%x) flags (0x%hx) dom (0x%hx) frame (0x%x)\n", 
   1.539 -                    i,
   1.540 -                    gt[i].flags,
   1.541 -                    gt[i].domid,
   1.542 -                    gt[i].frame );
   1.543 +	if (gt[i].flags) {
   1.544 +		len += sprintf(page + len,
   1.545 +			       "Grant: ref (0x%x) flags (0x%hx) "
   1.546 +			       "dom (0x%hx) frame (0x%x)\n", 
   1.547 +			       i,
   1.548 +			       gt[i].flags,
   1.549 +			       gt[i].domid,
   1.550 +			       gt[i].frame );
   1.551 +	}
   1.552  
   1.553 -    *eof = 1;
   1.554 -    return len;
   1.555 +	*eof = 1;
   1.556 +	return len;
   1.557  }
   1.558  
   1.559  static int
   1.560  grant_write(struct file *file, const char __user *buffer, unsigned long count,
   1.561  	    void *data)
   1.562  {
   1.563 -    /* TODO: implement this */
   1.564 -    return -ENOSYS;
   1.565 +	/* TODO: implement this */
   1.566 +	return -ENOSYS;
   1.567  }
   1.568  
   1.569  #endif /* CONFIG_PROC_FS */
   1.570 @@ -403,70 +412,80 @@ grant_write(struct file *file, const cha
   1.571  int
   1.572  gnttab_resume(void)
   1.573  {
   1.574 -    gnttab_setup_table_t setup;
   1.575 -    unsigned long        frames[NR_GRANT_FRAMES];
   1.576 -    int                  i;
   1.577 +	gnttab_setup_table_t setup;
   1.578 +	unsigned long        frames[NR_GRANT_FRAMES];
   1.579 +	int                  i;
   1.580  
   1.581 -    setup.dom        = DOMID_SELF;
   1.582 -    setup.nr_frames  = NR_GRANT_FRAMES;
   1.583 -    setup.frame_list = frames;
   1.584 +	setup.dom        = DOMID_SELF;
   1.585 +	setup.nr_frames  = NR_GRANT_FRAMES;
   1.586 +	setup.frame_list = frames;
   1.587  
   1.588 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1) != 0);
   1.589 -    BUG_ON(setup.status != 0);
   1.590 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1));
   1.591 +	BUG_ON(setup.status != 0);
   1.592  
   1.593 -    for ( i = 0; i < NR_GRANT_FRAMES; i++ )
   1.594 -        set_fixmap(FIX_GNTTAB_END - i, frames[i] << PAGE_SHIFT);
   1.595 +	for (i = 0; i < NR_GRANT_FRAMES; i++)
   1.596 +		set_fixmap(FIX_GNTTAB_END - i, frames[i] << PAGE_SHIFT);
   1.597  
   1.598 -    return 0;
   1.599 +	return 0;
   1.600  }
   1.601  
   1.602  int
   1.603  gnttab_suspend(void)
   1.604  {
   1.605 -    int i;
   1.606 +	int i;
   1.607  
   1.608 -    for ( i = 0; i < NR_GRANT_FRAMES; i++ )
   1.609 -	clear_fixmap(FIX_GNTTAB_END - i);
   1.610 +	for (i = 0; i < NR_GRANT_FRAMES; i++)
   1.611 +		clear_fixmap(FIX_GNTTAB_END - i);
   1.612  
   1.613 -    return 0;
   1.614 +	return 0;
   1.615  }
   1.616  
   1.617  static int __init
   1.618  gnttab_init(void)
   1.619  {
   1.620 -    int i;
   1.621 +	int i;
   1.622  
   1.623 -    if (xen_init() < 0)
   1.624 -        return -ENODEV;
   1.625 +	if (xen_init() < 0)
   1.626 +		return -ENODEV;
   1.627 +
   1.628 +	BUG_ON(gnttab_resume());
   1.629  
   1.630 -    BUG_ON(gnttab_resume());
   1.631 -
   1.632 -    shared = (grant_entry_t *)fix_to_virt(FIX_GNTTAB_END);
   1.633 +	shared = (grant_entry_t *)fix_to_virt(FIX_GNTTAB_END);
   1.634  
   1.635 -    for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   1.636 -        gnttab_list[i] = i + 1;
   1.637 -    
   1.638 +	for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
   1.639 +		gnttab_list[i] = i + 1;
   1.640 +	gnttab_free_count = NR_GRANT_ENTRIES;
   1.641 +
   1.642  #ifdef CONFIG_PROC_FS
   1.643 -    /*
   1.644 -     *  /proc/xen/grant : used by libxc to access grant tables
   1.645 -     */
   1.646 -    if ( (grant_pde = create_xen_proc_entry("grant", 0600)) == NULL )
   1.647 -    {
   1.648 -        WPRINTK("Unable to create grant xen proc entry\n");
   1.649 -        return -1;
   1.650 -    }
   1.651 +	/*
   1.652 +	 *  /proc/xen/grant : used by libxc to access grant tables
   1.653 +	 */
   1.654 +	if ((grant_pde = create_xen_proc_entry("grant", 0600)) == NULL) {
   1.655 +		WPRINTK("Unable to create grant xen proc entry\n");
   1.656 +		return -1;
   1.657 +	}
   1.658  
   1.659 -    grant_file_ops.read   = grant_pde->proc_fops->read;
   1.660 -    grant_file_ops.write  = grant_pde->proc_fops->write;
   1.661 +	grant_file_ops.read   = grant_pde->proc_fops->read;
   1.662 +	grant_file_ops.write  = grant_pde->proc_fops->write;
   1.663  
   1.664 -    grant_pde->proc_fops  = &grant_file_ops;
   1.665 +	grant_pde->proc_fops  = &grant_file_ops;
   1.666  
   1.667 -    grant_pde->read_proc  = &grant_read;
   1.668 -    grant_pde->write_proc = &grant_write;
   1.669 +	grant_pde->read_proc  = &grant_read;
   1.670 +	grant_pde->write_proc = &grant_write;
   1.671  #endif
   1.672  
   1.673 -    printk("Grant table initialized\n");
   1.674 -    return 0;
   1.675 +	printk("Grant table initialized\n");
   1.676 +	return 0;
   1.677  }
   1.678  
   1.679  __initcall(gnttab_init);
   1.680 +
   1.681 +/*
   1.682 + * Local variables:
   1.683 + *  c-file-style: "linux"
   1.684 + *  indent-tabs-mode: t
   1.685 + *  c-indent-level: 8
   1.686 + *  c-basic-offset: 8
   1.687 + *  tab-width: 8
   1.688 + * End:
   1.689 + */
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Sep 28 17:51:24 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Sep 28 18:01:40 2005 +0100
     2.3 @@ -57,7 +57,7 @@ static unsigned int blkif_state = BLKIF_
     2.4  
     2.5  #define MAXIMUM_OUTSTANDING_BLOCK_REQS \
     2.6      (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
     2.7 -#define GRANT_INVALID_REF	(0xFFFF)
     2.8 +#define GRANT_INVALID_REF	0
     2.9  
    2.10  static void kick_pending_request_queues(struct blkfront_info *info);
    2.11  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Wed Sep 28 17:51:24 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Wed Sep 28 18:01:40 2005 +0100
     3.3 @@ -1,7 +1,7 @@
     3.4  /******************************************************************************
     3.5   * Virtual network driver for conversing with remote driver backends.
     3.6   * 
     3.7 - * Copyright (c) 2002-2004, K A Fraser
     3.8 + * Copyright (c) 2002-2005, K A Fraser
     3.9   * 
    3.10   * This file may be distributed separately from the Linux kernel, or
    3.11   * incorporated into other software packages, subject to the following license:
    3.12 @@ -57,7 +57,7 @@
    3.13  #include <asm-xen/xen-public/grant_table.h>
    3.14  #include <asm-xen/gnttab.h>
    3.15  
    3.16 -#define GRANT_INVALID_REF	(0xFFFF)
    3.17 +#define GRANT_INVALID_REF	0
    3.18  
    3.19  #ifndef __GFP_NOWARN
    3.20  #define __GFP_NOWARN 0