blob: f6aded52bc4a4f66b830a9b17df34bdacf3d6d06 [file] [log] [blame]
Peter Stugedad1e302008-11-22 17:13:36 +00001/*
2 * This file is part of msrtool.
3 *
4 * Copyright (c) 2008 Peter Stuge <peter@stuge.se>
Stefan Reinauer37f39352009-09-01 10:03:01 +00005 * Copyright (c) 2009 coresystems GmbH
Peter Stugedad1e302008-11-22 17:13:36 +00006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Peter Stuge0924dee2008-11-25 02:03:16 +000021#include <pci/pci.h>
22
Peter Stugedad1e302008-11-22 17:13:36 +000023#include "msrtool.h"
24
25static struct cpuid_t id;
26
27struct cpuid_t *cpuid(void) {
28 uint32_t outeax;
Stefan Reinauer37f39352009-09-01 10:03:01 +000029
30#if defined(__DARWIN__) && !defined(__LP64__)
31 asm volatile (
32 "pushl %%ebx \n"
33 "cpuid \n"
34 "popl %%ebx \n"
35 : "=a" (outeax) : "a" (1) : "%ecx", "%edx"
36 );
37#else
Peter Stugedad1e302008-11-22 17:13:36 +000038 asm ("cpuid" : "=a" (outeax) : "a" (1) : "%ebx", "%ecx", "%edx");
Stefan Reinauer37f39352009-09-01 10:03:01 +000039#endif
40
Peter Stugedad1e302008-11-22 17:13:36 +000041 id.stepping = outeax & 0xf;
42 outeax >>= 4;
43 id.model = outeax & 0xf;
44 outeax >>= 4;
45 id.family = outeax & 0xf;
46 outeax >>= 8;
47 id.ext_model = outeax & 0xf;
48 outeax >>= 4;
49 id.ext_family = outeax & 0xff;
50 if (0xf == 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;
54 }
Stefan Reinauer37f39352009-09-01 10:03:01 +000055 printf_verbose("CPU: family %x, model %x, stepping %x\n",
56 id.family, id.model, id.stepping);
57
Peter Stugedad1e302008-11-22 17:13:36 +000058 return &id;
59}
Peter Stuge0924dee2008-11-25 02:03:16 +000060
61struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device) {
62 struct pci_dev *temp;
63 struct pci_filter filter;
64
65 pci_filter_init(NULL, &filter);
66 filter.vendor = vendor;
67 filter.device = device;
68
69 for (temp = pacc->devices; temp; temp = temp->next)
70 if (pci_filter_match(&filter, temp))
71 return temp;
72
73 return NULL;
74}