Changeset 74017ce in mainline for uspace/drv/char/ns8250/ns8250.c


Ignore:
Timestamp:
2017-11-22T17:36:54Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a6065c
Parents:
c4c6025
git-author:
Jiri Svoboda <jiri@…> (2017-11-22 15:53:34)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-22 17:36:54)
Message:

Convert char_dev_iface users to chardev.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/ns8250/ns8250.c

    rc4c6025 r74017ce  
    11/*
    22 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2011 Jiri Svoboda
     3 * Copyright (c) 2017 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    5353#include <ddf/interrupt.h>
    5454#include <ddf/log.h>
    55 #include <ops/char_dev.h>
     55#include <io/chardev_srv.h>
    5656
    5757#include <device/hw_res.h>
     
    153153        /** DDF function node */
    154154        ddf_fun_t *fun;
     155        /** Character device service */
     156        chardev_srvs_t cds;
    155157        /** Parent session */
    156158        async_sess_t *parent_sess;
     
    189191}
    190192
     193/** Obtain soft-state structure from chardev srv */
     194static ns8250_t *srv_ns8250(chardev_srv_t *srv)
     195{
     196        return (ns8250_t *)srv->srvs->sarg;
     197}
     198
     199
    191200/** Find out if there is some incoming data available on the serial port.
    192201 *
     
    234243/** Read data from the serial port device.
    235244 *
    236  * @param fun           The serial port function
     245 * @param srv           Server-side connection data
    237246 * @param buf           The output buffer for read data.
    238247 * @param count         The number of bytes to be read.
    239  *
    240  * @return              The number of bytes actually read on success, negative
    241  *                      error number otherwise.
    242  */
    243 static int ns8250_read(ddf_fun_t *fun, char *buf, size_t count)
    244 {
    245         ns8250_t *ns = fun_ns8250(fun);
    246         int ret = 0;
    247        
    248         if (count == 0) return 0;
     248 * @param nread         Place to store number of bytes actually read
     249 *
     250 * @return              EOK on success or non-zero error code
     251 */
     252static int ns8250_read(chardev_srv_t *srv, void *buf, size_t count, size_t *nread)
     253{
     254        ns8250_t *ns = srv_ns8250(srv);
     255        char *bp = (char *) buf;
     256        size_t pos = 0;
     257       
     258        if (count == 0) {
     259                *nread = 0;
     260                return EOK;
     261        }
    249262       
    250263        fibril_mutex_lock(&ns->mutex);
    251264        while (buf_is_empty(&ns->input_buffer))
    252265                fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex);
    253         while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) {
    254                 buf[ret] = (char)buf_pop_front(&ns->input_buffer);
    255                 ret++;
     266        while (!buf_is_empty(&ns->input_buffer) && pos < count) {
     267                bp[pos] = (char)buf_pop_front(&ns->input_buffer);
     268                pos++;
    256269        }
    257270        fibril_mutex_unlock(&ns->mutex);
    258271       
    259         return ret;
     272        *nread = pos;
     273        return EOK;
    260274}
    261275
     
    274288/** Write data to the serial port.
    275289 *
    276  * @param fun           The serial port function
     290 * @param srv           Server-side connection data
    277291 * @param buf           The data to be written
    278292 * @param count         The number of bytes to be written
    279  * @return              Zero on success
    280  */
    281 static int ns8250_write(ddf_fun_t *fun, char *buf, size_t count)
    282 {
    283         ns8250_t *ns = fun_ns8250(fun);
     293 * @param nwritten      Place to store number of bytes successfully written
     294 * @return              EOK on success or non-zero error code
     295 */
     296static int ns8250_write(chardev_srv_t *srv, const void *buf, size_t count,
     297    size_t *nwritten)
     298{
     299        ns8250_t *ns = srv_ns8250(srv);
    284300        size_t idx;
     301        uint8_t *bp = (uint8_t *) buf;
    285302       
    286303        for (idx = 0; idx < count; idx++)
    287                 ns8250_putchar(ns, (uint8_t) buf[idx]);
    288        
    289         return count;
    290 }
    291 
    292 static ddf_dev_ops_t ns8250_dev_ops;
     304                ns8250_putchar(ns, bp[idx]);
     305       
     306        *nwritten = count;
     307        return EOK;
     308}
     309
     310static int ns8250_open(chardev_srvs_t *, chardev_srv_t *);
     311static int ns8250_close(chardev_srv_t *);
     312static void ns8250_default_handler(chardev_srv_t *, ipc_callid_t, ipc_call_t *);
    293313
    294314/** The character interface's callbacks. */
    295 static char_dev_ops_t ns8250_char_dev_ops = {
    296         .read = &ns8250_read,
    297         .write = &ns8250_write
     315static chardev_ops_t ns8250_chardev_ops = {
     316        .open = ns8250_open,
     317        .close = ns8250_close,
     318        .read = ns8250_read,
     319        .write = ns8250_write,
     320        .def_handler = ns8250_default_handler
    298321};
     322
     323static void ns8250_char_conn(ipc_callid_t, ipc_call_t *, void *);
    299324
    300325static int ns8250_dev_add(ddf_dev_t *dev);
     
    872897        }
    873898       
    874         /* Set device operations. */
    875         ddf_fun_set_ops(fun, &ns8250_dev_ops);
     899        ddf_fun_set_conn_handler(fun, ns8250_char_conn);
     900       
     901        chardev_srvs_init(&ns->cds);
     902        ns->cds.ops = &ns8250_chardev_ops;
     903        ns->cds.sarg = ns;
     904       
    876905        rc = ddf_fun_bind(fun);
    877906        if (rc != EOK) {
     
    930959 * device.
    931960 *
    932  * @param dev           The device.
    933  */
    934 static int ns8250_open(ddf_fun_t *fun)
    935 {
    936         ns8250_t *ns = fun_ns8250(fun);
     961 * @param srvs          Service structure
     962 * @param srv           Server-side connection structure
     963 */
     964static int ns8250_open(chardev_srvs_t *srvs, chardev_srv_t *srv)
     965{
     966        ns8250_t *ns = srv_ns8250(srv);
    937967        int res;
    938968       
     
    954984 * the device.
    955985 *
    956  * @param dev           The device.
    957  */
    958 static void ns8250_close(ddf_fun_t *fun)
    959 {
    960         ns8250_t *data = fun_ns8250(fun);
     986 * @param srv           Server-side connection structure
     987 */
     988static int ns8250_close(chardev_srv_t *srv)
     989{
     990        ns8250_t *data = srv_ns8250(srv);
    961991       
    962992        fibril_mutex_lock(&data->mutex);
     
    968998       
    969999        fibril_mutex_unlock(&data->mutex);
     1000       
     1001        return EOK;
    9701002}
    9711003
     
    10341066 * Configure the parameters of the serial communication.
    10351067 */
    1036 static void ns8250_default_handler(ddf_fun_t *fun, ipc_callid_t callid,
     1068static void ns8250_default_handler(chardev_srv_t *srv, ipc_callid_t callid,
    10371069    ipc_call_t *call)
    10381070{
     1071        ns8250_t *ns8250 = srv_ns8250(srv);
    10391072        sysarg_t method = IPC_GET_IMETHOD(*call);
    10401073        int ret;
     
    10431076        switch (method) {
    10441077        case SERIAL_GET_COM_PROPS:
    1045                 ns8250_get_props(ddf_fun_get_dev(fun), &baud_rate, &parity, &word_length,
     1078                ns8250_get_props(ns8250->dev, &baud_rate, &parity, &word_length,
    10461079                    &stop_bits);
    10471080                async_answer_4(callid, EOK, baud_rate, parity, word_length,
     
    10541087                word_length = IPC_GET_ARG3(*call);
    10551088                stop_bits = IPC_GET_ARG4(*call);
    1056                 ret = ns8250_set_props(ddf_fun_get_dev(fun), baud_rate, parity, word_length,
     1089                ret = ns8250_set_props(ns8250->dev, baud_rate, parity, word_length,
    10571090                    stop_bits);
    10581091                async_answer_0(callid, ret);
     
    10641097}
    10651098
     1099void ns8250_char_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     1100{
     1101        ns8250_t *ns8250 = fun_ns8250((ddf_fun_t *)arg);
     1102
     1103        chardev_conn(iid, icall, &ns8250->cds);
     1104}
     1105
    10661106/** Initialize the serial port driver.
    10671107 *
     
    10721112{
    10731113        ddf_log_init(NAME);
    1074        
    1075         ns8250_dev_ops.open = &ns8250_open;
    1076         ns8250_dev_ops.close = &ns8250_close;
    1077        
    1078         ns8250_dev_ops.interfaces[CHAR_DEV_IFACE] = &ns8250_char_dev_ops;
    1079         ns8250_dev_ops.default_handler = &ns8250_default_handler;
    10801114}
    10811115
Note: See TracChangeset for help on using the changeset viewer.