1 /** @file
2   This file is used to implement the EFI_DISK_INFO_PROTOCOL interface.
3 
4 Copyright (c) 2011, 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 "UsbMass.h"
16 
17 EFI_DISK_INFO_PROTOCOL gUsbDiskInfoProtocolTemplate = {
18   EFI_DISK_INFO_USB_INTERFACE_GUID,
19   UsbDiskInfoInquiry,
20   UsbDiskInfoIdentify,
21   UsbDiskInfoSenseData,
22   UsbDiskInfoWhichIde
23 };
24 
25 /**
26   Initialize the installation of DiskInfo protocol.
27 
28   This function prepares for the installation of DiskInfo protocol on the child handle.
29   By default, it installs DiskInfo protocol with USB interface GUID.
30 
31   @param[in]  UsbMass  The pointer of USB_MASS_DEVICE.
32 
33 **/
34 VOID
InitializeDiskInfo(IN USB_MASS_DEVICE * UsbMass)35 InitializeDiskInfo (
36   IN  USB_MASS_DEVICE   *UsbMass
37   )
38 {
39   CopyMem (&UsbMass->DiskInfo, &gUsbDiskInfoProtocolTemplate, sizeof (gUsbDiskInfoProtocolTemplate));
40 }
41 
42 
43 /**
44   Provides inquiry information for the controller type.
45 
46   This function is used to get inquiry data.  Data format
47   of Identify data is defined by the Interface GUID.
48 
49   @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL instance.
50   @param[in, out] InquiryData       Pointer to a buffer for the inquiry data.
51   @param[in, out] InquiryDataSize   Pointer to the value for the inquiry data size.
52 
53   @retval EFI_SUCCESS            The command was accepted without any errors.
54   @retval EFI_NOT_FOUND          Device does not support this data class
55   @retval EFI_DEVICE_ERROR       Error reading InquiryData from device
56   @retval EFI_BUFFER_TOO_SMALL   InquiryDataSize not big enough
57 
58 **/
59 EFI_STATUS
60 EFIAPI
UsbDiskInfoInquiry(IN EFI_DISK_INFO_PROTOCOL * This,IN OUT VOID * InquiryData,IN OUT UINT32 * InquiryDataSize)61 UsbDiskInfoInquiry (
62   IN     EFI_DISK_INFO_PROTOCOL   *This,
63   IN OUT VOID                     *InquiryData,
64   IN OUT UINT32                   *InquiryDataSize
65   )
66 {
67   EFI_STATUS        Status;
68   USB_MASS_DEVICE   *UsbMass;
69 
70   UsbMass  = USB_MASS_DEVICE_FROM_DISK_INFO (This);
71 
72   Status = EFI_BUFFER_TOO_SMALL;
73   if (*InquiryDataSize >= sizeof (UsbMass->InquiryData)) {
74     Status = EFI_SUCCESS;
75     CopyMem (InquiryData, &UsbMass->InquiryData, sizeof (UsbMass->InquiryData));
76   }
77   *InquiryDataSize = sizeof (UsbMass->InquiryData);
78   return Status;
79 }
80 
81 
82 /**
83   Provides identify information for the controller type.
84 
85   This function is used to get identify data.  Data format
86   of Identify data is defined by the Interface GUID.
87 
88   @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL
89                                     instance.
90   @param[in, out] IdentifyData      Pointer to a buffer for the identify data.
91   @param[in, out] IdentifyDataSize  Pointer to the value for the identify data
92                                     size.
93 
94   @retval EFI_SUCCESS            The command was accepted without any errors.
95   @retval EFI_NOT_FOUND          Device does not support this data class
96   @retval EFI_DEVICE_ERROR       Error reading IdentifyData from device
97   @retval EFI_BUFFER_TOO_SMALL   IdentifyDataSize not big enough
98 
99 **/
100 EFI_STATUS
101 EFIAPI
UsbDiskInfoIdentify(IN EFI_DISK_INFO_PROTOCOL * This,IN OUT VOID * IdentifyData,IN OUT UINT32 * IdentifyDataSize)102 UsbDiskInfoIdentify (
103   IN     EFI_DISK_INFO_PROTOCOL   *This,
104   IN OUT VOID                     *IdentifyData,
105   IN OUT UINT32                   *IdentifyDataSize
106   )
107 {
108   return EFI_NOT_FOUND;
109 }
110 
111 /**
112   Provides sense data information for the controller type.
113 
114   This function is used to get sense data.
115   Data format of Sense data is defined by the Interface GUID.
116 
117   @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL instance.
118   @param[in, out] SenseData         Pointer to the SenseData.
119   @param[in, out] SenseDataSize     Size of SenseData in bytes.
120   @param[out]     SenseDataNumber   Pointer to the value for the sense data size.
121 
122   @retval EFI_SUCCESS            The command was accepted without any errors.
123   @retval EFI_NOT_FOUND          Device does not support this data class.
124   @retval EFI_DEVICE_ERROR       Error reading SenseData from device.
125   @retval EFI_BUFFER_TOO_SMALL   SenseDataSize not big enough.
126 
127 **/
128 EFI_STATUS
129 EFIAPI
UsbDiskInfoSenseData(IN EFI_DISK_INFO_PROTOCOL * This,IN OUT VOID * SenseData,IN OUT UINT32 * SenseDataSize,OUT UINT8 * SenseDataNumber)130 UsbDiskInfoSenseData (
131   IN     EFI_DISK_INFO_PROTOCOL   *This,
132   IN OUT VOID                     *SenseData,
133   IN OUT UINT32                   *SenseDataSize,
134   OUT    UINT8                    *SenseDataNumber
135   )
136 {
137   return EFI_NOT_FOUND;
138 }
139 
140 
141 /**
142   This function is used to get controller information.
143 
144   @param[in]  This         Pointer to the EFI_DISK_INFO_PROTOCOL instance.
145   @param[out] IdeChannel   Pointer to the Ide Channel number.  Primary or secondary.
146   @param[out] IdeDevice    Pointer to the Ide Device number.  Master or slave.
147 
148   @retval EFI_SUCCESS       IdeChannel and IdeDevice are valid.
149   @retval EFI_UNSUPPORTED   This is not an IDE device.
150 
151 **/
152 EFI_STATUS
153 EFIAPI
UsbDiskInfoWhichIde(IN EFI_DISK_INFO_PROTOCOL * This,OUT UINT32 * IdeChannel,OUT UINT32 * IdeDevice)154 UsbDiskInfoWhichIde (
155   IN  EFI_DISK_INFO_PROTOCOL   *This,
156   OUT UINT32                   *IdeChannel,
157   OUT UINT32                   *IdeDevice
158   )
159 {
160   return EFI_UNSUPPORTED;
161 }
162 
163