Skip to content

Commit bc4f82d

Browse files
ZideChen0lijinxia
authored andcommitted
hv: more cleanup for pci.h
Don't have any logical changes. - add more common PCI macros - remove redundant definitions in dmar_parse.c - move all the common mascos from vpci.h to pci.h Tracked-On: #1568 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Signed-off-by: Zide Chen <zide.chen@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent e24899d commit bc4f82d

File tree

4 files changed

+96
-30
lines changed

4 files changed

+96
-30
lines changed

hypervisor/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ INCLUDE_PATH += include/arch/x86
9999
INCLUDE_PATH += include/arch/x86/guest
100100
INCLUDE_PATH += include/debug
101101
INCLUDE_PATH += include/public
102-
ifeq ($(CONFIG_PARTITION_MODE),y)
103102
INCLUDE_PATH += include/dm
104-
endif
105103
INCLUDE_PATH += bsp/include
106104
INCLUDE_PATH += bsp/include/$(CONFIG_PLATFORM)
107105
INCLUDE_PATH += boot/include

hypervisor/boot/dmar_parse.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66

77
#ifdef CONFIG_DMAR_PARSE_ENABLED
88
#include <hypervisor.h>
9+
#include "pci.h"
910
#include "vtd.h"
1011
#include "acpi.h"
1112

