Changeset 79ae36dd in mainline for uspace/lib/c/generic/device
- Timestamp:
- 2011-06-08T19:01:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eff68e
- Parents:
- 764d71e
- Location:
- uspace/lib/c/generic/device
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/device/char_dev.c
r764d71e r79ae36dd 45 45 * using its character interface. 46 46 * 47 * @param dev_phone Phoneto the device.48 * @param buf 49 * @param size 50 * @param read 47 * @param sess Session to the device. 48 * @param buf Buffer for the data read from or written to the device. 49 * @param size Maximum size of data (in bytes) to be read or written. 50 * @param read Read from the device if true, write to it otherwise. 51 51 * 52 * @return Non-negative number of bytes actually read from or 53 * written to the device on success, negative error number 54 * otherwise. 52 * @return Non-negative number of bytes actually read from or 53 * written to the device on success, negative error number 54 * otherwise. 55 * 55 56 */ 56 static ssize_t char_dev_rw( int dev_phone, void *buf, size_t size, bool read)57 static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read) 57 58 { 58 async_serialize_start();59 60 59 ipc_call_t answer; 61 60 aid_t req; 62 61 int ret; 63 62 63 async_exch_t *exch = async_exchange_begin(sess); 64 64 65 if (read) { 65 req = async_send_1( dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),66 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 66 67 CHAR_DEV_READ, &answer); 67 ret = async_data_read_start( dev_phone, buf, size);68 ret = async_data_read_start(exch, buf, size); 68 69 } else { 69 req = async_send_1( dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE),70 req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 71 CHAR_DEV_WRITE, &answer); 71 ret = async_data_write_start( dev_phone, buf, size);72 ret = async_data_write_start(exch, buf, size); 72 73 } 74 75 async_exchange_end(exch); 73 76 74 77 sysarg_t rc; 75 78 if (ret != EOK) { 76 79 async_wait_for(req, &rc); 77 async_serialize_end();78 80 if (rc == EOK) 79 81 return (ssize_t) ret; … … 83 85 84 86 async_wait_for(req, &rc); 85 async_serialize_end();86 87 87 88 ret = (int) rc; … … 94 95 /** Read from character device. 95 96 * 96 * @param dev_phone Phoneto the device.97 * @param buf 98 * @param size 97 * @param sess Session to the device. 98 * @param buf Output buffer for the data read from the device. 99 * @param size Maximum size (in bytes) of the data to be read. 99 100 * 100 * @return Non-negative number of bytes actually read from the 101 * device on success, negative error number otherwise. 101 * @return Non-negative number of bytes actually read from the 102 * device on success, negative error number otherwise. 103 * 102 104 */ 103 ssize_t char_dev_read( int dev_phone, void *buf, size_t size)105 ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size) 104 106 { 105 return char_dev_rw( dev_phone, buf, size, true);107 return char_dev_rw(sess, buf, size, true); 106 108 } 107 109 108 110 /** Write to character device. 109 111 * 110 * @param dev_phone Phoneto the device.111 * @param buf 112 * 113 * @param size 112 * @param sess Session to the device. 113 * @param buf Input buffer containg the data to be written to the 114 * device. 115 * @param size Maximum size (in bytes) of the data to be written. 114 116 * 115 * @return Non-negative number of bytes actually written to the 116 * device on success, negative error number otherwise. 117 * @return Non-negative number of bytes actually written to the 118 * device on success, negative error number otherwise. 119 * 117 120 */ 118 ssize_t char_dev_write( int dev_phone, void *buf, size_t size)121 ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size) 119 122 { 120 return char_dev_rw( dev_phone, buf, size, false);123 return char_dev_rw(sess, buf, size, false); 121 124 } 122 125 -
uspace/lib/c/generic/device/hw_res.c
r764d71e r79ae36dd 38 38 #include <malloc.h> 39 39 40 int hw_res_get_resource_list(int dev_phone, hw_resource_list_t *hw_resources) 40 int hw_res_get_resource_list(async_sess_t *sess, 41 hw_resource_list_t *hw_resources) 41 42 { 42 43 sysarg_t count = 0; 43 44 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), 44 45 async_exch_t *exch = async_exchange_begin(sess); 46 int rc = async_req_1_1(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 45 47 HW_RES_GET_RESOURCE_LIST, &count); 46 47 hw_resources->count = count;48 if (rc != EOK)48 49 if (rc != EOK) { 50 async_exchange_end(exch); 49 51 return rc; 52 } 50 53 51 54 size_t size = count * sizeof(hw_resource_t); 52 hw_resources->resources = (hw_resource_t *)malloc(size); 53 if (!hw_resources->resources) 55 hw_resource_t *resources = (hw_resource_t *) malloc(size); 56 if (resources == NULL) { 57 // FIXME: This is protocol violation 58 async_exchange_end(exch); 54 59 return ENOMEM; 60 } 55 61 56 rc = async_data_read_start(dev_phone, hw_resources->resources, size); 62 rc = async_data_read_start(exch, resources, size); 63 async_exchange_end(exch); 64 57 65 if (rc != EOK) { 58 free(hw_resources->resources); 59 hw_resources->resources = NULL; 66 free(resources); 60 67 return rc; 61 68 } 69 70 hw_resources->resources = resources; 71 hw_resources->count = count; 62 72 63 73 return EOK; 64 74 } 65 75 66 bool hw_res_enable_interrupt( int dev_phone)76 bool hw_res_enable_interrupt(async_sess_t *sess) 67 77 { 68 int rc = async_req_1_0(dev_phone, DEV_IFACE_ID(HW_RES_DEV_IFACE), 78 async_exch_t *exch = async_exchange_begin(sess); 79 int rc = async_req_1_0(exch, DEV_IFACE_ID(HW_RES_DEV_IFACE), 69 80 HW_RES_ENABLE_INTERRUPT); 70 71 return rc == EOK; 81 async_exchange_end(exch); 82 83 return (rc == EOK); 72 84 } 73 85
Note:
See TracChangeset
for help on using the changeset viewer.