Changes in uspace/drv/block/ahci/ahci.c [5c55eb7:60744cb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
r5c55eb7 r60744cb 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda3 2 * Copyright (c) 2012 Petr Jerman 4 3 * All rights reserved. … … 33 32 34 33 #include <as.h> 35 #include <bd_srv.h>36 34 #include <errno.h> 37 35 #include <stdio.h> … … 41 39 #include <device/hw_res_parsed.h> 42 40 #include <pci_dev_iface.h> 41 #include <ahci_iface.h> 43 42 #include "ahci.h" 44 43 #include "ahci_hw.h" … … 110 109 } 111 110 112 static errno_t ahci_read_blocks(sata_dev_t *, uint64_t, size_t, void *); 113 static errno_t ahci_write_blocks(sata_dev_t *, uint64_t, size_t, void *); 111 static errno_t get_sata_device_name(ddf_fun_t *, size_t, char *); 112 static errno_t get_num_blocks(ddf_fun_t *, uint64_t *); 113 static errno_t get_block_size(ddf_fun_t *, size_t *); 114 static errno_t read_blocks(ddf_fun_t *, uint64_t, size_t, void *); 115 static errno_t write_blocks(ddf_fun_t *, uint64_t, size_t, void *); 114 116 115 117 static errno_t ahci_identify_device(sata_dev_t *); … … 129 131 static int sata_devices_count = 0; 130 132 131 static errno_t ahci_bd_open(bd_srvs_t *, bd_srv_t *); 132 static errno_t ahci_bd_close(bd_srv_t *); 133 static errno_t ahci_bd_read_blocks(bd_srv_t *, aoff64_t, size_t, void *, size_t); 134 static errno_t ahci_bd_write_blocks(bd_srv_t *, aoff64_t, size_t, const void *, size_t); 135 static errno_t ahci_bd_get_block_size(bd_srv_t *, size_t *); 136 static errno_t ahci_bd_get_num_blocks(bd_srv_t *, aoff64_t *); 137 138 static void ahci_bd_connection(ipc_call_t *, void *); 139 140 static bd_ops_t ahci_bd_ops = { 141 .open = ahci_bd_open, 142 .close = ahci_bd_close, 143 .read_blocks = ahci_bd_read_blocks, 144 .write_blocks = ahci_bd_write_blocks, 145 .get_block_size = ahci_bd_get_block_size, 146 .get_num_blocks = ahci_bd_get_num_blocks 133 /* 134 * AHCI Interface 135 */ 136 137 static ahci_iface_t ahci_interface = { 138 .get_sata_device_name = &get_sata_device_name, 139 .get_num_blocks = &get_num_blocks, 140 .get_block_size = &get_block_size, 141 .read_blocks = &read_blocks, 142 .write_blocks = &write_blocks 143 }; 144 145 static ddf_dev_ops_t ahci_ops = { 146 .interfaces[AHCI_DEV_IFACE] = &ahci_interface 147 147 }; 148 148 … … 156 156 }; 157 157 158 /** Get SATA structure from block device service structure. */ 159 static sata_dev_t *bd_srv_sata(bd_srv_t *bd) 160 { 161 return (sata_dev_t *) bd->srvs->sarg; 162 } 163 164 /** Read data blocks from SATA device. 165 * 166 * @param sata SATA device 158 /** Get SATA structure from DDF function. */ 159 static sata_dev_t *fun_sata_dev(ddf_fun_t *fun) 160 { 161 return ddf_fun_data_get(fun); 162 } 163 164 /** Get SATA device name. 165 * 166 * @param fun Device function handling the call. 167 * @param sata_dev_name_length Length of the sata_dev_name buffer. 168 * @param sata_dev_name Buffer for SATA device name. 169 * 170 * @return EOK. 171 * 172 */ 173 static errno_t get_sata_device_name(ddf_fun_t *fun, 174 size_t sata_dev_name_length, char *sata_dev_name) 175 { 176 sata_dev_t *sata = fun_sata_dev(fun); 177 str_cpy(sata_dev_name, sata_dev_name_length, sata->model); 178 return EOK; 179 } 180 181 /** Get Number of blocks in SATA device. 182 * 183 * @param fun Device function handling the call. 184 * @param blocks Return number of blocks in SATA device. 185 * 186 * @return EOK. 187 * 188 */ 189 static errno_t get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks) 190 { 191 sata_dev_t *sata = fun_sata_dev(fun); 192 *num_blocks = sata->blocks; 193 return EOK; 194 } 195 196 /** Get SATA device block size. 197 * 198 * @param fun Device function handling the call. 199 * @param block_size Return block size. 200 * 201 * @return EOK. 202 * 203 */ 204 static errno_t get_block_size(ddf_fun_t *fun, size_t *block_size) 205 { 206 sata_dev_t *sata = fun_sata_dev(fun); 207 *block_size = sata->block_size; 208 return EOK; 209 } 210 211 /** Read data blocks into SATA device. 212 * 213 * @param fun Device function handling the call. 167 214 * @param blocknum Number of first block. 168 215 * @param count Number of blocks to read. 169 216 * @param buf Buffer for data. 170 217 * 171 * @return EOK on success, error code otherwise172 * 173 */ 174 static errno_t ahci_read_blocks(sata_dev_t *sata, uint64_t blocknum,218 * @return EOK if succeed, error code otherwise 219 * 220 */ 221 static errno_t read_blocks(ddf_fun_t *fun, uint64_t blocknum, 175 222 size_t count, void *buf) 176 223 { 224 sata_dev_t *sata = fun_sata_dev(fun); 225 177 226 uintptr_t phys; 178 227 void *ibuf = AS_AREA_ANY; … … 203 252 } 204 253 205 /** Write data blocks to SATA device.206 * 207 * @param sata SATA device254 /** Write data blocks into SATA device. 255 * 256 * @param fun Device function handling the call. 208 257 * @param blocknum Number of first block. 209 258 * @param count Number of blocks to write. 210 259 * @param buf Buffer with data. 211 260 * 212 * @return EOK on success, error code otherwise 213 */ 214 static errno_t ahci_write_blocks(sata_dev_t *sata, uint64_t blocknum, 261 * @return EOK if succeed, error code otherwise 262 * 263 */ 264 static errno_t write_blocks(ddf_fun_t *fun, uint64_t blocknum, 215 265 size_t count, void *buf) 216 266 { 267 sata_dev_t *sata = fun_sata_dev(fun); 268 217 269 uintptr_t phys; 218 270 void *ibuf = AS_AREA_ANY; … … 238 290 239 291 return rc; 240 }241 242 /** Open device. */243 static errno_t ahci_bd_open(bd_srvs_t *bds, bd_srv_t *bd)244 {245 return EOK;246 }247 248 /** Close device. */249 static errno_t ahci_bd_close(bd_srv_t *bd)250 {251 return EOK;252 }253 254 /** Read blocks from partition. */255 static errno_t ahci_bd_read_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,256 void *buf, size_t size)257 {258 sata_dev_t *sata = bd_srv_sata(bd);259 260 if (size < cnt * sata->block_size)261 return EINVAL;262 263 return ahci_read_blocks(sata, ba, cnt, buf);264 }265 266 /** Write blocks to partition. */267 static errno_t ahci_bd_write_blocks(bd_srv_t *bd, aoff64_t ba, size_t cnt,268 const void *buf, size_t size)269 {270 sata_dev_t *sata = bd_srv_sata(bd);271 272 if (size < cnt * sata->block_size)273 return EINVAL;274 275 return ahci_write_blocks(sata, ba, cnt, (void *)buf);276 }277 278 /** Get device block size. */279 static errno_t ahci_bd_get_block_size(bd_srv_t *bd, size_t *rsize)280 {281 sata_dev_t *sata = bd_srv_sata(bd);282 283 *rsize = sata->block_size;284 return EOK;285 }286 287 /** Get number of blocks on device. */288 static errno_t ahci_bd_get_num_blocks(bd_srv_t *bd, aoff64_t *rnb)289 {290 sata_dev_t *sata = bd_srv_sata(bd);291 292 *rnb = sata->blocks;293 return EOK;294 }295 296 static void ahci_bd_connection(ipc_call_t *icall, void *arg)297 {298 sata_dev_t *sata;299 300 sata = (sata_dev_t *) ddf_fun_data_get((ddf_fun_t *)arg);301 bd_conn(icall, &sata->bds);302 292 } 303 293 … … 425 415 * @param sata SATA device structure. 426 416 * 427 * @return EOK on success, error code otherwise.417 * @return EOK if succeed, error code otherwise. 428 418 * 429 419 */ … … 606 596 * @param sata SATA device structure. 607 597 * 608 * @return EOK on success, error code otherwise598 * @return EOK if succeed, error code otherwise 609 599 * 610 600 */ … … 735 725 * @param blocknum Block number to read. 736 726 * 737 * @return EOK on success, error code otherwise727 * @return EOK if succeed, error code otherwise 738 728 * 739 729 */ … … 764 754 * @param blocknum Block number to write. 765 755 * 766 * @return EOK on success, error code otherwise756 * @return EOK if succeed, error code otherwise 767 757 * 768 758 */ … … 823 813 * @param blocknum Block number to write. 824 814 * 825 * @return EOK on success, error code otherwise815 * @return EOK if succeed, error code otherwise 826 816 * 827 817 */ … … 930 920 * @param port AHCI port structure 931 921 * 932 * @return SATA device structure on success, NULL otherwise.922 * @return SATA device structure if succeed, NULL otherwise. 933 923 * 934 924 */ … … 1038 1028 * @param port_num Number of AHCI port with existing SATA device. 1039 1029 * 1040 * @return EOK on success, error code otherwise.1030 * @return EOK if succeed, error code otherwise. 1041 1031 * 1042 1032 */ … … 1045 1035 { 1046 1036 ddf_fun_t *fun = NULL; 1047 bool bound = false;1048 1037 errno_t rc; 1049 1038 … … 1086 1075 } 1087 1076 1088 fun = sata->fun; 1089 1090 bd_srvs_init(&sata->bds); 1091 sata->bds.ops = &ahci_bd_ops; 1092 sata->bds.sarg = (void *)sata; 1093 1094 /* Set up a connection handler. */ 1095 ddf_fun_set_conn_handler(fun, ahci_bd_connection); 1096 1097 ddf_msg(LVL_NOTE, "Device %s - %s, blocks: %" PRIu64 1098 " block_size: %zu\n", sata_dev_name, sata->model, sata->blocks, 1099 sata->block_size); 1077 ddf_fun_set_ops(fun, &ahci_ops); 1100 1078 1101 1079 rc = ddf_fun_bind(fun); … … 1105 1083 } 1106 1084 1107 bound = true;1108 1109 rc = ddf_fun_add_to_category(fun, "disk");1110 if (rc != EOK) {1111 ddf_msg(LVL_ERROR, "Failed adding function %s to category "1112 "'disk'.", sata_dev_name);1113 goto error;1114 }1115 1116 1085 return EOK; 1117 1086 1118 1087 error: 1119 if (bound)1120 ddf_fun_unbind(fun);1121 1088 sata->is_invalid_device = true; 1122 1089 if (fun != NULL) … … 1155 1122 * @param dev DDF device structure. 1156 1123 * 1157 * @return AHCI device structure on success, NULL otherwise.1124 * @return AHCI device structure if succeed, NULL otherwise. 1158 1125 * 1159 1126 */ … … 1279 1246 * @param dev DDF device structure. 1280 1247 * 1281 * @return EOK on success, error code otherwise.1248 * @return EOK if succeed, error code otherwise. 1282 1249 * 1283 1250 */
Note:
See TracChangeset
for help on using the changeset viewer.