Changeset 1090b8c in mainline


Ignore:
Timestamp:
2009-05-18T19:45:17Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c00589d
Parents:
c5747fe
Message:

C binding for devmap. Gets rid of duplicate code.

Location:
uspace
Files:
2 added
8 edited

Legend:

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

    rc5747fe r1090b8c  
    3333#include <async.h>
    3434#include <errno.h>
    35 #include <ipc/devmap.h>
     35#include <devmap.h>
    3636#include "../tester.h"
    3737
     
    8585        handle = (int)arg;
    8686
    87         device_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
    88             DEVMAP_CONNECT_TO_DEVICE, handle);
    89 
     87        device_phone = devmap_device_connect(handle, 0);
    9088        if (device_phone < 0) {
    91                 printf("Failed to connect to devmap as client (handle = %u).\n",
     89                printf("Failed to connect to device (handle = %u).\n",
    9290                    handle);
    9391                return -1;
    9492        }
    95 /*     
    96  *      device_phone = (int) IPC_GET_ARG5(answer);
    97  */
     93
    9894        printf("Connected to device.\n");
    99         ipc_call_sync_1_0(device_phone, 1024, 1025);
    100 /*
    101  * ipc_hangup(device_phone);
    102  */
    10395        ipc_hangup(device_phone);
    10496
     
    120112*/
    121113        return EOK;
    122 }
    123 
    124 /**
    125  *
    126  */
    127 static int driver_register(char *name)
    128 {
    129         ipcarg_t retval;
    130         aid_t req;
    131         ipc_call_t answer;
    132         int phone;
    133         ipcarg_t callback_phonehash;
    134 
    135         phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
    136         if (phone < 0) {
    137                 printf("Failed to connect to device mapper\n");
    138                 return -1;
    139         }
    140        
    141         req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    142 
    143         retval = ipc_data_write_start(phone, (char *)name, str_size(name) + 1);
    144 
    145         if (retval != EOK) {
    146                 async_wait_for(req, NULL);
    147                 return -1;
    148         }
    149 
    150         async_set_client_connection(driver_client_connection);
    151 
    152         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    153 /*     
    154         if (NULL == async_new_connection(callback_phonehash, 0, NULL,
    155                         driver_client_connection)) {
    156                 printf("Failed to create new fibril.\n");       
    157                 async_wait_for(req, NULL);
    158                 return -1;
    159         }
    160 */
    161         async_wait_for(req, &retval);
    162         printf("Driver '%s' registered.\n", name);
    163 
    164         return phone;
    165 }
    166 
    167 static int device_get_handle(int driver_phone, char *name, int *handle)
    168 {
    169         ipcarg_t retval;
    170         aid_t req;
    171         ipc_call_t answer;
    172 
    173         req = async_send_2(driver_phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0,
    174             &answer);
    175 
    176         retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1);
    177 
    178         if (retval != EOK) {
    179                 printf("Failed to send device name '%s'.\n", name);
    180                 async_wait_for(req, NULL);
    181                 return retval;
    182         }
    183 
    184         async_wait_for(req, &retval);
    185 
    186         if (NULL != handle) {
    187                 *handle = -1;
    188         }
    189 
    190         if (EOK == retval) {
    191                
    192                 if (NULL != handle) {
    193                         *handle = (int) IPC_GET_ARG1(answer);
    194                 }
    195                 printf("Device '%s' has handle %u.\n", name,
    196                     (int) IPC_GET_ARG1(answer));
    197         } else {
    198                 printf("Failed to get handle for device '%s'.\n", name);
    199         }
    200 
    201         return retval;
    202 }
    203 
    204 /** Register new device.
    205  * @param driver_phone
    206  * @param name Device name.
    207  * @param handle Output variable. Handle to the created instance of device.
    208  */
    209 static int device_register(int driver_phone, char *name, int *handle)
    210 {
    211         ipcarg_t retval;
    212         aid_t req;
    213         ipc_call_t answer;
    214 
    215         req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
    216 
    217         retval = ipc_data_write_start(driver_phone, (char *)name,
    218             str_size(name) + 1);
    219 
    220         if (retval != EOK) {
    221                 printf("Failed to send device name '%s'.\n", name);
    222                 async_wait_for(req, NULL);
    223                 return retval;
    224         }
    225 
    226         async_wait_for(req, &retval);
    227 
    228         if (NULL != handle) {
    229                 *handle = -1;
    230         }
    231 
    232         if (EOK == retval) {
    233                
    234                 if (NULL != handle) {
    235                         *handle = (int) IPC_GET_ARG1(answer);
    236                 }
    237                 printf("Device registered with handle %u.\n",
    238                     (int) IPC_GET_ARG1(answer));
    239         }
    240 
    241         return retval;
    242114}
    243115
     
    253125        int dev3_handle;
    254126        int handle;
     127        int rc;
    255128
    256129        /* Register new driver */
    257         driver_phone = driver_register("TestDriver");
     130        driver_phone = devmap_driver_register("TestDriver",
     131            driver_client_connection);
    258132
    259133        if (driver_phone < 0) {
     
    261135        }
    262136
    263         /* Register new device dev1*/
    264         if (EOK != device_register(driver_phone, TEST_DEVICE1, &dev1_handle)) {
     137        /* Register new device dev1. */
     138        rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev1_handle);
     139        if (rc != EOK) {
    265140                ipc_hangup(driver_phone);
    266141                return "Error: cannot register device.\n";
    267142        }
    268143
    269         /* Get handle for dev2 (Should fail unless device is already
    270          * registered by someone else)
     144        /*
     145         * Get handle for dev2 (Should fail unless device is already registered
     146         * by someone else).
    271147         */
    272         if (EOK == device_get_handle(driver_phone, TEST_DEVICE2, &handle)) {
     148        rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0);
     149        if (rc == EOK) {
    273150                ipc_hangup(driver_phone);
    274151                return "Error: got handle for dev2 before it was registered.\n";
    275152        }
    276153
    277         /* Register new device dev2*/
    278         if (EOK != device_register(driver_phone, TEST_DEVICE2, &dev2_handle)) {
     154        /* Register new device dev2. */
     155        rc = devmap_device_register(driver_phone, TEST_DEVICE2, &dev2_handle);
     156        if (rc != EOK) {
    279157                ipc_hangup(driver_phone);
    280158                return "Error: cannot register device dev2.\n";
    281159        }
    282160
    283         /* Register again device dev1 */
    284         if (EOK == device_register(driver_phone, TEST_DEVICE1, &dev3_handle)) {
     161        /* Register device dev1 again. */
     162        rc = devmap_device_register(driver_phone, TEST_DEVICE1, &dev3_handle);
     163        if (rc == EOK) {
    285164                return "Error: dev1 registered twice.\n";
    286165        }
    287166
    288         /* Get handle for dev1*/
    289         if (EOK != device_get_handle(driver_phone, TEST_DEVICE1, &handle)) {
     167        /* Get handle for dev1. */
     168        rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0);
     169        if (rc != EOK) {
    290170                ipc_hangup(driver_phone);
    291171                return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
     
    297177        }
    298178
    299         if (EOK != device_client(dev1_handle)) {
     179        if (device_client(dev1_handle) != EOK) {
    300180                ipc_hangup(driver_phone);
    301181                return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
  • uspace/lib/libblock/libblock.c

    rc5747fe r1090b8c  
    147147                return ENOMEM;
    148148        }
    149         dev_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP,
    150             DEVMAP_CONNECT_TO_DEVICE, dev_handle);
    151 
     149
     150        dev_phone = devmap_device_connect(dev_handle, IPC_FLAG_BLOCKING);
    152151        if (dev_phone < 0) {
    153152                munmap(com_area, com_size);
  • uspace/lib/libc/Makefile

    rc5747fe r1090b8c  
    4848        generic/cap.c \
    4949        generic/console.c \
     50        generic/devmap.c \
    5051        generic/event.c \
    5152        generic/mem.c \
  • uspace/lib/libc/generic/vfs/vfs.c

    rc5747fe r1090b8c  
    4949#include <errno.h>
    5050#include <string.h>
    51 #include <ipc/devmap.h>
     51#include <devmap.h>
    5252#include "../../../srv/vfs/vfs.h"
    5353
     
    116116}
    117117
    118 static int device_get_handle(const char *name, dev_handle_t *handle,
    119     const unsigned int flags)
    120 {
    121         int phone;
    122        
    123         if (flags & IPC_FLAG_BLOCKING)
    124                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
    125         else
    126                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
    127        
    128         if (phone < 0)
    129                 return phone;
    130        
    131         ipc_call_t answer;
    132         aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0,
    133             &answer);
    134        
    135         ipcarg_t retval = ipc_data_write_start(phone, name, str_size(name) + 1);
    136        
    137         if (retval != EOK) {
    138                 async_wait_for(req, NULL);
    139                 ipc_hangup(phone);
    140                 return retval;
    141         }
    142        
    143         async_wait_for(req, &retval);
    144        
    145         if (handle != NULL)
    146                 *handle = -1;
    147        
    148         if (retval == EOK) {
    149                 if (handle != NULL)
    150                         *handle = (dev_handle_t) IPC_GET_ARG1(answer);
    151         }
    152        
    153         ipc_hangup(phone);
    154         return retval;
    155 }
    156 
    157118int mount(const char *fs_name, const char *mp, const char *dev,
    158     const char *opts, const unsigned int flags)
     119    const char *opts, unsigned int flags)
    159120{
    160121        int res;
     
    163124        dev_handle_t dev_handle;
    164125       
    165         res = device_get_handle(dev, &dev_handle, flags);
     126        res = devmap_device_get_handle(dev, &dev_handle, flags);
    166127        if (res != EOK)
    167128                return res;
  • uspace/lib/libc/include/ipc/devmap.h

    rc5747fe r1090b8c  
    3434#define DEVMAP_DEVMAP_H_
    3535
     36#include <atomic.h>
    3637#include <ipc/ipc.h>
    3738#include <libadt/list.h>
  • uspace/lib/libc/include/vfs/vfs.h

    rc5747fe r1090b8c  
    4141
    4242extern int mount(const char *, const char *, const char *, const char *,
    43     const unsigned int flags);
     43    unsigned int flags);
    4444
    4545#endif
  • uspace/srv/rd/rd.c

    rc5747fe r1090b8c  
    5353#include <futex.h>
    5454#include <stdio.h>
    55 #include <ipc/devmap.h>
     55#include <devmap.h>
    5656#include <ipc/bd.h>
    5757
     
    181181}
    182182
    183 static int driver_register(char *name)
    184 {
    185         ipcarg_t retval;
    186         aid_t req;
    187         ipc_call_t answer;
    188         int phone;
    189         ipcarg_t callback_phonehash;
    190 
    191         phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER, 0);
    192         if (phone < 0) {
    193                 printf(NAME ": Failed to connect to device mapper\n");
    194                 return -1;
    195         }
    196        
    197         req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    198 
    199         retval = ipc_data_write_start(phone, (char *) name, str_size(name) + 1);
    200 
    201         if (retval != EOK) {
    202                 async_wait_for(req, NULL);
    203                 return -1;
    204         }
    205 
    206         async_set_client_connection(rd_connection);
    207 
    208         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
    209         async_wait_for(req, &retval);
    210 
    211         return phone;
    212 }
    213 
    214 static int device_register(int driver_phone, char *name, int *handle)
    215 {
    216         ipcarg_t retval;
    217         aid_t req;
    218         ipc_call_t answer;
    219 
    220         req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
    221 
    222         retval = ipc_data_write_start(driver_phone, (char *) name,
    223             str_size(name) + 1);
    224 
    225         if (retval != EOK) {
    226                 async_wait_for(req, NULL);
    227                 return retval;
    228         }
    229 
    230         async_wait_for(req, &retval);
    231 
    232         if (handle != NULL)
    233                 *handle = -1;
    234        
    235         if (EOK == retval) {
    236                 if (NULL != handle)
    237                         *handle = (int) IPC_GET_ARG1(answer);
    238         }
    239        
    240         return retval;
    241 }
    242 
    243183/** Prepare the ramdisk image for operation. */
    244184static bool rd_init(void)
     
    265205        printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size);
    266206       
    267         int driver_phone = driver_register(NAME);
     207        int driver_phone = devmap_driver_register(NAME, rd_connection);
    268208        if (driver_phone < 0) {
    269209                printf(NAME ": Unable to register driver\n");
     
    272212       
    273213        int dev_handle;
    274         if (EOK != device_register(driver_phone, "initrd", &dev_handle)) {
     214        if (devmap_device_register(driver_phone, "initrd", &dev_handle) != EOK) {
    275215                ipc_hangup(driver_phone);
    276216                printf(NAME ": Unable to register device\n");
     
    284224         * be created dynamically...
    285225         */
    286         if (EOK != device_register(driver_phone, "spared", &dev_handle)) {
     226        if (devmap_device_register(driver_phone, "spared", &dev_handle) != EOK) {
    287227                ipc_hangup(driver_phone);
    288228                printf(NAME ": Unable to register device\n");
  • uspace/srv/vfs/vfs.h

    rc5747fe r1090b8c  
    3939#include <rwlock.h>
    4040#include <sys/types.h>
     41#include <devmap.h>
    4142#include <bool.h>
    4243
     
    5051/* Basic types. */
    5152typedef int16_t fs_handle_t;
    52 typedef int16_t dev_handle_t;
    5353typedef uint32_t fs_index_t;
    5454
Note: See TracChangeset for help on using the changeset viewer.