Changeset ebb1489 in mainline for uspace/drv/block/pci-ide/main.c
- Timestamp:
- 2024-10-13T08:23:40Z (8 weeks ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (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. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/pci-ide/main.c
r2a0c827c rebb1489 1 1 /* 2 * Copyright (c) 20 13Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup ata_bd29 /** @addtogroup pci-ide 30 30 * @{ 31 31 */ … … 42 42 #include <device/hw_res_parsed.h> 43 43 44 #include "ata_bd.h" 44 #include "pci-ide.h" 45 #include "pci-ide_hw.h" 45 46 #include "main.h" 46 47 47 static errno_t ata_dev_add(ddf_dev_t *dev);48 static errno_t ata_dev_remove(ddf_dev_t *dev);49 static errno_t ata_dev_gone(ddf_dev_t *dev);50 static errno_t ata_fun_online(ddf_fun_t *fun);51 static errno_t ata_fun_offline(ddf_fun_t *fun);52 53 static void ata_bd_connection(ipc_call_t *, void *);48 static errno_t pci_ide_dev_add(ddf_dev_t *dev); 49 static errno_t pci_ide_dev_remove(ddf_dev_t *dev); 50 static errno_t pci_ide_dev_gone(ddf_dev_t *dev); 51 static errno_t pci_ide_fun_online(ddf_fun_t *fun); 52 static errno_t pci_ide_fun_offline(ddf_fun_t *fun); 53 54 static void pci_ide_connection(ipc_call_t *, void *); 54 55 55 56 static driver_ops_t driver_ops = { 56 .dev_add = & ata_dev_add,57 .dev_remove = & ata_dev_remove,58 .dev_gone = & ata_dev_gone,59 .fun_online = & ata_fun_online,60 .fun_offline = & ata_fun_offline57 .dev_add = &pci_ide_dev_add, 58 .dev_remove = &pci_ide_dev_remove, 59 .dev_gone = &pci_ide_dev_gone, 60 .fun_online = &pci_ide_fun_online, 61 .fun_offline = &pci_ide_fun_offline 61 62 }; 62 63 63 static driver_t ata_driver = {64 static driver_t pci_ide_driver = { 64 65 .name = NAME, 65 66 .driver_ops = &driver_ops 66 67 }; 67 68 68 static errno_t ata_get_res(ddf_dev_t *dev, ata_base_t *ata_res)69 static errno_t pci_ide_get_res(ddf_dev_t *dev, pci_ide_hwres_t *res) 69 70 { 70 71 async_sess_t *parent_sess; … … 81 82 return rc; 82 83 83 if (hw_res.io_ranges.count != 2) {84 if (hw_res.io_ranges.count != 1) { 84 85 rc = EINVAL; 85 86 goto error; 86 87 } 87 88 88 addr_range_t *cmd_rng = &hw_res.io_ranges.ranges[0]; 89 addr_range_t *ctl_rng = &hw_res.io_ranges.ranges[1]; 90 ata_res->cmd = RNGABS(*cmd_rng); 91 ata_res->ctl = RNGABS(*ctl_rng); 92 93 if (RNGSZ(*ctl_rng) < sizeof(ata_ctl_t)) { 89 /* Legacty ISA I/O ranges are fixed */ 90 91 res->cmd1 = pci_ide_ata_cmd_p; 92 res->ctl1 = pci_ide_ata_ctl_p; 93 res->cmd2 = pci_ide_ata_cmd_s; 94 res->ctl2 = pci_ide_ata_ctl_s; 95 96 /* PCI I/O range */ 97 addr_range_t *bmregs_rng = &hw_res.io_ranges.ranges[0]; 98 res->bmregs = RNGABS(*bmregs_rng); 99 100 ddf_msg(LVL_NOTE, "sizes: %zu", RNGSZ(*bmregs_rng)); 101 102 if (RNGSZ(*bmregs_rng) < sizeof(pci_ide_regs_t)) { 94 103 rc = EINVAL; 95 104 goto error; 96 105 } 97 106 98 if (RNGSZ(*cmd_rng) < sizeof(ata_cmd_t)) { 99 rc = EINVAL; 100 goto error; 107 /* IRQ */ 108 if (hw_res.irqs.count > 0) { 109 res->irq1 = hw_res.irqs.irqs[0]; 110 } else { 111 res->irq1 = -1; 112 } 113 114 if (hw_res.irqs.count > 1) { 115 res->irq2 = hw_res.irqs.irqs[1]; 116 } else { 117 res->irq2 = -1; 101 118 } 102 119 … … 112 129 * @return EOK on success or an error code. 113 130 */ 114 static errno_t ata_dev_add(ddf_dev_t *dev)115 { 116 ata_ctrl_t *ctrl;117 ata_base_t res;118 errno_t rc; 119 120 rc = ata_get_res(dev, &res);131 static errno_t pci_ide_dev_add(ddf_dev_t *dev) 132 { 133 pci_ide_ctrl_t *ctrl; 134 pci_ide_hwres_t res; 135 errno_t rc; 136 137 rc = pci_ide_get_res(dev, &res); 121 138 if (rc != EOK) { 122 139 ddf_msg(LVL_ERROR, "Invalid HW resource configuration."); … … 124 141 } 125 142 126 ctrl = ddf_dev_data_alloc(dev, sizeof( ata_ctrl_t));143 ctrl = ddf_dev_data_alloc(dev, sizeof(pci_ide_ctrl_t)); 127 144 if (ctrl == NULL) { 128 145 ddf_msg(LVL_ERROR, "Failed allocating soft state."); … … 133 150 ctrl->dev = dev; 134 151 135 rc = ata_ctrl_init(ctrl, &res); 152 rc = pci_ide_ctrl_init(ctrl, &res); 153 if (rc != EOK) 154 goto error; 155 156 rc = pci_ide_channel_init(ctrl, &ctrl->channel[0], 0, &res); 157 if (rc == ENOENT) 158 goto error; 159 160 rc = pci_ide_channel_init(ctrl, &ctrl->channel[1], 1, &res); 136 161 if (rc == ENOENT) 137 162 goto error; … … 148 173 } 149 174 150 static char * ata_fun_name(disk_t *disk)175 static char *pci_ide_fun_name(pci_ide_channel_t *chan, unsigned idx) 151 176 { 152 177 char *fun_name; 153 178 154 if (asprintf(&fun_name, " d%u", disk->disk_id) < 0)179 if (asprintf(&fun_name, "c%ud%u", chan->chan_id, idx) < 0) 155 180 return NULL; 156 181 … … 158 183 } 159 184 160 errno_t ata_fun_create(disk_t *disk) 161 { 162 ata_ctrl_t *ctrl = disk->ctrl; 185 errno_t pci_ide_fun_create(pci_ide_channel_t *chan, unsigned idx, void *charg) 186 { 163 187 errno_t rc; 164 188 char *fun_name = NULL; 165 189 ddf_fun_t *fun = NULL; 166 ata_fun_t *afun = NULL;190 pci_ide_fun_t *ifun = NULL; 167 191 bool bound = false; 168 192 169 fun_name = ata_fun_name(disk);193 fun_name = pci_ide_fun_name(chan, idx); 170 194 if (fun_name == NULL) { 171 195 ddf_msg(LVL_ERROR, "Out of memory."); … … 174 198 } 175 199 176 fun = ddf_fun_create(c trl->dev, fun_exposed, fun_name);200 fun = ddf_fun_create(chan->ctrl->dev, fun_exposed, fun_name); 177 201 if (fun == NULL) { 178 202 ddf_msg(LVL_ERROR, "Failed creating DDF function."); … … 182 206 183 207 /* Allocate soft state */ 184 afun = ddf_fun_data_alloc(fun, sizeof(ata_fun_t));185 if ( afun == NULL) {208 ifun = ddf_fun_data_alloc(fun, sizeof(pci_ide_fun_t)); 209 if (ifun == NULL) { 186 210 ddf_msg(LVL_ERROR, "Failed allocating softstate."); 187 211 rc = ENOMEM; … … 189 213 } 190 214 191 afun->fun = fun; 192 afun->disk = disk; 193 194 bd_srvs_init(&afun->bds); 195 afun->bds.ops = &ata_bd_ops; 196 afun->bds.sarg = disk; 215 ifun->fun = fun; 216 ifun->charg = charg; 197 217 198 218 /* Set up a connection handler. */ 199 ddf_fun_set_conn_handler(fun, ata_bd_connection);219 ddf_fun_set_conn_handler(fun, pci_ide_connection); 200 220 201 221 rc = ddf_fun_bind(fun); … … 216 236 217 237 free(fun_name); 218 disk->afun = afun;219 238 return EOK; 220 239 error: … … 229 248 } 230 249 231 errno_t ata_fun_remove(disk_t *disk)250 errno_t pci_ide_fun_remove(pci_ide_channel_t *chan, unsigned idx) 232 251 { 233 252 errno_t rc; 234 253 char *fun_name; 235 236 if (disk->afun == NULL) 237 return EOK; 238 239 fun_name = ata_fun_name(disk); 254 pci_ide_fun_t *ifun = chan->fun[idx]; 255 256 fun_name = pci_ide_fun_name(chan, idx); 240 257 if (fun_name == NULL) { 241 258 ddf_msg(LVL_ERROR, "Out of memory."); … … 244 261 } 245 262 246 ddf_msg(LVL_DEBUG, " ata_fun_remove(%p, '%s')", disk, fun_name);247 rc = ddf_fun_offline( disk->afun->fun);263 ddf_msg(LVL_DEBUG, "pci_ide_fun_remove(%p, '%s')", ifun, fun_name); 264 rc = ddf_fun_offline(ifun->fun); 248 265 if (rc != EOK) { 249 266 ddf_msg(LVL_ERROR, "Error offlining function '%s'.", fun_name); … … 251 268 } 252 269 253 rc = ddf_fun_unbind( disk->afun->fun);270 rc = ddf_fun_unbind(ifun->fun); 254 271 if (rc != EOK) { 255 272 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", fun_name); … … 257 274 } 258 275 259 ddf_fun_destroy(disk->afun->fun); 260 disk->afun = NULL; 276 ddf_fun_destroy(ifun->fun); 261 277 free(fun_name); 262 278 return EOK; … … 267 283 } 268 284 269 errno_t ata_fun_unbind(disk_t *disk)285 errno_t pci_ide_fun_unbind(pci_ide_channel_t *chan, unsigned idx) 270 286 { 271 287 errno_t rc; 272 288 char *fun_name; 273 274 if (disk->afun == NULL) 275 return EOK; 276 277 fun_name = ata_fun_name(disk); 289 pci_ide_fun_t *ifun = chan->fun[idx]; 290 291 fun_name = pci_ide_fun_name(chan, idx); 278 292 if (fun_name == NULL) { 279 293 ddf_msg(LVL_ERROR, "Out of memory."); … … 282 296 } 283 297 284 ddf_msg(LVL_DEBUG, " ata_fun_unbind(%p, '%s')", disk, fun_name);285 rc = ddf_fun_unbind( disk->afun->fun);298 ddf_msg(LVL_DEBUG, "pci_ide_fun_unbind(%p, '%s')", ifun, fun_name); 299 rc = ddf_fun_unbind(ifun->fun); 286 300 if (rc != EOK) { 287 301 ddf_msg(LVL_ERROR, "Failed unbinding function '%s'.", fun_name); … … 289 303 } 290 304 291 ddf_fun_destroy(disk->afun->fun); 292 disk->afun = NULL; 305 ddf_fun_destroy(ifun->fun); 293 306 free(fun_name); 294 307 return EOK; … … 299 312 } 300 313 301 static errno_t ata_dev_remove(ddf_dev_t *dev) 302 { 303 ata_ctrl_t *ctrl = (ata_ctrl_t *)ddf_dev_data_get(dev); 304 305 ddf_msg(LVL_DEBUG, "ata_dev_remove(%p)", dev); 306 307 return ata_ctrl_remove(ctrl); 308 } 309 310 static errno_t ata_dev_gone(ddf_dev_t *dev) 311 { 312 ata_ctrl_t *ctrl = (ata_ctrl_t *)ddf_dev_data_get(dev); 313 314 ddf_msg(LVL_DEBUG, "ata_dev_gone(%p)", dev); 315 316 return ata_ctrl_gone(ctrl); 317 } 318 319 static errno_t ata_fun_online(ddf_fun_t *fun) 320 { 321 ddf_msg(LVL_DEBUG, "ata_fun_online()"); 314 static errno_t pci_ide_dev_remove(ddf_dev_t *dev) 315 { 316 pci_ide_ctrl_t *ctrl = (pci_ide_ctrl_t *)ddf_dev_data_get(dev); 317 errno_t rc; 318 319 ddf_msg(LVL_DEBUG, "pci_ide_dev_remove(%p)", dev); 320 321 rc = pci_ide_channel_fini(&ctrl->channel[0]); 322 if (rc != EOK) 323 return rc; 324 325 rc = pci_ide_channel_fini(&ctrl->channel[1]); 326 if (rc != EOK) 327 return rc; 328 329 return EOK; 330 } 331 332 static errno_t pci_ide_dev_gone(ddf_dev_t *dev) 333 { 334 pci_ide_ctrl_t *ctrl = (pci_ide_ctrl_t *)ddf_dev_data_get(dev); 335 errno_t rc; 336 337 ddf_msg(LVL_DEBUG, "pci_ide_dev_gone(%p)", dev); 338 339 rc = pci_ide_ctrl_fini(ctrl); 340 if (rc != EOK) 341 return rc; 342 343 rc = pci_ide_channel_fini(&ctrl->channel[0]); 344 if (rc != EOK) 345 return rc; 346 347 rc = pci_ide_channel_fini(&ctrl->channel[1]); 348 if (rc != EOK) 349 return rc; 350 351 return EOK; 352 } 353 354 static errno_t pci_ide_fun_online(ddf_fun_t *fun) 355 { 356 ddf_msg(LVL_DEBUG, "pci_ide_fun_online()"); 322 357 return ddf_fun_online(fun); 323 358 } 324 359 325 static errno_t ata_fun_offline(ddf_fun_t *fun)326 { 327 ddf_msg(LVL_DEBUG, " ata_fun_offline()");360 static errno_t pci_ide_fun_offline(ddf_fun_t *fun) 361 { 362 ddf_msg(LVL_DEBUG, "pci_ide_fun_offline()"); 328 363 return ddf_fun_offline(fun); 329 364 } 330 365 331 /** Block device connection handler */ 332 static void ata_bd_connection(ipc_call_t *icall, void *arg) 333 { 334 ata_fun_t *afun; 335 336 afun = (ata_fun_t *) ddf_fun_data_get((ddf_fun_t *)arg); 337 bd_conn(icall, &afun->bds); 366 static void pci_ide_connection(ipc_call_t *icall, void *arg) 367 { 368 pci_ide_fun_t *ifun; 369 370 ifun = (pci_ide_fun_t *) ddf_fun_data_get((ddf_fun_t *)arg); 371 ata_connection(icall, ifun->charg); 338 372 } 339 373 340 374 int main(int argc, char *argv[]) 341 375 { 342 printf(NAME ": HelenOS ATA(PI)device driver\n");376 printf(NAME ": HelenOS PCI IDE device driver\n"); 343 377 ddf_log_init(NAME); 344 return ddf_driver_main(& ata_driver);378 return ddf_driver_main(&pci_ide_driver); 345 379 } 346 380
Note:
See TracChangeset
for help on using the changeset viewer.