Changeset 15c5418 in mainline
- Timestamp:
- 2017-11-18T20:06:15Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 75fcf9b
- Parents:
- efb9fd08
- Location:
- uspace
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/adb-kbd/adb-kbd.c
refb9fd08 r15c5418 34 34 #include <ddf/log.h> 35 35 #include <errno.h> 36 #include <io/chardev.h> 36 37 #include <io/console.h> 37 38 #include <ipc/adb.h> -
uspace/drv/hid/atkbd/atkbd.c
refb9fd08 r15c5418 1 1 /* 2 * Copyright (c) 2017 Jiri Svoboda 2 3 * Copyright (c) 2011 Jan Vesely 3 4 * Copyright (c) 2009 Vineeth Pillai … … 201 202 static int polling(void *arg) 202 203 { 203 const at_kbd_t *kbd = arg; 204 205 assert(kbd); 206 assert(kbd->parent_sess); 207 208 async_exch_t *parent_exch = async_exchange_begin(kbd->parent_sess); 204 at_kbd_t *kbd = arg; 209 205 210 206 while (true) { 211 if (!parent_exch)212 parent_exch = async_exchange_begin(kbd->parent_sess);213 214 207 uint8_t code = 0; 215 ssize_t size = chardev_read( parent_exch, &code, 1);208 ssize_t size = chardev_read(kbd->chardev, &code, 1); 216 209 if (size != 1) 217 210 return EIO; … … 224 217 map_size = sizeof(scanmap_e0) / sizeof(unsigned int); 225 218 226 size = chardev_read( parent_exch, &code, 1);219 size = chardev_read(kbd->chardev, &code, 1); 227 220 if (size != 1) 228 221 return EIO; 229 222 } else if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) { 230 size = chardev_read( parent_exch, &code, 1);223 size = chardev_read(kbd->chardev, &code, 1); 231 224 if (size != 1) 232 225 return EIO; … … 234 227 continue; 235 228 236 size = chardev_read( parent_exch, &code, 1);229 size = chardev_read(kbd->chardev, &code, 1); 237 230 if (size != 1) 238 231 return EIO; … … 240 233 continue; 241 234 242 size = chardev_read( parent_exch, &code, 1);235 size = chardev_read(kbd->chardev, &code, 1); 243 236 if (size != 1) 244 237 return EIO; … … 246 239 continue; 247 240 248 size = chardev_read( parent_exch, &code, 1);241 size = chardev_read(kbd->chardev, &code, 1); 249 242 if (size != 1) 250 243 return EIO; … … 252 245 continue; 253 246 254 size = chardev_read( parent_exch, &code, 1);247 size = chardev_read(kbd->chardev, &code, 1); 255 248 if (size != 1) 256 249 return EIO; … … 258 251 continue; 259 252 260 size = chardev_read( parent_exch, &code, 1);253 size = chardev_read(kbd->chardev, &code, 1); 261 254 if (size != 1) 262 255 return EIO; … … 264 257 continue; 265 258 266 size = chardev_read( parent_exch, &code, 1);259 size = chardev_read(kbd->chardev, &code, 1); 267 260 if (size != 1) 268 261 return EIO; … … 279 272 if (code == KBD_SCANCODE_KEY_RELEASE) { 280 273 type = KEY_RELEASE; 281 size = chardev_read( parent_exch, &code, 1);274 size = chardev_read(kbd->chardev, &code, 1); 282 275 if (size != 1) 283 276 return EIO; … … 362 355 int at_kbd_init(at_kbd_t *kbd, ddf_dev_t *dev) 363 356 { 357 async_sess_t *parent_sess; 358 int rc; 359 364 360 assert(kbd); 365 361 assert(dev); 366 362 367 363 kbd->client_sess = NULL; 368 kbd->parent_sess = ddf_dev_parent_sess_get(dev); 369 370 if (!kbd->parent_sess) { 364 parent_sess = ddf_dev_parent_sess_get(dev); 365 if (parent_sess == NULL) { 371 366 ddf_msg(LVL_ERROR, "Failed creating parent session."); 367 rc = EIO; 368 goto error; 369 } 370 371 rc = chardev_open(parent_sess, &kbd->chardev); 372 if (rc != EOK) { 373 ddf_msg(LVL_ERROR, "Failed opening character device."); 372 374 return EIO; 373 375 } … … 407 409 fibril_add_ready(kbd->polling_fibril); 408 410 return EOK; 411 error: 412 chardev_close(kbd->chardev); 413 kbd->chardev = NULL; 414 return rc; 409 415 } -
uspace/drv/hid/atkbd/atkbd.h
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 34 35 */ 35 36 36 #ifndef _AT_KBD_H_37 #define _AT_KBD_H_37 #ifndef AT_KBD_H_ 38 #define AT_KBD_H_ 38 39 39 40 #include <ddf/driver.h> 40 41 #include <fibril.h> 42 #include <io/chardev.h> 41 43 42 44 /** PC/AT keyboard driver structure. */ 43 45 typedef struct { 44 ddf_fun_t *kbd_fun; /**< Keyboard function. */ 45 async_sess_t *parent_sess; /**< Connection to device providing data. */ 46 async_sess_t *client_sess; /**< Callback connection to client. */ 47 fid_t polling_fibril; /**< Fibril retrieving an parsing data. */ 46 /** Keyboard function */ 47 ddf_fun_t *kbd_fun; 48 /** Device providing keyboard connection */ 49 chardev_t *chardev; 50 /** Callback connection to client */ 51 async_sess_t *client_sess; 52 /** Fibril retrieving and parsing data */ 53 fid_t polling_fibril; 48 54 } at_kbd_t; 49 55 -
uspace/drv/hid/ps2mouse/main.c
refb9fd08 r15c5418 30 30 */ 31 31 /** @file 32 * @brief ps/2 mouse driver32 * @brief PS/2 mouse driver 33 33 */ 34 34 -
uspace/drv/hid/ps2mouse/ps2mouse.c
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 30 31 */ 31 32 /** @file 32 * @brief ps2 mouse driver.33 * @brief PS/2 mouse driver. 33 34 */ 34 35 … … 70 71 #define PS2_BUTTON_MASK(button) (1 << button) 71 72 72 #define MOUSE_READ_BYTE_TEST( sess, value_) \73 #define MOUSE_READ_BYTE_TEST(mouse, value_) \ 73 74 do { \ 74 75 uint8_t value = (value_); \ 75 76 uint8_t data = 0; \ 76 const ssize_t size = chardev_read( sess, &data, 1); \77 const ssize_t size = chardev_read((mouse)->chardev, &data, 1); \ 77 78 if (size != 1) { \ 78 79 ddf_msg(LVL_ERROR, "Failed reading byte: %zd)", size);\ … … 86 87 } while (0) 87 88 88 #define MOUSE_WRITE_BYTE( sess, value_) \89 #define MOUSE_WRITE_BYTE(mouse, value_) \ 89 90 do { \ 90 91 uint8_t value = (value_); \ 91 92 uint8_t data = (value); \ 92 const ssize_t size = chardev_write( sess, &data, 1); \93 const ssize_t size = chardev_write((mouse)->chardev, &data, 1); \ 93 94 if (size < 0 ) { \ 94 95 ddf_msg(LVL_ERROR, "Failed writing byte: %hhx", value); \ … … 99 100 static int polling_ps2(void *); 100 101 static int polling_intellimouse(void *); 101 static int probe_intellimouse( async_exch_t *, bool);102 static int probe_intellimouse(ps2_mouse_t *, bool); 102 103 static void default_connection_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); 103 104 … … 108 109 109 110 /** Initialize mouse driver structure. 111 * 112 * Connects to parent, creates keyboard function, starts polling fibril. 113 * 110 114 * @param kbd Mouse driver structure to initialize. 111 115 * @param dev DDF device structure. 112 116 * 113 * Connects to parent, creates keyboard function, starts polling fibril.117 * @return EOK on success or non-zero error code 114 118 */ 115 119 int ps2_mouse_init(ps2_mouse_t *mouse, ddf_dev_t *dev) 116 120 { 121 async_sess_t *parent_sess; 122 bool bound = false; 123 int rc; 124 117 125 mouse->client_sess = NULL; 118 mouse->parent_sess = ddf_dev_parent_sess_get(dev); 119 if (!mouse->parent_sess) 120 return ENOMEM; 126 127 parent_sess = ddf_dev_parent_sess_get(dev); 128 if (parent_sess == NULL) { 129 ddf_msg(LVL_ERROR, "Failed getting parent session."); 130 rc = ENOMEM; 131 goto error; 132 } 133 134 rc = chardev_open(parent_sess, &mouse->chardev); 135 if (rc != EOK) { 136 ddf_msg(LVL_ERROR, "Failed opening character device."); 137 goto error; 138 } 121 139 122 140 mouse->mouse_fun = ddf_fun_create(dev, fun_exposed, "mouse"); 123 if (!mouse->mouse_fun) { 124 return ENOMEM; 125 } 141 if (mouse->mouse_fun == NULL) { 142 ddf_msg(LVL_ERROR, "Error creating mouse function."); 143 rc = ENOMEM; 144 goto error; 145 } 146 126 147 ddf_fun_set_ops(mouse->mouse_fun, &mouse_ops); 127 148 128 int ret = ddf_fun_bind(mouse->mouse_fun); 129 if (ret != EOK) { 130 ddf_fun_destroy(mouse->mouse_fun); 131 return ENOMEM; 132 } 133 134 ret = ddf_fun_add_to_category(mouse->mouse_fun, "mouse"); 135 if (ret != EOK) { 136 ddf_fun_unbind(mouse->mouse_fun); 137 ddf_fun_destroy(mouse->mouse_fun); 138 return ENOMEM; 139 } 149 rc = ddf_fun_bind(mouse->mouse_fun); 150 if (rc != EOK) { 151 ddf_msg(LVL_ERROR, "Failed binding mouse function."); 152 goto error; 153 } 154 155 bound = true; 156 157 rc = ddf_fun_add_to_category(mouse->mouse_fun, "mouse"); 158 if (rc != EOK) { 159 ddf_msg(LVL_ERROR, "Failed adding mouse function to category."); 160 goto error; 161 } 162 140 163 /* Probe IntelliMouse extensions. */ 141 164 int (*polling_f)(void*) = polling_ps2; 142 async_exch_t *exch = async_exchange_begin(mouse->parent_sess); 143 if (probe_intellimouse(exch, false) == EOK) { 165 if (probe_intellimouse(mouse, false) == EOK) { 144 166 ddf_msg(LVL_NOTE, "Enabled IntelliMouse extensions"); 145 167 polling_f = polling_intellimouse; 146 if (probe_intellimouse( exch, true) == EOK)168 if (probe_intellimouse(mouse, true) == EOK) 147 169 ddf_msg(LVL_NOTE, "Enabled 4th and 5th button."); 148 170 } 171 149 172 /* Enable mouse data reporting. */ 150 173 uint8_t report = PS2_MOUSE_ENABLE_DATA_REPORT; 151 ssize_t size = chardev_write( exch, &report, 1);174 ssize_t size = chardev_write(mouse->chardev, &report, 1); 152 175 if (size != 1) { 153 176 ddf_msg(LVL_ERROR, "Failed to enable data reporting."); 154 async_exchange_end(exch); 155 ddf_fun_unbind(mouse->mouse_fun); 156 ddf_fun_destroy(mouse->mouse_fun); 157 return EIO; 158 } 159 160 size = chardev_read(exch, &report, 1); 161 async_exchange_end(exch); 177 rc = EIO; 178 goto error; 179 } 180 181 size = chardev_read(mouse->chardev, &report, 1); 162 182 if (size != 1 || report != PS2_MOUSE_ACK) { 163 183 ddf_msg(LVL_ERROR, "Failed to confirm data reporting: %hhx.", 164 184 report); 165 ddf_fun_unbind(mouse->mouse_fun); 166 ddf_fun_destroy(mouse->mouse_fun); 167 return EIO; 185 rc = EIO; 186 goto error; 168 187 } 169 188 170 189 mouse->polling_fibril = fibril_create(polling_f, mouse); 171 if ( !mouse->polling_fibril) {172 ddf_fun_unbind(mouse->mouse_fun);173 ddf_fun_destroy(mouse->mouse_fun);174 return ENOMEM;175 } 190 if (mouse->polling_fibril == 0) { 191 rc = ENOMEM; 192 goto error; 193 } 194 176 195 fibril_add_ready(mouse->polling_fibril); 177 196 return EOK; 197 error: 198 if (bound) 199 ddf_fun_unbind(mouse->mouse_fun); 200 if (mouse->mouse_fun != NULL) { 201 ddf_fun_destroy(mouse->mouse_fun); 202 mouse->mouse_fun = NULL; 203 } 204 205 chardev_close(mouse->chardev); 206 mouse->chardev = NULL; 207 return rc; 178 208 } 179 209 … … 184 214 int polling_ps2(void *arg) 185 215 { 186 assert(arg); 187 const ps2_mouse_t *mouse = arg; 188 189 assert(mouse->parent_sess); 216 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 217 190 218 bool buttons[PS2_BUTTON_COUNT] = {}; 191 async_exch_t *parent_exch = async_exchange_begin(mouse->parent_sess);192 219 while (1) { 193 194 220 uint8_t packet[PS2_BUFSIZE] = {}; 195 221 const ssize_t size = 196 chardev_read( parent_exch, packet, PS2_BUFSIZE);222 chardev_read(mouse->chardev, packet, PS2_BUFSIZE); 197 223 198 224 if (size != PS2_BUFSIZE) { … … 232 258 async_exchange_end(exch); 233 259 } 234 async_exchange_end(parent_exch); 260 261 return 0; 235 262 } 236 263 … … 241 268 static int polling_intellimouse(void *arg) 242 269 { 243 assert(arg); 244 const ps2_mouse_t *mouse = arg; 245 246 assert(mouse->parent_sess); 270 ps2_mouse_t *mouse = (ps2_mouse_t *) arg; 271 247 272 bool buttons[INTELLIMOUSE_BUTTON_COUNT] = {}; 248 async_exch_t *parent_exch = NULL;249 273 while (1) { 250 if (!parent_exch)251 parent_exch = async_exchange_begin(mouse->parent_sess);252 253 274 uint8_t packet[INTELLIMOUSE_BUFSIZE] = {}; 254 275 const ssize_t size = chardev_read( 255 parent_exch, packet, INTELLIMOUSE_BUFSIZE);276 mouse->chardev, packet, INTELLIMOUSE_BUFSIZE); 256 277 257 278 if (size != INTELLIMOUSE_BUFSIZE) { … … 310 331 async_exchange_end(exch); 311 332 } 312 async_exchange_end(parent_exch); 333 334 return 0; 313 335 } 314 336 … … 319 341 * See http://www.computer-engineering.org/ps2mouse/ for details. 320 342 */ 321 static int probe_intellimouse( async_exch_t *exch, bool buttons)343 static int probe_intellimouse(ps2_mouse_t *mouse, bool buttons) 322 344 { 323 assert(exch); 324 325 MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE); 326 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 327 MOUSE_WRITE_BYTE(exch, 200); 328 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 329 330 MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE); 331 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 332 MOUSE_WRITE_BYTE(exch, buttons ? 200 : 100); 333 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 334 335 MOUSE_WRITE_BYTE(exch, PS2_MOUSE_SET_SAMPLE_RATE); 336 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 337 MOUSE_WRITE_BYTE(exch, 80); 338 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 339 340 MOUSE_WRITE_BYTE(exch, PS2_MOUSE_GET_DEVICE_ID); 341 MOUSE_READ_BYTE_TEST(exch, PS2_MOUSE_ACK); 342 MOUSE_READ_BYTE_TEST(exch, buttons ? 4 : 3); 345 MOUSE_WRITE_BYTE(mouse, PS2_MOUSE_SET_SAMPLE_RATE); 346 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 347 MOUSE_WRITE_BYTE(mouse, 200); 348 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 349 350 MOUSE_WRITE_BYTE(mouse, PS2_MOUSE_SET_SAMPLE_RATE); 351 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 352 MOUSE_WRITE_BYTE(mouse, buttons ? 200 : 100); 353 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 354 355 MOUSE_WRITE_BYTE(mouse, PS2_MOUSE_SET_SAMPLE_RATE); 356 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 357 MOUSE_WRITE_BYTE(mouse, 80); 358 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 359 360 MOUSE_WRITE_BYTE(mouse, PS2_MOUSE_GET_DEVICE_ID); 361 MOUSE_READ_BYTE_TEST(mouse, PS2_MOUSE_ACK); 362 MOUSE_READ_BYTE_TEST(mouse, buttons ? 4 : 3); 343 363 344 364 return EOK; -
uspace/drv/hid/ps2mouse/ps2mouse.h
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 30 31 */ 31 32 /** @file 32 * @brief ps/2 mouse driver.33 * @brief PS/2 mouse driver. 33 34 */ 34 35 35 #ifndef _PS2MOUSE_H_36 #define _PS2MOUSE_H_36 #ifndef PS2MOUSE_H_ 37 #define PS2MOUSE_H_ 37 38 38 39 #include <ddf/driver.h> 39 40 #include <fibril.h> 41 #include <io/chardev.h> 40 42 41 43 /** PS/2 mouse driver structure. */ 42 44 typedef struct { 43 ddf_fun_t *mouse_fun; /**< Mouse function. */ 44 async_sess_t *parent_sess; /**< Connection to device providing data. */ 45 async_sess_t *client_sess; /**< Callback connection to client. */ 46 fid_t polling_fibril; /**< Fibril retrieving an parsing data. */ 45 /** Mouse function. */ 46 ddf_fun_t *mouse_fun; 47 /** Device providing mouse connection */ 48 chardev_t *chardev; 49 /** Callback connection to client. */ 50 async_sess_t *client_sess; 51 /** Fibril retrieving an parsing data. */ 52 fid_t polling_fibril; 47 53 } ps2_mouse_t; 48 54 49 int ps2_mouse_init(ps2_mouse_t *, ddf_dev_t *);55 extern int ps2_mouse_init(ps2_mouse_t *, ddf_dev_t *); 50 56 51 57 #endif 58 52 59 /** 53 60 * @} -
uspace/drv/hid/xtkbd/xtkbd.c
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 206 207 static int polling(void *arg) 207 208 { 208 const xt_kbd_t *kbd = arg; 209 210 assert(kbd); 211 assert(kbd->parent_sess); 212 213 async_exch_t *parent_exch = async_exchange_begin(kbd->parent_sess); 209 xt_kbd_t *kbd = arg; 214 210 215 211 while (true) { 216 if (!parent_exch)217 parent_exch = async_exchange_begin(kbd->parent_sess);218 219 212 const unsigned int *map = scanmap_simple; 220 213 size_t map_size = sizeof(scanmap_simple) / sizeof(unsigned int); 221 214 222 215 uint8_t code = 0; 223 ssize_t size = chardev_read( parent_exch, &code, 1);216 ssize_t size = chardev_read(kbd->chardev, &code, 1); 224 217 if (size != 1) 225 218 return EIO; … … 234 227 map_size = sizeof(scanmap_e0) / sizeof(unsigned int); 235 228 236 size = chardev_read( parent_exch, &code, 1);229 size = chardev_read(kbd->chardev, &code, 1); 237 230 if (size != 1) 238 231 return EIO; … … 241 234 242 235 if (code == 0x2a) { /* Print Screen */ 243 size = chardev_read( parent_exch, &code, 1);236 size = chardev_read(kbd->chardev, &code, 1); 244 237 if (size != 1) 245 238 return EIO; … … 248 241 continue; 249 242 250 size = chardev_read( parent_exch, &code, 1);243 size = chardev_read(kbd->chardev, &code, 1); 251 244 if (size != 1) 252 245 return EIO; … … 259 252 260 253 if (code == 0x46) { /* Break */ 261 size = chardev_read( parent_exch, &code, 1);254 size = chardev_read(kbd->chardev, &code, 1); 262 255 if (size != 1) 263 256 return EIO; … … 266 259 continue; 267 260 268 size = chardev_read( parent_exch, &code, 1);261 size = chardev_read(kbd->chardev, &code, 1); 269 262 if (size != 1) 270 263 return EIO; … … 279 272 /* Extended special set */ 280 273 if (code == KBD_SCANCODE_SET_EXTENDED_SPECIAL) { 281 size = chardev_read( parent_exch, &code, 1);274 size = chardev_read(kbd->chardev, &code, 1); 282 275 if (size != 1) 283 276 return EIO; … … 286 279 continue; 287 280 288 size = chardev_read( parent_exch, &code, 1);281 size = chardev_read(kbd->chardev, &code, 1); 289 282 if (size != 1) 290 283 return EIO; … … 293 286 continue; 294 287 295 size = chardev_read( parent_exch, &code, 1);288 size = chardev_read(kbd->chardev, &code, 1); 296 289 if (size != 1) 297 290 return EIO; … … 300 293 continue; 301 294 302 size = chardev_read( parent_exch, &code, 1);295 size = chardev_read(kbd->chardev, &code, 1); 303 296 if (size != 1) 304 297 return EIO; … … 307 300 continue; 308 301 309 size = chardev_read( parent_exch, &code, 1);302 size = chardev_read(kbd->chardev, &code, 1); 310 303 if (size != 1) 311 304 return EIO; … … 357 350 uint8_t cmds[] = { KBD_CMD_SET_LEDS, status }; 358 351 359 async_exch_t *exch = async_exchange_begin(kbd->parent_sess); 360 const ssize_t size = chardev_write(exch, cmds, sizeof(cmds)); 361 async_exchange_end(exch); 352 ssize_t size = chardev_write(kbd->chardev, cmds, sizeof(cmds)); 362 353 363 354 async_answer_0(icallid, size < 0 ? size : EOK); … … 413 404 int xt_kbd_init(xt_kbd_t *kbd, ddf_dev_t *dev) 414 405 { 415 assert(kbd); 416 assert(dev); 406 async_sess_t *parent_sess; 407 bool bound = false; 408 int rc; 417 409 418 410 kbd->client_sess = NULL; 419 kbd->parent_sess = ddf_dev_parent_sess_get(dev);420 421 if ( !kbd->parent_sess) {411 412 parent_sess = ddf_dev_parent_sess_get(dev); 413 if (parent_sess == NULL) { 422 414 ddf_msg(LVL_ERROR, "Failed creating parent session."); 423 return EIO; 415 rc = EIO; 416 goto error; 417 } 418 419 rc = chardev_open(parent_sess, &kbd->chardev); 420 if (rc != EOK) { 421 ddf_msg(LVL_ERROR, "Failed opening character device."); 422 goto error; 424 423 } 425 424 426 425 kbd->kbd_fun = ddf_fun_create(dev, fun_exposed, "kbd"); 427 if ( !kbd->kbd_fun) {426 if (kbd->kbd_fun == NULL) { 428 427 ddf_msg(LVL_ERROR, "Failed creating function 'kbd'."); 429 return ENOMEM; 428 rc = ENOMEM; 429 goto error; 430 430 } 431 431 432 432 ddf_fun_set_ops(kbd->kbd_fun, &kbd_ops); 433 433 434 int ret= ddf_fun_bind(kbd->kbd_fun);435 if (r et!= EOK) {434 rc = ddf_fun_bind(kbd->kbd_fun); 435 if (rc != EOK) { 436 436 ddf_msg(LVL_ERROR, "Failed binding function 'kbd'."); 437 ddf_fun_destroy(kbd->kbd_fun); 438 return EEXIST; 439 } 440 441 ret = ddf_fun_add_to_category(kbd->kbd_fun, "keyboard"); 442 if (ret != EOK) { 437 goto error; 438 } 439 440 rc = ddf_fun_add_to_category(kbd->kbd_fun, "keyboard"); 441 if (rc != EOK) { 443 442 ddf_msg(LVL_ERROR, "Failed adding function 'kbd' to category " 444 443 "'keyboard'."); 445 ddf_fun_unbind(kbd->kbd_fun); 446 ddf_fun_destroy(kbd->kbd_fun); 447 return ENOMEM; 444 goto error; 448 445 } 449 446 450 447 kbd->polling_fibril = fibril_create(polling, kbd); 451 if ( !kbd->polling_fibril) {448 if (kbd->polling_fibril == 0) { 452 449 ddf_msg(LVL_ERROR, "Failed creating polling fibril."); 453 ddf_fun_unbind(kbd->kbd_fun); 454 ddf_fun_destroy(kbd->kbd_fun); 455 return ENOMEM; 450 rc = ENOMEM; 451 goto error; 456 452 } 457 453 458 454 fibril_add_ready(kbd->polling_fibril); 459 455 return EOK; 456 error: 457 if (bound) 458 ddf_fun_unbind(kbd->kbd_fun); 459 if (kbd->kbd_fun != NULL) 460 ddf_fun_destroy(kbd->kbd_fun); 461 chardev_close(kbd->chardev); 462 return rc; 460 463 } -
uspace/drv/hid/xtkbd/xtkbd.h
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 34 35 */ 35 36 36 #ifndef _XT_KBD_H_37 #define _XT_KBD_H_37 #ifndef XT_KBD_H_ 38 #define XT_KBD_H_ 38 39 40 #include <async.h> 39 41 #include <ddf/driver.h> 40 42 #include <fibril.h> 43 #include <io/chardev.h> 41 44 42 /** PC/XT keyboard driver structure .*/45 /** PC/XT keyboard driver structure */ 43 46 typedef struct { 44 ddf_fun_t *kbd_fun; /**< Keyboard function. */ 45 async_sess_t *parent_sess; /**< Connection to device providing data. */ 46 async_sess_t *client_sess; /**< Callback connection to client. */ 47 fid_t polling_fibril; /**< Fibril retrieving an parsing data. */ 47 /** Keyboard function */ 48 ddf_fun_t *kbd_fun; 49 /** Device providing keyboard connection */ 50 chardev_t *chardev; 51 /** Callback connection to client */ 52 async_sess_t *client_sess; 53 /** Fibril retrieving an parsing data */ 54 fid_t polling_fibril; 48 55 } xt_kbd_t; 49 56 -
uspace/lib/c/generic/io/chardev.c
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 30 /** @addtogroup libc 31 * @{ 32 */ 33 /** 34 * @file 35 * @brief Character device client interface 36 */ 37 29 38 #include <errno.h> 30 39 #include <mem.h> 31 40 #include <io/chardev.h> 32 41 #include <ipc/chardev.h> 42 #include <stdlib.h> 33 43 34 ssize_t chardev_read(async_exch_t *exch, void *data, size_t size) 44 /** Open character device. 45 * 46 * @param sess Session with the character device 47 * @param rchardev Place to store pointer to the new character device structure 48 * 49 * @return EOK on success, ENOMEM if out of memory, EIO on I/O error 50 */ 51 int chardev_open(async_sess_t *sess, chardev_t **rchardev) 35 52 { 36 if (!exch) 37 return EBADMEM; 53 chardev_t *chardev; 54 55 chardev = calloc(1, sizeof(chardev_t)); 56 if (chardev == NULL) 57 return ENOMEM; 58 59 chardev->sess = sess; 60 *rchardev = chardev; 61 62 /* EIO might be used in a future implementation */ 63 return EOK; 64 } 65 66 /** Close character device. 67 * 68 * Frees the character device structure. The underlying session is 69 * not affected. 70 * 71 * @param chardev Character device or @c NULL 72 */ 73 void chardev_close(chardev_t *chardev) 74 { 75 free(chardev); 76 } 77 78 ssize_t chardev_read(chardev_t *chardev, void *data, size_t size) 79 { 38 80 if (size > 4 * sizeof(sysarg_t)) 39 81 return ELIMIT; 40 82 83 async_exch_t *exch = async_exchange_begin(chardev->sess); 41 84 sysarg_t message[4] = { 0 }; 42 85 const ssize_t ret = async_req_1_4(exch, CHARDEV_READ, size, 43 86 &message[0], &message[1], &message[2], &message[3]); 87 async_exchange_end(exch); 44 88 if (ret > 0 && (size_t)ret <= size) 45 89 memcpy(data, message, size); … … 47 91 } 48 92 49 ssize_t chardev_write( async_exch_t *exch, const void *data, size_t size)93 ssize_t chardev_write(chardev_t *chardev, const void *data, size_t size) 50 94 { 51 i f (!exch)52 return EBADMEM; 95 int ret; 96 53 97 if (size > 3 * sizeof(sysarg_t)) 54 98 return ELIMIT; 55 99 100 async_exch_t *exch = async_exchange_begin(chardev->sess); 56 101 sysarg_t message[3] = { 0 }; 57 102 memcpy(message, data, size); 58 ret urnasync_req_4_0(exch, CHARDEV_WRITE, size,103 ret = async_req_4_0(exch, CHARDEV_WRITE, size, 59 104 message[0], message[1], message[2]); 105 async_exchange_end(exch); 106 return ret; 60 107 } 108 109 /** @} 110 */ -
uspace/lib/c/include/io/chardev.h
refb9fd08 r15c5418 1 1 /* 2 2 * Copyright (c) 2011 Jan Vesely 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 33 34 #define LIBC_IO_CHARDEV_H_ 34 35 36 #include <async.h> 35 37 #include <types/common.h> 36 #include <async.h>37 38 38 ssize_t chardev_read(async_exch_t *, void *, size_t); 39 ssize_t chardev_write(async_exch_t *, const void *, size_t); 39 typedef struct { 40 async_sess_t *sess; 41 } chardev_t; 42 43 extern int chardev_open(async_sess_t *, chardev_t **); 44 extern void chardev_close(chardev_t *); 45 extern ssize_t chardev_read(chardev_t *, void *, size_t); 46 extern ssize_t chardev_write(chardev_t *, const void *, size_t); 40 47 41 48 #endif
Note:
See TracChangeset
for help on using the changeset viewer.