yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 1 | /** @file
|
lgao4 | 484c778 | 2008-11-13 08:30:16 +0000 | [diff] [blame] | 2 | Implementation of SmBusLib class library for DXE phase.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 3 |
|
| 4 | Copyright (c) 2006, Intel Corporation<BR>
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 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.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 12 |
|
| 13 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 14 | **/
|
| 15 |
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 16 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 17 | #include "InternalSmbusLib.h"
|
| 18 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 19 |
|
| 20 | //
|
| 21 | // Globle varible to cache pointer to Smbus protocol.
|
| 22 | //
|
jji4 | fe46741 | 2008-10-30 05:58:52 +0000 | [diff] [blame] | 23 | EFI_SMBUS_HC_PROTOCOL *mSmbus = NULL;
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 24 |
|
| 25 | /**
|
| 26 | The constructor function caches the pointer to Smbus protocol.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 27 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 28 | The constructor function locates Smbus protocol from protocol database.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 29 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 30 |
|
| 31 | @param ImageHandle The firmware allocated handle for the EFI image.
|
| 32 | @param SystemTable A pointer to the EFI System Table.
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 33 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 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;
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 45 |
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 46 | Status = gBS->LocateProtocol (&gEfiSmbusHcProtocolGuid, NULL, (VOID**) &mSmbus);
|
| 47 | ASSERT_EFI_ERROR (Status);
|
| 48 | ASSERT (mSmbus != NULL);
|
| 49 |
|
| 50 | return Status;
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 54 | Executes an SMBus operation to an SMBus controller.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 55 |
|
| 56 | This function provides a standard way to execute Smbus script
|
| 57 | as defined in the SmBus Specification. The data can either be of
|
| 58 | the Length byte, word, or a block of data.
|
| 59 |
|
| 60 | @param SmbusOperation Signifies which particular SMBus hardware protocol instance that it will use to
|
| 61 | execute the SMBus transactions.
|
| 62 | @param SmBusAddress Address that encodes the SMBUS Slave Address,
|
| 63 | SMBUS Command, SMBUS Data Length, and PEC.
|
| 64 | @param Length Signifies the number of bytes that this operation will do. The maximum number of
|
| 65 | bytes can be revision specific and operation specific.
|
| 66 | @param Buffer Contains the value of data to execute to the SMBus slave device. Not all operations
|
| 67 | require this argument. The length of this buffer is identified by Length.
|
| 68 | @param Status Return status for the executed command.
|
| 69 | This is an optional parameter and may be NULL.
|
| 70 |
|
klu2 | 070a76b | 2008-12-10 03:28:54 +0000 | [diff] [blame^] | 71 | @return The actual number of bytes that are executed for this operation.
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 72 |
|
| 73 | **/
|
| 74 | UINTN
|
| 75 | InternalSmBusExec (
|
| 76 | IN EFI_SMBUS_OPERATION SmbusOperation,
|
| 77 | IN UINTN SmBusAddress,
|
| 78 | IN UINTN Length,
|
| 79 | IN OUT VOID *Buffer,
|
| 80 | OUT RETURN_STATUS *Status OPTIONAL
|
| 81 | )
|
| 82 | {
|
| 83 | RETURN_STATUS ReturnStatus;
|
| 84 | EFI_SMBUS_DEVICE_ADDRESS SmbusDeviceAddress;
|
| 85 |
|
| 86 | SmbusDeviceAddress.SmbusDeviceAddress = SMBUS_LIB_SLAVE_ADDRESS (SmBusAddress);
|
| 87 |
|
| 88 | ReturnStatus = mSmbus->Execute (
|
| 89 | mSmbus,
|
| 90 | SmbusDeviceAddress,
|
| 91 | SMBUS_LIB_COMMAND (SmBusAddress),
|
| 92 | SmbusOperation,
|
vanjeff | bad4638 | 2007-07-05 06:59:50 +0000 | [diff] [blame] | 93 | SMBUS_LIB_PEC (SmBusAddress),
|
yshang1 | dd51a99 | 2007-06-29 05:29:46 +0000 | [diff] [blame] | 94 | &Length,
|
| 95 | Buffer
|
| 96 | );
|
| 97 | if (Status != NULL) {
|
| 98 | *Status = ReturnStatus;
|
| 99 | }
|
| 100 |
|
| 101 | return Length;
|
| 102 | }
|