59
/** Pointers to previous and next drivers in linked list */
59
/** Link to drivers_list */
61
/** Pointer to the linked list of devices controlled by this driver */
63
/** Phone asociated with this driver */
62
/** List of devices controlled by this driver */
65
/** Session asociated with this driver */
65
68
/** Device driver name */
67
71
/** Fibril mutex for list of devices owned by this driver */
68
72
fibril_mutex_t devices_mutex;
89
/** Pointer to the previous and next device in the list of all devices */
96
/** Link to global list of devices (devices_list) */
91
/** Pointer to the previous and next device in the list of devices
92
owned by one driver */
98
/** Link to driver list of devices (devmap_driver_t.devices) */
93
99
link_t driver_devices;
94
100
/** Unique device identifier */
95
101
devmap_handle_t handle;
217
223
/** Find namespace with given name. */
218
224
static devmap_namespace_t *devmap_namespace_find_name(const char *name)
222
226
assert(fibril_mutex_is_locked(&devices_list_mutex));
224
for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
228
list_foreach(namespaces_list, item) {
225
229
devmap_namespace_t *namespace =
226
230
list_get_instance(item, devmap_namespace_t, namespaces);
227
231
if (str_cmp(namespace->name, name) == 0)
239
243
static devmap_namespace_t *devmap_namespace_find_handle(devmap_handle_t handle)
243
245
assert(fibril_mutex_is_locked(&devices_list_mutex));
245
for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
247
list_foreach(namespaces_list, item) {
246
248
devmap_namespace_t *namespace =
247
249
list_get_instance(item, devmap_namespace_t, namespaces);
248
250
if (namespace->handle == handle)
256
258
static devmap_device_t *devmap_device_find_name(const char *ns_name,
257
259
const char *name)
261
261
assert(fibril_mutex_is_locked(&devices_list_mutex));
263
for (item = devices_list.next; item != &devices_list; item = item->next) {
263
list_foreach(devices_list, item) {
264
264
devmap_device_t *device =
265
265
list_get_instance(item, devmap_device_t, devices);
266
266
if ((str_cmp(device->namespace->name, ns_name) == 0)
279
279
static devmap_device_t *devmap_device_find_handle(devmap_handle_t handle)
283
281
assert(fibril_mutex_is_locked(&devices_list_mutex));
285
for (item = devices_list.next; item != &devices_list; item = item->next) {
283
list_foreach(devices_list, item) {
286
284
devmap_device_t *device =
287
285
list_get_instance(item, devmap_device_t, devices);
288
286
if (device->handle == handle)
405
403
* Create connection to the driver
408
ipc_callid_t callid = async_get_call(&call);
410
if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
405
driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
411
407
free(driver->name);
413
async_answer_0(callid, ENOTSUP);
414
409
async_answer_0(iid, ENOTSUP);
418
driver->phone = IPC_GET_ARG5(call);
419
async_answer_0(callid, EOK);
422
414
* Initialize mutex for list of devices
423
415
* owned by this driver
462
454
fibril_mutex_lock(&drivers_list_mutex);
464
if (driver->phone != 0)
465
async_hangup(driver->phone);
457
async_hangup(driver->sess);
467
459
/* Remove it from list of drivers */
468
460
list_remove(&(driver->drivers));
471
463
fibril_mutex_lock(&devices_list_mutex);
472
464
fibril_mutex_lock(&driver->devices_mutex);
474
while (!list_empty(&(driver->devices))) {
475
devmap_device_t *device = list_get_instance(driver->devices.next,
476
devmap_device_t, driver_devices);
466
while (!list_empty(&driver->devices)) {
467
devmap_device_t *device = list_get_instance(
468
list_first(&driver->devices), devmap_device_t,
477
470
devmap_device_unregister_core(device);
606
599
devmap_handle_t handle = IPC_GET_ARG2(*call);
607
600
devmap_device_t *dev = devmap_device_find_handle(handle);
609
if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
602
if ((dev == NULL) || (dev->driver == NULL) || (!dev->driver->sess)) {
610
603
fibril_mutex_unlock(&devices_list_mutex);
611
604
async_answer_0(callid, ENOENT);
615
if (dev->forward_interface == 0) {
616
async_forward_fast(callid, dev->driver->phone,
620
async_forward_fast(callid, dev->driver->phone,
621
dev->forward_interface, dev->handle, 0,
608
async_exch_t *exch = async_exchange_begin(dev->driver->sess);
610
if (dev->forward_interface == 0)
611
async_forward_fast(callid, exch, dev->handle, 0, 0, IPC_FF_NONE);
613
async_forward_fast(callid, exch, dev->forward_interface,
614
dev->handle, 0, IPC_FF_NONE);
616
async_exchange_end(exch);
625
618
fibril_mutex_unlock(&devices_list_mutex);
818
for (item = namespaces_list.next; item != &namespaces_list;
810
list_foreach(namespaces_list, item) {
820
811
devmap_namespace_t *namespace =
821
812
list_get_instance(item, devmap_namespace_t, namespaces);
884
for (item = devices_list.next; item != &devices_list; item = item->next) {
874
list_foreach(devices_list, item) {
885
875
devmap_device_t *device =
886
876
list_get_instance(item, devmap_device_t, devices);
1028
1018
if (driver == NULL)
1033
1022
ipc_call_t call;
1034
1023
ipc_callid_t callid = async_get_call(&call);
1025
if (!IPC_GET_IMETHOD(call))
1036
1028
switch (IPC_GET_IMETHOD(call)) {
1037
case IPC_M_PHONE_HUNGUP:
1040
1029
case DEVMAP_DRIVER_UNREGISTER:
1041
1030
if (NULL == driver)
1042
1031
async_answer_0(callid, ENOENT);
1079
1068
/* Accept connection */
1080
1069
async_answer_0(iid, EOK);
1084
1072
ipc_call_t call;
1085
1073
ipc_callid_t callid = async_get_call(&call);
1075
if (!IPC_GET_IMETHOD(call))
1087
1078
switch (IPC_GET_IMETHOD(call)) {
1088
case IPC_M_PHONE_HUNGUP:
1091
1079
case DEVMAP_DEVICE_GET_HANDLE:
1092
1080
devmap_device_get_handle(callid, &call);
1124
1112
/** Function for handling connections to devmap
1127
static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall)
1115
static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
1129
1117
/* Select interface */
1130
1118
switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {