Changes in uspace/drv/char/ns8250/ns8250.c [dd8ab1c:d51838f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/drv/char/ns8250/ns8250.c ¶
rdd8ab1c rd51838f 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 201 7Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 40 40 #include <stdio.h> 41 41 #include <errno.h> 42 #include <str_error.h>43 42 #include <stdbool.h> 44 43 #include <fibril_synch.h> … … 47 46 #include <ctype.h> 48 47 #include <macros.h> 49 #include < stdlib.h>48 #include <malloc.h> 50 49 #include <dirent.h> 51 50 #include <ddi.h> … … 54 53 #include <ddf/interrupt.h> 55 54 #include <ddf/log.h> 56 #include < io/chardev_srv.h>55 #include <ops/char_dev.h> 57 56 58 57 #include <device/hw_res.h> … … 154 153 /** DDF function node */ 155 154 ddf_fun_t *fun; 156 /** Character device service */157 chardev_srvs_t cds;158 155 /** Parent session */ 159 156 async_sess_t *parent_sess; … … 192 189 } 193 190 194 /** Obtain soft-state structure from chardev srv */195 static ns8250_t *srv_ns8250(chardev_srv_t *srv)196 {197 return (ns8250_t *)srv->srvs->sarg;198 }199 200 201 191 /** Find out if there is some incoming data available on the serial port. 202 192 * … … 244 234 /** Read data from the serial port device. 245 235 * 246 * @param srv Server-side connection data236 * @param fun The serial port function 247 237 * @param buf The output buffer for read data. 248 238 * @param count The number of bytes to be read. 249 * @param nread Place to store number of bytes actually read 250 * 251 * @return EOK on success or non-zero error code 252 */ 253 static int ns8250_read(chardev_srv_t *srv, void *buf, size_t count, size_t *nread) 254 { 255 ns8250_t *ns = srv_ns8250(srv); 256 char *bp = (char *) buf; 257 size_t pos = 0; 258 259 if (count == 0) { 260 *nread = 0; 261 return EOK; 262 } 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; 263 249 264 250 fibril_mutex_lock(&ns->mutex); 265 251 while (buf_is_empty(&ns->input_buffer)) 266 252 fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex); 267 while (!buf_is_empty(&ns->input_buffer) && pos< count) {268 b p[pos] = (char)buf_pop_front(&ns->input_buffer);269 pos++;253 while (!buf_is_empty(&ns->input_buffer) && (size_t)ret < count) { 254 buf[ret] = (char)buf_pop_front(&ns->input_buffer); 255 ret++; 270 256 } 271 257 fibril_mutex_unlock(&ns->mutex); 272 258 273 *nread = pos; 274 return EOK; 259 return ret; 275 260 } 276 261 … … 289 274 /** Write data to the serial port. 290 275 * 291 * @param srv Server-side connection data276 * @param fun The serial port function 292 277 * @param buf The data to be written 293 278 * @param count The number of bytes to be written 294 * @param nwritten Place to store number of bytes successfully written 295 * @return EOK on success or non-zero error code 296 */ 297 static int ns8250_write(chardev_srv_t *srv, const void *buf, size_t count, 298 size_t *nwritten) 299 { 300 ns8250_t *ns = srv_ns8250(srv); 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); 301 284 size_t idx; 302 uint8_t *bp = (uint8_t *) buf;303 285 304 286 for (idx = 0; idx < count; idx++) 305 ns8250_putchar(ns, bp[idx]); 306 307 *nwritten = count; 308 return EOK; 309 } 310 311 static int ns8250_open(chardev_srvs_t *, chardev_srv_t *); 312 static int ns8250_close(chardev_srv_t *); 313 static void ns8250_default_handler(chardev_srv_t *, ipc_callid_t, ipc_call_t *); 287 ns8250_putchar(ns, (uint8_t) buf[idx]); 288 289 return count; 290 } 291 292 static ddf_dev_ops_t ns8250_dev_ops; 314 293 315 294 /** The character interface's callbacks. */ 316 static chardev_ops_t ns8250_chardev_ops = { 317 .open = ns8250_open, 318 .close = ns8250_close, 319 .read = ns8250_read, 320 .write = ns8250_write, 321 .def_handler = ns8250_default_handler 295 static char_dev_ops_t ns8250_char_dev_ops = { 296 .read = &ns8250_read, 297 .write = &ns8250_write 322 298 }; 323 324 static void ns8250_char_conn(ipc_callid_t, ipc_call_t *, void *);325 299 326 300 static int ns8250_dev_add(ddf_dev_t *dev); … … 784 758 * 785 759 */ 786 static inline void ns8250_interrupt_handler(ipc_call_t *icall, ddf_dev_t *dev) 760 static inline void ns8250_interrupt_handler(ipc_callid_t iid, ipc_call_t *icall, 761 ddf_dev_t *dev) 787 762 { 788 763 ns8250_t *ns = dev_ns8250(dev); … … 803 778 * @param ns Serial port device 804 779 */ 805 static inline int ns8250_register_interrupt_handler(ns8250_t *ns, 806 cap_handle_t *handle) 780 static inline int ns8250_register_interrupt_handler(ns8250_t *ns) 807 781 { 808 782 return register_interrupt_handler(ns->dev, ns->irq, 809 ns8250_interrupt_handler, NULL , handle);783 ns8250_interrupt_handler, NULL); 810 784 } 811 785 … … 876 850 877 851 /* Register interrupt handler. */ 878 rc = ns8250_register_interrupt_handler(ns, &ns->irq_cap);879 if ( rc != EOK) {852 ns->irq_cap = ns8250_register_interrupt_handler(ns); 853 if (ns->irq_cap < 0) { 880 854 ddf_msg(LVL_ERROR, "Failed to register interrupt handler."); 881 855 rc = EADDRNOTAVAIL; … … 888 862 if (rc != EOK) { 889 863 ddf_msg(LVL_ERROR, "Failed to enable the interrupt. Error code = " 890 "% s.", str_error_name(rc));864 "%d.", rc); 891 865 goto fail; 892 866 } … … 898 872 } 899 873 900 ddf_fun_set_conn_handler(fun, ns8250_char_conn); 901 902 chardev_srvs_init(&ns->cds); 903 ns->cds.ops = &ns8250_chardev_ops; 904 ns->cds.sarg = ns; 905 874 /* Set device operations. */ 875 ddf_fun_set_ops(fun, &ns8250_dev_ops); 906 876 rc = ddf_fun_bind(fun); 907 877 if (rc != EOK) { … … 960 930 * device. 961 931 * 962 * @param srvs Service structure 963 * @param srv Server-side connection structure 964 */ 965 static int ns8250_open(chardev_srvs_t *srvs, chardev_srv_t *srv) 966 { 967 ns8250_t *ns = srv_ns8250(srv); 932 * @param dev The device. 933 */ 934 static int ns8250_open(ddf_fun_t *fun) 935 { 936 ns8250_t *ns = fun_ns8250(fun); 968 937 int res; 969 938 … … 985 954 * the device. 986 955 * 987 * @param srv Server-side connection structure988 */ 989 static int ns8250_close(chardev_srv_t *srv)990 { 991 ns8250_t *data = srv_ns8250(srv);956 * @param dev The device. 957 */ 958 static void ns8250_close(ddf_fun_t *fun) 959 { 960 ns8250_t *data = fun_ns8250(fun); 992 961 993 962 fibril_mutex_lock(&data->mutex); … … 999 968 1000 969 fibril_mutex_unlock(&data->mutex); 1001 1002 return EOK;1003 970 } 1004 971 … … 1067 1034 * Configure the parameters of the serial communication. 1068 1035 */ 1069 static void ns8250_default_handler( chardev_srv_t *srv, ipc_callid_t callid,1036 static void ns8250_default_handler(ddf_fun_t *fun, ipc_callid_t callid, 1070 1037 ipc_call_t *call) 1071 1038 { 1072 ns8250_t *ns8250 = srv_ns8250(srv);1073 1039 sysarg_t method = IPC_GET_IMETHOD(*call); 1074 1040 int ret; … … 1077 1043 switch (method) { 1078 1044 case SERIAL_GET_COM_PROPS: 1079 ns8250_get_props( ns8250->dev, &baud_rate, &parity, &word_length,1045 ns8250_get_props(ddf_fun_get_dev(fun), &baud_rate, &parity, &word_length, 1080 1046 &stop_bits); 1081 1047 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 1088 1054 word_length = IPC_GET_ARG3(*call); 1089 1055 stop_bits = IPC_GET_ARG4(*call); 1090 ret = ns8250_set_props( ns8250->dev, baud_rate, parity, word_length,1056 ret = ns8250_set_props(ddf_fun_get_dev(fun), baud_rate, parity, word_length, 1091 1057 stop_bits); 1092 1058 async_answer_0(callid, ret); … … 1098 1064 } 1099 1065 1100 void ns8250_char_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)1101 {1102 ns8250_t *ns8250 = fun_ns8250((ddf_fun_t *)arg);1103 1104 chardev_conn(iid, icall, &ns8250->cds);1105 }1106 1107 1066 /** Initialize the serial port driver. 1108 1067 * … … 1113 1072 { 1114 1073 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; 1115 1080 } 1116 1081
Note:
See TracChangeset
for help on using the changeset viewer.