Changeset 59c0f478 in mainline for uspace/drv/block/isa-ide/isa-ide.c
- Timestamp:
- 2024-05-16T18:20:35Z (8 months ago)
- Branches:
- master
- Children:
- 646849b3
- Parents:
- 2791fbb7
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/isa-ide/isa-ide.c
r2791fbb7 r59c0f478 27 27 */ 28 28 29 /** @addtogroup ata_bd29 /** @addtogroup isa-ide 30 30 * @{ 31 31 */ … … 33 33 /** 34 34 * @file 35 * @brief ISA ATAdriver35 * @brief ISA IDE driver 36 36 * 37 37 * The driver services a single IDE channel. … … 52 52 #include <errno.h> 53 53 54 #include " ata_bd.h"54 #include "isa-ide.h" 55 55 #include "main.h" 56 56 57 #define NAME "ata_bd" 58 59 static errno_t ata_bd_init_io(ata_ctrl_t *ctrl); 60 static void ata_bd_fini_io(ata_ctrl_t *ctrl); 61 static errno_t ata_bd_init_irq(ata_ctrl_t *ctrl); 62 static void ata_bd_fini_irq(ata_ctrl_t *ctrl); 63 static void ata_irq_handler(ipc_call_t *call, ddf_dev_t *dev); 64 65 static void ata_write_data_16(void *, uint16_t *, size_t); 66 static void ata_read_data_16(void *, uint16_t *, size_t); 67 static void ata_write_cmd_8(void *, uint16_t, uint8_t); 68 static uint8_t ata_read_cmd_8(void *, uint16_t); 69 static void ata_write_ctl_8(void *, uint16_t, uint8_t); 70 static uint8_t ata_read_ctl_8(void *, uint16_t); 71 static errno_t ata_irq_enable(void *); 72 static errno_t ata_irq_disable(void *); 73 static errno_t ata_add_device(void *, unsigned, void *); 74 static errno_t ata_remove_device(void *, unsigned); 75 static void ata_msg_debug(void *, char *); 76 static void ata_msg_note(void *, char *); 77 static void ata_msg_warn(void *, char *); 78 static void ata_msg_error(void *, char *); 79 80 static const irq_pio_range_t ata_irq_ranges[] = { 57 static errno_t isa_ide_init_io(isa_ide_ctrl_t *ctrl); 58 static void isa_ide_fini_io(isa_ide_ctrl_t *ctrl); 59 static errno_t isa_ide_init_irq(isa_ide_ctrl_t *ctrl); 60 static void isa_ide_fini_irq(isa_ide_ctrl_t *ctrl); 61 static void isa_ide_irq_handler(ipc_call_t *call, ddf_dev_t *dev); 62 63 static void isa_ide_write_data_16(void *, uint16_t *, size_t); 64 static void isa_ide_read_data_16(void *, uint16_t *, size_t); 65 static void isa_ide_write_cmd_8(void *, uint16_t, uint8_t); 66 static uint8_t isa_ide_read_cmd_8(void *, uint16_t); 67 static void isa_ide_write_ctl_8(void *, uint16_t, uint8_t); 68 static uint8_t isa_ide_read_ctl_8(void *, uint16_t); 69 static errno_t isa_ide_irq_enable(void *); 70 static errno_t isa_ide_irq_disable(void *); 71 static errno_t isa_ide_add_device(void *, unsigned, void *); 72 static errno_t isa_ide_remove_device(void *, unsigned); 73 static void isa_ide_msg_debug(void *, char *); 74 static void isa_ide_msg_note(void *, char *); 75 static void isa_ide_msg_warn(void *, char *); 76 static void isa_ide_msg_error(void *, char *); 77 78 static const irq_pio_range_t isa_ide_irq_ranges[] = { 81 79 { 82 80 .base = 0, … … 85 83 }; 86 84 87 /** ATAinterrupt pseudo code. */88 static const irq_cmd_t ata_irq_cmds[] = {85 /** IDE interrupt pseudo code. */ 86 static const irq_cmd_t isa_ide_irq_cmds[] = { 89 87 { 90 88 .cmd = CMD_PIO_READ_8, … … 97 95 }; 98 96 99 /** Initialize ATAcontroller. */100 errno_t ata_ctrl_init(ata_ctrl_t *ctrl, ata_hwres_t *res)97 /** Initialize ISA IDE controller. */ 98 errno_t isa_ide_ctrl_init(isa_ide_ctrl_t *ctrl, isa_ide_hwres_t *res) 101 99 { 102 100 errno_t rc; … … 104 102 ata_params_t params; 105 103 106 ddf_msg(LVL_DEBUG, " ata_ctrl_init()");104 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_init()"); 107 105 108 106 fibril_mutex_initialize(&ctrl->lock); … … 115 113 116 114 ddf_msg(LVL_DEBUG, "Init I/O"); 117 rc = ata_bd_init_io(ctrl);115 rc = isa_ide_init_io(ctrl); 118 116 if (rc != EOK) 119 117 return rc; 120 118 121 119 ddf_msg(LVL_DEBUG, "Init IRQ"); 122 rc = ata_bd_init_irq(ctrl);120 rc = isa_ide_init_irq(ctrl); 123 121 if (rc != EOK) { 124 122 ddf_msg(LVL_NOTE, "init IRQ failed"); … … 128 126 irq_inited = true; 129 127 130 ddf_msg(LVL_DEBUG, " ata_ctrl_init(): Initialize ATAchannel");128 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_init(): Initialize IDE channel"); 131 129 132 130 params.arg = (void *)ctrl; 133 131 params.have_irq = (ctrl->irq >= 0) ? true : false; 134 params.write_data_16 = ata_write_data_16;135 params.read_data_16 = ata_read_data_16;136 params.write_cmd_8 = ata_write_cmd_8;137 params.read_cmd_8 = ata_read_cmd_8;138 params.write_ctl_8 = ata_write_ctl_8;139 params.read_ctl_8 = ata_read_ctl_8;140 params.irq_enable = ata_irq_enable;141 params.irq_disable = ata_irq_disable;142 params.add_device = ata_add_device;143 params.remove_device = ata_remove_device;144 params.msg_debug = ata_msg_debug;145 params.msg_note = ata_msg_note;146 params.msg_warn = ata_msg_warn;147 params.msg_error = ata_msg_error;132 params.write_data_16 = isa_ide_write_data_16; 133 params.read_data_16 = isa_ide_read_data_16; 134 params.write_cmd_8 = isa_ide_write_cmd_8; 135 params.read_cmd_8 = isa_ide_read_cmd_8; 136 params.write_ctl_8 = isa_ide_write_ctl_8; 137 params.read_ctl_8 = isa_ide_read_ctl_8; 138 params.irq_enable = isa_ide_irq_enable; 139 params.irq_disable = isa_ide_irq_disable; 140 params.add_device = isa_ide_add_device; 141 params.remove_device = isa_ide_remove_device; 142 params.msg_debug = isa_ide_msg_debug; 143 params.msg_note = isa_ide_msg_note; 144 params.msg_warn = isa_ide_msg_warn; 145 params.msg_error = isa_ide_msg_error; 148 146 149 147 rc = ata_channel_create(¶ms, &ctrl->channel); … … 155 153 goto error; 156 154 157 ddf_msg(LVL_DEBUG, " ata_ctrl_init: DONE");155 ddf_msg(LVL_DEBUG, "isa_ide_ctrl_init: DONE"); 158 156 return EOK; 159 157 error: 160 158 if (irq_inited) 161 ata_bd_fini_irq(ctrl);162 ata_bd_fini_io(ctrl);159 isa_ide_fini_irq(ctrl); 160 isa_ide_fini_io(ctrl); 163 161 return rc; 164 162 } 165 163 166 /** Remove ATAcontroller. */167 errno_t ata_ctrl_remove(ata_ctrl_t *ctrl)168 { 169 errno_t rc; 170 171 ddf_msg(LVL_DEBUG, ": ata_ctrl_remove()");164 /** Remove ISA IDE controller. */ 165 errno_t isa_ide_ctrl_remove(isa_ide_ctrl_t *ctrl) 166 { 167 errno_t rc; 168 169 ddf_msg(LVL_DEBUG, ": isa_ide_ctrl_remove()"); 172 170 173 171 fibril_mutex_lock(&ctrl->lock); … … 179 177 } 180 178 181 ata_bd_fini_irq(ctrl);182 ata_bd_fini_io(ctrl);179 isa_ide_fini_irq(ctrl); 180 isa_ide_fini_io(ctrl); 183 181 fibril_mutex_unlock(&ctrl->lock); 184 182 … … 186 184 } 187 185 188 /** Surprise removal of ATAcontroller. */189 errno_t ata_ctrl_gone(ata_ctrl_t *ctrl)190 { 191 errno_t rc; 192 193 ddf_msg(LVL_DEBUG, " ata_ctrl_gone()");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()"); 194 192 195 193 fibril_mutex_lock(&ctrl->lock); … … 201 199 } 202 200 203 ata_bd_fini_io(ctrl);201 isa_ide_fini_io(ctrl); 204 202 fibril_mutex_unlock(&ctrl->lock); 205 203 … … 208 206 209 207 /** Enable device I/O. */ 210 static errno_t ata_bd_init_io(ata_ctrl_t *ctrl)208 static errno_t isa_ide_init_io(isa_ide_ctrl_t *ctrl) 211 209 { 212 210 errno_t rc; … … 232 230 233 231 /** Clean up device I/O. */ 234 static void ata_bd_fini_io(ata_ctrl_t *ctrl)232 static void isa_ide_fini_io(isa_ide_ctrl_t *ctrl) 235 233 { 236 234 (void) ctrl; … … 239 237 240 238 /** Initialize IRQ. */ 241 static errno_t ata_bd_init_irq(ata_ctrl_t *ctrl)239 static errno_t isa_ide_init_irq(isa_ide_ctrl_t *ctrl) 242 240 { 243 241 irq_code_t irq_code; … … 249 247 return EOK; 250 248 251 ranges = malloc(sizeof( ata_irq_ranges));249 ranges = malloc(sizeof(isa_ide_irq_ranges)); 252 250 if (ranges == NULL) 253 251 return ENOMEM; 254 252 255 cmds = malloc(sizeof( ata_irq_cmds));253 cmds = malloc(sizeof(isa_ide_irq_cmds)); 256 254 if (cmds == NULL) { 257 255 free(cmds); … … 259 257 } 260 258 261 memcpy(ranges, & ata_irq_ranges, sizeof(ata_irq_ranges));259 memcpy(ranges, &isa_ide_irq_ranges, sizeof(isa_ide_irq_ranges)); 262 260 ranges[0].base = ctrl->cmd_physical; 263 memcpy(cmds, & ata_irq_cmds, sizeof(ata_irq_cmds));261 memcpy(cmds, &isa_ide_irq_cmds, sizeof(isa_ide_irq_cmds)); 264 262 cmds[0].addr = &ctrl->cmd->status; 265 263 266 irq_code.rangecount = sizeof( ata_irq_ranges) / sizeof(irq_pio_range_t);264 irq_code.rangecount = sizeof(isa_ide_irq_ranges) / sizeof(irq_pio_range_t); 267 265 irq_code.ranges = ranges; 268 irq_code.cmdcount = sizeof( ata_irq_cmds) / sizeof(irq_cmd_t);266 irq_code.cmdcount = sizeof(isa_ide_irq_cmds) / sizeof(irq_cmd_t); 269 267 irq_code.cmds = cmds; 270 268 271 269 ddf_msg(LVL_NOTE, "IRQ %d", ctrl->irq); 272 rc = register_interrupt_handler(ctrl->dev, ctrl->irq, ata_irq_handler,270 rc = register_interrupt_handler(ctrl->dev, ctrl->irq, isa_ide_irq_handler, 273 271 &irq_code, &ctrl->ihandle); 274 272 if (rc != EOK) { … … 288 286 289 287 /** Clean up IRQ. */ 290 static void ata_bd_fini_irq(ata_ctrl_t *ctrl)288 static void isa_ide_fini_irq(isa_ide_ctrl_t *ctrl) 291 289 { 292 290 errno_t rc; … … 307 305 * @param dev Device that caused the interrupt 308 306 */ 309 static void ata_irq_handler(ipc_call_t *call, ddf_dev_t *dev)310 { 311 ata_ctrl_t *ctrl = (ata_ctrl_t *)ddf_dev_data_get(dev);307 static void isa_ide_irq_handler(ipc_call_t *call, ddf_dev_t *dev) 308 { 309 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)ddf_dev_data_get(dev); 312 310 uint8_t status; 313 311 async_sess_t *parent_sess; … … 322 320 /** Write the data register callback handler. 323 321 * 324 * @param arg Argument ( ata_ctrl_t *)322 * @param arg Argument (isa_ide_ctrl_t *) 325 323 * @param data Data 326 324 * @param nwords Number of words to write 327 325 */ 328 static void ata_write_data_16(void *arg, uint16_t *data, size_t nwords)329 { 330 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;326 static void isa_ide_write_data_16(void *arg, uint16_t *data, size_t nwords) 327 { 328 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 331 329 size_t i; 332 330 … … 337 335 /** Read the data register callback handler. 338 336 * 339 * @param arg Argument ( ata_ctrl_t *)337 * @param arg Argument (isa_ide_ctrl_t *) 340 338 * @param buf Destination buffer 341 339 * @param nwords Number of words to read 342 340 */ 343 static void ata_read_data_16(void *arg, uint16_t *buf, size_t nwords)344 { 345 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;341 static void isa_ide_read_data_16(void *arg, uint16_t *buf, size_t nwords) 342 { 343 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 346 344 size_t i; 347 345 … … 352 350 /** Write command register callback handler. 353 351 * 354 * @param arg Argument ( ata_ctrl_t *)352 * @param arg Argument (isa_ide_ctrl_t *) 355 353 * @param off Register offset 356 354 * @param value Value to write to command register 357 355 */ 358 static void ata_write_cmd_8(void *arg, uint16_t off, uint8_t value)359 { 360 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;356 static void isa_ide_write_cmd_8(void *arg, uint16_t off, uint8_t value) 357 { 358 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 361 359 362 360 pio_write_8(((ioport8_t *)ctrl->cmd) + off, value); … … 365 363 /** Read command register callback handler. 366 364 * 367 * @param arg Argument ( ata_ctrl_t *)365 * @param arg Argument (isa_ide_ctrl_t *) 368 366 * @param off Register offset 369 367 * @return value Value read from command register 370 368 */ 371 static uint8_t ata_read_cmd_8(void *arg, uint16_t off)372 { 373 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;369 static uint8_t isa_ide_read_cmd_8(void *arg, uint16_t off) 370 { 371 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 374 372 375 373 return pio_read_8(((ioport8_t *)ctrl->cmd) + off); … … 378 376 /** Write control register callback handler. 379 377 * 380 * @param arg Argument ( ata_ctrl_t *)378 * @param arg Argument (isa_ide_ctrl_t *) 381 379 * @param off Register offset 382 380 * @param value Value to write to control register 383 381 */ 384 static void ata_write_ctl_8(void *arg, uint16_t off, uint8_t value)385 { 386 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;382 static void isa_ide_write_ctl_8(void *arg, uint16_t off, uint8_t value) 383 { 384 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 387 385 388 386 pio_write_8(((ioport8_t *)ctrl->ctl) + off, value); … … 391 389 /** Read control register callback handler. 392 390 * 393 * @param arg Argument ( ata_ctrl_t *)391 * @param arg Argument (isa_ide_ctrl_t *) 394 392 * @param off Register offset 395 393 * @return value Value read from control register 396 394 */ 397 static uint8_t ata_read_ctl_8(void *arg, uint16_t off)398 { 399 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;395 static uint8_t isa_ide_read_ctl_8(void *arg, uint16_t off) 396 { 397 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 400 398 401 399 return pio_read_8(((ioport8_t *)ctrl->ctl) + off); … … 404 402 /** Enable IRQ callback handler 405 403 * 406 * @param arg Argument ( ata_ctrl_t *)404 * @param arg Argument (isa_ide_ctrl_t *) 407 405 * @return EOK on success or an error code 408 406 */ 409 static errno_t ata_irq_enable(void *arg)410 { 411 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;407 static errno_t isa_ide_irq_enable(void *arg) 408 { 409 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 412 410 async_sess_t *parent_sess; 413 411 errno_t rc; … … 430 428 /** Disable IRQ callback handler 431 429 * 432 * @param arg Argument ( ata_ctrl_t *)430 * @param arg Argument (isa_ide_ctrl_t *) 433 431 * @return EOK on success or an error code 434 432 */ 435 static errno_t ata_irq_disable(void *arg)436 { 437 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;433 static errno_t isa_ide_irq_disable(void *arg) 434 { 435 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 438 436 async_sess_t *parent_sess; 439 437 errno_t rc; … … 456 454 /** Add ATA device callback handler. 457 455 * 458 * @param arg Argument ( ata_ctrl_t *)456 * @param arg Argument (isa_ide_ctrl_t *) 459 457 * @param idx Device index 460 458 * $param charg Connection handler argument 461 459 * @return EOK on success or an error code 462 460 */ 463 static errno_t ata_add_device(void *arg, unsigned idx, void *charg)464 { 465 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;466 return ata_fun_create(ctrl, idx, charg);461 static errno_t isa_ide_add_device(void *arg, unsigned idx, void *charg) 462 { 463 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 464 return isa_ide_fun_create(ctrl, idx, charg); 467 465 } 468 466 469 467 /** Remove ATA device callback handler. 470 468 * 471 * @param arg Argument ( ata_ctrl_t *)469 * @param arg Argument (isa_ide_ctrl_t *) 472 470 * @param idx Device index 473 471 * @return EOK on success or an error code 474 472 */ 475 static errno_t ata_remove_device(void *arg, unsigned idx)476 { 477 ata_ctrl_t *ctrl = (ata_ctrl_t *)arg;478 return ata_fun_remove(ctrl, idx);473 static errno_t isa_ide_remove_device(void *arg, unsigned idx) 474 { 475 isa_ide_ctrl_t *ctrl = (isa_ide_ctrl_t *)arg; 476 return isa_ide_fun_remove(ctrl, idx); 479 477 } 480 478 481 479 /** Debug message callback handler. 482 480 * 483 * @param arg Argument ( ata_ctrl_t *)481 * @param arg Argument (isa_ide_ctrl_t *) 484 482 * @param msg Message 485 483 */ 486 static void ata_msg_debug(void *arg, char *msg)484 static void isa_ide_msg_debug(void *arg, char *msg) 487 485 { 488 486 (void)arg; … … 492 490 /** Notice message callback handler. 493 491 * 494 * @param arg Argument ( ata_ctrl_t *)492 * @param arg Argument (isa_ide_ctrl_t *) 495 493 * @param msg Message 496 494 */ 497 static void ata_msg_note(void *arg, char *msg)495 static void isa_ide_msg_note(void *arg, char *msg) 498 496 { 499 497 (void)arg; … … 503 501 /** Warning message callback handler. 504 502 * 505 * @param arg Argument ( ata_ctrl_t *)503 * @param arg Argument (isa_ide_ctrl_t *) 506 504 * @param msg Message 507 505 */ 508 static void ata_msg_warn(void *arg, char *msg)506 static void isa_ide_msg_warn(void *arg, char *msg) 509 507 { 510 508 (void)arg; … … 514 512 /** Error message callback handler. 515 513 * 516 * @param arg Argument ( ata_ctrl_t *)514 * @param arg Argument (isa_ide_ctrl_t *) 517 515 * @param msg Message 518 516 */ 519 static void ata_msg_error(void *arg, char *msg)517 static void isa_ide_msg_error(void *arg, char *msg) 520 518 { 521 519 (void)arg;
Note:
See TracChangeset
for help on using the changeset viewer.