Changeset e0ba26b in mainline for uspace/drv/vhc
- Timestamp:
- 2011-01-25T19:20:26Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 192a0063
- Parents:
- a088d15 (diff), 68a68705 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv/vhc
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/conn.h
ra088d15 re0ba26b 51 51 52 52 void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *); 53 void on_client_close(device_t *); 53 54 54 55 -
uspace/drv/vhc/conndev.c
ra088d15 re0ba26b 88 88 int callback = IPC_GET_ARG5(*icall); 89 89 virtdev_connection_t *dev 90 = virtdev_add_device(callback );90 = virtdev_add_device(callback, (sysarg_t)fibril_get_id()); 91 91 if (!dev) { 92 92 ipc_answer_0(icallid, EEXISTS); … … 99 99 int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH); 100 100 101 dprintf(0, "virtual device connected (name: %s)", 102 rc == EOK ? devname : "<unknown>"); 103 104 /* FIXME: destroy the device when the client disconnects. */ 101 dprintf(0, "virtual device connected (name: %s, id: %x)", 102 rc == EOK ? devname : "<unknown>", dev->id); 105 103 106 104 return; … … 110 108 } 111 109 110 /** Callback for DDF when client disconnects. 111 * 112 * @param d Device the client was connected to. 113 */ 114 void on_client_close(device_t *d) 115 { 116 /* 117 * Maybe a virtual device is being unplugged. 118 */ 119 virtdev_connection_t *dev = virtdev_find((sysarg_t)fibril_get_id()); 120 if (dev == NULL) { 121 return; 122 } 123 124 dprintf(0, "virtual device disconnected (id: %x)", dev->id); 125 virtdev_destroy_device(dev); 126 } 127 112 128 113 129 /** -
uspace/drv/vhc/devices.c
ra088d15 re0ba26b 58 58 /** Create virtual device. 59 59 * 60 * @param address USB address.61 60 * @param phone Callback phone. 61 * @param id Device id. 62 62 * @return New device. 63 * @retval NULL Out of memory or address already occupied.64 */ 65 virtdev_connection_t *virtdev_add_device(int phone )63 * @retval NULL Out of memory. 64 */ 65 virtdev_connection_t *virtdev_add_device(int phone, sysarg_t id) 66 66 { 67 67 virtdev_connection_t *dev = (virtdev_connection_t *) 68 68 malloc(sizeof(virtdev_connection_t)); 69 if (dev == NULL) { 70 return NULL; 71 } 72 69 73 dev->phone = phone; 74 dev->id = id; 70 75 list_append(&dev->link, &devices); 71 76 … … 73 78 74 79 return dev; 80 } 81 82 /** Find virtual device by id. 83 * 84 * @param id Device id. 85 * @return Device with given id. 86 * @retval NULL No such device. 87 */ 88 virtdev_connection_t *virtdev_find(sysarg_t id) 89 { 90 link_t *pos; 91 list_foreach(pos, &devices) { 92 virtdev_connection_t *dev 93 = list_get_instance(pos, virtdev_connection_t, link); 94 if (dev->id == id) { 95 return dev; 96 } 97 } 98 99 return NULL; 75 100 } 76 101 … … 90 115 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction) 91 116 { 117 /* For easier debugging. */ 118 switch (transaction->type) { 119 case USBVIRT_TRANSACTION_SETUP: 120 case USBVIRT_TRANSACTION_OUT: 121 transaction->actual_len = transaction->len; 122 break; 123 case USBVIRT_TRANSACTION_IN: 124 transaction->actual_len = 0; 125 break; 126 default: 127 assert(false && "unreachable branch in switch()"); 128 } 129 usb_transaction_outcome_t outcome = USB_OUTCOME_BABBLE; 130 92 131 link_t *pos; 93 132 list_foreach(pos, &devices) { … … 140 179 transaction->actual_len = IPC_GET_ARG1(answer_data); 141 180 rc = (int)answer_rc; 181 } 182 183 /* 184 * If at least one device was able to accept this 185 * transaction and process it, we can announce success. 186 */ 187 if (rc == EOK) { 188 outcome = USB_OUTCOME_OK; 142 189 } 143 190 } … … 165 212 transaction->buffer, transaction->len, 166 213 &tmp); 167 if (tmp < transaction->len) { 168 transaction->len = tmp; 169 } 214 transaction->actual_len = tmp; 170 215 break; 171 216 … … 178 223 } 179 224 dprintf(4, "transaction on hub processed..."); 225 outcome = USB_OUTCOME_OK; 180 226 } 181 227 … … 184 230 * real-life image. 185 231 */ 186 return USB_OUTCOME_OK;232 return outcome; 187 233 } 188 234 -
uspace/drv/vhc/devices.h
ra088d15 re0ba26b 45 45 /** Phone used when sending data to device. */ 46 46 int phone; 47 /** Unique identification. */ 48 sysarg_t id; 47 49 /** Linked-list handle. */ 48 50 link_t link; 49 51 } virtdev_connection_t; 50 52 51 virtdev_connection_t *virtdev_add_device(int );52 virtdev_connection_t *virtdev_ get_mine(void);53 virtdev_connection_t *virtdev_add_device(int, sysarg_t); 54 virtdev_connection_t *virtdev_find(sysarg_t); 53 55 void virtdev_destroy_device(virtdev_connection_t *); 54 56 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *); -
uspace/drv/vhc/hcd.c
ra088d15 re0ba26b 69 69 .interfaces[USBHC_DEV_IFACE] = &vhc_iface, 70 70 .interfaces[USB_DEV_IFACE] = &hc_usb_iface, 71 .close = on_client_close, 71 72 .default_handler = default_connection_handler 72 73 }; -
uspace/drv/vhc/hub/hub.c
ra088d15 re0ba26b 155 155 } 156 156 157 /** Disconnects a device from a hub. 158 * 159 * @param hub Hub the device was connected to. 160 * @param device Device to be disconnected. 161 * @return Error code. 162 */ 163 int hub_disconnect_device(hub_t *hub, void *device) 164 { 165 size_t index = hub_find_device(hub, device); 166 if (index == (size_t) -1) { 167 return ENOENT; 168 } 169 170 hub_port_t *port = &hub->ports[index]; 171 172 port->connected_device = NULL; 173 port->state = HUB_PORT_STATE_DISCONNECTED; 174 set_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 175 176 return EOK; 177 } 178 157 179 /** Find port device is connected to. 158 180 * … … 173 195 } 174 196 175 return 0;197 return -1; 176 198 } 177 199 -
uspace/drv/vhc/hub/hub.h
ra088d15 re0ba26b 94 94 void hub_init(hub_t *); 95 95 size_t hub_connect_device(hub_t *, void *); 96 int hub_disconnect_device(hub_t *, void *); 96 97 size_t hub_find_device(hub_t *, void *); 97 98 void hub_acquire(hub_t *); -
uspace/drv/vhc/hub/virthub.c
ra088d15 re0ba26b 203 203 204 204 hub_acquire(hub); 205 /* TODO: implement. */205 hub_disconnect_device(hub, conn); 206 206 hub_release(hub); 207 207
Note:
See TracChangeset
for help on using the changeset viewer.
