source: mainline/uspace/lib/c/generic/devman.c@ cb0ca35

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cb0ca35 was be12474, checked in by Jiri Svoboda <jiri@…>, 10 years ago

Revisit a few uses of list_count, list_nth w.r.t. type used for object count.

  • Property mode set to 100644
File size: 17.2 KB
RevLine 
[729fa2d6]1/*
2 * Copyright (c) 2007 Josef Cejka
[4c9b28a]3 * Copyright (c) 2013 Jiri Svoboda
[729fa2d6]4 * Copyright (c) 2010 Lenka Trochtova
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
[64d2b10]30
31/** @addtogroup libc
[5cd136ab]32 * @{
33 */
34/** @file
35 */
[729fa2d6]36
[b72efe8]37#include <adt/list.h>
[c47e1a8]38#include <str.h>
[729fa2d6]39#include <ipc/services.h>
[79ae36dd]40#include <ns.h>
[729fa2d6]41#include <ipc/devman.h>
42#include <devman.h>
[622dea8]43#include <fibril_synch.h>
[79ae36dd]44#include <async.h>
[729fa2d6]45#include <errno.h>
46#include <malloc.h>
[3e6a98c5]47#include <stdbool.h>
[729fa2d6]48
[79ae36dd]49static FIBRIL_MUTEX_INITIALIZE(devman_driver_block_mutex);
50static FIBRIL_MUTEX_INITIALIZE(devman_client_block_mutex);
51
52static FIBRIL_MUTEX_INITIALIZE(devman_driver_mutex);
53static FIBRIL_MUTEX_INITIALIZE(devman_client_mutex);
[729fa2d6]54
[79ae36dd]55static async_sess_t *devman_driver_block_sess = NULL;
56static async_sess_t *devman_client_block_sess = NULL;
[622dea8]57
[79ae36dd]58static async_sess_t *devman_driver_sess = NULL;
59static async_sess_t *devman_client_sess = NULL;
60
61static void clone_session(fibril_mutex_t *mtx, async_sess_t *src,
62 async_sess_t **dst)
63{
64 fibril_mutex_lock(mtx);
65
66 if ((*dst == NULL) && (src != NULL))
67 *dst = src;
68
69 fibril_mutex_unlock(mtx);
70}
71
72/** Start an async exchange on the devman session (blocking).
73 *
74 * @param iface Device manager interface to choose
75 *
76 * @return New exchange.
77 *
78 */
[f9b2cb4c]79async_exch_t *devman_exchange_begin_blocking(iface_t iface)
[729fa2d6]80{
81 switch (iface) {
[f9b2cb4c]82 case INTERFACE_DDF_DRIVER:
[79ae36dd]83 fibril_mutex_lock(&devman_driver_block_mutex);
84
85 while (devman_driver_block_sess == NULL) {
86 clone_session(&devman_driver_mutex, devman_driver_sess,
87 &devman_driver_block_sess);
88
89 if (devman_driver_block_sess == NULL)
90 devman_driver_block_sess =
[f9b2cb4c]91 service_connect_blocking(SERVICE_DEVMAN,
92 INTERFACE_DDF_DRIVER, 0);
[622dea8]93 }
[729fa2d6]94
[79ae36dd]95 fibril_mutex_unlock(&devman_driver_block_mutex);
[729fa2d6]96
[79ae36dd]97 clone_session(&devman_driver_mutex, devman_driver_block_sess,
98 &devman_driver_sess);
99
100 return async_exchange_begin(devman_driver_block_sess);
[f9b2cb4c]101 case INTERFACE_DDF_CLIENT:
[79ae36dd]102 fibril_mutex_lock(&devman_client_block_mutex);
[729fa2d6]103
[79ae36dd]104 while (devman_client_block_sess == NULL) {
105 clone_session(&devman_client_mutex, devman_client_sess,
106 &devman_client_block_sess);
107
108 if (devman_client_block_sess == NULL)
109 devman_client_block_sess =
[f9b2cb4c]110 service_connect_blocking(SERVICE_DEVMAN,
111 INTERFACE_DDF_CLIENT, 0);
[4db43721]112 }
[729fa2d6]113
[79ae36dd]114 fibril_mutex_unlock(&devman_client_block_mutex);
115
116 clone_session(&devman_client_mutex, devman_client_block_sess,
117 &devman_client_sess);
118
119 return async_exchange_begin(devman_client_block_sess);
[729fa2d6]120 default:
[79ae36dd]121 return NULL;
[729fa2d6]122 }
123}
124
[79ae36dd]125/** Start an async exchange on the devman session.
126 *
127 * @param iface Device manager interface to choose
128 *
129 * @return New exchange.
130 *
131 */
[f9b2cb4c]132async_exch_t *devman_exchange_begin(iface_t iface)
[79ae36dd]133{
134 switch (iface) {
[f9b2cb4c]135 case INTERFACE_DDF_DRIVER:
[79ae36dd]136 fibril_mutex_lock(&devman_driver_mutex);
137
138 if (devman_driver_sess == NULL)
139 devman_driver_sess =
[f9b2cb4c]140 service_connect(SERVICE_DEVMAN,
141 INTERFACE_DDF_DRIVER, 0);
[79ae36dd]142
143 fibril_mutex_unlock(&devman_driver_mutex);
144
145 if (devman_driver_sess == NULL)
146 return NULL;
147
148 return async_exchange_begin(devman_driver_sess);
[f9b2cb4c]149 case INTERFACE_DDF_CLIENT:
[79ae36dd]150 fibril_mutex_lock(&devman_client_mutex);
151
152 if (devman_client_sess == NULL)
153 devman_client_sess =
[f9b2cb4c]154 service_connect(SERVICE_DEVMAN,
155 INTERFACE_DDF_CLIENT, 0);
[79ae36dd]156
157 fibril_mutex_unlock(&devman_client_mutex);
158
159 if (devman_client_sess == NULL)
160 return NULL;
161
162 return async_exchange_begin(devman_client_sess);
163 default:
164 return NULL;
165 }
166}
167
168/** Finish an async exchange on the devman session.
169 *
170 * @param exch Exchange to be finished.
171 *
172 */
173void devman_exchange_end(async_exch_t *exch)
174{
175 async_exchange_end(exch);
176}
177
[729fa2d6]178/** Register running driver with device manager. */
[f302586]179int devman_driver_register(const char *name)
[729fa2d6]180{
[f9b2cb4c]181 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
[729fa2d6]182
183 ipc_call_t answer;
[79ae36dd]184 aid_t req = async_send_2(exch, DEVMAN_DRIVER_REGISTER, 0, 0, &answer);
185 sysarg_t retval = async_data_write_start(exch, name, str_size(name));
186
187 devman_exchange_end(exch);
[729fa2d6]188
189 if (retval != EOK) {
[50b581d]190 async_forget(req);
[79ae36dd]191 return retval;
[729fa2d6]192 }
193
[f9b2cb4c]194 exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
195 async_connect_to_me(exch, 0, 0, 0);
[79ae36dd]196 devman_exchange_end(exch);
[729fa2d6]197
[79ae36dd]198 async_wait_for(req, &retval);
[729fa2d6]199 return retval;
200}
201
[8b1e15ac]202/** Add function to a device.
203 *
204 * Request devman to add a new function to the specified device owned by
205 * this driver task.
206 *
[79ae36dd]207 * @param name Name of the new function
208 * @param ftype Function type, fun_inner or fun_exposed
209 * @param match_ids Match IDs (should be empty for fun_exposed)
210 * @param devh Devman handle of the device
211 * @param funh Place to store handle of the new function
212 *
213 * @return EOK on success or negative error code.
[8b1e15ac]214 *
215 */
216int devman_add_function(const char *name, fun_type_t ftype,
217 match_id_list_t *match_ids, devman_handle_t devh, devman_handle_t *funh)
[1b367b4]218{
[be12474]219 unsigned long match_count = list_count(&match_ids->ids);
[f9b2cb4c]220 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
[79ae36dd]221
[7707954]222 ipc_call_t answer;
[79ae36dd]223 aid_t req = async_send_3(exch, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype,
[8b1e15ac]224 devh, match_count, &answer);
[79ae36dd]225 sysarg_t retval = async_data_write_start(exch, name, str_size(name));
[7707954]226 if (retval != EOK) {
[79ae36dd]227 devman_exchange_end(exch);
[50b581d]228 async_forget(req);
[7707954]229 return retval;
230 }
231
[feeac0d]232 list_foreach(match_ids->ids, link, match_id_t, match_id) {
[15e54f5]233 ipc_call_t answer2;
234 aid_t req2 = async_send_1(exch, DEVMAN_ADD_MATCH_ID,
235 match_id->score, &answer2);
[79ae36dd]236 retval = async_data_write_start(exch, match_id->id,
237 str_size(match_id->id));
238 if (retval != EOK) {
239 devman_exchange_end(exch);
[50b581d]240 async_forget(req2);
241 async_forget(req);
[79ae36dd]242 return retval;
243 }
244
[15e54f5]245 async_wait_for(req2, &retval);
[79ae36dd]246 if (retval != EOK) {
247 devman_exchange_end(exch);
[50b581d]248 async_forget(req);
[79ae36dd]249 return retval;
250 }
[4265fd4]251 }
[7707954]252
[79ae36dd]253 devman_exchange_end(exch);
[15e54f5]254
255 async_wait_for(req, &retval);
[e6211f8]256 if (retval == EOK) {
[15e54f5]257 if (funh != NULL)
258 *funh = (int) IPC_GET_ARG1(answer);
259 } else {
260 if (funh != NULL)
261 *funh = -1;
262 }
263
264 return retval;
[7707954]265}
266
[1dc4a5e]267int devman_add_device_to_category(devman_handle_t devman_handle,
268 const char *cat_name)
[692c40cb]269{
[f9b2cb4c]270 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
[692c40cb]271
272 ipc_call_t answer;
[1dc4a5e]273 aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY,
[1b367b4]274 devman_handle, &answer);
[1dc4a5e]275 sysarg_t retval = async_data_write_start(exch, cat_name,
276 str_size(cat_name));
[79ae36dd]277
278 devman_exchange_end(exch);
279
[692c40cb]280 if (retval != EOK) {
[50b581d]281 async_forget(req);
[692c40cb]282 return retval;
283 }
284
285 async_wait_for(req, &retval);
[1b367b4]286 return retval;
[692c40cb]287}
288
[f9b2cb4c]289async_sess_t *devman_device_connect(devman_handle_t handle, unsigned int flags)
[5cd136ab]290{
[79ae36dd]291 async_sess_t *sess;
[5cd136ab]292
[79ae36dd]293 if (flags & IPC_FLAG_BLOCKING)
[f9b2cb4c]294 sess = service_connect_blocking(SERVICE_DEVMAN,
295 INTERFACE_DEVMAN_DEVICE, handle);
[79ae36dd]296 else
[f9b2cb4c]297 sess = service_connect(SERVICE_DEVMAN,
298 INTERFACE_DEVMAN_DEVICE, handle);
[79ae36dd]299
300 return sess;
[5cd136ab]301}
302
[d0dd7b5]303/** Remove function from device.
304 *
305 * Request devman to remove function owned by this driver task.
306 * @param funh Devman handle of the function
307 *
308 * @return EOK on success or negative error code.
309 */
310int devman_remove_function(devman_handle_t funh)
311{
312 async_exch_t *exch;
313 sysarg_t retval;
314
[f9b2cb4c]315 exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
[d0dd7b5]316 retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh);
317 devman_exchange_end(exch);
318
319 return (int) retval;
320}
321
[1a5b252]322int devman_drv_fun_online(devman_handle_t funh)
323{
[f9b2cb4c]324 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
[1a5b252]325 if (exch == NULL)
326 return ENOMEM;
327
328 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh);
329
330 devman_exchange_end(exch);
331 return (int) retval;
332}
333
334int devman_drv_fun_offline(devman_handle_t funh)
335{
[f9b2cb4c]336 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_DRIVER);
[1a5b252]337 if (exch == NULL)
338 return ENOMEM;
339
340 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh);
341
342 devman_exchange_end(exch);
343 return (int) retval;
344}
345
[f9b2cb4c]346async_sess_t *devman_parent_device_connect(devman_handle_t handle,
347 unsigned int flags)
[5cd136ab]348{
[79ae36dd]349 async_sess_t *sess;
[5cd136ab]350
[79ae36dd]351 if (flags & IPC_FLAG_BLOCKING)
[f9b2cb4c]352 sess = service_connect_blocking(SERVICE_DEVMAN,
353 INTERFACE_DEVMAN_PARENT, handle);
[79ae36dd]354 else
[f9b2cb4c]355 sess = service_connect_blocking(SERVICE_DEVMAN,
356 INTERFACE_DEVMAN_PARENT, handle);
[79ae36dd]357
358 return sess;
[5cd136ab]359}
360
[7beb220]361int devman_fun_get_handle(const char *pathname, devman_handle_t *handle,
[1b367b4]362 unsigned int flags)
[f658458]363{
[79ae36dd]364 async_exch_t *exch;
365
366 if (flags & IPC_FLAG_BLOCKING)
[f9b2cb4c]367 exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
[79ae36dd]368 else {
[f9b2cb4c]369 exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[79ae36dd]370 if (exch == NULL)
[e280857]371 return ENOMEM;
[79ae36dd]372 }
[f658458]373
374 ipc_call_t answer;
[79ae36dd]375 aid_t req = async_send_2(exch, DEVMAN_DEVICE_GET_HANDLE, flags, 0,
[f658458]376 &answer);
[79ae36dd]377 sysarg_t retval = async_data_write_start(exch, pathname,
[1b367b4]378 str_size(pathname));
[79ae36dd]379
380 devman_exchange_end(exch);
381
[f658458]382 if (retval != EOK) {
[50b581d]383 async_forget(req);
[f658458]384 return retval;
385 }
386
387 async_wait_for(req, &retval);
388
389 if (retval != EOK) {
390 if (handle != NULL)
[0b5a4131]391 *handle = (devman_handle_t) -1;
[79ae36dd]392
[f658458]393 return retval;
394 }
395
396 if (handle != NULL)
[0b5a4131]397 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
[f658458]398
399 return retval;
400}
401
[4c9b28a]402static int devman_get_str_internal(sysarg_t method, sysarg_t arg1,
403 sysarg_t arg2, sysarg_t *r1, char *buf, size_t buf_size)
[431d6d6]404{
[7beb220]405 async_exch_t *exch;
406 ipc_call_t dreply;
407 size_t act_size;
408 sysarg_t dretval;
[79ae36dd]409
[f9b2cb4c]410 exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
[79ae36dd]411
[7beb220]412 ipc_call_t answer;
[4c9b28a]413 aid_t req = async_send_2(exch, method, arg1, arg2, &answer);
[7beb220]414 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply);
415 async_wait_for(dreq, &dretval);
[79ae36dd]416
417 devman_exchange_end(exch);
418
[7beb220]419 if (dretval != EOK) {
[50b581d]420 async_forget(req);
[7beb220]421 return dretval;
[431d6d6]422 }
[79ae36dd]423
[7beb220]424 sysarg_t retval;
425 async_wait_for(req, &retval);
426
[3f57fb7]427 if (retval != EOK) {
[7beb220]428 return retval;
[3f57fb7]429 }
[7beb220]430
[4c9b28a]431 if (r1 != NULL)
432 *r1 = IPC_GET_ARG1(answer);
[7beb220]433 act_size = IPC_GET_ARG2(dreply);
434 assert(act_size <= buf_size - 1);
435 buf[act_size] = '\0';
436
437 return EOK;
438}
439
440int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size)
441{
[4c9b28a]442 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, 0, NULL,
443 buf, buf_size);
444}
445
446int devman_fun_get_match_id(devman_handle_t handle, size_t index, char *buf,
447 size_t buf_size, unsigned int *rscore)
448{
449 int rc;
450 sysarg_t score = 0;
451
452 rc = devman_get_str_internal(DEVMAN_FUN_GET_MATCH_ID, handle, index,
453 &score, buf, buf_size);
454 if (rc != EOK)
455 return rc;
456
457 *rscore = score;
458 return rc;
[7beb220]459}
460
461int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size)
462{
[4c9b28a]463 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, 0, NULL,
464 buf, buf_size);
[7beb220]465}
466
[3f57fb7]467int devman_fun_get_driver_name(devman_handle_t handle, char *buf, size_t buf_size)
468{
[4c9b28a]469 return devman_get_str_internal(DEVMAN_FUN_GET_DRIVER_NAME, handle, 0,
470 NULL, buf, buf_size);
[3f57fb7]471}
472
[1a5b252]473int devman_fun_online(devman_handle_t funh)
474{
[f9b2cb4c]475 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[1a5b252]476 if (exch == NULL)
477 return ENOMEM;
478
479 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh);
480
481 devman_exchange_end(exch);
482 return (int) retval;
483}
484
485int devman_fun_offline(devman_handle_t funh)
486{
[f9b2cb4c]487 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[1a5b252]488 if (exch == NULL)
489 return ENOMEM;
490
491 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh);
492
493 devman_exchange_end(exch);
494 return (int) retval;
495}
496
[7beb220]497static int devman_get_handles_once(sysarg_t method, sysarg_t arg1,
498 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size)
499{
[f9b2cb4c]500 async_exch_t *exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
[7beb220]501
502 ipc_call_t answer;
503 aid_t req = async_send_1(exch, method, arg1, &answer);
504 int rc = async_data_read_start(exch, handle_buf, buf_size);
[79ae36dd]505
[7beb220]506 devman_exchange_end(exch);
[79ae36dd]507
[7beb220]508 if (rc != EOK) {
[50b581d]509 async_forget(req);
[7beb220]510 return rc;
[431d6d6]511 }
[79ae36dd]512
[7beb220]513 sysarg_t retval;
514 async_wait_for(req, &retval);
[79ae36dd]515
[7beb220]516 if (retval != EOK) {
517 return retval;
518 }
[79ae36dd]519
[7beb220]520 *act_size = IPC_GET_ARG1(answer);
[431d6d6]521 return EOK;
522}
523
[7beb220]524/** Get list of handles.
525 *
526 * Returns an allocated array of handles.
527 *
528 * @param method IPC method
529 * @param arg1 IPC argument 1
530 * @param data Place to store pointer to array of handles
531 * @param count Place to store number of handles
532 * @return EOK on success or negative error code
533 */
534static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1,
535 devman_handle_t **data, size_t *count)
536{
537 devman_handle_t *handles;
538 size_t act_size;
539 size_t alloc_size;
540 int rc;
541
542 *data = NULL;
543 act_size = 0; /* silence warning */
544
545 rc = devman_get_handles_once(method, arg1, NULL, 0,
546 &act_size);
547 if (rc != EOK)
548 return rc;
549
550 alloc_size = act_size;
551 handles = malloc(alloc_size);
552 if (handles == NULL)
553 return ENOMEM;
554
555 while (true) {
556 rc = devman_get_handles_once(method, arg1, handles, alloc_size,
557 &act_size);
558 if (rc != EOK)
559 return rc;
560
561 if (act_size <= alloc_size)
562 break;
563
564 alloc_size *= 2;
565 free(handles);
566
567 handles = malloc(alloc_size);
568 if (handles == NULL)
569 return ENOMEM;
570 }
571
572 *count = act_size / sizeof(devman_handle_t);
573 *data = handles;
574 return EOK;
575}
576
577int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh)
578{
[f9b2cb4c]579 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[7beb220]580 if (exch == NULL)
581 return ENOMEM;
582
583 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
584 funh, devh);
585
586 devman_exchange_end(exch);
587 return (int) retval;
588}
589
590int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs,
591 size_t *count)
592{
593 return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS,
594 devh, funcs, count);
595}
596
[1db5669]597int devman_dev_get_parent(devman_handle_t devh, devman_handle_t *funh)
598{
[f9b2cb4c]599 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[1db5669]600 if (exch == NULL)
601 return ENOMEM;
602
603 sysarg_t retval = async_req_1_1(exch, DEVMAN_DEV_GET_PARENT,
604 devh, funh);
605
606 devman_exchange_end(exch);
607 return (int) retval;
608}
609
[e280857]610int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
611{
[f9b2cb4c]612 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[e280857]613 if (exch == NULL)
614 return ENOMEM;
615
616 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
617 sid, handle);
618
619 devman_exchange_end(exch);
620 return (int) retval;
621}
622
[0511549]623int devman_get_drivers(devman_handle_t **drvs,
624 size_t *count)
625{
626 return devman_get_handles_internal(DEVMAN_GET_DRIVERS, 0, drvs, count);
627}
628
[1db5669]629int devman_driver_get_devices(devman_handle_t drvh, devman_handle_t **devs,
630 size_t *count)
631{
632 return devman_get_handles_internal(DEVMAN_DRIVER_GET_DEVICES,
633 drvh, devs, count);
634}
635
[7969087]636int devman_driver_get_handle(const char *drvname, devman_handle_t *handle)
637{
638 async_exch_t *exch;
639
[f9b2cb4c]640 exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[7969087]641 if (exch == NULL)
642 return ENOMEM;
643
644 ipc_call_t answer;
645 aid_t req = async_send_0(exch, DEVMAN_DRIVER_GET_HANDLE, &answer);
646 sysarg_t retval = async_data_write_start(exch, drvname,
647 str_size(drvname));
648
649 devman_exchange_end(exch);
650
651 if (retval != EOK) {
652 async_forget(req);
653 return retval;
654 }
655
656 async_wait_for(req, &retval);
657
658 if (retval != EOK) {
659 if (handle != NULL)
660 *handle = (devman_handle_t) -1;
661
662 return retval;
663 }
664
665 if (handle != NULL)
666 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
667
668 return retval;
669}
670
[4c9b28a]671int devman_driver_get_match_id(devman_handle_t handle, size_t index, char *buf,
672 size_t buf_size, unsigned int *rscore)
673{
674 int rc;
675 sysarg_t score = 0;
676
677 rc = devman_get_str_internal(DEVMAN_DRIVER_GET_MATCH_ID, handle, index,
678 &score, buf, buf_size);
679 if (rc != EOK)
680 return rc;
681
682 *rscore = score;
683 return rc;
684}
685
[0511549]686int devman_driver_get_name(devman_handle_t handle, char *buf, size_t buf_size)
687{
[4c9b28a]688 return devman_get_str_internal(DEVMAN_DRIVER_GET_NAME, handle, 0, NULL,
689 buf, buf_size);
[0511549]690}
691
[e5556e4a]692int devman_driver_get_state(devman_handle_t drvh, driver_state_t *rstate)
693{
694 sysarg_t state;
[f9b2cb4c]695 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[e5556e4a]696 if (exch == NULL)
697 return ENOMEM;
698
699 int rc = async_req_1_1(exch, DEVMAN_DRIVER_GET_STATE, drvh,
700 &state);
701
702 devman_exchange_end(exch);
703 if (rc != EOK)
704 return rc;
705
706 *rstate = state;
707 return rc;
708}
709
[7969087]710int devman_driver_load(devman_handle_t drvh)
711{
[f9b2cb4c]712 async_exch_t *exch = devman_exchange_begin(INTERFACE_DDF_CLIENT);
[7969087]713 if (exch == NULL)
714 return ENOMEM;
715
716 int rc = async_req_1_0(exch, DEVMAN_DRIVER_LOAD, drvh);
717
718 devman_exchange_end(exch);
719 return rc;
720}
721
[5cd136ab]722/** @}
[398c4d7]723 */
Note: See TracBrowser for help on using the repository browser.