Changeset 4802dd7 in mainline for uspace/srv/bd/sata_bd/sata_bd.c


Ignore:
Timestamp:
2012-08-13T22:01:04Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
135486d, 71b0d4d4, 9dec6d4, cddcc4a3
Parents:
4820360
Message:

Factor out client and server IPC stubs for block devices.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/sata_bd/sata_bd.c

    r4820360 r4802dd7  
    3838
    3939#include <sys/types.h>
     40#include <bd_srv.h>
    4041#include <errno.h>
    4142#include <stdio.h>
    42 #include <ipc/bd.h>
    4343#include <str.h>
    4444#include <loc.h>
     
    5656static sata_bd_dev_t disk[MAXDISKS];
    5757static int disk_count;
     58
     59static int sata_bd_open(bd_srv_t *);
     60static int sata_bd_close(bd_srv_t *);
     61static int sata_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t);
     62static int sata_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t);
     63static int sata_bd_get_block_size(bd_srv_t *, size_t *);
     64static int sata_bd_get_num_blocks(bd_srv_t *, aoff64_t *);
     65
     66static bd_ops_t sata_bd_ops = {
     67        .open = sata_bd_open,
     68        .close = sata_bd_close,
     69        .read_blocks = sata_bd_read_blocks,
     70        .write_blocks = sata_bd_write_blocks,
     71        .get_block_size = sata_bd_get_block_size,
     72        .get_num_blocks = sata_bd_get_num_blocks
     73};
     74
     75static sata_bd_dev_t *bd_srv_sata(bd_srv_t *bd)
     76{
     77        return (sata_bd_dev_t *)bd->arg;
     78}
    5879
    5980/** Find SATA devices in device tree.
     
    82103               
    83104                ahci_get_num_blocks(disk[disk_count].sess, &disk[disk_count].blocks);
    84                                
     105               
     106                bd_srv_init(&disk[disk_count].bd);
     107                disk[disk_count].bd.ops = &sata_bd_ops;
     108                disk[disk_count].bd.arg = &disk[disk_count];
     109               
    85110                printf("Device %s - %s , blocks: %lu, block_size: %lu\n",
    86111                    disk[disk_count].dev_name, disk[disk_count].sata_dev_name,
     
    141166static void sata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    142167{
    143         void *fs_va = NULL;
    144         ipc_callid_t callid;
    145         ipc_call_t call;
    146         sysarg_t method;
    147168        service_id_t dsid;
    148         /* Size of the communication area. */
    149         size_t comm_size;       
    150         unsigned int flags;
    151         int retval = 0;
    152         uint64_t ba;
    153         size_t cnt;
    154169        int disk_id, i;
    155170
     
    168183        }
    169184
    170         /* Answer the IPC_M_CONNECT_ME_TO call. */
    171         async_answer_0(iid, EOK);
    172 
    173         if (!async_share_out_receive(&callid, &comm_size, &flags)) {
    174                 async_answer_0(callid, EHANGUP);
    175                 return;
    176         }
    177 
    178         (void) async_share_out_finalize(callid, &fs_va);
    179         if (fs_va == (void *) -1) {
    180                 async_answer_0(callid, EHANGUP);
    181                 return;
    182         }
    183 
    184         while (true) {
    185                 callid = async_get_call(&call);
    186                 method = IPC_GET_IMETHOD(call);
    187                
    188                 if (!method) {
    189                         /* The other side has hung up. */
    190                         async_answer_0(callid, EOK);
    191                         return;
    192                 }
    193                
    194                 switch (method) {
    195                         case BD_READ_BLOCKS:
    196                                 ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    197                                 cnt = IPC_GET_ARG3(call);
    198                                 if (cnt * disk[disk_id].block_size > comm_size) {
    199                                         retval = ELIMIT;
    200                                         break;
    201                                 }
    202                                 retval = ahci_read_blocks(disk[disk_id].sess, ba, cnt, fs_va);
    203                                 break;
    204                         case BD_WRITE_BLOCKS:
    205                                 ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
    206                                 cnt = IPC_GET_ARG3(call);
    207                                 if (cnt * disk[disk_id].block_size > comm_size) {
    208                                         retval = ELIMIT;
    209                                         break;
    210                                 }
    211                                 retval = ahci_write_blocks(disk[disk_id].sess, ba, cnt, fs_va);
    212                                 break;
    213                         case BD_GET_BLOCK_SIZE:
    214                                 async_answer_1(callid, EOK, disk[disk_id].block_size);
    215                                 continue;
    216                         case BD_GET_NUM_BLOCKS:
    217                                 async_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),
    218                                     UPPER32(disk[disk_id].blocks));
    219                                 break;
    220                         default:
    221                                 retval = EINVAL;
    222                                 break;
    223                         }
    224                 async_answer_0(callid, retval);
    225         }
    226 }
     185        bd_conn(iid, icall, &disk[disk_id].bd);
     186}
     187
     188/** Open device. */
     189static int sata_bd_open(bd_srv_t *bd)
     190{
     191        return EOK;
     192}
     193
     194/** Close device. */
     195static int sata_bd_close(bd_srv_t *bd)
     196{
     197        return EOK;
     198}
     199
     200/** Read blocks from partition. */
     201static int sata_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt, void *buf,
     202    size_t size)
     203{
     204        sata_bd_dev_t *sbd = bd_srv_sata(bd);
     205
     206        if (size < cnt * sbd->block_size)
     207                return EINVAL;
     208
     209        return ahci_read_blocks(sbd->sess, ba, cnt, buf);
     210}
     211
     212/** Write blocks to partition. */
     213static int sata_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,
     214    const void *buf, size_t size)
     215{
     216        sata_bd_dev_t *sbd = bd_srv_sata(bd);
     217
     218        if (size < cnt * sbd->block_size)
     219                return EINVAL;
     220
     221        return ahci_write_blocks(sbd->sess, ba, cnt, (void *)buf);
     222}
     223
     224/** Get device block size. */
     225static int sata_bd_get_block_size(bd_srv_t *bd, size_t *rsize)
     226{
     227        sata_bd_dev_t *sbd = bd_srv_sata(bd);
     228
     229        *rsize = sbd->block_size;
     230        return EOK;
     231}
     232
     233/** Get number of blocks on device. */
     234static int sata_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)
     235{
     236        sata_bd_dev_t *sbd = bd_srv_sata(bd);
     237
     238        *rnb = sbd->blocks;
     239        return EOK;
     240}
     241
    227242
    228243int main(int argc, char **argv)
Note: See TracChangeset for help on using the changeset viewer.