Changeset 355f7c2 in mainline
- Timestamp:
- 2010-10-25T07:44:02Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ca07cd3
- Parents:
- 7a7bfeb3
- Location:
- uspace
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/ids.h
r7a7bfeb3 r355f7c2 50 50 } usbvirt_transaction_type_t; 51 51 52 const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type); 52 53 53 54 #endif -
uspace/lib/usbvirt/transaction.c
r7a7bfeb3 r355f7c2 38 38 #include <mem.h> 39 39 40 #include "ids.h" 40 41 #include "private.h" 41 42 42 43 static usb_direction_t setup_transaction_direction(usb_endpoint_t, void *, size_t); 43 44 static void process_control_transfer(usb_endpoint_t, usbvirt_control_transfer_t *); 45 46 /** Convert virtual USB transaction type to string. 47 */ 48 const char *usbvirt_str_transaction_type(usbvirt_transaction_type_t type) 49 { 50 switch (type) { 51 case USBVIRT_TRANSACTION_SETUP: 52 return "setup"; 53 case USBVIRT_TRANSACTION_IN: 54 return "in"; 55 case USBVIRT_TRANSACTION_OUT: 56 return "out"; 57 default: 58 return "unknown"; 59 } 60 } 44 61 45 62 int transaction_setup(usbvirt_device_t *device, usb_endpoint_t endpoint, -
uspace/srv/hw/bus/usb/hcd/virtual/Makefile
r7a7bfeb3 r355f7c2 35 35 conndev.c \ 36 36 connhost.c \ 37 debug.c \ 37 38 devices.c \ 38 39 hc.c \ -
uspace/srv/hw/bus/usb/hcd/virtual/conndev.c
r7a7bfeb3 r355f7c2 44 44 /** Connection handler for communcation with virtual device. 45 45 * 46 * This function also takes care of proper phone hung-up. 47 * 46 48 * @param phone_hash Incoming phone hash. 47 49 * @param dev Virtual device handle. … … 51 53 assert(dev != NULL); 52 54 53 dprintf("phone%#x: virtual device %d connected", 54 phone_hash, dev->id); 55 dprintf(0, "virtual device connected through phone %#x", phone_hash); 55 56 56 57 while (true) { … … 64 65 ipc_hangup(dev->phone); 65 66 ipc_answer_0(callid, EOK); 66 dprintf( "phone%#x: device %d hang-up",67 phone_hash , dev->id);67 dprintf(0, "phone%#x: device hung-up", 68 phone_hash); 68 69 return; 69 70 … … 73 74 74 75 default: 76 dprintf_inval_call(2, call, phone_hash); 75 77 ipc_answer_0(callid, EINVAL); 76 78 break; -
uspace/srv/hw/bus/usb/hcd/virtual/connhost.c
r7a7bfeb3 r355f7c2 56 56 static void out_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg) 57 57 { 58 dprintf( "out_callback(buffer, %u, %d, %p)", len, outcome, arg);59 (void)len;58 dprintf(2, "out_callback(buffer, %u, %d, %p)", len, outcome, arg); 59 60 60 transaction_details_t * trans = (transaction_details_t *)arg; 61 61 … … 63 63 64 64 free(trans); 65 free(buffer); 65 if (buffer) { 66 free(buffer); 67 } 66 68 } 67 69 … … 70 72 static void in_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg) 71 73 { 72 dprintf( "in_callback(buffer, %u, %d, %p)", len, outcome, arg);74 dprintf(2, "in_callback(buffer, %u, %d, %p)", len, outcome, arg); 73 75 transaction_details_t * trans = (transaction_details_t *)arg; 74 76 … … 116 118 }; 117 119 118 dprintf( "pretending transfer to function (dev=%d:%d)",120 dprintf(1, "pretending transfer to function (dev=%d:%d)", 119 121 target.address, target.endpoint); 120 122 … … 144 146 trans->handle = handle; 145 147 146 dprintf("adding transaction to HC", NAME);147 148 hc_add_transaction_to_device(setup_transaction, target, 148 149 buffer, len, … … 150 151 151 152 ipc_answer_1(iid, EOK, handle); 152 dprintf( "transfer to function scheduled (handle %d)", handle);153 dprintf(2, "transfer to function scheduled (handle %d)", handle); 153 154 } 154 155 … … 163 164 size_t len = IPC_GET_ARG3(icall); 164 165 165 dprintf( "pretending transfer from function (dev=%d:%d)",166 dprintf(1, "pretending transfer from function (dev=%d:%d)", 166 167 target.address, target.endpoint); 167 168 … … 183 184 trans->handle = handle; 184 185 185 dprintf("adding transaction to HC", NAME);186 186 hc_add_transaction_from_device(target, 187 187 buffer, len, … … 189 189 190 190 ipc_answer_1(iid, EOK, handle); 191 dprintf( "transfer from function scheduled (handle %d)", handle);191 dprintf(2, "transfer from function scheduled (handle %d)", handle); 192 192 } 193 193 … … 197 197 * By host is typically meant top-level USB driver. 198 198 * 199 * This function also takes care of proper phone hung-up. 200 * 199 201 * @param phone_hash Incoming phone hash. 200 202 * @param host_phone Callback phone to host. … … 204 206 assert(host_phone > 0); 205 207 206 dprintf( "phone%#x: host connected", phone_hash);208 dprintf(0, "host connected through phone %#x", phone_hash); 207 209 208 210 … … 217 219 ipc_hangup(host_phone); 218 220 ipc_answer_0(callid, EOK); 219 dprintf("phone%#x: host hang-up", phone_hash); 221 dprintf(0, "phone%#x: host hung-up", 222 phone_hash); 220 223 return; 221 224 … … 223 226 ipc_answer_0(callid, ELIMIT); 224 227 break; 225 226 227 case IPC_M_USB_HCD_SEND_DATA:228 handle_data_to_function(callid, call,229 false, host_phone);230 break;231 232 case IPC_M_USB_HCD_RECEIVE_DATA:233 handle_data_from_function(callid, call, host_phone);234 break;235 228 236 229 case IPC_M_USB_HCD_TRANSACTION_SIZE: … … 271 264 272 265 default: 266 dprintf_inval_call(2, call, phone_hash); 273 267 ipc_answer_0(callid, EINVAL); 274 268 break; -
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
r7a7bfeb3 r355f7c2 68 68 static link_t transaction_list; 69 69 70 #define TRANSACTION_FORMAT "T[%d:%d (%d) %d]"70 #define TRANSACTION_FORMAT "T[%d:%d %s (%d)]" 71 71 #define TRANSACTION_PRINTF(t) \ 72 72 (t).target.address, (t).target.endpoint, \ 73 (int)(t).len, (int)(t).type 73 usbvirt_str_transaction_type((t).type), \ 74 (int)(t).len 74 75 75 76 #define transaction_get_instance(lnk) \ … … 88 89 usb_transaction_outcome_t outcome) 89 90 { 90 dprintf( "processing transaction " TRANSACTION_FORMAT ", outcome: %s",91 dprintf(3, "processing transaction " TRANSACTION_FORMAT ", outcome: %s", 91 92 TRANSACTION_PRINTF(*transaction), 92 93 usb_str_transaction_outcome(outcome)); … … 113 114 } 114 115 115 dprintf("virtual hub has address %d:*.", virthub_dev.address); 116 char ports[HUB_PORT_COUNT + 2]; 117 hub_get_port_statuses(ports, HUB_PORT_COUNT + 1); 118 dprintf(3, "virtual hub: addr=%d ports=%s", 119 virthub_dev.address, ports); 116 120 117 121 link_t *first_transaction_link = transaction_list.next; … … 120 124 list_remove(first_transaction_link); 121 125 122 dprintf( "processing transaction " TRANSACTION_FORMAT "",126 dprintf(3, "processing transaction " TRANSACTION_FORMAT "", 123 127 TRANSACTION_PRINTF(*transaction)); 124 128 … … 148 152 transaction->callback = callback; 149 153 transaction->callback_arg = arg; 154 155 dprintf(1, "creating transaction " TRANSACTION_FORMAT, 156 TRANSACTION_PRINTF(*transaction)); 150 157 151 158 return transaction; -
uspace/srv/hw/bus/usb/hcd/virtual/hcd.c
r7a7bfeb3 r355f7c2 57 57 58 58 ipc_answer_0(iid, EOK); 59 printf("%s: new client connected (phone %#x).\n", NAME, phone_hash);60 59 61 60 while (true) { … … 112 111 * No other methods could be served now. 113 112 */ 113 dprintf_inval_call(1, call, phone_hash); 114 114 ipc_answer_0(callid, ENOTSUP); 115 115 } … … 117 117 118 118 int main(int argc, char * argv[]) 119 { 120 printf("%s: Virtual USB host controller driver.\n", NAME); 119 { 120 printf("%s: virtual USB host controller driver.\n", NAME); 121 122 int i; 123 for (i = 1; i < argc; i++) { 124 if (str_cmp(argv[i], "-d") == 0) { 125 debug_level++; 126 } 127 } 121 128 122 129 int rc; … … 138 145 hub_init(); 139 146 140 printf("%s: accepting connections.\n", NAME); 147 printf("%s: accepting connections [devmap=%s, debug=%d].\n", NAME, 148 DEVMAP_PATH, debug_level); 141 149 hc_manager(); 142 150 -
uspace/srv/hw/bus/usb/hcd/virtual/hub.c
r7a7bfeb3 r355f7c2 43 43 #include "hubintern.h" 44 44 45 hub_port_t hub_ports[HUB_PORT_COUNT];46 45 47 46 /** Standard device descriptor. */ … … 108 107 }; 109 108 109 /** All hub configuration descriptors. */ 110 110 static usbvirt_device_configuration_extras_t extra_descriptors[] = { 111 111 { … … 137 137 }; 138 138 139 /** Hub as a virtual device. */ 139 140 usbvirt_device_t virthub_dev = { 140 141 .ops = &hub_ops, 141 142 .descriptors = &descriptors, 142 143 }; 143 144 145 /** Hub device. */ 144 146 hub_device_t hub_dev; 145 147 148 /** Initialize virtual hub. */ 146 149 void hub_init(void) 147 150 { … … 156 159 157 160 usbvirt_connect_local(&virthub_dev); 158 //virthub_dev.send_data = send_data; 159 160 printf("%s: virtual hub (%d ports) created.\n", NAME, HUB_PORT_COUNT); 161 } 162 161 162 dprintf(1, "virtual hub (%d ports) created", HUB_PORT_COUNT); 163 } 164 165 /** Connect device to the hub. 166 * 167 * @param device Device to be connected. 168 * @return Port where the device was connected to. 169 */ 163 170 size_t hub_add_device(virtdev_connection_t *device) 164 171 { … … 191 198 } 192 199 193 200 /** Disconnect device from the hub. */ 194 201 void hub_remove_device(virtdev_connection_t *device) 195 202 { … … 209 216 } 210 217 218 /** Tell whether device port is open. 219 * 220 * @return Whether communication to and from the device can go through the hub. 221 */ 211 222 bool hub_can_device_signal(virtdev_connection_t * device) 212 223 { … … 221 232 } 222 233 234 /** Format hub port status. 235 * 236 * @param result Buffer where to store status string. 237 * @param len Number of characters that is possible to store in @p result 238 * (excluding trailing zero). 239 */ 240 void hub_get_port_statuses(char *result, size_t len) 241 { 242 if (len > HUB_PORT_COUNT) { 243 len = HUB_PORT_COUNT; 244 } 245 size_t i; 246 for (i = 0; i < len; i++) { 247 result[i] = hub_port_state_as_char(hub_dev.ports[i].state); 248 } 249 result[len] = 0; 250 } 223 251 224 252 /** -
uspace/srv/hw/bus/usb/hcd/virtual/hub.h
r7a7bfeb3 r355f7c2 51 51 void hub_remove_device(virtdev_connection_t *); 52 52 bool hub_can_device_signal(virtdev_connection_t *); 53 void hub_get_port_statuses(char *result, size_t len); 53 54 54 55 #endif -
uspace/srv/hw/bus/usb/hcd/virtual/hubintern.h
r7a7bfeb3 r355f7c2 38 38 #include "hub.h" 39 39 40 /** Endpoint number for status change pipe. */ 40 41 #define HUB_STATUS_CHANGE_PIPE 1 42 /** Configuration value for hub configuration. */ 41 43 #define HUB_CONFIGURATION_ID 1 42 44 … … 66 68 } __attribute__ ((packed)) hub_descriptor_t; 67 69 70 /** Hub port internal state. 71 * Some states (e.g. port over current) are not covered as they are not 72 * simulated at all. 73 */ 68 74 typedef enum { 69 75 HUB_PORT_STATE_NOT_CONFIGURED, … … 78 84 } hub_port_state_t; 79 85 86 /** Convert hub port state to a char. */ 87 static inline char hub_port_state_as_char(hub_port_state_t state) { 88 switch (state) { 89 case HUB_PORT_STATE_NOT_CONFIGURED: 90 return '-'; 91 case HUB_PORT_STATE_POWERED_OFF: 92 return 'O'; 93 case HUB_PORT_STATE_DISCONNECTED: 94 return 'X'; 95 case HUB_PORT_STATE_DISABLED: 96 return 'D'; 97 case HUB_PORT_STATE_RESETTING: 98 return 'R'; 99 case HUB_PORT_STATE_ENABLED: 100 return 'E'; 101 case HUB_PORT_STATE_SUSPENDED: 102 return 'S'; 103 case HUB_PORT_STATE_RESUMING: 104 return 'F'; 105 default: 106 return '?'; 107 } 108 } 109 110 /** Hub status change mask bits. */ 80 111 typedef enum { 81 112 HUB_STATUS_C_PORT_CONNECTION = (1 << 0), … … 87 118 } hub_status_change_t; 88 119 120 /** Hub port information. */ 89 121 typedef struct { 90 122 virtdev_connection_t *device; … … 93 125 } hub_port_t; 94 126 127 /** Hub device type. */ 95 128 typedef struct { 96 129 hub_port_t ports[HUB_PORT_COUNT]; -
uspace/srv/hw/bus/usb/hcd/virtual/hubops.c
r7a7bfeb3 r355f7c2 43 43 #include "hubintern.h" 44 44 45 /** Produce a byte from bit values. 46 */ 45 47 #define MAKE_BYTE(b0, b1, b2, b3, b4, b5, b6, b7) \ 46 48 (( \ … … 63 65 void *buffer, size_t size, size_t *actual_size); 64 66 65 67 /** Standard USB requests. */ 66 68 static usbvirt_standard_device_request_ops_t standard_request_ops = { 67 69 .on_get_status = NULL, … … 78 80 }; 79 81 80 82 /** Hub operations. */ 81 83 usbvirt_device_ops_t hub_ops = { 82 84 .standard_request_ops = &standard_request_ops, … … 86 88 }; 87 89 90 /** Callback for GET_DESCRIPTOR request. */ 88 91 static int on_get_descriptor(struct usbvirt_device *dev, 89 92 usb_device_request_setup_packet_t *request, uint8_t *data) … … 124 127 } 125 128 129 /** Get access to a port or return with EINVAL. */ 126 130 #define _GET_PORT(portvar, index) \ 127 131 do { \ … … 274 278 275 279 276 277 280 /** Callback for class request. */ 278 281 static int on_class_request(struct usbvirt_device *dev, 279 282 usb_device_request_setup_packet_t *request, uint8_t *data) 280 283 { 281 printf("%s: hub class request (%d)\n", NAME, (int) request->request);284 dprintf(2, "hub class request (%d)\n", (int) request->request); 282 285 283 286 uint8_t recipient = request->request_type & 31; … … 287 290 do { \ 288 291 if (!(cond)) { \ 289 printf("%s:WARN: invalid class request (%s not met).\n", \292 dprintf(0, "WARN: invalid class request (%s not met).\n", \ 290 293 NAME, #cond); \ 291 294 return EINVAL; \ … … 347 350 } 348 351 352 /** Callback for data request. */ 349 353 static int on_data_request(struct usbvirt_device *dev, 350 354 usb_endpoint_t endpoint, 351 355 void *buffer, size_t size, size_t *actual_size) 352 356 { 357 if (endpoint != HUB_STATUS_CHANGE_PIPE) { 358 return EINVAL; 359 } 360 353 361 uint8_t change_map = 0; 354 362 -
uspace/srv/hw/bus/usb/hcd/virtual/vhcd.h
r7a7bfeb3 r355f7c2 36 36 #define VHCD_VHCD_H_ 37 37 38 #include <stdio.h>39 40 38 #define NAME "hcd-virt" 41 39 #define NAMESPACE "usb" … … 43 41 #define DEVMAP_PATH NAMESPACE "/" NAME 44 42 45 /** Debugging printf. 46 * @see printf 47 */ 48 static inline void dprintf(const char * format, ...) 49 { 50 printf("%s: ", NAME); 51 va_list args; 52 va_start(args, format); 53 vprintf(format, args); 54 va_end(args); 55 printf("\n"); 56 } 43 extern int debug_level; 44 void dprintf(int, const char *, ...); 45 void dprintf_inval_call(int, ipc_call_t, ipcarg_t); 57 46 58 47 #endif
Note:
See TracChangeset
for help on using the changeset viewer.