Changeset ac307b2 in mainline for uspace/drv
- Timestamp:
- 2017-11-25T11:12:23Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 98cb5e0d
- Parents:
- f571ca49 (diff), 0851a3d (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. - Location:
- uspace/drv
- Files:
-
- 1 deleted
- 13 edited
-
char/i8042/buffer.h (deleted)
-
char/i8042/i8042.c (modified) (9 diffs)
-
char/i8042/i8042.h (modified) (3 diffs)
-
char/msim-con/msim-con.c (modified) (5 diffs)
-
char/msim-con/msim-con.h (modified) (2 diffs)
-
char/ns8250/ns8250.c (modified) (15 diffs)
-
char/ski-con/ski-con.c (modified) (8 diffs)
-
char/ski-con/ski-con.h (modified) (2 diffs)
-
char/sun4v-con/sun4v-con.c (modified) (7 diffs)
-
char/sun4v-con/sun4v-con.h (modified) (2 diffs)
-
root/virt/devices.def (modified) (1 diff)
-
test/test1/Makefile (modified) (1 diff)
-
test/test1/test1.c (modified) (1 diff)
-
test/test1/test1.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
rf571ca49 rac307b2 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 3 * Copyright (c) 2006 Josef Cejka 4 * Copyright (c) 201 4Jiri Svoboda4 * Copyright (c) 2017 Jiri Svoboda 5 5 * Copyright (c) 2011 Jan Vesely 6 6 * All rights reserved. … … 39 39 */ 40 40 41 #include <adt/circ_buf.h> 41 42 #include <ddf/log.h> 42 43 #include <ddf/interrupt.h> … … 130 131 { 131 132 i8042_t *controller = ddf_dev_data_get(dev); 133 int rc; 132 134 133 135 const uint8_t status = IPC_GET_ARG1(*call); 134 136 const uint8_t data = IPC_GET_ARG2(*call); 135 137 136 buffer_t *buffer = (status & i8042_AUX_DATA) ? 137 &controller->aux_buffer : &controller->kbd_buffer; 138 139 buffer_write(buffer, data); 138 i8042_port_t *port = (status & i8042_AUX_DATA) ? 139 controller->aux : controller->kbd; 140 141 fibril_mutex_lock(&port->buf_lock); 142 143 rc = circ_buf_push(&port->cbuf, &data); 144 if (rc != EOK) 145 ddf_msg(LVL_ERROR, "Buffer overrun"); 146 147 fibril_mutex_unlock(&port->buf_lock); 148 fibril_condvar_broadcast(&port->buf_cv); 140 149 } 141 150 … … 159 168 const size_t cmd_count = sizeof(i8042_cmds) / sizeof(irq_cmd_t); 160 169 irq_cmd_t cmds[cmd_count]; 170 ddf_fun_t *kbd_fun; 171 ddf_fun_t *aux_fun; 161 172 i8042_regs_t *ar; 162 173 163 174 int rc; 164 175 bool kbd_bound = false; 165 176 bool aux_bound = false; 166 167 dev->kbd_fun = NULL;168 dev->aux_fun = NULL;169 177 170 178 if (regs->size < sizeof(i8042_regs_t)) { … … 178 186 } 179 187 180 dev->kbd_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2a");181 if ( dev->kbd_fun == NULL) {188 kbd_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2a"); 189 if (kbd_fun == NULL) { 182 190 rc = ENOMEM; 183 191 goto error; 184 192 }; 185 193 186 dev->kbd = ddf_fun_data_alloc( dev->kbd_fun, sizeof(i8042_port_t));194 dev->kbd = ddf_fun_data_alloc(kbd_fun, sizeof(i8042_port_t)); 187 195 if (dev->kbd == NULL) { 188 196 rc = ENOMEM; … … 190 198 } 191 199 200 dev->kbd->fun = kbd_fun; 192 201 dev->kbd->ctl = dev; 193 202 chardev_srvs_init(&dev->kbd->cds); 194 203 dev->kbd->cds.ops = &i8042_chardev_ops; 195 204 dev->kbd->cds.sarg = dev->kbd; 196 197 rc = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90); 205 fibril_mutex_initialize(&dev->kbd->buf_lock); 206 fibril_condvar_initialize(&dev->kbd->buf_cv); 207 208 rc = ddf_fun_add_match_id(dev->kbd->fun, "char/xtkbd", 90); 198 209 if (rc != EOK) 199 210 goto error; 200 211 201 dev->aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b");202 if ( dev->aux_fun == NULL) {212 aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b"); 213 if (aux_fun == NULL) { 203 214 rc = ENOMEM; 204 215 goto error; 205 216 } 206 217 207 dev->aux = ddf_fun_data_alloc( dev->aux_fun, sizeof(i8042_port_t));218 dev->aux = ddf_fun_data_alloc(aux_fun, sizeof(i8042_port_t)); 208 219 if (dev->aux == NULL) { 209 220 rc = ENOMEM; … … 211 222 } 212 223 224 dev->aux->fun = aux_fun; 213 225 dev->aux->ctl = dev; 214 226 chardev_srvs_init(&dev->aux->cds); 215 227 dev->aux->cds.ops = &i8042_chardev_ops; 216 228 dev->aux->cds.sarg = dev->aux; 217 218 rc = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90); 229 fibril_mutex_initialize(&dev->aux->buf_lock); 230 fibril_condvar_initialize(&dev->aux->buf_cv); 231 232 rc = ddf_fun_add_match_id(dev->aux->fun, "char/ps2mouse", 90); 219 233 if (rc != EOK) 220 234 goto error; 221 235 222 ddf_fun_set_conn_handler(dev->kbd _fun, i8042_char_conn);223 ddf_fun_set_conn_handler(dev->aux _fun, i8042_char_conn);224 225 buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE);226 buffer_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE);236 ddf_fun_set_conn_handler(dev->kbd->fun, i8042_char_conn); 237 ddf_fun_set_conn_handler(dev->aux->fun, i8042_char_conn); 238 239 circ_buf_init(&dev->kbd->cbuf, dev->kbd->buf_data, BUFFER_SIZE, 1); 240 circ_buf_init(&dev->aux->cbuf, dev->aux->buf_data, BUFFER_SIZE, 1); 227 241 fibril_mutex_initialize(&dev->write_guard); 228 242 229 rc = ddf_fun_bind(dev->kbd _fun);243 rc = ddf_fun_bind(dev->kbd->fun); 230 244 if (rc != EOK) { 231 245 ddf_msg(LVL_ERROR, "Failed to bind keyboard function: %s.", 232 ddf_fun_get_name(dev->kbd _fun));246 ddf_fun_get_name(dev->kbd->fun)); 233 247 goto error; 234 248 } 235 249 kbd_bound = true; 236 250 237 rc = ddf_fun_bind(dev->aux _fun);251 rc = ddf_fun_bind(dev->aux->fun); 238 252 if (rc != EOK) { 239 253 ddf_msg(LVL_ERROR, "Failed to bind aux function: %s.", 240 ddf_fun_get_name(dev->aux _fun));254 ddf_fun_get_name(dev->aux->fun)); 241 255 goto error; 242 256 } … … 317 331 error: 318 332 if (kbd_bound) 319 ddf_fun_unbind(dev->kbd _fun);333 ddf_fun_unbind(dev->kbd->fun); 320 334 if (aux_bound) 321 ddf_fun_unbind(dev->aux _fun);322 if (dev->kbd _fun != NULL)323 ddf_fun_destroy(dev->kbd _fun);324 if (dev->aux _fun != NULL)325 ddf_fun_destroy(dev->aux _fun);335 ddf_fun_unbind(dev->aux->fun); 336 if (dev->kbd->fun != NULL) 337 ddf_fun_destroy(dev->kbd->fun); 338 if (dev->aux->fun != NULL) 339 ddf_fun_destroy(dev->aux->fun); 326 340 327 341 return rc; … … 377 391 { 378 392 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 379 i8042_t *i8042 = port->ctl;393 size_t p; 380 394 uint8_t *destp = (uint8_t *)dest; 381 395 int rc; 382 size_t i; 383 384 buffer_t *buffer = (port == i8042->aux) ? 385 &i8042->aux_buffer : &i8042->kbd_buffer; 386 387 for (i = 0; i < size; ++i) { 388 rc = buffer_read(buffer, destp, i == 0); 396 397 fibril_mutex_lock(&port->buf_lock); 398 399 while (circ_buf_nused(&port->cbuf) == 0) 400 fibril_condvar_wait(&port->buf_cv, &port->buf_lock); 401 402 p = 0; 403 while (p < size) { 404 rc = circ_buf_pop(&port->cbuf, &destp[p]); 389 405 if (rc != EOK) 390 406 break; 391 ++destp; 392 } 393 394 *nread = i; 407 ++p; 408 } 409 410 fibril_mutex_unlock(&port->buf_lock); 411 412 *nread = p; 395 413 return EOK; 396 414 } -
uspace/drv/char/i8042/i8042.h
rf571ca49 rac307b2 2 2 * Copyright (c) 2006 Josef Cejka 3 3 * Copyright (c) 2011 Jan Vesely 4 * Copyright (c) 2017 Jiri Svoboda 4 5 * All rights reserved. 5 6 * … … 40 41 #define i8042_H_ 41 42 43 #include <adt/circ_buf.h> 42 44 #include <io/chardev_srv.h> 43 45 #include <ddi.h> 44 46 #include <fibril_synch.h> 45 47 #include <ddf/driver.h> 46 #include "buffer.h"47 48 48 49 #define NAME "i8042" … … 59 60 /** i8042 Port. */ 60 61 typedef struct { 61 struct i8042 *ctl; /**< Controller */ 62 chardev_srvs_t cds; /**< Character device server data */ 62 /** Controller */ 63 struct i8042 *ctl; 64 /** Device function */ 65 ddf_fun_t *fun; 66 /** Character device server data */ 67 chardev_srvs_t cds; 68 /** Circular buffer */ 69 circ_buf_t cbuf; 70 /** Buffer data space */ 71 uint8_t buf_data[BUFFER_SIZE]; 72 /** Protect buffer */ 73 fibril_mutex_t buf_lock; 74 /** Signal new data in buffer */ 75 fibril_condvar_t buf_cv; 63 76 } i8042_port_t; 64 77 65 78 /** i8042 Controller. */ 66 79 typedef struct i8042 { 67 i8042_regs_t *regs; /**< I/O registers. */ 68 ddf_fun_t *kbd_fun; /**< Pirmary port device function. */ 69 ddf_fun_t *aux_fun; /**< Auxiliary port device function. */ 70 buffer_t kbd_buffer; /**< Primary port buffer. */ 71 buffer_t aux_buffer; /**< Aux. port buffer. */ 72 uint8_t aux_data[BUFFER_SIZE]; /**< Primary port buffer space. */ 73 uint8_t kbd_data[BUFFER_SIZE]; /**< Aux. port buffer space. */ 80 /**< I/O registers. */ 81 i8042_regs_t *regs; 82 /** Keyboard port */ 74 83 i8042_port_t *kbd; 84 /** AUX port */ 75 85 i8042_port_t *aux; 76 fibril_mutex_t write_guard; /**< Prevents simultanous port writes.*/ 86 /** Prevents simultanous port writes.*/ 87 fibril_mutex_t write_guard; 77 88 } i8042_t; 78 79 89 80 90 extern int i8042_init(i8042_t *, addr_range_t *, int, int, ddf_dev_t *); -
uspace/drv/char/msim-con/msim-con.c
rf571ca49 rac307b2 37 37 #include <ddi.h> 38 38 #include <errno.h> 39 #include <i pc/char.h>39 #include <io/chardev_srv.h> 40 40 41 41 #include "msim-con.h" 42 42 43 43 static void msim_con_connection(ipc_callid_t, ipc_call_t *, void *); 44 45 static int msim_con_read(chardev_srv_t *, void *, size_t, size_t *); 46 static int msim_con_write(chardev_srv_t *, const void *, size_t, size_t *); 47 48 static chardev_ops_t msim_con_chardev_ops = { 49 .read = msim_con_read, 50 .write = msim_con_write 51 }; 44 52 45 53 static irq_cmd_t msim_cmds_proto[] = { … … 58 66 msim_con_t *con = (msim_con_t *) arg; 59 67 uint8_t c; 68 int rc; 69 70 fibril_mutex_lock(&con->buf_lock); 60 71 61 72 c = IPC_GET_ARG2(*call); 62 63 if ( con->client_sess != NULL) {64 async_exch_t *exch = async_exchange_begin(con->client_sess);65 async_msg_1(exch, CHAR_NOTIF_BYTE, c); 66 async_exchange_end(exch);67 }73 rc = circ_buf_push(&con->cbuf, &c); 74 if (rc != EOK) 75 ddf_msg(LVL_ERROR, "Buffer overrun"); 76 77 fibril_mutex_unlock(&con->buf_lock); 78 fibril_condvar_broadcast(&con->buf_cv); 68 79 } 69 80 … … 75 86 irq_cmd_t *msim_cmds = NULL; 76 87 int rc; 88 89 circ_buf_init(&con->cbuf, con->buf, msim_con_buf_size, 1); 90 fibril_mutex_initialize(&con->buf_lock); 91 fibril_condvar_initialize(&con->buf_cv); 77 92 78 93 msim_cmds = malloc(sizeof(msim_cmds_proto)); … … 106 121 async_irq_subscribe(res->irq, msim_irq_handler, con, &con->irq_code); 107 122 subscribed = true; 123 124 chardev_srvs_init(&con->cds); 125 con->cds.ops = &msim_con_chardev_ops; 126 con->cds.sarg = con; 108 127 109 128 rc = ddf_fun_bind(fun); … … 140 159 } 141 160 161 /** Read from msim console device */ 162 static int msim_con_read(chardev_srv_t *srv, void *buf, size_t size, 163 size_t *nread) 164 { 165 msim_con_t *con = (msim_con_t *) srv->srvs->sarg; 166 size_t p; 167 uint8_t *bp = (uint8_t *) buf; 168 int rc; 169 170 fibril_mutex_lock(&con->buf_lock); 171 172 while (circ_buf_nused(&con->cbuf) == 0) 173 fibril_condvar_wait(&con->buf_cv, &con->buf_lock); 174 175 p = 0; 176 while (p < size) { 177 rc = circ_buf_pop(&con->cbuf, &bp[p]); 178 if (rc != EOK) 179 break; 180 ++p; 181 } 182 183 fibril_mutex_unlock(&con->buf_lock); 184 185 *nread = p; 186 return EOK; 187 } 188 189 /** Write to msim console device */ 190 static int msim_con_write(chardev_srv_t *srv, const void *data, size_t size, 191 size_t *nwr) 192 { 193 msim_con_t *con = (msim_con_t *) srv->srvs->sarg; 194 size_t i; 195 uint8_t *dp = (uint8_t *) data; 196 197 for (i = 0; i < size; i++) 198 msim_con_putchar(con, dp[i]); 199 200 *nwr = size; 201 return EOK; 202 } 203 142 204 /** Character device connection handler. */ 143 205 static void msim_con_connection(ipc_callid_t iid, ipc_call_t *icall, 144 206 void *arg) 145 207 { 146 msim_con_t *con; 147 148 /* Answer the IPC_M_CONNECT_ME_TO call. */ 149 async_answer_0(iid, EOK); 150 151 con = (msim_con_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg)); 152 153 while (true) { 154 ipc_call_t call; 155 ipc_callid_t callid = async_get_call(&call); 156 sysarg_t method = IPC_GET_IMETHOD(call); 157 158 if (!method) { 159 /* The other side has hung up. */ 160 async_answer_0(callid, EOK); 161 return; 162 } 163 164 async_sess_t *sess = 165 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 166 if (sess != NULL) { 167 if (con->client_sess == NULL) { 168 con->client_sess = sess; 169 async_answer_0(callid, EOK); 170 } else 171 async_answer_0(callid, ELIMIT); 172 } else { 173 switch (method) { 174 case CHAR_WRITE_BYTE: 175 ddf_msg(LVL_DEBUG, "Write %" PRIun " to device\n", 176 IPC_GET_ARG1(call)); 177 msim_con_putchar(con, (uint8_t) IPC_GET_ARG1(call)); 178 async_answer_0(callid, EOK); 179 break; 180 default: 181 async_answer_0(callid, EINVAL); 182 } 183 } 184 } 208 msim_con_t *con = (msim_con_t *) ddf_dev_data_get( 209 ddf_fun_get_dev((ddf_fun_t *) arg)); 210 211 chardev_conn(iid, icall, &con->cds); 185 212 } 186 213 -
uspace/drv/char/msim-con/msim-con.h
rf571ca49 rac307b2 36 36 #define MSIM_CON_H 37 37 38 #include <adt/circ_buf.h> 38 39 #include <async.h> 39 40 #include <ddf/driver.h> 41 #include <fibril_synch.h> 42 #include <io/chardev_srv.h> 40 43 #include <loc.h> 41 44 #include <stdint.h> 45 46 enum { 47 msim_con_buf_size = 64 48 }; 42 49 43 50 /** MSIM console resources */ … … 51 58 async_sess_t *client_sess; 52 59 ddf_dev_t *dev; 60 chardev_srvs_t cds; 53 61 msim_con_res_t res; 54 62 irq_pio_range_t irq_range[1]; 55 63 irq_code_t irq_code; 64 circ_buf_t cbuf; 65 uint8_t buf[msim_con_buf_size]; 66 fibril_mutex_t buf_lock; 67 fibril_condvar_t buf_cv; 56 68 } msim_con_t; 57 69 -
uspace/drv/char/ns8250/ns8250.c
rf571ca49 rac307b2 1 1 /* 2 2 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2017 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 53 53 #include <ddf/interrupt.h> 54 54 #include <ddf/log.h> 55 #include < ops/char_dev.h>55 #include <io/chardev_srv.h> 56 56 57 57 #include <device/hw_res.h> … … 153 153 /** DDF function node */ 154 154 ddf_fun_t *fun; 155 /** Character device service */ 156 chardev_srvs_t cds; 155 157 /** Parent session */ 156 158 async_sess_t *parent_sess; … … 189 191 } 190 192 193 /** Obtain soft-state structure from chardev srv */ 194 static ns8250_t *srv_ns8250(chardev_srv_t *srv) 195 { 196 return (ns8250_t *)srv->srvs->sarg; 197 } 198 199 191 200 /** Find out if there is some incoming data available on the serial port. 192 201 * … … 234 243 /** Read data from the serial port device. 235 244 * 236 * @param fun The serial port function245 * @param srv Server-side connection data 237 246 * @param buf The output buffer for read data. 238 247 * @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 */ 252 static 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 } 249 262 250 263 fibril_mutex_lock(&ns->mutex); 251 264 while (buf_is_empty(&ns->input_buffer)) 252 265 fibril_condvar_wait(&ns->input_buffer_available, &ns->mutex); 253 while (!buf_is_empty(&ns->input_buffer) && (size_t)ret< count) {254 b uf[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++; 256 269 } 257 270 fibril_mutex_unlock(&ns->mutex); 258 271 259 return ret; 272 *nread = pos; 273 return EOK; 260 274 } 261 275 … … 274 288 /** Write data to the serial port. 275 289 * 276 * @param fun The serial port function290 * @param srv Server-side connection data 277 291 * @param buf The data to be written 278 292 * @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 */ 296 static 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); 284 300 size_t idx; 301 uint8_t *bp = (uint8_t *) buf; 285 302 286 303 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 310 static int ns8250_open(chardev_srvs_t *, chardev_srv_t *); 311 static int ns8250_close(chardev_srv_t *); 312 static void ns8250_default_handler(chardev_srv_t *, ipc_callid_t, ipc_call_t *); 293 313 294 314 /** The character interface's callbacks. */ 295 static char_dev_ops_t ns8250_char_dev_ops = { 296 .read = &ns8250_read, 297 .write = &ns8250_write 315 static 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 298 321 }; 322 323 static void ns8250_char_conn(ipc_callid_t, ipc_call_t *, void *); 299 324 300 325 static int ns8250_dev_add(ddf_dev_t *dev); … … 872 897 } 873 898 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 876 905 rc = ddf_fun_bind(fun); 877 906 if (rc != EOK) { … … 930 959 * device. 931 960 * 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 */ 964 static int ns8250_open(chardev_srvs_t *srvs, chardev_srv_t *srv) 965 { 966 ns8250_t *ns = srv_ns8250(srv); 937 967 int res; 938 968 … … 954 984 * the device. 955 985 * 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 */ 988 static int ns8250_close(chardev_srv_t *srv) 989 { 990 ns8250_t *data = srv_ns8250(srv); 961 991 962 992 fibril_mutex_lock(&data->mutex); … … 968 998 969 999 fibril_mutex_unlock(&data->mutex); 1000 1001 return EOK; 970 1002 } 971 1003 … … 1034 1066 * Configure the parameters of the serial communication. 1035 1067 */ 1036 static void ns8250_default_handler( ddf_fun_t *fun, ipc_callid_t callid,1068 static void ns8250_default_handler(chardev_srv_t *srv, ipc_callid_t callid, 1037 1069 ipc_call_t *call) 1038 1070 { 1071 ns8250_t *ns8250 = srv_ns8250(srv); 1039 1072 sysarg_t method = IPC_GET_IMETHOD(*call); 1040 1073 int ret; … … 1043 1076 switch (method) { 1044 1077 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, 1046 1079 &stop_bits); 1047 1080 async_answer_4(callid, EOK, baud_rate, parity, word_length, … … 1054 1087 word_length = IPC_GET_ARG3(*call); 1055 1088 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, 1057 1090 stop_bits); 1058 1091 async_answer_0(callid, ret); … … 1064 1097 } 1065 1098 1099 void 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 1066 1106 /** Initialize the serial port driver. 1067 1107 * … … 1072 1112 { 1073 1113 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;1080 1114 } 1081 1115 -
uspace/drv/char/ski-con/ski-con.c
rf571ca49 rac307b2 1 1 /* 2 2 * Copyright (c) 2005 Jakub Jermar 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2017 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 34 34 #include <ddf/log.h> 35 35 #include <errno.h> 36 #include <ipc/char.h> 36 #include <fibril.h> 37 #include <io/chardev.h> 37 38 #include <stdint.h> 38 39 #include <stdlib.h> 39 #include <thread.h>40 40 #include <stdbool.h> 41 41 … … 46 46 #define POLL_INTERVAL 10000 47 47 48 static void ski_con_thread_impl(void *arg);48 static int ski_con_fibril(void *arg); 49 49 static int32_t ski_con_getchar(void); 50 50 static void ski_con_connection(ipc_callid_t, ipc_call_t *, void *); 51 51 52 static int ski_con_read(chardev_srv_t *, void *, size_t, size_t *); 53 static int ski_con_write(chardev_srv_t *, const void *, size_t, size_t *); 54 55 static chardev_ops_t ski_con_chardev_ops = { 56 .read = ski_con_read, 57 .write = ski_con_write 58 }; 59 52 60 /** Add ski console device. */ 53 61 int ski_con_add(ski_con_t *con) 54 62 { 55 thread_id_t tid;63 fid_t fid; 56 64 ddf_fun_t *fun = NULL; 57 65 bool bound = false; 58 66 int rc; 67 68 circ_buf_init(&con->cbuf, con->buf, ski_con_buf_size, 1); 69 fibril_mutex_initialize(&con->buf_lock); 70 fibril_condvar_initialize(&con->buf_cv); 59 71 60 72 fun = ddf_fun_create(con->dev, fun_exposed, "a"); … … 67 79 ddf_fun_set_conn_handler(fun, ski_con_connection); 68 80 81 chardev_srvs_init(&con->cds); 82 con->cds.ops = &ski_con_chardev_ops; 83 con->cds.sarg = con; 84 69 85 rc = ddf_fun_bind(fun); 70 86 if (rc != EOK) { … … 75 91 bound = true; 76 92 77 rc = thread_create(ski_con_thread_impl, con, "kbd_poll", &tid); 78 if (rc != 0) { 79 return rc; 80 } 81 93 fid = fibril_create(ski_con_fibril, con); 94 if (fid == 0) { 95 ddf_msg(LVL_ERROR, "Error creating fibril."); 96 rc = ENOMEM; 97 goto error; 98 } 99 100 fibril_add_ready(fid); 82 101 return EOK; 83 102 error: … … 102 121 } 103 122 104 /** Thread to poll Ski for keypresses. */105 static void ski_con_thread_impl(void *arg)123 /** Poll Ski for keypresses. */ 124 static int ski_con_fibril(void *arg) 106 125 { 107 126 int32_t c; 108 127 ski_con_t *con = (ski_con_t *) arg; 128 int rc; 109 129 110 130 while (1) { … … 114 134 break; 115 135 116 if (con->client_sess != NULL) { 117 async_exch_t *exch = async_exchange_begin(con->client_sess); 118 async_msg_1(exch, CHAR_NOTIF_BYTE, c); 119 async_exchange_end(exch); 120 } 136 fibril_mutex_lock(&con->buf_lock); 137 138 rc = circ_buf_push(&con->cbuf, &c); 139 if (rc != EOK) 140 ddf_msg(LVL_ERROR, "Buffer overrun"); 141 142 fibril_mutex_unlock(&con->buf_lock); 143 fibril_condvar_broadcast(&con->buf_cv); 121 144 } 122 145 123 thread_usleep(POLL_INTERVAL); 124 } 146 fibril_usleep(POLL_INTERVAL); 147 } 148 149 return 0; 125 150 } 126 151 … … 157 182 } 158 183 184 /** Read from Ski console device */ 185 static int ski_con_read(chardev_srv_t *srv, void *buf, size_t size, 186 size_t *nread) 187 { 188 ski_con_t *con = (ski_con_t *) srv->srvs->sarg; 189 size_t p; 190 uint8_t *bp = (uint8_t *) buf; 191 int rc; 192 193 fibril_mutex_lock(&con->buf_lock); 194 195 while (circ_buf_nused(&con->cbuf) == 0) 196 fibril_condvar_wait(&con->buf_cv, &con->buf_lock); 197 198 p = 0; 199 while (p < size) { 200 rc = circ_buf_pop(&con->cbuf, &bp[p]); 201 if (rc != EOK) 202 break; 203 ++p; 204 } 205 206 fibril_mutex_unlock(&con->buf_lock); 207 208 *nread = p; 209 return EOK; 210 } 211 212 /** Write to Ski console device */ 213 static int ski_con_write(chardev_srv_t *srv, const void *data, size_t size, 214 size_t *nwr) 215 { 216 ski_con_t *con = (ski_con_t *) srv->srvs->sarg; 217 size_t i; 218 uint8_t *dp = (uint8_t *) data; 219 220 for (i = 0; i < size; i++) 221 ski_con_putchar(con, dp[i]); 222 223 *nwr = size; 224 return EOK; 225 } 226 159 227 /** Character device connection handler. */ 160 228 static void ski_con_connection(ipc_callid_t iid, ipc_call_t *icall, 161 229 void *arg) 162 230 { 163 ski_con_t *con; 164 165 /* Answer the IPC_M_CONNECT_ME_TO call. */ 166 async_answer_0(iid, EOK); 167 168 con = (ski_con_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg)); 169 170 while (true) { 171 ipc_call_t call; 172 ipc_callid_t callid = async_get_call(&call); 173 sysarg_t method = IPC_GET_IMETHOD(call); 174 175 if (!method) { 176 /* The other side has hung up. */ 177 async_answer_0(callid, EOK); 178 return; 179 } 180 181 async_sess_t *sess = 182 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 183 if (sess != NULL) { 184 if (con->client_sess == NULL) { 185 con->client_sess = sess; 186 async_answer_0(callid, EOK); 187 } else 188 async_answer_0(callid, ELIMIT); 189 } else { 190 switch (method) { 191 case CHAR_WRITE_BYTE: 192 ddf_msg(LVL_DEBUG, "Write %" PRIun " to device\n", 193 IPC_GET_ARG1(call)); 194 ski_con_putchar(con, (uint8_t) IPC_GET_ARG1(call)); 195 async_answer_0(callid, EOK); 196 break; 197 default: 198 async_answer_0(callid, EINVAL); 199 } 200 } 201 } 231 ski_con_t *con = (ski_con_t *) ddf_dev_data_get( 232 ddf_fun_get_dev((ddf_fun_t *) arg)); 233 234 chardev_conn(iid, icall, &con->cds); 202 235 } 203 236 -
uspace/drv/char/ski-con/ski-con.h
rf571ca49 rac307b2 36 36 #define SKI_CON_H 37 37 38 #include <adt/circ_buf.h> 38 39 #include <async.h> 39 40 #include <ddf/driver.h> 41 #include <io/chardev_srv.h> 40 42 #include <loc.h> 41 43 #include <stdint.h> 44 45 enum { 46 ski_con_buf_size = 64 47 }; 42 48 43 49 /** Ski console */ … … 45 51 async_sess_t *client_sess; 46 52 ddf_dev_t *dev; 53 chardev_srvs_t cds; 54 circ_buf_t cbuf; 55 uint8_t buf[ski_con_buf_size]; 56 fibril_mutex_t buf_lock; 57 fibril_condvar_t buf_cv; 47 58 } ski_con_t; 48 59 -
uspace/drv/char/sun4v-con/sun4v-con.c
rf571ca49 rac307b2 1 1 /* 2 2 * Copyright (c) 2008 Pavel Rimsky 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2017 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 36 36 #include <ddi.h> 37 37 #include <errno.h> 38 #include <i pc/char.h>38 #include <io/chardev_srv.h> 39 39 #include <stdbool.h> 40 40 #include <thread.h> … … 62 62 static input_buffer_t input_buffer; 63 63 64 static void sun4v_thread_impl(void *arg); 64 static int sun4v_con_read(chardev_srv_t *, void *, size_t, size_t *); 65 static int sun4v_con_write(chardev_srv_t *, const void *, size_t, size_t *); 66 67 static chardev_ops_t sun4v_con_chardev_ops = { 68 .read = sun4v_con_read, 69 .write = sun4v_con_write 70 }; 65 71 66 72 static void sun4v_con_putchar(sun4v_con_t *con, uint8_t data) … … 86 92 } 87 93 94 chardev_srvs_init(&con->cds); 95 con->cds.ops = &sun4v_con_chardev_ops; 96 con->cds.sarg = con; 97 88 98 ddf_fun_set_conn_handler(fun, sun4v_con_connection); 89 99 … … 94 104 goto error; 95 105 } 96 97 thread_id_t tid;98 rc = thread_create(sun4v_thread_impl, con, "kbd_poll", &tid);99 if (rc != EOK)100 goto error;101 106 102 107 rc = ddf_fun_bind(fun); … … 131 136 } 132 137 133 /** 134 * Called regularly by the polling thread. Reads codes of all the 135 * pressed keys from the buffer. 136 */ 137 static void sun4v_key_pressed(sun4v_con_t *con) 138 /** Read from Sun4v console device */ 139 static int sun4v_con_read(chardev_srv_t *srv, void *buf, size_t size, 140 size_t *nread) 138 141 { 142 size_t p; 143 uint8_t *bp = (uint8_t *) buf; 139 144 char c; 140 145 141 while (input_buffer->read_ptr != input_buffer->write_ptr) { 146 while (input_buffer->read_ptr == input_buffer->write_ptr) 147 fibril_usleep(POLL_INTERVAL); 148 149 p = 0; 150 while (p < size && input_buffer->read_ptr != input_buffer->write_ptr) { 142 151 c = input_buffer->data[input_buffer->read_ptr]; 143 152 input_buffer->read_ptr = 144 153 ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE; 145 if (con->client_sess != NULL) { 146 async_exch_t *exch = async_exchange_begin(con->client_sess); 147 async_msg_1(exch, CHAR_NOTIF_BYTE, c); 148 async_exchange_end(exch); 149 } 150 (void) c; 154 bp[p++] = c; 151 155 } 156 157 *nread = p; 158 return EOK; 152 159 } 153 160 154 /** 155 * Thread to poll Sun4v console for keypresses. 156 */ 157 static void sun4v_thread_impl(void *arg) 161 /** Write to Sun4v console device */ 162 static int sun4v_con_write(chardev_srv_t *srv, const void *data, size_t size, 163 size_t *nwr) 158 164 { 159 sun4v_con_t *con = (sun4v_con_t *) arg; 165 sun4v_con_t *con = (sun4v_con_t *) srv->srvs->sarg; 166 size_t i; 167 uint8_t *dp = (uint8_t *) data; 160 168 161 while (true) { 162 sun4v_key_pressed(con); 163 thread_usleep(POLL_INTERVAL); 164 } 169 for (i = 0; i < size; i++) 170 sun4v_con_putchar(con, dp[i]); 171 172 *nwr = size; 173 return EOK; 165 174 } 166 175 … … 169 178 void *arg) 170 179 { 171 sun4v_con_t *con; 180 sun4v_con_t *con = (sun4v_con_t *) ddf_dev_data_get( 181 ddf_fun_get_dev((ddf_fun_t *) arg)); 172 182 173 /* Answer the IPC_M_CONNECT_ME_TO call. */ 174 async_answer_0(iid, EOK); 175 176 con = (sun4v_con_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg)); 177 178 while (true) { 179 ipc_call_t call; 180 ipc_callid_t callid = async_get_call(&call); 181 sysarg_t method = IPC_GET_IMETHOD(call); 182 183 if (!method) { 184 /* The other side has hung up. */ 185 async_answer_0(callid, EOK); 186 return; 187 } 188 189 async_sess_t *sess = 190 async_callback_receive_start(EXCHANGE_SERIALIZE, &call); 191 if (sess != NULL) { 192 if (con->client_sess == NULL) { 193 con->client_sess = sess; 194 async_answer_0(callid, EOK); 195 } else 196 async_answer_0(callid, ELIMIT); 197 } else { 198 switch (method) { 199 case CHAR_WRITE_BYTE: 200 ddf_msg(LVL_DEBUG, "Write %" PRIun " to device\n", 201 IPC_GET_ARG1(call)); 202 sun4v_con_putchar(con, (uint8_t) IPC_GET_ARG1(call)); 203 async_answer_0(callid, EOK); 204 break; 205 default: 206 async_answer_0(callid, EINVAL); 207 } 208 } 209 } 183 chardev_conn(iid, icall, &con->cds); 210 184 } 211 185 -
uspace/drv/char/sun4v-con/sun4v-con.h
rf571ca49 rac307b2 38 38 #include <async.h> 39 39 #include <ddf/driver.h> 40 #include <io/chardev_srv.h> 40 41 #include <loc.h> 41 42 #include <stdint.h> … … 50 51 async_sess_t *client_sess; 51 52 ddf_dev_t *dev; 53 chardev_srvs_t cds; 52 54 sun4v_con_res_t res; 53 55 } sun4v_con_t; -
uspace/drv/root/virt/devices.def
rf571ca49 rac307b2 26 26 }, 27 27 { 28 .name = "null",29 .match_id = "virtual&test1"30 },31 {32 28 .name = "test3", 33 29 .match_id = "virtual&test3" -
uspace/drv/test/test1/Makefile
rf571ca49 rac307b2 32 32 33 33 SOURCES = \ 34 char.c \35 34 test1.c 36 35 -
uspace/drv/test/test1/test1.c
rf571ca49 rac307b2 177 177 ddf_fun_add_to_category(fun_a, "virtual"); 178 178 179 if (str_cmp(dev_name, "null") == 0) { 180 ddf_fun_set_ops(fun_a, &char_device_ops); 181 ddf_fun_add_to_category(fun_a, "virt-null"); 182 } else if (str_cmp(dev_name, "test1") == 0) { 179 if (str_cmp(dev_name, "test1") == 0) { 183 180 (void) register_fun_verbose(dev, 184 181 "cloning myself ;-)", "clone", -
uspace/drv/test/test1/test1.h
rf571ca49 rac307b2 36 36 #define NAME "test1" 37 37 38 extern ddf_dev_ops_t char_device_ops;39 40 38 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
