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