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 |
|
---|
44 | static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_call_t *);
|
---|
45 | static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_call_t *);
|
---|
46 | static void remote_hw_res_disable_interrupt(ddf_fun_t *, void *, ipc_call_t *);
|
---|
47 | static void remote_hw_res_clear_interrupt(ddf_fun_t *, void *, ipc_call_t *);
|
---|
48 | static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_call_t *);
|
---|
49 | static void remote_hw_res_dma_channel_remain(ddf_fun_t *, void *, ipc_call_t *);
|
---|
50 | static void remote_hw_res_query_legacy_io(ddf_fun_t *, void *, ipc_call_t *);
|
---|
51 | static void remote_hw_res_claim_legacy_io(ddf_fun_t *, void *, ipc_call_t *);
|
---|
52 |
|
---|
53 | static 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 |
|
---|
64 | const 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 |
|
---|
69 | static 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 |
|
---|
84 | static 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 |
|
---|
99 | static 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 |
|
---|
114 | static 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 |
|
---|
142 | static 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 |
|
---|
162 | static 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 |
|
---|
178 | static 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 |
|
---|
193 | static 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 | */
|
---|