Changeset ad7a6c9 in mainline for uspace/lib/c/generic/devman.c


Ignore:
Timestamp:
2011-03-30T13:10:24Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4ae90f9
Parents:
6e50466 (diff), d6b81941 (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 mainline changes

File:
1 edited

Legend:

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

    r6e50466 rad7a6c9  
    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>
    4241#include <devman.h>
    4342#include <async.h>
     43#include <fibril_synch.h>
    4444#include <errno.h>
    4545#include <malloc.h>
     
    5050static int devman_phone_client = -1;
    5151
     52static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex);
     53
    5254int devman_get_phone(devman_interface_t iface, unsigned int flags)
    5355{
    5456        switch (iface) {
    5557        case DEVMAN_DRIVER:
    56                 if (devman_phone_driver >= 0)
     58                fibril_mutex_lock(&devman_phone_mutex);
     59                if (devman_phone_driver >= 0) {
     60                        fibril_mutex_unlock(&devman_phone_mutex);
    5761                        return devman_phone_driver;
     62                }
    5863               
    5964                if (flags & IPC_FLAG_BLOCKING)
    60                         devman_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,
    61                             SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
     65                        devman_phone_driver = async_connect_me_to_blocking(
     66                            PHONE_NS, SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    6267                else
    63                         devman_phone_driver = ipc_connect_me_to(PHONE_NS,
     68                        devman_phone_driver = async_connect_me_to(PHONE_NS,
    6469                            SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    6570               
     71                fibril_mutex_unlock(&devman_phone_mutex);
    6672                return devman_phone_driver;
    6773        case DEVMAN_CLIENT:
    68                 if (devman_phone_client >= 0)
     74                fibril_mutex_lock(&devman_phone_mutex);
     75                if (devman_phone_client >= 0) {
     76                        fibril_mutex_unlock(&devman_phone_mutex);
    6977                        return devman_phone_client;
     78                }
    7079               
    71                 if (flags & IPC_FLAG_BLOCKING)
    72                         devman_phone_client = ipc_connect_me_to_blocking(PHONE_NS,
     80                if (flags & IPC_FLAG_BLOCKING) {
     81                        devman_phone_client = async_connect_me_to_blocking(
     82                            PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
     83                } else {
     84                        devman_phone_client = async_connect_me_to(PHONE_NS,
    7385                            SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
    74                 else
    75                         devman_phone_client = ipc_connect_me_to(PHONE_NS,
    76                             SERVICE_DEVMAN, DEVMAN_CLIENT, 0);
     86                }
    7787               
     88                fibril_mutex_unlock(&devman_phone_mutex);
    7889                return devman_phone_client;
    7990        default:
     
    104115        async_set_client_connection(conn);
    105116       
    106         sysarg_t callback_phonehash;
    107         ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash);
     117        async_connect_to_me(phone, 0, 0, 0, NULL);
    108118        async_wait_for(req, &retval);
    109119       
     
    113123}
    114124
    115 static int devman_send_match_id(int phone, match_id_t *match_id) \
    116 {
    117         ipc_call_t answer;
    118         aid_t req = async_send_1(phone, DEVMAN_ADD_MATCH_ID, match_id->score, &answer);
    119         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
    120134        async_wait_for(req, NULL);
    121135        return retval;
     
    123137
    124138
    125 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)
    126140{
    127141        link_t *link = match_ids->ids.next;
    128142        match_id_t *match_id = NULL;
    129143        int ret = EOK;
    130        
     144
    131145        while (link != &match_ids->ids) {
    132146                match_id = list_get_instance(link, match_id_t, link);
    133                 if (EOK != (ret = devman_send_match_id(phone, match_id)))
    134                 {
    135                         printf("Driver failed to send match id, error number = %d\n", ret);
    136                         return ret;                     
    137                 }
     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
    138154                link = link->next;
    139155        }
    140         return ret;     
    141 }
    142 
    143 int devman_child_device_register(
    144         const char *name, match_id_list_t *match_ids, devman_handle_t parent_handle, devman_handle_t *handle)
    145 {               
     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{
    146176        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     177        int fun_handle;
    147178       
    148179        if (phone < 0)
     
    151182        async_serialize_start();
    152183       
    153         int match_count = list_count(&match_ids->ids); 
    154         ipc_call_t answer;
    155         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);
    156189
    157190        sysarg_t retval = async_data_write_start(phone, name, str_size(name));
     
    168201        async_serialize_end();
    169202       
    170         if (retval != EOK) {
    171                 if (handle != NULL) {
    172                         *handle = -1;
    173                 }
    174                 return retval;
    175         }       
    176        
    177         if (handle != NULL)
    178                 *handle = (int) IPC_GET_ARG1(answer);   
    179                
    180         return retval;
    181 }
    182 
    183 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)
    184215{
    185216        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
     
    190221        async_serialize_start();
    191222        ipc_call_t answer;
    192         aid_t req = async_send_1(phone, DEVMAN_ADD_DEVICE_TO_CLASS, devman_handle, &answer);
    193        
    194         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));
    195228        if (retval != EOK) {
    196229                async_wait_for(req, NULL);
     
    202235        async_serialize_end();
    203236       
    204         return retval; 
     237        return retval;
    205238}
    206239
     
    210243        case DEVMAN_DRIVER:
    211244                if (devman_phone_driver >= 0) {
    212                         ipc_hangup(devman_phone_driver);
     245                        async_hangup(devman_phone_driver);
    213246                        devman_phone_driver = -1;
    214247                }
     
    216249        case DEVMAN_CLIENT:
    217250                if (devman_phone_client >= 0) {
    218                         ipc_hangup(devman_phone_client);
     251                        async_hangup(devman_phone_client);
    219252                        devman_phone_client = -1;
    220253                }
     
    230263       
    231264        if (flags & IPC_FLAG_BLOCKING) {
    232                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     265                phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
    233266                    DEVMAN_CONNECT_TO_DEVICE, handle);
    234267        } else {
    235                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     268                phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
    236269                    DEVMAN_CONNECT_TO_DEVICE, handle);
    237270        }
     
    245278       
    246279        if (flags & IPC_FLAG_BLOCKING) {
    247                 phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
     280                phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAN,
    248281                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
    249282        } else {
    250                 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
     283                phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN,
    251284                    DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle);
    252285        }
     
    255288}
    256289
    257 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)
    258292{
    259293        int phone = devman_get_phone(DEVMAN_CLIENT, flags);
     
    268302            &answer);
    269303       
    270         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));
    271306        if (retval != EOK) {
    272307                async_wait_for(req, NULL);
Note: See TracChangeset for help on using the changeset viewer.