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