1/* 2 * Copyright 2018, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12#pragma once 13 14#include <stdint.h> 15#include <string.h> 16#include <simple/simple.h> 17#include <utils/frequency.h> 18 19// uses the simple extended bootinfo interface to attempt to determine the tsc frequency 20// returns 0 on failure 21static inline uint32_t 22x86_get_tsc_freq_from_simple(simple_t *simple) { 23 // the simple interface is a bit awkward and doesn't give us a way to just get the last 4 24 // bytes so we have to define some scratch space to get what we want. use a char array instead 25 // of a custom struct so we're not worrying about padding and aliasing etc 26 char buf[sizeof(seL4_BootInfoHeader) + 4]; 27 ssize_t ret = simple_get_extended_bootinfo(simple, SEL4_BOOTINFO_HEADER_X86_TSC_FREQ, buf, sizeof(buf)); 28 if (ret == sizeof(buf)) { 29 uint32_t freq; 30 memcpy(&freq, buf + sizeof(seL4_BootInfoHeader), 4); 31 // convert mhz to hz 32 return freq * MHZ; 33 } 34 return 0; 35} 36