Changeset b61d47d in mainline


Ignore:
Timestamp:
2007-12-02T20:00:14Z (17 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
90c35436
Parents:
8df2eab
Message:

Function ipc_connect_me_to sends 3 user defined arguments now.
One argument added also to ipc_forward_fast.
Fixed devmap and improved its test.

Files:
15 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/ipc.h

    r8df2eab rb61d47d  
    139139 *                       indicating that it wants to be connected to some
    140140 *                       service
    141  *                     - arg1/2 are user specified, arg3 contains
     141 *                     - arg1/2/3 are user specified, arg5 contains
    142142 *                       address of the phone that should be connected
    143143 *                       (TODO: it leaks to userspace)
  • kernel/generic/include/ipc/sysipc.h

    r8df2eab rb61d47d  
    5353    int nonblocking);
    5454unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
    55     unative_t method, unative_t arg1, int mode);
     55    unative_t method, unative_t arg1, unative_t arg2, int mode);
    5656unative_t sys_ipc_hangup(int phoneid);
    5757unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
  • kernel/generic/src/ipc/sysipc.c

    r8df2eab rb61d47d  
    192192                /* If the users accepted call, connect */
    193193                if (!IPC_GET_RETVAL(answer->data)) {
    194                         ipc_phone_connect((phone_t *) IPC_GET_ARG3(*olddata),
     194                        ipc_phone_connect((phone_t *) IPC_GET_ARG5(*olddata),
    195195                            &TASK->answerbox);
    196196                }
     
    271271                        return ELIMIT;
    272272                /* Set arg3 for server */
    273                 IPC_SET_ARG3(call->data, (unative_t) &TASK->phones[newphid]);
     273                IPC_SET_ARG5(call->data, (unative_t) &TASK->phones[newphid]);
    274274                call->flags |= IPC_CALL_CONN_ME_TO;
    275275                call->priv = newphid;
     
    319319                        phone_dealloc(call->priv);
    320320                else
    321                         IPC_SET_ARG3(call->data, call->priv);
     321                        IPC_SET_ARG5(call->data, call->priv);
    322322        }
    323323}
     
    553553 */
    554554unative_t sys_ipc_forward_fast(unative_t callid, unative_t phoneid,
    555     unative_t method, unative_t arg1, int mode)
     555    unative_t method, unative_t arg1, unative_t arg2, int mode)
    556556{
    557557        call_t *call;
     
    578578        /*
    579579         * Userspace is not allowed to change method of system methods on
    580          * forward, allow changing ARG1 and ARG2 by means of method and arg1.
     580         * forward, allow changing ARG1, ARG2 and ARG3 by means of method,
     581         * arg1 and arg2.
    581582         * If the method is immutable, don't change anything.
    582583         */
     
    584585                if (method_is_system(IPC_GET_METHOD(call->data))) {
    585586                        if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME)
    586                                 phone_dealloc(IPC_GET_ARG3(call->data));
     587                                phone_dealloc(IPC_GET_ARG5(call->data));
    587588
    588589                        IPC_SET_ARG1(call->data, method);
    589590                        IPC_SET_ARG2(call->data, arg1);
     591                        IPC_SET_ARG3(call->data, arg2);
    590592                } else {
    591593                        IPC_SET_METHOD(call->data, method);
    592594                        IPC_SET_ARG1(call->data, arg1);
     595                        IPC_SET_ARG2(call->data, arg2);
    593596                }
    594597        }
  • uspace/app/tester/devmap/devmap1.c

    r8df2eab rb61d47d  
    3636#include "../tester.h"
    3737
     38#include <time.h>
     39
     40#define TEST_DEVICE1 "TestDevice1"
     41#define TEST_DEVICE2 "TestDevice2"
     42
     43/** Handle requests from clients
     44 *
     45 */
     46static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall)
     47{
     48        ipc_callid_t callid;
     49        ipc_call_t call;
     50        int retval;
     51       
     52        printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(*icall),
     53                IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), IPC_GET_ARG3(*icall));
     54
     55        printf("driver_client_connection.\n");
     56        ipc_answer_0(iid, EOK);
     57
     58        /* Ignore parameters, the connection is already opened */
     59        while (1) {
     60                callid = async_get_call(&call);
     61                retval = EOK;
     62                printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", IPC_GET_METHOD(call),
     63                        IPC_GET_ARG1(call), IPC_GET_ARG2(call), IPC_GET_ARG3(call));
     64                switch (IPC_GET_METHOD(call)) {
     65                case IPC_M_PHONE_HUNGUP:
     66                        /* TODO: Handle hangup */
     67                        return;
     68                default:
     69                        printf("Unknown device method %u.\n", IPC_GET_METHOD(call));
     70                        retval = ENOENT;
     71                }
     72                ipc_answer_0(callid, retval);
     73        }
     74        return;
     75}
     76
     77static int device_client_fibril(void *arg)
     78{
     79        int handle;
     80        int device_phone;
     81
     82        handle = (int)arg;
     83
     84        device_phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, \
     85                DEVMAP_CONNECT_TO_DEVICE, handle);
     86
     87        if (device_phone < 0) {
     88                printf("Failed to connect to devmap as client (handle = %u).\n",
     89                        handle);
     90                return -1;
     91        }
     92/*     
     93 *      device_phone = (int) IPC_GET_ARG3(answer);
     94 */
     95        printf("Connected to device.\n");
     96        ipc_call_sync_1_0(device_phone, 1024, 1025);
     97/*
     98 * ipc_hangup(device_phone);
     99 */
     100        ipc_hangup(device_phone);
     101
     102        return EOK;
     103}
     104
     105/** Communication test with device.
     106 * @param handle handle to tested instance.
     107 */
     108static int device_client(int handle)
     109{
     110/*      fid_t fid;
     111        ipc_call_t call;
     112        ipc_callid_t callid;
     113
     114        fid = fibril_create(device_client_fibril, (void *)handle);
     115        fibril_add_ready(fid);
     116
     117*/
     118        return EOK;
     119}
     120
     121/**
     122 *
     123 */
    38124static int driver_register(char *name)
    39125{
    40         int retval;
     126        ipcarg_t retval;
    41127        aid_t req;
    42128        ipc_call_t answer;
     
    44130        ipcarg_t callback_phonehash;
    45131
    46         phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER);
     132        phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
     133                DEVMAP_DRIVER, 0);
    47134
    48135        while (phone < 0) {
    49136                usleep(100000);
    50                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_DRIVER);
     137                phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP,
     138                        DEVMAP_DRIVER, 0);
    51139        }
    52140       
    53141        req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    54142
    55         retval = ipc_data_send(phone, (char *)name, strlen(name));
     143        retval = ipc_data_send(phone, (char *)name, strlen(name) + 1);
    56144
    57145        if (retval != EOK) {
     
    60148        }
    61149
     150        async_set_client_connection(driver_client_connection);
     151
    62152        ipc_connect_to_me(phone, 0, 0, &callback_phonehash);
    63 
    64         async_wait_for(req, NULL);
     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);
    65162        printf("Driver '%s' registered.\n", name);
    66163
     
    68165}
    69166
    70 static int device_register(int driver_phone, char *name, int *handle)
     167static int device_get_handle(int driver_phone, char *name, int *handle)
    71168{
    72169        ipcarg_t retval;
     
    74171        ipc_call_t answer;
    75172
     173        req = async_send_2(driver_phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0, &answer);
     174
     175        retval = ipc_data_send(driver_phone, name, strlen(name) + 1);
     176
     177        if (retval != EOK) {
     178                printf("Failed to send device name '%s'.\n", name);
     179                async_wait_for(req, NULL);
     180                return retval;
     181        }
     182
     183        async_wait_for(req, &retval);
     184
     185        if (NULL != handle) {
     186                *handle = -1;
     187        }
     188
     189        if (EOK == retval) {
     190               
     191                if (NULL != handle) {
     192                        *handle = (int) IPC_GET_ARG1(answer);
     193                }
     194                printf("Device '%s' has handle %u.\n", name, (int) IPC_GET_ARG1(answer));
     195        } else {
     196                printf("Failed to get handle for device '%s'.\n", name);
     197        }
     198
     199        return retval;
     200}
     201
     202/** Register new device.
     203 * @param driver_phone
     204 * @param name Device name.
     205 * @param handle Output variable. Handle to the created instance of device.
     206 */
     207static int device_register(int driver_phone, char *name, int *handle)
     208{
     209        ipcarg_t retval;
     210        aid_t req;
     211        ipc_call_t answer;
     212
    76213        req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
    77214
    78         retval = ipc_data_send(driver_phone, (char *)name, strlen(name));
     215        retval = ipc_data_send(driver_phone, (char *)name, strlen(name) + 1);
    79216
    80217        if (retval != EOK) {
     
    111248        int dev2_handle;
    112249        int dev3_handle;
     250        int handle;
    113251
    114252        /* Register new driver */
     
    120258
    121259        /* Register new device dev1*/
    122         if (EOK != device_register(driver_phone, "TestDevice1", &dev1_handle)) {
     260        if (EOK != device_register(driver_phone, TEST_DEVICE1, &dev1_handle)) {
    123261                ipc_hangup(driver_phone);
    124262                return "Error: cannot register device.\n";
    125263        }
    126        
    127         /* TODO: get handle for dev1*/
    128 
    129         /* TODO: get handle for dev2 (Should fail unless device is already
     264
     265        /* Get handle for dev2 (Should fail unless device is already
    130266         * registered by someone else)
    131267         */
     268        if (EOK == device_get_handle(driver_phone, TEST_DEVICE2, &handle)) {
     269                ipc_hangup(driver_phone);
     270                return "Error: got handle for dev2 before it was registered.\n";
     271        }
    132272
    133273        /* Register new device dev2*/
    134         if (EOK != device_register(driver_phone, "TestDevice2", &dev2_handle)) {
     274        if (EOK != device_register(driver_phone, TEST_DEVICE2, &dev2_handle)) {
    135275                ipc_hangup(driver_phone);
    136276                return "Error: cannot register device dev2.\n";
    137277        }
    138278
    139 
    140279        /* Register again device dev1 */
    141         if (EOK == device_register(driver_phone, "TestDevice1", &dev3_handle)) {
     280        if (EOK == device_register(driver_phone, TEST_DEVICE1, &dev3_handle)) {
    142281                return "Error: dev1 registered twice.\n";
    143282        }
    144283
    145         /* TODO: get handle for dev2 */
    146 
    147         /* TODO:  */
     284        /* Get handle for dev1*/
     285        if (EOK != device_get_handle(driver_phone, TEST_DEVICE1, &handle)) {
     286                ipc_hangup(driver_phone);
     287                return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
     288        }
     289
     290        if (handle != dev1_handle) {
     291                ipc_hangup(driver_phone);
     292                return "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n";
     293        }
     294
     295        if (EOK != device_client(dev1_handle)) {
     296                ipc_hangup(driver_phone);
     297                return "Error: failed client test for 'DEVMAP_DEVICE1'.\n";
     298        }
     299
     300        /* TODO: */
    148301
    149302        ipc_hangup(driver_phone);
  • uspace/app/tester/ipc/connect.c

    r8df2eab rb61d47d  
    4747       
    4848        printf("Connecting to %d..", svc);
    49         phid = ipc_connect_me_to(PHONE_NS, svc, 0);
     49        phid = ipc_connect_me_to(PHONE_NS, svc, 0, 0);
    5050        if (phid > 0) {
    5151                printf("phoneid: %d\n", phid);
  • uspace/lib/libc/generic/async.c

    r8df2eab rb61d47d  
    539539        case IPC_M_CONNECT_ME_TO:
    540540                /* Open new connection with fibril etc. */
    541                 async_new_connection(IPC_GET_ARG3(*call), callid, call,
     541                async_new_connection(IPC_GET_ARG5(*call), callid, call,
    542542                    client_connection);
    543543                return;
  • uspace/lib/libc/generic/io/stream.c

    r8df2eab rb61d47d  
    9797        if (console_phone < 0) {
    9898                while ((console_phone = ipc_connect_me_to(PHONE_NS,
    99                     SERVICE_CONSOLE, 0)) < 0) {
     99                    SERVICE_CONSOLE, 0, 0)) < 0) {
    100100                        usleep(10000);
    101101                }
     
    116116        if (console_phone < 0) {
    117117                while ((console_phone = ipc_connect_me_to(PHONE_NS,
    118                     SERVICE_CONSOLE, 0)) < 0) {
     118                    SERVICE_CONSOLE, 0, 0)) < 0) {
    119119                        usleep(10000);
    120120                }
  • uspace/lib/libc/generic/ipc.c

    r8df2eab rb61d47d  
    588588 * @param arg1          User defined argument.
    589589 * @param arg2          User defined argument.
     590 * @param arg3          User defined argument.
    590591 *
    591592 * @return              New phone handle on success or a negative error code.
    592593 */
    593 int ipc_connect_me_to(int phoneid, int arg1, int arg2)
     594int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3)
    594595{
    595596        ipcarg_t newphid;
    596597        int res;
    597598
    598         res = ipc_call_sync_2_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, NULL,
    599             NULL, &newphid);
     599        res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     600                NULL, NULL, NULL, NULL, &newphid);
    600601        if (res)
    601602                return res;
     
    647648 * @param method        New method for the forwarded call.
    648649 * @param arg1          New value of the first argument for the forwarded call.
     650 * @param arg2          New value of the second argument for the forwarded call.
    649651 * @param mode          Flags specifying mode of the forward operation.
    650652 *
     
    652654 *
    653655 * For non-system methods, the old method and arg1 are rewritten by the new
    654  * values. For system methods, the new method and arg1 are written to the old
    655  * arg1 and arg2, respectivelly. Calls with immutable methods are forwarded
    656  * verbatim.
     656 * values. For system methods, the new method, arg1 and arg2 are written
     657 * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable
     658 * methods are forwarded verbatim.
    657659 */
    658660int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method,
    659     ipcarg_t arg1, int mode)
    660 {
    661         return __SYSCALL5(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1,
    662             mode);
     661    ipcarg_t arg1, ipcarg_t arg2, int mode)
     662{
     663        return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1,
     664                arg2, mode);
    663665}
    664666
  • uspace/lib/libc/include/ipc/ipc.h

    r8df2eab rb61d47d  
    254254
    255255extern int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone);
    256 extern int ipc_connect_me_to(int phoneid, int arg1, int arg2);
     256extern int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3);
    257257extern int ipc_hangup(int phoneid);
    258258extern int ipc_register_irq(int inr, int devno, int method, irq_code_t *code);
    259259extern int ipc_unregister_irq(int inr, int devno);
    260260extern int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method,
    261     ipcarg_t arg1, int mode);
     261    ipcarg_t arg1, ipcarg_t arg2, int mode);
    262262extern int ipc_data_send(int phoneid, void *src, size_t size);
    263263extern int ipc_data_receive(ipc_callid_t *callid, void **dst, size_t *size);
  • uspace/srv/console/console.c

    r8df2eab rb61d47d  
    483483        /* Connect to keyboard driver */
    484484
    485         kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0);
     485        kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
    486486        while (kbd_phone < 0) {
    487487                usleep(10000);
    488                 kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0);
     488                kbd_phone = ipc_connect_me_to(PHONE_NS, SERVICE_KEYBOARD, 0, 0);
    489489        }
    490490       
     
    495495        /* Connect to framebuffer driver */
    496496       
    497         fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0);
     497        fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0);
    498498        while (fb_info.phone < 0) {
    499499                usleep(10000);
    500                 fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0);
     500                fb_info.phone = ipc_connect_me_to(PHONE_NS, SERVICE_VIDEO, 0, 0);
    501501        }
    502502       
  • uspace/srv/devmap/devmap.c

    r8df2eab rb61d47d  
    449449 * Find device driver owning requested device and forward
    450450 * the message to it.
    451  *
    452  *
    453451 */
    454452static void devmap_forward(ipc_callid_t callid, ipc_call_t *call)
     
    460458         * Get handle from request
    461459         */
    462         handle = IPC_GET_ARG1(*call);
     460        handle = IPC_GET_ARG2(*call);
    463461        dev = devmap_device_find_handle(handle);
    464462
     
    470468        }
    471469
    472         /* FIXME: is this correct method how to pass argument on forwarding ?*/
    473470        ipc_forward_fast(callid, dev->driver->phone, (ipcarg_t)(dev->handle),
    474             0, IPC_FF_NONE);
     471            IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
    475472        return;
    476473}
     
    670667                        continue; /* Exit thread */
    671668
    672                 case DEVMAP_DEVICE_CONNECT_ME_TO:
    673                         /* Connect client to selected device */
    674                         printf("DEVMAP: connect to device %d.\n",
    675                             IPC_GET_ARG1(call));
    676                         devmap_forward(callid, &call);
    677                         break;
    678 
    679669                case DEVMAP_DEVICE_GET_HANDLE:
    680670                        devmap_get_handle(callid, &call);
     
    710700                devmap_connection_client(iid, icall);
    711701                break;
     702        case DEVMAP_CONNECT_TO_DEVICE:
     703                        /* Connect client to selected device */
     704                printf("DEVMAP: connect to device %d.\n",
     705                    IPC_GET_ARG2(*icall));
     706                devmap_forward(iid, icall);
     707                break;
    712708        default:
    713709                ipc_answer_0(iid, ENOENT); /* No such interface */
  • uspace/srv/devmap/devmap.h

    r8df2eab rb61d47d  
    4242        DEVMAP_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
    4343        DEVMAP_DRIVER_UNREGISTER,
    44         DEVMAP_DEVICE_CONNECT_ME_TO,
    4544        DEVMAP_DEVICE_REGISTER,
    4645        DEVMAP_DEVICE_UNREGISTER,
     
    8382} devmap_device_t;
    8483
    85 /** Interface provided by DevMap.
    86  *
     84/** Interface provided by devmap.
     85 * Every process that connects to devmap must ask one of following
     86 * interfaces otherwise connection will be refused.
    8787 */
    8888typedef enum {
    89         DEVMAP_DRIVER = 1,
    90         DEVMAP_CLIENT
     89                /** Connect as device driver */
     90        DEVMAP_DRIVER = 1,     
     91                /** Connect as client */
     92        DEVMAP_CLIENT,
     93                /** Create new connection to instance of device that
     94                 * is specified by second argument of call. */
     95        DEVMAP_CONNECT_TO_DEVICE
    9196} devmap_interface_t;
    9297
  • uspace/srv/fs/fat/fat.c

    r8df2eab rb61d47d  
    127127        printf("FAT: HelenOS FAT file system server.\n");
    128128
    129         vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0);
     129        vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0);
    130130        while (vfs_phone < EOK) {
    131131                usleep(10000);
    132                 vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0);
     132                vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0);
    133133        }
    134134       
  • uspace/srv/ns/ns.c

    r8df2eab rb61d47d  
    213213        }
    214214        hs = hash_table_get_instance(hlp, hashed_service_t, link);
    215         return ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call), 0,
    216             IPC_FF_NONE);
     215        return ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call),
     216                IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
    217217}
    218218
  • uspace/srv/vfs/vfs_read.c

    r8df2eab rb61d47d  
    9797         */
    9898        ipc_forward_fast(callid, fs_phone, IPC_GET_METHOD(call),
    99             IPC_GET_ARG1(call), IPC_FF_ROUTE_FROM_ME);
     99            IPC_GET_ARG1(call), 0, IPC_FF_ROUTE_FROM_ME);
    100100
    101101        vfs_release_phone(fs_phone);
Note: See TracChangeset for help on using the changeset viewer.