Changeset db6e419 in mainline for uspace/srv/hid/input


Ignore:
Timestamp:
2011-08-16T18:53:00Z (14 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
49160c4
Parents:
e0e922d (diff), 45058baa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/srv/hid/input
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/ctl/kbdev.c

    re0e922d rdb6e419  
    4848#include <kbd_ctl.h>
    4949#include <kbd_port.h>
     50#include <loc.h>
    5051#include <stdlib.h>
    5152#include <vfs/vfs_sess.h>
    52 
     53#include <sys/typefmt.h>
    5354
    5455static int kbdev_ctl_init(kbd_dev_t *);
     
    7071        /** Session with kbdev device */
    7172        async_sess_t *sess;
    72 
    73         /** File descriptor of open kbdev device */
    74         int fd;
    7573} kbdev_t;
    7674
     
    8482
    8583        kbdev->kbd_dev = kdev;
    86         kbdev->fd = -1;
    8784
    8885        return kbdev;
     
    9390        if (kbdev->sess != NULL)
    9491                async_hangup(kbdev->sess);
    95         if (kbdev->fd >= 0)
    96                 close(kbdev->fd);
    9792        free(kbdev);
    9893}
     
    10095static int kbdev_ctl_init(kbd_dev_t *kdev)
    10196{
    102         const char *pathname;
    10397        async_sess_t *sess;
    10498        async_exch_t *exch;
    10599        kbdev_t *kbdev;
    106         int fd;
    107100        int rc;
    108101
    109         pathname = kdev->dev_path;
    110 
    111         fd = open(pathname, O_RDWR);
    112         if (fd < 0) {
    113                 return -1;
    114         }
    115 
    116         sess = fd_session(EXCHANGE_SERIALIZE, fd);
     102        sess = loc_service_connect(EXCHANGE_SERIALIZE, kdev->svc_id, 0);
    117103        if (sess == NULL) {
    118                 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
    119                 close(fd);
     104                printf("%s: Failed starting session with '%s.'\n", NAME,
     105                    kdev->svc_name);
    120106                return -1;
    121107        }
     
    124110        if (kbdev == NULL) {
    125111                printf("%s: Failed allocating device structure for '%s'.\n",
    126                     NAME, pathname);
     112                    NAME, kdev->svc_name);
    127113                return -1;
    128114        }
    129115
    130         kbdev->fd = fd;
    131116        kbdev->sess = sess;
    132117
    133118        exch = async_exchange_begin(sess);
    134119        if (exch == NULL) {
    135                 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     120                printf("%s: Failed starting exchange with '%s'.\n", NAME,
     121                    kdev->svc_name);
    136122                kbdev_destroy(kbdev);
    137123                return -1;
     
    141127        if (rc != EOK) {
    142128                printf("%s: Failed creating callback connection from '%s'.\n",
    143                     NAME, pathname);
     129                    NAME, kdev->svc_name);
    144130                async_exchange_end(exch);
    145131                kbdev_destroy(kbdev);
  • uspace/srv/hid/input/generic/input.c

    re0e922d rdb6e419  
    3838
    3939#include <adt/list.h>
     40#include <bool.h>
    4041#include <ipc/services.h>
    4142#include <ipc/input.h>
     
    5354#include <io/console.h>
    5455#include <io/keycode.h>
    55 #include <devmap.h>
     56#include <loc.h>
    5657#include <input.h>
    5758#include <kbd.h>
     
    6364
    6465// FIXME: remove this header
    65 #include <kernel/ipc/ipc_methods.h>
     66#include <abi/ipc/methods.h>
    6667
    6768/* In microseconds */
     
    275276        kdev->port_ops = port;
    276277        kdev->ctl_ops = ctl;
    277         kdev->dev_path = NULL;
     278        kdev->svc_id = 0;
    278279       
    279280        /* Initialize port driver. */
     
    303304        mdev->port_ops = port;
    304305        mdev->proto_ops = proto;
    305         mdev->dev_path = NULL;
     306        mdev->svc_id = 0;
    306307       
    307308        /* Initialize port driver. */
     
    324325/** Add new kbdev device.
    325326 *
    326  * @param dev_path Filesystem path to the device (/dev/class/...)
     327 * @param service_id    Service ID of the keyboard device
    327328 *
    328329 */
    329 static int kbd_add_kbdev(const char *dev_path)
     330static int kbd_add_kbdev(service_id_t service_id, kbd_dev_t **kdevp)
    330331{
    331332        kbd_dev_t *kdev = kbd_dev_new();
     
    333334                return -1;
    334335       
    335         kdev->dev_path = dev_path;
     336        kdev->svc_id = service_id;
    336337        kdev->port_ops = NULL;
    337338        kdev->ctl_ops = &kbdev_ctl;
    338339       
     340        int rc = loc_service_get_name(service_id, &kdev->svc_name);
     341        if (rc != EOK) {
     342                kdev->svc_name = NULL;
     343                goto fail;
     344        }
     345       
    339346        /* Initialize controller driver. */
    340347        if ((*kdev->ctl_ops->init)(kdev) != 0) {
     
    343350       
    344351        list_append(&kdev->kbd_devs, &kbd_devs);
     352        *kdevp = kdev;
    345353        return EOK;
    346354       
    347355fail:
     356        if (kdev->svc_name != NULL)
     357                free(kdev->svc_name);
    348358        free(kdev);
    349359        return -1;
     
    352362/** Add new mousedev device.
    353363 *
    354  * @param dev_path Filesystem path to the device (/dev/class/...)
     364 * @param service_id    Service ID of the mouse device
    355365 *
    356366 */
    357 static int mouse_add_mousedev(const char *dev_path)
     367static int mouse_add_mousedev(service_id_t service_id, mouse_dev_t **mdevp)
    358368{
    359369        mouse_dev_t *mdev = mouse_dev_new();
     
    361371                return -1;
    362372       
    363         mdev->dev_path = dev_path;
     373        mdev->svc_id = service_id;
    364374        mdev->port_ops = NULL;
    365375        mdev->proto_ops = &mousedev_proto;
    366376       
     377        int rc = loc_service_get_name(service_id, &mdev->svc_name);
     378        if (rc != EOK) {
     379                mdev->svc_name = NULL;
     380                goto fail;
     381        }
     382       
    367383        /* Initialize controller driver. */
    368384        if ((*mdev->proto_ops->init)(mdev) != 0) {
     
    371387       
    372388        list_append(&mdev->mouse_devs, &mouse_devs);
     389        *mdevp = mdev;
    373390        return EOK;
    374391       
     
    482499/** Periodically check for new input devices.
    483500 *
    484  * Looks under /dev/class/keyboard and /dev/class/mouse.
     501 * Looks under /loc/class/keyboard and /loc/class/mouse.
    485502 *
    486503 * @param arg Ignored
     
    489506static int dev_discovery_fibril(void *arg)
    490507{
    491         char *dev_path;
    492         size_t kbd_id = 1;
    493         size_t mouse_id = 1;
     508        category_id_t keyboard_cat, mouse_cat;
     509        service_id_t *svcs;
     510        size_t count, i;
     511        bool already_known;
    494512        int rc;
     513       
     514        rc = loc_category_get_id("keyboard", &keyboard_cat, IPC_FLAG_BLOCKING);
     515        if (rc != EOK) {
     516                printf("%s: Failed resolving category 'keyboard'.\n", NAME);
     517                return ENOENT;
     518        }
     519       
     520        rc = loc_category_get_id("mouse", &mouse_cat, IPC_FLAG_BLOCKING);
     521        if (rc != EOK) {
     522                printf("%s: Failed resolving category 'mouse'.\n", NAME);
     523                return ENOENT;
     524        }
    495525       
    496526        while (true) {
     
    498528               
    499529                /*
    500                  * Check for new keyboard device
     530                 * Check for new keyboard devices
    501531                 */
    502                 rc = asprintf(&dev_path, "/dev/class/keyboard\\%zu", kbd_id);
    503                 if (rc < 0)
     532                rc = loc_category_get_svcs(keyboard_cat, &svcs, &count);
     533                if (rc != EOK) {
     534                        printf("%s: Failed getting list of keyboard devices.\n",
     535                            NAME);
    504536                        continue;
    505                
    506                 if (kbd_add_kbdev(dev_path) == EOK) {
    507                         printf("%s: Connected keyboard device '%s'\n",
    508                             NAME, dev_path);
     537                }
     538
     539                for (i = 0; i < count; i++) {
     540                        already_known = false;
    509541                       
    510                         /* XXX Handle device removal */
    511                         ++kbd_id;
     542                        /* Determine whether we already know this device. */
     543                        list_foreach(kbd_devs, kdev_link) {
     544                                kbd_dev_t *kdev = list_get_instance(kdev_link,
     545                                    kbd_dev_t, kbd_devs);
     546                                if (kdev->svc_id == svcs[i]) {
     547                                        already_known = true;
     548                                        break;
     549                                }
     550                        }
     551
     552                        if (!already_known) {
     553                                kbd_dev_t *kdev;
     554                                if (kbd_add_kbdev(svcs[i], &kdev) == EOK) {
     555                                        printf("%s: Connected keyboard device '%s'\n",
     556                                            NAME, kdev->svc_name);
     557                                }
     558                        }
    512559                }
    513560               
    514                 free(dev_path);
     561                /* XXX Handle device removal */
    515562               
    516563                /*
    517                  * Check for new mouse device
     564                 * Check for new mouse devices
    518565                 */
    519                 rc = asprintf(&dev_path, "/dev/class/mouse\\%zu", mouse_id);
    520                 if (rc < 0)
     566                rc = loc_category_get_svcs(mouse_cat, &svcs, &count);
     567                if (rc != EOK) {
     568                        printf("%s: Failed getting list of mouse devices.\n",
     569                            NAME);
    521570                        continue;
    522                
    523                 if (mouse_add_mousedev(dev_path) == EOK) {
    524                         printf("%s: Connected mouse device '%s'\n",
    525                             NAME, dev_path);
     571                }
     572
     573                for (i = 0; i < count; i++) {
     574                        already_known = false;
    526575                       
    527                         /* XXX Handle device removal */
    528                         ++mouse_id;
     576                        /* Determine whether we already know this device. */
     577                        list_foreach(mouse_devs, mdev_link) {
     578                                mouse_dev_t *mdev = list_get_instance(mdev_link,
     579                                    mouse_dev_t, mouse_devs);
     580                                if (mdev->svc_id == svcs[i]) {
     581                                        already_known = true;
     582                                        break;
     583                                }
     584                        }
     585
     586                        if (!already_known) {
     587                                mouse_dev_t *mdev;
     588                                if (mouse_add_mousedev(svcs[i], &mdev) == EOK) {
     589                                        printf("%s: Connected mouse device '%s'\n",
     590                                            NAME, mdev->svc_name);
     591                                }
     592                        }
    529593                }
    530594               
    531                 free(dev_path);
     595                /* XXX Handle device removal */
    532596        }
    533597       
     
    572636       
    573637        /* Register driver */
    574         int rc = devmap_driver_register(NAME, client_connection);
     638        int rc = loc_server_register(NAME, client_connection);
    575639        if (rc < 0) {
    576                 printf("%s: Unable to register driver (%d)\n", NAME, rc);
     640                printf("%s: Unable to register server (%d)\n", NAME, rc);
    577641                return -1;
    578642        }
    579643       
    580         char kbd[DEVMAP_NAME_MAXLEN + 1];
    581         snprintf(kbd, DEVMAP_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
    582        
    583         devmap_handle_t devmap_handle;
    584         if (devmap_device_register(kbd, &devmap_handle) != EOK) {
    585                 printf("%s: Unable to register device %s\n", NAME, kbd);
     644        char kbd[LOC_NAME_MAXLEN + 1];
     645        snprintf(kbd, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME);
     646       
     647        service_id_t service_id;
     648        if (loc_service_register(kbd, &service_id) != EOK) {
     649                printf("%s: Unable to register service %s\n", NAME, kbd);
    586650                return -1;
    587651        }
  • uspace/srv/hid/input/include/kbd.h

    re0e922d rdb6e419  
    4040
    4141#include <adt/list.h>
     42#include <ipc/loc.h>
    4243
    4344struct kbd_port_ops;
     
    4950        link_t kbd_devs;
    5051
    51         /** Path to the device (only for kbdev devices) */
    52         const char *dev_path;
     52        /** Service ID (only for kbdev devices) */
     53        service_id_t svc_id;
     54
     55        /** Device service name (only for kbdev devices) */
     56        char *svc_name;
    5357
    5458        /** Port ops */
  • uspace/srv/hid/input/include/mouse.h

    re0e922d rdb6e419  
    3939
    4040#include <adt/list.h>
     41#include <ipc/loc.h>
    4142
    4243struct mouse_port_ops;
     
    4748        link_t mouse_devs;
    4849       
    49         /** Path to the device (only for mouseev devices) */
    50         const char *dev_path;
     50        /** Service ID (only for mousedev devices) */
     51        service_id_t svc_id;
     52       
     53        /** Device service name (only for mousedev devices) */
     54        char *svc_name;
    5155       
    5256        /** Port ops */
  • uspace/srv/hid/input/port/adb.c

    re0e922d rdb6e419  
    4343#include <fcntl.h>
    4444#include <errno.h>
    45 #include <devmap.h>
     45#include <loc.h>
    4646
    4747static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    6666{
    6767        const char *dev = "adb/kbd";
    68         devmap_handle_t handle;
     68        service_id_t service_id;
    6969        async_exch_t *exch;
    7070        int rc;
     
    7272        kbd_dev = kdev;
    7373       
    74         rc = devmap_device_get_handle(dev, &handle, 0);
     74        rc = loc_service_get_id(dev, &service_id, 0);
    7575        if (rc != EOK)
    7676                return rc;
    7777       
    78         dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
     78        dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id, 0);
    7979        if (dev_sess == NULL) {
    8080                printf("%s: Failed to connect to device\n", NAME);
  • uspace/srv/hid/input/port/adb_mouse.c

    re0e922d rdb6e419  
    4141#include <mouse.h>
    4242#include <errno.h>
    43 #include <devmap.h>
     43#include <loc.h>
    4444
    4545static mouse_dev_t *mouse_dev;
     
    7878        mouse_dev = mdev;
    7979       
    80         devmap_handle_t handle;
    81         int rc = devmap_device_get_handle(dev, &handle, 0);
     80        service_id_t service_id;
     81        int rc = loc_service_get_id(dev, &service_id, 0);
    8282        if (rc != EOK)
    8383                return rc;
    8484       
    85         dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
     85        dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id, 0);
    8686        if (dev_sess == NULL) {
    8787                printf("%s: Failed to connect to device\n", NAME);
  • uspace/srv/hid/input/port/chardev.c

    re0e922d rdb6e419  
    4040#include <kbd_port.h>
    4141#include <kbd.h>
    42 #include <devmap.h>
     42#include <loc.h>
    4343#include <errno.h>
    4444#include <stdio.h>
     
    7171static int chardev_port_init(kbd_dev_t *kdev)
    7272{
    73         devmap_handle_t handle;
     73        service_id_t service_id;
    7474        async_exch_t *exch;
    7575        unsigned int i;
     
    7979       
    8080        for (i = 0; i < num_devs; i++) {
    81                 rc = devmap_device_get_handle(in_devs[i], &handle, 0);
     81                rc = loc_service_get_id(in_devs[i], &service_id, 0);
    8282                if (rc == EOK)
    8383                        break;
     
    8989        }
    9090       
    91         dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
     91        dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id,
    9292            IPC_FLAG_BLOCKING);
    9393        if (dev_sess == NULL) {
  • uspace/srv/hid/input/port/chardev_mouse.c

    re0e922d rdb6e419  
    3939#include <async.h>
    4040#include <errno.h>
    41 #include <devmap.h>
     41#include <loc.h>
    4242#include <input.h>
    4343#include <mouse_port.h>
     
    8282static int chardev_port_init(mouse_dev_t *mdev)
    8383{
    84         devmap_handle_t handle;
     84        service_id_t service_id;
    8585        unsigned int i;
    8686        int rc;
     
    8989       
    9090        for (i = 0; i < num_devs; i++) {
    91                 rc = devmap_device_get_handle(in_devs[i], &handle, 0);
     91                rc = loc_service_get_id(in_devs[i], &service_id, 0);
    9292                if (rc == EOK)
    9393                        break;
     
    9999        }
    100100       
    101         dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
     101        dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id,
    102102            IPC_FLAG_BLOCKING);
    103103        if (dev_sess == NULL) {
  • uspace/srv/hid/input/proto/mousedev.c

    re0e922d rdb6e419  
    4444#include <ipc/mouseev.h>
    4545#include <input.h>
     46#include <loc.h>
    4647#include <mouse.h>
    4748#include <mouse_port.h>
    4849#include <mouse_proto.h>
     50#include <sys/typefmt.h>
    4951
    5052/** Mousedev softstate */
     
    5557        /** Session to mouse device */
    5658        async_sess_t *sess;
    57        
    58         /** File descriptor of open mousedev device */
    59         int fd;
    6059} mousedev_t;
    6160
     
    6766       
    6867        mousedev->mouse_dev = mdev;
    69         mousedev->fd = -1;
    7068       
    7169        return mousedev;
     
    7674        if (mousedev->sess != NULL)
    7775                async_hangup(mousedev->sess);
    78        
    79         if (mousedev->fd >= 0)
    80                 close(mousedev->fd);
    8176       
    8277        free(mousedev);
     
    122117static int mousedev_proto_init(mouse_dev_t *mdev)
    123118{
    124         const char *pathname = mdev->dev_path;
    125        
    126         int fd = open(pathname, O_RDWR);
    127         if (fd < 0)
    128                 return -1;
    129        
    130         async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     119        async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE,
     120            mdev->svc_id, 0);
    131121        if (sess == NULL) {
    132                 printf("%s: Failed starting session with '%s'\n", NAME, pathname);
    133                 close(fd);
     122                printf("%s: Failed starting session with '%s'\n", NAME,
     123                    mdev->svc_name);
    134124                return -1;
    135125        }
     
    138128        if (mousedev == NULL) {
    139129                printf("%s: Failed allocating device structure for '%s'.\n",
    140                     NAME, pathname);
     130                    NAME, mdev->svc_name);
    141131                return -1;
    142132        }
    143133       
    144         mousedev->fd = fd;
    145134        mousedev->sess = sess;
    146135       
    147136        async_exch_t *exch = async_exchange_begin(sess);
    148137        if (exch == NULL) {
    149                 printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     138                printf("%s: Failed starting exchange with '%s'.\n", NAME,
     139                    mdev->svc_name);
    150140                mousedev_destroy(mousedev);
    151141                return -1;
     
    157147        if (rc != EOK) {
    158148                printf("%s: Failed creating callback connection from '%s'.\n",
    159                     NAME, pathname);
     149                    NAME, mdev->svc_name);
    160150                mousedev_destroy(mousedev);
    161151                return -1;
Note: See TracChangeset for help on using the changeset viewer.