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

Last change on this file since c997374 was 443695e, checked in by Jiri Svoboda <jiri@…>, 15 months ago

Basic PCI-IDE driver (no DMA support)

Also, make sure we avoid attaching ISA IDE and PCI IDE
at the same time. For simplicity, use ISA IDE on ISA systems
and PCI IDE on PCI-based systems.

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2024 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_get_flags(ddf_fun_t *, void *, ipc_call_t *);
51
52static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
53 [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
54 [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
55 [HW_RES_DISABLE_INTERRUPT] = &remote_hw_res_disable_interrupt,
56 [HW_RES_CLEAR_INTERRUPT] = &remote_hw_res_clear_interrupt,
57 [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
58 [HW_RES_DMA_CHANNEL_REMAIN] = &remote_hw_res_dma_channel_remain,
59 [HW_RES_GET_FLAGS] = &remote_hw_res_get_flags
60};
61
62const remote_iface_t remote_hw_res_iface = {
63 .method_count = ARRAY_SIZE(remote_hw_res_iface_ops),
64 .methods = remote_hw_res_iface_ops
65};
66
67static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
68 ipc_call_t *call)
69{
70 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
71
72 if (hw_res_ops->enable_interrupt == NULL) {
73 async_answer_0(call, ENOTSUP);
74 return;
75 }
76
77 const int irq = DEV_IPC_GET_ARG1(*call);
78 const errno_t ret = hw_res_ops->enable_interrupt(fun, irq);
79 async_answer_0(call, ret);
80}
81
82static void remote_hw_res_disable_interrupt(ddf_fun_t *fun, void *ops,
83 ipc_call_t *call)
84{
85 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
86
87 if (hw_res_ops->disable_interrupt == NULL) {
88 async_answer_0(call, ENOTSUP);
89 return;
90 }
91
92 const int irq = DEV_IPC_GET_ARG1(*call);
93 const errno_t ret = hw_res_ops->disable_interrupt(fun, irq);
94 async_answer_0(call, ret);
95}
96
97static void remote_hw_res_clear_interrupt(ddf_fun_t *fun, void *ops,
98 ipc_call_t *call)
99{
100 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
101
102 if (hw_res_ops->clear_interrupt == NULL) {
103 async_answer_0(call, ENOTSUP);
104 return;
105 }
106
107 const int irq = DEV_IPC_GET_ARG1(*call);
108 const errno_t ret = hw_res_ops->clear_interrupt(fun, irq);
109 async_answer_0(call, ret);
110}
111
112static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
113 ipc_call_t *call)
114{
115 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
116
117 if (hw_res_ops->get_resource_list == NULL) {
118 async_answer_0(call, ENOTSUP);
119 return;
120 }
121
122 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
123 if (hw_resources == NULL) {
124 async_answer_0(call, ENOENT);
125 return;
126 }
127
128 async_answer_1(call, EOK, hw_resources->count);
129
130 ipc_call_t data;
131 size_t len;
132 if (!async_data_read_receive(&data, &len)) {
133 /* Protocol error - the recipient is not accepting data */
134 return;
135 }
136
137 async_data_read_finalize(&data, hw_resources->resources, len);
138}
139
140static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
141 ipc_call_t *call)
142{
143 hw_res_ops_t *hw_res_ops = ops;
144
145 if (hw_res_ops->dma_channel_setup == NULL) {
146 async_answer_0(call, ENOTSUP);
147 return;
148 }
149
150 const unsigned channel = DEV_IPC_GET_ARG1(*call) & 0xffff;
151 const uint8_t mode = DEV_IPC_GET_ARG1(*call) >> 16;
152 const uint32_t address = DEV_IPC_GET_ARG2(*call);
153 const uint32_t size = DEV_IPC_GET_ARG3(*call);
154
155 const errno_t ret = hw_res_ops->dma_channel_setup(
156 fun, channel, address, size, mode);
157 async_answer_0(call, ret);
158}
159
160static void remote_hw_res_dma_channel_remain(ddf_fun_t *fun, void *ops,
161 ipc_call_t *call)
162{
163 hw_res_ops_t *hw_res_ops = ops;
164
165 if (hw_res_ops->dma_channel_setup == NULL) {
166 async_answer_0(call, ENOTSUP);
167 return;
168 }
169
170 const unsigned channel = DEV_IPC_GET_ARG1(*call);
171 size_t remain = 0;
172 const errno_t ret = hw_res_ops->dma_channel_remain(fun, channel, &remain);
173 async_answer_1(call, ret, remain);
174}
175
176static void remote_hw_res_get_flags(ddf_fun_t *fun, void *ops,
177 ipc_call_t *call)
178{
179 hw_res_ops_t *hw_res_ops = ops;
180
181 if (hw_res_ops->get_flags == NULL) {
182 async_answer_0(call, ENOTSUP);
183 return;
184 }
185
186 hw_res_flags_t flags = 0;
187 const errno_t ret = hw_res_ops->get_flags(fun, &flags);
188 async_answer_1(call, ret, flags);
189}
190
191/**
192 * @}
193 */
Note: See TracBrowser for help on using the repository browser.