source: mainline/uspace/lib/drv/generic/driver.c@ f1fae414

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

Separate list_t typedef from link_t (user-space part).

  • list_t represents lists
  • Use list_first(), list_last(), list_empty() where appropriate
  • Use list_foreach() where possible
  • assert_link_not_used()
  • usb_hid_report_path_free() shall not unlink the path, caller must do it
  • Property mode set to 100644
File size: 16.4 KB
RevLine 
[c16cf62]1/*
2 * Copyright (c) 2010 Lenka Trochtova
[83a2f43]3 * Copyright (c) 2011 Jiri Svoboda
[c16cf62]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/**
31 * @defgroup libdrv generic device driver support.
32 * @brief HelenOS generic device driver support.
33 * @{
34 */
35
36/** @file
37 */
[52b7b1bb]38
[c16cf62]39#include <assert.h>
40#include <ipc/services.h>
41#include <ipc/ns.h>
42#include <async.h>
43#include <stdio.h>
44#include <errno.h>
45#include <bool.h>
46#include <fibril_synch.h>
47#include <stdlib.h>
[c47e1a8]48#include <str.h>
[3ad7b1c]49#include <str_error.h>
[c16cf62]50#include <ctype.h>
[66babbd]51#include <errno.h>
[7e752b2]52#include <inttypes.h>
[af6b5157]53#include <devman.h>
[c16cf62]54
[084ff99]55#include <ipc/driver.h>
[c16cf62]56
[5fdd7c3]57#include "dev_iface.h"
[af6b5157]58#include "ddf/driver.h"
59#include "ddf/interrupt.h"
[c16cf62]60
[36f2b3e]61/** Driver structure */
[c16cf62]62static driver_t *driver;
[7f8b581]63
[36f2b3e]64/** Devices */
[8b1e15ac]65LIST_INITIALIZE(functions);
66FIBRIL_MUTEX_INITIALIZE(functions_mutex);
[084ff99]67
[36f2b3e]68/** Interrupts */
[7f8b581]69static interrupt_context_list_t interrupt_contexts;
70
71static irq_cmd_t default_cmds[] = {
72 {
73 .cmd = CMD_ACCEPT
74 }
75};
76
77static irq_code_t default_pseudocode = {
78 sizeof(default_cmds) / sizeof(irq_cmd_t),
79 default_cmds
80};
81
[83a2f43]82static ddf_dev_t *create_device(void);
83static void delete_device(ddf_dev_t *);
[af6b5157]84static remote_handler_t *function_get_default_handler(ddf_fun_t *);
85static void *function_get_ops(ddf_fun_t *, dev_inferface_idx_t);
[7f8b581]86
87static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
[7a252ec8]88{
[228e490]89 int id = (int)IPC_GET_IMETHOD(*icall);
[7a252ec8]90 interrupt_context_t *ctx;
91
92 ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
[36f2b3e]93 if (ctx != NULL && ctx->handler != NULL)
[7a252ec8]94 (*ctx->handler)(ctx->dev, iid, icall);
[7f8b581]95}
96
[5fdd7c3]97interrupt_context_t *create_interrupt_context(void)
98{
99 interrupt_context_t *ctx;
100
101 ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
102 if (ctx != NULL)
103 memset(ctx, 0, sizeof(interrupt_context_t));
104
105 return ctx;
106}
107
108void delete_interrupt_context(interrupt_context_t *ctx)
109{
110 if (ctx != NULL)
111 free(ctx);
112}
113
114void init_interrupt_context_list(interrupt_context_list_t *list)
115{
116 memset(list, 0, sizeof(interrupt_context_list_t));
117 fibril_mutex_initialize(&list->mutex);
118 list_initialize(&list->contexts);
119}
120
121void
122add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
123{
124 fibril_mutex_lock(&list->mutex);
125 ctx->id = list->curr_id++;
126 list_append(&ctx->link, &list->contexts);
127 fibril_mutex_unlock(&list->mutex);
128}
129
130void remove_interrupt_context(interrupt_context_list_t *list,
131 interrupt_context_t *ctx)
132{
133 fibril_mutex_lock(&list->mutex);
134 list_remove(&ctx->link);
135 fibril_mutex_unlock(&list->mutex);
136}
137
138interrupt_context_t *
139find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
140{
141 interrupt_context_t *ctx;
142
[b72efe8]143 fibril_mutex_lock(&list->mutex);
144
145 list_foreach(list->contexts, link) {
[5fdd7c3]146 ctx = list_get_instance(link, interrupt_context_t, link);
147 if (ctx->id == id) {
148 fibril_mutex_unlock(&list->mutex);
149 return ctx;
150 }
151 }
152
153 fibril_mutex_unlock(&list->mutex);
154 return NULL;
155}
156
157interrupt_context_t *
[83a2f43]158find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
[5fdd7c3]159{
160 interrupt_context_t *ctx;
161
[b72efe8]162 fibril_mutex_lock(&list->mutex);
163
164 list_foreach(list->contexts, link) {
[5fdd7c3]165 ctx = list_get_instance(link, interrupt_context_t, link);
166 if (ctx->irq == irq && ctx->dev == dev) {
167 fibril_mutex_unlock(&list->mutex);
168 return ctx;
169 }
170 }
171
172 fibril_mutex_unlock(&list->mutex);
173 return NULL;
174}
175
176
[7a252ec8]177int
[83a2f43]178register_interrupt_handler(ddf_dev_t *dev, int irq, interrupt_handler_t *handler,
[7a252ec8]179 irq_code_t *pseudocode)
[7f8b581]180{
181 interrupt_context_t *ctx = create_interrupt_context();
182
183 ctx->dev = dev;
184 ctx->irq = irq;
185 ctx->handler = handler;
186
187 add_interrupt_context(&interrupt_contexts, ctx);
188
[36f2b3e]189 if (pseudocode == NULL)
[7f8b581]190 pseudocode = &default_pseudocode;
191
[ffa2c8ef]192 int res = register_irq(irq, dev->handle, ctx->id, pseudocode);
[36f2b3e]193 if (res != EOK) {
[7f8b581]194 remove_interrupt_context(&interrupt_contexts, ctx);
195 delete_interrupt_context(ctx);
196 }
[7a252ec8]197
198 return res;
[7f8b581]199}
200
[83a2f43]201int unregister_interrupt_handler(ddf_dev_t *dev, int irq)
[7f8b581]202{
[7a252ec8]203 interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
204 dev, irq);
[ffa2c8ef]205 int res = unregister_irq(irq, dev->handle);
[36f2b3e]206
207 if (ctx != NULL) {
[7f8b581]208 remove_interrupt_context(&interrupt_contexts, ctx);
[7a252ec8]209 delete_interrupt_context(ctx);
[7f8b581]210 }
[36f2b3e]211
[7f8b581]212 return res;
213}
214
[83a2f43]215static void add_to_functions_list(ddf_fun_t *fun)
[9a66bc2e]216{
[8b1e15ac]217 fibril_mutex_lock(&functions_mutex);
218 list_append(&fun->link, &functions);
219 fibril_mutex_unlock(&functions_mutex);
[9a66bc2e]220}
221
[83a2f43]222static void remove_from_functions_list(ddf_fun_t *fun)
[9a66bc2e]223{
[8b1e15ac]224 fibril_mutex_lock(&functions_mutex);
225 list_remove(&fun->link);
226 fibril_mutex_unlock(&functions_mutex);
[9a66bc2e]227}
228
[b72efe8]229static ddf_fun_t *driver_get_function(list_t *functions, devman_handle_t handle)
[52b7b1bb]230{
[83a2f43]231 ddf_fun_t *fun = NULL;
[8b1e15ac]232
233 fibril_mutex_lock(&functions_mutex);
234
[b72efe8]235 list_foreach(*functions, link) {
[83a2f43]236 fun = list_get_instance(link, ddf_fun_t, link);
[8b1e15ac]237 if (fun->handle == handle) {
238 fibril_mutex_unlock(&functions_mutex);
239 return fun;
[a1769ee]240 }
241 }
[36f2b3e]242
[8b1e15ac]243 fibril_mutex_unlock(&functions_mutex);
[36f2b3e]244
[a1769ee]245 return NULL;
246}
247
[52b7b1bb]248static void driver_add_device(ipc_callid_t iid, ipc_call_t *icall)
[084ff99]249{
[df747b9c]250 char *dev_name = NULL;
[36f2b3e]251 int res;
[9a66bc2e]252
[d35ac1d]253 devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
[8b1e15ac]254 devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
[d35ac1d]255
[83a2f43]256 ddf_dev_t *dev = create_device();
[084ff99]257 dev->handle = dev_handle;
[8b1e15ac]258
[7a252ec8]259 async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
[df747b9c]260 dev->name = dev_name;
[8b1e15ac]261
262 /*
263 * Currently not used, parent fun handle is stored in context
264 * of the connection to the parent device driver.
265 */
266 (void) parent_fun_handle;
[0d6915f]267
[df747b9c]268 res = driver->driver_ops->add_device(dev);
[fc51296]269 if (res != EOK)
[7a252ec8]270 delete_device(dev);
[df747b9c]271
[ffa2c8ef]272 async_answer_0(iid, res);
[084ff99]273}
[c16cf62]274
275static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
276{
277 /* Accept connection */
[ffa2c8ef]278 async_answer_0(iid, EOK);
[36f2b3e]279
[79ae36dd]280 while (true) {
[c16cf62]281 ipc_call_t call;
282 ipc_callid_t callid = async_get_call(&call);
[36f2b3e]283
[79ae36dd]284 if (!IPC_GET_IMETHOD(call))
285 break;
286
[228e490]287 switch (IPC_GET_IMETHOD(call)) {
[c16cf62]288 case DRIVER_ADD_DEVICE:
[084ff99]289 driver_add_device(callid, &call);
[c16cf62]290 break;
291 default:
[ffa2c8ef]292 async_answer_0(callid, ENOENT);
[c16cf62]293 }
[52b7b1bb]294 }
[c16cf62]295}
296
[79ae36dd]297/** Generic client connection handler both for applications and drivers.
298 *
299 * @param drv True for driver client, false for other clients
300 * (applications, services, etc.).
[52b7b1bb]301 *
[a1769ee]302 */
[9a66bc2e]303static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
[52b7b1bb]304{
[7a252ec8]305 /*
306 * Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of
307 * the device to which the client connected.
308 */
[0b5a4131]309 devman_handle_t handle = IPC_GET_ARG2(*icall);
[83a2f43]310 ddf_fun_t *fun = driver_get_function(&functions, handle);
[79ae36dd]311
[8b1e15ac]312 if (fun == NULL) {
313 printf("%s: driver_connection_gen error - no function with handle"
[7e752b2]314 " %" PRIun " was found.\n", driver->name, handle);
[ffa2c8ef]315 async_answer_0(iid, ENOENT);
[a1769ee]316 return;
317 }
[5cd136ab]318
[7a252ec8]319 /*
320 * TODO - if the client is not a driver, check whether it is allowed to
321 * use the device.
322 */
[36f2b3e]323
[25a7e11d]324 int ret = EOK;
[8b1e15ac]325 /* Open device function */
326 if (fun->ops != NULL && fun->ops->open != NULL)
327 ret = (*fun->ops->open)(fun);
[a1769ee]328
[ffa2c8ef]329 async_answer_0(iid, ret);
[36f2b3e]330 if (ret != EOK)
[a6e54c5d]331 return;
[36f2b3e]332
[79ae36dd]333 while (true) {
[a1769ee]334 ipc_callid_t callid;
335 ipc_call_t call;
336 callid = async_get_call(&call);
[228e490]337 sysarg_t method = IPC_GET_IMETHOD(call);
[3843ecb]338
[79ae36dd]339 if (!method) {
[8b1e15ac]340 /* Close device function */
341 if (fun->ops != NULL && fun->ops->close != NULL)
342 (*fun->ops->close)(fun);
[ffa2c8ef]343 async_answer_0(callid, EOK);
[a1769ee]344 return;
[79ae36dd]345 }
346
347 /* Convert ipc interface id to interface index */
348
349 int iface_idx = DEV_IFACE_IDX(method);
350
351 if (!is_valid_iface_idx(iface_idx)) {
352 remote_handler_t *default_handler =
353 function_get_default_handler(fun);
354 if (default_handler != NULL) {
355 (*default_handler)(fun, callid, &call);
[79a141a]356 continue;
[52b7b1bb]357 }
358
[7a252ec8]359 /*
[79ae36dd]360 * Function has no such interface and
361 * default handler is not provided.
[7a252ec8]362 */
[79ae36dd]363 printf("%s: driver_connection_gen error - "
364 "invalid interface id %d.",
365 driver->name, iface_idx);
366 async_answer_0(callid, ENOTSUP);
[79a141a]367 continue;
[79ae36dd]368 }
369
370 /* Calling one of the function's interfaces */
371
372 /* Get the interface ops structure. */
373 void *ops = function_get_ops(fun, iface_idx);
374 if (ops == NULL) {
375 printf("%s: driver_connection_gen error - ", driver->name);
376 printf("Function with handle %" PRIun " has no interface "
377 "with id %d.\n", handle, iface_idx);
378 async_answer_0(callid, ENOTSUP);
[79a141a]379 continue;
[79ae36dd]380 }
381
382 /*
383 * Get the corresponding interface for remote request
384 * handling ("remote interface").
385 */
386 remote_iface_t *rem_iface = get_remote_iface(iface_idx);
387 assert(rem_iface != NULL);
388
389 /* get the method of the remote interface */
390 sysarg_t iface_method_idx = IPC_GET_ARG1(call);
391 remote_iface_func_ptr_t iface_method_ptr =
392 get_remote_method(rem_iface, iface_method_idx);
393 if (iface_method_ptr == NULL) {
394 /* The interface has not such method */
395 printf("%s: driver_connection_gen error - "
396 "invalid interface method.", driver->name);
397 async_answer_0(callid, ENOTSUP);
[79a141a]398 continue;
[a1769ee]399 }
[79ae36dd]400
401 /*
402 * Call the remote interface's method, which will
403 * receive parameters from the remote client and it will
404 * pass it to the corresponding local interface method
405 * associated with the function by its driver.
406 */
407 (*iface_method_ptr)(fun, ops, callid, &call);
[a1769ee]408 }
409}
410
[c16cf62]411static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
412{
[52b7b1bb]413 driver_connection_gen(iid, icall, true);
[c16cf62]414}
415
416static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
417{
[52b7b1bb]418 driver_connection_gen(iid, icall, false);
[c16cf62]419}
420
[7a252ec8]421/** Function for handling connections to device driver. */
[9934f7d]422static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[c16cf62]423{
424 /* Select interface */
[96b02eb9]425 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
[c16cf62]426 case DRIVER_DEVMAN:
[36f2b3e]427 /* Handle request from device manager */
[c16cf62]428 driver_connection_devman(iid, icall);
429 break;
430 case DRIVER_DRIVER:
[36f2b3e]431 /* Handle request from drivers of child devices */
[c16cf62]432 driver_connection_driver(iid, icall);
433 break;
434 case DRIVER_CLIENT:
[36f2b3e]435 /* Handle request from client applications */
[c16cf62]436 driver_connection_client(iid, icall);
437 break;
438 default:
[52b7b1bb]439 /* No such interface */
[ffa2c8ef]440 async_answer_0(iid, ENOENT);
[c16cf62]441 }
442}
443
[5fdd7c3]444/** Create new device structure.
445 *
446 * @return The device structure.
447 */
[83a2f43]448static ddf_dev_t *create_device(void)
[5fdd7c3]449{
[83a2f43]450 ddf_dev_t *dev;
[5fdd7c3]451
[83a2f43]452 dev = malloc(sizeof(ddf_dev_t));
[8b1e15ac]453 if (dev == NULL)
454 return NULL;
[5fdd7c3]455
[83a2f43]456 memset(dev, 0, sizeof(ddf_dev_t));
[5fdd7c3]457 return dev;
458}
459
[8b1e15ac]460/** Create new function structure.
461 *
462 * @return The device structure.
463 */
[83a2f43]464static ddf_fun_t *create_function(void)
[8b1e15ac]465{
[83a2f43]466 ddf_fun_t *fun;
[8b1e15ac]467
[83a2f43]468 fun = calloc(1, sizeof(ddf_fun_t));
[8b1e15ac]469 if (fun == NULL)
470 return NULL;
471
472 init_match_ids(&fun->match_ids);
473 link_initialize(&fun->link);
474
475 return fun;
476}
477
[5fdd7c3]478/** Delete device structure.
479 *
480 * @param dev The device structure.
481 */
[83a2f43]482static void delete_device(ddf_dev_t *dev)
[5fdd7c3]483{
484 free(dev);
485}
486
[8b1e15ac]487/** Delete device structure.
488 *
489 * @param dev The device structure.
490 */
[83a2f43]491static void delete_function(ddf_fun_t *fun)
[8b1e15ac]492{
493 clean_match_ids(&fun->match_ids);
494 if (fun->name != NULL)
495 free(fun->name);
496 free(fun);
497}
498
[97a62fe]499/** Create a DDF function node.
500 *
501 * Create a DDF function (in memory). Both child devices and external clients
502 * communicate with a device via its functions.
503 *
504 * The created function node is fully formed, but only exists in the memory
505 * of the client task. In order to be visible to the system, the function
506 * must be bound using ddf_fun_bind().
507 *
508 * This function should only fail if there is not enough free memory.
509 * Specifically, this function succeeds even if @a dev already has
510 * a (bound) function with the same name.
511 *
512 * Type: A function of type fun_inner indicates that DDF should attempt
513 * to attach child devices to the function. fun_exposed means that
514 * the function should be exported to external clients (applications).
515 *
516 * @param dev Device to which we are adding function
517 * @param ftype Type of function (fun_inner or fun_exposed)
518 * @param name Name of function
519 *
520 * @return New function or @c NULL if memory is not available
521 */
[83a2f43]522ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
[97a62fe]523{
[83a2f43]524 ddf_fun_t *fun;
[97a62fe]525
526 fun = create_function();
527 if (fun == NULL)
528 return NULL;
529
530 fun->bound = false;
531 fun->dev = dev;
532 fun->ftype = ftype;
533
534 fun->name = str_dup(name);
535 if (fun->name == NULL) {
536 delete_function(fun);
537 return NULL;
538 }
539
540 return fun;
541}
542
543/** Destroy DDF function node.
544 *
545 * Destroy a function previously created with ddf_fun_create(). The function
546 * must not be bound.
547 *
548 * @param fun Function to destroy
549 */
[83a2f43]550void ddf_fun_destroy(ddf_fun_t *fun)
[97a62fe]551{
552 assert(fun->bound == false);
553 delete_function(fun);
554}
555
[af6b5157]556static void *function_get_ops(ddf_fun_t *fun, dev_inferface_idx_t idx)
[5fdd7c3]557{
558 assert(is_valid_iface_idx(idx));
[8b1e15ac]559 if (fun->ops == NULL)
[5fdd7c3]560 return NULL;
[8b1e15ac]561 return fun->ops->interfaces[idx];
[5fdd7c3]562}
563
[97a62fe]564/** Bind a function node.
565 *
566 * Bind the specified function to the system. This effectively makes
567 * the function visible to the system (uploads it to the server).
568 *
569 * This function can fail for several reasons. Specifically,
570 * it will fail if the device already has a bound function of
571 * the same name.
572 *
573 * @param fun Function to bind
574 * @return EOK on success or negative error code
575 */
[83a2f43]576int ddf_fun_bind(ddf_fun_t *fun)
[7707954]577{
[8b1e15ac]578 assert(fun->name != NULL);
[36f2b3e]579
[df747b9c]580 int res;
581
[8b1e15ac]582 add_to_functions_list(fun);
583 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
[97a62fe]584 fun->dev->handle, &fun->handle);
[36f2b3e]585 if (res != EOK) {
[8b1e15ac]586 remove_from_functions_list(fun);
[df747b9c]587 return res;
[36f2b3e]588 }
589
[97a62fe]590 fun->bound = true;
[df747b9c]591 return res;
[7707954]592}
593
[34588a80]594/** Add single match ID to inner function.
[cd0684d]595 *
596 * Construct and add a single match ID to the specified function.
[34588a80]597 * Cannot be called when the function node is bound.
[cd0684d]598 *
599 * @param fun Function
600 * @param match_id_str Match string
601 * @param match_score Match score
602 * @return EOK on success, ENOMEM if out of memory.
603 */
[83a2f43]604int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
[cd0684d]605 int match_score)
606{
607 match_id_t *match_id;
608
[34588a80]609 assert(fun->bound == false);
610 assert(fun->ftype == fun_inner);
611
[cd0684d]612 match_id = create_match_id();
613 if (match_id == NULL)
614 return ENOMEM;
615
616 match_id->id = match_id_str;
617 match_id->score = 90;
618
619 add_match_id(&fun->match_ids, match_id);
620 return EOK;
621}
622
[5fdd7c3]623/** Get default handler for client requests */
[af6b5157]624static remote_handler_t *function_get_default_handler(ddf_fun_t *fun)
[5fdd7c3]625{
[8b1e15ac]626 if (fun->ops == NULL)
[5fdd7c3]627 return NULL;
[8b1e15ac]628 return fun->ops->default_handler;
[5fdd7c3]629}
630
[34588a80]631/** Add exposed function to class.
632 *
633 * Must only be called when the function is bound.
634 */
[83a2f43]635int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name)
[5fdd7c3]636{
[34588a80]637 assert(fun->bound == true);
638 assert(fun->ftype == fun_exposed);
639
[8b1e15ac]640 return devman_add_device_to_class(fun->handle, class_name);
[5fdd7c3]641}
642
[83a2f43]643int ddf_driver_main(driver_t *drv)
[c16cf62]644{
[033cbf82]645 int rc;
646
[7a252ec8]647 /*
648 * Remember the driver structure - driver_ops will be called by generic
649 * handler for incoming connections.
650 */
[c16cf62]651 driver = drv;
[36f2b3e]652
[7a252ec8]653 /* Initialize the list of interrupt contexts. */
[7f8b581]654 init_interrupt_context_list(&interrupt_contexts);
655
[7a252ec8]656 /* Set generic interrupt handler. */
[7f8b581]657 async_set_interrupt_received(driver_irq_handler);
658
[7a252ec8]659 /*
[033cbf82]660 * Register driver with device manager using generic handler for
661 * incoming connections.
[7a252ec8]662 */
[033cbf82]663 rc = devman_driver_register(driver->name, driver_connection);
664 if (rc != EOK) {
[3ad7b1c]665 printf("Error: Failed to register driver with device manager "
666 "(%s).\n", (rc == EEXISTS) ? "driver already started" :
667 str_error(rc));
668
[033cbf82]669 return 1;
670 }
[36f2b3e]671
[26fa82bc]672 /* Return success from the task since server has started. */
673 rc = task_retval(0);
674 if (rc != EOK)
675 return 1;
676
[c16cf62]677 async_manager();
[36f2b3e]678
[7a252ec8]679 /* Never reached. */
[52b7b1bb]680 return 0;
[c16cf62]681}
682
683/**
684 * @}
[52b7b1bb]685 */
Note: See TracBrowser for help on using the repository browser.