Changeset 646849b3 in mainline for uspace/drv/block/isa-ide/isa-ide.c
- Timestamp:
- 2024-05-17T12:25:26Z (7 months ago)
- Branches:
- master
- Children:
- 60744cb
- Parents:
- 59c0f478
- git-author:
- Jiri Svoboda <jiri@…> (2024-05-16 19:25:07)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-05-17 12:25:26)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/isa-ide/isa-ide.c
r59c0f478 r646849b3 55 55 #include "main.h" 56 56 57 static errno_t isa_ide_init_io(isa_ide_c trl_t *ctrl);58 static void isa_ide_fini_io(isa_ide_c trl_t *ctrl);59 static errno_t isa_ide_init_irq(isa_ide_c trl_t *ctrl);60 static void isa_ide_fini_irq(isa_ide_c trl_t *ctrl);61 static void isa_ide_irq_handler(ipc_call_t * call, ddf_dev_t *dev);57 static errno_t isa_ide_init_io(isa_ide_channel_t *); 58 static void isa_ide_fini_io(isa_ide_channel_t *); 59 static errno_t isa_ide_init_irq(isa_ide_channel_t *); 60 static void isa_ide_fini_irq(isa_ide_channel_t *); 61 static void isa_ide_irq_handler(ipc_call_t *, ddf_dev_t *); 62 62 63 63 static void isa_ide_write_data_16(void *, uint16_t *, size_t); … … 95 95 }; 96 96 97 /** Initialize ISA IDE controller. */ 98 errno_t isa_ide_ctrl_init(isa_ide_ctrl_t *ctrl, isa_ide_hwres_t *res) 97 /** Initialize ISA IDE channel. */ 98 errno_t isa_ide_channel_init(isa_ide_ctrl_t *ctrl, isa_ide_channel_t *chan, 99 unsigned chan_id, isa_ide_hwres_t *res) 99 100 { 100 101 errno_t rc; … … 104 105 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_init()"); 105 106 106 fibril_mutex_initialize(&ctrl->lock); 107 ctrl->cmd_physical = res->cmd; 108 ctrl->ctl_physical = res->ctl; 109 ctrl->irq = res->irq; 110 111 ddf_msg(LVL_NOTE, "I/O address %p/%p", (void *) ctrl->cmd_physical, 112 (void *) ctrl->ctl_physical); 107 chan->ctrl = ctrl; 108 chan->chan_id = chan_id; 109 fibril_mutex_initialize(&chan->lock); 110 if (chan_id == 0) { 111 chan->cmd_physical = res->cmd1; 112 chan->ctl_physical = res->ctl1; 113 chan->irq = res->irq1; 114 } else { 115 chan->cmd_physical = res->cmd2; 116 chan->ctl_physical = res->ctl2; 117 chan->irq = res->irq2; 118 } 119 120 ddf_msg(LVL_NOTE, "I/O address %p/%p", (void *) chan->cmd_physical, 121 (void *) chan->ctl_physical); 113 122 114 123 ddf_msg(LVL_DEBUG, "Init I/O"); 115 rc = isa_ide_init_io(c trl);124 rc = isa_ide_init_io(chan); 116 125 if (rc != EOK) 117 126 return rc; 118 127 119 128 ddf_msg(LVL_DEBUG, "Init IRQ"); 120 rc = isa_ide_init_irq(c trl);129 rc = isa_ide_init_irq(chan); 121 130 if (rc != EOK) { 122 131 ddf_msg(LVL_NOTE, "init IRQ failed"); … … 128 137 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_init(): Initialize IDE channel"); 129 138 130 params.arg = (void *)c trl;131 params.have_irq = (c trl->irq >= 0) ? true : false;139 params.arg = (void *)chan; 140 params.have_irq = (chan->irq >= 0) ? true : false; 132 141 params.write_data_16 = isa_ide_write_data_16; 133 142 params.read_data_16 = isa_ide_read_data_16; … … 145 154 params.msg_error = isa_ide_msg_error; 146 155 147 rc = ata_channel_create(¶ms, &c trl->channel);156 rc = ata_channel_create(¶ms, &chan->channel); 148 157 if (rc != EOK) 149 158 goto error; 150 159 151 rc = ata_channel_initialize(c trl->channel);160 rc = ata_channel_initialize(chan->channel); 152 161 if (rc != EOK) 153 162 goto error; … … 157 166 error: 158 167 if (irq_inited) 159 isa_ide_fini_irq(c trl);160 isa_ide_fini_io(c trl);168 isa_ide_fini_irq(chan); 169 isa_ide_fini_io(chan); 161 170 return rc; 162 171 } 163 172 164 /** Remove ISA IDE controller. */165 errno_t isa_ide_c trl_remove(isa_ide_ctrl_t *ctrl)173 /** Finalize ISA IDE channel. */ 174 errno_t isa_ide_channel_fini(isa_ide_channel_t *chan) 166 175 { 167 176 errno_t rc; … … 169 178 ddf_msg(LVL_DEBUG, ": isa_ide_ctrl_remove()"); 170 179 171 fibril_mutex_lock(&c trl->lock);172 173 rc = ata_channel_destroy(c trl->channel);174 if (rc != EOK) { 175 fibril_mutex_unlock(&c trl->lock);176 return rc; 177 } 178 179 isa_ide_fini_irq(c trl);180 isa_ide_fini_io(c trl);181 fibril_mutex_unlock(&c trl->lock);180 fibril_mutex_lock(&chan->lock); 181 182 rc = ata_channel_destroy(chan->channel); 183 if (rc != EOK) { 184 fibril_mutex_unlock(&chan->lock); 185 return rc; 186 } 187 188 isa_ide_fini_irq(chan); 189 isa_ide_fini_io(chan); 190 fibril_mutex_unlock(&chan->lock); 182 191 183 192 return EOK; 184 193 } 185 194 186 /** Surprise removal of ISA IDE controller. */ 187 errno_t isa_ide_ctrl_gone(isa_ide_ctrl_t *ctrl) 188 { 189 errno_t rc; 190 191 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_gone()"); 192 193 fibril_mutex_lock(&ctrl->lock); 194 195 rc = ata_channel_destroy(ctrl->channel); 196 if (rc != EOK) { 197 fibril_mutex_unlock(&ctrl->lock); 198 return rc; 199 } 200 201 isa_ide_fini_io(ctrl); 202 fibril_mutex_unlock(&ctrl->lock); 203 195 /** Enable device I/O. */ 196 static errno_t isa_ide_init_io(isa_ide_channel_t *chan) 197 { 198 errno_t rc; 199 void *vaddr; 200 201 rc = pio_enable((void *) chan->cmd_physical, sizeof(ata_cmd_t), &vaddr); 202 if (rc != EOK) { 203 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space."); 204 return rc; 205 } 206 207 chan->cmd = vaddr; 208 209 rc = pio_enable((void *) chan->ctl_physical, sizeof(ata_ctl_t), &vaddr); 210 if (rc != EOK) { 211 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space."); 212 return rc; 213 } 214 215 chan->ctl = vaddr; 204 216 return EOK; 205 217 } 206 218 207 /** Enable device I/O. */208 static errno_t isa_ide_init_io(isa_ide_ctrl_t *ctrl)209 {210 errno_t rc;211 void *vaddr;212 213 rc = pio_enable((void *) ctrl->cmd_physical, sizeof(ata_cmd_t), &vaddr);214 if (rc != EOK) {215 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space.");216 return rc;217 }218 219 ctrl->cmd = vaddr;220 221 rc = pio_enable((void *) ctrl->ctl_physical, sizeof(ata_ctl_t), &vaddr);222 if (rc != EOK) {223 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space.");224 return rc;225 }226 227 ctrl->ctl = vaddr;228 return EOK;229 }230 231 219 /** Clean up device I/O. */ 232 static void isa_ide_fini_io(isa_ide_c trl_t *ctrl)233 { 234 (void) c trl;220 static void isa_ide_fini_io(isa_ide_channel_t *chan) 221 { 222 (void) chan; 235 223 /* XXX TODO */ 236 224 } 237 225 238 226 /** Initialize IRQ. */ 239 static errno_t isa_ide_init_irq(isa_ide_c trl_t *ctrl)227 static errno_t isa_ide_init_irq(isa_ide_channel_t *chan) 240 228 { 241 229 irq_code_t irq_code; … … 244 232 errno_t rc; 245 233 246 if (c trl->irq < 0)234 if (chan->irq < 0) 247 235 return EOK; 248 236 … … 258 246 259 247 memcpy(ranges, &isa_ide_irq_ranges, sizeof(isa_ide_irq_ranges)); 260 ranges[0].base = c trl->cmd_physical;248 ranges[0].base = chan->cmd_physical; 261 249 memcpy(cmds, &isa_ide_irq_cmds, sizeof(isa_ide_irq_cmds)); 262 cmds[0].addr = &c trl->cmd->status;250 cmds[0].addr = &chan->cmd->status; 263 251 264 252 irq_code.rangecount = sizeof(isa_ide_irq_ranges) / sizeof(irq_pio_range_t); … … 267 255 irq_code.cmds = cmds; 268 256 269 ddf_msg(LVL_NOTE, "IRQ %d", c trl->irq);270 rc = register_interrupt_handler (ctrl->dev, ctrl->irq, isa_ide_irq_handler,271 &irq_code, &ctrl->ihandle);257 ddf_msg(LVL_NOTE, "IRQ %d", chan->irq); 258 rc = register_interrupt_handler_arg(chan->ctrl->dev, chan->irq, 259 isa_ide_irq_handler, (void *)chan, &irq_code, &chan->ihandle); 272 260 if (rc != EOK) { 273 261 ddf_msg(LVL_ERROR, "Error registering IRQ."); … … 286 274 287 275 /** Clean up IRQ. */ 288 static void isa_ide_fini_irq(isa_ide_c trl_t *ctrl)276 static void isa_ide_fini_irq(isa_ide_channel_t *chan) 289 277 { 290 278 errno_t rc; 291 279 async_sess_t *parent_sess; 292 280 293 parent_sess = ddf_dev_parent_sess_get(c trl->dev);294 295 rc = hw_res_disable_interrupt(parent_sess, c trl->irq);281 parent_sess = ddf_dev_parent_sess_get(chan->ctrl->dev); 282 283 rc = hw_res_disable_interrupt(parent_sess, chan->irq); 296 284 if (rc != EOK) 297 285 ddf_msg(LVL_ERROR, "Error disabling IRQ."); 298 286 299 (void) unregister_interrupt_handler(c trl->dev, ctrl->ihandle);287 (void) unregister_interrupt_handler(chan->ctrl->dev, chan->ihandle); 300 288 } 301 289 … … 305 293 * @param dev Device that caused the interrupt 306 294 */ 307 static void isa_ide_irq_handler(ipc_call_t *call, ddf_dev_t * dev)308 { 309 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)ddf_dev_data_get(dev);295 static void isa_ide_irq_handler(ipc_call_t *call, ddf_dev_t *xdev) 296 { 297 isa_ide_channel_t *chan = (isa_ide_channel_t *)(void *)xdev; // XXX 310 298 uint8_t status; 311 299 async_sess_t *parent_sess; 312 300 313 301 status = ipc_get_arg1(call); 314 ata_channel_irq(c trl->channel, status);315 316 parent_sess = ddf_dev_parent_sess_get( dev);317 hw_res_clear_interrupt(parent_sess, c trl->irq);302 ata_channel_irq(chan->channel, status); 303 304 parent_sess = ddf_dev_parent_sess_get(chan->ctrl->dev); 305 hw_res_clear_interrupt(parent_sess, chan->irq); 318 306 } 319 307 320 308 /** Write the data register callback handler. 321 309 * 322 * @param arg Argument (isa_ide_c trl_t *)310 * @param arg Argument (isa_ide_channel_t *) 323 311 * @param data Data 324 312 * @param nwords Number of words to write … … 326 314 static void isa_ide_write_data_16(void *arg, uint16_t *data, size_t nwords) 327 315 { 328 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;316 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 329 317 size_t i; 330 318 331 319 for (i = 0; i < nwords; i++) 332 pio_write_16(&c trl->cmd->data_port, data[i]);320 pio_write_16(&chan->cmd->data_port, data[i]); 333 321 } 334 322 335 323 /** Read the data register callback handler. 336 324 * 337 * @param arg Argument (isa_ide_c trl_t *)325 * @param arg Argument (isa_ide_channel_t *) 338 326 * @param buf Destination buffer 339 327 * @param nwords Number of words to read … … 341 329 static void isa_ide_read_data_16(void *arg, uint16_t *buf, size_t nwords) 342 330 { 343 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;331 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 344 332 size_t i; 345 333 346 334 for (i = 0; i < nwords; i++) 347 buf[i] = pio_read_16(&c trl->cmd->data_port);335 buf[i] = pio_read_16(&chan->cmd->data_port); 348 336 } 349 337 350 338 /** Write command register callback handler. 351 339 * 352 * @param arg Argument (isa_ide_c trl_t *)340 * @param arg Argument (isa_ide_channel_t *) 353 341 * @param off Register offset 354 342 * @param value Value to write to command register … … 356 344 static void isa_ide_write_cmd_8(void *arg, uint16_t off, uint8_t value) 357 345 { 358 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;359 360 pio_write_8(((ioport8_t *)c trl->cmd) + off, value);346 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 347 348 pio_write_8(((ioport8_t *)chan->cmd) + off, value); 361 349 } 362 350 363 351 /** Read command register callback handler. 364 352 * 365 * @param arg Argument (isa_ide_c trl_t *)353 * @param arg Argument (isa_ide_channel_t *) 366 354 * @param off Register offset 367 355 * @return value Value read from command register … … 369 357 static uint8_t isa_ide_read_cmd_8(void *arg, uint16_t off) 370 358 { 371 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;372 373 return pio_read_8(((ioport8_t *)c trl->cmd) + off);359 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 360 361 return pio_read_8(((ioport8_t *)chan->cmd) + off); 374 362 } 375 363 376 364 /** Write control register callback handler. 377 365 * 378 * @param arg Argument (isa_ide_c trl_t *)366 * @param arg Argument (isa_ide_channel_t *) 379 367 * @param off Register offset 380 368 * @param value Value to write to control register … … 382 370 static void isa_ide_write_ctl_8(void *arg, uint16_t off, uint8_t value) 383 371 { 384 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;385 386 pio_write_8(((ioport8_t *)c trl->ctl) + off, value);372 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 373 374 pio_write_8(((ioport8_t *)chan->ctl) + off, value); 387 375 } 388 376 389 377 /** Read control register callback handler. 390 378 * 391 * @param arg Argument (isa_ide_c trl_t *)379 * @param arg Argument (isa_ide_channel_t *) 392 380 * @param off Register offset 393 381 * @return value Value read from control register … … 395 383 static uint8_t isa_ide_read_ctl_8(void *arg, uint16_t off) 396 384 { 397 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;398 399 return pio_read_8(((ioport8_t *)c trl->ctl) + off);385 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 386 387 return pio_read_8(((ioport8_t *)chan->ctl) + off); 400 388 } 401 389 402 390 /** Enable IRQ callback handler 403 391 * 404 * @param arg Argument (isa_ide_c trl_t *)392 * @param arg Argument (isa_ide_channel_t *) 405 393 * @return EOK on success or an error code 406 394 */ 407 395 static errno_t isa_ide_irq_enable(void *arg) 408 396 { 409 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;397 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 410 398 async_sess_t *parent_sess; 411 399 errno_t rc; 412 400 413 ddf_msg(LVL_DEBUG, "Enable IRQ"); 414 415 parent_sess = ddf_dev_parent_sess_get(ctrl->dev); 416 417 rc = hw_res_enable_interrupt(parent_sess, ctrl->irq); 401 ddf_msg(LVL_DEBUG, "Enable IRQ %d for channel %u", 402 chan->irq, chan->chan_id); 403 404 parent_sess = ddf_dev_parent_sess_get(chan->ctrl->dev); 405 406 rc = hw_res_enable_interrupt(parent_sess, chan->irq); 418 407 if (rc != EOK) { 419 408 ddf_msg(LVL_ERROR, "Error enabling IRQ."); 420 (void) unregister_interrupt_handler(ctrl->dev,421 ctrl->ihandle);422 409 return rc; 423 410 } … … 428 415 /** Disable IRQ callback handler 429 416 * 430 * @param arg Argument (isa_ide_c trl_t *)417 * @param arg Argument (isa_ide_channel_t *) 431 418 * @return EOK on success or an error code 432 419 */ 433 420 static errno_t isa_ide_irq_disable(void *arg) 434 421 { 435 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;422 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 436 423 async_sess_t *parent_sess; 437 424 errno_t rc; … … 439 426 ddf_msg(LVL_DEBUG, "Disable IRQ"); 440 427 441 parent_sess = ddf_dev_parent_sess_get(ctrl->dev); 442 443 rc = hw_res_disable_interrupt(parent_sess, ctrl->irq); 444 if (rc != EOK) { 445 ddf_msg(LVL_ERROR, "Error enabling IRQ."); 446 (void) unregister_interrupt_handler(ctrl->dev, 447 ctrl->ihandle); 428 parent_sess = ddf_dev_parent_sess_get(chan->ctrl->dev); 429 430 rc = hw_res_disable_interrupt(parent_sess, chan->irq); 431 if (rc != EOK) { 432 ddf_msg(LVL_ERROR, "Error disabling IRQ."); 448 433 return rc; 449 434 } … … 454 439 /** Add ATA device callback handler. 455 440 * 456 * @param arg Argument (isa_ide_c trl_t *)441 * @param arg Argument (isa_ide_channel_t *) 457 442 * @param idx Device index 458 443 * $param charg Connection handler argument … … 461 446 static errno_t isa_ide_add_device(void *arg, unsigned idx, void *charg) 462 447 { 463 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;464 return isa_ide_fun_create(c trl, idx, charg);448 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 449 return isa_ide_fun_create(chan, idx, charg); 465 450 } 466 451 467 452 /** Remove ATA device callback handler. 468 453 * 469 * @param arg Argument (isa_ide_c trl_t *)454 * @param arg Argument (isa_ide_channel_t *) 470 455 * @param idx Device index 471 456 * @return EOK on success or an error code … … 473 458 static errno_t isa_ide_remove_device(void *arg, unsigned idx) 474 459 { 475 isa_ide_c trl_t *ctrl = (isa_ide_ctrl_t *)arg;476 return isa_ide_fun_remove(c trl, idx);460 isa_ide_channel_t *chan = (isa_ide_channel_t *)arg; 461 return isa_ide_fun_remove(chan, idx); 477 462 } 478 463 479 464 /** Debug message callback handler. 480 465 * 481 * @param arg Argument (isa_ide_c trl_t *)466 * @param arg Argument (isa_ide_channel_t *) 482 467 * @param msg Message 483 468 */ … … 490 475 /** Notice message callback handler. 491 476 * 492 * @param arg Argument (isa_ide_c trl_t *)477 * @param arg Argument (isa_ide_channel_t *) 493 478 * @param msg Message 494 479 */ … … 501 486 /** Warning message callback handler. 502 487 * 503 * @param arg Argument (isa_ide_c trl_t *)488 * @param arg Argument (isa_ide_channel_t *) 504 489 * @param msg Message 505 490 */ … … 512 497 /** Error message callback handler. 513 498 * 514 * @param arg Argument (isa_ide_c trl_t *)499 * @param arg Argument (isa_ide_channel_t *) 515 500 * @param msg Message 516 501 */
Note:
See TracChangeset
for help on using the changeset viewer.