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