Changeset 03362fbd in mainline for uspace/srv/bd/sata_bd/sata_bd.c
- Timestamp:
- 2013-02-09T23:14:45Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 22dfd38
- Parents:
- b5d2e57 (diff), 005b765 (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
-
uspace/srv/bd/sata_bd/sata_bd.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/sata_bd/sata_bd.c
rb5d2e57 r03362fbd 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> … … 51 51 #define NAMESPACE "bd" 52 52 53 #define MAXDISKS 256 54 55 static sata_dev_t disk[MAXDISKS]; 53 /** Maximum number of disks handled */ 54 #define MAXDISKS 256 55 56 static sata_bd_dev_t disk[MAXDISKS]; 56 57 static int disk_count; 57 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 } 79 80 /** Find SATA devices in device tree. 81 * 82 * @param Device manager handle describing container for searching. 83 * 84 * @return EOK if succeed, error code otherwise. 85 * 86 */ 58 87 static int scan_device_tree(devman_handle_t funh) 59 88 { … … 74 103 75 104 ahci_get_num_blocks(disk[disk_count].sess, &disk[disk_count].blocks); 76 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 77 110 printf("Device %s - %s , blocks: %lu, block_size: %lu\n", 78 111 disk[disk_count].dev_name, disk[disk_count].sata_dev_name, … … 107 140 } 108 141 109 /** Find sata devices in device tree from root. */ 142 /** Find sata devices in device tree from root. 143 * 144 * @return EOK if succeed, error code otherwise. 145 * 146 */ 110 147 static int get_sata_disks() 111 148 { … … 129 166 static void sata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 130 167 { 131 void *fs_va = NULL;132 ipc_callid_t callid;133 ipc_call_t call;134 sysarg_t method;135 168 service_id_t dsid; 136 /* Size of the communication area. */137 size_t comm_size;138 unsigned int flags;139 int retval = 0;140 uint64_t ba;141 size_t cnt;142 169 int disk_id, i; 143 170 … … 156 183 } 157 184 158 /* Answer the IPC_M_CONNECT_ME_TO call. */159 async_answer_0(iid, EOK); 160 161 if (!async_share_out_receive(&callid, &comm_size, &flags)) { 162 async_answer_0(callid, EHANGUP); 163 return; 164 }165 166 (void) async_share_out_finalize(callid, &fs_va); 167 if (fs_va == (void *) -1) { 168 async_answer_0(callid, EHANGUP); 169 return; 170 }171 172 while (true) { 173 callid = async_get_call(&call); 174 method = IPC_GET_IMETHOD(call); 175 176 if (!method){177 /* The other side has hung up. */178 async_answer_0(callid, EOK); 179 return;180 }181 182 switch (method) {183 case BD_READ_BLOCKS: 184 ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 185 cnt = IPC_GET_ARG3(call); 186 if (cnt * disk[disk_id].block_size > comm_size) { 187 retval = ELIMIT; 188 break; 189 }190 retval = ahci_read_blocks(disk[disk_id].sess, ba, cnt, fs_va); 191 break;192 case BD_WRITE_BLOCKS:193 ba = MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 194 cnt = IPC_GET_ARG3(call);195 if (cnt * disk[disk_id].block_size > comm_size) { 196 retval = ELIMIT; 197 break; 198 } 199 retval = ahci_write_blocks(disk[disk_id].sess, ba, cnt, fs_va); 200 break;201 case BD_GET_BLOCK_SIZE: 202 async_answer_1(callid, EOK, disk[disk_id].block_size);203 continue;204 case BD_GET_NUM_BLOCKS: 205 async_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks), 206 UPPER32(disk[disk_id].blocks)); 207 break; 208 default: 209 retval = EINVAL;210 break; 211 }212 async_answer_0(callid, retval);213 }214 } 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 215 242 216 243 int main(int argc, char **argv)
Note:
See TracChangeset
for help on using the changeset viewer.
