-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aarch64: implement minimal PL031 support
This patch provides basic implementation of a subset of functionality of the PrimeCell Real Time Clock (PL031) device that is enough to capture boot time as number of seconds since epoch. Please note that this implementation does not handle any host clock drift and provides current time functionality that is only accurate up to a second. This patch effectively fixes 2 unit tests - tst-time.cc and tst-timerfd.cc. Fixes #1091 Signed-off-by: Waldemar Kozaczuk <[email protected]>
- Loading branch information
Showing
7 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2021 Waldemar Kozaczuk | ||
* | ||
* This work is open source software, licensed under the terms of the | ||
* BSD license as described in the LICENSE file in the top-level directory. | ||
*/ | ||
|
||
#include "pl031.hh" | ||
#include <osv/mmu.hh> | ||
|
||
/* spec: see PrimeCell Real Time Clock (PL031) Technical Reference Manual. | ||
* implemented according to Revision: r1p3. | ||
* See https://static.docs.arm.com/ddi0224/c/real_time_clock_pl031_r1p3_technical_reference_manual_DDI0224C.pdf | ||
* Please note that this a minimal implementation of a subset of the | ||
* functionality which is enough to read the current time in seconds | ||
* at the boot time. | ||
*/ | ||
|
||
#define rtc_reg(ADDR,REG_OFFSET) (*(volatile u32 *)(ADDR+REG_OFFSET)) | ||
|
||
pl031::pl031(u64 address) | ||
{ | ||
_address = address; | ||
mmu::linear_map((void *)_address, _address, mmu::page_size, mmu::page_size, | ||
mmu::mattr::dev); | ||
} | ||
|
||
pl031::~pl031() | ||
{ | ||
mmu::munmap((void*)_address, mmu::page_size); | ||
} | ||
|
||
uint64_t pl031::wallclock_ns() | ||
{ | ||
// Let us read various identificatin registers to | ||
// verify that it is indeed a valid PL031 device | ||
if( rtc_reg(_address, RTCPeriphID0) == RTCPeriphID0_val && | ||
rtc_reg(_address, RTCPeriphID1) == RTCPeriphID1_val && | ||
(rtc_reg(_address, RTCPeriphID2) & RTCPeriphID2_mask) == RTCPeriphID2_val && | ||
rtc_reg(_address, RTCPeriphID3) == RTCPeriphID3_val && | ||
rtc_reg(_address, RTCPCellID0) == RTCPCellID0_val && | ||
rtc_reg(_address, RTCPCellID1) == RTCPCellID1_val && | ||
rtc_reg(_address, RTCPCellID2) == RTCPCellID2_val && | ||
rtc_reg(_address, RTCPCellID3) == RTCPCellID3_val) { | ||
// Read value of RTC which is number of seconds since epoch | ||
// representing current time | ||
u64 epoch_time_in_seconds = rtc_reg(_address, RTCDR); | ||
#if CONF_logger_debug | ||
debug_early_u64("pl031::wallclock_ns(): RTC seconds since epoch read as ", epoch_time_in_seconds); | ||
#endif | ||
return epoch_time_in_seconds * 1000000000; | ||
} else { | ||
debug_early("pl031: could no detect!"); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (C) 2021 Waldemar Kozaczuk | ||
* | ||
* This work is open source software, licensed under the terms of the | ||
* BSD license as described in the LICENSE file in the top-level directory. | ||
*/ | ||
|
||
#ifndef OSV_PL031_HH | ||
#define OSV_PL031_HH | ||
|
||
#include <osv/types.h> | ||
|
||
#define RTCDR 0x000 /* data */ | ||
#define RTCMR 0x004 /* match */ | ||
#define RTCLR 0x008 /* load */ | ||
#define RTCCR 0x00c /* control */ | ||
#define RTCIMSC 0x010 /* interrupt mask set or clear */ | ||
#define RTCRIS 0x014 /* raw interrupt status */ | ||
#define RTCMIS 0x018 /* masked interrupt status */ | ||
#define RTCICR 0x01c /* interrupt clear */ | ||
#define RTCPeriphID0 0xfe0 /* peripheral ID bits [7:0] */ | ||
#define RTCPeriphID1 0xfe4 /* peripheral ID bits [15:8] */ | ||
#define RTCPeriphID2 0xfe8 /* peripheral ID bits [23:16] */ | ||
#define RTCPeriphID3 0xfec /* peripheral ID bits [31:24] */ | ||
#define RTCPCellID0 0xff0 /* PrimeCell ID bits [7:0] */ | ||
#define RTCPCellID1 0xff4 /* PrimeCell ID bits [7:0] */ | ||
#define RTCPCellID2 0xff8 /* PrimeCell ID bits [7:0] */ | ||
#define RTCPCellID3 0xffc /* PrimeCell ID bits [7:0] */ | ||
|
||
#define RTCPeriphID0_val 0x31 | ||
#define RTCPeriphID1_val 0x10 | ||
#define RTCPeriphID2_mask 0x0f | ||
#define RTCPeriphID2_val 0x04 | ||
#define RTCPeriphID3_val 0x00 | ||
|
||
#define RTCPCellID0_val 0x0d | ||
#define RTCPCellID1_val 0xf0 | ||
#define RTCPCellID2_val 0x05 | ||
#define RTCPCellID3_val 0xb1 | ||
|
||
class pl031 { | ||
public: | ||
pl031(u64 address); | ||
~pl031(); | ||
uint64_t wallclock_ns(); | ||
private: | ||
u64 _address; | ||
}; | ||
|
||
#endif //OSV_PL031_HH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters