41,7 → 41,6 |
#include <stdio.h> |
#include <errno.h> |
#include <bool.h> |
#include <fibril_sync.h> |
#include <stdlib.h> |
#include <string.h> |
#include <ipc/devmap.h> |
62,8 → 61,6 |
ipcarg_t phone; |
/** Device driver name */ |
char *name; |
/** Fibril mutex for list of devices owned by this driver */ |
fibril_mutex_t devices_mutex; |
} devmap_driver_t; |
|
/** Info about registered device |
94,17 → 91,6 |
LIST_INITIALIZE(drivers_list); |
LIST_INITIALIZE(pending_req); |
|
/* Locking order: |
* drivers_list_mutex |
* devices_list_mutex |
* (devmap_driver_t *)->devices_mutex |
* create_handle_mutex |
**/ |
|
static FIBRIL_MUTEX_INITIALIZE(devices_list_mutex); |
static FIBRIL_MUTEX_INITIALIZE(drivers_list_mutex); |
static FIBRIL_MUTEX_INITIALIZE(create_handle_mutex); |
|
static dev_handle_t last_handle = 0; |
|
static dev_handle_t devmap_create_handle(void) |
113,9 → 99,7 |
* and implement some version of LRU algorithm, avoid overflow |
*/ |
|
fibril_mutex_lock(&create_handle_mutex); |
last_handle++; |
fibril_mutex_unlock(&create_handle_mutex); |
|
return last_handle; |
} |
149,8 → 133,6 |
*/ |
static devmap_device_t *devmap_device_find_handle(dev_handle_t handle) |
{ |
fibril_mutex_lock(&devices_list_mutex); |
|
link_t *item = (&devices_list)->next; |
devmap_device_t *device = NULL; |
|
161,15 → 143,11 |
item = item->next; |
} |
|
if (item == &devices_list) { |
fibril_mutex_unlock(&devices_list_mutex); |
if (item == &devices_list) |
return NULL; |
} |
|
device = list_get_instance(item, devmap_device_t, devices); |
|
fibril_mutex_unlock(&devices_list_mutex); |
|
return device; |
} |
|
257,13 → 235,10 |
|
driver->name[name_size] = 0; |
|
/* Initialize mutex for list of devices owned by this driver */ |
fibril_mutex_initialize(&driver->devices_mutex); |
|
/* |
* Initialize list of asociated devices |
*/ |
list_initialize(&driver->devices); |
list_initialize(&(driver->devices)); |
|
/* |
* Create connection to the driver |
286,8 → 261,6 |
|
list_initialize(&(driver->drivers)); |
|
fibril_mutex_lock(&drivers_list_mutex); |
|
/* TODO: |
* check that no driver with name equal to driver->name is registered |
*/ |
296,7 → 269,6 |
* Insert new driver into list of registered drivers |
*/ |
list_append(&(driver->drivers), &drivers_list); |
fibril_mutex_unlock(&drivers_list_mutex); |
|
ipc_answer_0(iid, EOK); |
|
313,8 → 285,6 |
if (driver == NULL) |
return EEXISTS; |
|
fibril_mutex_lock(&drivers_list_mutex); |
|
if (driver->phone != 0) |
ipc_hangup(driver->phone); |
|
321,10 → 291,6 |
/* Remove it from list of drivers */ |
list_remove(&(driver->drivers)); |
|
/* Unregister all its devices */ |
fibril_mutex_lock(&devices_list_mutex); |
fibril_mutex_lock(&driver->devices_mutex); |
|
while (!list_empty(&(driver->devices))) { |
devmap_device_t *device = list_get_instance(driver->devices.next, |
devmap_device_t, driver_devices); |
331,10 → 297,6 |
devmap_device_unregister_core(device); |
} |
|
fibril_mutex_unlock(&driver->devices_mutex); |
fibril_mutex_unlock(&devices_list_mutex); |
fibril_mutex_unlock(&drivers_list_mutex); |
|
/* free name and driver */ |
if (driver->name != NULL) |
free(driver->name); |
348,6 → 310,8 |
/** Process pending lookup requests */ |
static void process_pending_lookup(void) |
{ |
async_serialize_start(); |
|
link_t *cur; |
|
loop: |
366,6 → 330,8 |
|
goto loop; |
} |
|
async_serialize_end(); |
} |
|
|
419,12 → 385,9 |
list_initialize(&(device->devices)); |
list_initialize(&(device->driver_devices)); |
|
fibril_mutex_lock(&devices_list_mutex); |
|
/* Check that device with such name is not already registered */ |
if (NULL != devmap_device_find_name(device->name)) { |
printf(NAME ": Device '%s' already registered\n", device->name); |
fibril_mutex_unlock(&devices_list_mutex); |
free(device->name); |
free(device); |
ipc_answer_0(iid, EEXISTS); |
439,14 → 402,8 |
/* Insert device into list of all devices */ |
list_append(&device->devices, &devices_list); |
|
/* Insert device into list of devices that belog to one driver */ |
fibril_mutex_lock(&device->driver->devices_mutex); |
|
list_append(&device->driver_devices, &device->driver->devices); |
|
fibril_mutex_unlock(&device->driver->devices_mutex); |
fibril_mutex_unlock(&devices_list_mutex); |
|
ipc_answer_1(iid, EOK, device->handle); |
} |
|
598,15 → 555,11 |
|
static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall) |
{ |
fibril_mutex_lock(&devices_list_mutex); |
ipc_answer_1(iid, EOK, list_count(&devices_list)); |
fibril_mutex_unlock(&devices_list_mutex); |
} |
|
static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall) |
{ |
fibril_mutex_lock(&devices_list_mutex); |
|
ipc_callid_t callid; |
size_t size; |
if (!ipc_data_read_receive(&callid, &size)) { |
650,8 → 603,6 |
|
free(desc); |
|
fibril_mutex_unlock(&devices_list_mutex); |
|
ipc_answer_1(iid, EOK, pos); |
} |
|
675,8 → 626,6 |
list_initialize(&(device->devices)); |
list_initialize(&(device->driver_devices)); |
|
fibril_mutex_lock(&devices_list_mutex); |
|
/* Get unique device handle */ |
device->handle = devmap_create_handle(); |
device->driver = NULL; |
684,8 → 633,6 |
/* Insert device into list of all devices */ |
list_append(&device->devices, &devices_list); |
|
fibril_mutex_unlock(&devices_list_mutex); |
|
return true; |
} |
|
708,9 → 655,12 |
ipc_call_t call; |
ipc_callid_t callid = async_get_call(&call); |
|
async_serialize_start(); |
|
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
cont = false; |
async_serialize_end(); |
continue; |
case DEVMAP_DRIVER_UNREGISTER: |
if (NULL == driver) |
736,6 → 686,8 |
if (!(callid & IPC_CALLID_NOTIFICATION)) |
ipc_answer_0(callid, ENOENT); |
} |
|
async_serialize_end(); |
} |
|
if (NULL != driver) { |
742,8 → 694,13 |
/* |
* Unregister the device driver and all its devices. |
*/ |
|
async_serialize_start(); |
|
devmap_driver_unregister(driver); |
driver = NULL; |
|
async_serialize_end(); |
} |
} |
|
760,9 → 717,12 |
ipc_call_t call; |
ipc_callid_t callid = async_get_call(&call); |
|
async_serialize_start(); |
|
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
cont = false; |
async_serialize_end(); |
continue; |
case DEVMAP_DEVICE_GET_HANDLE: |
devmap_get_handle(callid, &call); |
780,6 → 740,8 |
if (!(callid & IPC_CALLID_NOTIFICATION)) |
ipc_answer_0(callid, ENOENT); |
} |
|
async_serialize_end(); |
} |
} |
|