mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-11 09:29:53 +00:00
Added command dispatcher to Disk class
This commit is contained in:
parent
9772b976d4
commit
cdf9a6ad5b
@ -42,40 +42,6 @@ SCSIDEV::SCSIDEV() : SASIDEV()
|
||||
scsi.msc = 0;
|
||||
memset(scsi.msb, 0x00, sizeof(scsi.msb));
|
||||
|
||||
SetUpDiskCommand(eCmdTestUnitReady, "CmdTestUnitReady", &Disk::TestUnitReady);
|
||||
SetUpDiskCommand(eCmdRezero, "CmdRezero", &Disk::Rezero);
|
||||
SetUpDiskCommand(eCmdRequestSense, "CmdRequestSense", &Disk::RequestSense);
|
||||
SetUpDiskCommand(eCmdFormat, "CmdFormat", &Disk::Format);
|
||||
SetUpDiskCommand(eCmdReassign, "CmdReassign", &Disk::ReassignBlocks);
|
||||
SetUpDiskCommand(eCmdRead6, "CmdRead6", &Disk::Read6);
|
||||
SetUpDiskCommand(eCmdWrite6, "CmdWrite6", &Disk::Write6);
|
||||
SetUpDiskCommand(eCmdSeek6, "CmdSeek6", &Disk::Seek6);
|
||||
SetUpDiskCommand(eCmdInquiry, "CmdInquiry", &Disk::Inquiry);
|
||||
SetUpDiskCommand(eCmdModeSelect, "CmdModeSelect", &Disk::ModeSelect);
|
||||
SetUpDiskCommand(eCmdReserve6, "CmdReserve6", &Disk::Reserve6);
|
||||
SetUpDiskCommand(eCmdRelease6, "CmdRelease6", &Disk::Release6);
|
||||
SetUpDiskCommand(eCmdModeSense, "CmdModeSense", &Disk::ModeSense);
|
||||
SetUpDiskCommand(eCmdStartStop, "CmdStartStop", &Disk::StartStop);
|
||||
SetUpDiskCommand(eCmdSendDiag, "CmdSendDiag", &Disk::SendDiagnostic);
|
||||
SetUpDiskCommand(eCmdRemoval, "CmdRemoval", &Disk::PreventAllowRemoval);
|
||||
SetUpDiskCommand(eCmdReadCapacity10, "CmdReadCapacity10", &Disk::ReadCapacity10);
|
||||
SetUpDiskCommand(eCmdRead10, "CmdRead10", &Disk::Read10);
|
||||
SetUpDiskCommand(eCmdWrite10, "CmdWrite10", &Disk::Write10);
|
||||
SetUpDiskCommand(eCmdVerify10, "CmdVerify10", &Disk::Write10);
|
||||
SetUpDiskCommand(eCmdSeek10, "CmdSeek10", &Disk::Seek10);
|
||||
SetUpDiskCommand(eCmdVerify, "CmdVerify", &Disk::Verify);
|
||||
SetUpDiskCommand(eCmdSynchronizeCache, "CmdSynchronizeCache", &Disk::SynchronizeCache);
|
||||
SetUpDiskCommand(eCmdReadDefectData10, "CmdReadDefectData10", &Disk::ReadDefectData10);
|
||||
SetUpDiskCommand(eCmdModeSelect10, "CmdModeSelect10", &Disk::ModeSelect10);
|
||||
SetUpDiskCommand(eCmdReserve10, "CmdReserve10", &Disk::Reserve10);
|
||||
SetUpDiskCommand(eCmdRelease10, "CmdRelease10", &Disk::Release10);
|
||||
SetUpDiskCommand(eCmdModeSense10, "CmdModeSense10", &Disk::ModeSense10);
|
||||
SetUpDiskCommand(eCmdRead16, "CmdRead16", &Disk::Read16);
|
||||
SetUpDiskCommand(eCmdWrite16, "CmdWrite16", &Disk::Write16);
|
||||
SetUpDiskCommand(eCmdVerify16, "CmdVerify16", &Disk::Write16);
|
||||
SetUpDiskCommand(eCmdReadCapacity16, "CmdReadCapacity16", &Disk::ReadCapacity16);
|
||||
SetUpDiskCommand(eCmdReportLuns, "CmdReportLuns", &Disk::ReportLuns);
|
||||
|
||||
// MMC specific. TODO Move to separate class
|
||||
SetUpControllerCommand(eCmdReadToc, "CmdReadToc", &SCSIDEV::CmdReadToc);
|
||||
SetUpControllerCommand(eCmdPlayAudio10, "CmdPlayAudio10", &SCSIDEV::CmdPlayAudio10);
|
||||
@ -95,10 +61,6 @@ SCSIDEV::~SCSIDEV()
|
||||
for (auto const& command : controller_commands) {
|
||||
free(command.second);
|
||||
}
|
||||
|
||||
for (auto const& command : disk_commands) {
|
||||
free(command.second);
|
||||
}
|
||||
}
|
||||
|
||||
void SCSIDEV::SetUpControllerCommand(scsi_command opcode, const char* name, void (SCSIDEV::*execute)(void))
|
||||
@ -106,11 +68,6 @@ void SCSIDEV::SetUpControllerCommand(scsi_command opcode, const char* name, void
|
||||
controller_commands[opcode] = new controller_command_t(name, execute);
|
||||
}
|
||||
|
||||
void SCSIDEV::SetUpDiskCommand(scsi_command opcode, const char* name, void (Disk::*execute)(SASIDEV *))
|
||||
{
|
||||
disk_commands[opcode] = new disk_command_t(name, execute);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Device reset
|
||||
@ -307,13 +264,7 @@ void SCSIDEV::Execute()
|
||||
|
||||
ctrl.device = ctrl.unit[GetLun()];
|
||||
|
||||
if (disk_commands.count(static_cast<scsi_command>(ctrl.cmd[0]))) {
|
||||
disk_command_t *command = disk_commands[static_cast<scsi_command>(ctrl.cmd[0])];
|
||||
|
||||
LOGDEBUG("++++ CMD ++++ %s ID %d received %s ($%02X)", __PRETTY_FUNCTION__, GetSCSIID(), command->name, (unsigned int)ctrl.cmd[0]);
|
||||
|
||||
(ctrl.device->*command->execute)(this);
|
||||
|
||||
if (ctrl.device->Dispatch(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
class SCSIDEV : public SASIDEV
|
||||
{
|
||||
|
||||
private:
|
||||
public:
|
||||
enum scsi_command : int {
|
||||
eCmdTestUnitReady = 0x00,
|
||||
eCmdRezero = 0x01,
|
||||
@ -71,7 +71,6 @@ private:
|
||||
eCmdReportLuns = 0xA0
|
||||
};
|
||||
|
||||
public:
|
||||
// Internal data definition
|
||||
typedef struct {
|
||||
// Synchronous transfer
|
||||
@ -95,14 +94,6 @@ public:
|
||||
} controller_command_t;
|
||||
std::map<scsi_command, controller_command_t*> controller_commands;
|
||||
|
||||
typedef struct _disk_command_t {
|
||||
const char* name;
|
||||
void (Disk::*execute)(SASIDEV *);
|
||||
|
||||
_disk_command_t(const char* _name, void (Disk::*_execute)(SASIDEV *)) : name(_name), execute(_execute) { };
|
||||
} disk_command_t;
|
||||
std::map<scsi_command, disk_command_t*> disk_commands;
|
||||
|
||||
public:
|
||||
// Basic Functions
|
||||
SCSIDEV();
|
||||
@ -125,7 +116,6 @@ public:
|
||||
|
||||
private:
|
||||
void SetUpControllerCommand(scsi_command, const char*, void (SCSIDEV::*)(void));
|
||||
void SetUpDiskCommand(scsi_command, const char*, void (Disk::*)(SASIDEV *));
|
||||
|
||||
// Phase
|
||||
void BusFree(); // Bus free phase
|
||||
|
@ -1273,6 +1273,40 @@ Disk::Disk(const std::string id) : BlockDevice(id)
|
||||
|
||||
// Other
|
||||
cache_wb = TRUE;
|
||||
|
||||
AddCommand(SCSIDEV::eCmdTestUnitReady, "CmdTestUnitReady", &Disk::TestUnitReady);
|
||||
AddCommand(SCSIDEV::eCmdRezero, "CmdRezero", &Disk::Rezero);
|
||||
AddCommand(SCSIDEV::eCmdRequestSense, "CmdRequestSense", &Disk::RequestSense);
|
||||
AddCommand(SCSIDEV::eCmdFormat, "CmdFormat", &Disk::Format);
|
||||
AddCommand(SCSIDEV::eCmdReassign, "CmdReassign", &Disk::ReassignBlocks);
|
||||
AddCommand(SCSIDEV::eCmdRead6, "CmdRead6", &Disk::Read6);
|
||||
AddCommand(SCSIDEV::eCmdWrite6, "CmdWrite6", &Disk::Write6);
|
||||
AddCommand(SCSIDEV::eCmdSeek6, "CmdSeek6", &Disk::Seek6);
|
||||
AddCommand(SCSIDEV::eCmdInquiry, "CmdInquiry", &Disk::Inquiry);
|
||||
AddCommand(SCSIDEV::eCmdModeSelect, "CmdModeSelect", &Disk::ModeSelect);
|
||||
AddCommand(SCSIDEV::eCmdReserve6, "CmdReserve6", &Disk::Reserve6);
|
||||
AddCommand(SCSIDEV::eCmdRelease6, "CmdRelease6", &Disk::Release6);
|
||||
AddCommand(SCSIDEV::eCmdModeSense, "CmdModeSense", &Disk::ModeSense);
|
||||
AddCommand(SCSIDEV::eCmdStartStop, "CmdStartStop", &Disk::StartStop);
|
||||
AddCommand(SCSIDEV::eCmdSendDiag, "CmdSendDiag", &Disk::SendDiagnostic);
|
||||
AddCommand(SCSIDEV::eCmdRemoval, "CmdRemoval", &Disk::PreventAllowRemoval);
|
||||
AddCommand(SCSIDEV::eCmdReadCapacity10, "CmdReadCapacity10", &Disk::ReadCapacity10);
|
||||
AddCommand(SCSIDEV::eCmdRead10, "CmdRead10", &Disk::Read10);
|
||||
AddCommand(SCSIDEV::eCmdWrite10, "CmdWrite10", &Disk::Write10);
|
||||
AddCommand(SCSIDEV::eCmdVerify10, "CmdVerify10", &Disk::Write10);
|
||||
AddCommand(SCSIDEV::eCmdSeek10, "CmdSeek10", &Disk::Seek10);
|
||||
AddCommand(SCSIDEV::eCmdVerify, "CmdVerify", &Disk::Verify);
|
||||
AddCommand(SCSIDEV::eCmdSynchronizeCache, "CmdSynchronizeCache", &Disk::SynchronizeCache);
|
||||
AddCommand(SCSIDEV::eCmdReadDefectData10, "CmdReadDefectData10", &Disk::ReadDefectData10);
|
||||
AddCommand(SCSIDEV::eCmdModeSelect10, "CmdModeSelect10", &Disk::ModeSelect10);
|
||||
AddCommand(SCSIDEV::eCmdReserve10, "CmdReserve10", &Disk::Reserve10);
|
||||
AddCommand(SCSIDEV::eCmdRelease10, "CmdRelease10", &Disk::Release10);
|
||||
AddCommand(SCSIDEV::eCmdModeSense10, "CmdModeSense10", &Disk::ModeSense10);
|
||||
AddCommand(SCSIDEV::eCmdRead16, "CmdRead16", &Disk::Read16);
|
||||
AddCommand(SCSIDEV::eCmdWrite16, "CmdWrite16", &Disk::Write16);
|
||||
AddCommand(SCSIDEV::eCmdVerify16, "CmdVerify16", &Disk::Write16);
|
||||
AddCommand(SCSIDEV::eCmdReadCapacity16, "CmdReadCapacity16", &Disk::ReadCapacity16);
|
||||
AddCommand(SCSIDEV::eCmdReportLuns, "CmdReportLuns", &Disk::ReportLuns);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@ -1295,6 +1329,32 @@ Disk::~Disk()
|
||||
delete disk.dcache;
|
||||
disk.dcache = NULL;
|
||||
}
|
||||
|
||||
for (auto const& command : disk_commands) {
|
||||
free(command.second);
|
||||
}
|
||||
}
|
||||
|
||||
void Disk::AddCommand(SCSIDEV::scsi_command opcode, const char* name, void (Disk::*execute)(SASIDEV *))
|
||||
{
|
||||
disk_commands[opcode] = new disk_command_t(name, execute);
|
||||
}
|
||||
|
||||
bool Disk::Dispatch(SCSIDEV *controller)
|
||||
{
|
||||
SASIDEV::ctrl_t *ctrl = controller->GetWorkAddr();
|
||||
|
||||
if (disk_commands.count(static_cast<SCSIDEV::scsi_command>(ctrl->cmd[0]))) {
|
||||
disk_command_t *command = disk_commands[static_cast<SCSIDEV::scsi_command>(ctrl->cmd[0])];
|
||||
|
||||
LOGDEBUG("++++ CMD ++++ %s received %s ($%02X)", __PRETTY_FUNCTION__, command->name, (unsigned int)ctrl->cmd[0]);
|
||||
|
||||
(this->*command->execute)(controller);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -20,11 +20,12 @@
|
||||
#include "xm6.h"
|
||||
#include "log.h"
|
||||
#include "scsi.h"
|
||||
#include "controllers/sasidev_ctrl.h"
|
||||
#include "controllers/scsidev_ctrl.h"
|
||||
#include "block_device.h"
|
||||
#include "file_support.h"
|
||||
#include "filepath.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
@ -138,6 +139,15 @@ protected:
|
||||
off_t imgoffset; // Offset to actual data
|
||||
} disk_t;
|
||||
|
||||
private:
|
||||
typedef struct _disk_command_t {
|
||||
const char* name;
|
||||
void (Disk::*execute)(SASIDEV *);
|
||||
|
||||
_disk_command_t(const char* _name, void (Disk::*_execute)(SASIDEV *)) : name(_name), execute(_execute) { };
|
||||
} disk_command_t;
|
||||
std::map<SCSIDEV::scsi_command, disk_command_t*> disk_commands;
|
||||
|
||||
public:
|
||||
// Basic Functions
|
||||
Disk(std::string); // Constructor
|
||||
@ -221,6 +231,8 @@ public:
|
||||
bool Format(const DWORD *cdb); // FORMAT UNIT command
|
||||
bool Reassign(const DWORD *cdb); // REASSIGN UNIT command
|
||||
|
||||
bool Dispatch(SCSIDEV *);
|
||||
|
||||
protected:
|
||||
// Internal processing
|
||||
virtual int AddError(bool change, BYTE *buf); // Add error
|
||||
@ -236,4 +248,7 @@ protected:
|
||||
// Internal data
|
||||
disk_t disk; // Internal disk data
|
||||
BOOL cache_wb; // Cache mode
|
||||
|
||||
private:
|
||||
void AddCommand(SCSIDEV::scsi_command, const char*, void (Disk::*)(SASIDEV *));
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user