Changeset 79ae36dd in mainline for uspace/lib/c/generic/device


Ignore:
Timestamp:
2011-06-08T19:01:55Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
Location:
uspace/lib/c/generic/device
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/device/char_dev.c

    r764d71e r79ae36dd  
    4545 * using its character interface.
    4646 *
    47  * @param dev_phone     Phone 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.
     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.
    5151 *
    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 *
    5556 */
    56 static ssize_t char_dev_rw(int dev_phone, void *buf, size_t size, bool read)
     57static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read)
    5758{
    58         async_serialize_start();
    59        
    6059        ipc_call_t answer;
    6160        aid_t req;
    6261        int ret;
    6362       
     63        async_exch_t *exch = async_exchange_begin(sess);
     64       
    6465        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),
    6667                    CHAR_DEV_READ, &answer);
    67                 ret = async_data_read_start(dev_phone, buf, size);
     68                ret = async_data_read_start(exch, buf, size);
    6869        } 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),
    7071                    CHAR_DEV_WRITE, &answer);
    71                 ret = async_data_write_start(dev_phone, buf, size);
     72                ret = async_data_write_start(exch, buf, size);
    7273        }
     74       
     75        async_exchange_end(exch);
    7376       
    7477        sysarg_t rc;
    7578        if (ret != EOK) {
    7679                async_wait_for(req, &rc);
    77                 async_serialize_end();
    7880                if (rc == EOK)
    7981                        return (ssize_t) ret;
     
    8385       
    8486        async_wait_for(req, &rc);
    85         async_serialize_end();
    8687       
    8788        ret = (int) rc;
     
    9495/** Read from character device.
    9596 *
    96  * @param dev_phone     Phone to the device.
    97  * @param buf           Output buffer for the data read from the device.
    98  * @param size          Maximum size (in bytes) of the data to be read.
     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.
    99100 *
    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 *
    102104 */
    103 ssize_t char_dev_read(int dev_phone, void *buf, size_t size)
     105ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size)
    104106{
    105         return char_dev_rw(dev_phone, buf, size, true);
     107        return char_dev_rw(sess, buf, size, true);
    106108}
    107109
    108110/** Write to character device.
    109111 *
    110  * @param dev_phone     Phone to the device.
    111  * @param buf           Input buffer containg the data to be written to the
    112  *                      device.
    113  * @param size          Maximum size (in bytes) of the data to be written.
     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.
    114116 *
    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 *
    117120 */
    118 ssize_t char_dev_write(int dev_phone, void *buf, size_t size)
     121ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size)
    119122{
    120         return char_dev_rw(dev_phone, buf, size, false);
     123        return char_dev_rw(sess, buf, size, false);
    121124}
    122125
  • uspace/lib/c/generic/device/hw_res.c

    r764d71e r79ae36dd  
    3838#include <malloc.h>
    3939
    40 int hw_res_get_resource_list(int dev_phone, hw_resource_list_t *hw_resources)
     40int hw_res_get_resource_list(async_sess_t *sess,
     41    hw_resource_list_t *hw_resources)
    4142{
    4243        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),
    4547            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);
    4951                return rc;
     52        }
    5053       
    5154        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);
    5459                return ENOMEM;
     60        }
    5561       
    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       
    5765        if (rc != EOK) {
    58                 free(hw_resources->resources);
    59                 hw_resources->resources = NULL;
     66                free(resources);
    6067                return rc;
    6168        }
     69       
     70        hw_resources->resources = resources;
     71        hw_resources->count = count;
    6272       
    6373        return EOK;
    6474}
    6575
    66 bool hw_res_enable_interrupt(int dev_phone)
     76bool hw_res_enable_interrupt(async_sess_t *sess)
    6777{
    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),
    6980            HW_RES_ENABLE_INTERRUPT);
    70 
    71         return rc == EOK;
     81        async_exchange_end(exch);
     82       
     83        return (rc == EOK);
    7284}
    7385
Note: See TracChangeset for help on using the changeset viewer.