static ide_device_info * create_device(ide_bus_info *bus, bool is_device1) { ide_device_info *device; TRACE("create_device: bus %p, device-number %d\n", bus, is_device1); device = (ide_device_info *)malloc(sizeof(*device)); if (device == NULL) return NULL; memset(device, 0, sizeof(*device)); device->is_device1 = is_device1; device->target_id = is_device1; setup_device_links(bus, device); device->DMA_failures = 0; device->CQ_failures = 0; device->num_failed_send = 0; device->combined_sense = 0; device->num_running_reqs = 0; device->reconnect_timer.device = device; init_synced_pc(&device->reconnect_timeout_synced_pc, reconnect_timeout_worker); if (scsi->alloc_dpc(&device->reconnect_timeout_dpc) != B_OK) goto err; device->total_sectors = 0; return device; err: destroy_device(device); return NULL; }
int connect_channel( const char *name, ide_controller_interface *controller, ide_channel_cookie channel, ide_controller_params *controller_params, ide_bus_info **bus_out ) { ide_bus_info *bus; xpt_bus_cookie xpt_cookie; int res; SHOW_FLOW0( 3, "" ); bus = kmalloc( sizeof( *bus )); if( bus == NULL ) return ERR_NO_MEMORY; SHOW_FLOW0( 3, "1" ); memset( bus, 0, sizeof( *bus )); memcpy( &bus->controller_params, controller_params, sizeof( *controller_params )); bus->lock = 0; bus->num_running_reqs = 0; bus->controller = controller; bus->channel = channel; bus->active_qrequest = NULL; bus->disconnected = false; init_synced_pc( &bus->scan_bus_syncinfo, scan_device_worker ); init_synced_pc( &bus->disconnect_syncinfo, disconnect_worker ); bus->wait_id = bus->dpc_id = 0; bus->xpt_cookie = NULL; timer_setup_timer( ide_timeout, bus, &bus->timer ); bus->state = ide_state_idle; bus->device_to_reconnect = NULL; bus->synced_pc_list = NULL; if( (res = xpt->alloc_dpc( &bus->irq_dpc )) < 0 ) goto err1; SHOW_FLOW0( 3, "2" ); bus->active_device = NULL; bus->sync_wait_sem = sem_create( 0, "ide_sync_wait" ); if( bus->sync_wait_sem < 0 ) { res = bus->sync_wait_sem; goto err2; } SHOW_FLOW0( 3, "3" ); bus->devices[0] = bus->devices[1] = NULL; bus->scan_device_sem = sem_create( 0, "ide_scan_finished" ); if( bus->scan_device_sem < 0 ) { res = bus->scan_device_sem; goto err3; } SHOW_FLOW0( 3, "4" ); bus->first_device = NULL; strncpy( bus->controller_name, name, HBA_ID ); res = xpt->register_SIM( &ide_sim_interface, (cam_sim_cookie) bus, &xpt_cookie ); if( res < 0 ) goto err4; SHOW_FLOW0( 3, "5" ); bus->path_id = res; // do assignment very last as the irq handler uses this value, so it // must be either NULL or valid bus->xpt_cookie = xpt_cookie; // after this, the bus must be fully functional *bus_out = bus; call_xpt_bus_scan( bus ); return NO_ERROR; err4: sem_delete( bus->scan_device_sem ); err3: sem_delete( bus->sync_wait_sem ); err2: xpt->free_dpc( bus->irq_dpc ); err1: uninit_synced_pc( &bus->scan_bus_syncinfo ); uninit_synced_pc( &bus->disconnect_syncinfo ); kfree( bus ); return res; }