[4802dd7] | 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 |
|
---|
| 47 | static void bd_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
|
---|
| 48 |
|
---|
| 49 | int 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 | int rc = async_connect_to_me(exch, 0, 0, 0, bd_cb_conn, bd);
|
---|
| 60 | async_exchange_end(exch);
|
---|
| 61 |
|
---|
| 62 | if (rc != EOK)
|
---|
| 63 | goto error;
|
---|
| 64 |
|
---|
| 65 | *rbd = bd;
|
---|
| 66 | return EOK;
|
---|
| 67 |
|
---|
| 68 | error:
|
---|
| 69 | if (bd != NULL)
|
---|
| 70 | free(bd);
|
---|
| 71 |
|
---|
| 72 | return rc;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | void bd_close(bd_t *bd)
|
---|
| 76 | {
|
---|
| 77 | /* XXX Synchronize with bd_cb_conn */
|
---|
| 78 | free(bd);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | int bd_read_blocks(bd_t *bd, aoff64_t ba, size_t cnt, void *data, size_t size)
|
---|
| 82 | {
|
---|
| 83 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 84 |
|
---|
| 85 | ipc_call_t answer;
|
---|
| 86 | aid_t req = async_send_3(exch, BD_READ_BLOCKS, LOWER32(ba),
|
---|
| 87 | UPPER32(ba), cnt, &answer);
|
---|
| 88 | int rc = async_data_read_start(exch, data, size);
|
---|
| 89 | async_exchange_end(exch);
|
---|
| 90 |
|
---|
| 91 | if (rc != EOK) {
|
---|
| 92 | async_forget(req);
|
---|
| 93 | return rc;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | sysarg_t retval;
|
---|
| 97 | async_wait_for(req, &retval);
|
---|
| 98 |
|
---|
| 99 | if (retval != EOK)
|
---|
| 100 | return retval;
|
---|
| 101 |
|
---|
| 102 | return EOK;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | int bd_read_toc(bd_t *bd, uint8_t session, void *buf, size_t size)
|
---|
| 106 | {
|
---|
| 107 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 108 |
|
---|
| 109 | ipc_call_t answer;
|
---|
| 110 | aid_t req = async_send_1(exch, BD_READ_TOC, session, &answer);
|
---|
| 111 | int rc = async_data_read_start(exch, buf, size);
|
---|
| 112 | async_exchange_end(exch);
|
---|
| 113 |
|
---|
| 114 | if (rc != EOK) {
|
---|
| 115 | async_forget(req);
|
---|
| 116 | return rc;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | sysarg_t retval;
|
---|
| 120 | async_wait_for(req, &retval);
|
---|
| 121 |
|
---|
| 122 | if (retval != EOK)
|
---|
| 123 | return retval;
|
---|
| 124 |
|
---|
| 125 | return EOK;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | int bd_write_blocks(bd_t *bd, aoff64_t ba, size_t cnt, const void *data,
|
---|
| 129 | size_t size)
|
---|
| 130 | {
|
---|
| 131 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 132 |
|
---|
| 133 | ipc_call_t answer;
|
---|
| 134 | aid_t req = async_send_3(exch, BD_WRITE_BLOCKS, LOWER32(ba),
|
---|
| 135 | UPPER32(ba), cnt, &answer);
|
---|
| 136 | int rc = async_data_write_start(exch, data, size);
|
---|
| 137 | async_exchange_end(exch);
|
---|
| 138 |
|
---|
| 139 | if (rc != EOK) {
|
---|
| 140 | async_forget(req);
|
---|
| 141 | return rc;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | sysarg_t retval;
|
---|
| 145 | async_wait_for(req, &retval);
|
---|
| 146 | if (retval != EOK)
|
---|
| 147 | return retval;
|
---|
| 148 |
|
---|
| 149 | return EOK;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[dd8b6a8] | 152 | int bd_sync_cache(bd_t *bd, aoff64_t ba, size_t cnt)
|
---|
| 153 | {
|
---|
| 154 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 155 |
|
---|
| 156 | int rc = async_req_3_0(exch, BD_SYNC_CACHE, LOWER32(ba),
|
---|
| 157 | UPPER32(ba), cnt);
|
---|
| 158 | async_exchange_end(exch);
|
---|
| 159 |
|
---|
| 160 | return rc;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[4802dd7] | 163 | int bd_get_block_size(bd_t *bd, size_t *rbsize)
|
---|
| 164 | {
|
---|
| 165 | sysarg_t bsize;
|
---|
| 166 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 167 |
|
---|
| 168 | int rc = async_req_0_1(exch, BD_GET_BLOCK_SIZE, &bsize);
|
---|
| 169 | async_exchange_end(exch);
|
---|
| 170 |
|
---|
| 171 | if (rc != EOK)
|
---|
| 172 | return rc;
|
---|
| 173 |
|
---|
| 174 | *rbsize = bsize;
|
---|
| 175 | return EOK;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | int bd_get_num_blocks(bd_t *bd, aoff64_t *rnb)
|
---|
| 179 | {
|
---|
| 180 | sysarg_t nb_l;
|
---|
| 181 | sysarg_t nb_h;
|
---|
| 182 | async_exch_t *exch = async_exchange_begin(bd->sess);
|
---|
| 183 |
|
---|
| 184 | int rc = async_req_0_2(exch, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
|
---|
| 185 | async_exchange_end(exch);
|
---|
| 186 |
|
---|
| 187 | if (rc != EOK)
|
---|
| 188 | return rc;
|
---|
| 189 |
|
---|
| 190 | *rnb = (aoff64_t) MERGE_LOUP32(nb_l, nb_h);
|
---|
| 191 | return EOK;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | static void bd_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
| 195 | {
|
---|
| 196 | bd_t *bd = (bd_t *)arg;
|
---|
| 197 |
|
---|
| 198 | (void)bd;
|
---|
| 199 |
|
---|
| 200 | while (true) {
|
---|
| 201 | ipc_call_t call;
|
---|
| 202 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 203 |
|
---|
| 204 | if (!IPC_GET_IMETHOD(call)) {
|
---|
| 205 | /* TODO: Handle hangup */
|
---|
| 206 | return;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | switch (IPC_GET_IMETHOD(call)) {
|
---|
| 210 | default:
|
---|
| 211 | async_answer_0(callid, ENOTSUP);
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | /** @}
|
---|
| 217 | */
|
---|