]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsDevConfigProtocol.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsPassThruDxe / UfsDevConfigProtocol.c
1 /** @file
2 The implementation of the EFI UFS Device Config Protocol.
3
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "UfsPassThru.h"
10
11 /**
12 Read or write specified device descriptor of a UFS device.
13
14 The function is used to read/write UFS device descriptors. The consumer of this API is
15 responsible for allocating the data buffer pointed by Descriptor.
16
17 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
18 @param[in] Read The boolean variable to show r/w direction.
19 @param[in] DescId The ID of device descriptor.
20 @param[in] Index The Index of device descriptor.
21 @param[in] Selector The Selector of device descriptor.
22 @param[in, out] Descriptor The buffer of device descriptor to be read or written.
23 @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,
24 of the data buffer specified by Descriptor. On output, the number
25 of bytes that were actually transferred.
26
27 @retval EFI_SUCCESS The device descriptor is read/written successfully.
28 @retval EFI_INVALID_PARAMETER This is NULL or Descriptor is NULL or DescSize is NULL.
29 DescId, Index and Selector are invalid combination to point to a
30 type of UFS device descriptor.
31 @retval EFI_DEVICE_ERROR The device descriptor is not read/written successfully.
32
33 **/
34 EFI_STATUS
35 EFIAPI
36 UfsRwUfsDescriptor (
37 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
38 IN BOOLEAN Read,
39 IN UINT8 DescId,
40 IN UINT8 Index,
41 IN UINT8 Selector,
42 IN OUT UINT8 *Descriptor,
43 IN OUT UINT32 *DescSize
44 )
45 {
46 EFI_STATUS Status;
47 UFS_PASS_THRU_PRIVATE_DATA *Private;
48
49 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
50
51 if ((This == NULL) || (Descriptor == NULL) || (DescSize == NULL)) {
52 return EFI_INVALID_PARAMETER;
53 }
54
55 Status = UfsRwDeviceDesc (
56 Private,
57 Read,
58 DescId,
59 Index,
60 Selector,
61 Descriptor,
62 DescSize
63 );
64 if (Status == EFI_TIMEOUT) {
65 Status = EFI_DEVICE_ERROR;
66 }
67
68 return Status;
69 }
70
71 /**
72 Read or write specified flag of a UFS device.
73
74 The function is used to read/write UFS flag descriptors. The consumer of this API is responsible
75 for allocating the buffer pointed by Flag. The buffer size is 1 byte as UFS flag descriptor is
76 just a single Boolean value that represents a TRUE or FALSE, '0' or '1', ON or OFF type of value.
77
78 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
79 @param[in] Read The boolean variable to show r/w direction.
80 @param[in] FlagId The ID of flag to be read or written.
81 @param[in, out] Flag The buffer to set or clear flag.
82
83 @retval EFI_SUCCESS The flag descriptor is set/clear successfully.
84 @retval EFI_INVALID_PARAMETER This is NULL or Flag is NULL.
85 FlagId is an invalid UFS flag ID.
86 @retval EFI_DEVICE_ERROR The flag is not set/clear successfully.
87
88 **/
89 EFI_STATUS
90 EFIAPI
91 UfsRwUfsFlag (
92 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
93 IN BOOLEAN Read,
94 IN UINT8 FlagId,
95 IN OUT UINT8 *Flag
96 )
97 {
98 EFI_STATUS Status;
99 UFS_PASS_THRU_PRIVATE_DATA *Private;
100
101 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
102
103 if ((This == NULL) || (Flag == NULL)) {
104 return EFI_INVALID_PARAMETER;
105 }
106
107 Status = UfsRwFlags (Private, Read, FlagId, Flag);
108 if (Status == EFI_TIMEOUT) {
109 Status = EFI_DEVICE_ERROR;
110 }
111
112 return Status;
113 }
114
115 /**
116 Read or write specified attribute of a UFS device.
117
118 The function is used to read/write UFS attributes. The consumer of this API is responsible for
119 allocating the data buffer pointed by Attribute.
120
121 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.
122 @param[in] Read The boolean variable to show r/w direction.
123 @param[in] AttrId The ID of Attribute.
124 @param[in] Index The Index of Attribute.
125 @param[in] Selector The Selector of Attribute.
126 @param[in, out] Attribute The buffer of Attribute to be read or written.
127 @param[in, out] AttrSize The size of Attribute buffer. On input, the size, in bytes, of the
128 data buffer specified by Attribute. On output, the number of bytes
129 that were actually transferred.
130
131 @retval EFI_SUCCESS The attribute is read/written successfully.
132 @retval EFI_INVALID_PARAMETER This is NULL or Attribute is NULL or AttrSize is NULL.
133 AttrId, Index and Selector are invalid combination to point to a
134 type of UFS attribute.
135 @retval EFI_DEVICE_ERROR The attribute is not read/written successfully.
136
137 **/
138 EFI_STATUS
139 EFIAPI
140 UfsRwUfsAttribute (
141 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
142 IN BOOLEAN Read,
143 IN UINT8 AttrId,
144 IN UINT8 Index,
145 IN UINT8 Selector,
146 IN OUT UINT8 *Attribute,
147 IN OUT UINT32 *AttrSize
148 )
149 {
150 EFI_STATUS Status;
151 UFS_PASS_THRU_PRIVATE_DATA *Private;
152 UINT32 Attribute32;
153
154 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
155 Attribute32 = 0;
156
157 if ((This == NULL) || (Attribute == NULL) || (AttrSize == NULL)) {
158 return EFI_INVALID_PARAMETER;
159 }
160
161 //
162 // According to UFS Version 2.1 Spec (JESD220C) Section 14.3, the size of a attribute will not
163 // exceed 32-bit.
164 //
165 if (*AttrSize > 4) {
166 return EFI_INVALID_PARAMETER;
167 }
168
169 if (!Read) {
170 CopyMem (&Attribute32, Attribute, *AttrSize);
171 }
172
173 Status = UfsRwAttributes (
174 Private,
175 Read,
176 AttrId,
177 Index,
178 Selector,
179 &Attribute32
180 );
181 if (!EFI_ERROR (Status)) {
182 if (Read) {
183 CopyMem (Attribute, &Attribute32, *AttrSize);
184 }
185 } else {
186 *AttrSize = 0;
187 if (Status == EFI_TIMEOUT) {
188 Status = EFI_DEVICE_ERROR;
189 }
190 }
191
192 return Status;
193 }