Changeset a455321 in mainline
- Timestamp:
- 2012-01-04T00:13:53Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22e4e9b
- Parents:
- ecc6323
- Location:
- uspace/drv/char
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/char/i8042/i8042.c
recc6323 ra455321 55 55 static int i8042_write_kbd(ddf_fun_t *, char *, size_t); 56 56 static int i8042_read_kbd(ddf_fun_t *, char *, size_t); 57 static int i8042_write_aux(ddf_fun_t *, char *, size_t);58 static int i8042_read_aux(ddf_fun_t *, char *, size_t);59 57 60 58 /** Primary port interface structure. */ … … 64 62 }; 65 63 66 /** Auxiliary port interface structure. */ 67 static char_dev_ops_t aux_iface = { 68 .read = i8042_read_aux, 69 .write = i8042_write_aux, 70 }; 64 void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 71 65 72 66 /** Primary port function operations. */ 73 67 static ddf_dev_ops_t kbd_ops = { 74 .interfaces[CHAR_DEV_IFACE] = &kbd_iface 68 .interfaces[CHAR_DEV_IFACE] = &kbd_iface, 69 .default_handler = default_handler, 75 70 }; 76 71 77 72 /** Auxiliary port function operations. */ 78 static ddf_dev_ops_t aux_ops = {79 . interfaces[CHAR_DEV_IFACE] = &aux_iface73 static ddf_dev_ops_t ops = { 74 .default_handler = default_handler, 80 75 }; 81 76 … … 181 176 } 182 177 183 dev-> mouse_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b");184 if (!dev-> mouse_fun) {178 dev->aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b"); 179 if (!dev->aux_fun) { 185 180 ddf_fun_destroy(dev->kbd_fun); 186 181 return ENOMEM; 187 182 } 188 183 189 ret = ddf_fun_add_match_id(dev-> mouse_fun, "char/ps2mouse", 90);184 ret = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90); 190 185 if (ret != EOK) { 191 186 ddf_fun_destroy(dev->kbd_fun); 192 ddf_fun_destroy(dev-> mouse_fun);187 ddf_fun_destroy(dev->aux_fun); 193 188 return ret; 194 189 } 195 190 196 191 dev->kbd_fun->ops = &kbd_ops; 197 dev-> mouse_fun->ops = &aux_ops;192 dev->aux_fun->ops = &ops; 198 193 dev->kbd_fun->driver_data = dev; 199 dev-> mouse_fun->driver_data = dev;194 dev->aux_fun->driver_data = dev; 200 195 201 196 buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE); … … 210 205 ddf_fun_destroy(dev->kbd_fun); \ 211 206 } \ 212 if (dev-> mouse_fun) { \213 dev-> mouse_fun->driver_data = NULL; \214 ddf_fun_destroy(dev-> mouse_fun); \207 if (dev->aux_fun) { \ 208 dev->aux_fun->driver_data = NULL; \ 209 ddf_fun_destroy(dev->aux_fun); \ 215 210 } \ 216 211 } else (void)0 … … 220 215 "Failed to bind keyboard function: %s.", str_error(ret)); 221 216 222 ret = ddf_fun_bind(dev-> mouse_fun);217 ret = ddf_fun_bind(dev->aux_fun); 223 218 CHECK_RET_DESTROY(ret, 224 219 "Failed to bind mouse function: %s.", str_error(ret)); … … 242 237 ddf_fun_destroy(dev->kbd_fun); \ 243 238 } \ 244 if (dev-> mouse_fun) { \245 ddf_fun_unbind(dev-> mouse_fun); \246 dev-> mouse_fun->driver_data = NULL; \247 ddf_fun_destroy(dev-> mouse_fun); \239 if (dev->aux_fun) { \ 240 ddf_fun_unbind(dev->aux_fun); \ 241 dev->aux_fun->driver_data = NULL; \ 242 ddf_fun_destroy(dev->aux_fun); \ 248 243 } \ 249 244 } else (void)0 … … 328 323 } 329 324 330 /** Write data to i8042 auxiliary port. 325 // TODO use shared instead of own copy 326 enum { 327 IPC_CHAR_READ = DEV_FIRST_CUSTOM_METHOD, 328 IPC_CHAR_WRITE, 329 }; 330 331 /** Write data to i8042 port. 331 332 * @param fun DDF function. 332 333 * @param buffer Data source. … … 334 335 * @return Bytes written. 335 336 */ 336 static int i8042_write _aux(ddf_fun_t *fun, char *buffer, size_t size)337 static int i8042_write(ddf_fun_t *fun, char *buffer, size_t size) 337 338 { 338 339 assert(fun); … … 342 343 for (size_t i = 0; i < size; ++i) { 343 344 wait_ready(controller); 344 pio_write_8(&controller->regs->status, i8042_CMD_WRITE_AUX); 345 if (controller->aux_fun == fun) 346 pio_write_8( 347 &controller->regs->status, i8042_CMD_WRITE_AUX); 345 348 pio_write_8(&controller->regs->data, buffer[i]); 346 349 } … … 349 352 } 350 353 351 /** Read data from i8042 auxiliaryport.354 /** Read data from i8042 port. 352 355 * @param fun DDF function. 353 356 * @param buffer Data place. … … 355 358 * @return Bytes read. 356 359 */ 357 static int i8042_read _aux(ddf_fun_t *fun, char *buffer, size_t size)360 static int i8042_read(ddf_fun_t *fun, char *data, size_t size) 358 361 { 359 362 assert(fun); 360 363 assert(fun->driver_data); 361 bzero(buffer, size);362 364 363 365 i8042_t *controller = fun->driver_data; 366 buffer_t *buffer = (fun == controller->aux_fun) ? 367 &controller->aux_buffer : &controller->kbd_buffer; 364 368 for (size_t i = 0; i < size; ++i) { 365 * buffer++ = buffer_read(&controller->aux_buffer);369 *data++ = buffer_read(buffer); 366 370 } 367 371 return size; 372 } 373 374 void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call) 375 { 376 const sysarg_t method = IPC_GET_IMETHOD(*call); 377 const size_t size = IPC_GET_ARG1(*call); 378 switch (method) { 379 case IPC_CHAR_READ: 380 if (size <= 4 * sizeof(sysarg_t)) { 381 sysarg_t message[4] = { 0 }; 382 i8042_read(fun, (char*)message, size); 383 async_answer_4(id, size, message[0], message[1], 384 message[2], message[3]); 385 } else { 386 async_answer_0(id, ELIMIT); 387 } 388 break; 389 390 case IPC_CHAR_WRITE: 391 if (size <= 3 * sizeof(sysarg_t)) { 392 const sysarg_t message[3] = { 393 IPC_GET_ARG2(*call), IPC_GET_ARG3(*call), 394 IPC_GET_ARG4(*call) }; 395 i8042_write(fun, (char*)message, size); 396 async_answer_0(id, size); 397 } else { 398 async_answer_0(id, ELIMIT); 399 } 400 401 default: 402 async_answer_0(id, EINVAL); 403 } 368 404 } 369 405 /** -
uspace/drv/char/i8042/i8042.h
recc6323 ra455321 57 57 i8042_regs_t *regs; /**< I/O registers. */ 58 58 ddf_fun_t *kbd_fun; /**< Pirmary port device function. */ 59 ddf_fun_t * mouse_fun; /**< Auxiliary port device function. */59 ddf_fun_t *aux_fun; /**< Auxiliary port device function. */ 60 60 buffer_t kbd_buffer; /**< Primary port buffer. */ 61 61 buffer_t aux_buffer; /**< Aux. port buffer. */ -
uspace/drv/char/ps2mouse/Makefile
recc6323 ra455321 33 33 34 34 SOURCES = \ 35 chardev.c \ 35 36 main.c \ 36 37 ps2mouse.c -
uspace/drv/char/ps2mouse/ps2mouse.c
recc6323 ra455321 36 36 #include <errno.h> 37 37 #include <devman.h> 38 #include <device/char_dev.h>39 38 #include <ddf/log.h> 40 39 #include <io/keycode.h> … … 44 43 45 44 #include "ps2mouse.h" 45 #include "chardev.h" 46 46 47 47 #define PS2_MOUSE_GET_DEVICE_ID 0xf2 … … 74 74 do { \ 75 75 uint8_t data = 0; \ 76 const ssize_t size = char _dev_read(session, &data, 1); \76 const ssize_t size = chardev_read(session, &data, 1); \ 77 77 if (size != 1) { \ 78 78 ddf_msg(LVL_ERROR, "Failed reading byte: %d)", size);\ … … 85 85 } \ 86 86 } while (0) 87 87 88 #define MOUSE_WRITE_BYTE(sess, value) \ 88 89 do { \ 89 90 uint8_t data = (value); \ 90 const ssize_t size = char _dev_write(session, &data, 1); \91 const ssize_t size = chardev_write(session, &data, 1); \ 91 92 if (size < 0 ) { \ 92 93 ddf_msg(LVL_ERROR, "Failed writing byte: %hhx", value); \ … … 155 156 /* Enable mouse data reporting. */ 156 157 uint8_t report = PS2_MOUSE_ENABLE_DATA_REPORT; 157 ssize_t size = char _dev_write(mouse->parent_sess, &report, 1);158 ssize_t size = chardev_write(mouse->parent_sess, &report, 1); 158 159 if (size != 1) { 159 160 ddf_msg(LVL_ERROR, "Failed to enable data reporting."); … … 165 166 } 166 167 167 size = char _dev_read(mouse->parent_sess, &report, 1);168 size = chardev_read(mouse->parent_sess, &report, 1); 168 169 if (size != 1 || report != PS2_MOUSE_ACK) { 169 170 ddf_msg(LVL_ERROR, "Failed to confirm data reporting: %hhx.", … … 203 204 uint8_t packet[PS2_BUFSIZE] = {}; 204 205 const ssize_t size = 205 char _dev_read(mouse->parent_sess, packet, PS2_BUFSIZE);206 chardev_read(mouse->parent_sess, packet, PS2_BUFSIZE); 206 207 207 208 if (size != PS2_BUFSIZE) { … … 257 258 258 259 uint8_t packet[INTELLIMOUSE_BUFSIZE] = {}; 259 const ssize_t size = char _dev_read(260 const ssize_t size = chardev_read( 260 261 mouse->parent_sess, packet, INTELLIMOUSE_BUFSIZE); 261 262
Note:
See TracChangeset
for help on using the changeset viewer.