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