ReactOS 0.4.15-dev-7918-g2a2556c
id_sata.h
Go to the documentation of this file.
1/*++
2
3Copyright (c) 2008-2012 Alexandr A. Telyatnikov (Alter)
4
5Module Name:
6 id_probe.cpp
7
8Abstract:
9 This module handles SATA-related staff
10
11Author:
12 Alexander A. Telyatnikov (Alter)
13
14Environment:
15 kernel mode only
16
17Notes:
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
30Revision History:
31
32Licence:
33 GPLv2
34
35--*/
36
37#ifndef __UNIATA_SATA__H__
38#define __UNIATA_SATA__H__
39
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
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
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
78 IN PVOID HwDeviceExtension,
79 IN ULONG lChannel, // logical channel
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
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
106ULONG
107NTAPI
109 IN PHW_CHANNEL chan,
110 IN ULONG io_port_ndx,
111 IN ULONG pm_port=0 /* for port multipliers */
112 );
113
114VOID
115NTAPI
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
124NTAPI
126 IN PVOID HwDeviceExtension
127 );
128
129#ifdef _DEBUG
130VOID
131NTAPI
132UniataDumpAhciPortRegs(
133 IN PHW_CHANNEL chan
134 );
135#endif
136
138NTAPI
140 IN PVOID HwDeviceExtension,
141 IN PPCI_COMMON_CONFIG pciData, // optional
143 );
144
145UCHAR
146NTAPI
148 IN PVOID HwDeviceExtension,
149 IN ULONG lChannel,
151 );
152
153VOID
154NTAPI
156 IN PHW_CHANNEL chan,
159 );
160
161ULONG
162NTAPI
164 IN PHW_DEVICE_EXTENSION deviceExtension,
166 IN ULONG lChannel,
167 OUT PUCHAR fis,
172 );
173
174UCHAR
175NTAPI
177 IN PHW_CHANNEL chan,
179 );
180
181UCHAR
182NTAPI
184 IN PVOID HwDeviceExtension,
185 IN ULONG lChannel,
187 IN USHORT ahci_flags,
189 );
190
191UCHAR
192NTAPI
194 IN PVOID HwDeviceExtension,
195 IN ULONG lChannel,
198 IN PUCHAR data,
204 IN USHORT ahci_flags,
205 IN ULONG flags,
207 );
208
209UCHAR
210NTAPI
212 IN PVOID HwDeviceExtension,
213 IN ULONG lChannel,
217 IN ULONG wait_flags,
219 );
220
222NTAPI
224 IN PHW_CHANNEL chan
225 );
226
227ULONG
228NTAPI
230 IN PVOID HwDeviceExtension,
231 IN ULONG lChannel,
233 );
234
235ULONG
236NTAPI
238 IN PHW_CHANNEL chan,
240 );
241
242ULONG
243NTAPI
245 IN PVOID HwDeviceExtension,
246 IN ULONG lChannel,
247 OUT PULONG signature
248 );
249
250VOID
251NTAPI
253 IN PVOID HwDeviceExtension,
254 IN ULONG lChannel
255 );
256
257VOID
258NTAPI
260 IN PHW_CHANNEL chan
261 );
262
264NTAPI
266 IN PHW_CHANNEL chan
267 );
268
269VOID
270NTAPI
272 IN PHW_CHANNEL chan
273 );
274
276NTAPI
278 IN PHW_CHANNEL chan
279 );
280
282NTAPI
284 IN PHW_CHANNEL chan
285 );
286
287
288__inline
289ULONG
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
301VOID
303 IN PHW_CHANNEL chan,
304 IN ULONG io_port_ndx,
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
319UCHAR
320NTAPI
322 IN PVOID HwDeviceExtension,
323 IN ULONG lChannel,
326 );
327
328UCHAR
329NTAPI
331 IN PVOID HwDeviceExtension,
332 IN ULONG lChannel,
335 );
336
337VOID
338NTAPI
340 IN PHW_CHANNEL chan
341 );
342
343__inline
344ULONG
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
356USHORT
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
381NTAPI
383 IN PHW_CHANNEL chan,
385 IN ULONG Reg,
387 );
388
389UCHAR
390NTAPI
392 IN PHW_CHANNEL chan,
394 IN ULONG Reg,
396 );
397
398VOID
400IN OUT PATA_REQ AtaReq
401 );
402
404NTAPI
406 IN PVOID HwDeviceExtension,
408 IN ULONG lChannel,
410 IN ULONG Length = 0
411 );
412
413__inline
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__
unsigned char BOOLEAN
UCHAR const AtaCommandFlags[256]
Definition: atacmd_map.h:25
#define ATA_AHCI_CMD_WRITE
Definition: bsmaster.h:816
VOID DDKFASTAPI AtapiWritePortEx4(IN PHW_CHANNEL chan, IN ULONGIO_PTR port, IN ULONG offs, IN ULONG data)
ULONG DDKFASTAPI AtapiReadPortEx4(IN PHW_CHANNEL chan, IN ULONGIO_PTR port, IN ULONG offs)
#define IDX_SATA_SStatus
Definition: bsmaster.h:457
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
Definition: bufpool.h:45
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ULONGIO_PTR
Definition: config.h:102
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const GLubyte * c
Definition: glext.h:8905
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
VOID NTAPI UniataAhciStartFR(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2024
VOID NTAPI UniataAhciResume(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2390
BOOLEAN NTAPI UniataAhciStop(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2140
__inline ULONG UniataAhciUlongFromRFIS(PUCHAR RCV_FIS)
Definition: id_sata.h:345
__inline ULONG UniataAhciReadChannelPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx)
Definition: id_sata.h:290
BOOLEAN NTAPI UniataSataClearErr(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN BOOLEAN do_connect, IN ULONG pm_port=0)
Definition: id_sata.cpp:186
UCHAR NTAPI UniataAhciWritePM(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN ULONG Reg, IN ULONG value)
Definition: id_sata.cpp:2547
VOID NTAPI UniataAhciStart(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2071
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
BOOLEAN NTAPI UniataAhciReadPM(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN ULONG Reg, OUT PULONG result)
Definition: id_sata.cpp:2491
ULONG NTAPI UniataAhciWaitReady(IN PHW_CHANNEL chan, IN ULONG timeout)
Definition: id_sata.cpp:1853
__inline USHORT UniAtaAhciAdjustIoFlags(IN UCHAR command, IN USHORT ahci_flags, IN ULONG fis_size, IN ULONG DeviceNumber)
Definition: id_sata.h:357
UCHAR NTAPI UniataAhciStatus(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber)
Definition: id_sata.cpp:1131
BOOLEAN NTAPI UniataAhciDetect(IN PVOID HwDeviceExtension, IN PPCI_COMMON_CONFIG pciData, IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo)
Definition: id_sata.cpp:890
#define UNIATA_SATA_FAST_ENABLE
Definition: id_sata.h:49
ULONG NTAPI UniataAhciHardReset(IN PVOID HwDeviceExtension, IN ULONG lChannel, OUT PULONG signature)
Definition: id_sata.cpp:1880
ULONG NTAPI UniataSataReadPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx, IN ULONG pm_port=0)
Definition: id_sata.cpp:270
VOID NTAPI UniataAhciSnapAtaRegs(IN PHW_CHANNEL chan, IN ULONG DeviceNumber, IN OUT PIDEREGS_EX regs)
Definition: id_sata.cpp:1216
UCHAR NTAPI UniataAhciSendCommand(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN USHORT ahci_flags, IN ULONG timeout)
Definition: id_sata.cpp:1496
VOID NTAPI UniataAhciReset(IN PVOID HwDeviceExtension, IN ULONG lChannel)
Definition: id_sata.cpp:1925
__inline BOOLEAN UniataAhciChanImplemented(IN PHW_DEVICE_EXTENSION deviceExtension, IN ULONG c)
Definition: id_sata.h:415
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
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
UCHAR NTAPI UniataSataConnect(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG pm_port=0)
Definition: id_sata.cpp:44
__inline BOOLEAN UniataIsSATARangeAvailable(IN PHW_DEVICE_EXTENSION deviceExtension, IN ULONG lChannel)
Definition: id_sata.h:91
UCHAR NTAPI UniataAhciBeginTransaction(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb)
Definition: id_sata.cpp:2171
BOOLEAN NTAPI UniataAhciStopFR(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2042
BOOLEAN NTAPI UniataAhciCLO(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:2102
UCHAR NTAPI UniataAhciWaitCommandReady(IN PHW_CHANNEL chan, IN ULONG timeout)
Definition: id_sata.cpp:1434
BOOLEAN NTAPI UniataAhciAbortOperation(IN PHW_CHANNEL chan)
Definition: id_sata.cpp:1765
ULONG NTAPI UniataAhciSoftReset(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber)
Definition: id_sata.cpp:1787
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
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
BOOLEAN NTAPI UniataSataEvent(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG Action, IN ULONG pm_port=0)
Definition: id_sata.cpp:233
__inline VOID UniataAhciWriteChannelPort4(IN PHW_CHANNEL chan, IN ULONG io_port_ndx, IN ULONG data)
Definition: id_sata.h:302
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
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 UniataAhciEndTransaction(IN PVOID HwDeviceExtension, IN ULONG lChannel, IN ULONG DeviceNumber, IN PSCSI_REQUEST_BLOCK Srb)
Definition: id_sata.cpp:2294
INTERNETFEATURELIST feature
Definition: misc.c:1719
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
struct @5016 regs[]
Definition: dhcpd.h:245
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define lba
#define ATA_CMD_FLAG_Out
Definition: atapi.h:1603
#define KdPrint3(_x_)
Definition: atapi.h:153
#define KdPrint2(_x_)
Definition: atapi.h:154
#define PRINT_PREFIX
Definition: atapi.h:150
Definition: pdh_main.c:94
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
unsigned char UCHAR
Definition: xmlstorage.h:181