Skip to content

Commit 819bcec

Browse files
donshengEddie Dong
authored andcommitted
HV: remove sharing_mode_vdev_array from sharing_mode.c
Sharing mode has its own static global variables to store number of vdevs and vdev list, we already have the per vpci pci_vdev[] in struct acrn_vpci, so use the vpci_vdev in acrn_vpci instead to unify the vdev list management for both sharing mode and partition mode. Tracked-On: #2534 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 00f9b85 commit 819bcec

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

hypervisor/dm/vpci/pci_priv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes,
7979

8080
void populate_msi_struct(struct pci_vdev *vdev);
8181

82-
struct pci_vdev *sharing_mode_find_vdev(union pci_bdf pbdf);
8382
void add_vdev_handler(struct pci_vdev *vdev, const struct pci_vdev_ops *ops);
8483

8584
#endif /* PCI_PRIV_H_ */

hypervisor/dm/vpci/sharing_mode.c

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@
3232
#include <logmsg.h>
3333
#include "pci_priv.h"
3434

35-
static uint32_t num_pci_vdev;
36-
static struct pci_vdev sharing_mode_vdev_array[CONFIG_MAX_PCI_DEV_NUM];
3735

38-
struct pci_vdev *sharing_mode_find_vdev(union pci_bdf pbdf)
36+
/**
37+
* @pre tmp != NULL
38+
*/
39+
static struct pci_vdev *sharing_mode_find_vdev(const struct acrn_vpci *vpci, union pci_bdf pbdf)
3940
{
4041
struct pci_vdev *vdev, *tmp;
4142
uint32_t i;
4243

4344
vdev = NULL;
44-
/* SOS_VM uses phys BDF */
45-
for (i = 0U; i < num_pci_vdev; i++) {
46-
tmp = &sharing_mode_vdev_array[i];
47-
if ((tmp->pdev != NULL) && bdf_is_equal((union pci_bdf*)&(tmp->pdev->bdf), &pbdf)) {
45+
for (i = 0U; i < vpci->pci_vdev_cnt; i++) {
46+
tmp = (struct pci_vdev *)&(vpci->pci_vdevs[i]);
47+
if ((tmp->pdev != NULL) && bdf_is_equal((union pci_bdf *)&(tmp->pdev->bdf), &pbdf)) {
4848
vdev = tmp;
4949
break;
5050
}
@@ -53,20 +53,39 @@ struct pci_vdev *sharing_mode_find_vdev(union pci_bdf pbdf)
5353
return vdev;
5454
}
5555

56+
/**
57+
* @pre vpci != NULL
58+
*/
59+
static struct pci_vdev *sharing_mode_find_vdev_sos(union pci_bdf pbdf)
60+
{
61+
struct acrn_vm *vm;
62+
struct acrn_vpci *vpci;
63+
struct pci_vdev *vdev = NULL;
64+
65+
vm = get_sos_vm();
66+
if (vm != NULL) {
67+
vpci = &vm->vpci;
68+
vdev = sharing_mode_find_vdev(vpci, pbdf);
69+
}
70+
71+
return vdev;
72+
}
73+
74+
5675
static void sharing_mode_cfgread(__unused struct acrn_vpci *vpci, union pci_bdf bdf,
5776
uint32_t offset, uint32_t bytes, uint32_t *val)
5877
{
5978
struct pci_vdev *vdev;
6079
bool handled = false;
6180
uint32_t i;
6281

63-
vdev = sharing_mode_find_vdev(bdf);
82+
vdev = sharing_mode_find_vdev_sos(bdf);
6483

6584
/* vdev == NULL: Could be hit for PCI enumeration from guests */
6685
if ((vdev == NULL) || ((bytes != 1U) && (bytes != 2U) && (bytes != 4U))) {
6786
*val = ~0U;
6887
} else {
69-
for (i = 0U; (i < vdev->nr_ops) && !handled; i++) {
88+
for (i = 0U; (i < vdev->nr_ops) && (!handled); i++) {
7089
if (vdev->ops[i].cfgread != NULL) {
7190
if (vdev->ops[i].cfgread(vdev, offset, bytes, val) == 0) {
7291
handled = true;
@@ -89,9 +108,9 @@ static void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf
89108
uint32_t i;
90109

91110
if ((bytes == 1U) || (bytes == 2U) || (bytes == 4U)) {
92-
vdev = sharing_mode_find_vdev(bdf);
111+
vdev = sharing_mode_find_vdev_sos(bdf);
93112
if (vdev != NULL) {
94-
for (i = 0U; (i < vdev->nr_ops) && !handled; i++) {
113+
for (i = 0U; (i < vdev->nr_ops) && (!handled); i++) {
95114
if (vdev->ops[i].cfgwrite != NULL) {
96115
if (vdev->ops[i].cfgwrite(vdev, offset, bytes, val) == 0) {
97116
handled = true;
@@ -107,20 +126,25 @@ static void sharing_mode_cfgwrite(__unused struct acrn_vpci *vpci, union pci_bdf
107126
}
108127
}
109128

129+
/**
130+
* @pre vm != NULL
131+
* @pre pdev_ref != NULL
132+
* @pre vm->vpci->pci_vdev_cnt <= CONFIG_MAX_PCI_DEV_NUM
133+
* @pre vdev != NULL
134+
*/
110135
static struct pci_vdev *alloc_pci_vdev(const struct acrn_vm *vm, struct pci_pdev *pdev_ref)
111136
{
112137
struct pci_vdev *vdev = NULL;
138+
struct acrn_vpci *vpci = (struct acrn_vpci *)&(vm->vpci);
113139

114-
if (num_pci_vdev < CONFIG_MAX_PCI_DEV_NUM) {
115-
vdev = &sharing_mode_vdev_array[num_pci_vdev];
116-
num_pci_vdev++;
140+
if (vpci->pci_vdev_cnt < CONFIG_MAX_PCI_DEV_NUM) {
141+
vdev = &vpci->pci_vdevs[vpci->pci_vdev_cnt];
142+
vpci->pci_vdev_cnt++;
117143

118-
if ((vm != NULL) && (vdev != NULL) && (pdev_ref != NULL)) {
119-
vdev->vpci = &vm->vpci;
120-
/* vbdf equals to pbdf otherwise remapped */
121-
vdev->vbdf = pdev_ref->bdf;
122-
vdev->pdev = pdev_ref;
123-
}
144+
vdev->vpci = vpci;
145+
/* vbdf equals to pbdf otherwise remapped */
146+
vdev->vbdf = pdev_ref->bdf;
147+
vdev->pdev = pdev_ref;
124148
}
125149

126150
return vdev;
@@ -137,6 +161,9 @@ static void init_vdev_for_pdev(struct pci_pdev *pdev, const void *cb_data)
137161
}
138162
}
139163

164+
/**
165+
* @pre vdev != NULL
166+
*/
140167
static int32_t sharing_mode_vpci_init(const struct acrn_vm *vm)
141168
{
142169
struct pci_vdev *vdev;
@@ -153,8 +180,8 @@ static int32_t sharing_mode_vpci_init(const struct acrn_vm *vm)
153180
/* Build up vdev array for sos_vm */
154181
pci_pdev_foreach(init_vdev_for_pdev, vm);
155182

156-
for (i = 0U; i < num_pci_vdev; i++) {
157-
vdev = &sharing_mode_vdev_array[i];
183+
for (i = 0U; i < vm->vpci.pci_vdev_cnt; i++) {
184+
vdev = (struct pci_vdev *)&(vm->vpci.pci_vdevs[i]);
158185
for (j = 0U; j < vdev->nr_ops; j++) {
159186
if (vdev->ops[j].init != NULL) {
160187
(void)vdev->ops[j].init(vdev);
@@ -167,14 +194,17 @@ static int32_t sharing_mode_vpci_init(const struct acrn_vm *vm)
167194
return ret;
168195
}
169196

170-
static void sharing_mode_vpci_deinit(__unused const struct acrn_vm *vm)
197+
/**
198+
* @pre vdev != NULL
199+
*/
200+
static void sharing_mode_vpci_deinit(const struct acrn_vm *vm)
171201
{
172202
struct pci_vdev *vdev;
173203
uint32_t i, j;
174204

175205
if (is_sos_vm(vm)) {
176-
for (i = 0U; i < num_pci_vdev; i++) {
177-
vdev = &sharing_mode_vdev_array[i];
206+
for (i = 0U; i < vm->vpci.pci_vdev_cnt; i++) {
207+
vdev = (struct pci_vdev *)&(vm->vpci.pci_vdevs[i]);
178208
for (j = 0U; j < vdev->nr_ops; j++) {
179209
if (vdev->ops[j].deinit != NULL) {
180210
(void)vdev->ops[j].deinit(vdev);
@@ -204,8 +234,10 @@ const struct vpci_ops sharing_mode_vpci_ops = {
204234
void vpci_set_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf)
205235
{
206236
struct pci_vdev *vdev;
237+
union pci_bdf bdf;
207238

208-
vdev = sharing_mode_find_vdev((union pci_bdf)pbdf);
239+
bdf.value = pbdf;
240+
vdev = sharing_mode_find_vdev_sos(bdf);
209241
if (vdev == NULL) {
210242
pr_err("%s, can't find PCI device for vm%d, vbdf (0x%x) pbdf (0x%x)", __func__,
211243
target_vm->vm_id, vbdf, pbdf);
@@ -221,8 +253,10 @@ void vpci_reset_ptdev_intr_info(const struct acrn_vm *target_vm, uint16_t vbdf,
221253
{
222254
struct pci_vdev *vdev;
223255
struct acrn_vm *vm;
256+
union pci_bdf bdf;
224257

225-
vdev = sharing_mode_find_vdev((union pci_bdf)pbdf);
258+
bdf.value = pbdf;
259+
vdev = sharing_mode_find_vdev_sos(bdf);
226260
if (vdev == NULL) {
227261
pr_err("%s, can't find PCI device for vm%d, vbdf (0x%x) pbdf (0x%x)", __func__,
228262
target_vm->vm_id, vbdf, pbdf);

0 commit comments

Comments
 (0)