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