Changes in uspace/drv/block/ahci/ahci.c [f9b2cb4c:acdb5bac] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
rf9b2cb4c racdb5bac 37 37 #include <ddf/log.h> 38 38 #include <device/hw_res_parsed.h> 39 #include <pci_dev_iface.h> 40 #include <irc.h> 39 #include <device/pci.h> 40 #include <sysinfo.h> 41 #include <ipc/irc.h> 42 #include <ns.h> 41 43 #include <ahci_iface.h> 42 44 #include "ahci.h" … … 109 111 } 110 112 111 static int get_sata_device_name(ddf_fun_t *, size_t, char *);112 static int get_num_blocks(ddf_fun_t *, uint64_t *);113 static int get_block_size(ddf_fun_t *, size_t *);114 static int read_blocks(ddf_fun_t *, uint64_t, size_t, void *);115 static int write_blocks(ddf_fun_t *, uint64_t, size_t, void *);113 static int ahci_get_sata_device_name(ddf_fun_t *, size_t, char *); 114 static int ahci_get_num_blocks(ddf_fun_t *, uint64_t *); 115 static int ahci_get_block_size(ddf_fun_t *, size_t *); 116 static int ahci_read_blocks(ddf_fun_t *, uint64_t, size_t, void *); 117 static int ahci_write_blocks(ddf_fun_t *, uint64_t, size_t, void *); 116 118 117 119 static int ahci_identify_device(sata_dev_t *); 118 120 static int ahci_set_highest_ultra_dma_mode(sata_dev_t *); 119 static int ahci_rb_fpdma(sata_dev_t *, uintptr_t, uint64_t);120 static int ahci_wb_fpdma(sata_dev_t *, uintptr_t, uint64_t);121 static int ahci_rb_fpdma(sata_dev_t *, void *, uint64_t); 122 static int ahci_wb_fpdma(sata_dev_t *, void *, uint64_t); 121 123 122 124 static void ahci_sata_devices_create(ahci_dev_t *, ddf_dev_t *); … … 127 129 128 130 static void ahci_get_model_name(uint16_t *, char *); 131 static int ahci_enable_interrupt(int); 129 132 130 133 static fibril_mutex_t sata_devices_count_lock; … … 136 139 137 140 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_blocks141 .get_sata_device_name = &ahci_get_sata_device_name, 142 .get_num_blocks = &ahci_get_num_blocks, 143 .get_block_size = &ahci_get_block_size, 144 .read_blocks = &ahci_read_blocks, 145 .write_blocks = &ahci_write_blocks 143 146 }; 144 147 … … 177 180 * 178 181 */ 179 static int get_sata_device_name(ddf_fun_t *fun,182 static int ahci_get_sata_device_name(ddf_fun_t *fun, 180 183 size_t sata_dev_name_length, char *sata_dev_name) 181 184 { … … 193 196 * 194 197 */ 195 static int get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)198 static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks) 196 199 { 197 200 sata_dev_t *sata = fun_sata_dev(fun); … … 208 211 * 209 212 */ 210 static int get_block_size(ddf_fun_t *fun, size_t *block_size)213 static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size) 211 214 { 212 215 sata_dev_t *sata = fun_sata_dev(fun); … … 225 228 * 226 229 */ 227 static int read_blocks(ddf_fun_t *fun, uint64_t blocknum,230 static int ahci_read_blocks(ddf_fun_t *fun, uint64_t blocknum, 228 231 size_t count, void *buf) 229 232 { 230 233 sata_dev_t *sata = fun_sata_dev(fun); 231 234 232 uintptr_tphys;233 void *ibuf = AS_AREA_ANY;234 int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,235 AS_AREA_READ | AS_AREA_WRITE, 0, &phys,&ibuf);235 void *phys; 236 void *ibuf; 237 int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE, 238 0, &phys, (void **) &ibuf); 236 239 if (rc != EOK) { 237 240 ddf_msg(LVL_ERROR, "Cannot allocate read buffer."); … … 268 271 * 269 272 */ 270 static int write_blocks(ddf_fun_t *fun, uint64_t blocknum,273 static int ahci_write_blocks(ddf_fun_t *fun, uint64_t blocknum, 271 274 size_t count, void *buf) 272 275 { 273 276 sata_dev_t *sata = fun_sata_dev(fun); 274 277 275 uintptr_tphys;276 void *ibuf = AS_AREA_ANY;277 int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,278 AS_AREA_READ | AS_AREA_WRITE, 0, &phys,&ibuf);278 void *phys; 279 void *ibuf; 280 int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE, 281 0, &phys, (void **) &ibuf); 279 282 if (rc != EOK) { 280 283 ddf_msg(LVL_ERROR, "Cannot allocate write buffer."); … … 333 336 * 334 337 */ 335 static void ahci_identify_device_cmd(sata_dev_t *sata, uintptr_tphys)338 static void ahci_identify_device_cmd(sata_dev_t *sata, void *phys) 336 339 { 337 340 volatile sata_std_command_frame_t *cmd = … … 378 381 * 379 382 */ 380 static void ahci_identify_packet_device_cmd(sata_dev_t *sata, uintptr_tphys)383 static void ahci_identify_packet_device_cmd(sata_dev_t *sata, void *phys) 381 384 { 382 385 volatile sata_std_command_frame_t *cmd = … … 432 435 } 433 436 434 uintptr_tphys;435 sata_identify_data_t *idata = AS_AREA_ANY;437 void *phys; 438 sata_identify_data_t *idata; 436 439 int rc = dmamem_map_anonymous(SATA_IDENTIFY_DEVICE_BUFFER_LENGTH, 437 DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys, 438 (void *) &idata); 440 AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata); 439 441 if (rc != EOK) { 440 442 ddf_msg(LVL_ERROR, "Cannot allocate buffer to identify device."); … … 559 561 * 560 562 */ 561 static void ahci_set_mode_cmd(sata_dev_t *sata, uintptr_tphys, uint8_t mode)563 static void ahci_set_mode_cmd(sata_dev_t *sata, void* phys, uint8_t mode) 562 564 { 563 565 volatile sata_std_command_frame_t *cmd = … … 565 567 566 568 cmd->fis_type = SATA_CMD_FIS_TYPE; 567 cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR; 569 cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR; 568 570 cmd->command = 0xef; 569 571 cmd->features = 0x03; … … 626 628 } 627 629 628 uintptr_tphys;629 sata_identify_data_t *idata = AS_AREA_ANY;630 void *phys; 631 sata_identify_data_t *idata; 630 632 int rc = dmamem_map_anonymous(SATA_SET_FEATURE_BUFFER_LENGTH, 631 DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys, 632 (void *) &idata); 633 AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata); 633 634 if (rc != EOK) { 634 635 ddf_msg(LVL_ERROR, "Cannot allocate buffer for device set mode."); … … 676 677 * 677 678 */ 678 static void ahci_rb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys, 679 uint64_t blocknum) 679 static void ahci_rb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum) 680 680 { 681 681 volatile sata_ncq_command_frame_t *cmd = … … 734 734 * 735 735 */ 736 static int ahci_rb_fpdma(sata_dev_t *sata, uintptr_tphys, uint64_t blocknum)736 static int ahci_rb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum) 737 737 { 738 738 if (sata->is_invalid_device) { … … 763 763 * 764 764 */ 765 static void ahci_wb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys, 766 uint64_t blocknum) 765 static void ahci_wb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum) 767 766 { 768 767 volatile sata_ncq_command_frame_t *cmd = … … 822 821 * 823 822 */ 824 static int ahci_wb_fpdma(sata_dev_t *sata, uintptr_tphys, uint64_t blocknum)823 static int ahci_wb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum) 825 824 { 826 825 if (sata->is_invalid_device) { … … 890 889 /** AHCI interrupt handler. 891 890 * 891 * @param dev DDF device structure. 892 892 * @param iid The IPC call id. 893 893 * @param icall The IPC call structure. 894 * @param dev DDF device structure. 895 * 896 */ 897 static void ahci_interrupt(ipc_callid_t iid, ipc_call_t *icall, ddf_dev_t *dev) 894 * 895 */ 896 static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 898 897 { 899 898 ahci_dev_t *ahci = dev_ahci_dev(dev); … … 934 933 { 935 934 size_t size = 4096; 936 uintptr_t phys = 0;937 void *virt_fb = AS_AREA_ANY;938 void *virt_cmd = AS_AREA_ANY;939 void *virt_table = AS_AREA_ANY;935 void *phys = NULL; 936 void *virt_fb = NULL; 937 void *virt_cmd = NULL; 938 void *virt_table = NULL; 940 939 ddf_fun_t *fun; 941 940 … … 950 949 951 950 /* Allocate and init retfis structure. */ 952 int rc = dmamem_map_anonymous(size, DMAMEM_4GiB,953 AS_AREA_READ | AS_AREA_WRITE, 0,&phys, &virt_fb);951 int rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0, 952 &phys, &virt_fb); 954 953 if (rc != EOK) 955 954 goto error_retfis; … … 960 959 961 960 /* Allocate and init command header structure. */ 962 rc = dmamem_map_anonymous(size, DMAMEM_4GiB,963 AS_AREA_READ | AS_AREA_WRITE, 0,&phys, &virt_cmd);961 rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0, 962 &phys, &virt_cmd); 964 963 if (rc != EOK) 965 964 goto error_cmd; … … 971 970 972 971 /* Allocate and init command table structure. */ 973 rc = dmamem_map_anonymous(size, DMAMEM_4GiB,974 AS_AREA_READ | AS_AREA_WRITE, 0,&phys, &virt_table);972 rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0, 973 &phys, &virt_table); 975 974 if (rc != EOK) 976 975 goto error_table; … … 1140 1139 1141 1140 /* Connect to parent device */ 1142 ahci->parent_sess = ddf_dev_parent_sess_create(dev );1141 ahci->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE); 1143 1142 if (ahci->parent_sess == NULL) 1144 1143 return NULL; … … 1152 1151 1153 1152 /* Map AHCI registers. */ 1154 ahci->memregs = AS_AREA_ANY;1155 1156 physmem_map( RNGABS(hw_res_parsed.mem_ranges.ranges[0]),1153 ahci->memregs = NULL; 1154 1155 physmem_map((void *) (size_t) (hw_res_parsed.mem_ranges.ranges[0].address), 1157 1156 AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE, 1158 (void * ) &ahci->memregs);1157 (void **) &ahci->memregs); 1159 1158 if (ahci->memregs == NULL) 1160 1159 goto error_map_registers; 1161 1160 1162 1161 /* Register interrupt handler */ 1163 ahci_ranges[0].base = RNGABS(hw_res_parsed.mem_ranges.ranges[0]);1162 ahci_ranges[0].base = (size_t) hw_res_parsed.mem_ranges.ranges[0].address; 1164 1163 ahci_ranges[0].size = sizeof(ahci_memregs_t); 1165 1164 … … 1168 1167 1169 1168 ahci_cmds[base].addr = 1170 ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +1169 ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) + 1171 1170 AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE + 1172 1171 AHCI_PORT_IS_REGISTER_OFFSET; … … 1174 1173 1175 1174 ahci_cmds[base + 3].addr = 1176 ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +1175 ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) + 1177 1176 AHCI_GHC_IS_REGISTER_OFFSET; 1178 1177 ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr; … … 1192 1191 } 1193 1192 1194 rc = irc_enable_interrupt(hw_res_parsed.irqs.irqs[0]);1193 rc = ahci_enable_interrupt(hw_res_parsed.irqs.irqs[0]); 1195 1194 if (rc != EOK) { 1196 1195 ddf_msg(LVL_ERROR, "Failed enable interupt."); … … 1312 1311 } 1313 1312 1313 /** Enable interrupt using SERVICE_IRC. 1314 * 1315 * @param irq Requested irq number. 1316 * 1317 * @return EOK if succeed, error code otherwise. 1318 * 1319 */ 1320 static int ahci_enable_interrupt(int irq) 1321 { 1322 async_sess_t *irc_sess = NULL; 1323 irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_IRC, 0, 0); 1324 if (!irc_sess) 1325 return EINTR; 1326 1327 async_exch_t *exch = async_exchange_begin(irc_sess); 1328 const int rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq); 1329 async_exchange_end(exch); 1330 1331 async_hangup(irc_sess); 1332 return rc; 1333 } 1334 1314 1335 /*----------------------------------------------------------------------------*/ 1315 1336 /*-- AHCI Main routine -------------------------------------------------------*/
Note:
See TracChangeset
for help on using the changeset viewer.