Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of msrtool. |
| 3 | * |
| 4 | * Copyright (c) 2008 Peter Stuge <peter@stuge.se> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame^] | 20 | #include <pci/pci.h> |
| 21 | |
Peter Stuge | dad1e30 | 2008-11-22 17:13:36 +0000 | [diff] [blame] | 22 | #include "msrtool.h" |
| 23 | |
| 24 | static struct cpuid_t id; |
| 25 | |
| 26 | struct cpuid_t *cpuid(void) { |
| 27 | uint32_t outeax; |
| 28 | asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx"); |
| 29 | id.stepping = outeax & 0xf; |
| 30 | outeax >>= 4; |
| 31 | id.model = outeax & 0xf; |
| 32 | outeax >>= 4; |
| 33 | id.family = outeax & 0xf; |
| 34 | outeax >>= 8; |
| 35 | id.ext_model = outeax & 0xf; |
| 36 | outeax >>= 4; |
| 37 | id.ext_family = outeax & 0xff; |
| 38 | if (0xf == id.family) { |
| 39 | /* Intel says always do this, AMD says only for family f */ |
| 40 | id.model |= (id.ext_model << 4); |
| 41 | id.family += id.ext_family; |
| 42 | } |
| 43 | return &id; |
| 44 | } |
Peter Stuge | 0924dee | 2008-11-25 02:03:16 +0000 | [diff] [blame^] | 45 | |
| 46 | struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) { |
| 47 | struct pci_dev *temp; |
| 48 | struct pci_filter filter; |
| 49 | |
| 50 | pci_filter_init(NULL, &filter); |
| 51 | filter.vendor = vendor; |
| 52 | filter.device = device; |
| 53 | |
| 54 | for (temp = pacc->devices; temp; temp = temp->next) |
| 55 | if (pci_filter_match(&filter, temp)) |
| 56 | return temp; |
| 57 | |
| 58 | return NULL; |
| 59 | } |