[52b7b1bb] | 1 | /*
|
---|
[832cbe7] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[7a252ec8] | 3 | * Copyright (c) 2010 Lenka Trochtova
|
---|
[8a5962f] | 4 | * Copyright (c) 2011 Jan Vesely
|
---|
[52b7b1bb] | 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 |
|
---|
[57937dd] | 37 | #include <async.h>
|
---|
[52b7b1bb] | 38 | #include <errno.h>
|
---|
[9be30cdf] | 39 | #include <macros.h>
|
---|
[52b7b1bb] | 40 |
|
---|
[41b56084] | 41 | #include "ops/hw_res.h"
|
---|
[af6b5157] | 42 | #include "ddf/driver.h"
|
---|
[52b7b1bb] | 43 |
|
---|
[984a9ba] | 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 *);
|
---|
[832cbe7] | 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 *);
|
---|
[52b7b1bb] | 52 |
|
---|
[9be30cdf] | 53 | static const remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
|
---|
[9991c47] | 54 | [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
|
---|
| 55 | [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
|
---|
[d51838f] | 56 | [HW_RES_DISABLE_INTERRUPT] = &remote_hw_res_disable_interrupt,
|
---|
| 57 | [HW_RES_CLEAR_INTERRUPT] = &remote_hw_res_clear_interrupt,
|
---|
[9991c47] | 58 | [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
|
---|
[6fd365d] | 59 | [HW_RES_DMA_CHANNEL_REMAIN] = &remote_hw_res_dma_channel_remain,
|
---|
[832cbe7] | 60 | [HW_RES_QUERY_LEGACY_IO] = &remote_hw_res_query_legacy_io,
|
---|
| 61 | [HW_RES_CLAIM_LEGACY_IO] = &remote_hw_res_claim_legacy_io
|
---|
[7a252ec8] | 62 | };
|
---|
| 63 |
|
---|
[7f80313] | 64 | const remote_iface_t remote_hw_res_iface = {
|
---|
[9be30cdf] | 65 | .method_count = ARRAY_SIZE(remote_hw_res_iface_ops),
|
---|
[50c57df] | 66 | .methods = remote_hw_res_iface_ops
|
---|
[52b7b1bb] | 67 | };
|
---|
| 68 |
|
---|
[83a2f43] | 69 | static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 70 | ipc_call_t *call)
|
---|
[52b7b1bb] | 71 | {
|
---|
[d35ac1d] | 72 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
---|
[a35b458] | 73 |
|
---|
[cccd60c3] | 74 | if (hw_res_ops->enable_interrupt == NULL) {
|
---|
[984a9ba] | 75 | async_answer_0(call, ENOTSUP);
|
---|
[cccd60c3] | 76 | return;
|
---|
| 77 | }
|
---|
[a35b458] | 78 |
|
---|
[cccd60c3] | 79 | const int irq = DEV_IPC_GET_ARG1(*call);
|
---|
[b7fd2a0] | 80 | const errno_t ret = hw_res_ops->enable_interrupt(fun, irq);
|
---|
[984a9ba] | 81 | async_answer_0(call, ret);
|
---|
[52b7b1bb] | 82 | }
|
---|
| 83 |
|
---|
[d51838f] | 84 | static void remote_hw_res_disable_interrupt(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 85 | ipc_call_t *call)
|
---|
[d51838f] | 86 | {
|
---|
| 87 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
---|
[a35b458] | 88 |
|
---|
[d51838f] | 89 | if (hw_res_ops->disable_interrupt == NULL) {
|
---|
[984a9ba] | 90 | async_answer_0(call, ENOTSUP);
|
---|
[d51838f] | 91 | return;
|
---|
| 92 | }
|
---|
[a35b458] | 93 |
|
---|
[d51838f] | 94 | const int irq = DEV_IPC_GET_ARG1(*call);
|
---|
[b7fd2a0] | 95 | const errno_t ret = hw_res_ops->disable_interrupt(fun, irq);
|
---|
[984a9ba] | 96 | async_answer_0(call, ret);
|
---|
[d51838f] | 97 | }
|
---|
| 98 |
|
---|
| 99 | static void remote_hw_res_clear_interrupt(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 100 | ipc_call_t *call)
|
---|
[d51838f] | 101 | {
|
---|
| 102 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
---|
[a35b458] | 103 |
|
---|
[d51838f] | 104 | if (hw_res_ops->clear_interrupt == NULL) {
|
---|
[984a9ba] | 105 | async_answer_0(call, ENOTSUP);
|
---|
[d51838f] | 106 | return;
|
---|
| 107 | }
|
---|
[a35b458] | 108 |
|
---|
[d51838f] | 109 | const int irq = DEV_IPC_GET_ARG1(*call);
|
---|
[dbc1398] | 110 | const errno_t ret = hw_res_ops->clear_interrupt(fun, irq);
|
---|
[984a9ba] | 111 | async_answer_0(call, ret);
|
---|
[d51838f] | 112 | }
|
---|
| 113 |
|
---|
[83a2f43] | 114 | static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 115 | ipc_call_t *call)
|
---|
[52b7b1bb] | 116 | {
|
---|
[d35ac1d] | 117 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
---|
| 118 |
|
---|
| 119 | if (hw_res_ops->get_resource_list == NULL) {
|
---|
[984a9ba] | 120 | async_answer_0(call, ENOTSUP);
|
---|
[57937dd] | 121 | return;
|
---|
| 122 | }
|
---|
[a35b458] | 123 |
|
---|
[8b1e15ac] | 124 | hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
|
---|
[1433ecda] | 125 | if (hw_resources == NULL) {
|
---|
[984a9ba] | 126 | async_answer_0(call, ENOENT);
|
---|
[57937dd] | 127 | return;
|
---|
[36f2b3e] | 128 | }
|
---|
[a35b458] | 129 |
|
---|
[984a9ba] | 130 | async_answer_1(call, EOK, hw_resources->count);
|
---|
[57937dd] | 131 |
|
---|
[984a9ba] | 132 | ipc_call_t data;
|
---|
[57937dd] | 133 | size_t len;
|
---|
[984a9ba] | 134 | if (!async_data_read_receive(&data, &len)) {
|
---|
[36f2b3e] | 135 | /* Protocol error - the recipient is not accepting data */
|
---|
[57937dd] | 136 | return;
|
---|
| 137 | }
|
---|
[984a9ba] | 138 |
|
---|
| 139 | async_data_read_finalize(&data, hw_resources->resources, len);
|
---|
[52b7b1bb] | 140 | }
|
---|
[7a252ec8] | 141 |
|
---|
[9991c47] | 142 | static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 143 | ipc_call_t *call)
|
---|
[9991c47] | 144 | {
|
---|
| 145 | hw_res_ops_t *hw_res_ops = ops;
|
---|
| 146 |
|
---|
| 147 | if (hw_res_ops->dma_channel_setup == NULL) {
|
---|
[984a9ba] | 148 | async_answer_0(call, ENOTSUP);
|
---|
[9991c47] | 149 | return;
|
---|
| 150 | }
|
---|
[984a9ba] | 151 |
|
---|
[301032a] | 152 | const unsigned channel = DEV_IPC_GET_ARG1(*call) & 0xffff;
|
---|
| 153 | const uint8_t mode = DEV_IPC_GET_ARG1(*call) >> 16;
|
---|
[9991c47] | 154 | const uint32_t address = DEV_IPC_GET_ARG2(*call);
|
---|
[301032a] | 155 | const uint32_t size = DEV_IPC_GET_ARG3(*call);
|
---|
[9991c47] | 156 |
|
---|
[b7fd2a0] | 157 | const errno_t ret = hw_res_ops->dma_channel_setup(
|
---|
[8a5962f] | 158 | fun, channel, address, size, mode);
|
---|
[984a9ba] | 159 | async_answer_0(call, ret);
|
---|
[9991c47] | 160 | }
|
---|
| 161 |
|
---|
[6fd365d] | 162 | static void remote_hw_res_dma_channel_remain(ddf_fun_t *fun, void *ops,
|
---|
[984a9ba] | 163 | ipc_call_t *call)
|
---|
[6fd365d] | 164 | {
|
---|
| 165 | hw_res_ops_t *hw_res_ops = ops;
|
---|
| 166 |
|
---|
| 167 | if (hw_res_ops->dma_channel_setup == NULL) {
|
---|
[984a9ba] | 168 | async_answer_0(call, ENOTSUP);
|
---|
[6fd365d] | 169 | return;
|
---|
| 170 | }
|
---|
[984a9ba] | 171 |
|
---|
[6fd365d] | 172 | const unsigned channel = DEV_IPC_GET_ARG1(*call);
|
---|
[3869c596] | 173 | size_t remain = 0;
|
---|
[b7fd2a0] | 174 | const errno_t ret = hw_res_ops->dma_channel_remain(fun, channel, &remain);
|
---|
[984a9ba] | 175 | async_answer_1(call, ret, remain);
|
---|
[6fd365d] | 176 | }
|
---|
[984a9ba] | 177 |
|
---|
[832cbe7] | 178 | static void remote_hw_res_query_legacy_io(ddf_fun_t *fun, void *ops,
|
---|
[443695e] | 179 | ipc_call_t *call)
|
---|
| 180 | {
|
---|
| 181 | hw_res_ops_t *hw_res_ops = ops;
|
---|
| 182 |
|
---|
[832cbe7] | 183 | if (hw_res_ops->query_legacy_io == NULL) {
|
---|
[443695e] | 184 | async_answer_0(call, ENOTSUP);
|
---|
| 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[832cbe7] | 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);
|
---|
[443695e] | 208 | }
|
---|
| 209 |
|
---|
[7a252ec8] | 210 | /**
|
---|
[52b7b1bb] | 211 | * @}
|
---|
[7a252ec8] | 212 | */
|
---|