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

Last change on this file since b336bfd8 was 832cbe7, checked in by Jiri Svoboda <jiri@…>, 11 months ago

Add proper IDE PCI to ISA fallback mechanism.

To determine if legacy IDE I/O ports are free, isa-ide asks isa,
who asks pciintel. pciintel waits for bus enumeration to complete,
then waits for all functions except the one who is asking
(which is ISA bus) to stabilize. During attach pci-ide will claim
the legacy IDE ports. Thus, if at this point legacy IDE ports
are unclaimed, pciintel tells ISA they are free, which tells isa-ide,
which continues to attach. If they are not free, isa-ide will not
attach.

This works for all use cases, including system without PCI bus,
system with PCI bus, but no (or disabled) PCI IDE, system with PCI
IDE with unrecognized VID/PID (which we will handle in legacy ISA mode).

  • Property mode set to 100644
File size: 4.7 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_WAIT_STABLE,
151 DEVMAN_REMOVE_FUNCTION
152} driver_to_devman_t;
153
154typedef enum {
155 DRIVER_DEV_ADD = IPC_FIRST_USER_METHOD,
156 DRIVER_DEV_REMOVE,
157 DRIVER_DEV_GONE,
158 DRIVER_FUN_ONLINE,
159 DRIVER_FUN_OFFLINE,
160 DRIVER_STOP
161} devman_to_driver_t;
162
163typedef enum {
164 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
165 DEVMAN_DEV_GET_FUNCTIONS,
166 DEVMAN_DEV_GET_PARENT,
167 DEVMAN_FUN_GET_CHILD,
168 DEVMAN_FUN_GET_MATCH_ID,
169 DEVMAN_FUN_GET_NAME,
170 DEVMAN_FUN_GET_DRIVER_NAME,
171 DEVMAN_FUN_ONLINE,
172 DEVMAN_FUN_OFFLINE,
173 DEVMAN_FUN_GET_PATH,
174 DEVMAN_FUN_SID_TO_HANDLE,
175 DEVMAN_GET_DRIVERS,
176 DEVMAN_DRIVER_GET_DEVICES,
177 DEVMAN_DRIVER_GET_HANDLE,
178 DEVMAN_DRIVER_GET_MATCH_ID,
179 DEVMAN_DRIVER_GET_NAME,
180 DEVMAN_DRIVER_GET_STATE,
181 DEVMAN_DRIVER_LOAD,
182 DEVMAN_DRIVER_UNLOAD
183} client_to_devman_t;
184
185#endif
186
187/** @}
188 */
Note: See TracBrowser for help on using the repository browser.