ReactOS  0.4.14-dev-115-g4576127
id_sata.h
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) 2008-2012 Alexandr A. Telyatnikov (Alter)
4 
5 Module Name:
6  id_probe.cpp
7 
8 Abstract:
9  This module handles SATA-related staff
10 
11 Author:
12  Alexander A. Telyatnikov (Alter)
13 
14 Environment:
15  kernel mode only
16 
17 Notes:
18 
19  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 Revision History:
31 
32 Licence:
33  GPLv2
34 
35 --*/
36 
37 #ifndef __UNIATA_SATA__H__
38 #define __UNIATA_SATA__H__
39 
40 UCHAR
41 NTAPI
43  IN PVOID HwDeviceExtension,
44  IN ULONG lChannel, // logical channel
45  IN ULONG pm_port = 0 /* for port multipliers */
46  );
47 
48 #define UNIATA_SATA_RESET_ENABLE TRUE
49 #define UNIATA_SATA_FAST_ENABLE FALSE
50 
51 UCHAR
52 NTAPI
54  IN PVOID HwDeviceExtension,
55  IN ULONG lChannel, // logical channel
56  IN ULONG pm_port = 0, /* for port multipliers */
58  );
59 
60 #define UNIATA_SATA_DO_CONNECT TRUE
61 #define UNIATA_SATA_IGNORE_CONNECT FALSE
62 
63 BOOLEAN
64 NTAPI
66  IN PVOID HwDeviceExtension,
67  IN ULONG lChannel, // logical channel
68  IN BOOLEAN do_connect,
69  IN ULONG pm_port = 0 /* for port multipliers */
70  );
71 
72 #define UNIATA_SATA_EVENT_ATTACH 0x01
73 #define UNIATA_SATA_EVENT_DETACH 0x02
74 
75 BOOLEAN
76 NTAPI
78  IN PVOID HwDeviceExtension,
79  IN ULONG lChannel, // logical channel
80  IN ULONG Action,
81  IN ULONG pm_port = 0 /* for port multipliers */
82  );
83 /*
84 #define UniataIsSATARangeAvailable(deviceExtension, lChannel) \
85  ((deviceExtension->BaseIoAddressSATA_0.Addr || \
86  deviceExtension->BaseIoAHCI_0.Addr) && \
87  (deviceExtension->chan[lChannel].RegTranslation[IDX_SATA_SStatus].Addr))
88 */
89 __inline
90 BOOLEAN
92  IN PHW_DEVICE_EXTENSION deviceExtension,
93  IN ULONG lChannel
94  )
95 {
96  // seems, check for deviceExtension->BaseIoAddressSATA_0.Addr and
97  // deviceExtension->BaseIoAHCI_0.Addr is not necessary now
98  if(deviceExtension->chan[lChannel].RegTranslation[IDX_SATA_SStatus].Addr ||
99  deviceExtension->chan[lChannel].RegTranslation[IDX_SATA_SStatus].Proc) {
100  return TRUE;
101  }
102  return FALSE;
103 } // end UniataIsSATARangeAvailable()
104 
105 
106 ULONG
107 NTAPI
109  IN PHW_CHANNEL chan,
110  IN ULONG io_port_ndx,
111  IN ULONG pm_port=0 /* for port multipliers */
112  );
113 
114 VOID
115 NTAPI
117  IN PHW_CHANNEL chan,
118  IN ULONG io_port_ndx,
119  IN ULONG data,
120  IN ULONG pm_port=0 /* for port multipliers */
121  );
122 
123 BOOLEAN
124 NTAPI
126  IN PVOID HwDeviceExtension
127  );
128 
129 #ifdef _DEBUG
130 VOID
131 NTAPI
132 UniataDumpAhciPortRegs(
133  IN PHW_CHANNEL chan
134  );
135 #endif
136 
137 BOOLEAN
138 NTAPI
140  IN PVOID HwDeviceExtension,
141  IN PPCI_COMMON_CONFIG pciData, // optional
143  );
144 
145 UCHAR
146 NTAPI
148  IN PVOID HwDeviceExtension,
149  IN ULONG lChannel,
151  );
152 
153 VOID
154 NTAPI
156  IN PHW_CHANNEL chan,
159  );
160 
161 ULONG
162 NTAPI
164  IN PHW_DEVICE_EXTENSION deviceExtension,
166  IN ULONG lChannel,
167  OUT PUCHAR fis,
168  IN UCHAR command,
169  IN ULONGLONG lba,
170  IN USHORT count,
172  );
173 
174 UCHAR
175 NTAPI
177  IN PHW_CHANNEL chan,
179  );
180 
181 UCHAR
182 NTAPI
184  IN PVOID HwDeviceExtension,
185  IN ULONG lChannel,
187  IN USHORT ahci_flags,
189  );
190 
191 UCHAR
192 NTAPI
194  IN PVOID HwDeviceExtension,
195  IN ULONG lChannel,
198  IN PUCHAR data,
199  IN ULONG length,
200  IN UCHAR command,
201  IN ULONGLONG lba,
202  IN USHORT count,
203  IN USHORT feature,
204  IN USHORT ahci_flags,
205  IN ULONG flags,
207  );
208 
209 UCHAR
210 NTAPI
212  IN PVOID HwDeviceExtension,
213  IN ULONG lChannel,
217  IN ULONG wait_flags,
219  );
220 
221 BOOLEAN
222 NTAPI
224  IN PHW_CHANNEL chan
225  );
226 
227 ULONG
228 NTAPI
230  IN PVOID HwDeviceExtension,
231  IN ULONG lChannel,
233  );
234 
235 ULONG
236 NTAPI
238  IN PHW_CHANNEL chan,
240  );
241 
242 ULONG
243 NTAPI
245  IN PVOID HwDeviceExtension,
246  IN ULONG lChannel,
247  OUT PULONG signature
248  );
249 
250 VOID
251 NTAPI
253  IN PVOID HwDeviceExtension,
254  IN ULONG lChannel
255  );
256 
257 VOID
258 NTAPI
260  IN PHW_CHANNEL chan
261  );
262 
263 BOOLEAN
264 NTAPI
266  IN PHW_CHANNEL chan
267  );
268 
269 VOID
270 NTAPI
272  IN PHW_CHANNEL chan
273  );
274 
275 BOOLEAN
276 NTAPI
278  IN PHW_CHANNEL chan
279  );
280 
281 BOOLEAN
282 NTAPI
284  IN PHW_CHANNEL chan
285  );
286 
287 
288 __inline
289 ULONG
291  IN PHW_CHANNEL chan,
292  IN ULONG io_port_ndx
293  )
294 {
295  volatile ULONG v = AtapiReadPortEx4(NULL, (ULONGIO_PTR)&((chan)->BaseIoAHCI_Port), io_port_ndx);
296  KdPrint3((PRINT_PREFIX "ReadChannelPort4 ch%d[%x] = %x\n", chan->lChannel, io_port_ndx, v));
297  return v;
298 } // end UniataAhciReadChannelPort4()
299 
300 __inline
301 VOID
303  IN PHW_CHANNEL chan,
304  IN ULONG io_port_ndx,
305  IN ULONG data
306  )
307 {
308  KdPrint3((PRINT_PREFIX "WriteChannelPort4 %x => ch%d[%x]\n", data, chan->lChannel, io_port_ndx));
309  AtapiWritePortEx4(NULL, (ULONGIO_PTR)&((chan)->BaseIoAHCI_Port), io_port_ndx, data);
310 } // end UniataAhciWriteChannelPort4()
311 
312 
313 #define UniataAhciReadHostPort4(deviceExtension, io_port_ndx) \
314  AtapiReadPortEx4(NULL, (ULONGIO_PTR)&((deviceExtension)->BaseIoAHCI_0), io_port_ndx)
315 
316 #define UniataAhciWriteHostPort4(deviceExtension, io_port_ndx, data) \
317  AtapiWritePortEx4(NULL, (ULONGIO_PTR)&((deviceExtension)->BaseIoAHCI_0), io_port_ndx, data)
318 
319 UCHAR
320 NTAPI
322  IN PVOID HwDeviceExtension,
323  IN ULONG lChannel,
326  );
327 
328 UCHAR
329 NTAPI
331  IN PVOID HwDeviceExtension,
332  IN ULONG lChannel,
335  );
336 
337 VOID
338 NTAPI
340  IN PHW_CHANNEL chan
341  );
342 
343 __inline
344 ULONG
346  PUCHAR RCV_FIS
347  )
348 {
349  return ( (((ULONG)(RCV_FIS[6])) << 24) |
350  (((ULONG)(RCV_FIS[5])) << 16) |
351  (((ULONG)(RCV_FIS[4])) << 8) |
352  ((ULONG)(RCV_FIS[12])) );
353 } // end UniataAhciUlongFromRFIS()
354 
355 __inline
356 USHORT
358  IN UCHAR command,
359  IN USHORT ahci_flags,
360  IN ULONG fis_size,
362  )
363 {
364  ahci_flags |= (fis_size / sizeof(ULONG)) | (DeviceNumber << 12);
365  if(!command) {
366  return ahci_flags;
367  }
368 
370  ahci_flags |= ATA_AHCI_CMD_WRITE;
371  }
372 /*
373  if(AtaCommandFlags[command] & ATA_CMD_FLAG_In) {
374  ahci_flags |= ATA_AHCI_CMD_READ;
375  }
376 */
377  return ahci_flags;
378 } // end UniAtaAhciAdjustIoFlags()
379 
380 BOOLEAN
381 NTAPI
383  IN PHW_CHANNEL chan,
385  IN ULONG Reg,
387  );
388 
389 UCHAR
390 NTAPI
392  IN PHW_CHANNEL chan,
394  IN ULONG Reg,
395  IN ULONG value
396  );
397 
398 VOID
400 IN OUT PATA_REQ AtaReq
401  );
402 
404 NTAPI
406  IN PVOID HwDeviceExtension,
408  IN ULONG lChannel,
409  IN PUCHAR Buffer = NULL,
410  IN ULONG Length = 0
411  );
412 
413 __inline
414 BOOLEAN
416  IN PHW_DEVICE_EXTENSION deviceExtension,
417  IN ULONG c
418  )
419 {
420 #ifdef _DEBUG
421  KdPrint2((PRINT_PREFIX "imp: %#x & %#x\n", (deviceExtension)->AHCI_PI, (1<<c) ));
422 #endif
423  return (((deviceExtension)->AHCI_PI) & ((ULONG)1 << c)) ? TRUE : FALSE;
424 } // end UniataAhciChanImplemented()
425 
426 
427 #endif //__UNIATA_SATA__H__
ULONG NTAPI UniataAhciHardReset(IN PVOID HwDeviceExtension, IN ULONG lChannel, OUT PULONG signature)
Definition: id_sata.cpp:1880
INTERNETFEATURELIST feature
Definition: misc.c:1689
VOID NTAPI UniataAhciSnapAtaRegs(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN OUT PIDEREGS_EX regs)
Definition: id_sata.cpp:1216
#define ATA_AHCI_CMD_WRITE
Definition: bsmaster.h:816
#define IN
Definition: typedefs.h:38
UCHAR const AtaCommandFlags[256]
Definition: atacmd_map.h:25
VOID NTAPI UniataAhciReset(IN PVOID HwDeviceExtension, IN ULONG lChannel)
Definition: id_sata.cpp:1925
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI UniataAhciStopFR(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2042
#define KdPrint2(_x_)
Definition: atapi.h:154
__inline ULONG UniataAhciReadChannelPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx)
Definition: id_sata.h:290
BOOLEAN NTAPI UniataSataEvent(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG Action, IN ULONG pm_port=0)
Definition: id_sata.cpp:233
UCHAR NTAPI UniataAhciStatus(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber)
Definition: id_sata.cpp:1131
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned char * PUCHAR
Definition: retypes.h:3
BOOLEAN NTAPI UniataAhciDetect(IN PVOID HwDeviceExtension, IN PPCI_COMMON_CONFIG pciData, IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo)
Definition: id_sata.cpp:890
UCHAR NTAPI UniataAhciBeginTransaction(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb)
Definition: id_sata.cpp:2171
__inline USHORT UniAtaAhciAdjustIoFlags(IN UCHAR command, IN USHORT ahci_flags, IN ULONG fis_size, IN ULONG DeviceNumber)
Definition: id_sata.h:357
BOOLEAN NTAPI UniataAhciCLO(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2102
#define UNIATA_SATA_FAST_ENABLE
Definition: id_sata.h:49
PSCSI_REQUEST_BLOCK NTAPI BuildAhciInternalSrb(IN PVOID HwDeviceExtension, IN ULONG DeviceNumber, IN ULONG lChannel, IN PUCHAR Buffer=NULL, IN ULONG Length=0)
Definition: id_sata.cpp:2644
Definition: dhcpd.h:245
BOOLEAN NTAPI UniataAhciStop(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2140
__inline VOID UniataAhciWriteChannelPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx, IN ULONG data)
Definition: id_sata.h:302
#define lba
ULONG NTAPI UniataAhciSoftReset(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber)
Definition: id_sata.cpp:1787
__inline ULONG UniataAhciUlongFromRFIS(PUCHAR RCV_FIS)
Definition: id_sata.h:345
BOOLEAN NTAPI UniataAhciAbortOperation(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:1765
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned char BOOLEAN
UCHAR NTAPI UniataAhciSendCommand(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN USHORT ahci_flags, IN ULONG timeout)
Definition: id_sata.cpp:1496
smooth NULL
Definition: ftsmooth.c:416
ULONG NTAPI UniataSataReadPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx, IN ULONG pm_port=0)
Definition: id_sata.cpp:270
Definition: bufpool.h:45
VOID NTAPI UniataAhciStart(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2071
UCHAR NTAPI UniataAhciEndTransaction(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb)
Definition: id_sata.cpp:2294
__inline BOOLEAN UniataIsSATARangeAvailable(IN PHW_DEVICE_EXTENSION deviceExtension, IN ULONG lChannel)
Definition: id_sata.h:91
VOID NTAPI UniataAhciResume(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2390
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
uint64_t ULONGLONG
Definition: typedefs.h:65
VOID NTAPI UniataAhciStartFR(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2024
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG Action
Definition: fsrtlfuncs.h:738
const GLubyte * c
Definition: glext.h:8905
BOOLEAN NTAPI UniataAhciReadPM(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN ULONG Reg, OUT PULONG result)
Definition: id_sata.cpp:2491
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
unsigned char UCHAR
Definition: xmlstorage.h:181
#define KdPrint3(_x_)
Definition: atapi.h:153
UCHAR NTAPI UniataAhciWritePM(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN ULONG Reg, IN ULONG value)
Definition: id_sata.cpp:2547
VOID UniataAhciSetupCmdPtr(IN OUT PATA_REQ AtaReq)
Definition: id_sata.cpp:2611
BOOLEAN NTAPI UniataAhciInit(IN PVOID HwDeviceExtension)
Definition: id_sata.cpp:645
UCHAR NTAPI UniataAhciWaitCommandReady(IN PHW_CHANNEL chan, IN ULONG timeout)
Definition: id_sata.cpp:1434
const GLdouble * v
Definition: gl.h:2040
ULONG NTAPI UniataAhciWaitReady(IN PHW_CHANNEL chan, IN ULONG timeout)
Definition: id_sata.cpp:1853
unsigned short USHORT
Definition: pedump.c:61
VOID DDKFASTAPI AtapiWritePortEx4(IN PHW_CHANNEL chan, IN ULONGIO_PTR port, IN ULONG offs, IN ULONG data)
VOID NTAPI UniataSataWritePort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx, IN ULONG data, IN ULONG pm_port=0)
Definition: id_sata.cpp:357
unsigned int * PULONG
Definition: retypes.h:1
UCHAR NTAPI UniataSataPhyEnable(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG pm_port=0, IN BOOLEAN doReset=UNIATA_SATA_FAST_ENABLE)
Definition: id_sata.cpp:124
#define ATA_CMD_FLAG_Out
Definition: atapi.h:1605
#define IDX_SATA_SStatus
Definition: bsmaster.h:457
ULONG DDKFASTAPI AtapiReadPortEx4(IN PHW_CHANNEL chan, IN ULONGIO_PTR port, IN ULONG offs)
#define PRINT_PREFIX
Definition: atapi.h:150
ULONG NTAPI UniataAhciSetupFIS_H2D(IN PHW_DEVICE_EXTENSION deviceExtension, IN ULONG DeviceNumber, IN ULONG lChannel, OUT PUCHAR fis, IN UCHAR command, IN ULONGLONG lba, IN USHORT count, IN USHORT feature)
Definition: id_sata.cpp:1241
UCHAR NTAPI UniataAhciSendPIOCommand(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb, IN PUCHAR data, IN ULONG length, IN UCHAR command, IN ULONGLONG lba, IN USHORT count, IN USHORT feature, IN USHORT ahci_flags, IN ULONG flags, IN ULONG timeout)
Definition: id_sata.cpp:1538
#define OUT
Definition: typedefs.h:39
UCHAR NTAPI UniataAhciSendPIOCommandDirect(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb, IN PIDEREGS_EX regs, IN ULONG wait_flags, IN ULONG timeout)
Definition: id_sata.cpp:1655
unsigned int ULONG
Definition: retypes.h:1
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1036
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
BOOLEAN NTAPI UniataSataClearErr(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN BOOLEAN do_connect, IN ULONG pm_port=0)
Definition: id_sata.cpp:186
GLuint64EXT * result
Definition: glext.h:11304
#define ULONGIO_PTR
Definition: config.h:102
struct @4020 regs[]
UCHAR NTAPI UniataSataConnect(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG pm_port=0)
Definition: id_sata.cpp:44
__inline BOOLEAN UniataAhciChanImplemented(IN PHW_DEVICE_EXTENSION deviceExtension, IN ULONG c)
Definition: id_sata.h:415