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

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

Nits.

  • Property mode set to 100644
File size: 16.6 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);
[36f2b3e]275 if (res == EOK) {
[7e752b2]276 printf("%s: new device with handle=%" PRIun " was added.\n",
[7a252ec8]277 driver->name, dev_handle);
[9a66bc2e]278 } else {
[7e752b2]279 printf("%s: failed to add a new device with handle = %" PRIun ".\n",
[7a252ec8]280 driver->name, dev_handle);
281 delete_device(dev);
[084ff99]282 }
[df747b9c]283
[ffa2c8ef]284 async_answer_0(iid, res);
[084ff99]285}
[c16cf62]286
287static void driver_connection_devman(ipc_callid_t iid, ipc_call_t *icall)
288{
289 /* Accept connection */
[ffa2c8ef]290 async_answer_0(iid, EOK);
[36f2b3e]291
[c16cf62]292 bool cont = true;
293 while (cont) {
294 ipc_call_t call;
295 ipc_callid_t callid = async_get_call(&call);
[36f2b3e]296
[228e490]297 switch (IPC_GET_IMETHOD(call)) {
[c16cf62]298 case IPC_M_PHONE_HUNGUP:
299 cont = false;
300 continue;
301 case DRIVER_ADD_DEVICE:
[084ff99]302 driver_add_device(callid, &call);
[c16cf62]303 break;
304 default:
[ffa2c8ef]305 async_answer_0(callid, ENOENT);
[c16cf62]306 }
[52b7b1bb]307 }
[c16cf62]308}
309
[52b7b1bb]310/**
[a1769ee]311 * Generic client connection handler both for applications and drivers.
[52b7b1bb]312 *
[7a252ec8]313 * @param drv True for driver client, false for other clients
314 * (applications, services etc.).
[a1769ee]315 */
[9a66bc2e]316static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
[52b7b1bb]317{
[7a252ec8]318 /*
319 * Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of
320 * the device to which the client connected.
321 */
[0b5a4131]322 devman_handle_t handle = IPC_GET_ARG2(*icall);
[83a2f43]323 ddf_fun_t *fun = driver_get_function(&functions, handle);
[52b7b1bb]324
[8b1e15ac]325 if (fun == NULL) {
326 printf("%s: driver_connection_gen error - no function with handle"
[7e752b2]327 " %" PRIun " was found.\n", driver->name, handle);
[ffa2c8ef]328 async_answer_0(iid, ENOENT);
[a1769ee]329 return;
330 }
[5cd136ab]331
332
[7a252ec8]333 /*
334 * TODO - if the client is not a driver, check whether it is allowed to
335 * use the device.
336 */
[36f2b3e]337
[25a7e11d]338 int ret = EOK;
[8b1e15ac]339 /* Open device function */
340 if (fun->ops != NULL && fun->ops->open != NULL)
341 ret = (*fun->ops->open)(fun);
[a1769ee]342
[ffa2c8ef]343 async_answer_0(iid, ret);
[36f2b3e]344 if (ret != EOK)
[a6e54c5d]345 return;
[36f2b3e]346
[a1769ee]347 while (1) {
348 ipc_callid_t callid;
349 ipc_call_t call;
350 callid = async_get_call(&call);
[228e490]351 sysarg_t method = IPC_GET_IMETHOD(call);
[3843ecb]352 int iface_idx;
353
[a1769ee]354 switch (method) {
[d35ac1d]355 case IPC_M_PHONE_HUNGUP:
[8b1e15ac]356 /* Close device function */
357 if (fun->ops != NULL && fun->ops->close != NULL)
358 (*fun->ops->close)(fun);
[ffa2c8ef]359 async_answer_0(callid, EOK);
[a1769ee]360 return;
[d35ac1d]361 default:
[7a252ec8]362 /* convert ipc interface id to interface index */
[3843ecb]363
364 iface_idx = DEV_IFACE_IDX(method);
365
366 if (!is_valid_iface_idx(iface_idx)) {
[7a252ec8]367 remote_handler_t *default_handler =
[8b1e15ac]368 function_get_default_handler(fun);
[36f2b3e]369 if (default_handler != NULL) {
[8b1e15ac]370 (*default_handler)(fun, callid, &call);
[08d9525a]371 break;
372 }
[8b1e15ac]373
[7a252ec8]374 /*
[8b1e15ac]375 * Function has no such interface and
[7a252ec8]376 * default handler is not provided.
377 */
378 printf("%s: driver_connection_gen error - "
379 "invalid interface id %d.",
380 driver->name, iface_idx);
[ffa2c8ef]381 async_answer_0(callid, ENOTSUP);
[52b7b1bb]382 break;
383 }
[36f2b3e]384
[8b1e15ac]385 /* calling one of the function's interfaces */
[52b7b1bb]386
[d35ac1d]387 /* Get the interface ops structure. */
[8b1e15ac]388 void *ops = function_get_ops(fun, iface_idx);
[d35ac1d]389 if (ops == NULL) {
[7a252ec8]390 printf("%s: driver_connection_gen error - ",
391 driver->name);
[8b1e15ac]392 printf("Function with handle %" PRIun " has no interface "
[7a252ec8]393 "with id %d.\n", handle, iface_idx);
[ffa2c8ef]394 async_answer_0(callid, ENOTSUP);
[52b7b1bb]395 break;
[a1769ee]396 }
[36f2b3e]397
[7a252ec8]398 /*
399 * Get the corresponding interface for remote request
400 * handling ("remote interface").
401 */
[d35ac1d]402 remote_iface_t *rem_iface = get_remote_iface(iface_idx);
[36f2b3e]403 assert(rem_iface != NULL);
404
[7a252ec8]405 /* get the method of the remote interface */
[96b02eb9]406 sysarg_t iface_method_idx = IPC_GET_ARG1(call);
[7a252ec8]407 remote_iface_func_ptr_t iface_method_ptr =
408 get_remote_method(rem_iface, iface_method_idx);
[36f2b3e]409 if (iface_method_ptr == NULL) {
[52b7b1bb]410 // the interface has not such method
[7a252ec8]411 printf("%s: driver_connection_gen error - "
412 "invalid interface method.", driver->name);
[ffa2c8ef]413 async_answer_0(callid, ENOTSUP);
[52b7b1bb]414 break;
415 }
416
[7a252ec8]417 /*
418 * Call the remote interface's method, which will
419 * receive parameters from the remote client and it will
420 * pass it to the corresponding local interface method
[8b1e15ac]421 * associated with the function by its driver.
[7a252ec8]422 */
[8b1e15ac]423 (*iface_method_ptr)(fun, ops, callid, &call);
[a1769ee]424 break;
425 }
426 }
427}
428
[c16cf62]429static void driver_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
430{
[52b7b1bb]431 driver_connection_gen(iid, icall, true);
[c16cf62]432}
433
434static void driver_connection_client(ipc_callid_t iid, ipc_call_t *icall)
435{
[52b7b1bb]436 driver_connection_gen(iid, icall, false);
[c16cf62]437}
438
[7a252ec8]439/** Function for handling connections to device driver. */
[c16cf62]440static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
441{
442 /* Select interface */
[96b02eb9]443 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
[c16cf62]444 case DRIVER_DEVMAN:
[36f2b3e]445 /* Handle request from device manager */
[c16cf62]446 driver_connection_devman(iid, icall);
447 break;
448 case DRIVER_DRIVER:
[36f2b3e]449 /* Handle request from drivers of child devices */
[c16cf62]450 driver_connection_driver(iid, icall);
451 break;
452 case DRIVER_CLIENT:
[36f2b3e]453 /* Handle request from client applications */
[c16cf62]454 driver_connection_client(iid, icall);
455 break;
456 default:
[52b7b1bb]457 /* No such interface */
[ffa2c8ef]458 async_answer_0(iid, ENOENT);
[c16cf62]459 }
460}
461
[5fdd7c3]462/** Create new device structure.
463 *
464 * @return The device structure.
465 */
[83a2f43]466static ddf_dev_t *create_device(void)
[5fdd7c3]467{
[83a2f43]468 ddf_dev_t *dev;
[5fdd7c3]469
[83a2f43]470 dev = malloc(sizeof(ddf_dev_t));
[8b1e15ac]471 if (dev == NULL)
472 return NULL;
[5fdd7c3]473
[83a2f43]474 memset(dev, 0, sizeof(ddf_dev_t));
[5fdd7c3]475 return dev;
476}
477
[8b1e15ac]478/** Create new function structure.
479 *
480 * @return The device structure.
481 */
[83a2f43]482static ddf_fun_t *create_function(void)
[8b1e15ac]483{
[83a2f43]484 ddf_fun_t *fun;
[8b1e15ac]485
[83a2f43]486 fun = calloc(1, sizeof(ddf_fun_t));
[8b1e15ac]487 if (fun == NULL)
488 return NULL;
489
490 init_match_ids(&fun->match_ids);
491 link_initialize(&fun->link);
492
493 return fun;
494}
495
[5fdd7c3]496/** Delete device structure.
497 *
498 * @param dev The device structure.
499 */
[83a2f43]500static void delete_device(ddf_dev_t *dev)
[5fdd7c3]501{
502 free(dev);
503}
504
[8b1e15ac]505/** Delete device structure.
506 *
507 * @param dev The device structure.
508 */
[83a2f43]509static void delete_function(ddf_fun_t *fun)
[8b1e15ac]510{
511 clean_match_ids(&fun->match_ids);
512 if (fun->name != NULL)
513 free(fun->name);
514 free(fun);
515}
516
[97a62fe]517/** Create a DDF function node.
518 *
519 * Create a DDF function (in memory). Both child devices and external clients
520 * communicate with a device via its functions.
521 *
522 * The created function node is fully formed, but only exists in the memory
523 * of the client task. In order to be visible to the system, the function
524 * must be bound using ddf_fun_bind().
525 *
526 * This function should only fail if there is not enough free memory.
527 * Specifically, this function succeeds even if @a dev already has
528 * a (bound) function with the same name.
529 *
530 * Type: A function of type fun_inner indicates that DDF should attempt
531 * to attach child devices to the function. fun_exposed means that
532 * the function should be exported to external clients (applications).
533 *
534 * @param dev Device to which we are adding function
535 * @param ftype Type of function (fun_inner or fun_exposed)
536 * @param name Name of function
537 *
538 * @return New function or @c NULL if memory is not available
539 */
[83a2f43]540ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
[97a62fe]541{
[83a2f43]542 ddf_fun_t *fun;
[97a62fe]543
544 fun = create_function();
545 if (fun == NULL)
546 return NULL;
547
548 fun->bound = false;
549 fun->dev = dev;
550 fun->ftype = ftype;
551
552 fun->name = str_dup(name);
553 if (fun->name == NULL) {
554 delete_function(fun);
555 return NULL;
556 }
557
558 return fun;
559}
560
561/** Destroy DDF function node.
562 *
563 * Destroy a function previously created with ddf_fun_create(). The function
564 * must not be bound.
565 *
566 * @param fun Function to destroy
567 */
[83a2f43]568void ddf_fun_destroy(ddf_fun_t *fun)
[97a62fe]569{
570 assert(fun->bound == false);
571 delete_function(fun);
572}
573
[af6b5157]574static void *function_get_ops(ddf_fun_t *fun, dev_inferface_idx_t idx)
[5fdd7c3]575{
576 assert(is_valid_iface_idx(idx));
[8b1e15ac]577 if (fun->ops == NULL)
[5fdd7c3]578 return NULL;
[8b1e15ac]579 return fun->ops->interfaces[idx];
[5fdd7c3]580}
581
[97a62fe]582/** Bind a function node.
583 *
584 * Bind the specified function to the system. This effectively makes
585 * the function visible to the system (uploads it to the server).
586 *
587 * This function can fail for several reasons. Specifically,
588 * it will fail if the device already has a bound function of
589 * the same name.
590 *
591 * @param fun Function to bind
592 * @return EOK on success or negative error code
593 */
[83a2f43]594int ddf_fun_bind(ddf_fun_t *fun)
[7707954]595{
[8b1e15ac]596 assert(fun->name != NULL);
[36f2b3e]597
[df747b9c]598 int res;
599
[8b1e15ac]600 add_to_functions_list(fun);
601 res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
[97a62fe]602 fun->dev->handle, &fun->handle);
[36f2b3e]603 if (res != EOK) {
[8b1e15ac]604 remove_from_functions_list(fun);
[df747b9c]605 return res;
[36f2b3e]606 }
607
[97a62fe]608 fun->bound = true;
[df747b9c]609 return res;
[7707954]610}
611
[34588a80]612/** Add single match ID to inner function.
[cd0684d]613 *
614 * Construct and add a single match ID to the specified function.
[34588a80]615 * Cannot be called when the function node is bound.
[cd0684d]616 *
617 * @param fun Function
618 * @param match_id_str Match string
619 * @param match_score Match score
620 * @return EOK on success, ENOMEM if out of memory.
621 */
[83a2f43]622int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
[cd0684d]623 int match_score)
624{
625 match_id_t *match_id;
626
[34588a80]627 assert(fun->bound == false);
628 assert(fun->ftype == fun_inner);
629
[cd0684d]630 match_id = create_match_id();
631 if (match_id == NULL)
632 return ENOMEM;
633
634 match_id->id = match_id_str;
635 match_id->score = 90;
636
637 add_match_id(&fun->match_ids, match_id);
638 return EOK;
639}
640
[5fdd7c3]641/** Get default handler for client requests */
[af6b5157]642static remote_handler_t *function_get_default_handler(ddf_fun_t *fun)
[5fdd7c3]643{
[8b1e15ac]644 if (fun->ops == NULL)
[5fdd7c3]645 return NULL;
[8b1e15ac]646 return fun->ops->default_handler;
[5fdd7c3]647}
648
[34588a80]649/** Add exposed function to class.
650 *
651 * Must only be called when the function is bound.
652 */
[83a2f43]653int ddf_fun_add_to_class(ddf_fun_t *fun, const char *class_name)
[5fdd7c3]654{
[34588a80]655 assert(fun->bound == true);
656 assert(fun->ftype == fun_exposed);
657
[8b1e15ac]658 return devman_add_device_to_class(fun->handle, class_name);
[5fdd7c3]659}
660
[83a2f43]661int ddf_driver_main(driver_t *drv)
[c16cf62]662{
[7a252ec8]663 /*
664 * Remember the driver structure - driver_ops will be called by generic
665 * handler for incoming connections.
666 */
[c16cf62]667 driver = drv;
[36f2b3e]668
[7a252ec8]669 /* Initialize the list of interrupt contexts. */
[7f8b581]670 init_interrupt_context_list(&interrupt_contexts);
671
[7a252ec8]672 /* Set generic interrupt handler. */
[7f8b581]673 async_set_interrupt_received(driver_irq_handler);
674
[7a252ec8]675 /*
676 * Register driver by device manager with generic handler for incoming
677 * connections.
678 */
[52b7b1bb]679 devman_driver_register(driver->name, driver_connection);
[36f2b3e]680
[c16cf62]681 async_manager();
[36f2b3e]682
[7a252ec8]683 /* Never reached. */
[52b7b1bb]684 return 0;
[c16cf62]685}
686
687/**
688 * @}
[52b7b1bb]689 */
Note: See TracBrowser for help on using the repository browser.