static void *dev_thread (void *devs) { struct devstruct *dev = (struct devstruct*)devs; uae_set_thread_priority (2); dev->thread_running = 1; uae_sem_post (&dev->sync_sem); for (;;) { uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); uae_sem_wait (&change_sem); if (!request) { dev->thread_running = 0; uae_sem_post (&dev->sync_sem); uae_sem_post (&change_sem); return 0; } else if (get_async_request (dev, request, 1)) { uae_ReplyMsg (request); release_async_request (dev, request); } else if (dev_do_io (dev, request, 0) == 0) { uae_ReplyMsg (request); } else { add_async_request (dev, request); uaeser_trigger (dev->sysdata); } uae_sem_post (&change_sem); } return 0; }
static void *dev_thread (void *devs) { struct s2devstruct *dev = (struct s2devstruct*)devs; uae_set_thread_priority (NULL, 1); dev->thread_running = 1; uae_sem_post (&dev->sync_sem); for (;;) { uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); uae_sem_wait (&change_sem); if (!request) { dev->thread_running = 0; uae_sem_post (&dev->sync_sem); uae_sem_post (&change_sem); write_log (_T("%s: dev_thread killed\n"), getdevname ()); return 0; } else if (get_async_request (dev, request, 1)) { uae_ReplyMsg (request); release_async_request (dev, request); rem_async_packet (dev, request); } else if (dev_do_io (dev, request, 0) == 0) { uae_ReplyMsg (request); rem_async_packet (dev, request); } else { add_async_request (dev, request); ethernet_trigger (dev->sysdata); } uae_sem_post (&change_sem); } return 0; }
static void *dev_thread (void *devs) { struct devstruct *dev = devs; uae_set_thread_priority (2); dev->thread_running = 1; sys_command_open_thread (DF_SCSI, dev->unitnum); sys_command_open_thread (DF_IOCTL, dev->unitnum); uae_sem_post (&dev->sync_sem); for (;;) { uaecptr request = (uaecptr)read_comm_pipe_u32_blocking (&dev->requests); uae_sem_wait (&change_sem); if (!request) { dev->thread_running = 0; uae_sem_post (&dev->sync_sem); uae_sem_post (&change_sem); break; } else if (dev_do_io (dev, request) == 0) { put_byte (request + 30, get_byte (request + 30) & ~1); release_async_request (dev, request); uae_ReplyMsg (request); } else { if (log_scsi) write_log ("async request %08.8X\n", request); } uae_sem_post (&change_sem); } sys_command_close_thread (DF_SCSI, dev->unitnum); sys_command_close_thread (DF_IOCTL, dev->unitnum); return 0; }
static void abort_async (struct devstruct *dev, uaecptr request, int errcode, int type) { int i; i = 0; while (i < MAX_ASYNC_REQUESTS) { if (dev->d_request[i] == request && dev->d_request_type[i] == ASYNC_REQUEST_TEMP) { /* ASYNC_REQUEST_TEMP = request is processing */ uae_msleep (10); i = 0; continue; } i++; } i = release_async_request (dev, request); if (i >= 0 && log_scsi) write_log ("asyncronous request=%08.8X aborted, error=%d\n", request, errcode); }
static int dev_do_io (struct devstruct *dev, uaecptr request) { uae_u32 command; uae_u32 io_data = get_long (request + 40); // 0x28 uae_u32 io_length = get_long (request + 36); // 0x24 uae_u32 io_actual = get_long (request + 32); // 0x20 uae_u32 io_offset = get_long (request + 44); // 0x2c uae_u32 io_error = 0; int async = 0; struct device_info di; struct priv_devstruct *pdev = getpdevstruct (request); if (!pdev) return 0; command = get_word (request+28); switch (command) { case CMD_READ: io_error = command_read (pdev->mode, dev, io_data, io_offset, io_length, &io_actual); break; case CMD_WRITE: case CMD_FORMAT: io_error = 28; /* writeprotect */ break; case CMD_UPDATE: case CMD_CLEAR: case CMD_FLUSH: case CMD_MOTOR: case CMD_SEEK: io_actual = 0; break; case CMD_REMOVE: io_actual = 0; break; case CMD_CHANGENUM: io_actual = dev->changenum; break; case CMD_CHANGESTATE: io_actual = devinfo(pdev->mode, dev->unitnum, &di)->media_inserted ? 0 : 1; break; case CMD_PROTSTATUS: io_actual = devinfo(pdev->mode, dev->unitnum, &di)->write_protected ? -1 : 0; break; case CMD_GETDRIVETYPE: io_actual = dev->drivetype; break; case CMD_GETNUMTRACKS: io_actual = dev->di.cylinders; break; case CMD_ADDCHANGEINT: io_error = add_async_request (dev, request, ASYNC_REQUEST_CHANGEINT, io_data); if (!io_error) async = 1; break; case CMD_REMCHANGEINT: release_async_request (dev, request); break; case 28: /* HD_SCSICMD */ if (dev->allow_scsi && pdev->scsi) { uae_u32 sdd = get_long (request + 40); io_error = sys_command_scsi_direct (dev->unitnum, sdd); if (log_scsi) write_log ("scsidev: did io: sdd %p request %p error %d\n", sdd, request, get_byte (request + 31)); } break; default: io_error = -3; break; } put_long (request + 32, io_actual); put_byte (request + 31, io_error); io_log ("dev_io",request); return async; }