]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsDevConfigProtocol.c
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[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 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
9
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.
12
13 **/
14
15 #include "UfsPassThru.h"
16
17 /**
18 Read or write specified device descriptor of a UFS device.
19
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.
22
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.
32
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.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 UfsRwUfsDescriptor (
43 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
44 IN BOOLEAN Read,
45 IN UINT8 DescId,
46 IN UINT8 Index,
47 IN UINT8 Selector,
48 IN OUT UINT8 *Descriptor,
49 IN OUT UINT32 *DescSize
50 )
51 {
52 EFI_STATUS Status;
53 UFS_PASS_THRU_PRIVATE_DATA *Private;
54
55 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
56
57 if ((This == NULL) || (Descriptor == NULL) || (DescSize == NULL)) {
58 return EFI_INVALID_PARAMETER;
59 }
60
61 Status = UfsRwDeviceDesc (
62 Private,
63 Read,
64 DescId,
65 Index,
66 Selector,
67 Descriptor,
68 DescSize
69 );
70 if (Status == EFI_TIMEOUT) {
71 Status = EFI_DEVICE_ERROR;
72 }
73 return Status;
74 }
75
76 /**
77 Read or write specified flag of a UFS device.
78
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.
82
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.
87
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.
92
93 **/
94 EFI_STATUS
95 EFIAPI
96 UfsRwUfsFlag (
97 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
98 IN BOOLEAN Read,
99 IN UINT8 FlagId,
100 IN OUT UINT8 *Flag
101 )
102 {
103 EFI_STATUS Status;
104 UFS_PASS_THRU_PRIVATE_DATA *Private;
105
106 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
107
108 if ((This == NULL) || (Flag == NULL)) {
109 return EFI_INVALID_PARAMETER;
110 }
111
112 Status = UfsRwFlags (Private, Read, FlagId, Flag);
113 if (Status == EFI_TIMEOUT) {
114 Status = EFI_DEVICE_ERROR;
115 }
116 return Status;
117 }
118
119 /**
120 Read or write specified attribute of a UFS device.
121
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.
124
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.
134
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.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 UfsRwUfsAttribute (
145 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,
146 IN BOOLEAN Read,
147 IN UINT8 AttrId,
148 IN UINT8 Index,
149 IN UINT8 Selector,
150 IN OUT UINT8 *Attribute,
151 IN OUT UINT32 *AttrSize
152 )
153 {
154 EFI_STATUS Status;
155 UFS_PASS_THRU_PRIVATE_DATA *Private;
156 UINT32 Attribute32;
157
158 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG (This);
159 Attribute32 = 0;
160
161 if ((This == NULL) || (Attribute == NULL) || (AttrSize == NULL)) {
162 return EFI_INVALID_PARAMETER;
163 }
164
165 //
166 // According to UFS Version 2.1 Spec (JESD220C) Section 14.3, the size of a attribute will not
167 // exceed 32-bit.
168 //
169 if (*AttrSize > 4) {
170 return EFI_INVALID_PARAMETER;
171 }
172
173 if (!Read) {
174 CopyMem (&Attribute32, Attribute, *AttrSize);
175 }
176
177 Status = UfsRwAttributes (
178 Private,
179 Read,
180 AttrId,
181 Index,
182 Selector,
183 &Attribute32
184 );
185 if (!EFI_ERROR (Status)) {
186 if (Read) {
187 CopyMem (Attribute, &Attribute32, *AttrSize);
188 }
189 } else {
190 *AttrSize = 0;
191 if (Status == EFI_TIMEOUT) {
192 Status = EFI_DEVICE_ERROR;
193 }
194 }
195 return Status;
196 }