Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/libsaio/cpu.h

1/*
2 * Copyright 2008 Islam Ahmed Zaid. All rights reserved. <azismed@gmail.com>
3 * AsereBLN: 2009: cleanup and bugfix
4 */
5
6#ifndef __LIBSAIO_CPU_H
7#define __LIBSAIO_CPU_H
8
9#include "libsaio.h"
10
11extern void scan_cpu(void);
12
13#defineMSR_IA32_PERF_STATUS0x198
14#define MSR_IA32_PERF_CONTROL0x199
15#define MSR_IA32_EXT_CONFIG0x00EE
16#define MSR_FLEX_RATIO0x194
17#defineMSR_PLATFORM_INFO0xCE
18#define MSR_TURBO_RATIO_LIMIT0x1AD
19#define MSR_IA32_BIOS_SIGN_ID 0x08B
20#define MSR_CORE_THREAD_COUNT 0x035
21#define K8_FIDVID_STATUS0xC0010042
22#define K10_COFVID_STATUS0xC0010071
23
24#define DEFAULT_FSB100000 /* for now, hardcoding 100MHz for old CPUs */
25
26// DFE: This constant comes from older xnu:
27#define CLKNUM1193182/* formerly 1193167 */
28
29// DFE: These two constants come from Linux except CLOCK_TICK_RATE replaced with CLKNUM
30#define CALIBRATE_TIME_MSEC30/* 30 msecs */
31#define CALIBRATE_LATCH((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000)
32
33static inline uint64_t rdtsc64(void)
34{
35uint64_t ret;
36__asm__ volatile("rdtsc" : "=A" (ret));
37return ret;
38}
39
40static inline uint64_t rdmsr64(uint32_t msr)
41{
42 uint64_t ret;
43 __asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
44 return ret;
45}
46
47static inline void wrmsr64(uint32_t msr, uint64_t val)
48{
49__asm__ volatile("wrmsr" : : "c" (msr), "A" (val));
50}
51
52static inline void intel_waitforsts(void) {
53uint32_t inline_timeout = 100000;
54while (rdmsr64(MSR_IA32_PERF_STATUS) & (1 << 21)) { if (!inline_timeout--) break; }
55}
56
57static inline void do_cpuid2(uint32_t selector, uint32_t selector2, uint32_t *data)
58{
59asm volatile ("cpuid"
60 : "=a" (data[0]),
61 "=b" (data[1]),
62 "=c" (data[2]),
63 "=d" (data[3])
64 : "a" (selector), "c" (selector2),
65 "b" (0),
66 "d" (0));
67}
68
69#endif /* !__LIBSAIO_CPU_H */
70

Archive Download this file

Revision: 1984