ia64/xen-unstable

changeset 19254:08916e5135b3

minios: cleanup events.c

Don't throw away hypercall error codes. They might be useful. Also
some minor coding style cleanups.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 02 10:51:34 2009 +0000 (2009-03-02)
parents 9c4a38f70b16
children c9e9602cc080
files extras/mini-os/events.c
line diff
     1.1 --- a/extras/mini-os/events.c	Mon Mar 02 10:50:59 2009 +0000
     1.2 +++ b/extras/mini-os/events.c	Mon Mar 02 10:51:34 2009 +0000
     1.3 @@ -42,19 +42,23 @@ void unbind_all_ports(void)
     1.4      int cpu = 0;
     1.5      shared_info_t *s = HYPERVISOR_shared_info;
     1.6      vcpu_info_t   *vcpu_info = &s->vcpu_info[cpu];
     1.7 +    int rc;
     1.8  
     1.9 -    for (i = 0; i < NR_EVS; i++)
    1.10 +    for ( i = 0; i < NR_EVS; i++ )
    1.11      {
    1.12 -        if (i == start_info.console.domU.evtchn ||
    1.13 -            i == start_info.store_evtchn)
    1.14 +        if ( i == start_info.console.domU.evtchn ||
    1.15 +             i == start_info.store_evtchn)
    1.16              continue;
    1.17 -        if (test_and_clear_bit(i, bound_ports))
    1.18 +
    1.19 +        if ( test_and_clear_bit(i, bound_ports) )
    1.20          {
    1.21              struct evtchn_close close;
    1.22              printk("port %d still bound!\n", i);
    1.23              mask_evtchn(i);
    1.24              close.port = i;
    1.25 -            HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
    1.26 +            rc = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
    1.27 +            if ( rc )
    1.28 +                printk("WARN: close_port %s failed rc=%d. ignored\n", i, rc);
    1.29              clear_evtchn(i);
    1.30          }
    1.31      }
    1.32 @@ -71,8 +75,9 @@ int do_event(evtchn_port_t port, struct 
    1.33  
    1.34      clear_evtchn(port);
    1.35  
    1.36 -    if (port >= NR_EVS) {
    1.37 -        printk("Port number too large: %d\n", port);
    1.38 +    if ( port >= NR_EVS )
    1.39 +    {
    1.40 +        printk("WARN: do_event(): Port number too large: %d\n", port);
    1.41          return 1;
    1.42      }
    1.43  
    1.44 @@ -89,9 +94,9 @@ int do_event(evtchn_port_t port, struct 
    1.45  evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler,
    1.46  						  void *data)
    1.47  {
    1.48 - 	if(ev_actions[port].handler != default_handler)
    1.49 + 	if ( ev_actions[port].handler != default_handler )
    1.50          printk("WARN: Handler for port %d already registered, replacing\n",
    1.51 -				port);
    1.52 +               port);
    1.53  
    1.54  	ev_actions[port].data = data;
    1.55  	wmb();
    1.56 @@ -104,8 +109,9 @@ evtchn_port_t bind_evtchn(evtchn_port_t 
    1.57  void unbind_evtchn(evtchn_port_t port )
    1.58  {
    1.59  	struct evtchn_close close;
    1.60 +    int rc;
    1.61  
    1.62 -	if (ev_actions[port].handler == default_handler)
    1.63 +	if ( ev_actions[port].handler == default_handler )
    1.64  		printk("WARN: No handler for port %d when unbinding\n", port);
    1.65  	mask_evtchn(port);
    1.66  	clear_evtchn(port);
    1.67 @@ -116,37 +122,43 @@ void unbind_evtchn(evtchn_port_t port )
    1.68  	clear_bit(port, bound_ports);
    1.69  
    1.70  	close.port = port;
    1.71 -	HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
    1.72 +	rc = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close);
    1.73 +    if ( rc )
    1.74 +        printk("WARN: close_port %s failed rc=%d. ignored\n", port, rc);
    1.75 +        
    1.76  }
    1.77  
    1.78  evtchn_port_t bind_virq(uint32_t virq, evtchn_handler_t handler, void *data)
    1.79  {
    1.80  	evtchn_bind_virq_t op;
    1.81 +    int rc;
    1.82  
    1.83  	/* Try to bind the virq to a port */
    1.84  	op.virq = virq;
    1.85  	op.vcpu = smp_processor_id();
    1.86  
    1.87 -	if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op) != 0 )
    1.88 +	if ( (rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op)) != 0 )
    1.89  	{
    1.90 -		printk("Failed to bind virtual IRQ %d\n", virq);
    1.91 +		printk("Failed to bind virtual IRQ %d with rc=%d\n", virq, rc);
    1.92  		return -1;
    1.93      }
    1.94      bind_evtchn(op.port, handler, data);
    1.95  	return op.port;
    1.96  }
    1.97  
    1.98 -evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data)
    1.99 +evtchn_port_t bind_pirq(uint32_t pirq, int will_share,
   1.100 +                        evtchn_handler_t handler, void *data)
   1.101  {
   1.102  	evtchn_bind_pirq_t op;
   1.103 +    int rc;
   1.104  
   1.105  	/* Try to bind the pirq to a port */
   1.106  	op.pirq = pirq;
   1.107  	op.flags = will_share ? BIND_PIRQ__WILL_SHARE : 0;
   1.108  
   1.109 -	if ( HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &op) != 0 )
   1.110 +	if ( (rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &op)) != 0 )
   1.111  	{
   1.112 -		printk("Failed to bind physical IRQ %d\n", pirq);
   1.113 +		printk("Failed to bind physical IRQ %d with rc=%d\n", pirq, rc);
   1.114  		return -1;
   1.115  	}
   1.116  	bind_evtchn(op.port, handler, data);
   1.117 @@ -173,7 +185,8 @@ void init_events(void)
   1.118      asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
   1.119      wrmsrl(0xc0000101, &cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */
   1.120      cpu0_pda.irqcount = -1;
   1.121 -    cpu0_pda.irqstackptr = (void*) (((unsigned long)irqstack + 2 * STACK_SIZE) & ~(STACK_SIZE - 1));
   1.122 +    cpu0_pda.irqstackptr = (void*) (((unsigned long)irqstack + 2 * STACK_SIZE)
   1.123 +                                    & ~(STACK_SIZE - 1));
   1.124  #endif
   1.125      /* initialize event handler */
   1.126      for ( i = 0; i < NR_EVS; i++ )
   1.127 @@ -207,15 +220,19 @@ void default_handler(evtchn_port_t port,
   1.128  int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler,
   1.129  						 void *data, evtchn_port_t *port)
   1.130  {
   1.131 -    int err;
   1.132 +    int rc;
   1.133 +
   1.134      evtchn_alloc_unbound_t op;
   1.135      op.dom = DOMID_SELF;
   1.136      op.remote_dom = pal;
   1.137 -    err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
   1.138 -    if (err)
   1.139 -		return err;
   1.140 +    rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
   1.141 +    if ( rc )
   1.142 +    {
   1.143 +        printk("ERROR: alloc_unbound failed with rc=%d", rc);
   1.144 +		return rc;
   1.145 +    }
   1.146      *port = bind_evtchn(op.port, handler, data);
   1.147 -    return err;
   1.148 +    return rc;
   1.149  }
   1.150  
   1.151  /* Connect to a port so as to allow the exchange of notifications with
   1.152 @@ -225,15 +242,28 @@ int evtchn_bind_interdomain(domid_t pal,
   1.153  			    evtchn_handler_t handler, void *data,
   1.154  			    evtchn_port_t *local_port)
   1.155  {
   1.156 -    int err;
   1.157 +    int rc;
   1.158      evtchn_port_t port;
   1.159      evtchn_bind_interdomain_t op;
   1.160      op.remote_dom = pal;
   1.161      op.remote_port = remote_port;
   1.162 -    err = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
   1.163 -    if (err)
   1.164 -		return err;
   1.165 +    rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op);
   1.166 +    if ( rc )
   1.167 +    {
   1.168 +        printk("ERROR: bind_interdomain failed with rc=%d", rc);
   1.169 +		return rc;
   1.170 +    }
   1.171      port = op.local_port;
   1.172      *local_port = bind_evtchn(port, handler, data);
   1.173 -    return err;
   1.174 +    return rc;
   1.175  }
   1.176 +
   1.177 +/*
   1.178 + * Local variables:
   1.179 + * mode: C
   1.180 + * c-set-style: "BSD"
   1.181 + * c-basic-offset: 4
   1.182 + * tab-width: 4
   1.183 + * indent-tabs-mode: nil
   1.184 + * End:
   1.185 + */