20#include "modules/drivers/common/scsi/ScsiCommands.h"
21#include "pedigree/kernel/utilities/utility.h"
23ScsiCommand::ScsiCommand() =
default;
24ScsiCommand::~ScsiCommand() =
default;
26namespace ScsiCommands {
27Inquiry::Inquiry(uint16_t len,
bool enableVitalData, uint8_t pageCode, uint8_t ctl) {
28 ByteSet(&command, 0,
sizeof(command));
29 command.opcode = 0x12;
30 command.epvd = enableVitalData;
32 command.pageCode = pageCode;
33 command.len = HOST_TO_BIG16(len);
34 command.control = ctl;
37size_t Inquiry::serialise(uintptr_t& addr) {
38 addr =
reinterpret_cast<uintptr_t
>(&command);
39 return sizeof(command);
42UnitReady::UnitReady(uint8_t ctl) {
43 ByteSet(&command, 0,
sizeof(command));
45 command.control = ctl;
48size_t UnitReady::serialise(uintptr_t& addr) {
49 addr =
reinterpret_cast<uintptr_t
>(&command);
50 return sizeof(command);
53ReadSense::ReadSense(uint8_t desc, uint8_t len, uint8_t ctl) {
54 ByteSet(&command, 0,
sizeof(command));
55 command.opcode = 0x03;
58 command.control = ctl;
61size_t ReadSense::serialise(uintptr_t& addr) {
62 addr =
reinterpret_cast<uintptr_t
>(&command);
63 return sizeof(command);
66StartStop::StartStop(
bool imm, uint8_t newpower,
bool eject_load,
bool start, uint8_t ctl) {
67 ByteSet(&command, 0,
sizeof(command));
68 command.opcode = 0x1b;
69 command.imm = imm ? 1 : 0;
70 command.setup = (start ? 1 : 0) | ((eject_load ? 1 : 0) << 1) | (newpower << 4);
71 command.control = ctl;
74size_t StartStop::serialise(uintptr_t& addr) {
75 addr =
reinterpret_cast<uintptr_t
>(&command);
76 return sizeof(command);
79SendDiagnostic::SendDiagnostic(
bool selfTest, uint8_t selfTestCode, uintptr_t params,
80 size_t paramLen,
bool deviceOffline,
bool unitOffline, uint8_t ctl) {
81 ByteSet(&command, 0,
sizeof(command));
82 command.opcode = 0x1d;
83 command.unitOffline = unitOffline;
84 command.devOffline = deviceOffline;
85 command.selfTest = selfTest;
87 command.selfTestCode = selfTestCode;
88 command.paramListLen = HOST_TO_BIG16(paramLen);
89 command.control = ctl;
92size_t SendDiagnostic::serialise(uintptr_t& addr) {
93 addr =
reinterpret_cast<uintptr_t
>(&command);
94 return sizeof(command);
97ReadTocCommand::ReadTocCommand(uint16_t nativeBlockSize, uint8_t ctl) {
98 ByteSet(&command, 0,
sizeof(command));
99 command.opcode = 0x43;
100 command.len = HOST_TO_BIG16(nativeBlockSize);
103size_t ReadTocCommand::serialise(uintptr_t& addr) {
104 addr =
reinterpret_cast<uintptr_t
>(&command);
105 return sizeof(command);
108ReadCapacity10::ReadCapacity10(uint8_t ctl) {
109 ByteSet(&command, 0,
sizeof(command));
110 command.opcode = 0x25;
111 command.control = ctl;
114size_t ReadCapacity10::serialise(uintptr_t& addr) {
115 addr =
reinterpret_cast<uintptr_t
>(&command);
116 return sizeof(command);
119Read10::Read10(uint32_t nLba, uint32_t nSectors) {
120 ByteSet(&command, 0,
sizeof(command));
121 command.nOpCode = 0x28;
122 command.nLba = HOST_TO_BIG32(nLba);
123 command.nSectors = HOST_TO_BIG16(nSectors);
126size_t Read10::serialise(uintptr_t& addr) {
127 addr =
reinterpret_cast<uintptr_t
>(&command);
128 return sizeof(command);
131Read12::Read12(uint32_t nLba, uint32_t nSectors) {
132 ByteSet(&command, 0,
sizeof(command));
133 command.nOpCode = 0xa8;
134 command.nLba = HOST_TO_BIG32(nLba);
135 command.nSectors = HOST_TO_BIG32(nSectors);
138size_t Read12::serialise(uintptr_t& addr) {
139 addr =
reinterpret_cast<uintptr_t
>(&command);
140 return sizeof(command);
143Read16::Read16(uint64_t nLba, uint32_t nSectors) {
144 ByteSet(&command, 0,
sizeof(command));
145 command.nOpCode = 0x88;
146 command.nLba = HOST_TO_BIG64(nLba);
147 command.nSectors = HOST_TO_BIG32(nSectors);
150size_t Read16::serialise(uintptr_t& addr) {
151 addr =
reinterpret_cast<uintptr_t
>(&command);
152 return sizeof(command);
155Write10::Write10(uint32_t nLba, uint32_t nSectors) {
156 ByteSet(&command, 0,
sizeof(command));
157 command.nOpCode = 0x2A;
158 command.nLba = HOST_TO_BIG32(nLba);
159 command.nSectors = HOST_TO_BIG16(nSectors);
162size_t Write10::serialise(uintptr_t& addr) {
163 addr =
reinterpret_cast<uintptr_t
>(&command);
164 return sizeof(command);
167Write12::Write12(uint32_t nLba, uint32_t nSectors) {
168 ByteSet(&command, 0,
sizeof(command));
169 command.nOpCode = 0xAA;
170 command.nLba = HOST_TO_BIG32(nLba);
171 command.nSectors = HOST_TO_BIG32(nSectors);
174size_t Write12::serialise(uintptr_t& addr) {
175 addr =
reinterpret_cast<uintptr_t
>(&command);
176 return sizeof(command);
179Write16::Write16(uint64_t nLba, uint32_t nSectors) {
180 ByteSet(&command, 0,
sizeof(command));
181 command.nOpCode = 0x8A;
182 command.nLba = HOST_TO_BIG64(nLba);
183 command.nSectors = HOST_TO_BIG32(nSectors);
186size_t Write16::serialise(uintptr_t& addr) {
187 addr =
reinterpret_cast<uintptr_t
>(&command);
188 return sizeof(command);
191Synchronise10::Synchronise10(uint32_t nLba, uint32_t nSectors) {
192 ByteSet(&command, 0,
sizeof(command));
193 command.nOpCode = 0x35;
194 command.nLba = HOST_TO_BIG32(nLba);
195 command.nBlocks = HOST_TO_BIG16(nSectors);
198size_t Synchronise10::serialise(uintptr_t& addr) {
199 addr =
reinterpret_cast<uintptr_t
>(&command);
200 return sizeof(command);
203Synchronise16::Synchronise16(uint64_t nLba, uint32_t nSectors) {
204 ByteSet(&command, 0,
sizeof(command));
205 command.nOpCode = 0x91;
206 command.nLba = HOST_TO_BIG64(nLba);
207 command.nBlocks = HOST_TO_BIG32(nSectors);
210size_t Synchronise16::serialise(uintptr_t& addr) {
211 addr =
reinterpret_cast<uintptr_t
>(&command);
212 return sizeof(command);