12-
#define PCI_CONFIG_ADDRESS 0xcf8
13-
#define PCI_CONFIG_DATA 0xcfc
14-
#define PCI_CONFIG_ACCESS_EN 0x80000000
15-
1613
enum acpi_dmar_type {
1714
ACPI_DMAR_TYPE_HARDWARE_UNIT = 0,
1815
ACPI_DMAR_TYPE_RESERVED_MEMORY = 1,
@@ -148,8 +145,8 @@ static uint8_t get_secondary_bus(uint8_t bus, uint8_t dev, uint8_t func)
148145
{
149146
uint32_t data;
150147

151-
pio_write32(PCI_CONFIG_ACCESS_EN | (bus << 16) | (dev << 11) |
152-
(func << 8) | 0x18, PCI_CONFIG_ADDRESS);
148+
pio_write32(PCI_CFG_ENABLE | (bus << 16) | (dev << 11) |
149+
(func << 8) | 0x18, PCI_CONFIG_ADDR);
153150

154151
data = pio_read32(PCI_CONFIG_DATA);
155152

hypervisor/include/dm/pci.h

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,117 @@
3030
#ifndef PCI_H_
3131
#define PCI_H_
3232

33-
#define PCIM_BAR_MEM_BASE 0xFFFFFFF0U
33+
/*
34+
* PCIM_xxx: mask to locate subfield in register
35+
* PCIR_xxx: config register offset
36+
* PCIC_xxx: device class
37+
* PCIS_xxx: device subclass
38+
* PCIP_xxx: device programming interface
39+
* PCIV_xxx: PCI vendor ID (only required to fixup ancient devices)
40+
* PCID_xxx: device ID
41+
* PCIY_xxx: capability identification number
42+
* PCIZ_xxx: extended capability identification number
43+
*/
3444

45+
/* some PCI bus constants */
3546
#define PCI_BUSMAX 0xFFU
3647
#define PCI_SLOTMAX 0x1FU
3748
#define PCI_FUNCMAX 0x7U
49+
#define PCI_BAR_COUNT 0x6U
50+
#define PCI_REGMAX 0xFFU
51+
52+
#define PCI_BUS(bdf) (((bdf) >> 8U) & 0xFFU)
53+
#define PCI_SLOT(bdf) (((bdf) >> 3U) & 0x1FU)
54+
#define PCI_FUNC(bdf) ((bdf) & 0x7U)
55+
56+
/* I/O ports */
57+
#define PCI_CONFIG_ADDR 0xCF8U
58+
#define PCI_CONFIG_DATA 0xCFCU
3859

60+
#define PCI_CFG_ENABLE 0x80000000U
61+
62+
/* PCI config header registers for all devices */
3963
#define PCIR_VENDOR 0x00U
4064
#define PCIR_DEVICE 0x02U
4165
#define PCIR_COMMAND 0x04U
66+
#define PCIM_CMD_INTxDIS 0x400U
67+
#define PCIR_STATUS 0x06U
68+
#define PCIM_STATUS_CAPPRESENT 0x0010U
4269
#define PCIR_REVID 0x08U
4370
#define PCIR_SUBCLASS 0x0AU
4471
#define PCIR_CLASS 0x0BU
4572
#define PCIR_HDRTYPE 0x0EU
73+
#define PCIM_HDRTYPE 0x7FU
4674
#define PCIM_HDRTYPE_NORMAL 0x00U
75+
#define PCIM_HDRTYPE_BRIDGE 0x01U
4776
#define PCIM_MFDEV 0x80U
77+
#define PCIR_BARS 0x10U
78+
#define PCIM_BAR_SPACE 0x01U
79+
#define PCIM_BAR_IO_SPACE 0x01U
80+
#define PCIM_BAR_MEM_TYPE 0x06U
81+
#define PCIM_BAR_MEM_32 0x00U
82+
#define PCIM_BAR_MEM_1MB 0x02U
83+
#define PCIM_BAR_MEM_64 0x04U
84+
#define PCIM_BAR_MEM_BASE 0xFFFFFFF0U
85+
#define PCIR_CAP_PTR 0x34U
86+
87+
/* config registers for header type 1 (PCI-to-PCI bridge) devices */
88+
#define PCIR_PRIBUS_1 0x18U
89+
#define PCIR_SECBUS_1 0x19U
90+
#define PCIR_SUBBUS_1 0x1AU
4891

92+
/* Capability Register Offsets */
93+
#define PCICAP_ID 0x0U
94+
#define PCICAP_NEXTPTR 0x1U
95+
96+
/* Capability Identification Numbers */
97+
#define PCIY_MSI 0x05U
98+
#define PCIY_MSIX 0x11U
99+
100+
/* PCI Message Signalled Interrupts (MSI) */
101+
#define PCIR_MSI_CTRL 0x02U
102+
#define PCIM_MSICTRL_64BIT 0x80U
103+
#define PCIM_MSICTRL_MSI_ENABLE 0x01U
104+
#define PCIR_MSI_ADDR 0x4U
105+
#define PCIR_MSI_ADDR_HIGH 0x8U
106+
#define PCIR_MSI_DATA 0x8U
107+
#define PCIR_MSI_DATA_64BIT 0xCU
108+
#define PCIR_MSI_MASK 0x10U
109+
#define PCIM_MSICTRL_MMC_MASK 0x000EU
110+
#define PCIM_MSICTRL_MME_MASK 0x0070U
111+
112+
/* PCI device class */
49113
#define PCIC_BRIDGE 0x06U
50114
#define PCIS_BRIDGE_HOST 0x00U
51115

52-
#define PCI_CONFIG_ADDR 0xCF8U
53-
#define PCI_CONFIG_DATA 0xCFCU
116+
/* MSI-X definitions */
117+
#define PCIR_MSIX_CTRL 0x2U
118+
#define PCIR_MSIX_TABLE 0x4U
119+
#define PCIR_MSIX_PBA 0x8U
54120

55-
#define PCI_CFG_ENABLE 0x80000000U
121+
#define PCIM_MSIXCTRL_MSIX_ENABLE 0x8000U
122+
#define PCIM_MSIXCTRL_FUNCTION_MASK 0x4000U
123+
#define PCIM_MSIXCTRL_TABLE_SIZE 0x07FFU
124+
#define PCIM_MSIX_BIR_MASK 0x7U
125+
#define PCIM_MSIX_VCTRL_MASK 0x1U
126+
127+
#define MSIX_CAPLEN 12U
128+
#define MSIX_TABLE_ENTRY_SIZE 16U
129+
130+
union pci_bdf {
131+
uint16_t value;
132+
struct {
133+
uint8_t f : 3; /* BITs 0-2 */
134+
uint8_t d : 5; /* BITs 3-7 */
135+
uint8_t b; /* BITs 8-15 */
136+
} bits;
137+
};
138+
139+
enum pci_bar_type {
140+
PCIBAR_NONE = 0,
141+
PCIBAR_MEM32,
142+
PCIBAR_MEM64,
143+
};
56144

57145
static inline uint32_t pci_bar_offset(uint32_t idx)
58146
{

hypervisor/include/dm/vpci.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
#ifndef VPCI_H_
3131
#define VPCI_H_
3232

33-
#define PCI_BAR_COUNT 0x6U
34-
#define PCI_REGMAX 0xFFU
33+
#include <pci.h>
3534

3635
struct pci_vdev;
3736
struct pci_vdev_ops {
@@ -46,22 +45,6 @@ struct pci_vdev_ops {
4645
uint32_t bytes, uint32_t *val);
4746
};
4847

49-
union pci_bdf {
50-
uint16_t value;
51-
52-
struct {
53-
uint8_t f : 3; /* BITs 0-2 */
54-
uint8_t d : 5; /* BITs 3-7 */
55-
uint8_t b; /* BITs 8-15 */
56-
} bits;
57-
};
58-
59-
enum pci_bar_type {
60-
PCIBAR_NONE = 0,
61-
PCIBAR_MEM32,
62-
PCIBAR_MEM64,
63-
};
64-
6548
struct pci_bar {
6649
uint64_t base;
6750
uint64_t size;

0 commit comments

Comments
 (0)