1 /** @file 2 Header file for the defintions used in SMBus DXE driver. 3 4 Copyright (c) 2013-2015 Intel Corporation. 5 6 SPDX-License-Identifier: BSD-2-Clause-Patent 7 8 **/ 9 10 11 #ifndef _DXE_QNC_SMBUS_H_ 12 #define _DXE_QNC_SMBUS_H_ 13 #include "CommonHeader.h" 14 15 #include "QNCSmbus.h" 16 17 #define MAX_SMBUS_DEVICES 107 // Max number of SMBus devices (7 bit 18 // address yields 128 combinations but 21 19 // of those are reserved) 20 21 #define MICROSECOND 10 22 #define MILLISECOND (1000 * MICROSECOND) 23 #define ONESECOND (1000 * MILLISECOND) 24 25 #define STALL_TIME 1000000 // 1,000,000 microseconds = 1 second 26 #define BUS_TRIES 3 // How many times to retry on Bus Errors 27 #define SMBUS_NUM_RESERVED 21 // Number of device addresses that are 28 // reserved by the SMBus spec. 29 #define SMBUS_ADDRESS_ARP 0xC2 >> 1 30 #define SMBUS_DATA_PREPARE_TO_ARP 0x01 31 #define SMBUS_DATA_RESET_DEVICE 0x02 32 #define SMBUS_DATA_GET_UDID_GENERAL 0x03 33 #define SMBUS_DATA_ASSIGN_ADDRESS 0x04 34 #define SMBUS_GET_UDID_LENGTH 17 // 16 byte UDID + 1 byte address 35 36 /** 37 Executes an SMBus operation to an SMBus controller. Returns when either the command has been 38 executed or an error is encountered in doing the operation. 39 40 The Execute() function provides a standard way to execute an operation as defined in the System 41 Management Bus (SMBus) Specification. The resulting transaction will be either that the SMBus 42 slave devices accept this transaction or that this function returns with error. 43 44 @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. 45 @param SlaveAddress The SMBus slave address of the device with which to communicate. 46 @param Command This command is transmitted by the SMBus host controller to the 47 SMBus slave device and the interpretation is SMBus slave device 48 specific. It can mean the offset to a list of functions inside an 49 SMBus slave device. Not all operations or slave devices support 50 this command's registers. 51 @param Operation Signifies which particular SMBus hardware protocol instance that 52 it will use to execute the SMBus transactions. This SMBus 53 hardware protocol is defined by the SMBus Specification and is 54 not related to EFI. 55 @param PecCheck Defines if Packet Error Code (PEC) checking is required for this 56 operation. 57 @param Length Signifies the number of bytes that this operation will do. The 58 maximum number of bytes can be revision specific and operation 59 specific. This field will contain the actual number of bytes that 60 are executed for this operation. Not all operations require this 61 argument. 62 @param Buffer Contains the value of data to execute to the SMBus slave device. 63 Not all operations require this argument. The length of this 64 buffer is identified by Length. 65 66 @retval EFI_SUCCESS The last data that was returned from the access matched the poll 67 exit criteria. 68 @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrect). 69 @retval EFI_TIMEOUT Timeout expired before the operation was completed. Timeout is 70 determined by the SMBus host controller device. 71 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. 72 @retval EFI_DEVICE_ERROR The request was not completed because a failure that was 73 reflected in the Host Status Register bit. Device errors are a 74 result of a transaction collision, illegal command field, 75 unclaimed cycle (host initiated), or bus errors (collisions). 76 @retval EFI_INVALID_PARAMETER Operation is not defined in EFI_SMBUS_OPERATION. 77 @retval EFI_INVALID_PARAMETER Length/Buffer is NULL for operations except for EfiSmbusQuickRead 78 and EfiSmbusQuickWrite. Length is outside the range of valid 79 values. 80 @retval EFI_UNSUPPORTED The SMBus operation or PEC is not supported. 81 @retval EFI_BUFFER_TOO_SMALL Buffer is not sufficient for this operation. 82 83 **/ 84 EFI_STATUS 85 EFIAPI 86 SmbusExecute ( 87 IN CONST EFI_SMBUS_HC_PROTOCOL *This, 88 IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, 89 IN CONST EFI_SMBUS_DEVICE_COMMAND Command, 90 IN CONST EFI_SMBUS_OPERATION Operation, 91 IN CONST BOOLEAN PecCheck, 92 IN OUT UINTN *Length, 93 IN OUT VOID *Buffer 94 ); 95 96 /** 97 Sets the SMBus slave device addresses for the device with a given unique ID or enumerates the 98 entire bus. 99 100 The ArpDevice() function provides a standard way for a device driver to enumerate the entire 101 SMBus or specific devices on the bus. 102 103 @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. 104 @param ArpAll A Boolean expression that indicates if the host drivers need to 105 enumerate all the devices or enumerate only the device that is 106 identified by SmbusUdid. If ArpAll is TRUE, SmbusUdid and 107 SlaveAddress are optional. If ArpAll is FALSE, ArpDevice will 108 enumerate SmbusUdid and the address will be at SlaveAddress. 109 @param SmbusUdid The Unique Device Identifier (UDID) that is associated with this 110 device. 111 @param SlaveAddress The SMBus slave address that is associated with an SMBus UDID. 112 113 @retval EFI_SUCCESS The last data that was returned from the access matched the poll 114 exit criteria. 115 @retval EFI_CRC_ERROR Checksum is not correct (PEC is incorrect). 116 @retval EFI_TIMEOUT Timeout expired before the operation was completed. Timeout is 117 determined by the SMBus host controller device. 118 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. 119 @retval EFI_DEVICE_ERROR The request was not completed because a failure that was 120 reflected in the Host Status Register bit. Device errors are a 121 result of a transaction collision, illegal command field, 122 unclaimed cycle (host initiated), or bus errors (collisions). 123 @retval EFI_UNSUPPORTED The corresponding operation is not supported. 124 125 **/ 126 EFI_STATUS 127 EFIAPI 128 SmbusArpDevice ( 129 IN CONST EFI_SMBUS_HC_PROTOCOL *This, 130 IN BOOLEAN ArpAll, 131 IN EFI_SMBUS_UDID *SmbusUdid, OPTIONAL 132 IN OUT EFI_SMBUS_DEVICE_ADDRESS *SlaveAddress OPTIONAL 133 ); 134 135 /** 136 Returns a pointer to the Address Resolution Protocol (ARP) map that contains the ID/address pair 137 of the slave devices that were enumerated by the SMBus host controller driver. 138 139 The GetArpMap() function returns the mapping of all the SMBus devices that were enumerated by the 140 SMBus host driver. 141 142 @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. 143 @param Length Size of the buffer that contains the SMBus device map. 144 @param SmbusDeviceMap The pointer to the device map as enumerated by the SMBus 145 controller driver. 146 147 @retval EFI_SUCCESS The SMBus returned the current device map. 148 @retval EFI_UNSUPPORTED The corresponding operation is not supported. 149 150 **/ 151 EFI_STATUS 152 EFIAPI 153 SmbusGetArpMap ( 154 IN CONST EFI_SMBUS_HC_PROTOCOL *This, 155 IN OUT UINTN *Length, 156 IN OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap 157 ); 158 159 /** 160 Allows a device driver to register for a callback when the bus driver detects a state that it 161 needs to propagate to other drivers that are registered for a callback. 162 163 The Notify() function registers all the callback functions to allow the bus driver to call these 164 functions when the SlaveAddress/Data pair happens. 165 If NotifyFunction is NULL, then ASSERT (). 166 167 @param This A pointer to the EFI_SMBUS_HC_PROTOCOL instance. 168 @param SlaveAddress The SMBUS hardware address to which the SMBUS device is 169 preassigned or allocated. 170 @param Data Data of the SMBus host notify command that the caller wants to be 171 called. 172 @param NotifyFunction The function to call when the bus driver detects the SlaveAddress 173 and Data pair. 174 175 @retval EFI_SUCCESS NotifyFunction was registered. 176 @retval EFI_UNSUPPORTED The corresponding operation is not supported. 177 178 **/ 179 EFI_STATUS 180 EFIAPI 181 SmbusNotify ( 182 IN CONST EFI_SMBUS_HC_PROTOCOL *This, 183 IN CONST EFI_SMBUS_DEVICE_ADDRESS SlaveAddress, 184 IN CONST UINTN Data, 185 IN CONST EFI_SMBUS_NOTIFY_FUNCTION NotifyFunction 186 ); 187 188 /** 189 Entry point to the DXE Driver that produces the SMBus Host Controller Protocol. 190 191 @param ImageHandle ImageHandle of the loaded driver. 192 @param SystemTable Pointer to the EFI System Table. 193 194 @retval EFI_SUCCESS The entry point of SMBus DXE driver is executed successfully. 195 @retval !EFI_SUCESS Some error occurs in the entry point of SMBus DXE driver. 196 197 **/ 198 EFI_STATUS 199 EFIAPI 200 InitializeQNCSmbus ( 201 IN EFI_HANDLE ImageHandle, 202 IN EFI_SYSTEM_TABLE *SystemTable 203 ); 204 205 #endif 206