Skip to content

Commit 5e4e6bc

Browse files
Tomasz Bursztykanashif
authored andcommitted
drivers/pcie: Add Virtual Channel configuration support
Basic support of VC capability, where a driver can enable VC and map its traffic classes. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent faadbc4 commit 5e4e6bc

File tree

3 files changed

+181
-1
lines changed

3 files changed

+181
-1
lines changed

drivers/pcie/host/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
zephyr_library()
22

3-
zephyr_library_sources(pcie.c)
3+
zephyr_library_sources(pcie.c vc.c)
44
zephyr_library_sources_ifdef(CONFIG_PCIE_CONTROLLER controller.c)
55
zephyr_library_sources_ifdef(CONFIG_PCIE_ECAM pcie_ecam.c)
66
zephyr_library_sources_ifdef(CONFIG_PCIE_MSI msi.c)

drivers/pcie/host/vc.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2023 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <errno.h>
8+
9+
#include <zephyr/kernel.h>
10+
11+
#include <zephyr/drivers/pcie/pcie.h>
12+
#include <zephyr/drivers/pcie/cap.h>
13+
14+
#include "vc.h"
15+
16+
uint32_t pcie_vc_cap_lookup(pcie_bdf_t bdf, struct pcie_vc_regs *regs)
17+
{
18+
uint32_t base;
19+
20+
base = pcie_get_ext_cap(bdf, PCIE_EXT_CAP_ID_VC);
21+
if (base == 0) {
22+
base = pcie_get_ext_cap(bdf, PCIE_EXT_CAP_ID_MFVC_VC);
23+
if (base == 0) {
24+
return 0;
25+
}
26+
}
27+
28+
regs->cap_reg_1.raw = pcie_conf_read(bdf, base +
29+
PCIE_VC_CAP_REG_1_OFFSET);
30+
regs->cap_reg_2.raw = pcie_conf_read(bdf, base +
31+
PCIE_VC_CAP_REG_2_OFFSET);
32+
regs->ctrl_reg.raw = pcie_conf_read(bdf, base +
33+
PCIE_VC_CTRL_STATUS_REG_OFFSET);
34+
35+
return base;
36+
}
37+
38+
void pcie_vc_load_resources_regs(pcie_bdf_t bdf,
39+
uint32_t base,
40+
struct pcie_vc_resource_regs *regs,
41+
int nb_regs)
42+
{
43+
int idx;
44+
45+
for (idx = 0; idx < nb_regs; idx++) {
46+
regs->cap_reg.raw =
47+
pcie_conf_read(bdf, base +
48+
PCIE_VC_RES_CAP_REG_OFFSET(idx));
49+
regs->ctrl_reg.raw =
50+
pcie_conf_read(bdf, base +
51+
PCIE_VC_RES_CTRL_REG_OFFSET(idx));
52+
regs->status_reg.raw =
53+
pcie_conf_read(bdf, base +
54+
PCIE_VC_RES_STATUS_REG_OFFSET(idx));
55+
regs++;
56+
}
57+
}

