Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_ahci.c

    r58563585 r9904eb90  
    3333 */
    3434
    35 #include <as.h>
    3635#include <async.h>
    37 #include <devman.h>
    3836#include <errno.h>
    3937#include <stdio.h>
    40 #include <macros.h>
    4138#include "ahci_iface.h"
    4239#include "ddf/driver.h"
     
    5047} ahci_iface_funcs_t;
    5148
    52 #define MAX_NAME_LENGTH  1024
    53 
    5449#define LO(ptr) \
    5550        ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff))
     
    5853        ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32))
    5954
    60 async_sess_t* ahci_get_sess(devman_handle_t funh, char **name)
    61 {
    62         // FIXME: Use a better way than substring match
    63        
    64         *name = NULL;
    65        
    66         char devn[MAX_NAME_LENGTH];
    67         int rc = devman_fun_get_name(funh, devn, MAX_NAME_LENGTH);
    68         if (rc != EOK)
    69                 return NULL;
    70        
    71         size_t devn_size = str_size(devn);
    72        
    73         if ((devn_size > 5) && (str_lcmp(devn, "ahci_", 5) == 0)) {
    74                 async_sess_t *sess = devman_device_connect(funh, IPC_FLAG_BLOCKING);
    75                
    76                 if (sess) {
    77                         *name = str_dup(devn);
    78                         return sess;
    79                 }
    80         }
    81        
    82         return NULL;
    83 }
    84 
    85 int ahci_get_sata_device_name(async_sess_t *sess, size_t sata_dev_name_length,
    86     char *sata_dev_name)
    87 {
    88         async_exch_t *exch = async_exchange_begin(sess);
    89         if (!exch)
    90                 return EINVAL;
    91        
    92         aid_t req = async_send_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    93             IPC_M_AHCI_GET_SATA_DEVICE_NAME, sata_dev_name_length, NULL);
    94        
    95         async_data_read_start(exch, sata_dev_name, sata_dev_name_length);
    96        
    97         sysarg_t rc;
    98         async_wait_for(req, &rc);
    99        
    100         return rc;
    101 }
    102 
    103 int ahci_get_num_blocks(async_sess_t *sess, uint64_t *blocks)
    104 {
    105         async_exch_t *exch = async_exchange_begin(sess);
    106         if (!exch)
    107                 return EINVAL;
    108        
    109         sysarg_t blocks_hi;
    110         sysarg_t blocks_lo;
    111         int rc = async_req_1_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    112             IPC_M_AHCI_GET_NUM_BLOCKS, &blocks_hi, &blocks_lo);
    113        
    114         async_exchange_end(exch);
    115        
    116         if (rc == EOK) {
    117                 *blocks = (((uint64_t) blocks_hi) << 32)
    118                     | (((uint64_t) blocks_lo) & 0xffffffff);
    119         }
    120        
    121         return rc;
    122 }
    123 
    124 int ahci_get_block_size(async_sess_t *sess, size_t *blocks_size)
    125 {
    126         async_exch_t *exch = async_exchange_begin(sess);
    127         if (!exch)
    128                 return EINVAL;
    129        
    130         sysarg_t bs;
    131         int rc = async_req_1_1(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    132             IPC_M_AHCI_GET_BLOCK_SIZE, &bs);
    133        
    134         async_exchange_end(exch);
    135        
    136         if (rc == EOK)
    137                 *blocks_size = (size_t) bs;
    138        
    139         return rc;
    140 }
    141 
    142 int ahci_read_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
    143     void *buf)
    144 {
    145         async_exch_t *exch = async_exchange_begin(sess);
    146         if (!exch)
    147                 return EINVAL;
    148        
    149         aid_t req;
    150         req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    151             IPC_M_AHCI_READ_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    152        
    153         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    154        
    155         async_exchange_end(exch);
    156        
    157         sysarg_t rc;
    158         async_wait_for(req, &rc);
    159        
    160         return rc;
    161 }
    162 
    163 int ahci_write_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
    164     void* buf)
    165 {
    166         async_exch_t *exch = async_exchange_begin(sess);
    167         if (!exch)
    168                 return EINVAL;
    169        
    170         aid_t req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    171             IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    172        
    173         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    174        
    175         async_exchange_end(exch);
    176        
    177         sysarg_t rc;
    178         async_wait_for(req, &rc);
    179        
    180         return rc;
    181 }
    182 
    18355static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t,
    18456    ipc_call_t *);
     
    19365
    19466/** Remote AHCI interface operations. */
    195 static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
     67static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
    19668        [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name,
    19769        [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks,
     
    20375/** Remote AHCI interface structure.
    20476 */
    205 const remote_iface_t remote_ahci_iface = {
    206         .method_count = ARRAY_SIZE(remote_ahci_iface_ops),
     77remote_iface_t remote_ahci_iface = {
     78        .method_count = sizeof(remote_ahci_iface_ops) /
     79            sizeof(remote_ahci_iface_ops[0]),
    20780        .methods = remote_ahci_iface_ops
    20881};
     
    22295       
    22396        char* sata_dev_name = malloc(sata_dev_name_length);
    224         if (sata_dev_name == NULL) {
    225                 async_answer_0(callid, ENOMEM);
    226                 return;
    227         }       
    22897       
    22998        const int ret = ahci_iface->get_sata_device_name(fun,
     
    236105                async_data_read_finalize(cid, sata_dev_name, sata_dev_name_length);
    237106       
    238         free(sata_dev_name);
    239107        async_answer_0(callid, ret);
    240108}
Note: See TracChangeset for help on using the changeset viewer.