Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7fcb74c in mainline


Ignore:
Timestamp:
2009-06-29T16:02:32Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
f49cf64
Parents:
bfd247f
Message:

add support for creating null devices on demand

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/devmap.c

    rbfd247f r7fcb74c  
    219219}
    220220
     221int devmap_null_create(void)
     222{
     223        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     224       
     225        if (phone < 0)
     226                return -1;
     227       
     228        ipcarg_t null_id;
     229        int retval = async_req_0_1(phone, DEVMAP_DEVICE_NULL_CREATE, &null_id);
     230        if (retval != EOK)
     231                return -1;
     232       
     233        return (int) null_id;
     234}
     235
     236void devmap_null_destroy(int null_id)
     237{
     238        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     239       
     240        if (phone < 0)
     241                return;
     242       
     243        async_req_1_0(phone, DEVMAP_DEVICE_NULL_DESTROY, (ipcarg_t) null_id);
     244}
     245
    221246ipcarg_t devmap_device_get_count(void)
    222247{
  • uspace/lib/libc/include/devmap.h

    rbfd247f r7fcb74c  
    4848extern int devmap_device_connect(dev_handle_t, unsigned int);
    4949
     50extern int devmap_null_create(void);
     51extern void devmap_null_destroy(int);
     52
    5053extern ipcarg_t devmap_device_get_count(void);
    5154extern ipcarg_t devmap_device_get_devices(ipcarg_t, dev_desc_t *);
  • uspace/lib/libc/include/ipc/devmap.h

    rbfd247f r7fcb74c  
    2929/** @addtogroup devmap
    3030 * @{
    31  */ 
     31 */
    3232
    3333#ifndef DEVMAP_DEVMAP_H_
     
    4949        DEVMAP_DEVICE_GET_NAME,
    5050        DEVMAP_DEVICE_GET_HANDLE,
     51        DEVMAP_DEVICE_NULL_CREATE,
     52        DEVMAP_DEVICE_NULL_DESTROY,
    5153        DEVMAP_DEVICE_GET_COUNT,
    5254        DEVMAP_DEVICE_GET_DEVICES
  • 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.