Ignore:
File:
1 edited

Legend:

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

    r7f620e8 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(EXCHANGE_PARALLEL,
    75                     funh, IPC_FLAG_BLOCKING);
    76                
    77                 if (sess) {
    78                         *name = str_dup(devn);
    79                         return sess;
    80                 }
    81         }
    82        
    83         return NULL;
    84 }
    85 
    86 int ahci_get_sata_device_name(async_sess_t *sess, size_t sata_dev_name_length,
    87     char *sata_dev_name)
    88 {
    89         async_exch_t *exch = async_exchange_begin(sess);
    90         if (!exch)
    91                 return EINVAL;
    92        
    93         aid_t req = async_send_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    94             IPC_M_AHCI_GET_SATA_DEVICE_NAME, sata_dev_name_length, NULL);
    95        
    96         async_data_read_start(exch, sata_dev_name, sata_dev_name_length);
    97        
    98         sysarg_t rc;
    99         async_wait_for(req, &rc);
    100        
    101         return rc;
    102 }
    103 
    104 int ahci_get_num_blocks(async_sess_t *sess, uint64_t *blocks)
    105 {
    106         async_exch_t *exch = async_exchange_begin(sess);
    107         if (!exch)
    108                 return EINVAL;
    109        
    110         sysarg_t blocks_hi;
    111         sysarg_t blocks_lo;
    112         int rc = async_req_1_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    113             IPC_M_AHCI_GET_NUM_BLOCKS, &blocks_hi, &blocks_lo);
    114        
    115         async_exchange_end(exch);
    116        
    117         if (rc == EOK) {
    118                 *blocks = (((uint64_t) blocks_hi) << 32)
    119                     | (((uint64_t) blocks_lo) & 0xffffffff);
    120         }
    121        
    122         return rc;
    123 }
    124 
    125 int ahci_get_block_size(async_sess_t *sess, size_t *blocks_size)
    126 {
    127         async_exch_t *exch = async_exchange_begin(sess);
    128         if (!exch)
    129                 return EINVAL;
    130        
    131         sysarg_t bs;
    132         int rc = async_req_1_1(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    133             IPC_M_AHCI_GET_BLOCK_SIZE, &bs);
    134        
    135         async_exchange_end(exch);
    136        
    137         if (rc == EOK)
    138                 *blocks_size = (size_t) bs;
    139        
    140         return rc;
    141 }
    142 
    143 int ahci_read_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
    144     void *buf)
    145 {
    146         async_exch_t *exch = async_exchange_begin(sess);
    147         if (!exch)
    148                 return EINVAL;
    149        
    150         aid_t req;
    151         req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    152             IPC_M_AHCI_READ_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    153        
    154         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    155        
    156         async_exchange_end(exch);
    157        
    158         sysarg_t rc;
    159         async_wait_for(req, &rc);
    160        
    161         return rc;
    162 }
    163 
    164 int ahci_write_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
    165     void* buf)
    166 {
    167         async_exch_t *exch = async_exchange_begin(sess);
    168         if (!exch)
    169                 return EINVAL;
    170        
    171         aid_t req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
    172             IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
    173        
    174         async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
    175        
    176         async_exchange_end(exch);
    177        
    178         sysarg_t rc;
    179         async_wait_for(req, &rc);
    180        
    181         return rc;
    182 }
    183 
    18455static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t,
    18556    ipc_call_t *);
     
    19465
    19566/** Remote AHCI interface operations. */
    196 static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
     67static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
    19768        [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name,
    19869        [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks,
     
    20475/** Remote AHCI interface structure.
    20576 */
    206 const remote_iface_t remote_ahci_iface = {
    207         .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]),
    20880        .methods = remote_ahci_iface_ops
    20981};
Note: See TracChangeset for help on using the changeset viewer.