The Pedigree Project  0.1
ScsiCommands.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef SCSICOMMANDS_H
21 #define SCSICOMMANDS_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
27 {
28  public:
29  ScsiCommand();
30  virtual ~ScsiCommand();
31 
32  virtual size_t serialise(uintptr_t &addr) = 0;
33 };
34 
35 namespace ScsiCommands
36 {
37 class Inquiry : public ScsiCommand
38 {
39  public:
40  Inquiry(
41  uint16_t len = 0, bool enableVitalData = false, uint8_t pageCode = 0,
42  uint8_t ctl = 0);
43 
44  virtual size_t serialise(uintptr_t &addr);
45 
46  struct
47  {
48  uint8_t opcode;
49  uint8_t epvd;
50  uint8_t pageCode;
51  uint16_t len;
52  uint8_t control;
53  } PACKED command;
54 };
55 
56 class UnitReady : public ScsiCommand
57 {
58  public:
59  UnitReady(uint8_t ctl = 0);
60 
61  virtual size_t serialise(uintptr_t &addr);
62 
63  struct
64  {
65  uint8_t opcode;
66  uint32_t rsvd;
67  uint8_t control;
68  } PACKED command;
69 };
70 
71 class ReadSense : public ScsiCommand
72 {
73  public:
74  ReadSense(uint8_t desc, uint8_t len, uint8_t ctl = 0);
75 
76  virtual size_t serialise(uintptr_t &addr);
77 
78  struct
79  {
80  uint8_t opcode;
81  uint8_t desc;
82  uint16_t rsvd;
83  uint8_t len;
84  uint8_t control;
85  } PACKED command;
86 };
87 
88 class StartStop : public ScsiCommand
89 {
90  public:
91  StartStop(
92  bool imm, uint8_t newpower, bool eject_load, bool start,
93  uint8_t ctl = 0);
94 
95  virtual size_t serialise(uintptr_t &addr);
96 
97  struct
98  {
99  uint8_t opcode;
100  uint8_t imm;
101  uint16_t rsvd;
102  uint8_t setup;
103  uint8_t control;
104  } PACKED command;
105 };
106 
108 {
109  public:
111  bool selfTest, uint8_t selfTestCode = 0, uintptr_t params = 0,
112  size_t paramLen = 0, bool deviceOffline = false,
113  bool unitOffline = false, uint8_t ctl = 0);
114 
115  virtual size_t serialise(uintptr_t &addr);
116 
117  struct
118  {
119  uint8_t opcode;
120  uint32_t unitOffline : 1;
121  uint32_t devOffline : 1;
122  uint32_t selfTest : 1;
123  uint32_t rsvd1 : 1;
124  uint32_t pf : 1;
125  uint32_t selfTestCode : 3;
126  uint8_t rsvd2;
127  uint16_t paramListLen;
128  uint8_t control;
129  } PACKED command;
130 };
131 
133 {
134  public:
135  ReadTocCommand(uint16_t nativeBlockSize, uint8_t ctl = 0);
136 
137  virtual size_t serialise(uintptr_t &addr);
138 
139  struct
140  {
141  uint8_t opcode;
142  uint8_t flags;
143  uint8_t format;
144  uint8_t rsvd1;
145  uint8_t rsvd2;
146  uint8_t rsvd3;
147  uint8_t track;
148  uint16_t len;
149  uint8_t control;
150  } PACKED command;
151 
152  struct TocEntry
153  {
154  uint8_t Rsvd1;
155  uint8_t Flags;
156  uint8_t TrackNum;
157  uint8_t Rsvd2;
158  uint32_t TrackStart;
159  } PACKED;
160 };
161 
163 {
164  public:
165  ReadCapacity10(uint8_t ctl = 0);
166 
167  virtual size_t serialise(uintptr_t &addr);
168 
169  struct
170  {
171  uint8_t opcode;
172  uint8_t obsolete_rsvd;
173  uint32_t lba;
174  uint8_t rsvd[2];
175  uint8_t pmi;
176  uint8_t control;
177  } PACKED command;
178 };
179 
180 class Read10 : public ScsiCommand
181 {
182  public:
183  Read10(uint32_t nLba, uint32_t nSectors);
184 
185  virtual size_t serialise(uintptr_t &addr);
186 
187  struct command
188  {
189  uint8_t nOpCode;
190  uint8_t bRelAddr : 1;
191  uint8_t res0 : 2;
192  uint8_t bFUA : 1;
193  uint8_t bDPO : 1;
194  uint8_t res1 : 3;
195  uint32_t nLba;
196  uint8_t res2;
197  uint16_t nSectors;
198  uint8_t nControl;
199  } PACKED command;
200 };
201 
202 class Read12 : public ScsiCommand
203 {
204  public:
205  Read12(uint32_t nLba, uint32_t nSectors);
206 
207  virtual size_t serialise(uintptr_t &addr);
208 
209  struct command
210  {
211  uint8_t nOpCode;
212  uint8_t bRelAddr : 1;
213  uint8_t res0 : 2;
214  uint8_t bFUA : 1;
215  uint8_t bDPO : 1;
216  uint8_t res1 : 3;
217  uint32_t nLba;
218  uint32_t nSectors;
219  uint8_t res2;
220  uint8_t nControl;
221  } PACKED command;
222 };
223 
224 class Read16 : public ScsiCommand
225 {
226  public:
227  Read16(uint32_t nLba, uint32_t nSectors);
228 
229  virtual size_t serialise(uintptr_t &addr);
230 
231  struct command
232  {
233  uint8_t nOpCode;
234  uint8_t bRelAddr : 1;
235  uint8_t res0 : 2;
236  uint8_t bFUA : 1;
237  uint8_t bDPO : 1;
238  uint8_t res1 : 3;
239  uint64_t nLba;
240  uint32_t nSectors;
241  uint8_t res2;
242  uint8_t nControl;
243  } PACKED command;
244 };
245 
246 class Write10 : public ScsiCommand
247 {
248  public:
249  Write10(uint32_t nLba, uint32_t nSectors);
250 
251  virtual size_t serialise(uintptr_t &addr);
252 
253  struct command
254  {
255  uint8_t nOpCode;
256  uint8_t obs : 1;
257  uint8_t bFUA_NV : 1;
258  uint8_t res1 : 1;
259  uint8_t bFUA : 1;
260  uint8_t bDPO : 1;
261  uint8_t nWrProtect : 3;
262  uint32_t nLba;
263  uint8_t res2;
264  uint16_t nSectors;
265  uint8_t nControl;
266  } PACKED command;
267 };
268 
269 class Write12 : public ScsiCommand
270 {
271  public:
272  Write12(uint32_t nLba, uint32_t nSectors);
273 
274  virtual size_t serialise(uintptr_t &addr);
275 
276  struct command
277  {
278  uint8_t nOpCode;
279  uint8_t obs : 1;
280  uint8_t bFUA_NV : 1;
281  uint8_t res1 : 1;
282  uint8_t bFUA : 1;
283  uint8_t bDPO : 1;
284  uint8_t nWrProtect : 3;
285  uint32_t nLba;
286  uint32_t nSectors;
287  uint8_t res2;
288  uint8_t nControl;
289  } PACKED command;
290 };
291 
292 class Write16 : public ScsiCommand
293 {
294  public:
295  Write16(uint32_t nLba, uint32_t nSectors);
296 
297  virtual size_t serialise(uintptr_t &addr);
298 
299  struct command
300  {
301  uint8_t nOpCode;
302  uint8_t obs : 1;
303  uint8_t bFUA_NV : 1;
304  uint8_t res1 : 1;
305  uint8_t bFUA : 1;
306  uint8_t bDPO : 1;
307  uint8_t nWrProtect : 3;
308  uint64_t nLba;
309  uint32_t nSectors;
310  uint8_t res2;
311  uint8_t nControl;
312  } PACKED command;
313 };
314 
316 {
317  public:
318  Synchronise10(uint32_t nLba, uint32_t nSectors);
319 
320  virtual size_t serialise(uintptr_t &addr);
321 
322  struct command
323  {
324  uint8_t nOpCode;
325  uint8_t obs : 1;
326  uint8_t bImmed : 1;
327  uint8_t bSyncNV : 1;
328  uint8_t rsvd1 : 5;
329  uint32_t nLba;
330  uint8_t nGroup : 5;
331  uint8_t rsvd2 : 3;
332  uint16_t nBlocks;
333  uint8_t nControl;
334  } PACKED command;
335 };
336 
338 {
339  public:
340  Synchronise16(uint32_t nLba, uint32_t nSectors);
341 
342  virtual size_t serialise(uintptr_t &addr);
343 
344  struct command
345  {
346  uint8_t nOpCode;
347  uint8_t obs : 1;
348  uint8_t bImmed : 1;
349  uint8_t bSyncNV : 1;
350  uint8_t rsvd1 : 5;
351  uint64_t nLba;
352  uint32_t nBlocks;
353  uint8_t nGroup : 5;
354  uint8_t rsvd2 : 3;
355  uint8_t nControl;
356  } PACKED command;
357 };
358 }; // namespace ScsiCommands
359 
360 #endif