Changes in uspace/drv/char/i8042/i8042.c [75751db6:8820544] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
r75751db6 r8820544 2 2 * Copyright (c) 2001-2004 Jakub Jermar 3 3 * Copyright (c) 2006 Josef Cejka 4 * Copyright (c) 20 14Jiri Svoboda4 * Copyright (c) 2009 Jiri Svoboda 5 5 * Copyright (c) 2011 Jan Vesely 6 6 * All rights reserved. … … 39 39 */ 40 40 41 #include <ddf/log.h> 42 #include <ddf/interrupt.h> 41 #include <device/hw_res.h> 43 42 #include <ddi.h> 44 #include <device/hw_res.h>45 43 #include <errno.h> 46 44 #include <str_error.h> 47 45 #include <inttypes.h> 48 #include < io/chardev_srv.h>49 46 #include <ddf/log.h> 47 #include <ddf/interrupt.h> 50 48 #include "i8042.h" 51 49 … … 66 64 #define i8042_KBD_TRANSLATE 0x40 /* Use this to switch to XT scancodes */ 67 65 68 static void i8042_char_conn(ipc_callid_t, ipc_call_t *, void *); 69 static int i8042_read(chardev_srv_t *, void *, size_t); 70 static int i8042_write(chardev_srv_t *, const void *, size_t); 71 72 static chardev_ops_t i8042_chardev_ops = { 73 .read = i8042_read, 74 .write = i8042_write 66 static void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 67 68 /** Port function operations. */ 69 static ddf_dev_ops_t ops = { 70 .default_handler = default_handler 75 71 }; 76 72 … … 110 106 }; 111 107 108 /** Get i8042 soft state from device node. */ 109 static i8042_t *dev_i8042(ddf_dev_t *dev) 110 { 111 return ddf_dev_data_get(dev); 112 } 113 112 114 /** Wait until it is safe to write to the device. */ 113 115 static void wait_ready(i8042_t *dev) … … 129 131 ddf_dev_t *dev) 130 132 { 131 i8042_t *controller = d df_dev_data_get(dev);133 i8042_t *controller = dev_i8042(dev); 132 134 133 135 const uint8_t status = IPC_GET_ARG1(*call); … … 184 186 }; 185 187 186 dev->kbd = ddf_fun_data_alloc(dev->kbd_fun, sizeof(i8042_port_t));187 if (dev->kbd == NULL) {188 rc = ENOMEM;189 goto error;190 }191 192 dev->kbd->ctl = dev;193 chardev_srvs_init(&dev->kbd->cds);194 dev->kbd->cds.ops = &i8042_chardev_ops;195 dev->kbd->cds.sarg = dev->kbd;196 197 188 rc = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90); 198 189 if (rc != EOK) … … 205 196 } 206 197 207 dev->aux = ddf_fun_data_alloc(dev->aux_fun, sizeof(i8042_port_t));208 if (dev->aux == NULL) {209 rc = ENOMEM;210 goto error;211 }212 213 dev->aux->ctl = dev;214 chardev_srvs_init(&dev->aux->cds);215 dev->aux->cds.ops = &i8042_chardev_ops;216 dev->aux->cds.sarg = dev->aux;217 218 198 rc = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90); 219 199 if (rc != EOK) 220 200 goto error; 221 201 222 ddf_fun_set_ conn_handler(dev->kbd_fun, i8042_char_conn);223 ddf_fun_set_ conn_handler(dev->aux_fun, i8042_char_conn);202 ddf_fun_set_ops(dev->kbd_fun, &ops); 203 ddf_fun_set_ops(dev->aux_fun, &ops); 224 204 225 205 buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE); … … 318 298 } 319 299 300 // FIXME TODO use shared instead this 301 enum { 302 IPC_CHAR_READ = DEV_FIRST_CUSTOM_METHOD, 303 IPC_CHAR_WRITE, 304 }; 305 320 306 /** Write data to i8042 port. 321 307 * 322 * @param srv Connection-specific data323 * @param buffer Data source 324 * @param size Data size 308 * @param fun DDF function. 309 * @param buffer Data source. 310 * @param size Data size. 325 311 * 326 312 * @return Bytes written. 327 313 * 328 314 */ 329 static int i8042_write(chardev_srv_t *srv, const void *data, size_t size) 330 { 331 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 332 i8042_t *i8042 = port->ctl; 333 const char *dp = (const char *)data; 334 335 fibril_mutex_lock(&i8042->write_guard); 315 static int i8042_write(ddf_fun_t *fun, char *buffer, size_t size) 316 { 317 i8042_t *controller = dev_i8042(ddf_fun_get_dev(fun)); 318 fibril_mutex_lock(&controller->write_guard); 336 319 337 320 for (size_t i = 0; i < size; ++i) { 338 if ( port == i8042->aux) {339 wait_ready( i8042);340 pio_write_8(& i8042->regs->status,321 if (controller->aux_fun == fun) { 322 wait_ready(controller); 323 pio_write_8(&controller->regs->status, 341 324 i8042_CMD_WRITE_AUX); 342 325 } 343 326 344 wait_ready( i8042);345 pio_write_8(& i8042->regs->data, dp[i]);346 } 347 348 fibril_mutex_unlock(& i8042->write_guard);327 wait_ready(controller); 328 pio_write_8(&controller->regs->data, buffer[i]); 329 } 330 331 fibril_mutex_unlock(&controller->write_guard); 349 332 return size; 350 333 } … … 352 335 /** Read data from i8042 port. 353 336 * 354 * @param srv Connection-specific data355 * @param buffer Data place 356 * @param size Data place size 337 * @param fun DDF function. 338 * @param buffer Data place. 339 * @param size Data place size. 357 340 * 358 341 * @return Bytes read. 359 342 * 360 343 */ 361 static int i8042_read(chardev_srv_t *srv, void *dest, size_t size) 362 { 363 i8042_port_t *port = (i8042_port_t *)srv->srvs->sarg; 364 i8042_t *i8042 = port->ctl; 365 uint8_t *destp = (uint8_t *)dest; 366 367 buffer_t *buffer = (port == i8042->aux) ? 368 &i8042->aux_buffer : &i8042->kbd_buffer; 344 static int i8042_read(ddf_fun_t *fun, char *data, size_t size) 345 { 346 i8042_t *controller = dev_i8042(ddf_fun_get_dev(fun)); 347 buffer_t *buffer = (fun == controller->aux_fun) ? 348 &controller->aux_buffer : &controller->kbd_buffer; 369 349 370 350 for (size_t i = 0; i < size; ++i) 371 *d estp++ = buffer_read(buffer);351 *data++ = buffer_read(buffer); 372 352 373 353 return size; … … 376 356 /** Handle data requests. 377 357 * 358 * @param fun ddf_fun_t function. 378 359 * @param id callid 379 360 * @param call IPC request. 380 * @param arg ddf_fun_t function. 381 */ 382 void i8042_char_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 383 { 384 i8042_port_t *port = ddf_fun_data_get((ddf_fun_t *)arg); 385 386 chardev_conn(iid, icall, &port->cds); 361 * 362 */ 363 static void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call) 364 { 365 const sysarg_t method = IPC_GET_IMETHOD(*call); 366 const size_t size = IPC_GET_ARG1(*call); 367 368 switch (method) { 369 case IPC_CHAR_READ: 370 if (size <= 4 * sizeof(sysarg_t)) { 371 sysarg_t message[4] = {}; 372 373 i8042_read(fun, (char *) message, size); 374 async_answer_4(id, size, message[0], message[1], 375 message[2], message[3]); 376 } else 377 async_answer_0(id, ELIMIT); 378 break; 379 380 case IPC_CHAR_WRITE: 381 if (size <= 3 * sizeof(sysarg_t)) { 382 const sysarg_t message[3] = { 383 IPC_GET_ARG2(*call), 384 IPC_GET_ARG3(*call), 385 IPC_GET_ARG4(*call) 386 }; 387 388 i8042_write(fun, (char *) message, size); 389 async_answer_0(id, size); 390 } else 391 async_answer_0(id, ELIMIT); 392 393 default: 394 async_answer_0(id, EINVAL); 395 } 387 396 } 388 397
Note:
See TracChangeset
for help on using the changeset viewer.