Changeset ad7a6c9 in mainline for uspace/lib/c/generic/devman.c
- Timestamp:
- 2011-03-30T13:10:24Z (14 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/devman.c
r6e50466 rad7a6c9 28 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 30 31 /** @addtogroup libc 32 32 * @{ 33 33 */ … … 37 37 #include <str.h> 38 38 #include <stdio.h> 39 #include <ipc/ipc.h>40 39 #include <ipc/services.h> 41 40 #include <ipc/devman.h> 42 41 #include <devman.h> 43 42 #include <async.h> 43 #include <fibril_synch.h> 44 44 #include <errno.h> 45 45 #include <malloc.h> … … 50 50 static int devman_phone_client = -1; 51 51 52 static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex); 53 52 54 int devman_get_phone(devman_interface_t iface, unsigned int flags) 53 55 { 54 56 switch (iface) { 55 57 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); 57 61 return devman_phone_driver; 62 } 58 63 59 64 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); 62 67 else 63 devman_phone_driver = ipc_connect_me_to(PHONE_NS,68 devman_phone_driver = async_connect_me_to(PHONE_NS, 64 69 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 65 70 71 fibril_mutex_unlock(&devman_phone_mutex); 66 72 return devman_phone_driver; 67 73 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); 69 77 return devman_phone_client; 78 } 70 79 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, 73 85 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 74 else 75 devman_phone_client = ipc_connect_me_to(PHONE_NS, 76 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 86 } 77 87 88 fibril_mutex_unlock(&devman_phone_mutex); 78 89 return devman_phone_client; 79 90 default: … … 104 115 async_set_client_connection(conn); 105 116 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); 108 118 async_wait_for(req, &retval); 109 119 … … 113 123 } 114 124 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)); 125 static 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 120 134 async_wait_for(req, NULL); 121 135 return retval; … … 123 137 124 138 125 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 139 static int devman_send_match_ids(int phone, match_id_list_t *match_ids) 126 140 { 127 141 link_t *link = match_ids->ids.next; 128 142 match_id_t *match_id = NULL; 129 143 int ret = EOK; 130 144 131 145 while (link != &match_ids->ids) { 132 146 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 138 154 link = link->next; 139 155 } 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 */ 173 int 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 { 146 176 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); 177 int fun_handle; 147 178 148 179 if (phone < 0) … … 151 182 async_serialize_start(); 152 183 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); 156 189 157 190 sysarg_t retval = async_data_write_start(phone, name, str_size(name)); … … 168 201 async_serialize_end(); 169 202 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 213 int devman_add_device_to_class(devman_handle_t devman_handle, 214 const char *class_name) 184 215 { 185 216 int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING); … … 190 221 async_serialize_start(); 191 222 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)); 195 228 if (retval != EOK) { 196 229 async_wait_for(req, NULL); … … 202 235 async_serialize_end(); 203 236 204 return retval; 237 return retval; 205 238 } 206 239 … … 210 243 case DEVMAN_DRIVER: 211 244 if (devman_phone_driver >= 0) { 212 ipc_hangup(devman_phone_driver);245 async_hangup(devman_phone_driver); 213 246 devman_phone_driver = -1; 214 247 } … … 216 249 case DEVMAN_CLIENT: 217 250 if (devman_phone_client >= 0) { 218 ipc_hangup(devman_phone_client);251 async_hangup(devman_phone_client); 219 252 devman_phone_client = -1; 220 253 } … … 230 263 231 264 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, 233 266 DEVMAN_CONNECT_TO_DEVICE, handle); 234 267 } else { 235 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,268 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 236 269 DEVMAN_CONNECT_TO_DEVICE, handle); 237 270 } … … 245 278 246 279 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, 248 281 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 249 282 } else { 250 phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAN,283 phone = async_connect_me_to(PHONE_NS, SERVICE_DEVMAN, 251 284 DEVMAN_CONNECT_TO_PARENTS_DEVICE, handle); 252 285 } … … 255 288 } 256 289 257 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, unsigned int flags) 290 int devman_device_get_handle(const char *pathname, devman_handle_t *handle, 291 unsigned int flags) 258 292 { 259 293 int phone = devman_get_phone(DEVMAN_CLIENT, flags); … … 268 302 &answer); 269 303 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)); 271 306 if (retval != EOK) { 272 307 async_wait_for(req, NULL);
Note:
See TracChangeset
for help on using the changeset viewer.