Changeset cb41a5e in mainline


Ignore:
Timestamp:
2009-05-21T07:03:38Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a095d20
Parents:
2246de6
Message:

improve devmap interface
remove spared device

Location:
uspace
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/devmap/devmap1.c

    r2246de6 rcb41a5e  
    120120char * test_devmap1(bool quiet)
    121121{
    122         int driver_phone;
    123         int dev1_handle;
    124         int dev2_handle;
    125         int dev3_handle;
    126         int handle;
    127         int rc;
    128 
     122        const char *retval = NULL;
     123       
    129124        /* Register new driver */
    130         driver_phone = devmap_driver_register("TestDriver",
    131             driver_client_connection);
    132 
    133         if (driver_phone < 0) {
    134                 return "Error: Cannot register driver.\n";     
    135         }
    136 
     125        int rc = devmap_driver_register("TestDriver", driver_client_connection);
     126        if (rc < 0) {
     127                retval = "Error: Cannot register driver.\n";
     128                goto out;
     129        }
     130       
    137131        /* Register new device dev1. */
    138         rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev1_handle);
     132        dev_handle_t dev1_handle;
     133        rc = devmap_device_register(TEST_DEVICE1, &dev1_handle);
    139134        if (rc != EOK) {
    140                 ipc_hangup(driver_phone);
    141                 return "Error: cannot register device.\n";
    142         }
    143 
     135                retval = "Error: cannot register device.\n";
     136                goto out;
     137        }
     138       
    144139        /*
    145140         * Get handle for dev2 (Should fail unless device is already registered
    146141         * by someone else).
    147142         */
     143        dev_handle_t handle;
    148144        rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0);
    149145        if (rc == EOK) {
    150                 ipc_hangup(driver_phone);
    151                 return "Error: got handle for dev2 before it was registered.\n";
    152         }
    153 
     146                retval = "Error: got handle for dev2 before it was registered.\n";
     147                goto out;
     148        }
     149       
    154150        /* Register new device dev2. */
    155         rc = devmap_device_register(driver_phone, TEST_DEVICE2, &dev2_handle);
     151        dev_handle_t dev2_handle;
     152        rc = devmap_device_register(TEST_DEVICE2, &dev2_handle);
    156153        if (rc != EOK) {
    157                 ipc_hangup(driver_phone);
    158                 return "Error: cannot register device dev2.\n";
    159         }
    160 
     154                retval = "Error: cannot register device dev2.\n";
     155                goto out;
     156        }
     157       
    161158        /* Register device dev1 again. */
    162         rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev3_handle);
     159        dev_handle_t dev3_handle;
     160        rc = devmap_device_register(TEST_DEVICE1, &dev3_handle);
    163161        if (rc == EOK) {
    164                 return "Error: dev1 registered twice.\n";
    165         }
    166 
     162                retval = "Error: dev1 registered twice.\n";
     163                goto out;
     164        }
     165       
    167166        /* Get handle for dev1. */
    168167        rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0);
    169168        if (rc != EOK) {
    170                 ipc_hangup(driver_phone);
    171                 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
    172         }
    173 
     169                retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
     170                goto out;
     171        }
     172       
    174173        if (handle != dev1_handle) {
    175                 ipc_hangup(driver_phone);
    176                 return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
    177         }
    178 
     174                retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
     175                goto out;
     176        }
     177       
    179178        if (device_client(dev1_handle) != EOK) {
    180                 ipc_hangup(driver_phone);
    181                 return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
    182         }
    183 
    184         /* TODO: */
    185 
    186         ipc_hangup(driver_phone);
    187 
     179                retval = "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
     180                goto out;
     181        }
     182       
     183out:
     184        devmap_hangup_phone(DEVMAP_DRIVER);
     185        devmap_hangup_phone(DEVMAP_CLIENT);
     186       
    188187        return NULL;
    189188}
  • uspace/lib/libc/generic/devmap.c

    r2246de6 rcb41a5e  
    3636#include <errno.h>
    3737
    38 static int devmap_phone = -1;
     38static int devmap_phone_driver = -1;
     39static int devmap_phone_client = -1;
    3940
    4041/** Get phone to device mapper task. */
    41 static int devmap_get_phone(unsigned int flags)
    42 {
    43         int phone;
    44 
    45         if (devmap_phone >= 0)
    46                 return devmap_phone;
    47 
    48         if (flags & IPC_FLAG_BLOCKING) {
    49                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP,
    50                     DEVMAP_CLIENT, 0);
    51         } else {
    52                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
    53                     DEVMAP_CLIENT, 0);
    54         }
    55 
    56         if (phone < 0)
    57                 return phone;
    58 
    59         devmap_phone = phone;
    60         return phone;
     42int devmap_get_phone(devmap_interface_t iface, unsigned int flags)
     43{
     44        switch (iface) {
     45        case DEVMAP_DRIVER:
     46                if (devmap_phone_driver >= 0)
     47                        return devmap_phone_driver;
     48               
     49                if (flags & IPC_FLAG_BLOCKING)
     50                        devmap_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
     51                            SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
     52                else
     53                        devmap_phone_driver = ipc_connect_me_to(PHONE_NS,
     54                            SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
     55               
     56                return devmap_phone_driver;
     57        case DEVMAP_CLIENT:
     58                if (devmap_phone_client >= 0)
     59                        return devmap_phone_client;
     60               
     61                if (flags & IPC_FLAG_BLOCKING)
     62                        devmap_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
     63                            SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     64                else
     65                        devmap_phone_client = ipc_connect_me_to(PHONE_NS,
     66                            SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     67               
     68                return devmap_phone_client;
     69        default:
     70                return -1;
     71        }
     72}
     73
     74void devmap_hangup_phone(devmap_interface_t iface)
     75{
     76        switch (iface) {
     77        case DEVMAP_DRIVER:
     78                if (devmap_phone_driver >= 0) {
     79                        ipc_hangup(devmap_phone_driver);
     80                        devmap_phone_driver = -1;
     81                }
     82                break;
     83        case DEVMAP_CLIENT:
     84                if (devmap_phone_client >= 0) {
     85                        ipc_hangup(devmap_phone_client);
     86                        devmap_phone_client = -1;
     87                }
     88                break;
     89        default:
     90                break;
     91        }
    6192}
    6293
     
    6495int devmap_driver_register(const char *name, async_client_conn_t conn)
    6596{
    66         ipcarg_t retval;
    67         aid_t req;
    68         ipc_call_t answer;
    69         int phone;
     97        int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING);
     98       
     99        if (phone < 0)
     100                return phone;
     101       
     102        ipc_call_t answer;
     103        aid_t req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
     104       
     105        ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1);
     106       
     107        if (retval != EOK) {
     108                async_wait_for(req, NULL);
     109                return -1;
     110        }
     111       
     112        async_set_client_connection(conn);
     113       
    70114        ipcarg_t callback_phonehash;
    71 
    72         phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP,
    73             DEVMAP_DRIVER, 0);
    74 
    75         if (phone < 0) {
     115        ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
     116        async_wait_for(req, &retval);
     117       
     118        return retval;
     119}
     120
     121/** Register new device.
     122 *
     123 * @param name   Device name.
     124 * @param handle Output: Handle to the created instance of device.
     125 *
     126 */
     127int devmap_device_register(const char *name, dev_handle_t *handle)
     128{
     129        int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING);
     130       
     131        if (phone < 0)
    76132                return phone;
    77         }
    78        
    79         req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    80         retval = ipc_data_write_start(phone, name, str_size(name) + 1);
    81 
    82         if (retval != EOK) {
    83                 async_wait_for(req, NULL);
    84                 ipc_hangup(phone);
    85                 return -1;
    86         }
    87 
    88         async_set_client_connection(conn);
    89 
    90         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    91         async_wait_for(req, &retval);
    92 
    93         return phone;
    94 }
    95 
    96 int devmap_device_get_handle(const char *name, dev_handle_t *handle,
    97     unsigned int flags)
    98 {
    99         ipcarg_t retval;
    100         aid_t req;
    101         ipc_call_t answer;
    102         int phone;
    103 
    104         phone = devmap_get_phone(flags);
    105         if (phone < 0)
    106                 return phone;
    107 
    108         req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0,
     133       
     134        ipc_call_t answer;
     135        aid_t req = async_send_2(phone, DEVMAP_DEVICE_REGISTER, 0, 0,
    109136            &answer);
    110 
    111         retval = ipc_data_write_start(phone, name, str_size(name) + 1);
    112 
    113         if (retval != EOK) {
    114                 async_wait_for(req, NULL);
    115                 return retval;
    116         }
    117 
    118         async_wait_for(req, &retval);
    119 
     137       
     138        ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1);
     139       
     140        if (retval != EOK) {
     141                async_wait_for(req, NULL);
     142                return retval;
     143        }
     144       
     145        async_wait_for(req, &retval);
     146       
    120147        if (retval != EOK) {
    121148                if (handle != NULL)
     
    123150                return retval;
    124151        }
    125 
     152       
    126153        if (handle != NULL)
    127                 *handle = (int) IPC_GET_ARG1(answer);
    128 
     154                *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     155       
    129156        return retval;
    130157}
    131158
     159int devmap_device_get_handle(const char *name, dev_handle_t *handle, unsigned int flags)
     160{
     161        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     162       
     163        if (phone < 0)
     164                return phone;
     165       
     166        ipc_call_t answer;
     167        aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0,
     168            &answer);
     169       
     170        ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1);
     171       
     172        if (retval != EOK) {
     173                async_wait_for(req, NULL);
     174                return retval;
     175        }
     176       
     177        async_wait_for(req, &retval);
     178       
     179        if (retval != EOK) {
     180                if (handle != NULL)
     181                        *handle = -1;
     182                return retval;
     183        }
     184       
     185        if (handle != NULL)
     186                *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     187       
     188        return retval;
     189}
     190
    132191int devmap_device_connect(dev_handle_t handle, unsigned int flags)
    133192{
    134193        int phone;
    135 
     194       
    136195        if (flags & IPC_FLAG_BLOCKING) {
    137196                phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP,
     
    141200                    DEVMAP_CONNECT_TO_DEVICE, handle);
    142201        }
    143 
     202       
    144203        return phone;
    145204}
    146205
    147 /** Register new device.
    148  *
    149  * @param driver_phone
    150  * @param name Device name.
    151  * @param handle Output: Handle to the created instance of device.
    152  */
    153 int devmap_device_register(int driver_phone, const char *name, int *handle)
    154 {
    155         ipcarg_t retval;
    156         aid_t req;
    157         ipc_call_t answer;
    158 
    159         req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0,
    160             &answer);
    161 
    162         retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1);
    163 
    164         if (retval != EOK) {
    165                 async_wait_for(req, NULL);
    166                 return retval;
    167         }
    168 
    169         async_wait_for(req, &retval);
    170 
    171         if (retval != EOK) {
    172                 if (handle != NULL)
    173                         *handle = -1;
    174                 return retval;
    175         }
    176 
    177         *handle = (int) IPC_GET_ARG1(answer);
    178         return retval;
    179 }
     206ipcarg_t devmap_device_get_count(void)
     207{
     208        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     209       
     210        if (phone < 0)
     211                return 0;
     212       
     213        ipcarg_t count;
     214        int retval = ipc_call_sync_0_1(phone, DEVMAP_DEVICE_GET_COUNT, &count);
     215        if (retval != EOK)
     216                return 0;
     217       
     218        return count;
     219}
     220
     221ipcarg_t devmap_device_get_devices(ipcarg_t count, dev_desc_t *data)
     222{
     223        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     224       
     225        if (phone < 0)
     226                return 0;
     227       
     228        ipc_call_t answer;
     229        aid_t req = async_send_0(phone, DEVMAP_DEVICE_GET_DEVICES, &answer);
     230       
     231        ipcarg_t retval = ipc_data_read_start(phone, data, count * sizeof(dev_desc_t));
     232       
     233        if (retval != EOK) {
     234                async_wait_for(req, NULL);
     235                return 0;
     236        }
     237       
     238        async_wait_for(req, &retval);
     239       
     240        if (retval != EOK)
     241                return 0;
     242       
     243        return IPC_GET_ARG1(answer);
     244}
  • uspace/lib/libc/include/devmap.h

    r2246de6 rcb41a5e  
    3939#include <async.h>
    4040
    41 typedef int dev_handle_t;
     41extern int devmap_get_phone(devmap_interface_t, unsigned int);
     42extern void devmap_hangup_phone(devmap_interface_t iface);
    4243
    4344extern int devmap_driver_register(const char *, async_client_conn_t);
    44 extern int devmap_device_get_handle(const char *, dev_handle_t *,
    45     unsigned int);
     45extern int devmap_device_register(const char *, dev_handle_t *);
     46
     47extern int devmap_device_get_handle(const char *, dev_handle_t *, unsigned int);
    4648extern int devmap_device_connect(dev_handle_t, unsigned int);
    47 extern int devmap_device_register(int, const char *, int *);
     49
     50extern ipcarg_t devmap_device_get_count(void);
     51extern ipcarg_t devmap_device_get_devices(ipcarg_t, dev_desc_t *);
    4852
    4953#endif
  • uspace/lib/libc/include/ipc/devmap.h

    r2246de6 rcb41a5e  
    3838#include <libadt/list.h>
    3939
    40 #define DEVMAP_NAME_MAXLEN 512
     40#define DEVMAP_NAME_MAXLEN  255
     41
     42typedef ipcarg_t dev_handle_t;
    4143
    4244typedef enum {
     
    4648        DEVMAP_DEVICE_UNREGISTER,
    4749        DEVMAP_DEVICE_GET_NAME,
    48         DEVMAP_DEVICE_GET_HANDLE
     50        DEVMAP_DEVICE_GET_HANDLE,
     51        DEVMAP_DEVICE_GET_COUNT,
     52        DEVMAP_DEVICE_GET_DEVICES
    4953} devmap_request_t;
    5054
    51 /** Representation of device driver.
    52  * Each driver is responsible for a set of devices.
    53  */
    54 typedef struct {
    55                 /** Pointers to previous and next drivers in linked list */
    56         link_t drivers;
    57                 /** Pointer to the linked list of devices controlled by
    58                  * this driver */
    59         link_t devices;
    60                 /** Phone asociated with this driver */
    61         ipcarg_t phone;
    62                 /** Device driver name */
    63         char *name;     
    64                 /** Futex for list of devices owned by this driver */
    65         atomic_t devices_futex;
    66 } devmap_driver_t;
    67 
    68 /** Info about registered device
     55/** Interface provided by devmap.
     56 *
     57 * Every process that connects to devmap must ask one of following
     58 * interfaces otherwise connection will be refused.
    6959 *
    7060 */
    71 typedef struct {
    72                 /** Pointer to the previous and next device in the list of all devices */
    73         link_t devices;
    74                 /** Pointer to the previous and next device in the list of devices
    75                  owned by one driver */
    76         link_t driver_devices;
    77                 /** Unique device identifier  */
    78         int handle;
    79                 /** Device name */
    80         char *name;
    81                 /** Device driver handling this device */
    82         devmap_driver_t *driver;
    83 } devmap_device_t;
    84 
    85 /** Interface provided by devmap.
    86  * Every process that connects to devmap must ask one of following
    87  * interfaces otherwise connection will be refused.
    88  */
    8961typedef enum {
    90                 /** Connect as device driver */
    91         DEVMAP_DRIVER = 1,     
    92                 /** Connect as client */
     62        /** Connect as device driver */
     63        DEVMAP_DRIVER = 1,
     64        /** Connect as client */
    9365        DEVMAP_CLIENT,
    94                 /** Create new connection to instance of device that
    95                  * is specified by second argument of call. */
     66        /** Create new connection to instance of device that
     67            is specified by second argument of call. */
    9668        DEVMAP_CONNECT_TO_DEVICE
    9769} devmap_interface_t;
    9870
     71typedef struct {
     72        dev_handle_t handle;
     73        char name[DEVMAP_NAME_MAXLEN + 1];
     74} dev_desc_t;
     75
    9976#endif
    100 
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    r2246de6 rcb41a5e  
    116116static int gxe_bd_init(void)
    117117{
    118         int driver_phone;
    119118        dev_handle_t dev_handle;
    120119        void *vaddr;
     
    126125                return rc;
    127126        }
    128         driver_phone = rc;
    129127
    130128        rc = pio_enable((void *) dev_physical, sizeof(gxe_bd_t), &vaddr);
     
    144142        devbuf = vaddr;
    145143
    146         rc = devmap_device_register(driver_phone, "disk0", &dev_handle);
     144        rc = devmap_device_register("disk0", &dev_handle);
    147145        if (rc != EOK) {
    148                 ipc_hangup(driver_phone);
     146                devmap_hangup_phone(DEVMAP_DRIVER);
    149147                printf(NAME ": Unable to register device.\n");
    150148                return rc;
  • uspace/srv/devmap/devmap.c

    r2246de6 rcb41a5e  
    4949#define NAME  "devmap"
    5050
     51/** Representation of device driver.
     52 *
     53 * Each driver is responsible for a set of devices.
     54 *
     55 */
     56typedef struct {
     57        /** Pointers to previous and next drivers in linked list */
     58        link_t drivers;
     59        /** Pointer to the linked list of devices controlled by this driver */
     60        link_t devices;
     61        /** Phone asociated with this driver */
     62        ipcarg_t phone;
     63        /** Device driver name */
     64        char *name;
     65        /** Futex for list of devices owned by this driver */
     66        atomic_t devices_futex;
     67} devmap_driver_t;
     68
     69/** Info about registered device
     70 *
     71 */
     72typedef struct {
     73        /** Pointer to the previous and next device in the list of all devices */
     74        link_t devices;
     75        /** Pointer to the previous and next device in the list of devices
     76            owned by one driver */
     77        link_t driver_devices;
     78        /** Unique device identifier  */
     79        dev_handle_t handle;
     80        /** Device name */
     81        char *name;
     82        /** Device driver handling this device */
     83        devmap_driver_t *driver;
     84} devmap_device_t;
     85
    5186/** Pending lookup structure. */
    5287typedef struct {
     
    71106static atomic_t create_handle_futex = FUTEX_INITIALIZER;
    72107
    73 static int devmap_create_handle(void)
    74 {
    75         static int last_handle = 0;
    76         int handle;
    77        
     108static dev_handle_t last_handle = 0;
     109
     110static dev_handle_t devmap_create_handle(void)
     111{
    78112        /* TODO: allow reusing old handles after their unregistration
    79113         * and implement some version of LRU algorithm
     
    82116        /* FIXME: overflow */
    83117        futex_down(&create_handle_futex);
    84        
    85         last_handle += 1;
    86         handle = last_handle;
    87        
     118        last_handle++;
    88119        futex_up(&create_handle_futex);
    89120       
    90         return handle;
    91 }
    92 
    93 
    94 /** Initialize device mapper.
    95  *
    96  *
    97  */
    98 static int devmap_init()
    99 {
    100         /* TODO: */
    101        
    102         return EOK;
     121        return last_handle;
    103122}
    104123
     
    130149 *
    131150 */
    132 static devmap_device_t *devmap_device_find_handle(int handle)
     151static devmap_device_t *devmap_device_find_handle(dev_handle_t handle)
    133152{
    134153        futex_down(&devices_list_futex);
     
    298317        futex_down(&drivers_list_futex);
    299318       
    300         ipc_hangup(driver->phone);
    301        
    302         /* remove it from list of drivers */
     319        if (driver->phone != 0)
     320                ipc_hangup(driver->phone);
     321       
     322        /* Remove it from list of drivers */
    303323        list_remove(&(driver->drivers));
    304324       
    305         /* unregister all its devices */
    306        
     325        /* Unregister all its devices */
    307326        futex_down(&devices_list_futex);
    308327        futex_down(&(driver->devices_futex));
     
    319338       
    320339        /* free name and driver */
    321         if (NULL != driver->name)
     340        if (driver->name != NULL)
    322341                free(driver->name);
    323342       
     
    455474         * Get handle from request
    456475         */
    457         int handle = IPC_GET_ARG2(*call);
     476        dev_handle_t handle = IPC_GET_ARG2(*call);
    458477        devmap_device_t *dev = devmap_device_find_handle(handle);
    459478       
    460         if (NULL == dev) {
     479        if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
    461480                ipc_answer_0(callid, ENOENT);
    462481                return;
    463482        }
    464483       
    465         ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle),
     484        ipc_forward_fast(callid, dev->driver->phone, dev->handle,
    466485            IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
    467486}
     
    496515         * Allocate buffer for device name.
    497516         */
    498         char *name = (char *) malloc(size);
     517        char *name = (char *) malloc(size + 1);
    499518        if (name == NULL) {
    500519                ipc_answer_0(callid, ENOMEM);
     
    550569 *
    551570 */
    552 static void devmap_get_name(ipc_callid_t iid, ipc_call_t *icall) 
     571static void devmap_get_name(ipc_callid_t iid, ipc_call_t *icall)
    553572{
    554573        const devmap_device_t *device = devmap_device_find_handle(IPC_GET_ARG1(*icall));
     
    578597       
    579598        /* TODO: send name in response */
     599}
     600
     601static void devmap_get_count(ipc_callid_t iid, ipc_call_t *icall)
     602{
     603        futex_down(&devices_list_futex);
     604        ipc_answer_1(iid, EOK, list_count(&devices_list));
     605        futex_up(&devices_list_futex);
     606}
     607
     608static void devmap_get_devices(ipc_callid_t iid, ipc_call_t *icall)
     609{
     610        futex_down(&devices_list_futex);
     611       
     612        ipc_callid_t callid;
     613        size_t size;
     614        if (!ipc_data_read_receive(&callid, &size)) {
     615                ipc_answer_0(callid, EREFUSED);
     616                ipc_answer_0(iid, EREFUSED);
     617                return;
     618        }
     619       
     620        if ((size % sizeof(dev_desc_t)) != 0) {
     621                ipc_answer_0(callid, EINVAL);
     622                ipc_answer_0(iid, EREFUSED);
     623                return;
     624        }
     625       
     626        count_t count = size / sizeof(dev_desc_t);
     627        dev_desc_t *desc = (dev_desc_t *) malloc(size);
     628        if (desc == NULL) {
     629                ipc_answer_0(callid, ENOMEM);
     630                ipc_answer_0(iid, EREFUSED);
     631                return;
     632        }
     633       
     634        count_t pos = 0;
     635        link_t *item = devices_list.next;
     636       
     637        while ((item != &devices_list) && (pos < count)) {
     638                devmap_device_t *device = list_get_instance(item, devmap_device_t, devices);
     639               
     640                desc[pos].handle = device->handle;
     641                str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, device->name);
     642                pos++;
     643                item = item->next;
     644        }
     645       
     646        ipcarg_t retval = ipc_data_read_finalize(callid, desc, pos * sizeof(dev_desc_t));
     647        if (retval != EOK) {
     648                ipc_answer_0(iid, EREFUSED);
     649                free(desc);
     650                return;
     651        }
     652       
     653        free(desc);
     654       
     655        futex_up(&devices_list_futex);
     656       
     657        ipc_answer_1(iid, EOK, pos);
     658}
     659
     660/** Initialize device mapper.
     661 *
     662 *
     663 */
     664static bool devmap_init()
     665{
     666        /* Create NULL device entry */
     667        devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t));
     668        if (device == NULL)
     669                return false;
     670       
     671        device->name = str_dup("null");
     672        if (device->name == NULL) {
     673                free(device);
     674                return false;
     675        }
     676       
     677        list_initialize(&(device->devices));
     678        list_initialize(&(device->driver_devices));
     679       
     680        futex_down(&devices_list_futex);
     681       
     682        /* Get unique device handle */
     683        device->handle = devmap_create_handle();
     684        device->driver = NULL;
     685       
     686        /* Insert device into list of all devices  */
     687        list_append(&device->devices, &devices_list);
     688       
     689        futex_up(&devices_list_futex);
     690       
     691        return true;
    580692}
    581693
     
    622734                        break;
    623735                case DEVMAP_DEVICE_GET_NAME:
    624                         devmap_get_handle(callid, &call);
     736                        devmap_get_name(callid, &call);
    625737                        break;
    626738                default:
     
    661773                        break;
    662774                case DEVMAP_DEVICE_GET_NAME:
    663                         /* TODO */
    664775                        devmap_get_name(callid, &call);
     776                        break;
     777                case DEVMAP_DEVICE_GET_COUNT:
     778                        devmap_get_count(callid, &call);
     779                        break;
     780                case DEVMAP_DEVICE_GET_DEVICES:
     781                        devmap_get_devices(callid, &call);
    665782                        break;
    666783                default:
     
    701818        printf(NAME ": HelenOS Device Mapper\n");
    702819       
    703         if (devmap_init() != 0) {
     820        if (!devmap_init()) {
    704821                printf(NAME ": Error while initializing service\n");
    705822                return -1;
  • uspace/srv/rd/rd.c

    r2246de6 rcb41a5e  
    113113        }
    114114       
    115         while (1) {
     115        while (true) {
    116116                callid = async_get_call(&call);
    117117                switch (IPC_GET_METHOD(call)) {
     
    205205        printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size);
    206206       
    207         int driver_phone = devmap_driver_register(NAME, rd_connection);
    208         if (driver_phone < 0) {
    209                 printf(NAME ": Unable to register driver\n");
     207        int rc = devmap_driver_register(NAME, rd_connection);
     208        if (rc < 0) {
     209                printf(NAME ": Unable to register driver (%d)\n", rc);
    210210                return false;
    211211        }
    212212       
    213213        dev_handle_t dev_handle;
    214         if (devmap_device_register(driver_phone, "initrd", &dev_handle) != EOK) {
    215                 ipc_hangup(driver_phone);
    216                 printf(NAME ": Unable to register device\n");
    217                 return false;
    218         }
    219 
    220         /*
    221          * Create the second device.
    222          * We need at least two devices for the sake of testing of non-root
    223          * mounts. Of course it would be better to allow the second device
    224          * be created dynamically...
    225          */
    226         if (devmap_device_register(driver_phone, "spared", &dev_handle) != EOK) {
    227                 ipc_hangup(driver_phone);
     214        if (devmap_device_register("initrd", &dev_handle) != EOK) {
     215                devmap_hangup_phone(DEVMAP_DRIVER);
    228216                printf(NAME ": Unable to register device\n");
    229217                return false;
     
    249237/**
    250238 * @}
    251  */ 
     239 */
Note: See TracChangeset for help on using the changeset viewer.