Changeset 19a1800 in mainline for uspace/lib/c/generic/devman.c


Ignore:
Timestamp:
2011-03-01T22:20:56Z (14 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e24e7b1
Parents:
976f546 (diff), ac8285d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with the current development

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/devman.c

    r976f546 r19a1800  
    2828 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2929 */
    30  
    31  /** @addtogroup libc
     30
     31/** @addtogroup libc
    3232 * @{
    3333 */
     
    3737#include <str.h>
    3838#include <stdio.h>
    39 #include <ipc/ipc.h>
    4039#include <ipc/services.h>
    4140#include <ipc/devman.h>
     
    116115        async_set_client_connection(conn);
    117116       
    118         sysarg_t callback_phonehash;
    119         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
     117        async_connect_to_me(phone, 0, 0, 0, NULL);
    120118        async_wait_for(req, &retval);
    121119       
     
    125123}
    126124
    127 static int devman_send_match_id(int phone, match_id_t *match_id) \
    128 {
    129         ipc_call_t answer;
    130         aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);
    131         int retval = async_data_write_start(phone, match_id->id, str_size(match_id->id));
     125static int devman_send_match_id(int phone, match_id_t *match_id)
     126{
     127        ipc_call_t answer;
     128
     129        aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score,
     130            &answer);
     131        int retval = async_data_write_start(phone, match_id->id,
     132            str_size(match_id->id));
     133
    132134        async_wait_for(req, NULL);
    133135        return retval;
     
    135137
    136138
    137 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 
     139static int devman_send_match_ids(int phone, match_id_list_t *match_ids)
    138140{
    139141        link_t *link = match_ids->ids.next;
    140142        match_id_t *match_id = NULL;
    141143        int ret = EOK;
    142        
     144
    143145        while (link != &match_ids->ids) {
    144146                match_id = list_get_instance(link, match_id_t, link);
    145                 if (EOK != (ret = devman_send_match_id(phone, match_id)))
    146                 {
    147                         printf("Driver failed to send match id, error number = %d\n", ret);
    148                         return ret;                     
    149                 }
     147                ret = devman_send_match_id(phone, match_id);
     148                if (ret != EOK) {
     149                        printf("Driver failed to send match id, error %d\n",
     150                            ret);
     151                        return ret;
     152                }
     153
    150154                link = link->next;
    151155        }
    152         return ret;     
    153 }
    154 
    155 int devman_child_device_register(
    156         const char *name, match_id_list_t *match_ids, devman_handle_t parent_handle, devman_handle_t *handle)
    157 {               
     156
     157        return ret;
     158}
     159
     160/** Add function to a device.
     161 *
     162 * Request devman to add a new function to the specified device owned by
     163 * this driver task.
     164 *
     165 * @param name          Name of the new function
     166 * @param ftype         Function type, fun_inner or fun_exposed
     167 * @param match_ids     Match IDs (should be empty for fun_exposed)
     168 * @param devh          Devman handle of the device
     169 * @param funh          Place to store handle of the new function
     170 *
     171 * @return              EOK on success or negative error code.
     172 */
     173int devman_add_function(const char *name, fun_type_t ftype,
     174    match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh)
     175{
    158176        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     177        int fun_handle;
    159178       
    160179        if (phone < 0)
     
    163182        async_serialize_start();
    164183       
    165         int match_count = list_count(&match_ids->ids); 
    166         ipc_call_t answer;
    167         aid_t req = async_send_2(phone, DEVMAN_ADD_CHILD_DEVICE, parent_handle, match_count, &answer);
     184        int match_count = list_count(&match_ids->ids);
     185        ipc_call_t answer;
     186
     187        aid_t req = async_send_3(phone, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype,
     188            devh, match_count, &answer);
    168189
    169190        sysarg_t retval = async_data_write_start(phone, name, str_size(name));
     
    180201        async_serialize_end();
    181202       
    182         if (retval != EOK) {
    183                 if (handle != NULL) {
    184                         *handle = -1;
    185                 }
    186                 return retval;
    187         }       
    188        
    189         if (handle != NULL)
    190                 *handle = (int) IPC_GET_ARG1(answer);   
    191                
    192         return retval;
    193 }
    194 
    195 int devman_add_device_to_class(devman_handle_t devman_handle, const char *class_name)
     203        if (retval == EOK)
     204                fun_handle = (int) IPC_GET_ARG1(answer);
     205        else
     206                fun_handle = -1;
     207       
     208        *funh = fun_handle;
     209
     210        return retval;
     211}
     212
     213int devman_add_device_to_class(devman_handle_t devman_handle,
     214    const char *class_name)
    196215{
    197216        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     
    202221        async_serialize_start();
    203222        ipc_call_t answer;
    204         aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, devman_handle, &answer);
    205        
    206         sysarg_t retval = async_data_write_start(phone, class_name, str_size(class_name));
     223        aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS,
     224            devman_handle, &answer);
     225       
     226        sysarg_t retval = async_data_write_start(phone, class_name,
     227            str_size(class_name));
    207228        if (retval != EOK) {
    208229                async_wait_for(req, NULL);
     
    214235        async_serialize_end();
    215236       
    216         return retval; 
     237        return retval;
    217238}
    218239
     
    222243        case DEVMAN_DRIVER:
    223244                if (devman_phone_driver >= 0) {
    224                         ipc_hangup(devman_phone_driver);
     245                        async_hangup(devman_phone_driver);
    225246                        devman_phone_driver = -1;
    226247                }
     
    228249        case DEVMAN_CLIENT:
    229250                if (devman_phone_client >= 0) {
    230                         ipc_hangup(devman_phone_client);
     251                        async_hangup(devman_phone_client);
    231252                        devman_phone_client = -1;
    232253                }
     
    267288}
    268289
    269 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, unsigned int flags)
     290int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     291    unsigned int flags)
    270292{
    271293        int phone = devman_get_phone(DEVMAN_CLIENT, flags);
     
    280302            &answer);
    281303       
    282         sysarg_t retval = async_data_write_start(phone, pathname, str_size(pathname));
     304        sysarg_t retval = async_data_write_start(phone, pathname,
     305            str_size(pathname));
    283306        if (retval != EOK) {
    284307                async_wait_for(req, NULL);
Note: See TracChangeset for help on using the changeset viewer.