123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- /*++
- Copyright (c) 2012 Minoca Corp. All Rights Reserved
- Module Name:
- archtimr.c
- Abstract:
- This module implements architecture-specific timer support for the hardware
- library.
- Author:
- Evan Green 31-Oct-2012
- Environment:
- Kernel
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <minoca/kernel/kernel.h>
- #include <minoca/kernel/arm.h>
- #include "../hlp.h"
- #include "../timer.h"
- #include "../clock.h"
- #include "../intrupt.h"
- #include "../profiler.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- //
- // Builtin hardware module function prototypes.
- //
- VOID
- HlpArmCycleCounterModuleEntry (
- VOID
- );
- VOID
- HlpCpTimerModuleEntry (
- VOID
- );
- VOID
- HlpSp804TimerModuleEntry (
- VOID
- );
- VOID
- HlpOmap3TimerModuleEntry (
- VOID
- );
- VOID
- HlpOmap4TimerModuleEntry (
- VOID
- );
- VOID
- HlpAm335TimerModuleEntry (
- VOID
- );
- VOID
- HlpBcm2709TimerModuleEntry (
- VOID
- );
- VOID
- HlpRk32TimerModuleEntry (
- VOID
- );
- VOID
- HlpGtModuleEntry (
- VOID
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // Timer modules that are initialized before the debugger.
- //
- PHARDWARE_MODULE_ENTRY HlPreDebuggerTimerModules[] = {
- HlpArmCycleCounterModuleEntry,
- };
- //
- // Built-in hardware modules.
- //
- PHARDWARE_MODULE_ENTRY HlBuiltinTimerModules[] = {
- HlpCpTimerModuleEntry,
- HlpSp804TimerModuleEntry,
- HlpOmap3TimerModuleEntry,
- HlpOmap4TimerModuleEntry,
- HlpAm335TimerModuleEntry,
- HlpBcm2709TimerModuleEntry,
- HlpRk32TimerModuleEntry,
- HlpGtModuleEntry
- };
- //
- // ------------------------------------------------------------------ Functions
- //
- KSTATUS
- HlGetProcessorCounterInformation (
- PHL_PROCESSOR_COUNTER_INFORMATION Information
- )
- /*++
- Routine Description:
- This routine returns information about the cycle counter built into the
- processor.
- Arguments:
- Information - Supplies a pointer where the processor counter information
- will be returned on success.
- Return Value:
- STATUS_SUCCESS on success.
- STATUS_NOT_SUPPORTED if the processor does not have a processor cycle
- counter.
- --*/
- {
- Information->Frequency = HlProcessorCounter->CounterFrequency;
- //
- // The ARM cycle counter is configured to divide actual cycles by 64, since
- // it's only a 32 bit value and can roll over quickly.
- //
- Information->Multiplier = 64;
- Information->Features = HlProcessorCounter->Features;
- return STATUS_SUCCESS;
- }
- VOID
- HlpArchInitializeTimersPreDebugger (
- VOID
- )
- /*++
- Routine Description:
- This routine implements early timer initialization for the hardware module
- API layer. This routine is *undebuggable*, as it is called before the
- debugger is brought online.
- Arguments:
- None.
- Return Value:
- None.
- --*/
- {
- PHARDWARE_MODULE_ENTRY ModuleEntry;
- UINTN TimerCount;
- UINTN TimerIndex;
- TimerCount = sizeof(HlPreDebuggerTimerModules) /
- sizeof(HlPreDebuggerTimerModules[0]);
- for (TimerIndex = 0; TimerIndex < TimerCount; TimerIndex += 1) {
- ModuleEntry = HlPreDebuggerTimerModules[TimerIndex];
- ModuleEntry();
- }
- return;
- }
- KSTATUS
- HlpArchInitializeTimers (
- VOID
- )
- /*++
- Routine Description:
- This routine performs architecture-specific initialization for the timer
- subsystem.
- Arguments:
- None.
- Return Value:
- Status code.
- --*/
- {
- UINTN ModuleCount;
- PHARDWARE_MODULE_ENTRY ModuleEntry;
- UINTN ModuleIndex;
- //
- // On the boot processor, perform one-time initialization.
- //
- if (KeGetCurrentProcessorNumber() == 0) {
- //
- // Loop through and initialize every built in hardware module.
- //
- ModuleCount = sizeof(HlBuiltinTimerModules) /
- sizeof(HlBuiltinTimerModules[0]);
- for (ModuleIndex = 0; ModuleIndex < ModuleCount; ModuleIndex += 1) {
- ModuleEntry = HlBuiltinTimerModules[ModuleIndex];
- ModuleEntry();
- }
- }
- return STATUS_SUCCESS;
- }
- KSTATUS
- HlpArchInitializeCalendarTimers (
- VOID
- )
- /*++
- Routine Description:
- This routine performs architecture-specific initialization for the
- calendar timer subsystem.
- Arguments:
- None.
- Return Value:
- Status code.
- --*/
- {
- return STATUS_SUCCESS;
- }
- KERNEL_API
- ULONGLONG
- HlQueryProcessorCounter (
- VOID
- )
- /*++
- Routine Description:
- This routine queries the processor counter hardware and returns a 64-bit
- monotonically non-decreasing value that correlates to "processor" time.
- This does not necessarily correspond to wall-clock time, as the frequency
- of this counter may vary over time. This counter may also vary across
- processors, so this routine must be called at dispatch level or higher.
- Failing to call this routine at or above dispatch level may cause the
- counter's internal accounting to malfunction.
- This routine is intended primarily for the scheduler to track processor
- cycles. Users looking to measure units of time should query the time
- counter.
- Arguments:
- None.
- Return Value:
- Returns a 64-bit non-decreasing value corresponding to "processor" time.
- --*/
- {
- //
- // Ideally there wouldn't be an assert in such a hot path, but it's very
- // important that this not be called below dispatch level, as doing so
- // would cause the "current count" software managed bits to get miscounted.
- //
- ASSERT((KeGetRunLevel() >= RunLevelDispatch) ||
- (ArAreInterruptsEnabled() == FALSE));
- return HlpTimerExtendedQuery(HlProcessorCounter);
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|