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