source: mainline/uspace/lib/drv/generic/remote_hw_res.c@ 4bbfb93

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

libdrv, hw_res: Add forgotten ddf_fun_t* argument.

Set pointer to uint32_t, ISA DMA is limited to 24 bit addresses.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[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>
38
[41b56084]39#include "ops/hw_res.h"
[af6b5157]40#include "ddf/driver.h"
[52b7b1bb]41
[83a2f43]42static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t,
[7a252ec8]43 ipc_call_t *);
[83a2f43]44static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t,
[7a252ec8]45 ipc_call_t *);
[9991c47]46static void remote_hw_res_dma_channel_setup(ddf_fun_t *, void *, ipc_callid_t,
47 ipc_call_t *);
[52b7b1bb]48
[50c57df]49static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
[9991c47]50 [HW_RES_GET_RESOURCE_LIST] = &remote_hw_res_get_resource_list,
51 [HW_RES_ENABLE_INTERRUPT] = &remote_hw_res_enable_interrupt,
52 [HW_RES_DMA_CHANNEL_SETUP] = &remote_hw_res_dma_channel_setup,
[7a252ec8]53};
54
[50c57df]55remote_iface_t remote_hw_res_iface = {
56 .method_count = sizeof(remote_hw_res_iface_ops) /
[7a252ec8]57 sizeof(remote_iface_func_ptr_t),
[50c57df]58 .methods = remote_hw_res_iface_ops
[52b7b1bb]59};
60
[83a2f43]61static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
[7a252ec8]62 ipc_callid_t callid, ipc_call_t *call)
[52b7b1bb]63{
[d35ac1d]64 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
[52b7b1bb]65
[d35ac1d]66 if (hw_res_ops->enable_interrupt == NULL)
[ffa2c8ef]67 async_answer_0(callid, ENOTSUP);
[8b1e15ac]68 else if (hw_res_ops->enable_interrupt(fun))
[ffa2c8ef]69 async_answer_0(callid, EOK);
[7a252ec8]70 else
[ffa2c8ef]71 async_answer_0(callid, EREFUSED);
[52b7b1bb]72}
73
[83a2f43]74static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
[7a252ec8]75 ipc_callid_t callid, ipc_call_t *call)
[52b7b1bb]76{
[d35ac1d]77 hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
78
79 if (hw_res_ops->get_resource_list == NULL) {
[ffa2c8ef]80 async_answer_0(callid, ENOTSUP);
[57937dd]81 return;
82 }
[52b7b1bb]83
[8b1e15ac]84 hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
[36f2b3e]85 if (hw_resources == NULL){
[ffa2c8ef]86 async_answer_0(callid, ENOENT);
[57937dd]87 return;
[36f2b3e]88 }
[52b7b1bb]89
[ffa2c8ef]90 async_answer_1(callid, EOK, hw_resources->count);
[57937dd]91
92 size_t len;
93 if (!async_data_read_receive(&callid, &len)) {
[36f2b3e]94 /* Protocol error - the recipient is not accepting data */
[57937dd]95 return;
96 }
97 async_data_read_finalize(callid, hw_resources->resources, len);
[52b7b1bb]98}
[7a252ec8]99
[9991c47]100static void remote_hw_res_dma_channel_setup(ddf_fun_t *fun, void *ops,
101 ipc_callid_t callid, ipc_call_t *call)
102{
103 hw_res_ops_t *hw_res_ops = ops;
104
105 if (hw_res_ops->dma_channel_setup == NULL) {
106 async_answer_0(callid, ENOTSUP);
107 return;
108 }
109 const unsigned channel = DEV_IPC_GET_ARG1(*call);
110 const uint32_t address = DEV_IPC_GET_ARG2(*call);
111 const uint16_t size = DEV_IPC_GET_ARG3(*call) & 0xffff;
112 const uint8_t mode = DEV_IPC_GET_ARG3(*call) >> 16;
113
114 const int ret = hw_res_ops->dma_channel_setup(
[8a5962f]115 fun, channel, address, size, mode);
[9991c47]116 async_answer_0(callid, ret);
117}
118
[7a252ec8]119/**
[52b7b1bb]120 * @}
[7a252ec8]121 */
Note: See TracBrowser for help on using the repository browser.