Changeset affaf2e in mainline for uspace/srv/bd/sata_bd/sata_bd.c
- Timestamp:
- 2012-08-15T15:13:20Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b546231
- Parents:
- f66ca57f (diff), 135486d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/sata_bd/sata_bd.c
rf66ca57f raffaf2e 38 38 39 39 #include <sys/types.h> 40 #include <bd_srv.h> 40 41 #include <errno.h> 41 42 #include <stdio.h> 42 #include <ipc/bd.h>43 43 #include <str.h> 44 44 #include <loc.h> … … 56 56 static sata_bd_dev_t disk[MAXDISKS]; 57 57 static int disk_count; 58 59 static int sata_bd_open(bd_srvs_t *, bd_srv_t *); 60 static int sata_bd_close(bd_srv_t *); 61 static int sata_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t); 62 static int sata_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t); 63 static int sata_bd_get_block_size(bd_srv_t *, size_t *); 64 static int sata_bd_get_num_blocks(bd_srv_t *, aoff64_t *); 65 66 static 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 75 static sata_bd_dev_t *bd_srv_sata(bd_srv_t *bd) 76 { 77 return (sata_bd_dev_t *)bd->srvs->sarg; 78 } 58 79 59 80 /** Find SATA devices in device tree. … … 82 103 83 104 ahci_get_num_blocks(disk[disk_count].sess, &disk[disk_count].blocks); 84 105 106 bd_srvs_init(&disk[disk_count].bds); 107 disk[disk_count].bds.ops = &sata_bd_ops; 108 disk[disk_count].bds.sarg = &disk[disk_count]; 109 85 110 printf("Device %s - %s , blocks: %lu, block_size: %lu\n", 86 111 disk[disk_count].dev_name, disk[disk_count].sata_dev_name, … … 141 166 static void sata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 142 167 { 143 void *fs_va = NULL;144 ipc_callid_t callid;145 ipc_call_t call;146 sysarg_t method;147 168 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;154 169 int disk_id, i; 155 170 … … 168 183 } 169 184 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].bds); 186 } 187 188 /** Open device. */ 189 static int sata_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 190 { 191 return EOK; 192 } 193 194 /** Close device. */ 195 static int sata_bd_close(bd_srv_t *bd) 196 { 197 return EOK; 198 } 199 200 /** Read blocks from partition. */ 201 static 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. */ 213 static 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. */ 225 static 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. */ 234 static 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 227 242 228 243 int main(int argc, char **argv)
Note:
See TracChangeset
for help on using the changeset viewer.