source: mainline/uspace/lib/drv/generic/remote_hw_res.c

Last change on this file was 832cbe7, checked in by Jiri Svoboda <jiri@…>, 5 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: 6.4 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
3 * Copyright (c) 2010 Lenka Trochtova
4 * Copyright (c) 2011 Jan Vesely
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup libdrv
32 * @{
33 */
34/** @file
35 */
36
37#include <async.h>
38#include <errno.h>
39#include <macros.h>
40
41#include "ops/hw_res.h"
42#include "ddf/driver.h"
43
44static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_call_t *);
45static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_call_t *);
46static void remote_hw_res_disable_interrupt(ddf_fun_t *, void *, ipc_call_t *);
47static void remote_hw_res_clear_interrupt(ddf_fun_t *, void *, ipc_call_t *);
48static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_call_t *);
49static void remote_hw_res_dma_channel_remain(ddf_fun_t *, void *, ipc_call_t *);
50static void remote_hw_res_query_legacy_io(ddf_fun_t *, void *, ipc_call_t *);
51static void remote_hw_res_claim_legacy_io(ddf_fun_t *, void *, ipc_call_t *);
52
53static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
54 [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
55 [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
56 [HW_RES_DISABLE_INTERRUPT] = &remote_hw_res_disable_interrupt,
57 [HW_RES_CLEAR_INTERRUPT] = &remote_hw_res_clear_interrupt,
58 [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
59 [HW_RES_DMA_CHANNEL_REMAIN] = &remote_hw_res_dma_channel_remain,
60 [HW_RES_QUERY_LEGACY_IO] = &remote_hw_res_query_legacy_io,
61 [HW_RES_CLAIM_LEGACY_IO] = &remote_hw_res_claim_legacy_io
62};
63
64const remote_iface_t remote_hw_res_iface = {
65 .method_count = ARRAY_SIZE(remote_hw_res_iface_ops),
66 .methods = remote_hw_res_iface_ops
67};
68
69static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
70 ipc_call_t *call)
71{
72 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
73
74 if (hw_res_ops->enable_interrupt == NULL) {
75 async_answer_0(call, ENOTSUP);
76 return;
77 }
78
79 const int irq = DEV_IPC_GET_ARG1(*call);
80 const errno_t ret = hw_res_ops->enable_interrupt(fun, irq);
81 async_answer_0(call, ret);
82}
83
84static void remote_hw_res_disable_interrupt(ddf_fun_t *fun, void *ops,
85 ipc_call_t *call)
86{
87 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
88
89 if (hw_res_ops->disable_interrupt == NULL) {
90 async_answer_0(call, ENOTSUP);
91 return;
92 }
93
94 const int irq = DEV_IPC_GET_ARG1(*call);
95 const errno_t ret = hw_res_ops->disable_interrupt(fun, irq);
96 async_answer_0(call, ret);
97}
98
99static void remote_hw_res_clear_interrupt(ddf_fun_t *fun, void *ops,
100 ipc_call_t *call)
101{
102 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
103
104 if (hw_res_ops->clear_interrupt == NULL) {
105 async_answer_0(call, ENOTSUP);
106 return;
107 }
108
109 const int irq = DEV_IPC_GET_ARG1(*call);
110 const errno_t ret = hw_res_ops->clear_interrupt(fun, irq);
111 async_answer_0(call, ret);
112}
113
114static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
115 ipc_call_t *call)
116{
117 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
118
119 if (hw_res_ops->get_resource_list == NULL) {
120 async_answer_0(call, ENOTSUP);
121 return;
122 }
123
124 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
125 if (hw_resources == NULL) {
126 async_answer_0(call, ENOENT);
127 return;
128 }
129
130 async_answer_1(call, EOK, hw_resources->count);
131
132 ipc_call_t data;
133 size_t len;
134 if (!async_data_read_receive(&data, &len)) {
135 /* Protocol error - the recipient is not accepting data */
136 return;
137 }
138
139 async_data_read_finalize(&data, hw_resources->resources, len);
140}
141
142static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
143 ipc_call_t *call)
144{
145 hw_res_ops_t *hw_res_ops = ops;
146
147 if (hw_res_ops->dma_channel_setup == NULL) {
148 async_answer_0(call, ENOTSUP);
149 return;
150 }
151
152 const unsigned channel = DEV_IPC_GET_ARG1(*call) & 0xffff;
153 const uint8_t mode = DEV_IPC_GET_ARG1(*call) >> 16;
154 const uint32_t address = DEV_IPC_GET_ARG2(*call);
155 const uint32_t size = DEV_IPC_GET_ARG3(*call);
156
157 const errno_t ret = hw_res_ops->dma_channel_setup(
158 fun, channel, address, size, mode);
159 async_answer_0(call, ret);
160}
161
162static void remote_hw_res_dma_channel_remain(ddf_fun_t *fun, void *ops,
163 ipc_call_t *call)
164{
165 hw_res_ops_t *hw_res_ops = ops;
166
167 if (hw_res_ops->dma_channel_setup == NULL) {
168 async_answer_0(call, ENOTSUP);
169 return;
170 }
171
172 const unsigned channel = DEV_IPC_GET_ARG1(*call);
173 size_t remain = 0;
174 const errno_t ret = hw_res_ops->dma_channel_remain(fun, channel, &remain);
175 async_answer_1(call, ret, remain);
176}
177
178static void remote_hw_res_query_legacy_io(ddf_fun_t *fun, void *ops,
179 ipc_call_t *call)
180{
181 hw_res_ops_t *hw_res_ops = ops;
182
183 if (hw_res_ops->query_legacy_io == NULL) {
184 async_answer_0(call, ENOTSUP);
185 return;
186 }
187
188 hw_res_claims_t claims = 0;
189 const errno_t ret = hw_res_ops->query_legacy_io(fun, &claims);
190 async_answer_1(call, ret, claims);
191}
192
193static void remote_hw_res_claim_legacy_io(ddf_fun_t *fun, void *ops,
194 ipc_call_t *call)
195{
196 hw_res_ops_t *hw_res_ops = ops;
197 hw_res_claims_t claims;
198
199 if (hw_res_ops->claim_legacy_io == NULL) {
200 async_answer_0(call, ENOTSUP);
201 return;
202 }
203
204 claims = DEV_IPC_GET_ARG1(*call);
205
206 const errno_t ret = hw_res_ops->claim_legacy_io(fun, claims);
207 async_answer_0(call, ret);
208}
209
210/**
211 * @}
212 */
Note: See TracBrowser for help on using the repository browser.