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

Last change on this file was 8300c72, checked in by Jiri Svoboda <jiri@…>, 5 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
RevLine 
[e2b9a993]1/*
[832cbe7]2 * Copyright (c) 2025 Jiri Svoboda
[e2b9a993]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 */
[64d2b10]33
[edeee9f]34#ifndef LIBDEVICE_IPC_DEVMAN_H
35#define LIBDEVICE_IPC_DEVMAN_H
[e2b9a993]36
[64d2b10]37#include <ipc/common.h>
[bda60d9]38#include <adt/list.h>
[64d2b10]39#include <mem.h>
[38d150e]40#include <stdlib.h>
[e2b9a993]41
[64d2b10]42#define DEVMAN_NAME_MAXLEN 256
[729fa2d6]43
[96b02eb9]44typedef sysarg_t devman_handle_t;
[bda60d9]45
[e5556e4a]46typedef enum {
47 /** Driver has not been started. */
48 DRIVER_NOT_STARTED = 0,
[a35b458]49
[e5556e4a]50 /**
51 * Driver has been started, but has not registered as running and ready
52 * to receive requests.
53 */
54 DRIVER_STARTING,
[a35b458]55
[e5556e4a]56 /** Driver is running and prepared to serve incomming requests. */
57 DRIVER_RUNNING
58} driver_state_t;
59
[8b1e15ac]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
[bda60d9]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 */
[33b8d024]77 char *id;
[bda60d9]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 {
[b72efe8]89 list_t ids;
[bda60d9]90} match_id_list_t;
91
[64d2b10]92static inline match_id_t *create_match_id(void)
[bda60d9]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
[64d2b10]109static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
[bda60d9]110{
111 match_id_t *mid = NULL;
[b72efe8]112 link_t *link = ids->ids.head.next;
[a35b458]113
[b72efe8]114 while (link != &ids->ids.head) {
[1433ecda]115 mid = list_get_instance(link, match_id_t, link);
[bda60d9]116 if (mid->score < id->score) {
117 break;
[b72efe8]118 }
[bda60d9]119 link = link->next;
120 }
[a35b458]121
[64d2b10]122 list_insert_before(&id->link, link);
[bda60d9]123}
124
[5af21c5]125static inline void init_match_ids(match_id_list_t *id_list)
126{
127 list_initialize(&id_list->ids);
128}
129
[bda60d9]130static inline void clean_match_ids(match_id_list_t *ids)
131{
132 link_t *link = NULL;
133 match_id_t *id;
[a35b458]134
[b72efe8]135 while (!list_empty(&ids->ids)) {
136 link = list_first(&ids->ids);
137 list_remove(link);
[bda60d9]138 id = list_get_instance(link, match_id_t, link);
[b72efe8]139 delete_match_id(id);
140 }
[bda60d9]141}
142
[e2b9a993]143typedef enum {
144 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
[8b1e15ac]145 DEVMAN_ADD_FUNCTION,
[692c40cb]146 DEVMAN_ADD_MATCH_ID,
[d0dd7b5]147 DEVMAN_ADD_DEVICE_TO_CATEGORY,
[1a5b252]148 DEVMAN_DRV_FUN_ONLINE,
149 DEVMAN_DRV_FUN_OFFLINE,
[8300c72]150 DEVMAN_DRV_FUN_QUIESCE,
[832cbe7]151 DEVMAN_DRV_FUN_WAIT_STABLE,
[d0dd7b5]152 DEVMAN_REMOVE_FUNCTION
[924c75e1]153} driver_to_devman_t;
154
155typedef enum {
[1a5b252]156 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
157 DRIVER_DEV_REMOVE,
[80a96d2]158 DRIVER_DEV_GONE,
[8300c72]159 DRIVER_DEV_QUIESCE,
[1a5b252]160 DRIVER_FUN_ONLINE,
161 DRIVER_FUN_OFFLINE,
[81685dd9]162 DRIVER_STOP
[924c75e1]163} devman_to_driver_t;
[e2b9a993]164
[f658458]165typedef enum {
[fc8c2b6]166 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
[7beb220]167 DEVMAN_DEV_GET_FUNCTIONS,
[1db5669]168 DEVMAN_DEV_GET_PARENT,
[7beb220]169 DEVMAN_FUN_GET_CHILD,
[4c9b28a]170 DEVMAN_FUN_GET_MATCH_ID,
[7beb220]171 DEVMAN_FUN_GET_NAME,
[3f57fb7]172 DEVMAN_FUN_GET_DRIVER_NAME,
[1a5b252]173 DEVMAN_FUN_ONLINE,
174 DEVMAN_FUN_OFFLINE,
[8300c72]175 DEVMAN_FUN_QUIESCE,
[7beb220]176 DEVMAN_FUN_GET_PATH,
[0511549]177 DEVMAN_FUN_SID_TO_HANDLE,
178 DEVMAN_GET_DRIVERS,
[1db5669]179 DEVMAN_DRIVER_GET_DEVICES,
[7969087]180 DEVMAN_DRIVER_GET_HANDLE,
[4c9b28a]181 DEVMAN_DRIVER_GET_MATCH_ID,
[e5556e4a]182 DEVMAN_DRIVER_GET_NAME,
[7969087]183 DEVMAN_DRIVER_GET_STATE,
[81685dd9]184 DEVMAN_DRIVER_LOAD,
185 DEVMAN_DRIVER_UNLOAD
[f658458]186} client_to_devman_t;
187
[c16cf62]188#endif
[e2b9a993]189
[c16cf62]190/** @}
[47a7174f]191 */
Note: See TracBrowser for help on using the repository browser.