source: mainline/uspace/lib/drv/generic/remote_ahci.c@ 99e8fb7b

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

libdrv: Make interface structures constant.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2012 Petr Jerman
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
35#include <async.h>
36#include <errno.h>
37#include <stdio.h>
38#include <macros.h>
39#include "ahci_iface.h"
40#include "ddf/driver.h"
41
42typedef enum {
43 IPC_M_AHCI_GET_SATA_DEVICE_NAME,
44 IPC_M_AHCI_GET_NUM_BLOCKS,
45 IPC_M_AHCI_GET_BLOCK_SIZE,
46 IPC_M_AHCI_READ_BLOCKS,
47 IPC_M_AHCI_WRITE_BLOCKS
48} ahci_iface_funcs_t;
49
50#define LO(ptr) \
51 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff))
52
53#define HI(ptr) \
54 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32))
55
56static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t,
57 ipc_call_t *);
58static void remote_ahci_get_num_blocks(ddf_fun_t *, void *, ipc_callid_t,
59 ipc_call_t *);
60static void remote_ahci_get_block_size(ddf_fun_t *, void *, ipc_callid_t,
61 ipc_call_t *);
62static void remote_ahci_read_blocks(ddf_fun_t *, void *, ipc_callid_t,
63 ipc_call_t *);
64static void remote_ahci_write_blocks(ddf_fun_t *, void *, ipc_callid_t,
65 ipc_call_t *);
66
67/** Remote AHCI interface operations. */
68static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
69 [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name,
70 [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks,
71 [IPC_M_AHCI_GET_BLOCK_SIZE] = remote_ahci_get_block_size,
72 [IPC_M_AHCI_READ_BLOCKS] = remote_ahci_read_blocks,
73 [IPC_M_AHCI_WRITE_BLOCKS] = remote_ahci_write_blocks
74};
75
76/** Remote AHCI interface structure.
77 */
78const remote_iface_t remote_ahci_iface = {
79 .method_count = ARRAY_SIZE(remote_ahci_iface_ops),
80 .methods = remote_ahci_iface_ops
81};
82
83void remote_ahci_get_sata_device_name(ddf_fun_t *fun, void *iface,
84 ipc_callid_t callid, ipc_call_t *call)
85{
86 const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
87
88 if (ahci_iface->get_sata_device_name == NULL) {
89 async_answer_0(callid, ENOTSUP);
90 return;
91 }
92
93 const size_t sata_dev_name_length =
94 (size_t) DEV_IPC_GET_ARG1(*call);
95
96 char* sata_dev_name = malloc(sata_dev_name_length);
97
98 const int ret = ahci_iface->get_sata_device_name(fun,
99 sata_dev_name_length, sata_dev_name);
100
101 size_t real_size;
102 ipc_callid_t cid;
103 if ((async_data_read_receive(&cid, &real_size)) &&
104 (real_size == sata_dev_name_length))
105 async_data_read_finalize(cid, sata_dev_name, sata_dev_name_length);
106
107 async_answer_0(callid, ret);
108}
109
110static void remote_ahci_get_num_blocks(ddf_fun_t *fun, void *iface,
111 ipc_callid_t callid, ipc_call_t *call)
112{
113 const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
114
115 if (ahci_iface->get_num_blocks == NULL) {
116 async_answer_0(callid, ENOTSUP);
117 return;
118 }
119
120 uint64_t blocks;
121 const int ret = ahci_iface->get_num_blocks(fun, &blocks);
122
123 if (ret != EOK)
124 async_answer_0(callid, ret);
125 else
126 async_answer_2(callid, EOK, HI(blocks), LO(blocks));
127}
128
129static void remote_ahci_get_block_size(ddf_fun_t *fun, void *iface,
130 ipc_callid_t callid, ipc_call_t *call)
131{
132 const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
133
134 if (ahci_iface->get_block_size == NULL) {
135 async_answer_0(callid, ENOTSUP);
136 return;
137 }
138
139 size_t blocks;
140 const int ret = ahci_iface->get_block_size(fun, &blocks);
141
142 if (ret != EOK)
143 async_answer_0(callid, ret);
144 else
145 async_answer_1(callid, EOK, blocks);
146}
147
148void remote_ahci_read_blocks(ddf_fun_t *fun, void *iface,
149 ipc_callid_t callid, ipc_call_t *call)
150{
151 const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
152
153 if (ahci_iface->read_blocks == NULL) {
154 async_answer_0(callid, ENOTSUP);
155 return;
156 }
157
158 size_t maxblock_size;
159 unsigned int flags;
160
161 ipc_callid_t cid;
162 async_share_out_receive(&cid, &maxblock_size, &flags);
163
164 void *buf;
165 async_share_out_finalize(cid, &buf);
166
167 const uint64_t blocknum =
168 (((uint64_t) (DEV_IPC_GET_ARG1(*call))) << 32) |
169 (((uint64_t) (DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
170 const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
171
172 const int ret = ahci_iface->read_blocks(fun, blocknum, cnt, buf);
173
174 async_answer_0(callid, ret);
175}
176
177void remote_ahci_write_blocks(ddf_fun_t *fun, void *iface, ipc_callid_t callid,
178 ipc_call_t *call)
179{
180 const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
181
182 if (ahci_iface->read_blocks == NULL) {
183 async_answer_0(callid, ENOTSUP);
184 return;
185 }
186
187 size_t maxblock_size;
188 unsigned int flags;
189
190 ipc_callid_t cid;
191 async_share_out_receive(&cid, &maxblock_size, &flags);
192
193 void *buf;
194 async_share_out_finalize(cid, &buf);
195
196 const uint64_t blocknum =
197 (((uint64_t)(DEV_IPC_GET_ARG1(*call))) << 32) |
198 (((uint64_t)(DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
199 const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
200
201 const int ret = ahci_iface->write_blocks(fun, blocknum, cnt, buf);
202
203 async_answer_0(callid, ret);
204}
205
206/**
207 * @}
208 */
Note: See TracBrowser for help on using the repository browser.