]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeSmbusLib/DxeSmbusLib.c
4c888370ebcc18bcccf9daa6cad477dd5a4ebc7b
[mirror_edk2.git] / MdePkg / Library / DxeSmbusLib / DxeSmbusLib.c
1 /** @file
2 Implementation of SmBusLib class library for PEI phase.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. 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 Module Name: DxeSmbusLib.c
15
16 **/
17
18 #include "InternalSmbusLib.h"
19
20 //
21 // Globle varible to cache pointer to Smbus protocol.
22 //
23 STATIC EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
24
25 /**
26 The constructor function caches the pointer to Smbus protocol.
27
28 The constructor function locates Smbus protocol from protocol database.
29 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
30
31 @param ImageHandle The firmware allocated handle for the EFI image.
32 @param SystemTable A pointer to the EFI System Table.
33
34 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 SmbusLibConstructor (
40 IN EFI_HANDLE ImageHandle,
41 IN EFI_SYSTEM_TABLE *SystemTable
42 )
43 {
44 EFI_STATUS Status;
45
46 Status = gBS->LocateProtocol (
47 &gEfiCpuIoProtocolGuid,
48 NULL,
49 (VOID**) &mSmbus
50 );
51 ASSERT_EFI_ERROR (Status);
52 ASSERT (mSmbus != NULL);
53
54 return Status;
55 }
56
57 /**
58 Executes an SMBus operation to an SMBus controller.
59
60 This function provides a standard way to execute Smbus script
61 as defined in the SmBus Specification. The data can either be of
62 the Length byte, word, or a block of data.
63
64 @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
65 execute the SMBus transactions.
66 @param SmBusAddress Address that encodes the SMBUS Slave Address,
67 SMBUS Command, SMBUS Data Length, and PEC.
68 @param Length Signifies the number of bytes that this operation will do. The maximum number of
69 bytes can be revision specific and operation specific.
70 @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
71 require this argument. The length of this buffer is identified by Length.
72 @param Status Return status for the executed command.
73 This is an optional parameter and may be NULL.
74
75 @return The actual number of bytes that are executed for this operation..
76
77 **/
78 UINTN
79 InternalSmBusExec (
80 IN EFI_SMBUS_OPERATION SmbusOperation,
81 IN UINTN SmBusAddress,
82 IN UINTN Length,
83 IN VOID *Buffer,
84 OUT RETURN_STATUS *Status OPTIONAL
85 )
86 {
87 RETURN_STATUS ReturnStatus;
88 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
89
90 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
91
92 ReturnStatus = mSmbus->Execute (
93 mSmbus,
94 SmbusDeviceAddress,
95 SMBUS_LIB_COMMAND (SmBusAddress),
96 SmbusOperation,
97 SMBUS_LIB_PEC (SmBusAddress),
98 &Length,
99 Buffer
100 );
101 if (Status != NULL) {
102 *Status = ReturnStatus;
103 }
104
105 return Length;
106 }
107
108 /**
109 Assigns an SMBUS slave addresses.
110
111 Assigns the SMBUS device specified by Uuid the slave address specified by SmBusAddress.
112 The status of the executed command is returned.
113
114 @param SmBusAddress Address that encodes the SMBUS Slave Address,
115 SMBUS Command, SMBUS Data Length, and PEC.
116 @param Uuid Pointer to the UUID of the device to assign a slave address.
117 It will assign to all SMBUS slave devices if it is NULL.
118
119 @retval RETURN_SUCCESS The SMBUS command was executed.
120 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
121 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
122 in the Host Status Register bit.
123 Device errors are a result of a transaction collision, illegal command field,
124 unclaimed cycle (host initiated), or bus errors (collisions).
125
126 **/
127 RETURN_STATUS
128 InternalSmBusArpDevice (
129 IN UINTN SmBusAddress,
130 IN CONST GUID *Uuid OPTIONAL
131 )
132 {
133 EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
134
135 SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
136 return (RETURN_STATUS) mSmbus->ArpDevice (
137 mSmbus,
138 (BOOLEAN) (Uuid == NULL),
139 (EFI_SMBUS_UDID *) Uuid,
140 &SmbusDeviceAddress
141 );
142 }
143
144 /**
145 Retrieves the mapping of all the SMBus devices.
146
147 The GetArpMap() function returns the mapping of all the SMBus devices
148 that are enumerated by the SMBus host driver.
149
150 @param Length Size of the buffer that contains the SMBus device map.
151 @param SmbusDeviceMap The pointer to the device map as enumerated by the SMBus controller driver.
152
153 @retval RETURN_SUCCESS The SMBUS command was executed.
154 @retval RETURN_TIMEOUT A timeout occurred while executing the SMBUS command.
155 @retval RETURN_DEVICE_ERROR The request was not completed because a failure reflected
156 in the Host Status Register bit.
157 Device errors are a result of a transaction collision, illegal command field,
158 unclaimed cycle (host initiated), or bus errors (collisions).
159
160 **/
161 RETURN_STATUS
162 InternalGetArpMap (
163 OUT UINTN *Length,
164 OUT EFI_SMBUS_DEVICE_MAP **SmbusDeviceMap
165 )
166 {
167 return (RETURN_STATUS) mSmbus->GetArpMap (mSmbus, Length, SmbusDeviceMap);
168 }