source: mainline/uspace/lib/drv/generic/remote_hw_res.c@ 9991c47

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9991c47 was 9991c47, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

libc, libdrv: Add support for DMA channel handling.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[52b7b1bb]1/*
[7a252ec8]2 * Copyright (c) 2010 Lenka Trochtova
[52b7b1bb]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libdrv
30 * @{
31 */
32/** @file
33 */
34
[57937dd]35#include <async.h>
[52b7b1bb]36#include <errno.h>
37
[41b56084]38#include "ops/hw_res.h"
[af6b5157]39#include "ddf/driver.h"
[52b7b1bb]40
[83a2f43]41static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t,
[7a252ec8]42 ipc_call_t *);
[83a2f43]43static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t,
[7a252ec8]44 ipc_call_t *);
[9991c47]45static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_callid_t,
46 ipc_call_t *);
[52b7b1bb]47
[50c57df]48static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
[9991c47]49 [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
50 [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
51 [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
[7a252ec8]52};
53
[50c57df]54remote_iface_t remote_hw_res_iface = {
55 .method_count = sizeof(remote_hw_res_iface_ops) /
[7a252ec8]56 sizeof(remote_iface_func_ptr_t),
[50c57df]57 .methods = remote_hw_res_iface_ops
[52b7b1bb]58};
59
[83a2f43]60static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
[7a252ec8]61 ipc_callid_t callid, ipc_call_t *call)
[52b7b1bb]62{
[d35ac1d]63 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
[52b7b1bb]64
[d35ac1d]65 if (hw_res_ops->enable_interrupt == NULL)
[ffa2c8ef]66 async_answer_0(callid, ENOTSUP);
[8b1e15ac]67 else if (hw_res_ops->enable_interrupt(fun))
[ffa2c8ef]68 async_answer_0(callid, EOK);
[7a252ec8]69 else
[ffa2c8ef]70 async_answer_0(callid, EREFUSED);
[52b7b1bb]71}
72
[83a2f43]73static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
[7a252ec8]74 ipc_callid_t callid, ipc_call_t *call)
[52b7b1bb]75{
[d35ac1d]76 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
77
78 if (hw_res_ops->get_resource_list == NULL) {
[ffa2c8ef]79 async_answer_0(callid, ENOTSUP);
[57937dd]80 return;
81 }
[52b7b1bb]82
[8b1e15ac]83 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
[36f2b3e]84 if (hw_resources == NULL){
[ffa2c8ef]85 async_answer_0(callid, ENOENT);
[57937dd]86 return;
[36f2b3e]87 }
[52b7b1bb]88
[ffa2c8ef]89 async_answer_1(callid, EOK, hw_resources->count);
[57937dd]90
91 size_t len;
92 if (!async_data_read_receive(&callid, &len)) {
[36f2b3e]93 /* Protocol error - the recipient is not accepting data */
[57937dd]94 return;
95 }
96 async_data_read_finalize(callid, hw_resources->resources, len);
[52b7b1bb]97}
[7a252ec8]98
[9991c47]99static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
100 ipc_callid_t callid, ipc_call_t *call)
101{
102 hw_res_ops_t *hw_res_ops = ops;
103
104 if (hw_res_ops->dma_channel_setup == NULL) {
105 async_answer_0(callid, ENOTSUP);
106 return;
107 }
108 const unsigned channel = DEV_IPC_GET_ARG1(*call);
109 const uint32_t address = DEV_IPC_GET_ARG2(*call);
110 const uint16_t size = DEV_IPC_GET_ARG3(*call) & 0xffff;
111 const uint8_t mode = DEV_IPC_GET_ARG3(*call) >> 16;
112
113 const int ret = hw_res_ops->dma_channel_setup(
114 channel, address, size, mode);
115 async_answer_0(callid, ret);
116}
117
[7a252ec8]118/**
[52b7b1bb]119 * @}
[7a252ec8]120 */
Note: See TracBrowser for help on using the repository browser.