Skip to content

Commit

Permalink
cpuid: move functions from cpuid.h into cpuid.c
Browse files Browse the repository at this point in the history
While at it, move cpuid.h into arch/x86 directory.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jan 24, 2022
1 parent e55bb28 commit ab9d49e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
15 changes: 4 additions & 11 deletions include/cpuid.h → arch/x86/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KTF_CPUID_H
#define KTF_CPUID_H

#include <ktf.h>
#include <string.h>
#include <cpuid.h>

/* CPU vendor detection */
#define CPUID_EXT_INFO_LEAF 0x80000000U
#define CPUID_BRAND_INFO_MIN 0x80000002U
#define CPUID_BRAND_INFO_MAX 0x80000004U

static uint64_t get_cpu_freq(const char *cpu_str) {
uint64_t get_cpu_freq(const char *cpu_str) {
size_t len = strlen(cpu_str);
uint64_t frequency = 0;
char buf[16];
Expand Down Expand Up @@ -96,7 +91,7 @@ static uint64_t get_cpu_freq(const char *cpu_str) {
return frequency;
}

static inline bool cpu_vendor_string(char *cpu_str) {
bool cpu_vendor_string(char *cpu_str) {
uint32_t leaf = CPUID_EXT_INFO_LEAF;
uint32_t ebx = 0, ecx = 0, edx = 0;
uint32_t eax = cpuid_eax(leaf);
Expand All @@ -117,5 +112,3 @@ static inline bool cpu_vendor_string(char *cpu_str) {

return true;
}

#endif /* KTF_CPUID_H */
38 changes: 38 additions & 0 deletions include/arch/x86/cpuid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright © 2020 Amazon.com, Inc. or its affiliates.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KTF_CPUID_H
#define KTF_CPUID_H

#include <ktf.h>

/* CPU vendor detection */
#define CPUID_EXT_INFO_LEAF 0x80000000U
#define CPUID_BRAND_INFO_MIN 0x80000002U
#define CPUID_BRAND_INFO_MAX 0x80000004U

extern uint64_t get_cpu_freq(const char *cpu_str);
extern bool cpu_vendor_string(char *cpu_str);

#endif /* KTF_CPUID_H */

0 comments on commit ab9d49e

Please sign in to comment.