Changeset e7588a8 in mainline
- Timestamp:
- 2017-11-24T02:21:56Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0851a3d
- Parents:
- 221176c1
- Location:
- uspace/drv/char/i8042
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
r221176c1 re7588a8 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) ?138 circ_buf_t *cbuf = (status & i8042_AUX_DATA) ? 137 139 &controller->aux_buffer : &controller->kbd_buffer; 138 139 buffer_write(buffer, data); 140 i8042_port_t *port = (status & i8042_AUX_DATA) ? 141 controller->aux : controller->kbd; 142 143 fibril_mutex_lock(&port->buf_lock); 144 145 rc = circ_buf_push(cbuf, &data); 146 if (rc != EOK) 147 ddf_msg(LVL_ERROR, "Buffer overrun"); 148 149 fibril_mutex_unlock(&port->buf_lock); 150 fibril_condvar_broadcast(&port->buf_cv); 140 151 } 141 152 … … 194 205 dev->kbd->cds.ops = &i8042_chardev_ops; 195 206 dev->kbd->cds.sarg = dev->kbd; 207 fibril_mutex_initialize(&dev->kbd->buf_lock); 208 fibril_condvar_initialize(&dev->kbd->buf_cv); 196 209 197 210 rc = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90); … … 215 228 dev->aux->cds.ops = &i8042_chardev_ops; 216 229 dev->aux->cds.sarg = dev->aux; 230 fibril_mutex_initialize(&dev->aux->buf_lock); 231 fibril_condvar_initialize(&dev->aux->buf_cv); 217 232 218 233 rc = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90); … … 223 238 ddf_fun_set_conn_handler(dev->aux_fun, i8042_char_conn); 224 239 225 buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE);226 buffer_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE);240 circ_buf_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE, 1); 241 circ_buf_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE, 1); 227 242 fibril_mutex_initialize(&dev->write_guard); 228 243 … … 377 392 { 378 393 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 394 size_t p; 379 395 i8042_t *i8042 = port->ctl; 380 396 uint8_t *destp = (uint8_t *)dest; 381 397 int rc; 382 size_t i; 383 384 buffer_t *buffer = (port == i8042->aux) ? 398 399 circ_buf_t *cbuf = (port == i8042->aux) ? 385 400 &i8042->aux_buffer : &i8042->kbd_buffer; 386 401 387 for (i = 0; i < size; ++i) { 388 rc = buffer_read(buffer, destp, i == 0); 402 fibril_mutex_lock(&port->buf_lock); 403 404 while (circ_buf_nused(cbuf) == 0) 405 fibril_condvar_wait(&port->buf_cv, &port->buf_lock); 406 407 p = 0; 408 while (p < size) { 409 rc = circ_buf_pop(cbuf, &destp[p]); 389 410 if (rc != EOK) 390 411 break; 391 ++destp; 392 } 393 394 *nread = i; 412 ++p; 413 } 414 415 fibril_mutex_unlock(&port->buf_lock); 416 417 *nread = p; 395 418 return EOK; 396 419 } -
uspace/drv/char/i8042/i8042.h
r221176c1 re7588a8 40 40 #define i8042_H_ 41 41 42 #include <adt/circ_buf.h> 42 43 #include <io/chardev_srv.h> 43 44 #include <ddi.h> 44 45 #include <fibril_synch.h> 45 46 #include <ddf/driver.h> 46 #include "buffer.h"47 47 48 48 #define NAME "i8042" … … 61 61 struct i8042 *ctl; /**< Controller */ 62 62 chardev_srvs_t cds; /**< Character device server data */ 63 fibril_mutex_t buf_lock; /**< Protect buffer */ 64 fibril_condvar_t buf_cv; /**< Signal new data in buffer */ 63 65 } i8042_port_t; 64 66 … … 68 70 ddf_fun_t *kbd_fun; /**< Pirmary port device function. */ 69 71 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 circ_buf_t kbd_buffer; /**< Primary port buffer. */ 73 circ_buf_t aux_buffer; /**< Aux. port buffer. */ 72 74 uint8_t aux_data[BUFFER_SIZE]; /**< Primary port buffer space. */ 73 75 uint8_t kbd_data[BUFFER_SIZE]; /**< Aux. port buffer space. */
Note:
See TracChangeset
for help on using the changeset viewer.