Changeset 1e32a63 in mainline
- Timestamp:
- 2010-12-13T00:30:09Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f9a0cef
- Parents:
- f8597ca
- Location:
- uspace/drv/vhc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/hub.c
rf8597ca r1e32a63 181 181 hub_port_t *port = &hub_dev.ports[i]; 182 182 183 port->index = (int) i ;183 port->index = (int) i + 1; 184 184 port->device = NULL; 185 185 port->state = HUB_PORT_STATE_NOT_CONFIGURED; 186 186 port->status_change = 0; 187 fibril_mutex_initialize(&port->guard); 187 188 } 188 189 … … 225 226 for (i = 0; i < HUB_PORT_COUNT; i++) { 226 227 hub_port_t *port = &hub_dev.ports[i]; 228 fibril_mutex_lock(&port->guard); 227 229 228 230 if (port->device != NULL) { 231 fibril_mutex_unlock(&port->guard); 229 232 continue; 230 233 } … … 241 244 //if (port->state == HUB_PORT_STATE_DISCONNECTED) { 242 245 port->state = HUB_PORT_STATE_DISABLED; 243 set_port_status_change (port, HUB_STATUS_C_PORT_CONNECTION);246 set_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 244 247 //} 245 248 249 fibril_mutex_unlock(&port->guard); 250 246 251 return i; 247 252 } -
uspace/drv/vhc/hubintern.h
rf8597ca r1e32a63 37 37 38 38 #include "hub.h" 39 #include <fibril_synch.h> 39 40 40 41 /** Endpoint number for status change pipe. */ … … 124 125 hub_port_state_t state; 125 126 uint16_t status_change; 127 fibril_mutex_t guard; 126 128 } hub_port_t; 127 129 … … 139 141 void clear_port_status_change(hub_port_t *, uint16_t); 140 142 void set_port_status_change(hub_port_t *, uint16_t); 143 void set_port_status_change_nl(hub_port_t *, uint16_t); 141 144 142 145 -
uspace/drv/vhc/hubops.c
rf8597ca r1e32a63 67 67 void *buffer, size_t size, size_t *actual_size); 68 68 static void set_port_state(hub_port_t *, hub_port_state_t); 69 static void clear_port_status_change_nl(hub_port_t *, uint16_t); 70 static void set_port_state_nl(hub_port_t *, hub_port_state_t); 69 71 70 72 /** Standard USB requests. */ … … 135 137 async_usleep(change->delay); 136 138 139 fibril_mutex_lock(&change->port->guard); 137 140 if (change->port->state == change->old_state) { 138 set_port_state(change->port, change->new_state); 139 } 141 set_port_state_nl(change->port, change->new_state); 142 } 143 fibril_mutex_unlock(&change->port->guard); 140 144 141 145 free(change); … … 166 170 void set_port_state(hub_port_t *port, hub_port_state_t state) 167 171 { 168 dprintf(1, "setting port %d state to %d (%c)", port->index, 169 state, hub_port_state_as_char(state)); 172 fibril_mutex_lock(&port->guard); 173 set_port_state_nl(port, state); 174 fibril_mutex_unlock(&port->guard); 175 } 176 177 void set_port_state_nl(hub_port_t *port, hub_port_state_t state) 178 { 179 180 dprintf(2, "setting port %d state to %d (%c) from %c (change=%u)", 181 port->index, 182 state, hub_port_state_as_char(state), 183 hub_port_state_as_char(port->state), 184 (unsigned int) port->status_change); 170 185 171 186 if (state == HUB_PORT_STATE_POWERED_OFF) { 172 clear_port_status_change (port, HUB_STATUS_C_PORT_CONNECTION);173 clear_port_status_change (port, HUB_STATUS_C_PORT_ENABLE);174 clear_port_status_change (port, HUB_STATUS_C_PORT_RESET);187 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 188 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE); 189 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 175 190 } 176 191 if (state == HUB_PORT_STATE_RESUMING) { … … 184 199 if ((port->state == HUB_PORT_STATE_RESETTING) 185 200 && (state == HUB_PORT_STATE_ENABLED)) { 186 set_port_status_change (port, HUB_STATUS_C_PORT_RESET);201 set_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 187 202 } 188 203 … … 212 227 _GET_PORT(port, portindex); 213 228 229 fibril_mutex_lock(&port->guard); 230 int rc = ENOTSUP; 231 214 232 switch (feature) { 215 233 case USB_HUB_FEATURE_PORT_ENABLE: 216 234 if ((port->state != HUB_PORT_STATE_NOT_CONFIGURED) 217 235 && (port->state != HUB_PORT_STATE_POWERED_OFF)) { 218 set_port_state(port, HUB_PORT_STATE_DISABLED); 219 } 220 return EOK; 236 set_port_state_nl(port, HUB_PORT_STATE_DISABLED); 237 } 238 rc = EOK; 239 break; 221 240 222 241 case USB_HUB_FEATURE_PORT_SUSPEND: 223 242 if (port->state != HUB_PORT_STATE_SUSPENDED) { 224 return EOK; 225 } 226 set_port_state(port, HUB_PORT_STATE_RESUMING); 227 return EOK; 243 rc = EOK; 244 break; 245 } 246 set_port_state_nl(port, HUB_PORT_STATE_RESUMING); 247 rc = EOK; 248 break; 228 249 229 250 case USB_HUB_FEATURE_PORT_POWER: 230 251 if (port->state != HUB_PORT_STATE_NOT_CONFIGURED) { 231 set_port_state(port, HUB_PORT_STATE_POWERED_OFF); 232 } 233 return EOK; 252 set_port_state_nl(port, HUB_PORT_STATE_POWERED_OFF); 253 } 254 rc = EOK; 255 break; 234 256 235 257 case USB_HUB_FEATURE_C_PORT_CONNECTION: 236 clear_port_status_change(port, HUB_STATUS_C_PORT_CONNECTION); 237 return EOK; 258 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_CONNECTION); 259 rc = EOK; 260 break; 238 261 239 262 case USB_HUB_FEATURE_C_PORT_ENABLE: 240 clear_port_status_change(port, HUB_STATUS_C_PORT_ENABLE); 241 return EOK; 263 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_ENABLE); 264 rc = EOK; 265 break; 242 266 243 267 case USB_HUB_FEATURE_C_PORT_SUSPEND: 244 clear_port_status_change(port, HUB_STATUS_C_PORT_SUSPEND); 245 return EOK; 268 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_SUSPEND); 269 rc = EOK; 270 break; 246 271 247 272 case USB_HUB_FEATURE_C_PORT_OVER_CURRENT: 248 clear_port_status_change(port, HUB_STATUS_C_PORT_OVER_CURRENT); 249 return EOK; 250 } 251 252 return ENOTSUP; 273 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_OVER_CURRENT); 274 rc = EOK; 275 break; 276 277 case USB_HUB_FEATURE_C_PORT_RESET: 278 clear_port_status_change_nl(port, HUB_STATUS_C_PORT_RESET); 279 rc = EOK; 280 break; 281 } 282 283 fibril_mutex_unlock(&port->guard); 284 285 return rc; 253 286 } 254 287 … … 285 318 _GET_PORT(port, portindex); 286 319 320 fibril_mutex_lock(&port->guard); 321 287 322 uint32_t status; 288 323 status = MAKE_BYTE( … … 312 347 status |= (port->status_change << 16); 313 348 349 fibril_mutex_unlock(&port->guard); 350 314 351 dprintf(2, "GetPortStatus(port=%d, status=%u)\n", (int)portindex, 315 352 (unsigned int) status); … … 327 364 _GET_PORT(port, portindex); 328 365 366 fibril_mutex_lock(&port->guard); 367 368 int rc = ENOTSUP; 369 329 370 switch (feature) { 330 371 case USB_HUB_FEATURE_PORT_RESET: 331 372 if (port->state != HUB_PORT_STATE_POWERED_OFF) { 332 set_port_state(port, HUB_PORT_STATE_RESETTING); 333 } 334 return EOK; 373 set_port_state_nl(port, HUB_PORT_STATE_RESETTING); 374 } 375 rc = EOK; 376 break; 335 377 336 378 case USB_HUB_FEATURE_PORT_SUSPEND: 337 379 if (port->state == HUB_PORT_STATE_ENABLED) { 338 set_port_state(port, HUB_PORT_STATE_SUSPENDED); 339 } 340 return EOK; 380 set_port_state_nl(port, HUB_PORT_STATE_SUSPENDED); 381 } 382 rc = EOK; 383 break; 341 384 342 385 case USB_HUB_FEATURE_PORT_POWER: 343 386 if (port->state == HUB_PORT_STATE_POWERED_OFF) { 344 set_port_state(port, HUB_PORT_STATE_DISCONNECTED); 345 } 346 return EOK; 347 } 348 return ENOTSUP; 387 set_port_state_nl(port, HUB_PORT_STATE_DISCONNECTED); 388 } 389 rc = EOK; 390 break; 391 } 392 393 fibril_mutex_unlock(&port->guard); 394 return rc; 349 395 } 350 396 … … 416 462 } 417 463 464 void clear_port_status_change_nl(hub_port_t *port, uint16_t change) 465 { 466 port->status_change &= (~change); 467 dprintf(2, "cleared port %d status change %d (%u)", port->index, 468 (int)change, (unsigned int) port->status_change); 469 } 470 471 void set_port_status_change_nl(hub_port_t *port, uint16_t change) 472 { 473 port->status_change |= change; 474 dprintf(2, "set port %d status change %d (%u)", port->index, 475 (int)change, (unsigned int) port->status_change); 476 477 } 478 418 479 void clear_port_status_change(hub_port_t *port, uint16_t change) 419 480 { 420 port->status_change &= (~change); 481 fibril_mutex_lock(&port->guard); 482 clear_port_status_change_nl(port, change); 483 fibril_mutex_unlock(&port->guard); 421 484 } 422 485 423 486 void set_port_status_change(hub_port_t *port, uint16_t change) 424 487 { 425 port->status_change |= change; 488 fibril_mutex_lock(&port->guard); 489 set_port_status_change_nl(port, change); 490 fibril_mutex_unlock(&port->guard); 426 491 } 427 492 … … 441 506 hub_port_t *port = &hub_dev.ports[i]; 442 507 508 fibril_mutex_lock(&port->guard); 443 509 if (port->status_change != 0) { 444 510 change_map |= (1 << (i + 1)); 445 511 } 512 fibril_mutex_unlock(&port->guard); 446 513 } 447 514
Note:
See TracChangeset
for help on using the changeset viewer.