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

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

Merge mainline changes

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[c16cf62]1/*
[a1769ee]2 * Copyright (c) 2010 Lenka Trochtova
[c16cf62]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 */
[7a252ec8]34
[c16cf62]35#ifndef LIBDRV_DRIVER_H_
36#define LIBDRV_DRIVER_H_
37
[084ff99]38#include <adt/list.h>
[7f8b581]39#include <ipc/ipc.h>
[692c40cb]40#include <devman.h>
[bda60d9]41#include <ipc/devman.h>
[a1769ee]42#include <ipc/dev_iface.h>
[52b7b1bb]43#include <assert.h>
[cfe7716]44#include <ddi.h>
45#include <libarch/ddi.h>
46#include <fibril_synch.h>
47#include <malloc.h>
[084ff99]48
[22027b6e]49#include "dev_iface.h"
50
[a1769ee]51struct device;
52typedef struct device device_t;
53
[7a252ec8]54/*
[97adec8]55 * Device class
[7a252ec8]56 */
[a1769ee]57
[97adec8]58/** Devices operations */
[5159ae9]59typedef struct device_ops {
[7a252ec8]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
[08d9525a]72 /** The table of standard interfaces implemented by the device. */
[7a252ec8]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 */
[08d9525a]80 remote_handler_t *default_handler;
[5159ae9]81} device_ops_t;
[3843ecb]82
83
[97adec8]84/*
85 * Device
86 */
[a1769ee]87
[97adec8]88/** Device structure */
[a1769ee]89struct device {
[7a252ec8]90 /**
91 * Globally unique device identifier (assigned to the device by the
92 * device manager).
93 */
[0b5a4131]94 devman_handle_t handle;
[7a252ec8]95
96 /**
[97adec8]97 * Phone to the parent device driver (if it is different from this
98 * driver)
[7a252ec8]99 */
[9a66bc2e]100 int parent_phone;
[7a252ec8]101
[97adec8]102 /** Parent device if handled by this driver, NULL otherwise */
[5e598e0]103 device_t *parent;
[97adec8]104 /** Device name */
[bda60d9]105 const char *name;
[97adec8]106 /** List of device ids for device-to-driver matching */
[bda60d9]107 match_id_list_t match_ids;
[97adec8]108 /** Driver-specific data associated with this device */
[eff1a590]109 void *driver_data;
[97adec8]110 /** The implementation of operations provided by this device */
[5159ae9]111 device_ops_t *ops;
[7a252ec8]112
[97adec8]113 /** Link in the list of devices handled by the driver */
[084ff99]114 link_t link;
[a1769ee]115};
[c16cf62]116
[97adec8]117/*
118 * Driver
119 */
[a1769ee]120
[97adec8]121/** Generic device driver operations */
[a1769ee]122typedef struct driver_ops {
[97adec8]123 /** Callback method for passing a new device to the device driver */
[df747b9c]124 int (*add_device)(device_t *dev);
[97adec8]125 /* TODO: add other generic driver operations */
[c16cf62]126} driver_ops_t;
127
[97adec8]128/** Driver structure */
[c16cf62]129typedef struct driver {
[97adec8]130 /** Name of the device driver */
[c16cf62]131 const char *name;
[97adec8]132 /** Generic device driver operations */
[c16cf62]133 driver_ops_t *driver_ops;
134} driver_t;
135
[7a252ec8]136int driver_main(driver_t *);
[c16cf62]137
[7a252ec8]138/** Create new device structure.
139 *
140 * @return The device structure.
[52b7b1bb]141 */
[5fdd7c3]142extern device_t *create_device(void);
143extern void delete_device(device_t *);
144extern void *device_get_ops(device_t *, dev_inferface_idx_t);
[7a252ec8]145
[5fdd7c3]146extern int child_device_register(device_t *, device_t *);
147extern int child_device_register_wrapper(device_t *, const char *, const char *,
[6610565b]148 int, devman_handle_t *);
[7707954]149
[97adec8]150/*
151 * Interrupts
152 */
[cfe7716]153
[7a252ec8]154typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
[cfe7716]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
[5fdd7c3]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 *,
[7a252ec8]183 irq_code_t *);
[5fdd7c3]184extern int unregister_interrupt_handler(device_t *, int);
[08d9525a]185
[5fdd7c3]186extern remote_handler_t *device_get_default_handler(device_t *);
187extern int add_device_to_class(device_t *, const char *);
[692c40cb]188
[c16cf62]189#endif
190
191/**
192 * @}
[a1769ee]193 */
Note: See TracBrowser for help on using the repository browser.