fedora core 2.6.9-1.11-FC2
[linux-2.6.git] / drivers / xen / usbback / control.c
1 /******************************************************************************
2  * arch/xen/drivers/usbif/backend/control.c
3  * 
4  * Routines for interfacing with the control plane.
5  * 
6  * Copyright (c) 2004, Keir Fraser
7  */
8
9 #include "common.h"
10
11 static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
12 {
13     DPRINTK("Received usbif backend message, subtype=%d\n", msg->subtype);
14     
15     switch ( msg->subtype )
16     {
17     case CMSG_USBIF_BE_CREATE:
18         usbif_create((usbif_be_create_t *)&msg->msg[0]);
19         break;        
20     case CMSG_USBIF_BE_DESTROY:
21         usbif_destroy((usbif_be_destroy_t *)&msg->msg[0]);
22         break;        
23     case CMSG_USBIF_BE_CONNECT:
24         usbif_connect((usbif_be_connect_t *)&msg->msg[0]);
25         break;        
26     case CMSG_USBIF_BE_DISCONNECT:
27         if ( !usbif_disconnect((usbif_be_disconnect_t *)&msg->msg[0],msg->id) )
28             return; /* Sending the response is deferred until later. */
29         break;        
30     case CMSG_USBIF_BE_CLAIM_PORT:
31         usbif_claim_port((usbif_be_claim_port_t *)&msg->msg[0]);
32         break;
33     case CMSG_USBIF_BE_RELEASE_PORT:
34         usbif_release_port((usbif_be_release_port_t *)&msg->msg[0]);
35         break;
36     default:
37         DPRINTK("Parse error while reading message subtype %d, len %d\n",
38                 msg->subtype, msg->length);
39         msg->length = 0;
40         break;
41     }
42
43     ctrl_if_send_response(msg);
44 }
45
46 void usbif_ctrlif_init(void)
47 {
48     ctrl_msg_t                       cmsg;
49     usbif_be_driver_status_changed_t st;
50
51     (void)ctrl_if_register_receiver(CMSG_USBIF_BE, usbif_ctrlif_rx, 
52                                     CALLBACK_IN_BLOCKING_CONTEXT);
53
54     /* Send a driver-UP notification to the domain controller. */
55     cmsg.type      = CMSG_USBIF_BE;
56     cmsg.subtype   = CMSG_USBIF_BE_DRIVER_STATUS_CHANGED;
57     cmsg.length    = sizeof(usbif_be_driver_status_changed_t);
58     st.status      = USBIF_DRIVER_STATUS_UP;
59     memcpy(cmsg.msg, &st, sizeof(st));
60     ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
61 }