source: mainline/uspace/lib/drv/include/driver.h@ 5fdd7c3

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

Say no to static functions.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdrv
30 * @{
31 */
32/** @file
33 */
34
35#ifndef LIBDRV_DRIVER_H_
36#define LIBDRV_DRIVER_H_
37
38#include <adt/list.h>
39#include <ipc/ipc.h>
40#include <devman.h>
41#include <ipc/devman.h>
42#include <ipc/dev_iface.h>
43#include <assert.h>
44#include <ddi.h>
45#include <libarch/ddi.h>
46#include <fibril_synch.h>
47#include <malloc.h>
48
49struct device;
50typedef struct device device_t;
51
52/*
53 * Device interface
54 */
55
56/*
57 * First two parameters: device and interface structure registered by the
58 * devices driver.
59 */
60typedef void remote_iface_func_t(device_t *, void *, ipc_callid_t,
61 ipc_call_t *);
62typedef remote_iface_func_t *remote_iface_func_ptr_t;
63typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
64
65typedef struct {
66 size_t method_count;
67 remote_iface_func_ptr_t *methods;
68} remote_iface_t;
69
70typedef struct {
71 remote_iface_t *ifaces[DEV_IFACE_COUNT];
72} iface_dipatch_table_t;
73
74extern remote_iface_t *get_remote_iface(int);
75extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
76
77/*
78 * Device class
79 */
80
81/** Devices operations */
82typedef struct device_ops {
83 /**
84 * Optional callback function called when a client is connecting to the
85 * device.
86 */
87 int (*open)(device_t *);
88
89 /**
90 * Optional callback function called when a client is disconnecting from
91 * the device.
92 */
93 void (*close)(device_t *);
94
95 /** The table of standard interfaces implemented by the device. */
96 void *interfaces[DEV_IFACE_COUNT];
97
98 /**
99 * The default handler of remote client requests. If the client's remote
100 * request cannot be handled by any of the standard interfaces, the
101 * default handler is used.
102 */
103 remote_handler_t *default_handler;
104} device_ops_t;
105
106
107/*
108 * Device
109 */
110
111/** Device structure */
112struct device {
113 /**
114 * Globally unique device identifier (assigned to the device by the
115 * device manager).
116 */
117 devman_handle_t handle;
118
119 /**
120 * Phone to the parent device driver (if it is different from this
121 * driver)
122 */
123 int parent_phone;
124
125 /** Parent device if handled by this driver, NULL otherwise */
126 device_t *parent;
127 /** Device name */
128 const char *name;
129 /** List of device ids for device-to-driver matching */
130 match_id_list_t match_ids;
131 /** Driver-specific data associated with this device */
132 void *driver_data;
133 /** The implementation of operations provided by this device */
134 device_ops_t *ops;
135
136 /** Link in the list of devices handled by the driver */
137 link_t link;
138};
139
140
141/*
142 * Driver
143 */
144
145/** Generic device driver operations */
146typedef struct driver_ops {
147 /** Callback method for passing a new device to the device driver */
148 int (*add_device)(device_t *dev);
149 /* TODO: add other generic driver operations */
150} driver_ops_t;
151
152/** Driver structure */
153typedef struct driver {
154 /** Name of the device driver */
155 const char *name;
156 /** Generic device driver operations */
157 driver_ops_t *driver_ops;
158} driver_t;
159
160int driver_main(driver_t *);
161
162/** Create new device structure.
163 *
164 * @return The device structure.
165 */
166extern device_t *create_device(void);
167extern void delete_device(device_t *);
168extern void *device_get_ops(device_t *, dev_inferface_idx_t);
169
170extern int child_device_register(device_t *, device_t *);
171extern int child_device_register_wrapper(device_t *, const char *, const char *,
172 int);
173
174/*
175 * Interrupts
176 */
177
178typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
179
180typedef struct interrupt_context {
181 int id;
182 device_t *dev;
183 int irq;
184 interrupt_handler_t *handler;
185 link_t link;
186} interrupt_context_t;
187
188typedef struct interrupt_context_list {
189 int curr_id;
190 link_t contexts;
191 fibril_mutex_t mutex;
192} interrupt_context_list_t;
193
194extern interrupt_context_t *create_interrupt_context(void);
195extern void delete_interrupt_context(interrupt_context_t *);
196extern void init_interrupt_context_list(interrupt_context_list_t *);
197extern void add_interrupt_context(interrupt_context_list_t *,
198 interrupt_context_t *);
199extern void remove_interrupt_context(interrupt_context_list_t *,
200 interrupt_context_t *);
201extern interrupt_context_t *find_interrupt_context_by_id(
202 interrupt_context_list_t *, int);
203extern interrupt_context_t *find_interrupt_context(
204 interrupt_context_list_t *, device_t *, int);
205
206extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
207 irq_code_t *);
208extern int unregister_interrupt_handler(device_t *, int);
209
210extern remote_handler_t *device_get_default_handler(device_t *);
211extern int add_device_to_class(device_t *, const char *);
212
213#endif
214
215/**
216 * @}
217 */
Note: See TracBrowser for help on using the repository browser.