source: mainline/uspace/lib/device/include/ipc/devman.h

Last change on this file was 8300c72, checked in by Jiri Svoboda <jiri@…>, 4 months ago

Quiesce devices before proceeding with shutdown.

Only implemented for e1k, uhci and xhci.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * Copyright (c) 2010 Lenka Trochtova
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup devman
31 * @{
32 */
33
34#ifndef LIBDEVICE_IPC_DEVMAN_H
35#define LIBDEVICE_IPC_DEVMAN_H
36
37#include <ipc/common.h>
38#include <adt/list.h>
39#include <mem.h>
40#include <stdlib.h>
41
42#define DEVMAN_NAME_MAXLEN 256
43
44typedef sysarg_t devman_handle_t;
45
46typedef enum {
47 /** Driver has not been started. */
48 DRIVER_NOT_STARTED = 0,
49
50 /**
51 * Driver has been started, but has not registered as running and ready
52 * to receive requests.
53 */
54 DRIVER_STARTING,
55
56 /** Driver is running and prepared to serve incomming requests. */
57 DRIVER_RUNNING
58} driver_state_t;
59
60typedef enum {
61 /** Invalid value for debugging purposes */
62 fun_invalid = 0,
63 /** Function to which child devices attach */
64 fun_inner,
65 /** Fuction exported to external clients (leaf function) */
66 fun_exposed
67} fun_type_t;
68
69/** Ids of device models used for device-to-driver matching.
70 */
71typedef struct match_id {
72 /** Pointers to next and previous ids.
73 */
74 link_t link;
75 /** Id of device model.
76 */
77 char *id;
78 /** Relevancy of device-to-driver match.
79 * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
80 * the more suitable is the leaf driver for handling the device.
81 */
82 unsigned int score;
83} match_id_t;
84
85/** List of ids for matching devices to drivers sorted
86 * according to match scores in descending order.
87 */
88typedef struct match_id_list {
89 list_t ids;
90} match_id_list_t;
91
92static inline match_id_t *create_match_id(void)
93{
94 match_id_t *id = malloc(sizeof(match_id_t));
95 memset(id, 0, sizeof(match_id_t));
96 return id;
97}
98
99static inline void delete_match_id(match_id_t *id)
100{
101 if (id) {
102 if (NULL != id->id) {
103 free(id->id);
104 }
105 free(id);
106 }
107}
108
109static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
110{
111 match_id_t *mid = NULL;
112 link_t *link = ids->ids.head.next;
113
114 while (link != &ids->ids.head) {
115 mid = list_get_instance(link, match_id_t, link);
116 if (mid->score < id->score) {
117 break;
118 }
119 link = link->next;
120 }
121
122 list_insert_before(&id->link, link);
123}
124
125static inline void init_match_ids(match_id_list_t *id_list)
126{
127 list_initialize(&id_list->ids);
128}
129
130static inline void clean_match_ids(match_id_list_t *ids)
131{
132 link_t *link = NULL;
133 match_id_t *id;
134
135 while (!list_empty(&ids->ids)) {
136 link = list_first(&ids->ids);
137 list_remove(link);
138 id = list_get_instance(link, match_id_t, link);
139 delete_match_id(id);
140 }
141}
142
143typedef enum {
144 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
145 DEVMAN_ADD_FUNCTION,
146 DEVMAN_ADD_MATCH_ID,
147 DEVMAN_ADD_DEVICE_TO_CATEGORY,
148 DEVMAN_DRV_FUN_ONLINE,
149 DEVMAN_DRV_FUN_OFFLINE,
150 DEVMAN_DRV_FUN_QUIESCE,
151 DEVMAN_DRV_FUN_WAIT_STABLE,
152 DEVMAN_REMOVE_FUNCTION
153} driver_to_devman_t;
154
155typedef enum {
156 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
157 DRIVER_DEV_REMOVE,
158 DRIVER_DEV_GONE,
159 DRIVER_DEV_QUIESCE,
160 DRIVER_FUN_ONLINE,
161 DRIVER_FUN_OFFLINE,
162 DRIVER_STOP
163} devman_to_driver_t;
164
165typedef enum {
166 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
167 DEVMAN_DEV_GET_FUNCTIONS,
168 DEVMAN_DEV_GET_PARENT,
169 DEVMAN_FUN_GET_CHILD,
170 DEVMAN_FUN_GET_MATCH_ID,
171 DEVMAN_FUN_GET_NAME,
172 DEVMAN_FUN_GET_DRIVER_NAME,
173 DEVMAN_FUN_ONLINE,
174 DEVMAN_FUN_OFFLINE,
175 DEVMAN_FUN_QUIESCE,
176 DEVMAN_FUN_GET_PATH,
177 DEVMAN_FUN_SID_TO_HANDLE,
178 DEVMAN_GET_DRIVERS,
179 DEVMAN_DRIVER_GET_DEVICES,
180 DEVMAN_DRIVER_GET_HANDLE,
181 DEVMAN_DRIVER_GET_MATCH_ID,
182 DEVMAN_DRIVER_GET_NAME,
183 DEVMAN_DRIVER_GET_STATE,
184 DEVMAN_DRIVER_LOAD,
185 DEVMAN_DRIVER_UNLOAD
186} client_to_devman_t;
187
188#endif
189
190/** @}
191 */
Note: See TracBrowser for help on using the repository browser.