Discover user area partition in the SD device. @param[in] Device The pointer to the SD_DEVICE data structure. @retval EFI_SUCCESS The user area partition in the SD device is successfully identified. @return Others Some error occurs when identifying the user area. **/
| 177 | |
| 178 | **/ |
| 179 | EFI_STATUS |
| 180 | DiscoverUserArea ( |
| 181 | IN SD_DEVICE *Device |
| 182 | ) |
| 183 | { |
| 184 | EFI_STATUS Status; |
| 185 | SD_CSD *Csd; |
| 186 | SD_CSD2 *Csd2; |
| 187 | SD_CID *Cid; |
| 188 | UINT64 Capacity; |
| 189 | UINT32 DevStatus; |
| 190 | UINT16 Rca; |
| 191 | UINT32 CSize; |
| 192 | UINT32 CSizeMul; |
| 193 | UINT32 ReadBlLen; |
| 194 | |
| 195 | // |
| 196 | // Deselect the device to force it enter stby mode. |
| 197 | // Note here we don't judge return status as some SD devices return |
| 198 | // error but the state has been stby. |
| 199 | // |
| 200 | SdSelect (Device, 0); |
| 201 | |
| 202 | Status = SdSetRca (Device, &Rca); |
| 203 | if (EFI_ERROR(Status)) { |
| 204 | DEBUG ((EFI_D_ERROR, "DiscoverUserArea(): Assign new Rca = 0x%x fails with %r\n", Rca, Status)); |
| 205 | return Status; |
| 206 | } |
| 207 | |
| 208 | Csd = &Device->Csd; |
| 209 | Status = SdGetCsd (Device, Rca, Csd); |
| 210 | if (EFI_ERROR(Status)) { |
| 211 | return Status; |
| 212 | } |
| 213 | DumpCsd (Csd); |
| 214 | |
| 215 | Cid = &Device->Cid; |
| 216 | Status = SdGetCid (Device, Rca, Cid); |
| 217 | if (EFI_ERROR(Status)) { |
| 218 | return Status; |
| 219 | } |
| 220 | GetSdModelName (Device, Cid); |
| 221 | |
| 222 | Status = SdSelect (Device, Rca); |
| 223 | if (EFI_ERROR(Status)) { |
| 224 | DEBUG ((EFI_D_ERROR, "DiscoverUserArea(): Reselect the device 0x%x fails with %r\n", Rca, Status)); |
| 225 | return Status; |
| 226 | } |
| 227 | |
| 228 | Status = SdSendStatus (Device, Rca, &DevStatus); |
| 229 | if (EFI_ERROR(Status)) { |
| 230 | return Status; |
| 231 | } |
| 232 | |
| 233 | if (Csd->CsdStructure == 0) { |
| 234 | Device->SectorAddressing = FALSE; |
| 235 | CSize = (Csd->CSizeHigh << 2 | Csd->CSizeLow) + 1; |
| 236 | CSizeMul = (1 << (Csd->CSizeMul + 2)); |
no test coverage detected