source: mainline/uspace/lib/c/generic/bd.c@ fcab7ef

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fcab7ef was f9b2cb4c, checked in by Martin Decky <martin@…>, 10 years ago

unify interface API

  • introduce new interfaces
  • unify location service clients to always expect service ID as the second argument
  • remove obsolete methods that take explicit exchange management arguments (first phase)
  • use interfaces in device drivers, devman, location service, logger, inet
  • Property mode set to 100644
File size: 4.8 KB
Line 
1/*
2 * Copyright (c) 2012 Jiri Svoboda
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 libc
30 * @{
31 */
32/**
33 * @file
34 * @brief IP link client stub
35 */
36
37#include <async.h>
38#include <assert.h>
39#include <bd.h>
40#include <errno.h>
41#include <ipc/bd.h>
42#include <ipc/services.h>
43#include <loc.h>
44#include <macros.h>
45#include <stdlib.h>
46
47static void bd_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
48
49int bd_open(async_sess_t *sess, bd_t **rbd)
50{
51 bd_t *bd = calloc(1, sizeof(bd_t));
52 if (bd == NULL)
53 return ENOMEM;
54
55 bd->sess = sess;
56
57 async_exch_t *exch = async_exchange_begin(sess);
58
59 port_id_t port;
60 int rc = async_create_callback_port(exch, INTERFACE_BLOCK_CB, 0, 0,
61 bd_cb_conn, bd, &port);
62
63 async_exchange_end(exch);
64
65 if (rc != EOK)
66 goto error;
67
68 *rbd = bd;
69 return EOK;
70
71error:
72 if (bd != NULL)
73 free(bd);
74
75 return rc;
76}
77
78void bd_close(bd_t *bd)
79{
80 /* XXX Synchronize with bd_cb_conn */
81 free(bd);
82}
83
84int bd_read_blocks(bd_t *bd, aoff64_t ba, size_t cnt, void *data, size_t size)
85{
86 async_exch_t *exch = async_exchange_begin(bd->sess);
87
88 ipc_call_t answer;
89 aid_t req = async_send_3(exch, BD_READ_BLOCKS, LOWER32(ba),
90 UPPER32(ba), cnt, &answer);
91 int rc = async_data_read_start(exch, data, size);
92 async_exchange_end(exch);
93
94 if (rc != EOK) {
95 async_forget(req);
96 return rc;
97 }
98
99 sysarg_t retval;
100 async_wait_for(req, &retval);
101
102 if (retval != EOK)
103 return retval;
104
105 return EOK;
106}
107
108int bd_read_toc(bd_t *bd, uint8_t session, void *buf, size_t size)
109{
110 async_exch_t *exch = async_exchange_begin(bd->sess);
111
112 ipc_call_t answer;
113 aid_t req = async_send_1(exch, BD_READ_TOC, session, &answer);
114 int rc = async_data_read_start(exch, buf, size);
115 async_exchange_end(exch);
116
117 if (rc != EOK) {
118 async_forget(req);
119 return rc;
120 }
121
122 sysarg_t retval;
123 async_wait_for(req, &retval);
124
125 if (retval != EOK)
126 return retval;
127
128 return EOK;
129}
130
131int bd_write_blocks(bd_t *bd, aoff64_t ba, size_t cnt, const void *data,
132 size_t size)
133{
134 async_exch_t *exch = async_exchange_begin(bd->sess);
135
136 ipc_call_t answer;
137 aid_t req = async_send_3(exch, BD_WRITE_BLOCKS, LOWER32(ba),
138 UPPER32(ba), cnt, &answer);
139 int rc = async_data_write_start(exch, data, size);
140 async_exchange_end(exch);
141
142 if (rc != EOK) {
143 async_forget(req);
144 return rc;
145 }
146
147 sysarg_t retval;
148 async_wait_for(req, &retval);
149 if (retval != EOK)
150 return retval;
151
152 return EOK;
153}
154
155int bd_sync_cache(bd_t *bd, aoff64_t ba, size_t cnt)
156{
157 async_exch_t *exch = async_exchange_begin(bd->sess);
158
159 int rc = async_req_3_0(exch, BD_SYNC_CACHE, LOWER32(ba),
160 UPPER32(ba), cnt);
161 async_exchange_end(exch);
162
163 return rc;
164}
165
166int bd_get_block_size(bd_t *bd, size_t *rbsize)
167{
168 sysarg_t bsize;
169 async_exch_t *exch = async_exchange_begin(bd->sess);
170
171 int rc = async_req_0_1(exch, BD_GET_BLOCK_SIZE, &bsize);
172 async_exchange_end(exch);
173
174 if (rc != EOK)
175 return rc;
176
177 *rbsize = bsize;
178 return EOK;
179}
180
181int bd_get_num_blocks(bd_t *bd, aoff64_t *rnb)
182{
183 sysarg_t nb_l;
184 sysarg_t nb_h;
185 async_exch_t *exch = async_exchange_begin(bd->sess);
186
187 int rc = async_req_0_2(exch, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
188 async_exchange_end(exch);
189
190 if (rc != EOK)
191 return rc;
192
193 *rnb = (aoff64_t) MERGE_LOUP32(nb_l, nb_h);
194 return EOK;
195}
196
197static void bd_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
198{
199 bd_t *bd = (bd_t *)arg;
200
201 (void)bd;
202
203 while (true) {
204 ipc_call_t call;
205 ipc_callid_t callid = async_get_call(&call);
206
207 if (!IPC_GET_IMETHOD(call)) {
208 /* TODO: Handle hangup */
209 return;
210 }
211
212 switch (IPC_GET_IMETHOD(call)) {
213 default:
214 async_answer_0(callid, ENOTSUP);
215 }
216 }
217}
218
219/** @}
220 */
Note: See TracBrowser for help on using the repository browser.