source: mainline/uspace/lib/c/include/ipc/devman.h@ 3061bc1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3061bc1 was 33b8d024, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Remove const qualifier from the argument of free() and realloc(),
as well as in numerous other variables that hold ownership of memory.

By convention, a pointer that holds ownership is _never_ qualified by const.
This is reflected in the standard type signature of free() and realloc().
Allowing const pointers to hold ownership may seem superficially convenient,
but is actually quite confusing to experienced C programmers.

  • Property mode set to 100644
File size: 4.7 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 devman
30 * @{
31 */
32
33#ifndef LIBC_IPC_DEVMAN_H_
34#define LIBC_IPC_DEVMAN_H_
35
36#include <ipc/common.h>
37#include <adt/list.h>
38#include <mem.h>
39#include <stdlib.h>
40
41#define DEVMAN_NAME_MAXLEN 256
42
43typedef sysarg_t devman_handle_t;
44
45typedef enum {
46 /** Driver has not been started. */
47 DRIVER_NOT_STARTED = 0,
48
49 /**
50 * Driver has been started, but has not registered as running and ready
51 * to receive requests.
52 */
53 DRIVER_STARTING,
54
55 /** Driver is running and prepared to serve incomming requests. */
56 DRIVER_RUNNING
57} driver_state_t;
58
59typedef enum {
60 /** Invalid value for debugging purposes */
61 fun_invalid = 0,
62 /** Function to which child devices attach */
63 fun_inner,
64 /** Fuction exported to external clients (leaf function) */
65 fun_exposed
66} fun_type_t;
67
68/** Ids of device models used for device-to-driver matching.
69 */
70typedef struct match_id {
71 /** Pointers to next and previous ids.
72 */
73 link_t link;
74 /** Id of device model.
75 */
76 char *id;
77 /** Relevancy of device-to-driver match.
78 * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
79 * the more suitable is the leaf driver for handling the device.
80 */
81 unsigned int score;
82} match_id_t;
83
84/** List of ids for matching devices to drivers sorted
85 * according to match scores in descending order.
86 */
87typedef struct match_id_list {
88 list_t ids;
89} match_id_list_t;
90
91static inline match_id_t *create_match_id(void)
92{
93 match_id_t *id = malloc(sizeof(match_id_t));
94 memset(id, 0, sizeof(match_id_t));
95 return id;
96}
97
98static inline void delete_match_id(match_id_t *id)
99{
100 if (id) {
101 if (NULL != id->id) {
102 free(id->id);
103 }
104 free(id);
105 }
106}
107
108static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
109{
110 match_id_t *mid = NULL;
111 link_t *link = ids->ids.head.next;
112
113 while (link != &ids->ids.head) {
114 mid = list_get_instance(link, match_id_t,link);
115 if (mid->score < id->score) {
116 break;
117 }
118 link = link->next;
119 }
120
121 list_insert_before(&id->link, link);
122}
123
124static inline void init_match_ids(match_id_list_t *id_list)
125{
126 list_initialize(&id_list->ids);
127}
128
129static inline void clean_match_ids(match_id_list_t *ids)
130{
131 link_t *link = NULL;
132 match_id_t *id;
133
134 while (!list_empty(&ids->ids)) {
135 link = list_first(&ids->ids);
136 list_remove(link);
137 id = list_get_instance(link, match_id_t, link);
138 delete_match_id(id);
139 }
140}
141
142typedef enum {
143 DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
144 DEVMAN_ADD_FUNCTION,
145 DEVMAN_ADD_MATCH_ID,
146 DEVMAN_ADD_DEVICE_TO_CATEGORY,
147 DEVMAN_DRV_FUN_ONLINE,
148 DEVMAN_DRV_FUN_OFFLINE,
149 DEVMAN_REMOVE_FUNCTION
150} driver_to_devman_t;
151
152typedef enum {
153 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
154 DRIVER_DEV_REMOVE,
155 DRIVER_DEV_GONE,
156 DRIVER_FUN_ONLINE,
157 DRIVER_FUN_OFFLINE,
158 DRIVER_STOP
159} devman_to_driver_t;
160
161typedef enum {
162 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
163 DEVMAN_DEV_GET_FUNCTIONS,
164 DEVMAN_DEV_GET_PARENT,
165 DEVMAN_FUN_GET_CHILD,
166 DEVMAN_FUN_GET_MATCH_ID,
167 DEVMAN_FUN_GET_NAME,
168 DEVMAN_FUN_GET_DRIVER_NAME,
169 DEVMAN_FUN_ONLINE,
170 DEVMAN_FUN_OFFLINE,
171 DEVMAN_FUN_GET_PATH,
172 DEVMAN_FUN_SID_TO_HANDLE,
173 DEVMAN_GET_DRIVERS,
174 DEVMAN_DRIVER_GET_DEVICES,
175 DEVMAN_DRIVER_GET_HANDLE,
176 DEVMAN_DRIVER_GET_MATCH_ID,
177 DEVMAN_DRIVER_GET_NAME,
178 DEVMAN_DRIVER_GET_STATE,
179 DEVMAN_DRIVER_LOAD,
180 DEVMAN_DRIVER_UNLOAD
181} client_to_devman_t;
182
183#endif
184
185/** @}
186 */
Note: See TracBrowser for help on using the repository browser.