drivers/pcie/host/vc.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2021 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_PCIE_HOST_VC_H_
8+
#define ZEPHYR_DRIVERS_PCIE_HOST_VC_H_
9+
10+
#define PCIE_VC_MAX_COUNT 8
11+
12+
#define PCIE_VC_CAP_REG_1_OFFSET 0x04U
13+
#define PCIE_VC_CAP_REG_2_OFFSET 0x08U
14+
#define PCIE_VC_CTRL_STATUS_REG_OFFSET 0x0CU
15+
16+
/** Virtual Channel capability and control Registers */
17+
struct pcie_vc_regs {
18+
union {
19+
struct {
20+
/** Virtual Channel Count */
21+
uint32_t vc_count : 3;
22+
uint32_t _reserved1 : 1;
23+
/** Low Priority Virtual Channel Count */
24+
uint32_t lpvc_count : 3;
25+
uint32_t _reserved2 : 1;
26+
/** Reference Clock */
27+
uint32_t reference_clock : 2;
28+
/** Port Arbitration Table Entry Size */
29+
uint32_t pat_entry_size : 3;
30+
uint32_t _reserved3 : 19;
31+
};
32+
uint32_t raw;
33+
} cap_reg_1;
34+
35+
union {
36+
struct {
37+
/** Virtual Channel Arbitration Capability */
38+
uint32_t vca_cap : 8;
39+
uint32_t _reserved1 : 16;
40+
/** Virtual Channel Arbitration Table Offset */
41+
uint32_t vca_table_offset : 8;
42+
};
43+
uint32_t raw;
44+
} cap_reg_2;
45+
46+
union {
47+
struct {
48+
/** Load Virtual Channel Arbitration Table */
49+
uint32_t load_vca_table : 1;
50+
/** Virtual Channel Arbitration Select */
51+
uint32_t vca_select : 3;
52+
uint32_t _reserved1 : 12;
53+
/** Virtual Channel Arbitration Table Status */
54+
uint32_t vca_table_status : 1;
55+
uint32_t _reserved2 : 15;
56+
};
57+
uint32_t raw;
58+
} ctrl_reg;
59+
};
60+
61+
#define PCIE_VC_RES_CAP_REG_OFFSET(_vc) (0x10U + _vc * 0X0CU)
62+
#define PCIE_VC_RES_CTRL_REG_OFFSET(_vc) (0x14U + _vc * 0X0CU)
63+
#define PCIE_VC_RES_STATUS_REG_OFFSET(_vc) (0x18U + _vc * 0X0CU)
64+
65+
/** Virtual Channel Resource Registers */
66+
struct pcie_vc_resource_regs {
67+
union {
68+
struct {
69+
/** Port Arbitration Capability */
70+
uint32_t pa_cap : 8;
71+
uint32_t _reserved1 : 6;
72+
uint32_t undefined : 1;
73+
/** Reject Snoop Transactions */
74+
uint32_t rst : 1;
75+
/** Maximum Time Slots */
76+
uint32_t max_time_slots : 7;
77+
uint32_t _reserved2 : 1;
78+
/** Port Arbitration Table Offset */
79+
uint32_t pa_table_offset : 8;
80+
};
81+
uint32_t raw;
82+
} cap_reg;
83+
84+
union {
85+
struct {
86+
/** Traffic Class to Virtual Channel Map */
87+
uint32_t tc_vc_map : 8;
88+
uint32_t _reserved1 : 8;
89+
/** Load Port Arbitration Table */
90+
uint32_t load_pa_table : 1;
91+
/** Port Arbitration Select */
92+
uint32_t pa_select : 3;
93+
uint32_t _reserved2 : 4;
94+
/** Virtual Channel ID */
95+
uint32_t vc_id : 3;
96+
uint32_t _reserved3 : 4;
97+
/** Virtual Channel Enable */
98+
uint32_t vc_enable : 1;
99+
};
100+
uint32_t raw;
101+
} ctrl_reg;
102+
103+
union {
104+
struct {
105+
uint32_t _reserved1 : 16;
106+
/** Port Arbitration Table Status */
107+
uint32_t pa_table_status : 1;
108+
/** Virtual Channel Negociation Pending */
109+
uint32_t vc_negocation_pending : 1;
110+
uint32_t _reserved2 : 14;
111+
};
112+
uint32_t raw;
113+
} status_reg;
114+
};
115+
116+
uint32_t pcie_vc_cap_lookup(pcie_bdf_t bdf, struct pcie_vc_regs *regs);
117+
118+
void pcie_vc_load_resources_regs(pcie_bdf_t bdf,
119+
uint32_t base,
120+
struct pcie_vc_resource_regs *regs,
121+
int nb_regs);
122+
123+
#endif /* ZEPHYR_DRIVERS_PCIE_HOST_VC_H_ */

0 commit comments

Comments
 (0)