Ignore:
Timestamp:
2018-01-30T03:20:45Z (8 years ago)
Author:
Jenda <jenda.jzqk73@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5a6cc679
Parents:
8bfb163 (diff), 6a5d05b (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 commit '6a5d05bd2551e64111bea4f9332dd7448c26ce84' into forwardport

Separate return value from error code in gen_irq_code*().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/output/port/chardev.c

    r8bfb163 r132ab5d1  
    11/*
    22 * Copyright (c) 2016 Jakub Jermar
     3 * Copyright (c) 2017 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3031 */
    3132
     33#include <async.h>
     34#include <config.h>
     35#include <errno.h>
     36#include <fibril_synch.h>
     37#include <io/chardev.h>
     38#include <loc.h>
    3239#include <stddef.h>
    3340#include <stdint.h>
    34 #include <char_dev_iface.h>
    3541#include <stdio.h>
    3642#include <stdlib.h>
    37 #include <async.h>
    38 #include <fibril_synch.h>
    39 #include <loc.h>
    40 #include <errno.h>
    4143#include <str.h>
    42 #include <config.h>
    4344#include "../ctl/serial.h"
    4445#include "../output.h"
    4546#include "chardev.h"
    4647
     48enum {
     49        chardev_buf_size = 4096
     50};
     51
    4752static char *console;
    4853
    4954static async_sess_t *sess;
     55static chardev_t *chardev;
    5056static service_id_t serial_cat_id;
     57static service_id_t console_cat_id;
     58
     59static uint8_t chardev_buf[chardev_buf_size];
     60static size_t chardev_bused;
    5161
    5262static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
     
    5464static FIBRIL_CONDVAR_INITIALIZE(discovery_cv);
    5565
     66static void chardev_flush(void)
     67{
     68        size_t nwr;
     69
     70        if (chardev_bused == 0)
     71                return;
     72
     73        chardev_write(chardev, chardev_buf, chardev_bused, &nwr);
     74        /* XXX Handle error */
     75
     76        chardev_bused = 0;
     77}
     78
    5679static void chardev_putchar(wchar_t ch)
    5780{
    58         uint8_t byte = (uint8_t) ch;
    59         char_dev_write(sess, &byte, 1);
     81        if (chardev_bused == chardev_buf_size)
     82                chardev_flush();
     83        if (!ascii_check(ch))
     84                ch = '?';
     85        chardev_buf[chardev_bused++] = (uint8_t) ch;
    6086}
    6187
    6288static void chardev_control_puts(const char *str)
    6389{
    64         char_dev_write(sess, (void *) str, str_size(str));
     90        const char *p;
     91
     92        p = str;
     93        while (*p != '\0')
     94                chardev_putchar(*p++);
     95}
     96
     97static bool find_output_dev(service_id_t *svcid)
     98{
     99        service_id_t *svc;
     100        size_t svcs;
     101        int rc;
     102
     103        rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs);
     104        if (rc != EOK) {
     105                fibril_mutex_unlock(&discovery_lock);
     106                printf("%s: Failed to get services\n", NAME);
     107                return false;
     108        }
     109
     110        for (size_t i = 0; i < svcs; i++) {
     111                char *name;
     112
     113                rc = loc_service_get_name(svc[i], &name);
     114                if (rc != EOK)
     115                        continue;
     116
     117                if (!str_cmp(console, name)) {
     118                        /*
     119                         * This is the serial console service that the user
     120                         * wanted to use.
     121                         */
     122                        *svcid = svc[i];
     123                        free(svc);
     124                        return true;
     125                }
     126
     127                free(name);
     128        }
     129
     130        free(svc);
     131
     132        /* Look for any service in the 'console' category */
     133
     134        rc = loc_category_get_svcs(console_cat_id, &svc, &svcs);
     135        if (rc != EOK) {
     136                fibril_mutex_unlock(&discovery_lock);
     137                printf("%s: Failed to get services\n", NAME);
     138                return false;
     139        }
     140
     141        if (svcs > 0) {
     142                *svcid = svc[0];
     143                free(svc);
     144                return true;
     145        }
     146
     147        free(svc);
     148        return false;
    65149}
    66150
     
    74158{
    75159        int rc;
     160        bool found;
     161        service_id_t sid;
    76162
    77163        fibril_mutex_lock(&discovery_lock);
     
    82168        }
    83169
    84         service_id_t *svc;
    85         size_t svcs;
    86         rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs);
    87         if (rc != EOK) {
    88                 fibril_mutex_unlock(&discovery_lock);
    89                 printf("%s: Failed to get services\n", NAME);
    90                 return;
    91         }
    92 
    93         service_id_t sid;
    94         bool found = false;
    95 
    96         for (size_t i = 0; i < svcs && !found; i++) {
    97                 char *name;
    98                
    99                 rc = loc_service_get_name(svc[i], &name);
    100                 if (rc != EOK)
    101                         continue;
    102 
    103                 if (!str_cmp(console, name)) {
    104                         /*
    105                          * This is the serial console service that the user
    106                          * wanted to use.
    107                          */
    108                         found = true;
    109                         sid = svc[i];
    110                 }
    111                        
    112                 free(name);
    113         }
    114 
    115         free(svc);
    116 
     170        found = find_output_dev(&sid);
    117171        if (!found) {
    118172                fibril_mutex_unlock(&discovery_lock);
    119173                return;
    120174        }
     175
     176        printf("%s: Connecting service %zu\n", NAME, sid);
     177        char *name;
     178        rc = loc_service_get_name(sid, &name);
     179        if (rc != EOK) {
     180                fibril_mutex_unlock(&discovery_lock);
     181                return;
     182        }
     183        printf("%s: Service name is %s\n", NAME, name);
     184        free(name);
    121185
    122186        sess = loc_service_connect(sid, INTERFACE_DDF, IPC_FLAG_BLOCKING);
     
    126190                return;
    127191        }
    128         serial_init(chardev_putchar, chardev_control_puts);
     192
     193        rc = chardev_open(sess, &chardev);
     194        if (rc != EOK) {
     195                fibril_mutex_unlock(&discovery_lock);
     196                printf("%s: Failed opening character device\n", NAME);
     197                return;
     198        }
     199
     200        serial_init(chardev_putchar, chardev_control_puts, chardev_flush);
    129201
    130202        discovery_finished = true;
     
    135207int chardev_init(void)
    136208{
    137         console = config_get_value("console");
    138         if (!console) {
    139                 /*
    140                  * The system is not configured to use serial console.
    141                  */
     209        if (!config_key_exists("console")) {
     210                console = NULL;
     211#ifdef MACHINE_ski
     212                /* OK */
     213#elif defined(UARCH_sparc64) && defined(PROCESSOR_sun4v)
     214                /* OK */
     215#elif defined(MACHINE_msim)
     216                /* OK */
     217#else
    142218                return EOK;
     219#endif
     220        } else {
     221                console = config_get_value("console");
     222                if (!console)
     223                        return EOK;
    143224        }
    144225
     
    149230        }
    150231
     232        rc = loc_category_get_id("console", &console_cat_id, IPC_FLAG_BLOCKING);
     233        if (rc != EOK) {
     234                printf("%s: Failed to get \"console\" category ID.\n", NAME);
     235                return rc;
     236        }
     237
    151238        rc = loc_register_cat_change_cb(check_for_dev);
    152239        if (rc != EOK) {
     
    155242                return rc;
    156243        }
     244
     245        check_for_dev();
    157246
    158247        fibril_mutex_lock(&discovery_lock);
Note: See TracChangeset for help on using the changeset viewer.