3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "SataSiI3132.h"
17 #include <IndustryStandard/Atapi.h>
18 #include <Library/DevicePathLib.h>
22 IN SATA_SI3132_INSTANCE
* SataInstance
,
24 IN UINT16 PortMultiplierPort
27 SATA_SI3132_PORT
*SataPort
;
28 SATA_SI3132_DEVICE
*SataDevice
;
30 if (Port
>= SATA_SII3132_MAXPORT
) {
34 SataPort
= &(SataInstance
->Ports
[Port
]);
35 List
= SataPort
->Devices
.ForwardLink
;
37 while (List
!= &SataPort
->Devices
) {
38 SataDevice
= (SATA_SI3132_DEVICE
*)List
;
39 if (SataDevice
->Index
== PortMultiplierPort
) {
42 List
= List
->ForwardLink
;
48 SiI3132AtaPassThruCommand (
49 IN SATA_SI3132_INSTANCE
*SataSiI3132Instance
,
50 IN SATA_SI3132_PORT
*SataPort
,
51 IN UINT16 PortMultiplierPort
,
52 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
53 IN EFI_EVENT Event OPTIONAL
56 SATA_SI3132_DEVICE
*SataDevice
;
57 EFI_PHYSICAL_ADDRESS PhysInDataBuffer
;
58 UINTN InDataBufferLength
= 0;
59 EFI_PHYSICAL_ADDRESS PhysOutDataBuffer
;
60 UINTN OutDataBufferLength
;
61 CONST UINTN EmptySlot
= 0;
62 UINTN Control
= PRB_CTRL_ATA
;
64 UINT32 Value32
, Error
, Timeout
= 0;
65 CONST UINT32 IrqMask
= (SII3132_PORT_INT_CMDCOMPL
| SII3132_PORT_INT_CMDERR
) << 16;
67 VOID
* PciAllocMapping
= NULL
;
68 EFI_PCI_IO_PROTOCOL
*PciIo
;
70 PciIo
= SataSiI3132Instance
->PciIo
;
71 ZeroMem (SataPort
->HostPRB
, sizeof (SATA_SI3132_PRB
));
73 // Construct Si3132 PRB
74 switch (Packet
->Protocol
) {
75 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_HARDWARE_RESET
:
76 ASSERT (0); //TODO: Implement me!
78 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_SOFTWARE_RESET
:
79 SATA_TRACE ("SiI3132AtaPassThru() EFI_ATA_PASS_THRU_PROTOCOL_ATA_SOFTWARE_RESET");
80 Control
= PRB_CTRL_SRST
;
82 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
83 SataPort
->HostPRB
->Fis
.Control
= 0x0F;
86 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
:
87 ASSERT (0); //TODO: Implement me!
90 // There is no difference for SiI3132 between PIO and DMA invokation
91 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN
:
92 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
:
93 // Fixup the size for block transfer. Following UEFI Specification, 'InTransferLength' should
94 // be in number of bytes. But for most data transfer commands, the value is in number of blocks
95 if (Packet
->Acb
->AtaCommand
== ATA_CMD_IDENTIFY_DRIVE
) {
96 InDataBufferLength
= Packet
->InTransferLength
;
98 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
99 if (!SataDevice
|| (SataDevice
->BlockSize
== 0)) {
100 return EFI_INVALID_PARAMETER
;
103 InDataBufferLength
= Packet
->InTransferLength
* SataDevice
->BlockSize
;
106 Status
= PciIo
->Map (
107 PciIo
, EfiPciIoOperationBusMasterRead
,
108 Packet
->InDataBuffer
, &InDataBufferLength
, &PhysInDataBuffer
, &PciAllocMapping
110 if (EFI_ERROR (Status
)) {
114 // Construct SGEs (32-bit system)
115 SataPort
->HostPRB
->Sge
[0].DataAddressLow
= (UINT32
)PhysInDataBuffer
;
116 SataPort
->HostPRB
->Sge
[0].DataAddressHigh
= (UINT32
)(PhysInDataBuffer
>> 32);
117 SataPort
->HostPRB
->Sge
[0].Attributes
= SGE_TRM
; // Only one SGE
118 SataPort
->HostPRB
->Sge
[0].DataCount
= InDataBufferLength
;
120 // Copy the Ata Command Block
121 CopyMem (&SataPort
->HostPRB
->Fis
, Packet
->Acb
, sizeof (EFI_ATA_COMMAND_BLOCK
));
124 SataPort
->HostPRB
->Fis
.FisType
= 0x27; // Register - Host to Device FIS
125 SataPort
->HostPRB
->Fis
.Control
= 1 << 7; // Is a command
126 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
127 SataPort
->HostPRB
->Fis
.Control
|= PortMultiplierPort
& 0xFF;
130 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT
:
131 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
:
132 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
133 if (!SataDevice
|| (SataDevice
->BlockSize
== 0)) {
134 return EFI_INVALID_PARAMETER
;
137 // Fixup the size for block transfer. Following UEFI Specification, 'InTransferLength' should
138 // be in number of bytes. But for most data transfer commands, the value is in number of blocks
139 OutDataBufferLength
= Packet
->OutTransferLength
* SataDevice
->BlockSize
;
141 Status
= PciIo
->Map (
142 PciIo
, EfiPciIoOperationBusMasterWrite
,
143 Packet
->OutDataBuffer
, &OutDataBufferLength
, &PhysOutDataBuffer
, &PciAllocMapping
145 if (EFI_ERROR (Status
)) {
149 // Construct SGEs (32-bit system)
150 SataPort
->HostPRB
->Sge
[0].DataAddressLow
= (UINT32
)PhysOutDataBuffer
;
151 SataPort
->HostPRB
->Sge
[0].DataAddressHigh
= (UINT32
)(PhysOutDataBuffer
>> 32);
152 SataPort
->HostPRB
->Sge
[0].Attributes
= SGE_TRM
; // Only one SGE
153 SataPort
->HostPRB
->Sge
[0].DataCount
= OutDataBufferLength
;
155 // Copy the Ata Command Block
156 CopyMem (&SataPort
->HostPRB
->Fis
, Packet
->Acb
, sizeof (EFI_ATA_COMMAND_BLOCK
));
159 SataPort
->HostPRB
->Fis
.FisType
= 0x27; // Register - Host to Device FIS
160 SataPort
->HostPRB
->Fis
.Control
= 1 << 7; // Is a command
161 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
162 SataPort
->HostPRB
->Fis
.Control
|= PortMultiplierPort
& 0xFF;
165 case EFI_ATA_PASS_THRU_PROTOCOL_DMA
:
166 ASSERT (0); //TODO: Implement me!
168 case EFI_ATA_PASS_THRU_PROTOCOL_DMA_QUEUED
:
169 ASSERT (0); //TODO: Implement me!
171 case EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_DIAGNOSTIC
:
172 ASSERT (0); //TODO: Implement me!
174 case EFI_ATA_PASS_THRU_PROTOCOL_DEVICE_RESET
:
175 ASSERT (0); //TODO: Implement me!
177 case EFI_ATA_PASS_THRU_PROTOCOL_FPDMA
:
178 ASSERT (0); //TODO: Implement me!
180 case EFI_ATA_PASS_THRU_PROTOCOL_RETURN_RESPONSE
:
181 ASSERT (0); //TODO: Implement me!
188 SataPort
->HostPRB
->Control
= Control
;
189 SataPort
->HostPRB
->ProtocolOverride
= Protocol
;
192 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, IrqMask
);
194 if (!FeaturePcdGet (PcdSataSiI3132FeatureDirectCommandIssuing
)) {
195 // Indirect Command Issuance
197 //TODO: Find which slot is free (maybe use the Cmd FIFO)
198 //SATA_PORT_READ32 (SataPort->RegBase + SII3132_PORT_CMDEXECFIFO_REG, &EmptySlot);
200 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDACTIV_REG
+ (EmptySlot
* 8),
201 (UINT32
)(SataPort
->PhysAddrHostPRB
& 0xFFFFFFFF));
202 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDACTIV_REG
+ (EmptySlot
* 8) + 4,
203 (UINT32
)((SataPort
->PhysAddrHostPRB
>> 32) & 0xFFFFFFFF));
205 // Direct Command Issuance
206 Status
= PciIo
->Mem
.Write (PciIo
, EfiPciIoWidthUint32
, 1, // Bar 1
207 SataPort
->RegBase
+ (EmptySlot
* 0x80),
208 sizeof (SATA_SI3132_PRB
) / 4,
210 ASSERT_EFI_ERROR (Status
);
212 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CMDEXECFIFO_REG
, EmptySlot
);
216 // Could need to be implemented if we run multiple command in parallel to know which slot has been completed
217 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_SLOTSTATUS_REG
, &Value32
);
218 Timeout
= Packet
->Timeout
;
219 while (!Timeout
&& !Value32
) {
221 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_SLOTSTATUS_REG
, &Value32
);
225 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
226 if (!Packet
->Timeout
) {
227 while (!(Value32
& IrqMask
)) {
229 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
232 Timeout
= Packet
->Timeout
;
233 while (Timeout
&& !(Value32
& IrqMask
)) {
235 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, &Value32
);
240 // Fill Packet Ata Status Block
241 Status
= PciIo
->Mem
.Read (PciIo
, EfiPciIoWidthUint32
, 1, // Bar 1
242 SataPort
->RegBase
+ 0x08,
243 sizeof (EFI_ATA_STATUS_BLOCK
) / 4,
245 ASSERT_EFI_ERROR (Status
);
248 if ((Packet
->Timeout
!= 0) && (Timeout
== 0)) {
249 DEBUG ((EFI_D_ERROR
, "SiI3132AtaPassThru() Err:Timeout\n"));
252 } else if (Value32
& (SII3132_PORT_INT_CMDERR
<< 16)) {
253 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_CMDERROR_REG
, &Error
);
254 DEBUG ((EFI_D_ERROR
, "SiI3132AtaPassThru() CmdErr:0x%X (SiI3132 Err:0x%X)\n", Value32
, Error
));
256 return EFI_DEVICE_ERROR
;
257 } else if (Value32
& (SII3132_PORT_INT_CMDCOMPL
<< 16)) {
258 // Clear Command Complete
259 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_INTSTATUS_REG
, SII3132_PORT_INT_CMDCOMPL
<< 16);
261 if (PciAllocMapping
) {
262 Status
= PciIo
->Unmap (PciIo
, PciAllocMapping
);
263 ASSERT (!EFI_ERROR (Status
));
266 // If the command was ATA_CMD_IDENTIFY_DRIVE then we need to update the BlockSize
267 if (Packet
->Acb
->AtaCommand
== ATA_CMD_IDENTIFY_DRIVE
) {
268 ATA_IDENTIFY_DATA
*IdentifyData
= (ATA_IDENTIFY_DATA
*)Packet
->InDataBuffer
;
270 // Get the corresponding Block Device
271 SataDevice
= GetSataDevice (SataSiI3132Instance
, SataPort
->Index
, PortMultiplierPort
);
273 // Check logical block size
274 if ((IdentifyData
->phy_logic_sector_support
& BIT12
) != 0) {
275 ASSERT (SataDevice
!= NULL
);
276 SataDevice
->BlockSize
= (UINT32
) (((IdentifyData
->logic_sector_size_hi
<< 16) |
277 IdentifyData
->logic_sector_size_lo
) * sizeof (UINT16
));
279 SataDevice
->BlockSize
= 0x200;
285 return EFI_DEVICE_ERROR
;
290 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
291 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
292 and the non-blocking I/O functionality is optional.
294 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
295 @param[in] Port The port number of the ATA device to send the command.
296 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
297 If there is no port multiplier, then specify 0.
298 @param[in,out] Packet A pointer to the ATA command to send to the ATA device specified by Port
299 and PortMultiplierPort.
300 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking
301 I/O is performed. If Event is NULL, then blocking I/O is performed. If
302 Event is not NULL and non blocking I/O is supported, then non-blocking
303 I/O is performed, and Event will be signaled when the ATA command completes.
305 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands,
306 InTransferLength bytes were transferred from InDataBuffer. For write and
307 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
308 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred
309 is returned in InTransferLength. For write and bi-directional commands,
310 OutTransferLength bytes were transferred by OutDataBuffer.
311 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands
312 already queued. The caller may retry again later.
313 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command.
314 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA
315 command was not sent, so no additional status information is available.
320 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
322 IN UINT16 PortMultiplierPort
,
323 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET
*Packet
,
324 IN EFI_EVENT Event OPTIONAL
327 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
328 SATA_SI3132_DEVICE
*SataDevice
;
329 SATA_SI3132_PORT
*SataPort
;
331 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
332 if (!SataSiI3132Instance
) {
333 return EFI_INVALID_PARAMETER
;
336 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
338 return EFI_INVALID_PARAMETER
;
340 SataPort
= SataDevice
->Port
;
342 DEBUG ((EFI_D_INFO
, "SiI3132AtaPassThru(%d,%d) : AtaCmd:0x%X Prot:%d\n", Port
, PortMultiplierPort
,
343 Packet
->Acb
->AtaCommand
, Packet
->Protocol
));
345 return SiI3132AtaPassThruCommand (SataSiI3132Instance
, SataPort
, PortMultiplierPort
, Packet
, Event
);
349 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller.
350 These can either be the list of ports where ATA devices are actually present or the
351 list of legal port numbers for the ATA controller. Regardless, the caller of this
352 function must probe the port number returned to see if an ATA device is actually
353 present at that location on the ATA controller.
355 The GetNextPort() function retrieves the port number on an ATA controller. If on input
356 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned
357 in Port and EFI_SUCCESS is returned.
359 If Port is a port number that was returned on a previous call to GetNextPort(), then the
360 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS
361 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to
362 GetNextPort(), then EFI_INVALID_PARAMETER is returned.
364 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
367 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
368 @param[in,out] Port On input, a pointer to the port number on the ATA controller.
369 On output, a pointer to the next port number on the ATA
370 controller. An input value of 0xFFFF retrieves the first port
371 number on the ATA controller.
373 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port.
374 @retval EFI_NOT_FOUND There are no more ports on this ATA controller.
375 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call
381 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
385 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
387 EFI_STATUS Status
= EFI_SUCCESS
;
389 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
390 if (!SataSiI3132Instance
) {
391 return EFI_INVALID_PARAMETER
;
396 if (PrevPort
== 0xFFFF) {
399 if (PrevPort
< SATA_SII3132_MAXPORT
) {
400 *Port
= PrevPort
+ 1;
402 Status
= EFI_NOT_FOUND
;
409 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
410 controller. These can either be the list of port multiplier ports where ATA devices are actually
411 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
412 function must probe the port number and port multiplier port number returned to see if an ATA
413 device is actually present.
415 The GetNextDevice() function retrieves the port multiplier port number of an ATA device
416 present on a port of an ATA controller.
418 If PortMultiplierPort points to a port multiplier port number value that was returned on a
419 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
420 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
423 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
424 ATA device on port of the ATA controller is returned in PortMultiplierPort and
425 EFI_SUCCESS is returned.
427 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
428 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
431 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
432 the ATA controller, then EFI_NOT_FOUND is returned.
434 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
435 @param[in] Port The port number present on the ATA controller.
436 @param[in,out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
437 ATA device present on the ATA controller.
438 If on input a PortMultiplierPort of 0xFFFF is specified,
439 then the port multiplier port number of the first ATA device
440 is returned. On output, a pointer to the port multiplier port
441 number of the next ATA device present on an ATA controller.
443 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port
444 of the ATA controller was returned in PortMultiplierPort.
445 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller.
446 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not
447 returned on a previous call to GetNextDevice().
451 SiI3132GetNextDevice (
452 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
454 IN OUT UINT16
*PortMultiplierPort
457 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
458 SATA_SI3132_PORT
*SataPort
;
459 SATA_SI3132_DEVICE
*SataDevice
;
461 EFI_STATUS Status
= EFI_SUCCESS
;
463 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
464 if (!SataSiI3132Instance
) {
465 return EFI_INVALID_PARAMETER
;
468 if (Port
>= SATA_SII3132_MAXPORT
) {
469 return EFI_INVALID_PARAMETER
;
472 SataPort
= &(SataSiI3132Instance
->Ports
[Port
]);
474 if (*PortMultiplierPort
== 0xFFFF) {
475 List
= SataPort
->Devices
.ForwardLink
;
476 if (List
!= &SataPort
->Devices
) {
477 // The list is not empty, return the first device
478 *PortMultiplierPort
= ((SATA_SI3132_DEVICE
*)List
)->Index
;
480 Status
= EFI_NOT_FOUND
;
483 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, *PortMultiplierPort
);
484 if (SataDevice
!= NULL
) {
485 // We have found the previous port multiplier, return the next one
486 List
= SataDevice
->Link
.ForwardLink
;
487 if (List
!= &SataPort
->Devices
) {
488 *PortMultiplierPort
= ((SATA_SI3132_DEVICE
*)List
)->Index
;
490 Status
= EFI_NOT_FOUND
;
493 Status
= EFI_NOT_FOUND
;
500 Used to allocate and build a device path node for an ATA device on an ATA controller.
502 The BuildDevicePath() function allocates and builds a single device node for the ATA
503 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and
504 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned.
505 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough
506 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
508 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
509 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort,
510 and EFI_SUCCESS is returned.
512 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
513 @param[in] Port Port specifies the port number of the ATA device for which a
514 device path node is to be allocated and built.
515 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a
516 device path node is to be allocated and built. If there is no
517 port multiplier, then specify 0.
518 @param[in,out] DevicePath A pointer to a single device path node that describes the ATA
519 device specified by Port and PortMultiplierPort. This function
520 is responsible for allocating the buffer DevicePath with the
521 boot service AllocatePool(). It is the caller's responsibility
522 to free DevicePath when the caller is finished with DevicePath.
523 @retval EFI_SUCCESS The device path node that describes the ATA device specified by
524 Port and PortMultiplierPort was allocated and returned in DevicePath.
525 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not
526 exist on the ATA controller.
527 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
528 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
532 SiI3132BuildDevicePath (
533 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
535 IN UINT16 PortMultiplierPort
,
536 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
539 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
540 SATA_SI3132_DEVICE
*SataDevice
;
541 EFI_DEVICE_PATH_PROTOCOL
*SiI3132DevicePath
;
543 SATA_TRACE ("SiI3132BuildDevicePath()");
545 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
546 if (!SataSiI3132Instance
) {
547 return EFI_INVALID_PARAMETER
;
550 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
551 if (SataDevice
== NULL
) {
552 return EFI_NOT_FOUND
;
555 SiI3132DevicePath
= CreateDeviceNode (MESSAGING_DEVICE_PATH
, MSG_SATA_DP
, sizeof (SATA_DEVICE_PATH
));
556 if (SiI3132DevicePath
== NULL
) {
557 return EFI_OUT_OF_RESOURCES
;
560 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->HBAPortNumber
= Port
;
561 if (FeaturePcdGet (PcdSataSiI3132FeaturePMPSupport
)) {
562 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->PortMultiplierPortNumber
= PortMultiplierPort
;
564 //Temp:((SATA_DEVICE_PATH*)SiI3132DevicePath)->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
565 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->PortMultiplierPortNumber
= 0;
567 ((SATA_DEVICE_PATH
*)SiI3132DevicePath
)->Lun
= Port
; //TODO: Search information how to define properly LUN (Logical Unit Number)
569 *DevicePath
= SiI3132DevicePath
;
574 Used to translate a device path node to a port number and port multiplier port number.
576 The GetDevice() function determines the port and port multiplier port number associated with
577 the ATA device described by DevicePath. If DevicePath is a device path node type that the
578 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
579 DevicePath into a port number and port multiplier port number.
581 If this translation is successful, then that port number and port multiplier port number are returned
582 in Port and PortMultiplierPort, and EFI_SUCCESS is returned.
584 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
586 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
587 EFI_UNSUPPORTED is returned.
589 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
590 a valid translation from DevicePath to a port number and port multiplier port number, then
591 EFI_NOT_FOUND is returned.
593 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
594 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the
596 @param[out] Port On return, points to the port number of an ATA device on the ATA controller.
597 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device
598 on the ATA controller.
600 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier
601 port number, and they were returned in Port and PortMultiplierPort.
602 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
603 @retval EFI_INVALID_PARAMETER Port is NULL.
604 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL.
605 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath.
606 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier
607 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 Sevice 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.
727 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
731 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
732 SATA_SI3132_PORT
*SataPort
;
734 SATA_TRACE ("SiI3132ResetPort()");
736 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
737 if (!SataSiI3132Instance
) {
738 return EFI_INVALID_PARAMETER
;
741 if (Port
>= SATA_SII3132_MAXPORT
) {
742 return EFI_UNSUPPORTED
;
745 SataPort
= &(SataSiI3132Instance
->Ports
[Port
]);
746 return SiI3132HwResetPort (SataPort
);
750 Resets an ATA device that is connected to an ATA controller.
752 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort.
753 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
756 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
757 EFI_INVALID_PARAMETER is returned.
759 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
762 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is
765 If the device reset operation is completed, then EFI_SUCCESS is returned.
767 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
768 @param[in] Port Port represents the port number of the ATA device to be reset.
769 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset.
770 If there is no port multiplier, then specify 0.
771 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset.
772 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation.
773 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid.
774 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device
775 specified by Port and PortMultiplierPort.
776 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device
777 specified by Port and PortMultiplierPort.
782 IN EFI_ATA_PASS_THRU_PROTOCOL
*This
,
784 IN UINT16 PortMultiplierPort
787 EFI_PCI_IO_PROTOCOL
*PciIo
;
788 SATA_SI3132_INSTANCE
*SataSiI3132Instance
;
789 SATA_SI3132_PORT
*SataPort
;
790 SATA_SI3132_DEVICE
*SataDevice
;
794 SATA_TRACE ("SiI3132ResetDevice()");
796 SataSiI3132Instance
= INSTANCE_FROM_ATAPASSTHRU_THIS (This
);
797 if (!SataSiI3132Instance
) {
798 return EFI_INVALID_PARAMETER
;
801 PciIo
= SataSiI3132Instance
->PciIo
;
803 SataDevice
= GetSataDevice (SataSiI3132Instance
, Port
, PortMultiplierPort
);
805 return EFI_INVALID_PARAMETER
;
807 SataPort
= SataDevice
->Port
;
809 SATA_PORT_WRITE32 (SataPort
->RegBase
+ SII3132_PORT_CONTROLSET_REG
, SII3132_PORT_DEVICE_RESET
);
812 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_STATUS_REG
, &Value32
);
813 while ((Timeout
> 0) && ((Value32
& SII3132_PORT_DEVICE_RESET
) != 0)) {
815 SATA_PORT_READ32 (SataPort
->RegBase
+ SII3132_PORT_STATUS_REG
, &Value32
);
820 SATA_TRACE ("SiI3132ResetDevice(): Timeout");