Changeset 7eaeec1 in mainline for uspace/drv/block/ahci/ahci.c
- Timestamp:
- 2012-08-20T21:27:38Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6a97f2e
- Parents:
- f3a37e28 (diff), dd13349 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
rf3a37e28 r7eaeec1 34 34 #include <errno.h> 35 35 #include <stdio.h> 36 #include <devman.h>37 36 #include <ddf/interrupt.h> 38 37 #include <ddf/log.h> … … 160 159 }; 161 160 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 162 173 /** Get SATA device name. 163 174 * … … 172 183 size_t sata_dev_name_length, char *sata_dev_name) 173 184 { 174 sata_dev_t *sata = (sata_dev_t *) fun->driver_data;185 sata_dev_t *sata = fun_sata_dev(fun); 175 186 str_cpy(sata_dev_name, sata_dev_name_length, sata->model); 176 187 return EOK; … … 187 198 static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks) 188 199 { 189 sata_dev_t *sata = (sata_dev_t *) fun->driver_data;200 sata_dev_t *sata = fun_sata_dev(fun); 190 201 *num_blocks = sata->blocks; 191 202 return EOK; … … 202 213 static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size) 203 214 { 204 sata_dev_t *sata = (sata_dev_t *) fun->driver_data;215 sata_dev_t *sata = fun_sata_dev(fun); 205 216 *block_size = sata->block_size; 206 217 return EOK; … … 220 231 size_t count, void *buf) 221 232 { 222 sata_dev_t *sata = (sata_dev_t *) fun->driver_data;233 sata_dev_t *sata = fun_sata_dev(fun); 223 234 224 235 void *phys; … … 263 274 size_t count, void *buf) 264 275 { 265 sata_dev_t *sata = (sata_dev_t *) fun->driver_data;276 sata_dev_t *sata = fun_sata_dev(fun); 266 277 267 278 void *phys; … … 885 896 static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall) 886 897 { 887 ahci_dev_t *ahci = (ahci_dev_t *) dev->driver_data;898 ahci_dev_t *ahci = dev_ahci_dev(dev); 888 899 unsigned int port = IPC_GET_ARG1(*icall); 889 900 ahci_port_is_t pxis = IPC_GET_ARG2(*icall); … … 919 930 * 920 931 */ 921 static sata_dev_t *ahci_sata_allocate( volatile ahci_port_t *port)932 static sata_dev_t *ahci_sata_allocate(ahci_dev_t *ahci, volatile ahci_port_t *port) 922 933 { 923 934 size_t size = 4096; … … 926 937 void *virt_cmd = NULL; 927 938 void *virt_table = NULL; 928 929 sata_dev_t *sata = malloc(sizeof(sata_dev_t)); 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)); 930 944 if (sata == NULL) 931 945 return NULL; 932 946 933 bzero(sata, sizeof(sata_dev_t)); 934 947 sata->fun = fun; 935 948 sata->port = port; 936 949 … … 1029 1042 { 1030 1043 ddf_fun_t *fun = NULL; 1031 sata_dev_t *sata = ahci_sata_allocate(port); 1044 int rc; 1045 1046 sata_dev_t *sata = ahci_sata_allocate(ahci, port); 1032 1047 if (sata == NULL) 1033 1048 return EINTR; … … 1061 1076 fibril_mutex_unlock(&sata_devices_count_lock); 1062 1077 1063 fun = ddf_fun_create(dev, fun_exposed, sata_dev_name);1064 if ( fun == NULL) {1065 ddf_msg(LVL_ERROR, "Failed creating function.");1078 rc= ddf_fun_set_name(sata->fun, sata_dev_name); 1079 if (rc != EOK) { 1080 ddf_msg(LVL_ERROR, "Failed setting function name."); 1066 1081 goto error; 1067 1082 } 1068 1083 1069 fun->ops = &ahci_ops;1070 fun->driver_data = sata;1071 intrc = ddf_fun_bind(fun);1084 ddf_fun_set_ops(fun, &ahci_ops); 1085 1086 rc = ddf_fun_bind(fun); 1072 1087 if (rc != EOK) { 1073 1088 ddf_msg(LVL_ERROR, "Failed binding function."); … … 1119 1134 static ahci_dev_t *ahci_ahci_create(ddf_dev_t *dev) 1120 1135 { 1121 ahci_dev_t *ahci = malloc(sizeof(ahci_dev_t));1136 ahci_dev_t *ahci = ddf_dev_data_alloc(dev, sizeof(ahci_dev_t)); 1122 1137 if (!ahci) 1123 1138 return NULL; 1124 1139 1125 bzero(ahci, sizeof(ahci_dev_t)); 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; 1126 1144 1127 1145 ahci->dev = dev; … … 1129 1147 hw_res_list_parsed_t hw_res_parsed; 1130 1148 hw_res_list_parsed_init(&hw_res_parsed); 1131 if (hw_res_get_list_parsed( dev->parent_sess, &hw_res_parsed, 0) != EOK)1149 if (hw_res_get_list_parsed(ahci->parent_sess, &hw_res_parsed, 0) != EOK) 1132 1150 goto error_get_res_parsed; 1133 1151 … … 1211 1229 1212 1230 /* Set master latency timer. */ 1213 pci_config_space_write_8(ahci-> dev->parent_sess, AHCI_PCI_MLT, 32);1231 pci_config_space_write_8(ahci->parent_sess, AHCI_PCI_MLT, 32); 1214 1232 1215 1233 /* Enable PCI interrupt and bus mastering */ 1216 1234 ahci_pcireg_cmd_t cmd; 1217 1235 1218 pci_config_space_read_16(ahci-> dev->parent_sess, AHCI_PCI_CMD, &cmd.u16);1236 pci_config_space_read_16(ahci->parent_sess, AHCI_PCI_CMD, &cmd.u16); 1219 1237 cmd.id = 0; 1220 1238 cmd.bme = 1; 1221 pci_config_space_write_16(ahci-> dev->parent_sess, AHCI_PCI_CMD, cmd.u16);1239 pci_config_space_write_16(ahci->parent_sess, AHCI_PCI_CMD, cmd.u16); 1222 1240 1223 1241 /* Enable AHCI and interrupt. */ … … 1237 1255 static int ahci_dev_add(ddf_dev_t *dev) 1238 1256 { 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 1245 1257 ahci_dev_t *ahci = ahci_ahci_create(dev); 1246 1258 if (ahci == NULL) 1247 1259 goto error; 1248 1260 1249 dev->driver_data = ahci;1250 1251 1261 /* Start AHCI hardware. */ 1252 1262 ahci_ahci_hw_start(ahci); … … 1258 1268 1259 1269 error: 1260 async_hangup(dev->parent_sess);1261 1270 return EINTR; 1262 1271 }
Note:
See TracChangeset
for help on using the changeset viewer.