<commit_before>/** @file
  ACPI Timer implements one instance of Timer Library.

  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
  Copyright (c) 2011, <NAME> <<EMAIL>>

  This program and the accompanying materials are
  licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <Base.h>
#include <Library/TimerLib.h>
#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/PciLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>

//
// PIIX4 Power Management Base Address
//
STATIC UINT32 mPmba;

#define PCI_BAR_IO             0x1
#define ACPI_TIMER_FREQUENCY   3579545
#define ACPI_TIMER_COUNT_SIZE  0x01000000
#define ACPI_TIMER_OFFSET      0x8

/**
  The constructor function enables ACPI IO space.

  If ACPI I/O space not enabled, this function will enable it.
  It will always return RETURN_SUCCESS.

  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.

**/
RETURN_STATUS
EFIAPI
AcpiTimerLibConstructor (
  VOID
  )
{
  UINT8 Device;

  Device = 1;
  // Device = 7;

  if (PciRead8 (PCI_LIB_ADDRESS (0,Device,3,0x80)) & 1) {
    mPmba = PciRead32 (PCI_LIB_ADDRESS (0,Device,3,0x40));
    ASSERT (mPmba & PCI_BAR_IO);
    mPmba &= ~PCI_BAR_IO;
  } else {
    mPmba = PcdGet16 (PcdAcpiPmBaseAddress);

    PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40),
                    (UINT32) ~0xFFC0, mPmba);
    PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x04), 0x01);
  }

  //
  // ACPI Timer enable is in Bus 0, Device ?, Function 3
  //
  PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01);
  return RETURN_SUCCESS;
}

/**
  Internal function to read the current tick counter of ACPI.

  Internal function to read the current tick counter of ACPI.

  @return The tick counter read.

**/
STATIC
UINT32
InternalAcpiGetTimerTick (
  VOID
  )
{<commit_msg>OvmfPkg: use PCI_COMMAND_OFFSET/EFI_PCI_COMMAND_IO_SPACE in AcpiTimerLib<commit_after>/** @file
  ACPI Timer implements one instance of Timer Library.

  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
  Copyright (c) 2011, <NAME> <<EMAIL>>

  This program and the accompanying materials are
  licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <Base.h>
#include <Library/TimerLib.h>
#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/PciLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <IndustryStandard/Pci22.h>

//
// PIIX4 Power Management Base Address
//
STATIC UINT32 mPmba;

#define PCI_BAR_IO             0x1
#define ACPI_TIMER_FREQUENCY   3579545
#define ACPI_TIMER_COUNT_SIZE  0x01000000
#define ACPI_TIMER_OFFSET      0x8

/**
  The constructor function enables ACPI IO space.

  If ACPI I/O space not enabled, this function will enable it.
  It will always return RETURN_SUCCESS.

  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.

**/
RETURN_STATUS
EFIAPI
AcpiTimerLibConstructor (
  VOID
  )
{
  UINT8 Device;

  Device = 1;
  // Device = 7;

  if (PciRead8 (PCI_LIB_ADDRESS (0,Device,3,0x80)) & 1) {
    mPmba = PciRead32 (PCI_LIB_ADDRESS (0,Device,3,0x40));
    ASSERT (mPmba & PCI_BAR_IO);
    mPmba &= ~PCI_BAR_IO;
  } else {
    mPmba = PcdGet16 (PcdAcpiPmBaseAddress);

    PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40),
                    (UINT32) ~0xFFC0, mPmba);
    PciOr8 (
      PCI_LIB_ADDRESS (0, Device, 3, PCI_COMMAND_OFFSET),
      EFI_PCI_COMMAND_IO_SPACE
      );
  }

  //
  // ACPI Timer enable is in Bus 0, Device ?, Function 3
  //
  PciOr8         (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01);
  return RETURN_SUCCESS;
}

/**
  Internal function to read the current tick counter of ACPI.

  Internal function to read the current tick counter of ACPI.

  @return The tick counter read.

**/
STATIC
UINT32
InternalAcpiGetTimerTick (
  VOID
  )
{
{'fraction_non_alphanumeric': 0.09117383512544804, 'fraction_numerical': 0.03808243727598566, 'mean_word_length': 3.5422177009155646, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4615719', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1555, 'n_words': 469}