Changeset 7fcb74c in mainline for uspace/srv/devmap/devmap.c


Ignore:
Timestamp:
2009-06-29T16:02:32Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f49cf64
Parents:
bfd247f
Message:

add support for creating null devices on demand

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devmap/devmap.c

    rbfd247f r7fcb74c  
    4747#include <ipc/devmap.h>
    4848
    49 #define NAME  "devmap"
     49#define NAME          "devmap"
     50#define NULL_DEVICES  256
    5051
    5152/** Representation of device driver.
     
    9899static FIBRIL_MUTEX_INITIALIZE(drivers_list_mutex);
    99100static FIBRIL_MUTEX_INITIALIZE(create_handle_mutex);
     101static FIBRIL_MUTEX_INITIALIZE(null_devices_mutex);
    100102
    101103static dev_handle_t last_handle = 0;
     104static devmap_device_t *null_devices[NULL_DEVICES];
    102105
    103106static dev_handle_t devmap_create_handle(void)
     
    619622}
    620623
    621 /** Initialize device mapper.
    622  *
    623  *
    624  */
    625 static bool devmap_init(void)
    626 {
     624static void devmap_null_create(ipc_callid_t iid, ipc_call_t *icall)
     625{
     626        fibril_mutex_lock(&null_devices_mutex);
     627       
     628        unsigned int i;
     629        bool fnd = false;
     630       
     631        for (i = 0; i < NULL_DEVICES; i++) {
     632                if (null_devices[i] == NULL) {
     633                        fnd = true;
     634                        break;
     635                }
     636        }
     637       
     638        if (!fnd) {
     639                fibril_mutex_unlock(&null_devices_mutex);
     640                ipc_answer_0(iid, ENOMEM);
     641                return;
     642        }
     643       
    627644        /* Create NULL device entry */
    628645        devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t));
    629         if (device == NULL)
    630                 return false;
    631        
    632         device->name = str_dup("null");
     646        if (device == NULL) {
     647                fibril_mutex_unlock(&null_devices_mutex);
     648                ipc_answer_0(iid, ENOMEM);
     649                return;
     650        }
     651       
     652        char null[DEVMAP_NAME_MAXLEN];
     653        snprintf(null, DEVMAP_NAME_MAXLEN, "null%u", i);
     654       
     655        device->name = str_dup(null);
    633656        if (device->name == NULL) {
     657                fibril_mutex_unlock(&null_devices_mutex);
    634658                free(device);
    635                 return false;
     659                ipc_answer_0(iid, ENOMEM);
     660                return;
    636661        }
    637662       
     
    645670        device->driver = NULL;
    646671       
    647         /* Insert device into list of all devices  */
     672        /* Insert device into list of all devices
     673           and into null devices array */
    648674        list_append(&device->devices, &devices_list);
     675        null_devices[i] = device;
    649676       
    650677        fibril_mutex_unlock(&devices_list_mutex);
     678        fibril_mutex_unlock(&null_devices_mutex);
     679       
     680        ipc_answer_1(iid, EOK, (ipcarg_t) i);
     681}
     682
     683static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall)
     684{
     685        fibril_mutex_lock(&null_devices_mutex);
     686       
     687        ipcarg_t i = IPC_GET_ARG1(*icall);
     688       
     689        if (null_devices[i] == NULL) {
     690                ipc_answer_0(iid, ENOENT);
     691                return;
     692        }
     693       
     694        devmap_device_unregister_core(null_devices[i]);
     695        null_devices[i] = NULL;
     696       
     697        fibril_mutex_unlock(&null_devices_mutex);
     698       
     699        ipc_answer_0(iid, EOK);
     700}
     701
     702/** Initialize device mapper.
     703 *
     704 *
     705 */
     706static bool devmap_init(void)
     707{
     708        fibril_mutex_lock(&null_devices_mutex);
     709       
     710        unsigned int i;
     711        for (i = 0; i < NULL_DEVICES; i++)
     712                null_devices[i] = NULL;
     713       
     714        fibril_mutex_unlock(&null_devices_mutex);
    651715       
    652716        return true;
     
    702766        }
    703767       
    704         if (NULL != driver) {
     768        if (driver != NULL) {
    705769                /*
    706770                 * Unregister the device driver and all its devices.
     
    733797                case DEVMAP_DEVICE_GET_NAME:
    734798                        devmap_get_name(callid, &call);
     799                        break;
     800                case DEVMAP_DEVICE_NULL_CREATE:
     801                        devmap_null_create(callid, &call);
     802                        break;
     803                case DEVMAP_DEVICE_NULL_DESTROY:
     804                        devmap_null_destroy(callid, &call);
    735805                        break;
    736806                case DEVMAP_DEVICE_GET_COUNT:
     
    784854        /* Set a handler of incomming connections */
    785855        async_set_client_connection(devmap_connection);
    786 
     856       
    787857        /* Register device mapper at naming service */
    788858        ipcarg_t phonead;
Note: See TracChangeset for help on using the changeset viewer.