Rev 2594 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2594 | Rev 2598 | ||
---|---|---|---|
Line 152... | Line 152... | ||
152 | futex_up(&devices_list_futex); |
152 | futex_up(&devices_list_futex); |
153 | 153 | ||
154 | return device; |
154 | return device; |
155 | } |
155 | } |
156 | 156 | ||
- | 157 | /** |
|
157 | /** Unregister device and free it. Its assumed that driver's device list |
158 | * Unregister device and free it. It's assumed that driver's device list is |
158 | * is already locked. |
159 | * already locked. |
159 | * |
- | |
160 | */ |
160 | */ |
161 | static int devmap_device_unregister_core(devmap_device_t *device) |
161 | static int devmap_device_unregister_core(devmap_device_t *device) |
162 | { |
162 | { |
163 | 163 | ||
164 | list_remove(&(device->devices)); |
164 | list_remove(&(device->devices)); |
Line 169... | Line 169... | ||
169 | 169 | ||
170 | 170 | ||
171 | return EOK; |
171 | return EOK; |
172 | } |
172 | } |
173 | 173 | ||
- | 174 | /** |
|
174 | /** Read info about new driver and add it into linked list of registered drivers. |
175 | * Read info about new driver and add it into linked list of registered |
- | 176 | * drivers. |
|
175 | */ |
177 | */ |
176 | static void devmap_driver_register(devmap_driver_t **odriver) |
178 | static void devmap_driver_register(devmap_driver_t **odriver) |
177 | { |
179 | { |
178 | size_t name_size; |
180 | size_t name_size; |
179 | ipc_callid_t callid; |
181 | ipc_callid_t callid; |
Line 189... | Line 191... | ||
189 | if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) { |
191 | if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) { |
190 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
192 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
191 | return; |
193 | return; |
192 | } |
194 | } |
193 | 195 | ||
- | 196 | if (NULL == |
|
194 | if (NULL == (driver = (devmap_driver_t *)malloc(sizeof(devmap_driver_t)))) { |
197 | (driver = (devmap_driver_t *)malloc(sizeof(devmap_driver_t)))) { |
195 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
198 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
196 | return; |
199 | return; |
197 | } |
200 | } |
198 | 201 | ||
199 | /* |
202 | /* |
Line 206... | Line 209... | ||
206 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
209 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
207 | return; |
210 | return; |
208 | } |
211 | } |
209 | 212 | ||
210 | if (name_size > DEVMAP_NAME_MAXLEN) { |
213 | if (name_size > DEVMAP_NAME_MAXLEN) { |
211 | printf("Too logn name: %u: maximum is %u.\n", name_size, DEVMAP_NAME_MAXLEN); |
214 | printf("Too logn name: %u: maximum is %u.\n", name_size, |
- | 215 | DEVMAP_NAME_MAXLEN); |
|
212 | free(driver); |
216 | free(driver); |
213 | ipc_answer_fast(callid, EINVAL, 0, 0); |
217 | ipc_answer_fast(callid, EINVAL, 0, 0); |
214 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
218 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
215 | return; |
219 | return; |
216 | } |
220 | } |
Line 253... | Line 257... | ||
253 | * Create connection to the driver |
257 | * Create connection to the driver |
254 | */ |
258 | */ |
255 | callid = async_get_call(&call); |
259 | callid = async_get_call(&call); |
256 | 260 | ||
257 | if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { |
261 | if (IPC_M_CONNECT_TO_ME != IPC_GET_METHOD(call)) { |
258 | printf("DevMap: Unexpected method: %u.\n", \ |
262 | printf("DevMap: Unexpected method: %u.\n", |
259 | IPC_GET_METHOD(call)); |
263 | IPC_GET_METHOD(call)); |
260 | ipc_answer_fast(callid, ENOTSUP, 0, 0); |
264 | ipc_answer_fast(callid, ENOTSUP, 0, 0); |
261 | 265 | ||
262 | free(driver->name); |
266 | free(driver->name); |
263 | free(driver); |
267 | free(driver); |
Line 271... | Line 275... | ||
271 | 275 | ||
272 | list_initialize(&(driver->drivers)); |
276 | list_initialize(&(driver->drivers)); |
273 | 277 | ||
274 | futex_down(&drivers_list_futex); |
278 | futex_down(&drivers_list_futex); |
275 | 279 | ||
- | 280 | /* TODO: |
|
276 | /* TODO: check that no driver with name equals to driver->name is registered */ |
281 | * check that no driver with name equal to driver->name is registered |
- | 282 | */ |
|
277 | 283 | ||
278 | /* |
284 | /* |
279 | * Insert new driver into list of registered drivers |
285 | * Insert new driver into list of registered drivers |
280 | */ |
286 | */ |
281 | list_append(&(driver->drivers), &drivers_list); |
287 | list_append(&(driver->drivers), &drivers_list); |
Line 312... | Line 318... | ||
312 | 318 | ||
313 | futex_down(&devices_list_futex); |
319 | futex_down(&devices_list_futex); |
314 | futex_down(&(driver->devices_futex)); |
320 | futex_down(&(driver->devices_futex)); |
315 | 321 | ||
316 | while (!list_empty(&(driver->devices))) { |
322 | while (!list_empty(&(driver->devices))) { |
317 | device = list_get_instance(driver->devices.next, devmap_device_t, driver_devices); |
323 | device = list_get_instance(driver->devices.next, |
- | 324 | devmap_device_t, driver_devices); |
|
318 | printf("Unregister device '%s'.\n", device->name); |
325 | printf("Unregister device '%s'.\n", device->name); |
319 | devmap_device_unregister_core(device); |
326 | devmap_device_unregister_core(device); |
320 | } |
327 | } |
321 | 328 | ||
322 | futex_up(&(driver->devices_futex)); |
329 | futex_up(&(driver->devices_futex)); |
Line 352... | Line 359... | ||
352 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
359 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
353 | return; |
360 | return; |
354 | } |
361 | } |
355 | 362 | ||
356 | /* Create new device entry */ |
363 | /* Create new device entry */ |
- | 364 | if (NULL == |
|
357 | if (NULL == (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { |
365 | (device = (devmap_device_t *)malloc(sizeof(devmap_device_t)))) { |
358 | printf("Cannot allocate new device.\n"); |
366 | printf("Cannot allocate new device.\n"); |
359 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
367 | ipc_answer_fast(iid, ENOMEM, 0, 0); |
360 | return; |
368 | return; |
361 | } |
369 | } |
362 | 370 | ||
Line 454... | Line 462... | ||
454 | */ |
462 | */ |
455 | handle = IPC_GET_ARG1(*call); |
463 | handle = IPC_GET_ARG1(*call); |
456 | dev = devmap_device_find_handle(handle); |
464 | dev = devmap_device_find_handle(handle); |
457 | 465 | ||
458 | if (NULL == dev) { |
466 | if (NULL == dev) { |
459 | printf("DevMap: No registered device with handle %d.\n", handle); |
467 | printf("DevMap: No registered device with handle %d.\n", |
- | 468 | handle); |
|
460 | ipc_answer_fast(callid, ENOENT, 0, 0); |
469 | ipc_answer_fast(callid, ENOENT, 0, 0); |
461 | return; |
470 | return; |
462 | } |
471 | } |
463 | 472 | ||
464 | /* FIXME: is this correct method how to pass argument on forwarding ?*/ |
473 | /* FIXME: is this correct method how to pass argument on forwarding ?*/ |
465 | ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle), 0); |
474 | ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle), |
- | 475 | 0); |
|
466 | return; |
476 | return; |
467 | } |
477 | } |
468 | 478 | ||
469 | /** Find handle for device instance identified by name. |
479 | /** Find handle for device instance identified by name. |
470 | * In answer will be send EOK and device handle in arg1 or a error |
480 | * In answer will be send EOK and device handle in arg1 or a error |
Line 506... | Line 516... | ||
506 | } |
516 | } |
507 | 517 | ||
508 | /* |
518 | /* |
509 | * Send confirmation to sender and get data into buffer. |
519 | * Send confirmation to sender and get data into buffer. |
510 | */ |
520 | */ |
511 | if (EOK != (retval = ipc_data_deliver(callid, &call, name, name_size))) { |
521 | if (EOK != (retval = ipc_data_deliver(callid, &call, name, |
- | 522 | name_size))) { |
|
512 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
523 | ipc_answer_fast(iid, EREFUSED, 0, 0); |
513 | return; |
524 | return; |
514 | } |
525 | } |
515 | 526 | ||
516 | /* |
527 | /* |
Line 661... | Line 672... | ||
661 | cont = false; |
672 | cont = false; |
662 | continue; /* Exit thread */ |
673 | continue; /* Exit thread */ |
663 | 674 | ||
664 | case DEVMAP_DEVICE_CONNECT_ME_TO: |
675 | case DEVMAP_DEVICE_CONNECT_ME_TO: |
665 | /* Connect client to selected device */ |
676 | /* Connect client to selected device */ |
666 | printf("DevMap: connect to device %d.\n", IPC_GET_ARG1(call)); |
677 | printf("DevMap: connect to device %d.\n", |
- | 678 | IPC_GET_ARG1(call)); |
|
667 | devmap_forward(callid, &call); |
679 | devmap_forward(callid, &call); |
668 | break; |
680 | break; |
669 | 681 | ||
670 | case DEVMAP_DEVICE_GET_HANDLE: |
682 | case DEVMAP_DEVICE_GET_HANDLE: |
671 | devmap_get_handle(callid, &call); |
683 | devmap_get_handle(callid, &call); |
Line 700... | Line 712... | ||
700 | case DEVMAP_CLIENT: |
712 | case DEVMAP_CLIENT: |
701 | devmap_connection_client(iid, icall); |
713 | devmap_connection_client(iid, icall); |
702 | break; |
714 | break; |
703 | default: |
715 | default: |
704 | ipc_answer_fast(iid, ENOENT, 0, 0); /* No such interface */ |
716 | ipc_answer_fast(iid, ENOENT, 0, 0); /* No such interface */ |
705 | printf("DevMap: Unknown interface %u.\n", \ |
717 | printf("DevMap: Unknown interface %u.\n", |
706 | (ipcarg_t)(IPC_GET_ARG1(*icall))); |
718 | (ipcarg_t)(IPC_GET_ARG1(*icall))); |
707 | } |
719 | } |
708 | 720 | ||
709 | /* Cleanup */ |
721 | /* Cleanup */ |
710 | 722 |