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

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

Add logging for device drivers.

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