Changeset 5c55eb7 in mainline
- Timestamp:
- 2025-06-10T09:39:41Z (5 days ago)
- Branches:
- master
- Children:
- c44b399
- Parents:
- 0f5c4e4
- git-author:
- Jiri Svoboda <jiri@…> (2025-06-09 17:39:30)
- git-committer:
- Jiri Svoboda <jiri@…> (2025-06-10 09:39:41)
- Location:
- uspace
- Files:
-
- 6 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
r0f5c4e4 r5c55eb7 33 33 34 34 #include <as.h> 35 #include <bd_srv.h> 35 36 #include <errno.h> 36 37 #include <stdio.h> … … 40 41 #include <device/hw_res_parsed.h> 41 42 #include <pci_dev_iface.h> 42 #include <ahci_iface.h>43 43 #include "ahci.h" 44 44 #include "ahci_hw.h" … … 110 110 } 111 111 112 static errno_t get_sata_device_name(ddf_fun_t *, size_t, char *); 113 static errno_t get_num_blocks(ddf_fun_t *, uint64_t *); 114 static errno_t get_block_size(ddf_fun_t *, size_t *); 115 static errno_t read_blocks(ddf_fun_t *, uint64_t, size_t, void *); 116 static errno_t write_blocks(ddf_fun_t *, uint64_t, size_t, void *); 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 *); 117 114 118 115 static errno_t ahci_identify_device(sata_dev_t *); … … 132 129 static int sata_devices_count = 0; 133 130 134 /* 135 * AHCI Interface 136 */ 137 138 static ahci_iface_t ahci_interface = { 139 .get_sata_device_name = &get_sata_device_name, 140 .get_num_blocks = &get_num_blocks, 141 .get_block_size = &get_block_size, 142 .read_blocks = &read_blocks, 143 .write_blocks = &write_blocks 144 }; 145 146 static ddf_dev_ops_t ahci_ops = { 147 .interfaces[AHCI_DEV_IFACE] = &ahci_interface 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 148 147 }; 149 148 … … 157 156 }; 158 157 159 /** Get SATA structure from DDF function. */ 160 static sata_dev_t *fun_sata_dev(ddf_fun_t *fun) 161 { 162 return ddf_fun_data_get(fun); 163 } 164 165 /** Get SATA device name. 166 * 167 * @param fun Device function handling the call. 168 * @param sata_dev_name_length Length of the sata_dev_name buffer. 169 * @param sata_dev_name Buffer for SATA device name. 170 * 171 * @return EOK. 172 * 173 */ 174 static errno_t get_sata_device_name(ddf_fun_t *fun, 175 size_t sata_dev_name_length, char *sata_dev_name) 176 { 177 sata_dev_t *sata = fun_sata_dev(fun); 178 str_cpy(sata_dev_name, sata_dev_name_length, sata->model); 179 return EOK; 180 } 181 182 /** Get Number of blocks in SATA device. 183 * 184 * @param fun Device function handling the call. 185 * @param blocks Return number of blocks in SATA device. 186 * 187 * @return EOK. 188 * 189 */ 190 static errno_t get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks) 191 { 192 sata_dev_t *sata = fun_sata_dev(fun); 193 *num_blocks = sata->blocks; 194 return EOK; 195 } 196 197 /** Get SATA device block size. 198 * 199 * @param fun Device function handling the call. 200 * @param block_size Return block size. 201 * 202 * @return EOK. 203 * 204 */ 205 static errno_t get_block_size(ddf_fun_t *fun, size_t *block_size) 206 { 207 sata_dev_t *sata = fun_sata_dev(fun); 208 *block_size = sata->block_size; 209 return EOK; 210 } 211 212 /** Read data blocks into SATA device. 213 * 214 * @param fun Device function handling the call. 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 215 167 * @param blocknum Number of first block. 216 168 * @param count Number of blocks to read. 217 169 * @param buf Buffer for data. 218 170 * 219 * @return EOK if succeed, error code otherwise220 * 221 */ 222 static errno_t read_blocks(ddf_fun_t *fun, uint64_t blocknum,171 * @return EOK on success, error code otherwise 172 * 173 */ 174 static errno_t ahci_read_blocks(sata_dev_t *sata, uint64_t blocknum, 223 175 size_t count, void *buf) 224 176 { 225 sata_dev_t *sata = fun_sata_dev(fun);226 227 177 uintptr_t phys; 228 178 void *ibuf = AS_AREA_ANY; … … 253 203 } 254 204 255 /** Write data blocks into SATA device.256 * 257 * @param fun Device function handling the call.205 /** Write data blocks to SATA device. 206 * 207 * @param sata SATA device 258 208 * @param blocknum Number of first block. 259 209 * @param count Number of blocks to write. 260 210 * @param buf Buffer with data. 261 211 * 262 * @return EOK if succeed, error code otherwise 263 * 264 */ 265 static errno_t write_blocks(ddf_fun_t *fun, uint64_t blocknum, 212 * @return EOK on success, error code otherwise 213 */ 214 static errno_t ahci_write_blocks(sata_dev_t *sata, uint64_t blocknum, 266 215 size_t count, void *buf) 267 216 { 268 sata_dev_t *sata = fun_sata_dev(fun);269 270 217 uintptr_t phys; 271 218 void *ibuf = AS_AREA_ANY; … … 291 238 292 239 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); 293 302 } 294 303 … … 416 425 * @param sata SATA device structure. 417 426 * 418 * @return EOK if succeed, error code otherwise.427 * @return EOK on success, error code otherwise. 419 428 * 420 429 */ … … 597 606 * @param sata SATA device structure. 598 607 * 599 * @return EOK if succeed, error code otherwise608 * @return EOK on success, error code otherwise 600 609 * 601 610 */ … … 726 735 * @param blocknum Block number to read. 727 736 * 728 * @return EOK if succeed, error code otherwise737 * @return EOK on success, error code otherwise 729 738 * 730 739 */ … … 755 764 * @param blocknum Block number to write. 756 765 * 757 * @return EOK if succeed, error code otherwise766 * @return EOK on success, error code otherwise 758 767 * 759 768 */ … … 814 823 * @param blocknum Block number to write. 815 824 * 816 * @return EOK if succeed, error code otherwise825 * @return EOK on success, error code otherwise 817 826 * 818 827 */ … … 921 930 * @param port AHCI port structure 922 931 * 923 * @return SATA device structure if succeed, NULL otherwise.932 * @return SATA device structure on success, NULL otherwise. 924 933 * 925 934 */ … … 1029 1038 * @param port_num Number of AHCI port with existing SATA device. 1030 1039 * 1031 * @return EOK if succeed, error code otherwise.1040 * @return EOK on success, error code otherwise. 1032 1041 * 1033 1042 */ … … 1036 1045 { 1037 1046 ddf_fun_t *fun = NULL; 1047 bool bound = false; 1038 1048 errno_t rc; 1039 1049 … … 1077 1087 1078 1088 fun = sata->fun; 1079 ddf_fun_set_ops(fun, &ahci_ops); 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); 1080 1100 1081 1101 rc = ddf_fun_bind(fun); … … 1085 1105 } 1086 1106 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 1087 1116 return EOK; 1088 1117 1089 1118 error: 1119 if (bound) 1120 ddf_fun_unbind(fun); 1090 1121 sata->is_invalid_device = true; 1091 1122 if (fun != NULL) … … 1124 1155 * @param dev DDF device structure. 1125 1156 * 1126 * @return AHCI device structure if succeed, NULL otherwise.1157 * @return AHCI device structure on success, NULL otherwise. 1127 1158 * 1128 1159 */ … … 1248 1279 * @param dev DDF device structure. 1249 1280 * 1250 * @return EOK if succeed, error code otherwise.1281 * @return EOK on success, error code otherwise. 1251 1282 * 1252 1283 */ -
uspace/drv/block/ahci/ahci.h
r0f5c4e4 r5c55eb7 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2012 Petr Jerman 3 4 * All rights reserved. … … 31 32 */ 32 33 33 #ifndef __AHCI_H__34 #define __AHCI_H__34 #ifndef AHCI_H 35 #define AHCI_H 35 36 36 37 #include <async.h> 38 #include <bd_srv.h> 37 39 #include <ddf/interrupt.h> 38 40 #include <stdio.h> … … 105 107 /** Highest UDMA mode supported. */ 106 108 uint8_t highest_udma_mode; 109 110 /** Block device service structure */ 111 bd_srvs_t bds; 107 112 } sata_dev_t; 108 113 -
uspace/drv/block/ahci/ahci_hw.h
r0f5c4e4 r5c55eb7 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2012 Petr Jerman 3 4 * All rights reserved. … … 31 32 */ 32 33 33 #ifndef __AHCI_HW_H__34 #define __AHCI_HW_H__34 #ifndef AHCI_HW_H 35 #define AHCI_HW_H 35 36 36 37 #include <stdint.h> -
uspace/drv/block/ahci/ahci_sata.h
r0f5c4e4 r5c55eb7 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2012 Petr Jerman 3 4 * All rights reserved. … … 31 32 */ 32 33 33 #ifndef __AHCI_SATA_H__34 #define __AHCI_SATA_H__34 #ifndef AHCI_SATA_H 35 #define AHCI_SATA_H 35 36 36 37 #include <stdint.h> -
uspace/lib/drv/generic/dev_iface.c
r0f5c4e4 r5c55eb7 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 4 * All rights reserved. … … 53 54 #include "remote_audio_mixer.h" 54 55 #include "remote_audio_pcm.h" 55 #include "remote_ahci.h"56 56 57 57 static const iface_dipatch_table_t remote_ifaces = { … … 71 71 [LED_DEV_IFACE] = &remote_led_dev_iface, 72 72 [BATTERY_DEV_IFACE] = &remote_battery_dev_iface, 73 [AHCI_DEV_IFACE] = &remote_ahci_iface,74 73 } 75 74 }; -
uspace/lib/drv/meson.build
r0f5c4e4 r5c55eb7 1 1 # 2 # Copyright (c) 2025 Jiri Svoboda 2 3 # Copyright (c) 2005 Martin Decky 3 4 # Copyright (c) 2007 Jakub Jermar … … 50 51 'generic/remote_led_dev.c', 51 52 'generic/remote_battery_dev.c', 52 'generic/remote_ahci.c',53 53 ) -
uspace/srv/meson.build
r0f5c4e4 r5c55eb7 1 1 # 2 # Copyright (c) 202 4Jiri Svoboda2 # Copyright (c) 2025 Jiri Svoboda 3 3 # Copyright (c) 2019 Jiří Zárevúcky 4 4 # All rights reserved. … … 32 32 'bd/file_bd', 33 33 'bd/rd', 34 'bd/sata_bd',35 34 'bd/vbd', 36 35 'clipboard',
Note:
See TracChangeset
for help on using the changeset viewer.