Intel(r) Performance Counter Monitor
pci.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2009-2012, Intel Corporation
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9  * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 */
13 // written by Roman Dementiev
14 // Pat Fay
15 // Jim Harris (FreeBSD)
16 
17 
18 #ifndef CPUCounters_PCI_H
19 #define CPUCounters_PCI_H
20 
26 #include "types.h"
27 
28 #ifdef _MSC_VER
29 #include "windows.h"
30 #else
31 #include <unistd.h>
32 #endif
33 
34 #ifdef __APPLE__
35 #include "PCIDriverInterface.h"
36 #endif
37 
38 #include <vector>
39 
40 #define PCM_USE_PCI_MM_LINUX
41 
42 class PciHandle
43 {
44 #ifdef _MSC_VER
45  HANDLE hDriver;
46 #else
47  int32 fd;
48 #endif
49 
50  uint32 bus;
51  uint32 device;
52  uint32 function;
53 #ifdef _MSC_VER
54  DWORD pciAddress;
55 #endif
56 
57  PciHandle(); // forbidden
58  PciHandle(PciHandle &); // forbidden
59 
60 public:
61  PciHandle(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 function_);
62 
63  static bool exists(uint32 bus_, uint32 device_, uint32 function_);
64 
65  int32 read32(uint64 offset, uint32 * value);
66  int32 write32(uint64 offset, uint32 value);
67 
68  int32 read64(uint64 offset, uint64 * value);
69 
70  virtual ~PciHandle();
71 };
72 
73 #ifdef _MSC_VER
74 typedef PciHandle PciHandleM;
75 #elif __APPLE__
76 // This may need to change if it can be implemented for OSX
77 typedef PciHandle PciHandleM;
78 #elif __FreeBSD__
79 typedef PciHandle PciHandleM;
80 #else
81 
82 // read/write PCI config space using physical memory
84 {
85 #ifdef _MSC_VER
86 
87 #else
88  int32 fd;
89 #endif
90 
91  uint32 bus;
92  uint32 device;
93  uint32 function;
94  uint64 base_addr;
95 
96  PciHandleM(); // forbidden
97  PciHandleM(PciHandleM &); // forbidden
98 
99 public:
100  PciHandleM(uint32 bus_, uint32 device_, uint32 function_);
101 
102  static bool exists(uint32 bus_, uint32 device_, uint32 function_);
103 
104  int32 read32(uint64 offset, uint32 * value);
105  int32 write32(uint64 offset, uint32 value);
106 
107  int32 read64(uint64 offset, uint64 * value);
108 
109  virtual ~PciHandleM();
110 };
111 
112 #ifndef _MSC_VER
113 
114 // read/write PCI config space using physical memory using mmaped file I/O
116 {
117  int32 fd;
118  char * mmapAddr;
119 
120  uint32 bus;
121  uint32 device;
122  uint32 function;
123  uint64 base_addr;
124 
125 #ifdef __linux__
126  static MCFGHeader mcfgHeader;
127  static std::vector<MCFGRecord> mcfgRecords;
128  static void readMCFG();
129 #endif
130 
131  PciHandleMM(); // forbidden
132  PciHandleMM(PciHandleM &); // forbidden
133 
134 public:
135  PciHandleMM(uint32 groupnr_, uint32 bus_, uint32 device_, uint32 function_);
136 
137  static bool exists(uint32 bus_, uint32 device_, uint32 function_);
138 
139  int32 read32(uint64 offset, uint32 * value);
140  int32 write32(uint64 offset, uint32 value);
141 
142  int32 read64(uint64 offset, uint64 * value);
143 
144  virtual ~PciHandleMM();
145 
146 #ifdef __linux__
147  static const std::vector<MCFGRecord> & getMCFGRecords();
148 #endif
149 };
150 
151 #ifdef PCM_USE_PCI_MM_LINUX
152 #define PciHandleM PciHandleMM
153 #endif
154 
155 #endif // _MSC_VER
156 
157 #endif
158 
159 
160 #endif
Internal type and constant definitions.
Definition: pci.h:83
Definition: types.h:726
Definition: pci.h:115
Definition: pci.h:42