Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 2 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 3 | #include <pci/pci.h> |
| 4 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 5 | #include "msrtool.h" |
| 6 | |
| 7 | static struct cpuid_t id; |
| 8 | |
| 9 | struct cpuid_t *cpuid(void) { |
| 10 | uint32_t outeax; |
Anton Kochkov | ffbbecc | 2012-07-04 07:31:37 +0400 | [diff] [blame] | 11 | uint32_t outebx; |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 12 | |
Anton Kochkov | ffbbecc | 2012-07-04 07:31:37 +0400 | [diff] [blame] | 13 | /* First, we need determine which vendor we have */ |
| 14 | #if defined(__DARWIN__) && !defined(__LP64__) |
Elyes HAOUAS | 3baa7e7 | 2016-10-15 10:01:21 +0200 | [diff] [blame] | 15 | asm volatile ( |
| 16 | "pushl %%ebx \n" |
| 17 | "cpuid \n" |
| 18 | "popl %%ebx \n" |
| 19 | : "=b" (outebx) : "a" (0) : "%ecx", "%edx" |
| 20 | ); |
Anton Kochkov | ffbbecc | 2012-07-04 07:31:37 +0400 | [diff] [blame] | 21 | #else |
| 22 | asm ("cpuid" : "=b" (outebx) : "a" (0) : "%ecx", "%edx"); |
| 23 | #endif |
| 24 | |
Lubomir Rintel | fbf5759 | 2017-01-22 22:19:21 +0100 | [diff] [blame] | 25 | id.vendor = outebx; |
Anton Kochkov | ffbbecc | 2012-07-04 07:31:37 +0400 | [diff] [blame] | 26 | |
| 27 | /* Then, identificate CPU itself */ |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 28 | #if defined(__DARWIN__) && !defined(__LP64__) |
Elyes HAOUAS | 3baa7e7 | 2016-10-15 10:01:21 +0200 | [diff] [blame] | 29 | asm volatile ( |
| 30 | "pushl %%ebx \n" |
| 31 | "cpuid \n" |
| 32 | "popl %%ebx \n" |
| 33 | : "=a" (outeax) : "a" (1) : "%ecx", "%edx" |
| 34 | ); |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 35 | #else |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 36 | asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx"); |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 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; |
Anton Kochkov | ffbbecc | 2012-07-04 07:31:37 +0400 | [diff] [blame] | 48 | if ((0xf == id.family) || ((VENDOR_INTEL == id.vendor) |
| 49 | && (0x6 == id.family))) { |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 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 | } |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 54 | printf_verbose("CPU: family %x, model %x, stepping %x\n", |
| 55 | id.family, id.model, id.stepping); |
| 56 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 57 | return &id; |
| 58 | } |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame] | 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 | } |