source: mainline/uspace/lib/drv/include/ddf/driver.h@ b4b534ac

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b4b534ac was b4b534ac, checked in by Jakub Jermar <jakub@…>, 9 years ago

Merge from lp:~jan.vesely/helenos/usb

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * Copyright (c) 2011 Jiri Svoboda
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/** @addtogroup libdrv
31 * @{
32 */
33/** @file
34 */
35
36#ifndef DDF_DRIVER_H_
37#define DDF_DRIVER_H_
38
39#include <async.h>
40#include <ipc/devman.h>
41#include <ipc/dev_iface.h>
42#include "../dev_iface.h"
43
44
45/*
46 * Device
47 */
48
49typedef struct ddf_dev ddf_dev_t;
50typedef struct ddf_fun ddf_fun_t;
51
52/** Devices operations */
53typedef struct ddf_dev_ops {
54 /**
55 * Optional callback function called when a client is connecting to the
56 * device.
57 */
58 int (*open)(ddf_fun_t *);
59
60 /**
61 * Optional callback function called when a client is disconnecting from
62 * the device.
63 */
64 void (*close)(ddf_fun_t *);
65
66 /** The table of standard interfaces implemented by the device. */
67 void *interfaces[DEV_IFACE_COUNT];
68
69 /**
70 * The default handler of remote client requests. If the client's remote
71 * request cannot be handled by any of the standard interfaces, the
72 * default handler is used.
73 */
74 remote_handler_t *default_handler;
75} ddf_dev_ops_t;
76
77/** Device structure */
78struct ddf_dev;
79
80/** Function structure */
81struct ddf_fun;
82
83/*
84 * Driver
85 */
86
87/** Generic device driver operations */
88typedef struct driver_ops {
89 /** Callback method for passing a new device to the device driver */
90 int (*dev_add)(ddf_dev_t *);
91
92 /** Ask driver to remove a device */
93 int (*dev_remove)(ddf_dev_t *);
94
95 /** Inform driver a device disappeared */
96 int (*dev_gone)(ddf_dev_t *);
97
98 /** Ask driver to online a specific function */
99 int (*fun_online)(ddf_fun_t *);
100
101 /** Ask driver to offline a specific function */
102 int (*fun_offline)(ddf_fun_t *);
103} driver_ops_t;
104
105/** Driver structure */
106typedef struct driver {
107 /** Name of the device driver */
108 const char *name;
109 /** Generic device driver operations */
110 const driver_ops_t *driver_ops;
111} driver_t;
112
113extern int ddf_driver_main(const driver_t *);
114
115extern void *ddf_dev_data_alloc(ddf_dev_t *, size_t);
116extern void *ddf_dev_data_get(ddf_dev_t *);
117extern devman_handle_t ddf_dev_get_handle(ddf_dev_t *);
118extern const char *ddf_dev_get_name(ddf_dev_t *);
119extern async_sess_t *ddf_dev_parent_sess_create(ddf_dev_t *);
120extern async_sess_t *ddf_dev_parent_sess_get(ddf_dev_t *);
121extern ddf_fun_t *ddf_fun_create(ddf_dev_t *, fun_type_t, const char *);
122extern devman_handle_t ddf_fun_get_handle(ddf_fun_t *);
123extern void ddf_fun_destroy(ddf_fun_t *);
124extern void *ddf_fun_data_alloc(ddf_fun_t *, size_t);
125extern void *ddf_fun_data_get(ddf_fun_t *);
126extern const char *ddf_fun_get_name(ddf_fun_t *);
127extern int ddf_fun_set_name(ddf_fun_t *, const char *);
128extern ddf_dev_t *ddf_fun_get_dev(ddf_fun_t *);
129extern int ddf_fun_bind(ddf_fun_t *);
130extern int ddf_fun_unbind(ddf_fun_t *);
131extern int ddf_fun_online(ddf_fun_t *);
132extern int ddf_fun_offline(ddf_fun_t *);
133extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int);
134extern void ddf_fun_set_ops(ddf_fun_t *, const ddf_dev_ops_t *);
135extern void ddf_fun_set_conn_handler(ddf_fun_t *, async_port_handler_t);
136extern int ddf_fun_add_to_category(ddf_fun_t *, const char *);
137
138#endif
139
140/**
141 * @}
142 */
Note: See TracBrowser for help on using the repository browser.