HyperDbg Debugger
Loading...
Searching...
No Matches
Pci.h File Reference
#include "pch.h"

Go to the source code of this file.

Macros

#define CFGADR   0xCF8
#define CFGDAT   0xCFC

Functions

QWORD PciReadCam (WORD Bus, WORD Device, WORD Function, BYTE Offset, UINT8 Width)
 Read from PCI configuration space (CAM) at given offset.
BOOLEAN PciWriteCam (WORD Bus, WORD Device, WORD Function, BYTE Offset, UINT8 Width, QWORD Value)
 Write to PCI configuration space (CAM) at given offset.

Macro Definition Documentation

◆ CFGADR

#define CFGADR   0xCF8

◆ CFGDAT

#define CFGDAT   0xCFC

Function Documentation

◆ PciReadCam()

QWORD PciReadCam ( WORD Bus,
WORD Device,
WORD Function,
BYTE Offset,
UINT8 Width )

Read from PCI configuration space (CAM) at given offset.

Parameters
Bus
Device
Function
Offset
WidthNumber of bytes to return. Supported data types: BYTE (1), WORD (2), DWORD (4), QWORD (8).
Returns
QWORD
26{
27 WORD Target = 0;
28
29 //
30 // Restrict Offset to CAM address space; restrict BDF to our internal limits
31 //
32 if (Offset > CAM_CONFIG_SPACE_LENGTH ||
33 Bus >= BUS_MAX_NUM ||
35 Function >= FUNCTION_MAX_NUM)
36 {
37 return MAXDWORD64;
38 }
39
40 Target = Function + ((Device & 0x1F) << 3) + ((Bus & 0xFF) << 8);
41 _outpd(CFGADR, (DWORD)(Target << 8) | 0x80000000UL | ((DWORD)Offset & ~3));
42
43 switch ((UINT32)Width)
44 {
45 case sizeof(BYTE):
46 return (BYTE)_inp(CFGDAT + (Offset & 0x3));
47 break;
48 case sizeof(WORD):
49 return (WORD)_inpw(CFGDAT + (Offset & 0x2));
50 break;
51 case sizeof(DWORD):
52 return _inpd(CFGDAT);
53 break;
54 case sizeof(QWORD):
55 return (PciReadCam(Bus, Device, Function, Offset + sizeof(DWORD), sizeof(DWORD)) << 32) | PciReadCam(Bus, Device, Function, Offset + 0, sizeof(DWORD));
56 break;
57 default:
58 return MAXDWORD64;
59 }
60}
#define CFGDAT
Definition Pci.h:20
#define CFGADR
Definition Pci.h:19
unsigned short WORD
Definition BasicTypes.h:42
unsigned char BYTE
Definition BasicTypes.h:40
unsigned long long QWORD
Definition BasicTypes.h:24
unsigned long DWORD
Definition BasicTypes.h:38
unsigned int UINT32
Definition BasicTypes.h:54
#define FUNCTION_MAX_NUM
Definition Pcie.h:41
#define DEVICE_MAX_NUM
Definition Pcie.h:40
#define BUS_MAX_NUM
Definition Pcie.h:39
#define CAM_CONFIG_SPACE_LENGTH
Definition Pcie.h:43
IMPORT_EXPORT_VMM QWORD PciReadCam(WORD Bus, WORD Device, WORD Function, BYTE Offset, UINT8 Width)
Read from PCI configuration space (CAM) at given offset.
Definition Pci.c:25
return
Definition command-parser-testcases.txt:388
Definition pci-id.h:26

◆ PciWriteCam()

BOOLEAN PciWriteCam ( WORD Bus,
WORD Device,
WORD Function,
BYTE Offset,
UINT8 Width,
QWORD Value )

Write to PCI configuration space (CAM) at given offset.

Parameters
Bus
Device
Function
Offset
WidthNumber of bytes to write. Supported data types: BYTE (1), WORD (2), DWORD (4), QWORD (8).
Valueto write.
Returns
BOOLEAN
75{
76 BOOLEAN Result = TRUE;
77 WORD Target = 0;
78
79 //
80 // Restrict Offset to CAM address space; restrict BDF to our internal limits
81 //
82 if (Offset > CAM_CONFIG_SPACE_LENGTH ||
83 Bus >= BUS_MAX_NUM ||
85 Function >= FUNCTION_MAX_NUM)
86 {
87 Result = FALSE;
88 }
89 else
90 {
91 Target = Function + ((Device & 0x1F) << 3) + ((Bus & 0xFF) << 8);
92 _outpd(CFGADR, (DWORD)(Target << 8) | 0x80000000UL | ((DWORD)Offset & ~3));
93
94 switch ((UINT32)Width)
95 {
96 case sizeof(BYTE):
97 _outp((CFGDAT + (Offset & 0x3)), (BYTE)Value);
98 Result = TRUE;
99 break;
100 case sizeof(WORD):
101 _outpw((CFGDAT + (Offset & 0x2)), (WORD)Value);
102 Result = TRUE;
103 break;
104 case sizeof(DWORD):
105 _outpd((CFGDAT + Offset), (DWORD)Value);
106 Result = TRUE;
107 break;
108 case sizeof(QWORD):
109 Result = PciWriteCam(Bus, Device, Function, Offset + sizeof(DWORD), sizeof(DWORD), (DWORD)(Value >> 32));
110 Result = PciWriteCam(Bus, Device, Function, Offset + 0, sizeof(DWORD), (DWORD)Value);
111 break;
112 default:
113 Result = FALSE;
114 }
115 }
116
117 return Result;
118}
BOOLEAN PciWriteCam(WORD Bus, WORD Device, WORD Function, BYTE Offset, UINT8 Width, QWORD Value)
Write to PCI configuration space (CAM) at given offset.
Definition Pci.c:74
UCHAR BOOLEAN
Definition BasicTypes.h:35
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
RequestedActionOfThePacket Value(0x1) 00000000