| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Lenka Trochtova
|
|---|
| 3 | * Copyright (c) 2011 Jan Vesely
|
|---|
| 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 |
|
|---|
| 36 | #include <async.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 |
|
|---|
| 39 | #include "ops/hw_res.h"
|
|---|
| 40 | #include "ddf/driver.h"
|
|---|
| 41 |
|
|---|
| 42 | static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t,
|
|---|
| 43 | ipc_call_t *);
|
|---|
| 44 | static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t,
|
|---|
| 45 | ipc_call_t *);
|
|---|
| 46 | static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_callid_t,
|
|---|
| 47 | ipc_call_t *);
|
|---|
| 48 | static void remote_hw_res_dma_channel_remain(ddf_fun_t *, void *, ipc_callid_t,
|
|---|
| 49 | ipc_call_t *);
|
|---|
| 50 |
|
|---|
| 51 | static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
|
|---|
| 52 | [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
|
|---|
| 53 | [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
|
|---|
| 54 | [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
|
|---|
| 55 | [HW_RES_DMA_CHANNEL_REMAIN] = &remote_hw_res_dma_channel_remain,
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 | remote_iface_t remote_hw_res_iface = {
|
|---|
| 59 | .method_count = sizeof(remote_hw_res_iface_ops) /
|
|---|
| 60 | sizeof(remote_iface_func_ptr_t),
|
|---|
| 61 | .methods = remote_hw_res_iface_ops
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
|
|---|
| 65 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 66 | {
|
|---|
| 67 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
|---|
| 68 |
|
|---|
| 69 | if (hw_res_ops->enable_interrupt == NULL)
|
|---|
| 70 | async_answer_0(callid, ENOTSUP);
|
|---|
| 71 | else if (hw_res_ops->enable_interrupt(fun))
|
|---|
| 72 | async_answer_0(callid, EOK);
|
|---|
| 73 | else
|
|---|
| 74 | async_answer_0(callid, EREFUSED);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
|
|---|
| 78 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 79 | {
|
|---|
| 80 | hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
|
|---|
| 81 |
|
|---|
| 82 | if (hw_res_ops->get_resource_list == NULL) {
|
|---|
| 83 | async_answer_0(callid, ENOTSUP);
|
|---|
| 84 | return;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
|
|---|
| 88 | if (hw_resources == NULL){
|
|---|
| 89 | async_answer_0(callid, ENOENT);
|
|---|
| 90 | return;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | async_answer_1(callid, EOK, hw_resources->count);
|
|---|
| 94 |
|
|---|
| 95 | size_t len;
|
|---|
| 96 | if (!async_data_read_receive(&callid, &len)) {
|
|---|
| 97 | /* Protocol error - the recipient is not accepting data */
|
|---|
| 98 | return;
|
|---|
| 99 | }
|
|---|
| 100 | async_data_read_finalize(callid, hw_resources->resources, len);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
|
|---|
| 104 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 105 | {
|
|---|
| 106 | hw_res_ops_t *hw_res_ops = ops;
|
|---|
| 107 |
|
|---|
| 108 | if (hw_res_ops->dma_channel_setup == NULL) {
|
|---|
| 109 | async_answer_0(callid, ENOTSUP);
|
|---|
| 110 | return;
|
|---|
| 111 | }
|
|---|
| 112 | const unsigned channel = DEV_IPC_GET_ARG1(*call) & 0xffff;
|
|---|
| 113 | const uint8_t mode = DEV_IPC_GET_ARG1(*call) >> 16;
|
|---|
| 114 | const uint32_t address = DEV_IPC_GET_ARG2(*call);
|
|---|
| 115 | const uint32_t size = DEV_IPC_GET_ARG3(*call);
|
|---|
| 116 |
|
|---|
| 117 | const int ret = hw_res_ops->dma_channel_setup(
|
|---|
| 118 | fun, channel, address, size, mode);
|
|---|
| 119 | async_answer_0(callid, ret);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | static void remote_hw_res_dma_channel_remain(ddf_fun_t *fun, void *ops,
|
|---|
| 123 | ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 124 | {
|
|---|
| 125 | hw_res_ops_t *hw_res_ops = ops;
|
|---|
| 126 |
|
|---|
| 127 | if (hw_res_ops->dma_channel_setup == NULL) {
|
|---|
| 128 | async_answer_0(callid, ENOTSUP);
|
|---|
| 129 | return;
|
|---|
| 130 | }
|
|---|
| 131 | const unsigned channel = DEV_IPC_GET_ARG1(*call);
|
|---|
| 132 | size_t remain = 0;
|
|---|
| 133 | const int ret = hw_res_ops->dma_channel_remain(fun, channel, &remain);
|
|---|
| 134 | async_answer_1(callid, ret, remain);
|
|---|
| 135 | }
|
|---|
| 136 | /**
|
|---|
| 137 | * @}
|
|---|
| 138 | */
|
|---|