Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/console.c

    r79ae36dd rffa2c8ef  
    3939#include <ipc/fb.h>
    4040#include <ipc/services.h>
    41 #include <ns.h>
    42 #include <ns_obsolete.h>
     41#include <ipc/ns.h>
    4342#include <errno.h>
    44 #include <str_error.h>
    4543#include <ipc/console.h>
    4644#include <unistd.h>
    4745#include <async.h>
    48 #include <async_obsolete.h>
    4946#include <adt/fifo.h>
    5047#include <sys/mman.h>
     
    5451#include <event.h>
    5552#include <devmap.h>
    56 #include <devmap_obsolete.h>
    5753#include <fcntl.h>
    5854#include <vfs/vfs.h>
     
    6056#include <io/style.h>
    6157#include <io/screenbuffer.h>
    62 #include <inttypes.h>
    6358
    6459#include "console.h"
     
    6661#include "keybuffer.h"
    6762
    68 // FIXME: remove this header
    69 #include <kernel/ipc/ipc_methods.h>
    7063
    7164#define NAME       "console"
    7265#define NAMESPACE  "term"
    73 
    74 /** Interval for checking for new keyboard (1/4s). */
    75 #define HOTPLUG_WATCH_INTERVAL (1000 * 250)
    76 
    77 /* Kernel defines 32 but does not export it. */
    78 #define MAX_IPC_OUTGOING_PHONES 128
    79 
    80 /** To allow proper phone closing. */
    81 static ipc_callid_t driver_phones[MAX_IPC_OUTGOING_PHONES] = { 0 };
    8266
    8367/** Phone to the keyboard driver. */
     
    127111static void curs_visibility(bool visible)
    128112{
    129         async_obsolete_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
     113        async_msg_1(fb_info.phone, FB_CURSOR_VISIBILITY, visible);
    130114}
    131115
    132116static void curs_hide_sync(void)
    133117{
    134         async_obsolete_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
     118        async_req_1_0(fb_info.phone, FB_CURSOR_VISIBILITY, false);
    135119}
    136120
    137121static void curs_goto(sysarg_t x, sysarg_t y)
    138122{
    139         async_obsolete_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
     123        async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
    140124}
    141125
    142126static void screen_clear(void)
    143127{
    144         async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
     128        async_msg_0(fb_info.phone, FB_CLEAR);
    145129}
    146130
    147131static void screen_yield(void)
    148132{
    149         async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_YIELD);
     133        async_req_0_0(fb_info.phone, FB_SCREEN_YIELD);
    150134}
    151135
    152136static void screen_reclaim(void)
    153137{
    154         async_obsolete_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
     138        async_req_0_0(fb_info.phone, FB_SCREEN_RECLAIM);
    155139}
    156140
    157141static void kbd_yield(void)
    158142{
    159         async_obsolete_req_0_0(kbd_phone, KBD_YIELD);
     143        async_req_0_0(kbd_phone, KBD_YIELD);
    160144}
    161145
    162146static void kbd_reclaim(void)
    163147{
    164         async_obsolete_req_0_0(kbd_phone, KBD_RECLAIM);
     148        async_req_0_0(kbd_phone, KBD_RECLAIM);
    165149}
    166150
    167151static void set_style(uint8_t style)
    168152{
    169         async_obsolete_msg_1(fb_info.phone, FB_SET_STYLE, style);
     153        async_msg_1(fb_info.phone, FB_SET_STYLE, style);
    170154}
    171155
    172156static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
    173157{
    174         async_obsolete_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
     158        async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
    175159}
    176160
    177161static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
    178162{
    179         async_obsolete_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
     163        async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
    180164}
    181165
     
    232216                }
    233217               
    234                 async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
     218                async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
    235219                    x0, y0, width, height);
    236220        }
     
    273257static void fb_putchar(wchar_t c, sysarg_t col, sysarg_t row)
    274258{
    275         async_obsolete_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
     259        async_msg_3(fb_info.phone, FB_PUTCHAR, c, col, row);
    276260}
    277261
     
    322306               
    323307                if (cons == active_console)
    324                         async_obsolete_msg_1(fb_info.phone, FB_SCROLL, 1);
     308                        async_msg_1(fb_info.phone, FB_SCROLL, 1);
    325309        }
    326310       
     
    339323       
    340324        if (cons == kernel_console) {
    341                 async_obsolete_serialize_start();
     325                async_serialize_start();
    342326                curs_hide_sync();
    343327                gcons_in_kernel();
    344328                screen_yield();
    345329                kbd_yield();
    346                 async_obsolete_serialize_end();
     330                async_serialize_end();
    347331               
    348332                if (__SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE)) {
     
    354338       
    355339        if (cons != kernel_console) {
    356                 async_obsolete_serialize_start();
     340                async_serialize_start();
    357341               
    358342                if (active_console == kernel_console) {
     
    381365                       
    382366                        /* This call can preempt, but we are already at the end */
    383                         rc = async_obsolete_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
     367                        rc = async_req_4_0(fb_info.phone, FB_DRAW_TEXT_DATA,
    384368                            0, 0, cons->scr.size_x,
    385369                            cons->scr.size_y);
     
    409393                curs_visibility(cons->scr.is_cursor_visible);
    410394               
    411                 async_obsolete_serialize_end();
    412         }
    413 }
    414 
    415 static void close_driver_phone(ipc_callid_t hash)
    416 {
    417         int i;
    418         for (i = 0; i < MAX_IPC_OUTGOING_PHONES; i++) {
    419                 if (driver_phones[i] == hash) {
    420                         printf("Device %" PRIxn " gone.\n", hash);
    421                         driver_phones[i] = 0;
    422                         async_obsolete_hangup(i);
    423                         return;
    424                 }
     395                async_serialize_end();
    425396        }
    426397}
     
    435406               
    436407                int retval;
    437                 kbd_event_t ev;
    438                
    439                 if (!IPC_GET_IMETHOD(call)) {
     408                console_event_t ev;
     409               
     410                switch (IPC_GET_IMETHOD(call)) {
     411                case IPC_M_PHONE_HUNGUP:
    440412                        /* TODO: Handle hangup */
    441                         close_driver_phone(iid);
    442413                        return;
    443                 }
    444                
    445                 switch (IPC_GET_IMETHOD(call)) {
    446414                case KBD_EVENT:
    447415                        /* Got event from keyboard driver. */
     
    483451                int retval;
    484452               
    485                 if (!IPC_GET_IMETHOD(call)) {
     453                switch (IPC_GET_IMETHOD(call)) {
     454                case IPC_M_PHONE_HUNGUP:
    486455                        /* TODO: Handle hangup */
    487                         close_driver_phone(iid);
    488456                        return;
    489                 }
    490                
    491                 switch (IPC_GET_IMETHOD(call)) {
    492457                case MEVENT_BUTTON:
    493458                        if (IPC_GET_ARG1(call) == 1) {
     
    522487        }
    523488       
    524         async_obsolete_serialize_start();
     489        async_serialize_start();
    525490       
    526491        size_t off = 0;
     
    530495        }
    531496       
    532         async_obsolete_serialize_end();
     497        async_serialize_end();
    533498       
    534499        gcons_notify_char(cons->index);
     
    556521       
    557522        size_t pos = 0;
    558         kbd_event_t ev;
     523        console_event_t ev;
    559524        fibril_mutex_lock(&input_mutex);
    560525       
     
    581546static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
    582547{
    583         kbd_event_t ev;
     548        console_event_t ev;
    584549       
    585550        fibril_mutex_lock(&input_mutex);
     
    625590        int rc;
    626591       
    627         async_obsolete_serialize_start();
     592        async_serialize_start();
    628593        if (cons->refcount == 0)
    629594                gcons_notify_connect(cons->index);
     
    635600       
    636601        while (true) {
    637                 async_obsolete_serialize_end();
     602                async_serialize_end();
    638603                callid = async_get_call(&call);
    639                 async_obsolete_serialize_start();
     604                async_serialize_start();
    640605               
    641606                arg1 = 0;
     
    643608                arg3 = 0;
    644609               
    645                 if (!IPC_GET_IMETHOD(call)) {
     610                switch (IPC_GET_IMETHOD(call)) {
     611                case IPC_M_PHONE_HUNGUP:
    646612                        cons->refcount--;
    647613                        if (cons->refcount == 0)
    648614                                gcons_notify_disconnect(cons->index);
    649615                        return;
    650                 }
    651                
    652                 switch (IPC_GET_IMETHOD(call)) {
    653616                case VFS_OUT_READ:
    654                         async_obsolete_serialize_end();
     617                        async_serialize_end();
    655618                        cons_read(cons, callid, &call);
    656                         async_obsolete_serialize_start();
     619                        async_serialize_start();
    657620                        continue;
    658621                case VFS_OUT_WRITE:
    659                         async_obsolete_serialize_end();
     622                        async_serialize_end();
    660623                        cons_write(cons, callid, &call);
    661                         async_obsolete_serialize_start();
     624                        async_serialize_start();
    662625                        continue;
    663626                case VFS_OUT_SYNC:
    664627                        fb_pending_flush();
    665628                        if (cons == active_console) {
    666                                 async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
     629                                async_req_0_0(fb_info.phone, FB_FLUSH);
    667630                                curs_goto(cons->scr.position_x, cons->scr.position_y);
    668631                        }
     
    671634                        /* Send message to fb */
    672635                        if (cons == active_console)
    673                                 async_obsolete_msg_0(fb_info.phone, FB_CLEAR);
     636                                async_msg_0(fb_info.phone, FB_CLEAR);
    674637                       
    675638                        screenbuffer_clear(&cons->scr);
     
    730693                        break;
    731694                case CONSOLE_GET_EVENT:
    732                         async_obsolete_serialize_end();
     695                        async_serialize_end();
    733696                        cons_get_event(cons, callid, &call);
    734                         async_obsolete_serialize_start();
     697                        async_serialize_start();
    735698                        continue;
    736699                case CONSOLE_KCON_ENABLE:
     
    747710}
    748711
    749 static int async_connect_to_me_hack(int phone, sysarg_t arg1, sysarg_t arg2,
    750     sysarg_t arg3, async_client_conn_t client_receiver, ipc_callid_t *hash)
    751 {
    752         sysarg_t task_hash;
    753         sysarg_t phone_hash;
    754         int rc = async_obsolete_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    755             NULL, NULL, NULL, &task_hash, &phone_hash);
    756         if (rc != EOK)
    757                 return rc;
    758        
    759         if (client_receiver != NULL)
    760                 async_new_connection(task_hash, phone_hash, phone_hash, NULL,
    761                     client_receiver);
    762        
    763         if (hash != NULL)
    764                 *hash = phone_hash;
    765        
    766         return EOK;
    767 }
    768 
    769 static int connect_keyboard_or_mouse(const char *devname,
    770     async_client_conn_t handler, const char *dev)
    771 {
    772         int phone;
    773         devmap_handle_t handle;
    774        
    775         int rc = devmap_device_get_handle(dev, &handle, 0);
    776         if (rc == EOK) {
    777                 phone = devmap_obsolete_device_connect(handle, 0);
    778                 if (phone < 0) {
    779                         printf("%s: Failed to connect to input device\n", NAME);
    780                         return phone;
    781                 }
    782         } else
    783                 return rc;
     712static bool console_init(char *input)
     713{
     714        /* Connect to input device */
     715        int input_fd = open(input, O_RDONLY);
     716        if (input_fd < 0) {
     717                printf(NAME ": Failed opening %s\n", input);
     718                return false;
     719        }
     720       
     721        kbd_phone = fd_phone(input_fd);
     722        if (kbd_phone < 0) {
     723                printf(NAME ": Failed to connect to input device\n");
     724                return false;
     725        }
    784726       
    785727        /* NB: The callback connection is slotted for removal */
    786         ipc_callid_t hash;
    787         rc = async_connect_to_me_hack(phone, SERVICE_CONSOLE, 0, phone,
    788             handler, &hash);
    789         if (rc != EOK) {
    790                 async_obsolete_hangup(phone);
    791                 printf("%s: Failed to create callback from input device (%s).\n",
    792                     NAME, str_error(rc));
    793                 return rc;
    794         }
    795        
    796         driver_phones[phone] = hash;
    797         printf("%s: found %s \"%s\" (%" PRIxn ").\n", NAME, devname, dev, hash);
    798         return phone;
    799 }
    800 
    801 static int connect_keyboard(const char *dev)
    802 {
    803         return connect_keyboard_or_mouse("keyboard", keyboard_events, dev);
    804 }
    805 
    806 static int connect_mouse(const char *dev)
    807 {
    808         return connect_keyboard_or_mouse("mouse", mouse_events, dev);
    809 }
    810 
    811 struct hid_class_info {
    812         char *classname;
    813         int (*connection_func)(const char *);
    814 };
    815 
    816 /** Periodically check for new keyboards in /dev/class/.
    817  *
    818  * @param arg Class name.
    819  *
    820  * @return This function should never exit.
    821  *
    822  */
    823 static int check_new_device_fibril(void *arg)
    824 {
    825         struct hid_class_info *dev_info = (struct hid_class_info *) arg;
    826        
    827         size_t index = 1;
    828        
    829         while (true) {
    830                 async_usleep(HOTPLUG_WATCH_INTERVAL);
    831                
    832                 char *dev;
    833                 int rc = asprintf(&dev, "class/%s\\%zu",
    834                     dev_info->classname, index);
    835                 if (rc < 0)
    836                         continue;
    837                
    838                 rc = dev_info->connection_func(dev);
    839                 if (rc > 0) {
    840                         /* We do not allow unplug. */
    841                         index++;
    842                 }
    843                
    844                 free(dev);
    845         }
    846        
    847         return EOK;
    848 }
    849 
    850 /** Start a fibril monitoring hot-plugged keyboards.
    851  */
    852 static void check_new_devices_in_background(int (*connection_func)(const char *),
    853     const char *classname)
    854 {
    855         struct hid_class_info *dev_info = malloc(sizeof(struct hid_class_info));
    856         if (dev_info == NULL) {
    857                 printf("%s: Out of memory, no hot-plug support.\n", NAME);
    858                 return;
    859         }
    860        
    861         int rc = asprintf(&dev_info->classname, "%s", classname);
    862         if (rc < 0) {
    863                 printf("%s: Failed to format classname: %s.\n", NAME,
    864                     str_error(rc));
    865                 return;
    866         }
    867        
    868         dev_info->connection_func = connection_func;
    869        
    870         fid_t fid = fibril_create(check_new_device_fibril, (void *) dev_info);
    871         if (!fid) {
    872                 printf("%s: Failed to create hot-plug fibril for %s.\n", NAME,
    873                     classname);
    874                 return;
    875         }
    876        
    877         fibril_add_ready(fid);
    878 }
    879 
    880 static bool console_srv_init(char *kdev)
    881 {
    882         /* Connect to input device */
    883         kbd_phone = connect_keyboard(kdev);
    884         if (kbd_phone < 0)
     728        if (async_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, keyboard_events)
     729            != 0) {
     730                printf(NAME ": Failed to create callback from input device\n");
    885731                return false;
    886        
    887         mouse_phone = connect_mouse("hid_in/mouse");
     732        }
     733       
     734        /* Connect to mouse device */
     735        mouse_phone = -1;
     736        int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
     737       
     738        if (mouse_fd < 0) {
     739                printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
     740                goto skip_mouse;
     741        }
     742       
     743        mouse_phone = fd_phone(mouse_fd);
    888744        if (mouse_phone < 0) {
    889                 printf("%s: Failed to connect to mouse device %s\n", NAME,
    890                     str_error(mouse_phone));
    891         }
     745                printf(NAME ": Failed to connect to mouse device\n");
     746                goto skip_mouse;
     747        }
     748       
     749        if (async_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, mouse_events)
     750            != 0) {
     751                printf(NAME ": Failed to create callback from mouse device\n");
     752                mouse_phone = -1;
     753                goto skip_mouse;
     754        }
     755       
     756skip_mouse:
    892757       
    893758        /* Connect to framebuffer driver */
    894         fb_info.phone = service_obsolete_connect_blocking(SERVICE_VIDEO, 0, 0);
     759        fb_info.phone = service_connect_blocking(SERVICE_VIDEO, 0, 0);
    895760        if (fb_info.phone < 0) {
    896                 printf("%s: Failed to connect to video service\n", NAME);
    897                 return false;
     761                printf(NAME ": Failed to connect to video service\n");
     762                return -1;
    898763        }
    899764       
     
    901766        int rc = devmap_driver_register(NAME, client_connection);
    902767        if (rc < 0) {
    903                 printf("%s: Unable to register driver (%d)\n", NAME, rc);
     768                printf(NAME ": Unable to register driver (%d)\n", rc);
    904769                return false;
    905770        }
     
    909774       
    910775        /* Synchronize, the gcons could put something in queue */
    911         async_obsolete_req_0_0(fb_info.phone, FB_FLUSH);
    912         async_obsolete_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
    913         async_obsolete_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
     776        async_req_0_0(fb_info.phone, FB_FLUSH);
     777        async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
     778        async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
    914779       
    915780        /* Set up shared memory buffer. */
     
    922787       
    923788        if (interbuffer) {
    924                 if (async_obsolete_share_out_start(fb_info.phone, interbuffer,
     789                if (async_share_out_start(fb_info.phone, interbuffer,
    925790                    AS_AREA_READ) != EOK) {
    926791                        as_area_destroy(interbuffer);
     
    937802                        if (screenbuffer_init(&consoles[i].scr,
    938803                            fb_info.cols, fb_info.rows) == NULL) {
    939                                 printf("%s: Unable to allocate screen buffer %zu\n", NAME, i);
     804                                printf(NAME ": Unable to allocate screen buffer %zu\n", i);
    940805                                return false;
    941806                        }
     
    949814                       
    950815                        if (devmap_device_register(vc, &consoles[i].devmap_handle) != EOK) {
    951                                 printf("%s: Unable to register device %s\n", NAME, vc);
     816                                printf(NAME ": Unable to register device %s\n", vc);
    952817                                return false;
    953818                        }
     
    959824       
    960825        /* Initialize the screen */
    961         async_obsolete_serialize_start();
     826        async_serialize_start();
    962827        gcons_redraw_console();
    963828        set_style(STYLE_NORMAL);
     
    965830        curs_goto(0, 0);
    966831        curs_visibility(active_console->scr.is_cursor_visible);
    967         async_obsolete_serialize_end();
     832        async_serialize_end();
    968833       
    969834        /* Receive kernel notifications */
    970835        async_set_interrupt_received(interrupt_received);
    971836        if (event_subscribe(EVENT_KCONSOLE, 0) != EOK)
    972                 printf("%s: Error registering kconsole notifications\n", NAME);
    973        
    974         /* Start fibril for checking on hot-plugged keyboards. */
    975         check_new_devices_in_background(connect_keyboard, "keyboard");
    976         check_new_devices_in_background(connect_mouse, "mouse");
     837                printf(NAME ": Error registering kconsole notifications\n");
    977838       
    978839        return true;
     
    993854        printf(NAME ": HelenOS Console service\n");
    994855       
    995         if (!console_srv_init(argv[1]))
     856        if (!console_init(argv[1]))
    996857                return -1;
    997858       
Note: See TracChangeset for help on using the changeset viewer.