Changes in uspace/drv/block/ahci/ahci.c [56fd7cf:76c07e4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
r56fd7cf r76c07e4 34 34 #include <errno.h> 35 35 #include <stdio.h> 36 #include <devman.h> 36 37 #include <ddf/interrupt.h> 37 38 #include <ddf/log.h> … … 159 160 }; 160 161 161 /** Get SATA structure from DDF function. */162 static sata_dev_t *fun_sata_dev(ddf_fun_t *fun)163 {164 return ddf_fun_data_get(fun);165 }166 167 /** Get AHCI structure from DDF device. */168 static ahci_dev_t *dev_ahci_dev(ddf_dev_t *dev)169 {170 return ddf_dev_data_get(dev);171 }172 173 162 /** Get SATA device name. 174 163 * … … 183 172 size_t sata_dev_name_length, char *sata_dev_name) 184 173 { 185 sata_dev_t *sata = fun_sata_dev(fun);174 sata_dev_t *sata = (sata_dev_t *) fun->driver_data; 186 175 str_cpy(sata_dev_name, sata_dev_name_length, sata->model); 187 176 return EOK; … … 198 187 static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks) 199 188 { 200 sata_dev_t *sata = fun_sata_dev(fun);189 sata_dev_t *sata = (sata_dev_t *) fun->driver_data; 201 190 *num_blocks = sata->blocks; 202 191 return EOK; … … 213 202 static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size) 214 203 { 215 sata_dev_t *sata = fun_sata_dev(fun);204 sata_dev_t *sata = (sata_dev_t *) fun->driver_data; 216 205 *block_size = sata->block_size; 217 206 return EOK; … … 231 220 size_t count, void *buf) 232 221 { 233 sata_dev_t *sata = fun_sata_dev(fun);222 sata_dev_t *sata = (sata_dev_t *) fun->driver_data; 234 223 235 224 void *phys; … … 274 263 size_t count, void *buf) 275 264 { 276 sata_dev_t *sata = fun_sata_dev(fun);265 sata_dev_t *sata = (sata_dev_t *) fun->driver_data; 277 266 278 267 void *phys; … … 896 885 static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 897 886 { 898 ahci_dev_t *ahci = dev_ahci_dev(dev);887 ahci_dev_t *ahci = (ahci_dev_t *) dev->driver_data; 899 888 unsigned int port = IPC_GET_ARG1(*icall); 900 889 ahci_port_is_t pxis = IPC_GET_ARG2(*icall); … … 930 919 * 931 920 */ 932 static sata_dev_t *ahci_sata_allocate( ahci_dev_t *ahci,volatile ahci_port_t *port)921 static sata_dev_t *ahci_sata_allocate(volatile ahci_port_t *port) 933 922 { 934 923 size_t size = 4096; … … 937 926 void *virt_cmd = NULL; 938 927 void *virt_table = NULL; 939 ddf_fun_t *fun; 940 941 fun = ddf_fun_create(ahci->dev, fun_exposed, NULL); 942 943 sata_dev_t *sata = ddf_fun_data_alloc(fun, sizeof(sata_dev_t)); 928 929 sata_dev_t *sata = malloc(sizeof(sata_dev_t)); 944 930 if (sata == NULL) 945 931 return NULL; 946 932 947 sata->fun = fun; 933 bzero(sata, sizeof(sata_dev_t)); 934 948 935 sata->port = port; 949 936 … … 1042 1029 { 1043 1030 ddf_fun_t *fun = NULL; 1044 int rc; 1045 1046 sata_dev_t *sata = ahci_sata_allocate(ahci, port); 1031 sata_dev_t *sata = ahci_sata_allocate(port); 1047 1032 if (sata == NULL) 1048 1033 return EINTR; … … 1076 1061 fibril_mutex_unlock(&sata_devices_count_lock); 1077 1062 1078 rc= ddf_fun_set_name(sata->fun, sata_dev_name);1079 if ( rc != EOK) {1080 ddf_msg(LVL_ERROR, "Failed setting function name.");1063 fun = ddf_fun_create(dev, fun_exposed, sata_dev_name); 1064 if (fun == NULL) { 1065 ddf_msg(LVL_ERROR, "Failed creating function."); 1081 1066 goto error; 1082 1067 } 1083 1068 1084 ddf_fun_set_ops(fun, &ahci_ops);1085 1086 rc = ddf_fun_bind(fun);1069 fun->ops = &ahci_ops; 1070 fun->driver_data = sata; 1071 int rc = ddf_fun_bind(fun); 1087 1072 if (rc != EOK) { 1088 1073 ddf_msg(LVL_ERROR, "Failed binding function."); … … 1134 1119 static ahci_dev_t *ahci_ahci_create(ddf_dev_t *dev) 1135 1120 { 1136 ahci_dev_t *ahci = ddf_dev_data_alloc(dev,sizeof(ahci_dev_t));1121 ahci_dev_t *ahci = malloc(sizeof(ahci_dev_t)); 1137 1122 if (!ahci) 1138 1123 return NULL; 1139 1124 1140 /* Connect to parent device */ 1141 ahci->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE); 1142 if (ahci->parent_sess == NULL) 1143 return NULL; 1125 bzero(ahci, sizeof(ahci_dev_t)); 1144 1126 1145 1127 ahci->dev = dev; … … 1147 1129 hw_res_list_parsed_t hw_res_parsed; 1148 1130 hw_res_list_parsed_init(&hw_res_parsed); 1149 if (hw_res_get_list_parsed( ahci->parent_sess, &hw_res_parsed, 0) != EOK)1131 if (hw_res_get_list_parsed(dev->parent_sess, &hw_res_parsed, 0) != EOK) 1150 1132 goto error_get_res_parsed; 1151 1133 … … 1229 1211 1230 1212 /* Set master latency timer. */ 1231 pci_config_space_write_8(ahci-> parent_sess, AHCI_PCI_MLT, 32);1213 pci_config_space_write_8(ahci->dev->parent_sess, AHCI_PCI_MLT, 32); 1232 1214 1233 1215 /* Enable PCI interrupt and bus mastering */ 1234 1216 ahci_pcireg_cmd_t cmd; 1235 1217 1236 pci_config_space_read_16(ahci-> parent_sess, AHCI_PCI_CMD, &cmd.u16);1218 pci_config_space_read_16(ahci->dev->parent_sess, AHCI_PCI_CMD, &cmd.u16); 1237 1219 cmd.id = 0; 1238 1220 cmd.bme = 1; 1239 pci_config_space_write_16(ahci-> parent_sess, AHCI_PCI_CMD, cmd.u16);1221 pci_config_space_write_16(ahci->dev->parent_sess, AHCI_PCI_CMD, cmd.u16); 1240 1222 1241 1223 /* Enable AHCI and interrupt. */ … … 1255 1237 static int ahci_dev_add(ddf_dev_t *dev) 1256 1238 { 1239 /* Connect to parent device */ 1240 dev->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE, 1241 dev->handle, IPC_FLAG_BLOCKING); 1242 if (dev->parent_sess == NULL) 1243 return EINTR; 1244 1257 1245 ahci_dev_t *ahci = ahci_ahci_create(dev); 1258 1246 if (ahci == NULL) 1259 1247 goto error; 1260 1248 1249 dev->driver_data = ahci; 1250 1261 1251 /* Start AHCI hardware. */ 1262 1252 ahci_ahci_hw_start(ahci); … … 1268 1258 1269 1259 error: 1260 async_hangup(dev->parent_sess); 1270 1261 return EINTR; 1271 1262 }
Note:
See TracChangeset
for help on using the changeset viewer.