Changeset db71e2a in mainline for uspace/drv
- Timestamp:
- 2013-07-24T17:42:25Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 69b264a9
- Parents:
- 52f1882 (diff), cffa14e6 (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. - Location:
- uspace/drv
- Files:
-
- 10 added
- 24 edited
- 3 moved
-
block/ahci/ahci.c (modified) (7 diffs)
-
block/ata_bd/Makefile (added)
-
block/ata_bd/ata_bd.c (moved) (moved from uspace/srv/bd/ata_bd/ata_bd.c ) (37 diffs)
-
block/ata_bd/ata_bd.h (moved) (moved from uspace/srv/bd/ata_bd/ata_bd.h ) (3 diffs)
-
block/ata_bd/ata_bd.ma (added)
-
block/ata_bd/ata_hw.h (moved) (moved from uspace/srv/bd/ata_bd/ata_hw.h )
-
block/ata_bd/main.c (added)
-
block/ata_bd/main.h (added)
-
bus/isa/isa.dev (modified) (1 diff)
-
bus/pci/pciintel/pci.c (modified) (2 diffs)
-
bus/pci/pciintel/pci.h (modified) (1 diff)
-
bus/pci/pciintel/pci_regs.h (modified) (1 diff)
-
bus/usb/ohci/hc.c (modified) (1 diff)
-
bus/usb/ohci/hw_struct/endpoint_descriptor.c (modified) (1 diff)
-
bus/usb/ohci/hw_struct/hcca.h (modified) (1 diff)
-
bus/usb/ohci/hw_struct/transfer_descriptor.c (modified) (1 diff)
-
bus/usb/uhci/uhci_batch.c (modified) (1 diff)
-
bus/usb/usbhub/port.c (modified) (1 diff)
-
bus/usb/usbmast/scsi_ms.c (modified) (1 diff)
-
bus/usb/vhc/hub/virthubops.c (modified) (1 diff)
-
char/i8042/buffer.h (modified) (1 diff)
-
char/i8042/i8042.c (modified) (1 diff)
-
char/i8042/main.c (modified) (4 diffs)
-
char/ns8250/ns8250.c (modified) (13 diffs)
-
char/ps2mouse/main.c (modified) (1 diff)
-
char/ps2mouse/ps2mouse.c (modified) (2 diffs)
-
char/xtkbd/main.c (modified) (1 diff)
-
fb/amdm37x_dispc/Makefile (added)
-
fb/amdm37x_dispc/amdm37x_dispc.c (added)
-
fb/amdm37x_dispc/amdm37x_dispc.h (added)
-
fb/amdm37x_dispc/amdm37x_dispc.ma (added)
-
fb/amdm37x_dispc/amdm37x_dispc_regs.h (added)
-
fb/amdm37x_dispc/main.c (added)
-
infrastructure/rootamdm37x/rootamdm37x.c (modified) (1 diff)
-
nic/e1k/e1k.c (modified) (3 diffs)
-
nic/ne2k/dp8390.c (modified) (1 diff)
-
nic/rtl8139/driver.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ahci/ahci.c
r52f1882 rdb71e2a 242 242 } 243 243 244 bzero(buf, sata->block_size);244 memset(buf, 0, sata->block_size); 245 245 246 246 fibril_mutex_lock(&sata->lock); … … 444 444 } 445 445 446 bzero(idata, SATA_IDENTIFY_DEVICE_BUFFER_LENGTH);446 memset(idata, 0, SATA_IDENTIFY_DEVICE_BUFFER_LENGTH); 447 447 448 448 fibril_mutex_lock(&sata->lock); … … 637 637 } 638 638 639 bzero(idata, SATA_SET_FEATURE_BUFFER_LENGTH);639 memset(idata, 0, SATA_SET_FEATURE_BUFFER_LENGTH); 640 640 641 641 fibril_mutex_lock(&sata->lock); … … 954 954 goto error_retfis; 955 955 956 bzero(virt_fb, size);956 memset(virt_fb, 0, size); 957 957 sata->port->pxfbu = HI(phys); 958 958 sata->port->pxfb = LO(phys); … … 964 964 goto error_cmd; 965 965 966 bzero(virt_cmd, size);966 memset(virt_cmd, 0, size); 967 967 sata->port->pxclbu = HI(phys); 968 968 sata->port->pxclb = LO(phys); … … 975 975 goto error_table; 976 976 977 bzero(virt_table, size);977 memset(virt_table, 0, size); 978 978 sata->cmd_header->cmdtableu = HI(phys); 979 979 sata->cmd_header->cmdtable = LO(phys); … … 1287 1287 { 1288 1288 uint8_t model[40]; 1289 bzero(model, 40);1289 memset(model, 0, 40); 1290 1290 1291 1291 for (unsigned int i = 0; i < 20; i++) { -
uspace/drv/block/ata_bd/ata_bd.c
r52f1882 rdb71e2a 1 1 /* 2 * Copyright (c) 20 09Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 35 35 * @brief ATA disk driver 36 36 * 37 * This driver supports CHS, 28-bit and 48-bit LBA addressing . It only uses38 * P IO transfers. There is no support DMA, the PACKET feature set or any other39 * fancy features such as S.M.A.R.T, removable devices, etc.37 * This driver supports CHS, 28-bit and 48-bit LBA addressing, as well as 38 * PACKET devices. It only uses PIO transfers. There is no support DMA 39 * or any other fancy features such as S.M.A.R.T, removable devices, etc. 40 40 * 41 41 * This driver is based on the ATA-1, ATA-2, ATA-3 and ATA/ATAPI-4 through 7 … … 48 48 */ 49 49 50 #include <stdio.h>51 50 #include <ddi.h> 51 #include <ddf/log.h> 52 52 #include <async.h> 53 53 #include <as.h> … … 61 61 #include <errno.h> 62 62 #include <stdbool.h> 63 #include <stdio.h> 63 64 #include <byteorder.h> 64 65 #include <task.h> … … 67 68 #include "ata_hw.h" 68 69 #include "ata_bd.h" 70 #include "main.h" 69 71 70 72 #define NAME "ata_bd" … … 80 82 static const size_t identify_data_size = 512; 81 83 82 /** I/O base address of the command registers. */ 83 static uintptr_t cmd_physical; 84 /** I/O base address of the control registers. */ 85 static uintptr_t ctl_physical; 86 87 /** I/O base addresses for legacy (ISA-compatible) controllers. */ 88 static ata_base_t legacy_base[LEGACY_CTLS] = { 89 { 0x1f0, 0x3f0 }, 90 { 0x170, 0x370 }, 91 { 0x1e8, 0x3e8 }, 92 { 0x168, 0x368 } 93 }; 94 95 static ata_cmd_t *cmd; 96 static ata_ctl_t *ctl; 97 98 /** Per-disk state. */ 99 static disk_t ata_disk[MAX_DISKS]; 100 101 static void print_syntax(void); 102 static int ata_bd_init(void); 103 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *); 84 static int ata_bd_init_io(ata_ctrl_t *ctrl); 85 static void ata_bd_fini_io(ata_ctrl_t *ctrl); 104 86 105 87 static int ata_bd_open(bd_srvs_t *, bd_srv_t *); … … 117 99 static int ata_rcmd_write(disk_t *disk, uint64_t ba, size_t cnt, 118 100 const void *buf); 119 static int disk_init( disk_t *d, int disk_id);120 static int drive_identify(disk_t *disk, void *buf);121 static int identify_pkt_dev(disk_t *disk, void *buf);101 static int disk_init(ata_ctrl_t *ctrl, disk_t *d, int disk_id); 102 static int ata_identify_dev(disk_t *disk, void *buf); 103 static int ata_identify_pkt_dev(disk_t *disk, void *buf); 122 104 static int ata_cmd_packet(disk_t *disk, const void *cpkt, size_t cpkt_size, 123 105 void *obuf, size_t obuf_size); … … 129 111 static void disk_print_summary(disk_t *d); 130 112 static int coord_calc(disk_t *d, uint64_t ba, block_coord_t *bc); 131 static void coord_sc_program(const block_coord_t *bc, uint16_t scnt); 132 static int wait_status(unsigned set, unsigned n_reset, uint8_t *pstatus, 133 unsigned timeout); 134 135 static bd_ops_t ata_bd_ops = { 113 static void coord_sc_program(ata_ctrl_t *ctrl, const block_coord_t *bc, 114 uint16_t scnt); 115 static int wait_status(ata_ctrl_t *ctrl, unsigned set, unsigned n_reset, 116 uint8_t *pstatus, unsigned timeout); 117 118 bd_ops_t ata_bd_ops = { 136 119 .open = ata_bd_open, 137 120 .close = ata_bd_close, … … 153 136 } 154 137 155 int main(int argc, char **argv) 156 { 157 char name[16]; 138 /** Initialize ATA controller. */ 139 int ata_ctrl_init(ata_ctrl_t *ctrl, ata_base_t *res) 140 { 158 141 int i, rc; 159 142 int n_disks; 160 unsigned ctl_num; 161 char *eptr; 162 163 printf(NAME ": ATA disk driver\n"); 164 165 if (argc > 1) { 166 ctl_num = strtoul(argv[1], &eptr, 0); 167 if (*eptr != '\0' || ctl_num == 0 || ctl_num > 4) { 168 printf("Invalid argument.\n"); 169 print_syntax(); 170 return -1; 171 } 172 } else { 173 ctl_num = 1; 174 } 175 176 cmd_physical = legacy_base[ctl_num - 1].cmd; 177 ctl_physical = legacy_base[ctl_num - 1].ctl; 178 179 printf("I/O address %p/%p\n", (void *) cmd_physical, 180 (void *) ctl_physical); 181 182 if (ata_bd_init() != EOK) 183 return -1; 143 144 ddf_msg(LVL_DEBUG, "ata_ctrl_init()"); 145 146 fibril_mutex_initialize(&ctrl->lock); 147 ctrl->cmd_physical = res->cmd; 148 ctrl->ctl_physical = res->ctl; 149 150 ddf_msg(LVL_NOTE, "I/O address %p/%p", (void *) ctrl->cmd_physical, 151 (void *) ctrl->ctl_physical); 152 153 rc = ata_bd_init_io(ctrl); 154 if (rc != EOK) 155 return rc; 184 156 185 157 for (i = 0; i < MAX_DISKS; i++) { 186 printf("Identify drive %d... ", i); 187 fflush(stdout); 188 189 rc = disk_init(&ata_disk[i], i); 158 ddf_msg(LVL_NOTE, "Identify drive %d...", i); 159 160 rc = disk_init(ctrl, &ctrl->disk[i], i); 190 161 191 162 if (rc == EOK) { 192 disk_print_summary(& ata_disk[i]);163 disk_print_summary(&ctrl->disk[i]); 193 164 } else { 194 printf("Not found.\n");165 ddf_msg(LVL_NOTE, "Not found."); 195 166 } 196 167 } … … 200 171 for (i = 0; i < MAX_DISKS; i++) { 201 172 /* Skip unattached drives. */ 202 if ( ata_disk[i].present == false)173 if (ctrl->disk[i].present == false) 203 174 continue; 204 205 snprintf(name, 16, "%s/ata%udisk%d", NAMESPACE, ctl_num, i); 206 rc = loc_service_register(name, &ata_disk[i].service_id); 175 176 rc = ata_fun_create(&ctrl->disk[i]); 207 177 if (rc != EOK) { 208 printf(NAME ": Unable to register device %s.\n", name); 178 ddf_msg(LVL_ERROR, "Unable to create function for " 179 "disk %d.", i); 180 goto error; 181 } 182 ++n_disks; 183 } 184 185 if (n_disks == 0) { 186 ddf_msg(LVL_WARN, "No disks detected."); 187 rc = EIO; 188 goto error; 189 } 190 191 return EOK; 192 error: 193 for (i = 0; i < MAX_DISKS; i++) { 194 if (ata_fun_remove(&ctrl->disk[i]) != EOK) { 195 ddf_msg(LVL_ERROR, "Unable to clean up function for " 196 "disk %d.", i); 197 } 198 } 199 ata_bd_fini_io(ctrl); 200 return rc; 201 } 202 203 /** Remove ATA controller. */ 204 int ata_ctrl_remove(ata_ctrl_t *ctrl) 205 { 206 int i, rc; 207 208 ddf_msg(LVL_DEBUG, ": ata_ctrl_remove()"); 209 210 fibril_mutex_lock(&ctrl->lock); 211 212 for (i = 0; i < MAX_DISKS; i++) { 213 rc = ata_fun_remove(&ctrl->disk[i]); 214 if (rc != EOK) { 215 ddf_msg(LVL_ERROR, "Unable to clean up function for " 216 "disk %d.", i); 209 217 return rc; 210 218 } 211 ++n_disks; 212 } 213 214 if (n_disks == 0) { 215 printf("No disks detected.\n"); 216 return -1; 217 } 218 219 printf("%s: Accepting connections\n", NAME); 220 task_retval(0); 221 async_manager(); 222 223 /* Not reached */ 224 return 0; 225 } 226 227 228 static void print_syntax(void) 229 { 230 printf("Syntax: " NAME " <controller_number>\n"); 231 printf("Controller number = 1..4\n"); 219 } 220 221 ata_bd_fini_io(ctrl); 222 fibril_mutex_unlock(&ctrl->lock); 223 224 return EOK; 225 } 226 227 /** Surprise removal of ATA controller. */ 228 int ata_ctrl_gone(ata_ctrl_t *ctrl) 229 { 230 int i, rc; 231 232 ddf_msg(LVL_DEBUG, "ata_ctrl_gone()"); 233 234 fibril_mutex_lock(&ctrl->lock); 235 236 for (i = 0; i < MAX_DISKS; i++) { 237 rc = ata_fun_unbind(&ctrl->disk[i]); 238 if (rc != EOK) { 239 ddf_msg(LVL_ERROR, "Unable to clean up function for " 240 "disk %d.", i); 241 return rc; 242 } 243 } 244 245 ata_bd_fini_io(ctrl); 246 fibril_mutex_unlock(&ctrl->lock); 247 248 return EOK; 232 249 } 233 250 … … 236 253 { 237 254 uint64_t mbytes; 238 239 printf("%s: ", d->model); 255 char *atype = NULL; 256 char *cap = NULL; 257 int rc; 240 258 241 259 if (d->dev_type == ata_reg_dev) { 242 260 switch (d->amode) { 243 261 case am_chs: 244 printf("CHS %u cylinders, %u heads, %u sectors",245 d->geom.cylinders, d->geom.heads,262 rc = asprintf(&atype, "CHS %u cylinders, %u heads, " 263 "%u sectors", d->geom.cylinders, d->geom.heads, 246 264 d->geom.sectors); 265 if (rc < 0) { 266 /* Out of memory */ 267 atype = NULL; 268 } 247 269 break; 248 270 case am_lba28: 249 printf("LBA-28");271 atype = str_dup("LBA-28"); 250 272 break; 251 273 case am_lba48: 252 printf("LBA-48");274 atype = str_dup("LBA-48"); 253 275 break; 254 276 } 255 277 } else { 256 printf("PACKET"); 257 } 258 259 printf(" %" PRIu64 " blocks", d->blocks); 278 atype = str_dup("PACKET"); 279 } 280 281 if (atype == NULL) 282 return; 260 283 261 284 mbytes = d->blocks / (2 * 1024); 262 if (mbytes > 0) 263 printf(" %" PRIu64 " MB.", mbytes); 264 265 printf("\n"); 266 } 267 268 /** Register driver and enable device I/O. */ 269 static int ata_bd_init(void) 270 { 271 async_set_client_connection(ata_bd_connection); 272 int rc = loc_server_register(NAME); 285 if (mbytes > 0) { 286 rc = asprintf(&cap, " %" PRIu64 " MB.", mbytes); 287 if (rc < 0) { 288 cap = NULL; 289 goto cleanup; 290 } 291 } 292 293 ddf_msg(LVL_NOTE, "%s: %s %" PRIu64 " blocks%s", d->model, atype, 294 d->blocks, cap); 295 cleanup: 296 free(atype); 297 free(cap); 298 } 299 300 /** Enable device I/O. */ 301 static int ata_bd_init_io(ata_ctrl_t *ctrl) 302 { 303 int rc; 304 void *vaddr; 305 306 rc = pio_enable((void *) ctrl->cmd_physical, sizeof(ata_cmd_t), &vaddr); 273 307 if (rc != EOK) { 274 printf("%s: Unable to register driver.\n", NAME);308 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space."); 275 309 return rc; 276 310 } 277 278 void *vaddr; 279 rc = pio_enable((void *) cmd_physical, sizeof(ata_cmd_t), &vaddr); 311 312 ctrl->cmd = vaddr; 313 314 rc = pio_enable((void *) ctrl->ctl_physical, sizeof(ata_ctl_t), &vaddr); 280 315 if (rc != EOK) { 281 printf("%s: Could not initialize device I/O space.\n", NAME);316 ddf_msg(LVL_ERROR, "Cannot initialize device I/O space."); 282 317 return rc; 283 318 } 284 285 cmd = vaddr; 286 287 rc = pio_enable((void *) ctl_physical, sizeof(ata_ctl_t), &vaddr); 288 if (rc != EOK) { 289 printf("%s: Could not initialize device I/O space.\n", NAME); 290 return rc; 291 } 292 293 ctl = vaddr; 294 295 return EOK; 296 } 297 298 /** Block device connection handler */ 299 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 300 { 301 service_id_t dsid; 302 int i; 303 disk_t *disk; 304 305 /* Get the device service ID. */ 306 dsid = IPC_GET_ARG1(*icall); 307 308 /* Determine which disk device is the client connecting to. */ 309 disk = NULL; 310 for (i = 0; i < MAX_DISKS; i++) 311 if (ata_disk[i].service_id == dsid) 312 disk = &ata_disk[i]; 313 314 if (disk == NULL || disk->present == false) { 315 async_answer_0(iid, EINVAL); 316 return; 317 } 318 319 bd_conn(iid, icall, &disk->bds); 319 320 ctrl->ctl = vaddr; 321 322 return EOK; 323 } 324 325 /** Clean up device I/O. */ 326 static void ata_bd_fini_io(ata_ctrl_t *ctrl) 327 { 328 (void) ctrl; 329 /* XXX TODO */ 320 330 } 321 331 … … 325 335 * the disk structure. 326 336 */ 327 static int disk_init( disk_t *d, int disk_id)337 static int disk_init(ata_ctrl_t *ctrl, disk_t *d, int disk_id) 328 338 { 329 339 identify_data_t idata; … … 337 347 unsigned i; 338 348 349 d->ctrl = ctrl; 339 350 d->disk_id = disk_id; 340 351 d->present = false; 341 fibril_mutex_initialize(&d->lock); 342 343 bd_srvs_init(&d->bds); 344 d->bds.ops = &ata_bd_ops; 345 d->bds.sarg = d; 352 d->afun = NULL; 346 353 347 354 /* Try identify command. */ 348 rc = drive_identify(d, &idata);355 rc = ata_identify_dev(d, &idata); 349 356 if (rc == EOK) { 350 357 /* Success. It's a register (non-packet) device. */ 351 printf("ATA register-only device found.\n");358 ddf_msg(LVL_NOTE, "ATA register-only device found."); 352 359 d->dev_type = ata_reg_dev; 353 360 } else if (rc == EIO) { … … 362 369 * the byte count registers. So, only check these. 363 370 */ 364 bc = ((uint16_t)pio_read_8(&c md->cylinder_high) << 8) |365 pio_read_8(&c md->cylinder_low);371 bc = ((uint16_t)pio_read_8(&ctrl->cmd->cylinder_high) << 8) | 372 pio_read_8(&ctrl->cmd->cylinder_low); 366 373 367 374 if (bc == PDEV_SIGNATURE_BC) { 368 rc = identify_pkt_dev(d, &idata);375 rc = ata_identify_pkt_dev(d, &idata); 369 376 if (rc == EOK) { 370 377 /* We have a packet device. */ … … 452 459 rc = ata_pcmd_inquiry(d, &inq_data, sizeof(inq_data)); 453 460 if (rc != EOK) { 454 printf("Device inquiry failed.\n");461 ddf_msg(LVL_ERROR, "Device inquiry failed."); 455 462 d->present = false; 456 463 return EIO; … … 459 466 /* Check device type. */ 460 467 if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM) 461 printf("Warning: Peripheral device type is not CD-ROM.\n");468 ddf_msg(LVL_WARN, "Peripheral device type is not CD-ROM."); 462 469 463 470 /* Assume 2k block size for now. */ … … 563 570 } 564 571 565 /** Issue IDENTIFY command. 572 /** PIO data-in command protocol. */ 573 static int ata_pio_data_in(disk_t *disk, void *obuf, size_t obuf_size, 574 size_t blk_size, size_t nblocks) 575 { 576 ata_ctrl_t *ctrl = disk->ctrl; 577 uint16_t data; 578 size_t i; 579 uint8_t status; 580 581 /* XXX Support multiple blocks */ 582 assert(nblocks == 1); 583 assert(blk_size % 2 == 0); 584 585 if (wait_status(ctrl, 0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) 586 return EIO; 587 588 if ((status & SR_DRQ) != 0) { 589 /* Read data from the device buffer. */ 590 591 for (i = 0; i < blk_size / 2; i++) { 592 data = pio_read_16(&ctrl->cmd->data_port); 593 ((uint16_t *) obuf)[i] = data; 594 } 595 } 596 597 if ((status & SR_ERR) != 0) 598 return EIO; 599 600 return EOK; 601 } 602 603 /** PIO data-out command protocol. */ 604 static int ata_pio_data_out(disk_t *disk, const void *buf, size_t buf_size, 605 size_t blk_size, size_t nblocks) 606 { 607 ata_ctrl_t *ctrl = disk->ctrl; 608 size_t i; 609 uint8_t status; 610 611 /* XXX Support multiple blocks */ 612 assert(nblocks == 1); 613 assert(blk_size % 2 == 0); 614 615 if (wait_status(ctrl, 0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) 616 return EIO; 617 618 if ((status & SR_DRQ) != 0) { 619 /* Write data to the device buffer. */ 620 621 for (i = 0; i < blk_size / 2; i++) { 622 pio_write_16(&ctrl->cmd->data_port, ((uint16_t *) buf)[i]); 623 } 624 } 625 626 if (status & SR_ERR) 627 return EIO; 628 629 return EOK; 630 } 631 632 /** Issue IDENTIFY DEVICE command. 566 633 * 567 634 * Reads @c identify data into the provided buffer. This is used to detect … … 574 641 * not present). EIO if device responds with error. 575 642 */ 576 static int drive_identify(disk_t *disk, void *buf)577 { 578 uint16_t data;643 static int ata_identify_dev(disk_t *disk, void *buf) 644 { 645 ata_ctrl_t *ctrl = disk->ctrl; 579 646 uint8_t status; 580 647 uint8_t drv_head; 581 size_t i;582 648 583 649 drv_head = ((disk_dev_idx(disk) != 0) ? DHR_DRV : 0); 584 650 585 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)651 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 586 652 return ETIMEOUT; 587 653 588 pio_write_8(&c md->drive_head, drv_head);654 pio_write_8(&ctrl->cmd->drive_head, drv_head); 589 655 590 656 /* … … 593 659 * set after issuing the command. 594 660 */ 595 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)661 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 596 662 return ETIMEOUT; 597 663 598 pio_write_8(&c md->command, CMD_IDENTIFY_DRIVE);599 600 if (wait_status( 0, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK)664 pio_write_8(&ctrl->cmd->command, CMD_IDENTIFY_DRIVE); 665 666 if (wait_status(ctrl, 0, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK) 601 667 return ETIMEOUT; 602 668 … … 605 671 * the caller to check for one. 606 672 */ 607 if ((status & SR_ERR) != 0) { 608 return EIO; 609 } 610 611 if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK) 673 if ((status & SR_ERR) != 0) 674 return EIO; 675 676 /* 677 * For probing purposes we need to wait for some status bit to become 678 * active - otherwise we could be fooled just by receiving all zeroes. 679 */ 680 if (wait_status(ctrl, SR_DRQ, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK) 612 681 return ETIMEOUT; 613 682 614 /* Read data from the disk buffer. */ 615 616 for (i = 0; i < identify_data_size / 2; i++) { 617 data = pio_read_16(&cmd->data_port); 618 ((uint16_t *) buf)[i] = data; 619 } 620 621 return EOK; 683 return ata_pio_data_in(disk, buf, identify_data_size, 684 identify_data_size, 1); 622 685 } 623 686 … … 630 693 * @param buf Pointer to a 512-byte buffer. 631 694 */ 632 static int identify_pkt_dev(disk_t *disk, void *buf) 633 { 634 uint16_t data; 635 uint8_t status; 695 static int ata_identify_pkt_dev(disk_t *disk, void *buf) 696 { 697 ata_ctrl_t *ctrl = disk->ctrl; 636 698 uint8_t drv_head; 637 size_t i;638 699 639 700 drv_head = ((disk_dev_idx(disk) != 0) ? DHR_DRV : 0); 640 701 641 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)642 return EIO; 643 644 pio_write_8(&c md->drive_head, drv_head);702 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 703 return EIO; 704 705 pio_write_8(&ctrl->cmd->drive_head, drv_head); 645 706 646 707 /* For ATAPI commands we do not need to wait for DRDY. */ 647 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 648 return EIO; 649 650 pio_write_8(&cmd->command, CMD_IDENTIFY_PKT_DEV); 651 652 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) 653 return EIO; 654 655 /* Read data from the device buffer. */ 656 657 if ((status & SR_DRQ) != 0) { 658 for (i = 0; i < identify_data_size / 2; i++) { 659 data = pio_read_16(&cmd->data_port); 660 ((uint16_t *) buf)[i] = data; 661 } 662 } 663 664 if ((status & SR_ERR) != 0) 665 return EIO; 666 667 return EOK; 708 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 709 return EIO; 710 711 pio_write_8(&ctrl->cmd->command, CMD_IDENTIFY_PKT_DEV); 712 713 return ata_pio_data_in(disk, buf, identify_data_size, 714 identify_data_size, 1); 668 715 } 669 716 … … 681 728 void *obuf, size_t obuf_size) 682 729 { 730 ata_ctrl_t *ctrl = disk->ctrl; 683 731 size_t i; 684 732 uint8_t status; … … 687 735 uint16_t val; 688 736 689 fibril_mutex_lock(& disk->lock);737 fibril_mutex_lock(&ctrl->lock); 690 738 691 739 /* New value for Drive/Head register */ … … 693 741 ((disk_dev_idx(disk) != 0) ? DHR_DRV : 0); 694 742 695 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) {696 fibril_mutex_unlock(& disk->lock);697 return EIO; 698 } 699 700 pio_write_8(&c md->drive_head, drv_head);701 702 if (wait_status( 0, ~(SR_BSY|SR_DRQ), NULL, TIMEOUT_BSY) != EOK) {703 fibril_mutex_unlock(& disk->lock);743 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) { 744 fibril_mutex_unlock(&ctrl->lock); 745 return EIO; 746 } 747 748 pio_write_8(&ctrl->cmd->drive_head, drv_head); 749 750 if (wait_status(ctrl, 0, ~(SR_BSY|SR_DRQ), NULL, TIMEOUT_BSY) != EOK) { 751 fibril_mutex_unlock(&ctrl->lock); 704 752 return EIO; 705 753 } 706 754 707 755 /* Byte count <- max. number of bytes we can read in one transfer. */ 708 pio_write_8(&c md->cylinder_low, 0xfe);709 pio_write_8(&c md->cylinder_high, 0xff);710 711 pio_write_8(&c md->command, CMD_PACKET);712 713 if (wait_status( SR_DRQ, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {714 fibril_mutex_unlock(& disk->lock);756 pio_write_8(&ctrl->cmd->cylinder_low, 0xfe); 757 pio_write_8(&ctrl->cmd->cylinder_high, 0xff); 758 759 pio_write_8(&ctrl->cmd->command, CMD_PACKET); 760 761 if (wait_status(ctrl, SR_DRQ, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) { 762 fibril_mutex_unlock(&ctrl->lock); 715 763 return EIO; 716 764 } … … 718 766 /* Write command packet. */ 719 767 for (i = 0; i < (cpkt_size + 1) / 2; i++) 720 pio_write_16(&c md->data_port, ((uint16_t *) cpkt)[i]);721 722 if (wait_status( 0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) {723 fibril_mutex_unlock(& disk->lock);768 pio_write_16(&ctrl->cmd->data_port, ((uint16_t *) cpkt)[i]); 769 770 if (wait_status(ctrl, 0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) { 771 fibril_mutex_unlock(&ctrl->lock); 724 772 return EIO; 725 773 } 726 774 727 775 if ((status & SR_DRQ) == 0) { 728 fibril_mutex_unlock(& disk->lock);776 fibril_mutex_unlock(&ctrl->lock); 729 777 return EIO; 730 778 } 731 779 732 780 /* Read byte count. */ 733 data_size = (uint16_t) pio_read_8(&c md->cylinder_low) +734 ((uint16_t) pio_read_8(&c md->cylinder_high) << 8);781 data_size = (uint16_t) pio_read_8(&ctrl->cmd->cylinder_low) + 782 ((uint16_t) pio_read_8(&ctrl->cmd->cylinder_high) << 8); 735 783 736 784 /* Check whether data fits into output buffer. */ 737 785 if (data_size > obuf_size) { 738 786 /* Output buffer is too small to store data. */ 739 fibril_mutex_unlock(& disk->lock);787 fibril_mutex_unlock(&ctrl->lock); 740 788 return EIO; 741 789 } … … 743 791 /* Read data from the device buffer. */ 744 792 for (i = 0; i < (data_size + 1) / 2; i++) { 745 val = pio_read_16(&c md->data_port);793 val = pio_read_16(&ctrl->cmd->data_port); 746 794 ((uint16_t *) obuf)[i] = val; 747 795 } 748 796 749 if (status & SR_ERR) { 750 fibril_mutex_unlock(&disk->lock); 751 return EIO; 752 } 753 754 fibril_mutex_unlock(&disk->lock); 797 fibril_mutex_unlock(&ctrl->lock); 798 799 if (status & SR_ERR) 800 return EIO; 755 801 756 802 return EOK; … … 849 895 cp.oldformat = 0x40; /* 0x01 = multi-session mode (shifted to MSB) */ 850 896 851 rc = ata_cmd_packet( 0, &cp, sizeof(cp), obuf, obuf_size);897 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size); 852 898 if (rc != EOK) 853 899 return rc; … … 856 902 } 857 903 858 /** Read a physical from the device.904 /** Read a physical block from the device. 859 905 * 860 906 * @param disk Disk … … 868 914 void *buf) 869 915 { 870 size_t i; 871 uint16_t data; 872 uint8_t status; 916 ata_ctrl_t *ctrl = disk->ctrl; 873 917 uint8_t drv_head; 874 918 block_coord_t bc; 919 int rc; 875 920 876 921 /* Silence warning. */ … … 887 932 (bc.h & 0x0f); 888 933 889 fibril_mutex_lock(& disk->lock);934 fibril_mutex_lock(&ctrl->lock); 890 935 891 936 /* Program a Read Sectors operation. */ 892 937 893 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) {894 fibril_mutex_unlock(& disk->lock);895 return EIO; 896 } 897 898 pio_write_8(&c md->drive_head, drv_head);899 900 if (wait_status( SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) {901 fibril_mutex_unlock(& disk->lock);938 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) { 939 fibril_mutex_unlock(&ctrl->lock); 940 return EIO; 941 } 942 943 pio_write_8(&ctrl->cmd->drive_head, drv_head); 944 945 if (wait_status(ctrl, SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) { 946 fibril_mutex_unlock(&ctrl->lock); 902 947 return EIO; 903 948 } 904 949 905 950 /* Program block coordinates into the device. */ 906 coord_sc_program( &bc, 1);907 908 pio_write_8(&c md->command, disk->amode == am_lba48 ?951 coord_sc_program(ctrl, &bc, 1); 952 953 pio_write_8(&ctrl->cmd->command, disk->amode == am_lba48 ? 909 954 CMD_READ_SECTORS_EXT : CMD_READ_SECTORS); 910 955 911 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) { 912 fibril_mutex_unlock(&disk->lock); 913 return EIO; 914 } 915 916 if ((status & SR_DRQ) != 0) { 917 /* Read data from the device buffer. */ 918 919 for (i = 0; i < disk->block_size / 2; i++) { 920 data = pio_read_16(&cmd->data_port); 921 ((uint16_t *) buf)[i] = data; 922 } 923 } 924 925 if ((status & SR_ERR) != 0) 926 return EIO; 927 928 fibril_mutex_unlock(&disk->lock); 929 return EOK; 956 rc = ata_pio_data_in(disk, buf, blk_cnt * disk->block_size, 957 disk->block_size, blk_cnt); 958 959 fibril_mutex_unlock(&ctrl->lock); 960 961 return rc; 930 962 } 931 963 … … 942 974 const void *buf) 943 975 { 944 size_t i; 945 uint8_t status; 976 ata_ctrl_t *ctrl = disk->ctrl; 946 977 uint8_t drv_head; 947 978 block_coord_t bc; 979 int rc; 948 980 949 981 /* Silence warning. */ … … 960 992 (bc.h & 0x0f); 961 993 962 fibril_mutex_lock(& disk->lock);994 fibril_mutex_lock(&ctrl->lock); 963 995 964 996 /* Program a Write Sectors operation. */ 965 997 966 if (wait_status( 0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) {967 fibril_mutex_unlock(& disk->lock);968 return EIO; 969 } 970 971 pio_write_8(&c md->drive_head, drv_head);972 973 if (wait_status( SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) {974 fibril_mutex_unlock(& disk->lock);998 if (wait_status(ctrl, 0, ~SR_BSY, NULL, TIMEOUT_BSY) != EOK) { 999 fibril_mutex_unlock(&ctrl->lock); 1000 return EIO; 1001 } 1002 1003 pio_write_8(&ctrl->cmd->drive_head, drv_head); 1004 1005 if (wait_status(ctrl, SR_DRDY, ~SR_BSY, NULL, TIMEOUT_DRDY) != EOK) { 1006 fibril_mutex_unlock(&ctrl->lock); 975 1007 return EIO; 976 1008 } 977 1009 978 1010 /* Program block coordinates into the device. */ 979 coord_sc_program( &bc, 1);980 981 pio_write_8(&c md->command, disk->amode == am_lba48 ?1011 coord_sc_program(ctrl, &bc, 1); 1012 1013 pio_write_8(&ctrl->cmd->command, disk->amode == am_lba48 ? 982 1014 CMD_WRITE_SECTORS_EXT : CMD_WRITE_SECTORS); 983 1015 984 if (wait_status(0, ~SR_BSY, &status, TIMEOUT_BSY) != EOK) { 985 fibril_mutex_unlock(&disk->lock); 986 return EIO; 987 } 988 989 if ((status & SR_DRQ) != 0) { 990 /* Write data to the device buffer. */ 991 992 for (i = 0; i < disk->block_size / 2; i++) { 993 pio_write_16(&cmd->data_port, ((uint16_t *) buf)[i]); 994 } 995 } 996 997 fibril_mutex_unlock(&disk->lock); 998 999 if (status & SR_ERR) 1000 return EIO; 1001 1002 return EOK; 1016 rc = ata_pio_data_out(disk, buf, cnt * disk->block_size, 1017 disk->block_size, cnt); 1018 1019 fibril_mutex_unlock(&ctrl->lock); 1020 return rc; 1003 1021 } 1004 1022 … … 1060 1078 * 1061 1079 * Note that bc->h must be programmed separately into the device/head register. 1062 */ 1063 static void coord_sc_program(const block_coord_t *bc, uint16_t scnt) 1064 { 1080 * 1081 * @param ctrl Controller 1082 * @param bc Block coordinates 1083 * @param scnt Sector count 1084 */ 1085 static void coord_sc_program(ata_ctrl_t *ctrl, const block_coord_t *bc, 1086 uint16_t scnt) 1087 { 1088 ata_cmd_t *cmd = ctrl->cmd; 1089 1065 1090 if (bc->amode == am_lba48) { 1066 1091 /* Write high-order bits. */ … … 1080 1105 /** Wait until some status bits are set and some are reset. 1081 1106 * 1082 * Example: wait_status( SR_DRDY, ~SR_BSY) waits for SR_DRDY to become1107 * Example: wait_status(ctrl, SR_DRDY, ~SR_BSY, ...) waits for SR_DRDY to become 1083 1108 * set and SR_BSY to become reset. 1084 1109 * 1110 * @param ctrl Controller 1085 1111 * @param set Combination if bits which must be all set. 1086 1112 * @param n_reset Negated combination of bits which must be all reset. … … 1090 1116 * @return EOK on success, EIO on timeout. 1091 1117 */ 1092 static int wait_status( unsigned set, unsigned n_reset, uint8_t *pstatus,1093 u nsigned timeout)1118 static int wait_status(ata_ctrl_t *ctrl, unsigned set, unsigned n_reset, 1119 uint8_t *pstatus, unsigned timeout) 1094 1120 { 1095 1121 uint8_t status; 1096 1122 int cnt; 1097 1123 1098 status = pio_read_8(&c md->status);1124 status = pio_read_8(&ctrl->cmd->status); 1099 1125 1100 1126 /* … … 1110 1136 if (cnt <= 0) break; 1111 1137 1112 status = pio_read_8(&c md->status);1138 status = pio_read_8(&ctrl->cmd->status); 1113 1139 } 1114 1140 … … 1119 1145 if (cnt <= 0) break; 1120 1146 1121 status = pio_read_8(&c md->status);1147 status = pio_read_8(&ctrl->cmd->status); 1122 1148 } 1123 1149 -
uspace/drv/block/ata_bd/ata_bd.h
r52f1882 rdb71e2a 36 36 #define __ATA_BD_H__ 37 37 38 #include <async.h> 38 39 #include <bd_srv.h> 40 #include <ddf/driver.h> 39 41 #include <sys/types.h> 40 42 #include <fibril_synch.h> 41 43 #include <str.h> 44 #include "ata_hw.h" 45 46 #define NAME "ata_bd" 42 47 43 48 /** Base addresses for ATA I/O blocks. */ … … 95 100 typedef struct { 96 101 bool present; 102 struct ata_ctrl *ctrl; 103 struct ata_fun *afun; 97 104 98 105 /** Device type */ … … 116 123 char model[STR_BOUNDS(40) + 1]; 117 124 125 int disk_id; 126 } disk_t; 127 128 /** ATA controller */ 129 typedef struct ata_ctrl { 130 /** DDF device */ 131 ddf_dev_t *dev; 132 /** I/O base address of the command registers */ 133 uintptr_t cmd_physical; 134 /** I/O base address of the control registers */ 135 uintptr_t ctl_physical; 136 137 /** Command registers */ 138 ata_cmd_t *cmd; 139 /** Control registers */ 140 ata_ctl_t *ctl; 141 142 /** Per-disk state. */ 143 disk_t disk[MAX_DISKS]; 144 118 145 fibril_mutex_t lock; 119 service_id_t service_id; 120 int disk_id; 146 } ata_ctrl_t; 147 148 typedef struct ata_fun { 149 ddf_fun_t *fun; 150 disk_t *disk; 121 151 bd_srvs_t bds; 122 } disk_t; 152 } ata_fun_t; 153 154 extern int ata_ctrl_init(ata_ctrl_t *, ata_base_t *); 155 extern int ata_ctrl_remove(ata_ctrl_t *); 156 extern int ata_ctrl_gone(ata_ctrl_t *); 157 158 extern bd_ops_t ata_bd_ops; 123 159 124 160 #endif -
uspace/drv/bus/isa/isa.dev
r52f1882 rdb71e2a 31 31 match 100 isa/cmos-rtc 32 32 io_range 70 2 33 34 ata-c1: 35 match 100 isa/ata_bd 36 io_range 0x1f0 8 37 io_range 0x3f0 8 38 39 ata-c2: 40 match 100 isa/ata_bd 41 io_range 0x170 8 42 io_range 0x370 8 43 44 ata-c3: 45 match 100 isa/ata_bd 46 io_range 0x1e8 8 47 io_range 0x3e8 8 48 49 ata-c4: 50 match 100 isa/ata_bd 51 io_range 0x168 8 52 io_range 0x368 8 -
uspace/drv/bus/pci/pciintel/pci.c
r52f1882 rdb71e2a 327 327 328 328 /* Vendor ID & Device ID, length(incl \0) 22 */ 329 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04 x&dev=%04x",330 fun->vendor_id, fun->device_id);329 rc = snprintf(match_id_str, ID_MAX_STR_LEN, "pci/ven=%04" 330 PRIx16 "&dev=%04" PRIx16, fun->vendor_id, fun->device_id); 331 331 if (rc < 0) { 332 332 ddf_msg(LVL_ERROR, "Failed creating match ID str: %s", … … 758 758 fun->vendor_id = pci_conf_read_16(fun, PCI_VENDOR_ID); 759 759 fun->device_id = pci_conf_read_16(fun, PCI_DEVICE_ID); 760 761 /* Explicitly enable PCI bus mastering */ 762 fun->command = pci_conf_read_16(fun, PCI_COMMAND) | 763 PCI_COMMAND_MASTER; 764 pci_conf_write_16(fun, PCI_COMMAND, fun->command); 765 760 766 fun->class_code = pci_conf_read_8(fun, PCI_BASE_CLASS); 761 767 fun->subclass_code = pci_conf_read_8(fun, PCI_SUB_CLASS); -
uspace/drv/bus/pci/pciintel/pci.h
r52f1882 rdb71e2a 59 59 int dev; 60 60 int fn; 61 int vendor_id; 62 int device_id; 61 uint16_t vendor_id; 62 uint16_t device_id; 63 uint16_t command; 63 64 uint8_t class_code; 64 65 uint8_t subclass_code; -
uspace/drv/bus/pci/pciintel/pci_regs.h
r52f1882 rdb71e2a 95 95 #define PCI_BRIDGE_CTL 0x3E 96 96 97 /* PCI command flags */ 98 #define PCI_COMMAND_IO 0x001 99 #define PCI_COMMAND_MEMORY 0x002 100 #define PCI_COMMAND_MASTER 0x004 101 #define PCI_COMMAND_SPECIAL 0x008 102 #define PCI_COMMAND_INVALIDATE 0x010 103 #define PCI_COMMAND_VGA_PALETTE 0x020 104 #define PCI_COMMAND_PARITY 0x040 105 #define PCI_COMMAND_WAIT 0x080 106 #define PCI_COMMAND_SERR 0x100 107 #define PCI_COMMAND_FAST_BACK 0x200 108 #define PCI_COMMAND_INTX_DISABLE 0x400 109 97 110 #endif 98 111 -
uspace/drv/bus/usb/ohci/hc.c
r52f1882 rdb71e2a 533 533 assert(instance); 534 534 535 bzero(&instance->rh, sizeof(instance->rh));535 memset(&instance->rh, 0, sizeof(instance->rh)); 536 536 /* Init queues */ 537 537 const int ret = hc_init_transfer_lists(instance); -
uspace/drv/bus/usb/ohci/hw_struct/endpoint_descriptor.c
r52f1882 rdb71e2a 53 53 { 54 54 assert(instance); 55 bzero(instance, sizeof(ed_t));55 memset(instance, 0, sizeof(ed_t)); 56 56 57 57 if (ep == NULL) { -
uspace/drv/bus/usb/ohci/hw_struct/hcca.h
r52f1882 rdb71e2a 68 68 hcca_t *hcca = memalign(256, sizeof(hcca_t)); 69 69 if (hcca) 70 bzero(hcca, sizeof(hcca_t));70 memset(hcca, 0, sizeof(hcca_t)); 71 71 return hcca; 72 72 } -
uspace/drv/bus/usb/ohci/hw_struct/transfer_descriptor.c
r52f1882 rdb71e2a 58 58 { 59 59 assert(instance); 60 bzero(instance, sizeof(td_t));60 memset(instance, 0, sizeof(td_t)); 61 61 /* Set PID and Error code */ 62 62 OHCI_MEM32_WR(instance->status, -
uspace/drv/bus/usb/uhci/uhci_batch.c
r52f1882 rdb71e2a 112 112 CHECK_NULL_DISPOSE_RETURN(uhci_batch->device_buffer, 113 113 "Failed to allocate UHCI buffer.\n"); 114 bzero(uhci_batch->device_buffer, total_size);114 memset(uhci_batch->device_buffer, 0, total_size); 115 115 116 116 uhci_batch->tds = uhci_batch->device_buffer; -
uspace/drv/bus/usb/usbhub/port.c
r52f1882 rdb71e2a 141 141 usb_log_debug("Interrupt at port %zu\n", port->port_number); 142 142 143 usb_port_status_t status ;143 usb_port_status_t status = 0; 144 144 const int opResult = get_port_status(port, &status); 145 145 if (opResult != EOK) { -
uspace/drv/bus/usb/usbmast/scsi_ms.c
r52f1882 rdb71e2a 167 167 */ 168 168 169 bzero(inq_res, sizeof(*inq_res));169 memset(inq_res, 0, sizeof(*inq_res)); 170 170 171 171 inq_res->device_type = BIT_RANGE_EXTRACT(uint8_t, -
uspace/drv/bus/usb/vhc/hub/virthubops.c
r52f1882 rdb71e2a 299 299 size_t *act_size) 300 300 { 301 int rc ;301 int rc = ENOTSUP; 302 302 size_t port = request->index - 1; 303 303 usb_hub_class_feature_t feature = request->value; -
uspace/drv/char/i8042/buffer.h
r52f1882 rdb71e2a 76 76 buffer->read_head = buffer->buffer; 77 77 buffer->write_head = buffer->buffer; 78 bzero(buffer->buffer, size);78 memset(buffer->buffer, 0, size); 79 79 } 80 80 -
uspace/drv/char/i8042/i8042.c
r52f1882 rdb71e2a 63 63 #define i8042_AUX_DISABLE 0x20 64 64 #define i8042_KBD_TRANSLATE 0x40 /* Use this to switch to XT scancodes */ 65 66 #define CHECK_RET_DESTROY(ret, msg...) \67 do { \68 if (ret != EOK) { \69 ddf_msg(LVL_ERROR, msg); \70 if (dev->kbd_fun) { \71 dev->kbd_fun->driver_data = NULL; \72 ddf_fun_destroy(dev->kbd_fun); \73 } \74 if (dev->aux_fun) { \75 dev->aux_fun->driver_data = NULL; \76 ddf_fun_destroy(dev->aux_fun); \77 } \78 } \79 } while (0)80 81 #define CHECK_RET_UNBIND_DESTROY(ret, msg...) \82 do { \83 if (ret != EOK) { \84 ddf_msg(LVL_ERROR, msg); \85 if (dev->kbd_fun) { \86 ddf_fun_unbind(dev->kbd_fun); \87 dev->kbd_fun->driver_data = NULL; \88 ddf_fun_destroy(dev->kbd_fun); \89 } \90 if (dev->aux_fun) { \91 ddf_fun_unbind(dev->aux_fun); \92 dev->aux_fun->driver_data = NULL; \93 ddf_fun_destroy(dev->aux_fun); \94 } \95 } \96 } while (0)97 65 98 66 void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *); -
uspace/drv/char/i8042/main.c
r52f1882 rdb71e2a 36 36 37 37 #include <libarch/inttypes.h> 38 #include <libarch/config.h> 38 39 #include <ddf/driver.h> 39 40 #include <device/hw_res_parsed.h> … … 42 43 #include <ddf/log.h> 43 44 #include <stdio.h> 45 #include <async.h> 44 46 #include "i8042.h" 45 46 #define CHECK_RET_RETURN(ret, message...) \47 do { \48 if (ret != EOK) { \49 ddf_msg(LVL_ERROR, message); \50 return ret; \51 } \52 } while (0)53 47 54 48 /** Get address of I/O registers. … … 110 104 static int i8042_dev_add(ddf_dev_t *device) 111 105 { 112 if (!device)113 return EINVAL;114 115 106 uintptr_t io_regs = 0; 116 107 size_t io_size = 0; 117 108 int kbd = 0; 118 109 int mouse = 0; 110 int rc; 119 111 120 int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse); 121 CHECK_RET_RETURN(ret, "Failed to get registers: %s.", 122 str_error(ret)); 112 if (!device) 113 return EINVAL; 114 115 rc = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse); 116 if (rc != EOK) { 117 ddf_msg(LVL_ERROR, "Failed to get registers: %s.", 118 str_error(rc)); 119 return rc; 120 } 121 123 122 ddf_msg(LVL_DEBUG, "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.", 124 123 (void *) io_regs, io_size, kbd, mouse); 125 124 126 125 i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t)); 127 ret = (i8042 == NULL) ? ENOMEM : EOK; 128 CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance."); 126 if (i8042 == NULL) { 127 ddf_msg(LVL_ERROR, "Out of memory."); 128 return ENOMEM; 129 } 129 130 130 ret = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device); 131 CHECK_RET_RETURN(ret, "Failed to initialize i8042 driver: %s.", 132 str_error(ret)); 131 rc = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device); 132 if (rc != EOK) { 133 ddf_msg(LVL_ERROR, "Failed to initialize i8042 driver: %s.", 134 str_error(rc)); 135 return rc; 136 } 133 137 134 138 ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").", … … 152 156 printf("%s: HelenOS PS/2 driver.\n", NAME); 153 157 ddf_log_init(NAME); 158 159 /* 160 * Alleviate the virtual memory / page table pressure caused by 161 * interrupt storms when the default large stacks are used. 162 */ 163 async_set_interrupt_handler_stack_size(PAGE_SIZE); 164 154 165 return ddf_driver_main(&i8042_driver); 155 166 } -
uspace/drv/char/ns8250/ns8250.c
r52f1882 rdb71e2a 160 160 /** I/O registers **/ 161 161 ns8250_regs_t *regs; 162 /** Is there any client conntected to the device? */163 bool client_connected;162 /** Are there any clients connected to the device? */ 163 unsigned client_connections; 164 164 /** The irq assigned to this device. */ 165 165 int irq; … … 168 168 /** The i/o port used to access the serial ports registers. */ 169 169 ioport8_t *port; 170 /** The buffer for incom ming data. */170 /** The buffer for incoming data. */ 171 171 cyclic_buffer_t input_buffer; 172 172 /** The fibril mutex for synchronizing the access to the device. */ … … 190 190 } 191 191 192 /** Find out if there is some incom ming data available on the serial port.192 /** Find out if there is some incoming data available on the serial port. 193 193 * 194 194 * @param port The base address of the serial port device's ports. … … 236 236 * 237 237 * @param fun The serial port function 238 * @param buf The ou put buffer for read data.238 * @param buf The output buffer for read data. 239 239 * @param count The number of bytes to be read. 240 240 * … … 420 420 ns->irq = res->res.interrupt.irq; 421 421 irq = true; 422 ddf_msg(LVL_NOTE, "Device %s was as igned irq = 0x%x.",422 ddf_msg(LVL_NOTE, "Device %s was assigned irq = 0x%x.", 423 423 ddf_dev_get_name(ns->dev), ns->irq); 424 424 break; … … 433 433 } 434 434 ioport = true; 435 ddf_msg(LVL_NOTE, "Device %s was as igned I/O address = "435 ddf_msg(LVL_NOTE, "Device %s was assigned I/O address = " 436 436 "0x%x.", ddf_dev_get_name(ns->dev), ns->io_addr); 437 437 break; … … 753 753 uint8_t val = ns8250_read_8(regs); 754 754 755 if (ns->client_connect ed) {755 if (ns->client_connections > 0) { 756 756 bool buf_was_empty = buf_is_empty(&ns->input_buffer); 757 757 if (!buf_push_back(&ns->input_buffer, val)) { … … 827 827 ddf_fun_t *fun = NULL; 828 828 bool need_cleanup = false; 829 bool need_unreg_intr_handler = false; 829 830 int rc; 830 831 … … 869 870 goto fail; 870 871 } 872 need_unreg_intr_handler = true; 871 873 872 874 /* Enable interrupt. */ … … 903 905 if (fun != NULL) 904 906 ddf_fun_destroy(fun); 907 if (need_unreg_intr_handler) 908 ns8250_unregister_interrupt_handler(ns); 905 909 if (need_cleanup) 906 910 ns8250_dev_cleanup(ns); … … 914 918 915 919 fibril_mutex_lock(&ns->mutex); 916 if (ns->client_connect ed) {920 if (ns->client_connections > 0) { 917 921 fibril_mutex_unlock(&ns->mutex); 918 922 return EBUSY; … … 948 952 949 953 fibril_mutex_lock(&ns->mutex); 950 if (ns->client_connected) { 951 res = ELIMIT; 952 } else if (ns->removed) { 954 if (ns->removed) { 953 955 res = ENXIO; 954 956 } else { 955 957 res = EOK; 956 ns->client_connect ed = true;958 ns->client_connections++; 957 959 } 958 960 fibril_mutex_unlock(&ns->mutex); … … 974 976 fibril_mutex_lock(&data->mutex); 975 977 976 assert(data->client_connect ed);977 978 data->client_connected = false;979 buf_clear(&data->input_buffer);978 assert(data->client_connections > 0); 979 980 if (!(--data->client_connections)) 981 buf_clear(&data->input_buffer); 980 982 981 983 fibril_mutex_unlock(&data->mutex); -
uspace/drv/char/ps2mouse/main.c
r52f1882 rdb71e2a 80 80 static int mouse_add(ddf_dev_t *device) 81 81 { 82 int rc; 83 82 84 if (!device) 83 85 return EINVAL; 84 86 85 #define CHECK_RET_RETURN(ret, message...) \ 86 if (ret != EOK) { \ 87 ddf_msg(LVL_ERROR, message); \88 return ret; \89 } else (void)0 87 ps2_mouse_t *mouse = ddf_dev_data_alloc(device, sizeof(ps2_mouse_t)); 88 if (mouse == NULL) { 89 ddf_msg(LVL_ERROR, "Failed to allocate mouse driver instance."); 90 return ENOMEM; 91 } 90 92 91 ps2_mouse_t *mouse = ddf_dev_data_alloc(device, sizeof(ps2_mouse_t)); 92 int ret = (mouse == NULL) ? ENOMEM : EOK; 93 CHECK_RET_RETURN(ret, "Failed to allocate mouse driver instance."); 94 95 ret = ps2_mouse_init(mouse, device); 96 CHECK_RET_RETURN(ret, 97 "Failed to initialize mouse driver: %s.", str_error(ret)); 93 rc = ps2_mouse_init(mouse, device); 94 if (rc != EOK) { 95 ddf_msg(LVL_ERROR, "Failed to initialize mouse driver: %s.", 96 str_error(rc)); 97 return rc; 98 } 98 99 99 100 ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").", -
uspace/drv/char/ps2mouse/ps2mouse.c
r52f1882 rdb71e2a 70 70 #define PS2_BUTTON_MASK(button) (1 << button) 71 71 72 #define MOUSE_READ_BYTE_TEST(sess, value ) \72 #define MOUSE_READ_BYTE_TEST(sess, value_) \ 73 73 do { \ 74 uint8_t value = (value_); \ 74 75 uint8_t data = 0; \ 75 76 const ssize_t size = chardev_read(sess, &data, 1); \ … … 78 79 return size < 0 ? size : EIO; \ 79 80 } \ 80 if (data != (value)) { \81 if (data != value) { \ 81 82 ddf_msg(LVL_DEBUG, "Failed testing byte: got %hhx vs. %hhx)", \ 82 data, (value)); \83 data, value); \ 83 84 return EIO; \ 84 85 } \ 85 86 } while (0) 86 87 87 #define MOUSE_WRITE_BYTE(sess, value ) \88 #define MOUSE_WRITE_BYTE(sess, value_) \ 88 89 do { \ 90 uint8_t value = (value_); \ 89 91 uint8_t data = (value); \ 90 92 const ssize_t size = chardev_write(sess, &data, 1); \ -
uspace/drv/char/xtkbd/main.c
r52f1882 rdb71e2a 80 80 static int xt_kbd_add(ddf_dev_t *device) 81 81 { 82 int rc; 83 82 84 if (!device) 83 85 return EINVAL; 84 86 85 #define CHECK_RET_RETURN(ret, message...) \ 86 if (ret != EOK) { \ 87 ddf_msg(LVL_ERROR, message); \88 return ret; \89 } else (void)0 87 xt_kbd_t *kbd = ddf_dev_data_alloc(device, sizeof(xt_kbd_t)); 88 if (kbd == NULL) { 89 ddf_msg(LVL_ERROR, "Failed to allocate XT/KBD driver instance."); 90 return ENOMEM; 91 } 90 92 91 xt_kbd_t *kbd = ddf_dev_data_alloc(device, sizeof(xt_kbd_t)); 92 int ret = (kbd == NULL) ? ENOMEM : EOK; 93 CHECK_RET_RETURN(ret, "Failed to allocate XT/KBD driver instance."); 94 95 ret = xt_kbd_init(kbd, device); 96 CHECK_RET_RETURN(ret, 97 "Failed to initialize XT_KBD driver: %s.", str_error(ret)); 93 rc = xt_kbd_init(kbd, device); 94 if (rc != EOK) { 95 ddf_msg(LVL_ERROR, "Failed to initialize XT_KBD driver: %s.", 96 str_error(rc)); 97 return rc; 98 } 98 99 99 100 ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").", -
uspace/drv/infrastructure/rootamdm37x/rootamdm37x.c
r52f1882 rdb71e2a 195 195 ddf_msg(LVL_ERROR, "Failed to add EHCI function for " 196 196 "BeagleBoard-xM platform."); 197 if (rootamdm37x_add_fun(dev, "dispc", "amdm37x&dispc", &ehci) != EOK) 198 ddf_msg(LVL_ERROR, "Failed to add dispc function for " 199 "BeagleBoard-xM platform."); 197 200 198 201 return EOK; -
uspace/drv/nic/e1k/e1k.c
r52f1882 rdb71e2a 293 293 assert(info); 294 294 295 bzero(info, sizeof(nic_device_info_t));295 memset(info, 0, sizeof(nic_device_info_t)); 296 296 297 297 info->vendor_id = 0x8086; … … 1581 1581 goto error; 1582 1582 1583 bzero(e1000->tx_ring_virt,1583 memset(e1000->tx_ring_virt, 0, 1584 1584 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t)); 1585 1585 … … 1872 1872 } 1873 1873 1874 bzero(e1000, sizeof(e1000_t));1874 memset(e1000, 0, sizeof(e1000_t)); 1875 1875 1876 1876 nic_set_specific(nic, e1000); -
uspace/drv/nic/ne2k/dp8390.c
r52f1882 rdb71e2a 446 446 return NULL; 447 447 448 bzero(frame->data, length);448 memset(frame->data, 0, length); 449 449 uint8_t last = page + length / DP_PAGE; 450 450 -
uspace/drv/nic/rtl8139/driver.c
r52f1882 rdb71e2a 620 620 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 621 621 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4" PRIu16 ", " 622 "header 0x%4" PRIx 16 ". Offset: %d)", size, frame_header,622 "header 0x%4" PRIx32 ". Offset: %" PRIu16 ")", size, frame_header, 623 623 rx_offset); 624 624 goto rx_err; … … 1020 1020 } 1021 1021 1022 bzero(rtl8139, sizeof(rtl8139_t));1022 memset(rtl8139, 0, sizeof(rtl8139_t)); 1023 1023 1024 1024 rtl8139->nic_data = nic_data;
Note:
See TracChangeset
for help on using the changeset viewer.
