source: mainline/uspace/lib/drv/include/driver.h@ 17aca1c

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

Merge mainline changes

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