3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "SataSiI3132.h"
11 #include <IndustryStandard/Atapi.h>
12 #include <Library/DevicePathLib.h>
16 IN SATA_SI3132_INSTANCE
* SataInstance
,
18 IN UINT16 PortMultiplierPort
21 SATA_SI3132_PORT
*SataPort
;
22 SATA_SI3132_DEVICE
*SataDevice
;
24 if (Port
>= SATA_SII3132_MAXPORT
) {
28 SataPort
= &(SataInstance
->Ports
[Port
]);
29 List
= SataPort
->Devices
.ForwardLink
;
31 while (List
!= &SataPort
->Devices
) {
32 SataDevice
= (SATA_SI3132_DEVICE
*)List
;
33 if (SataDevice
->Index
== PortMultiplierPort
) {
36 List
= List
->ForwardLink
;
43 SiI3132AtaPassThruCommand (
44 IN SATA_SI3132_INSTANCE
*SataSiI3132Instance
,
45 IN SATA_SI3132_PORT
*SataPort
,
46 IN UINT16 PortMultiplierPort
,
47 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
48 IN EFI_EVENT Event OPTIONAL
51 SATA_SI3132_DEVICE
*SataDevice
;
52 EFI_PHYSICAL_ADDRESS PhysInDataBuffer
;
53 UINTN InDataBufferLength
= 0;
54 EFI_PHYSICAL_ADDRESS PhysOutDataBuffer
;
55 UINTN OutDataBufferLength
;
56 CONST UINTN EmptySlot
= 0;
57 UINTN Control
= PRB_CTRL_ATA
;
59 UINT32 Value32
, Error
, Timeout
= 0;
60 CONST UINT32 IrqMask
= (SII3132_PORT_INT_CMDCOMPL
| SII3132_PORT_INT_CMDERR
) << 16;
62 VOID
* PciAllocMapping
= NULL
;
63 EFI_PCI_IO_PROTOCOL
*PciIo
;
65 PciIo
= SataSiI3132Instance
->PciIo
;
66 ZeroMem (SataPort
->HostPRB
, sizeof (SATA_SI3132_PRB
));
68 // Construct Si3132 PRB
69 switch (Packet
->Protocol
) {
70 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_HARDWARE_RESET
:
71 ASSERT (0); //TODO: Implement me!
73 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_SOFTWARE_RESET
:
74 SATA_TRACE ("SiI3132AtaPassThru() EFI_ATA_PASS_THRU_PROTOCOL_ATA_SOFTWARE_RESET");
75 Control
= PRB_CTRL_SRST
;
77 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
78 SataPort
->HostPRB
->Fis
.Control
= 0x0F;
81 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
82 ASSERT (0); //TODO: Implement me!
85 // There is no difference for SiI3132 between PIO and DMA invokation
86 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
87 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
88 // Fixup the size for block transfer. Following UEFI Specification, 'InTransferLength' should
89 // be in number of bytes. But for most data transfer commands, the value is in number of blocks
90 if (Packet
->Acb
->AtaCommand
== ATA_CMD_IDENTIFY_DRIVE
) {
91 InDataBufferLength
= Packet
->InTransferLength
;
93 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
94 if (!SataDevice
|| (SataDevice
->BlockSize
== 0)) {
95 return EFI_INVALID_PARAMETER
;
98 InDataBufferLength
= Packet
->InTransferLength
* SataDevice
->BlockSize
;
101 Status
= PciIo
->Map (
102 PciIo
, EfiPciIoOperationBusMasterWrite
,
103 Packet
->InDataBuffer
, &InDataBufferLength
, &PhysInDataBuffer
, &PciAllocMapping
105 if (EFI_ERROR (Status
)) {
109 // Construct SGEs (32-bit system)
110 SataPort
->HostPRB
->Sge
[0].DataAddressLow
= (UINT32
)PhysInDataBuffer
;
111 SataPort
->HostPRB
->Sge
[0].DataAddressHigh
= (UINT32
)(PhysInDataBuffer
>> 32);
112 SataPort
->HostPRB
->Sge
[0].Attributes
= SGE_TRM
; // Only one SGE
113 SataPort
->HostPRB
->Sge
[0].DataCount
= InDataBufferLength
;
115 // Copy the Ata Command Block
116 CopyMem (&SataPort
->HostPRB
->Fis
, Packet
->Acb
, sizeof (EFI_ATA_COMMAND_BLOCK
));
119 SataPort
->HostPRB
->Fis
.FisType
= 0x27; // Register - Host to Device FIS
120 SataPort
->HostPRB
->Fis
.Control
= 1 << 7; // Is a command
121 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
122 SataPort
->HostPRB
->Fis
.Control
|= PortMultiplierPort
& 0xFF;
125 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
126 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
127 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
128 if (!SataDevice
|| (SataDevice
->BlockSize
== 0)) {
129 return EFI_INVALID_PARAMETER
;
132 // Fixup the size for block transfer. Following UEFI Specification, 'InTransferLength' should
133 // be in number of bytes. But for most data transfer commands, the value is in number of blocks
134 OutDataBufferLength
= Packet
->OutTransferLength
* SataDevice
->BlockSize
;
136 Status
= PciIo
->Map (
137 PciIo
, EfiPciIoOperationBusMasterRead
,
138 Packet
->OutDataBuffer
, &OutDataBufferLength
, &PhysOutDataBuffer
, &PciAllocMapping
140 if (EFI_ERROR (Status
)) {
144 // Construct SGEs (32-bit system)
145 SataPort
->HostPRB
->Sge
[0].DataAddressLow
= (UINT32
)PhysOutDataBuffer
;
146 SataPort
->HostPRB
->Sge
[0].DataAddressHigh
= (UINT32
)(PhysOutDataBuffer
>> 32);
147 SataPort
->HostPRB
->Sge
[0].Attributes
= SGE_TRM
; // Only one SGE
148 SataPort
->HostPRB
->Sge
[0].DataCount
= OutDataBufferLength
;
150 // Copy the Ata Command Block
151 CopyMem (&SataPort
->HostPRB
->Fis
, Packet
->Acb
, sizeof (EFI_ATA_COMMAND_BLOCK
));
154 SataPort
->HostPRB
->Fis
.FisType
= 0x27; // Register - Host to Device FIS
155 SataPort
->HostPRB
->Fis
.Control
= 1 << 7; // Is a command
156 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
157 SataPort
->HostPRB
->Fis
.Control
|= PortMultiplierPort
& 0xFF;
160 case EFI_ATA_PASS_THRU_PROTOCOL_DMA
:
161 ASSERT (0); //TODO: Implement me!
163 case EFI_ATA_PASS_THRU_PROTOCOL_DMA_QUEUED
:
164 ASSERT (0); //TODO: Implement me!
166 case EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_DIAGNOSTIC
:
167 ASSERT (0); //TODO: Implement me!
169 case EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_RESET
:
170 ASSERT (0); //TODO: Implement me!
172 case EFI_ATA_PASS_THRU_PROTOCOL_FPDMA
:
173 ASSERT (0); //TODO: Implement me!
175 case EFI_ATA_PASS_THRU_PROTOCOL_RETURN_RESPONSE
:
176 ASSERT (0); //TODO: Implement me!
183 SataPort
->HostPRB
->Control
= Control
;
184 SataPort
->HostPRB
->ProtocolOverride
= Protocol
;
187 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, IrqMask
);
189 if (!FeaturePcdGet (PcdSataSiI3132FeatureDirectCommandIssuing
)) {
190 // Indirect Command Issuance
192 //TODO: Find which slot is free (maybe use the Cmd FIFO)
193 //SATA_PORT_READ32 (SataPort->RegBase + SII3132_PORT_CMDEXECFIFO_REG, &EmptySlot);
195 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDACTIV_REG
+ (EmptySlot
* 8),
196 (UINT32
)(SataPort
->PhysAddrHostPRB
& 0xFFFFFFFF));
197 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDACTIV_REG
+ (EmptySlot
* 8) + 4,
198 (UINT32
)((SataPort
->PhysAddrHostPRB
>> 32) & 0xFFFFFFFF));
200 // Direct Command Issuance
201 Status
= PciIo
->Mem
.Write (PciIo
, EfiPciIoWidthUint32
, 1, // Bar 1
202 SataPort
->RegBase
+ (EmptySlot
* 0x80),
203 sizeof (SATA_SI3132_PRB
) / 4,
205 ASSERT_EFI_ERROR (Status
);
207 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDEXECFIFO_REG
, EmptySlot
);
211 // Could need to be implemented if we run multiple command in parallel to know which slot has been completed
212 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_SLOTSTATUS_REG
, &Value32
);
213 Timeout
= Packet
->Timeout
;
214 while (!Timeout
&& !Value32
) {
216 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_SLOTSTATUS_REG
, &Value32
);
220 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
221 if (!Packet
->Timeout
) {
222 while (!(Value32
& IrqMask
)) {
224 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
227 Timeout
= Packet
->Timeout
;
228 while (Timeout
&& !(Value32
& IrqMask
)) {
230 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
235 // Fill Packet Ata Status Block
236 Status
= PciIo
->Mem
.Read (PciIo
, EfiPciIoWidthUint32
, 1, // Bar 1
237 SataPort
->RegBase
+ 0x08,
238 sizeof (EFI_ATA_STATUS_BLOCK
) / 4,
240 ASSERT_EFI_ERROR (Status
);
243 if ((Packet
->Timeout
!= 0) && (Timeout
== 0)) {
244 DEBUG ((EFI_D_ERROR
, "SiI3132AtaPassThru() Err:Timeout\n"));
247 } else if (Value32
& (SII3132_PORT_INT_CMDERR
<< 16)) {
248 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_CMDERROR_REG
, &Error
);
249 DEBUG ((EFI_D_ERROR
, "SiI3132AtaPassThru() CmdErr:0x%X (SiI3132 Err:0x%X)\n", Value32
, Error
));
251 return EFI_DEVICE_ERROR
;
252 } else if (Value32
& (SII3132_PORT_INT_CMDCOMPL
<< 16)) {
253 // Clear Command Complete
254 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, SII3132_PORT_INT_CMDCOMPL
<< 16);
256 if (PciAllocMapping
) {
257 Status
= PciIo
->Unmap (PciIo
, PciAllocMapping
);
258 ASSERT (!EFI_ERROR (Status
));
261 // If the command was ATA_CMD_IDENTIFY_DRIVE then we need to update the BlockSize
262 if (Packet
->Acb
->AtaCommand
== ATA_CMD_IDENTIFY_DRIVE
) {
263 ATA_IDENTIFY_DATA
*IdentifyData
= (ATA_IDENTIFY_DATA
*)Packet
->InDataBuffer
;
265 // Get the corresponding Block Device
266 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
268 // Check logical block size
269 if ((IdentifyData
->phy_logic_sector_support
& BIT12
) != 0) {
270 ASSERT (SataDevice
!= NULL
);
271 SataDevice
->BlockSize
= (UINT32
) (((IdentifyData
->logic_sector_size_hi
<< 16) |
272 IdentifyData
->logic_sector_size_lo
) * sizeof (UINT16
));
274 SataDevice
->BlockSize
= 0x200;
280 return EFI_DEVICE_ERROR
;
285 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
286 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
287 and the non-blocking I/O functionality is optional.
289 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
290 @param[in] Port The port number of the ATA device to send the command.
291 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
292 If there is no port multiplier, then specify 0.
293 @param[in,out] Packet A pointer to the ATA command to send to the ATA device specified by Port
294 and PortMultiplierPort.
295 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking
296 I/O is performed. If Event is NULL, then blocking I/O is performed. If
297 Event is not NULL and non blocking I/O is supported, then non-blocking
298 I/O is performed, and Event will be signaled when the ATA command completes.
300 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands,
301 InTransferLength bytes were transferred from InDataBuffer. For write and
302 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
303 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred
304 is returned in InTransferLength. For write and bi-directional commands,
305 OutTransferLength bytes were transferred by OutDataBuffer.
306 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands
307 already queued. The caller may retry again later.
308 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command.
309 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA
310 command was not sent, so no additional status information is available.
316 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
318 IN UINT16 PortMultiplierPort
,
319 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
320 IN EFI_EVENT Event OPTIONAL
323 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
324 SATA_SI3132_DEVICE
*SataDevice
;
325 SATA_SI3132_PORT
*SataPort
;
327 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
328 if (!SataSiI3132Instance
) {
329 return EFI_INVALID_PARAMETER
;
332 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
334 return EFI_INVALID_PARAMETER
;
336 SataPort
= SataDevice
->Port
;
338 DEBUG ((EFI_D_INFO
, "SiI3132AtaPassThru(%d,%d) : AtaCmd:0x%X Prot:%d\n", Port
, PortMultiplierPort
,
339 Packet
->Acb
->AtaCommand
, Packet
->Protocol
));
341 return SiI3132AtaPassThruCommand (SataSiI3132Instance
, SataPort
, PortMultiplierPort
, Packet
, Event
);
345 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller.
346 These can either be the list of ports where ATA devices are actually present or the
347 list of legal port numbers for the ATA controller. Regardless, the caller of this
348 function must probe the port number returned to see if an ATA device is actually
349 present at that location on the ATA controller.
351 The GetNextPort() function retrieves the port number on an ATA controller. If on input
352 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned
353 in Port and EFI_SUCCESS is returned.
355 If Port is a port number that was returned on a previous call to GetNextPort(), then the
356 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS
357 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to
358 GetNextPort(), then EFI_INVALID_PARAMETER is returned.
360 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
363 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
364 @param[in,out] Port On input, a pointer to the port number on the ATA controller.
365 On output, a pointer to the next port number on the ATA
366 controller. An input value of 0xFFFF retrieves the first port
367 number on the ATA controller.
369 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port.
370 @retval EFI_NOT_FOUND There are no more ports on this ATA controller.
371 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call
378 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
382 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
384 EFI_STATUS Status
= EFI_SUCCESS
;
386 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
387 if (!SataSiI3132Instance
) {
388 return EFI_INVALID_PARAMETER
;
393 if (PrevPort
== 0xFFFF) {
396 if (PrevPort
< SATA_SII3132_MAXPORT
) {
397 *Port
= PrevPort
+ 1;
399 Status
= EFI_NOT_FOUND
;
406 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
407 controller. These can either be the list of port multiplier ports where ATA devices are actually
408 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
409 function must probe the port number and port multiplier port number returned to see if an ATA
410 device is actually present.
412 The GetNextDevice() function retrieves the port multiplier port number of an ATA device
413 present on a port of an ATA controller.
415 If PortMultiplierPort points to a port multiplier port number value that was returned on a
416 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
417 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
420 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
421 ATA device on port of the ATA controller is returned in PortMultiplierPort and
422 EFI_SUCCESS is returned.
424 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
425 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
428 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
429 the ATA controller, then EFI_NOT_FOUND is returned.
431 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
432 @param[in] Port The port number present on the ATA controller.
433 @param[in,out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
434 ATA device present on the ATA controller.
435 If on input a PortMultiplierPort of 0xFFFF is specified,
436 then the port multiplier port number of the first ATA device
437 is returned. On output, a pointer to the port multiplier port
438 number of the next ATA device present on an ATA controller.
440 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port
441 of the ATA controller was returned in PortMultiplierPort.
442 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller.
443 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not
444 returned on a previous call to GetNextDevice().
449 SiI3132GetNextDevice (
450 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
452 IN OUT UINT16
*PortMultiplierPort
455 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
456 SATA_SI3132_PORT
*SataPort
;
457 SATA_SI3132_DEVICE
*SataDevice
;
459 EFI_STATUS Status
= EFI_SUCCESS
;
461 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
462 if (!SataSiI3132Instance
) {
463 return EFI_INVALID_PARAMETER
;
466 if (Port
>= SATA_SII3132_MAXPORT
) {
467 return EFI_INVALID_PARAMETER
;
470 SataPort
= &(SataSiI3132Instance
->Ports
[Port
]);
472 if (*PortMultiplierPort
== 0xFFFF) {
473 List
= SataPort
->Devices
.ForwardLink
;
474 if (List
!= &SataPort
->Devices
) {
475 // The list is not empty, return the first device
476 *PortMultiplierPort
= ((SATA_SI3132_DEVICE
*)List
)->Index
;
478 Status
= EFI_NOT_FOUND
;
481 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, *PortMultiplierPort
);
482 if (SataDevice
!= NULL
) {
483 // We have found the previous port multiplier, return the next one
484 List
= SataDevice
->Link
.ForwardLink
;
485 if (List
!= &SataPort
->Devices
) {
486 *PortMultiplierPort
= ((SATA_SI3132_DEVICE
*)List
)->Index
;
488 Status
= EFI_NOT_FOUND
;
491 Status
= EFI_NOT_FOUND
;
498 Used to allocate and build a device path node for an ATA device on an ATA controller.
500 The BuildDevicePath() function allocates and builds a single device node for the ATA
501 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and
502 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned.
503 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough
504 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
506 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
507 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort,
508 and EFI_SUCCESS is returned.
510 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
511 @param[in] Port Port specifies the port number of the ATA device for which a
512 device path node is to be allocated and built.
513 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a
514 device path node is to be allocated and built. If there is no
515 port multiplier, then specify 0.
516 @param[in,out] DevicePath A pointer to a single device path node that describes the ATA
517 device specified by Port and PortMultiplierPort. This function
518 is responsible for allocating the buffer DevicePath with the
519 boot service AllocatePool(). It is the caller's responsibility
520 to free DevicePath when the caller is finished with DevicePath.
521 @retval EFI_SUCCESS The device path node that describes the ATA device specified by
522 Port and PortMultiplierPort was allocated and returned in DevicePath.
523 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not
524 exist on the ATA controller.
525 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
526 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
531 SiI3132BuildDevicePath (
532 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
534 IN UINT16 PortMultiplierPort
,
535 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
538 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
539 SATA_SI3132_DEVICE
*SataDevice
;
540 EFI_DEVICE_PATH_PROTOCOL
*SiI3132DevicePath
;
542 SATA_TRACE ("SiI3132BuildDevicePath()");
544 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
545 if (!SataSiI3132Instance
) {
546 return EFI_INVALID_PARAMETER
;
549 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
550 if (SataDevice
== NULL
) {
551 return EFI_NOT_FOUND
;
554 SiI3132DevicePath
= CreateDeviceNode (MESSAGING_DEVICE_PATH
, MSG_SATA_DP
, sizeof (SATA_DEVICE_PATH
));
555 if (SiI3132DevicePath
== NULL
) {
556 return EFI_OUT_OF_RESOURCES
;
559 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->HBAPortNumber
= Port
;
560 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
561 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->PortMultiplierPortNumber
= PortMultiplierPort
;
563 //Temp:((SATA_DEVICE_PATH*)SiI3132DevicePath)->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
564 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->PortMultiplierPortNumber
= 0;
566 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->Lun
= Port
; //TODO: Search information how to define properly LUN (Logical Unit Number)
568 *DevicePath
= SiI3132DevicePath
;
573 Used to translate a device path node to a port number and port multiplier port number.
575 The GetDevice() function determines the port and port multiplier port number associated with
576 the ATA device described by DevicePath. If DevicePath is a device path node type that the
577 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
578 DevicePath into a port number and port multiplier port number.
580 If this translation is successful, then that port number and port multiplier port number are returned
581 in Port and PortMultiplierPort, and EFI_SUCCESS is returned.
583 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
585 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
586 EFI_UNSUPPORTED is returned.
588 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
589 a valid translation from DevicePath to a port number and port multiplier port number, then
590 EFI_NOT_FOUND is returned.
592 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
593 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the
595 @param[out] Port On return, points to the port number of an ATA device on the ATA controller.
596 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device
597 on the ATA controller.
599 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier
600 port number, and they were returned in Port and PortMultiplierPort.
601 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
602 @retval EFI_INVALID_PARAMETER Port is NULL.
603 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL.
604 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath.
605 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier
606 port number does not exist.
611 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
612 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
614 OUT UINT16
*PortMultiplierPort
617 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
619 SATA_TRACE ("SiI3132GetDevice()");
621 if (!DevicePath
|| !Port
|| !PortMultiplierPort
) {
622 return EFI_INVALID_PARAMETER
;
625 if ((DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) || (DevicePath
->SubType
!= MSG_SATA_DP
)) {
626 return EFI_UNSUPPORTED
;
629 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
630 if (!SataSiI3132Instance
) {
631 return EFI_INVALID_PARAMETER
;
634 if (((SATA_DEVICE_PATH
*)DevicePath
)->Lun
>= SATA_SII3132_MAXPORT
) {
635 return EFI_NOT_FOUND
;
638 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
639 ASSERT (0); //TODO: Implement me!
640 return EFI_UNSUPPORTED
;
642 *Port
= ((SATA_DEVICE_PATH
*)DevicePath
)->Lun
;
643 // Return the first Sata Device as there should be only one directly connected
644 *PortMultiplierPort
= ((SATA_SI3132_DEVICE
*)SataSiI3132Instance
->Ports
[*Port
].Devices
.ForwardLink
)->Index
;
651 IN SATA_SI3132_PORT
*SataPort
654 EFI_PCI_IO_PROTOCOL
*PciIo
;
658 SATA_TRACE ("SiI3132HwResetPort()");
660 PciIo
= SataPort
->Instance
->PciIo
;
663 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CONTROLCLEAR_REG
, SII3132_PORT_CONTROL_RESET
);
665 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_STATUS_REG
, &Value32
);
666 ASSERT (!(Value32
& SII3132_PORT_CONTROL_RESET
));
668 // Initialize error counters
669 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_ERRCOUNTDECODE
, 0);
670 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_ERRCOUNTCRC
, 0);
671 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_ERRCOUNTHANDSHAKE
, 0);
673 // Enable interrupts for command completion and command errors
674 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_ENABLEINT_REG
, SII3132_PORT_INT_CMDCOMPL
| SII3132_PORT_INT_CMDERR
);
677 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_ENABLEINT_REG
, SII3132_PORT_INT_CMDCOMPL
| SII3132_PORT_INT_CMDERR
| SII3132_PORT_INT_PORTRDY
| (1 << 3));
679 // Wait until Port Ready
680 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
682 while ((Timeout
> 0) && ((Value32
& SII3132_PORT_INT_PORTRDY
) == 0)) {
685 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
688 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, SII3132_PORT_INT_PORTRDY
);
691 SATA_TRACE ("SiI3132HwResetPort(): Timeout");
693 } else if ((Value32
& SII3132_PORT_INT_PORTRDY
) == 0) {
694 SATA_TRACE ("SiI3132HwResetPort(): Port Not Ready");
695 return EFI_DEVICE_ERROR
;
702 Resets a specific port on the ATA controller. This operation also resets all the ATA devices
703 connected to the port.
705 The ResetChannel() function resets an a specific port on an ATA controller. This operation
706 resets all the ATA devices connected to that port. If this ATA controller does not support
707 a reset port operation, then EFI_UNSUPPORTED is returned.
709 If a device error occurs while executing that port reset operation, then EFI_DEVICE_ERROR is
712 If a timeout occurs during the execution of the port reset operation, then EFI_TIMEOUT is returned.
714 If the port reset operation is completed, then EFI_SUCCESS is returned.
716 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
717 @param[in] Port The port number on the ATA controller.
719 @retval EFI_SUCCESS The ATA controller port was reset.
720 @retval EFI_UNSUPPORTED The ATA controller does not support a port reset operation.
721 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA port.
722 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA port.
728 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
732 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
733 SATA_SI3132_PORT
*SataPort
;
735 SATA_TRACE ("SiI3132ResetPort()");
737 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
738 if (!SataSiI3132Instance
) {
739 return EFI_INVALID_PARAMETER
;
742 if (Port
>= SATA_SII3132_MAXPORT
) {
743 return EFI_UNSUPPORTED
;
746 SataPort
= &(SataSiI3132Instance
->Ports
[Port
]);
747 return SiI3132HwResetPort (SataPort
);
751 Resets an ATA device that is connected to an ATA controller.
753 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort.
754 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
757 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
758 EFI_INVALID_PARAMETER is returned.
760 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
763 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is
766 If the device reset operation is completed, then EFI_SUCCESS is returned.
768 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
769 @param[in] Port Port represents the port number of the ATA device to be reset.
770 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset.
771 If there is no port multiplier, then specify 0.
772 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset.
773 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation.
774 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid.
775 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device
776 specified by Port and PortMultiplierPort.
777 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device
778 specified by Port and PortMultiplierPort.
784 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
786 IN UINT16 PortMultiplierPort
789 EFI_PCI_IO_PROTOCOL
*PciIo
;
790 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
791 SATA_SI3132_PORT
*SataPort
;
792 SATA_SI3132_DEVICE
*SataDevice
;
796 SATA_TRACE ("SiI3132ResetDevice()");
798 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
799 if (!SataSiI3132Instance
) {
800 return EFI_INVALID_PARAMETER
;
803 PciIo
= SataSiI3132Instance
->PciIo
;
805 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
807 return EFI_INVALID_PARAMETER
;
809 SataPort
= SataDevice
->Port
;
811 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CONTROLSET_REG
, SII3132_PORT_DEVICE_RESET
);
814 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_STATUS_REG
, &Value32
);
815 while ((Timeout
> 0) && ((Value32
& SII3132_PORT_DEVICE_RESET
) != 0)) {
817 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_STATUS_REG
, &Value32
);
822 SATA_TRACE ("SiI3132ResetDevice(): Timeout");