UEFI application and programming--ReadAudioTool

ReadAudioTool.c

/*
 * ReadAudioTool.c
 *
 * Created on: September 30, 2017
 * Author:
 */
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/SerialPortLib.h>
#include <Library/IoLib.h>

#define R_HDA_STATESTS 0x0E // Wake Status
#define R_PCH_HDA_HDBARL 0x10 // HDA CTL Memory BAR Lower
#define IC 0x60
#define IR 0x64
#define ICS 0x68
#define SSIDCMD 0x001F2000
#define ICBEn 0x01
#ifndef PCI_EXPRESS_BASE_ADDRESS
 #define PCI_EXPRESS_BASE_ADDRESS 0xE0000000
#endif

#define MmPciAddress( Segment, Bus, Device, Function, Register ) \
  ( (UINTN)PCI_EXPRESS_BASE_ADDRESS + \
    (UINTN)(Bus << 20) + \
    (UINTN)(Device << 15) + \
    (UINTN)(Function << 12) + \
    (UINTN)(Register) \
  )

INTN
EFIAPI
ShellAppMain (
  IN UINTN Argc,
  IN CHAR16 **Argv
  )
{
  
  UINTN AzaliaBase;
  EFI_PHYSICAL_ADDRESS BaseAddressBarMem;
  UINT32 CodecBase;
  UINT64 *Address;
  UINT8 ICB;
  UINT32 IRR;
  UINT32 NodeValue;
  UINT8 Nid;
  
  Address = NULL;
  
  AzaliaBase = MmPciAddress (
                  0,
                  0,
                  27,
                  0,
                  0
                  );
  Print(L"controller cfg base:%x\r\n", AzaliaBase);
  BaseAddressBarMem = MmioRead32 (AzaliaBase + R_PCH_HDA_HDBARL) & 0xFFFFFFF0;
  CodecBase = (UINT32) BaseAddressBarMem;
  Print(L"codec mmio base:%x\r\n", CodecBase);
  MmioWrite32 (CodecBase + IC, SSIDCMD);
  MmioWrite8 (CodecBase + ICS, ICBEn);
  Do{
    ICB = MmioRead8 (CodecBase + ICS);
  }while(ICB&0x01);
  IRR = MmioRead32(CodecBase + IR);
  Print(L"Codec SSID:%x\r\n", IRR);
  
  For(Nid = 0; Nid < 0x30; Nid++){
    NodeValue = 0x000F1C00;
    NodeValue |= (Nid<<20);
    MmioWrite32(CodecBase + IC , NodeValue);
    MmioWrite8 (CodecBase + ICS, ICBEn);
    Do{
      ICB = MmioRead8 (CodecBase + ICS);
    }while(ICB&0x01);
    IRR = MmioRead32(CodecBase + IR);
    If(IRR != 0)
      Print(L"Nid%02X=0x%08X\n",Nid,IRR);
  }
  Return EFI_SUCCESS;

}

ReadAudioTool.inf

[Defines]  
  INF_VERSION             = 0x00010005  
  BASE_NAME               = ReadAudioTool  
  FILE_GUID               = dc72d2c7-a48a-42fd-80b6-9d229d9943c8  
  MODULE_TYPE             = UEFI_APPLICATION  
  VERSION_STRING          = 1.0  
  ENTRY_POINT             = ShellCEntryLib  

[Sources]  
  ReadAudioTool.c
  
[Sources.X64]


[Packages]  
  MdePkg/MdePkg.dec  
  ShellPkg/ShellPkg.dec
  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
  IntelFrameworkPkg/IntelFrameworkPkg.dec

[LibraryClasses]  
  UefiLib
  IoLib
  ShellCEntryLib
[Protocols]  

[Ppis]  
  
[Guids]  
  
[BuildOptions]  
  
  
[Pcd]  
  
  
[PcdEx]  
  
  
[FixedPcd]  
  
 
[FeaturePcd]  
  
[PatchPcd]