treewide: replace GPLv2 long form headers with SPDX header
[coreboot.git] / util / msrtool / sys.c
blobf32246ed3492292cc8926bbf64d3ab121b6320b9
1 /* This file is part of msrtool. */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <pci/pci.h>
6 #include "msrtool.h"
8 static struct cpuid_t id;
10 struct cpuid_t *cpuid(void) {
11 uint32_t outeax;
12 uint32_t outebx;
14 /* First, we need determine which vendor we have */
15 #if defined(__DARWIN__) && !defined(__LP64__)
16 asm volatile (
17 "pushl %%ebx \n"
18 "cpuid \n"
19 "popl %%ebx \n"
20 : "=b" (outebx) : "a" (0) : "%ecx", "%edx"
22 #else
23 asm ("cpuid" : "=b" (outebx) : "a" (0) : "%ecx", "%edx");
24 #endif
26 id.vendor = outebx;
28 /* Then, identificate CPU itself */
29 #if defined(__DARWIN__) && !defined(__LP64__)
30 asm volatile (
31 "pushl %%ebx \n"
32 "cpuid \n"
33 "popl %%ebx \n"
34 : "=a" (outeax) : "a" (1) : "%ecx", "%edx"
36 #else
37 asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx");
38 #endif
40 id.stepping = outeax & 0xf;
41 outeax >>= 4;
42 id.model = outeax & 0xf;
43 outeax >>= 4;
44 id.family = outeax & 0xf;
45 outeax >>= 8;
46 id.ext_model = outeax & 0xf;
47 outeax >>= 4;
48 id.ext_family = outeax & 0xff;
49 if ((0xf == id.family) || ((VENDOR_INTEL == id.vendor)
50 && (0x6 == id.family))) {
51 /* Intel says always do this, AMD says only for family f */
52 id.model |= (id.ext_model << 4);
53 id.family += id.ext_family;
55 printf_verbose("CPU: family %x, model %x, stepping %x\n",
56 id.family, id.model, id.stepping);
58 return &id;
61 struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) {
62 struct pci_dev *temp;
63 struct pci_filter filter;
65 pci_filter_init(NULL, &filter);
66 filter.vendor = vendor;
67 filter.device = device;
69 for (temp = pacc->devices; temp; temp = temp->next)
70 if (pci_filter_match(&filter, temp))
71 return temp;
73 return NULL;