2 The implementation of the EFI UFS Device Config Protocol.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
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 "UfsPassThru.h"
18 Read or write specified device descriptor of a UFS device.
20 The function is used to read/write UFS device descriptors. The consumer of this API is
21 responsible for allocating the data buffer pointed by Descriptor.
23 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
24 @param[in] Read The boolean variable to show r/w direction.
25 @param[in] DescId The ID of device descriptor.
26 @param[in] Index The Index of device descriptor.
27 @param[in] Selector The Selector of device descriptor.
28 @param[in, out] Descriptor The buffer of device descriptor to be read or written.
29 @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,
30 of the data buffer specified by Descriptor. On output, the number
31 of bytes that were actually transferred.
33 @retval EFI_SUCCESS The device descriptor is read/written successfully.
34 @retval EFI_INVALID_PARAMETER This is NULL or Descriptor is NULL or DescSize is NULL.
35 DescId, Index and Selector are invalid combination to point to a
36 type of UFS device descriptor.
37 @retval EFI_DEVICE_ERROR The device descriptor is not read/written successfully.
43 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL
*This
,
48 IN OUT UINT8
*Descriptor
,
49 IN OUT UINT32
*DescSize
53 UFS_PASS_THRU_PRIVATE_DATA
*Private
;
55 Private
= UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This
);
57 if ((This
== NULL
) || (Descriptor
== NULL
) || (DescSize
== NULL
)) {
58 return EFI_INVALID_PARAMETER
;
61 Status
= UfsRwDeviceDesc (
70 if (Status
== EFI_TIMEOUT
) {
71 Status
= EFI_DEVICE_ERROR
;
77 Read or write specified flag of a UFS device.
79 The function is used to read/write UFS flag descriptors. The consumer of this API is responsible
80 for allocating the buffer pointed by Flag. The buffer size is 1 byte as UFS flag descriptor is
81 just a single Boolean value that represents a TRUE or FALSE, '0' or '1', ON or OFF type of value.
83 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
84 @param[in] Read The boolean variable to show r/w direction.
85 @param[in] FlagId The ID of flag to be read or written.
86 @param[in, out] Flag The buffer to set or clear flag.
88 @retval EFI_SUCCESS The flag descriptor is set/clear successfully.
89 @retval EFI_INVALID_PARAMETER This is NULL or Flag is NULL.
90 FlagId is an invalid UFS flag ID.
91 @retval EFI_DEVICE_ERROR The flag is not set/clear successfully.
97 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL
*This
,
104 UFS_PASS_THRU_PRIVATE_DATA
*Private
;
106 Private
= UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This
);
108 if ((This
== NULL
) || (Flag
== NULL
)) {
109 return EFI_INVALID_PARAMETER
;
112 Status
= UfsRwFlags (Private
, Read
, FlagId
, Flag
);
113 if (Status
== EFI_TIMEOUT
) {
114 Status
= EFI_DEVICE_ERROR
;
120 Read or write specified attribute of a UFS device.
122 The function is used to read/write UFS attributes. The consumer of this API is responsible for
123 allocating the data buffer pointed by Attribute.
125 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
126 @param[in] Read The boolean variable to show r/w direction.
127 @param[in] AttrId The ID of Attribute.
128 @param[in] Index The Index of Attribute.
129 @param[in] Selector The Selector of Attribute.
130 @param[in, out] Attribute The buffer of Attribute to be read or written.
131 @param[in, out] AttrSize The size of Attribute buffer. On input, the size, in bytes, of the
132 data buffer specified by Attribute. On output, the number of bytes
133 that were actually transferred.
135 @retval EFI_SUCCESS The attribute is read/written successfully.
136 @retval EFI_INVALID_PARAMETER This is NULL or Attribute is NULL or AttrSize is NULL.
137 AttrId, Index and Selector are invalid combination to point to a
138 type of UFS attribute.
139 @retval EFI_DEVICE_ERROR The attribute is not read/written successfully.
145 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL
*This
,
150 IN OUT UINT8
*Attribute
,
151 IN OUT UINT32
*AttrSize
155 UFS_PASS_THRU_PRIVATE_DATA
*Private
;
158 Private
= UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This
);
161 if ((This
== NULL
) || (Attribute
== NULL
) || (AttrSize
== NULL
)) {
162 return EFI_INVALID_PARAMETER
;
166 // According to UFS Version 2.1 Spec (JESD220C) Section 14.3, the size of a attribute will not
170 return EFI_INVALID_PARAMETER
;
174 CopyMem (&Attribute32
, Attribute
, *AttrSize
);
177 Status
= UfsRwAttributes (
185 if (!EFI_ERROR (Status
)) {
187 CopyMem (Attribute
, &Attribute32
, *AttrSize
);
191 if (Status
== EFI_TIMEOUT
) {
192 Status
= EFI_DEVICE_ERROR
;