Changes in uspace/lib/drv/generic/remote_ahci.c [9904eb90:58563585] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_ahci.c
r9904eb90 r58563585 33 33 */ 34 34 35 #include <as.h> 35 36 #include <async.h> 37 #include <devman.h> 36 38 #include <errno.h> 37 39 #include <stdio.h> 40 #include <macros.h> 38 41 #include "ahci_iface.h" 39 42 #include "ddf/driver.h" … … 47 50 } ahci_iface_funcs_t; 48 51 52 #define MAX_NAME_LENGTH 1024 53 49 54 #define LO(ptr) \ 50 55 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff)) … … 53 58 ((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32)) 54 59 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 55 183 static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t, 56 184 ipc_call_t *); … … 65 193 66 194 /** Remote AHCI interface operations. */ 67 static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {195 static const remote_iface_func_ptr_t remote_ahci_iface_ops [] = { 68 196 [IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name, 69 197 [IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks, … … 75 203 /** Remote AHCI interface structure. 76 204 */ 77 remote_iface_t remote_ahci_iface = { 78 .method_count = sizeof(remote_ahci_iface_ops) / 79 sizeof(remote_ahci_iface_ops[0]), 205 const remote_iface_t remote_ahci_iface = { 206 .method_count = ARRAY_SIZE(remote_ahci_iface_ops), 80 207 .methods = remote_ahci_iface_ops 81 208 }; … … 95 222 96 223 char* sata_dev_name = malloc(sata_dev_name_length); 224 if (sata_dev_name == NULL) { 225 async_answer_0(callid, ENOMEM); 226 return; 227 } 97 228 98 229 const int ret = ahci_iface->get_sata_device_name(fun, … … 105 236 async_data_read_finalize(cid, sata_dev_name, sata_dev_name_length); 106 237 238 free(sata_dev_name); 107 239 async_answer_0(callid, ret); 108 240 }
Note:
See TracChangeset
for help on using the changeset viewer.