source: mainline/uspace/lib/drv/include/driver.h@ 6610565b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6610565b was 6610565b, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Merge mainline changes

  • Property mode set to 100644
File size: 5.2 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
49#include "dev_iface.h"
50
51struct device;
52typedef struct device device_t;
53
54/*
55 * Device class
56 */
57
58/** Devices operations */
59typedef struct device_ops {
60 /**
61 * Optional callback function called when a client is connecting to the
62 * device.
63 */
64 int (*open)(device_t *);
65
66 /**
67 * Optional callback function called when a client is disconnecting from
68 * the device.
69 */
70 void (*close)(device_t *);
71
72 /** The table of standard interfaces implemented by the device. */
73 void *interfaces[DEV_IFACE_COUNT];
74
75 /**
76 * The default handler of remote client requests. If the client's remote
77 * request cannot be handled by any of the standard interfaces, the
78 * default handler is used.
79 */
80 remote_handler_t *default_handler;
81} device_ops_t;
82
83
84/*
85 * Device
86 */
87
88/** Device structure */
89struct device {
90 /**
91 * Globally unique device identifier (assigned to the device by the
92 * device manager).
93 */
94 devman_handle_t handle;
95
96 /**
97 * Phone to the parent device driver (if it is different from this
98 * driver)
99 */
100 int parent_phone;
101
102 /** Parent device if handled by this driver, NULL otherwise */
103 device_t *parent;
104 /** Device name */
105 const char *name;
106 /** List of device ids for device-to-driver matching */
107 match_id_list_t match_ids;
108 /** Driver-specific data associated with this device */
109 void *driver_data;
110 /** The implementation of operations provided by this device */
111 device_ops_t *ops;
112
113 /** Link in the list of devices handled by the driver */
114 link_t link;
115};
116
117/*
118 * Driver
119 */
120
121/** Generic device driver operations */
122typedef struct driver_ops {
123 /** Callback method for passing a new device to the device driver */
124 int (*add_device)(device_t *dev);
125 /* TODO: add other generic driver operations */
126} driver_ops_t;
127
128/** Driver structure */
129typedef struct driver {
130 /** Name of the device driver */
131 const char *name;
132 /** Generic device driver operations */
133 driver_ops_t *driver_ops;
134} driver_t;
135
136int driver_main(driver_t *);
137
138/** Create new device structure.
139 *
140 * @return The device structure.
141 */
142extern device_t *create_device(void);
143extern void delete_device(device_t *);
144extern void *device_get_ops(device_t *, dev_inferface_idx_t);
145
146extern int child_device_register(device_t *, device_t *);
147extern int child_device_register_wrapper(device_t *, const char *, const char *,
148 int, devman_handle_t *);
149
150/*
151 * Interrupts
152 */
153
154typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
155
156typedef struct interrupt_context {
157 int id;
158 device_t *dev;
159 int irq;
160 interrupt_handler_t *handler;
161 link_t link;
162} interrupt_context_t;
163
164typedef struct interrupt_context_list {
165 int curr_id;
166 link_t contexts;
167 fibril_mutex_t mutex;
168} interrupt_context_list_t;
169
170extern interrupt_context_t *create_interrupt_context(void);
171extern void delete_interrupt_context(interrupt_context_t *);
172extern void init_interrupt_context_list(interrupt_context_list_t *);
173extern void add_interrupt_context(interrupt_context_list_t *,
174 interrupt_context_t *);
175extern void remove_interrupt_context(interrupt_context_list_t *,
176 interrupt_context_t *);
177extern interrupt_context_t *find_interrupt_context_by_id(
178 interrupt_context_list_t *, int);
179extern interrupt_context_t *find_interrupt_context(
180 interrupt_context_list_t *, device_t *, int);
181
182extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
183 irq_code_t *);
184extern int unregister_interrupt_handler(device_t *, int);
185
186extern remote_handler_t *device_get_default_handler(device_t *);
187extern int add_device_to_class(device_t *, const char *);
188
189#endif
190
191/**
192 * @}
193 */
Note: See TracBrowser for help on using the repository browser.