Skip to content

Commit 1aa3834

Browse files
Christoph Hellwigawilliam
authored andcommitted
drm/i915/gvt: simplify vgpu configuration management
Instead of copying the information from the vgpu_types arrays into each intel_vgpu_type structure, just reference this constant information with a pointer to the already existing data structure, and pass it into the low-level VGPU creation helpers intead of copying the data into yet anothe params data structure. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Zhenyu Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] [aw: Fold fix from [email protected]] Signed-off-by: Alex Williamson <[email protected]>
1 parent 9882895 commit 1aa3834

File tree

4 files changed

+81
-145
lines changed

4 files changed

+81
-145
lines changed

drivers/gpu/drm/i915/gvt/aperture_gm.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ static void free_resource(struct intel_vgpu *vgpu)
240240
}
241241

242242
static int alloc_resource(struct intel_vgpu *vgpu,
243-
struct intel_vgpu_creation_params *param)
243+
const struct intel_vgpu_config *conf)
244244
{
245245
struct intel_gvt *gvt = vgpu->gvt;
246246
unsigned long request, avail, max, taken;
247247
const char *item;
248248

249-
if (!param->low_gm_sz || !param->high_gm_sz || !param->fence_sz) {
249+
if (!conf->low_mm || !conf->high_mm || !conf->fence) {
250250
gvt_vgpu_err("Invalid vGPU creation params\n");
251251
return -EINVAL;
252252
}
@@ -255,7 +255,7 @@ static int alloc_resource(struct intel_vgpu *vgpu,
255255
max = gvt_aperture_sz(gvt) - HOST_LOW_GM_SIZE;
256256
taken = gvt->gm.vgpu_allocated_low_gm_size;
257257
avail = max - taken;
258-
request = MB_TO_BYTES(param->low_gm_sz);
258+
request = conf->low_mm;
259259

260260
if (request > avail)
261261
goto no_enough_resource;
@@ -266,7 +266,7 @@ static int alloc_resource(struct intel_vgpu *vgpu,
266266
max = gvt_hidden_sz(gvt) - HOST_HIGH_GM_SIZE;
267267
taken = gvt->gm.vgpu_allocated_high_gm_size;
268268
avail = max - taken;
269-
request = MB_TO_BYTES(param->high_gm_sz);
269+
request = conf->high_mm;
270270

271271
if (request > avail)
272272
goto no_enough_resource;
@@ -277,16 +277,16 @@ static int alloc_resource(struct intel_vgpu *vgpu,
277277
max = gvt_fence_sz(gvt) - HOST_FENCE;
278278
taken = gvt->fence.vgpu_allocated_fence_num;
279279
avail = max - taken;
280-
request = param->fence_sz;
280+
request = conf->fence;
281281

282282
if (request > avail)
283283
goto no_enough_resource;
284284

285285
vgpu_fence_sz(vgpu) = request;
286286

287-
gvt->gm.vgpu_allocated_low_gm_size += MB_TO_BYTES(param->low_gm_sz);
288-
gvt->gm.vgpu_allocated_high_gm_size += MB_TO_BYTES(param->high_gm_sz);
289-
gvt->fence.vgpu_allocated_fence_num += param->fence_sz;
287+
gvt->gm.vgpu_allocated_low_gm_size += conf->low_mm;
288+
gvt->gm.vgpu_allocated_high_gm_size += conf->high_mm;
289+
gvt->fence.vgpu_allocated_fence_num += conf->fence;
290290
return 0;
291291

292292
no_enough_resource:
@@ -340,11 +340,11 @@ void intel_vgpu_reset_resource(struct intel_vgpu *vgpu)
340340
*
341341
*/
342342
int intel_vgpu_alloc_resource(struct intel_vgpu *vgpu,
343-
struct intel_vgpu_creation_params *param)
343+
const struct intel_vgpu_config *conf)
344344
{
345345
int ret;
346346

347-
ret = alloc_resource(vgpu, param);
347+
ret = alloc_resource(vgpu, conf);
348348
if (ret)
349349
return ret;
350350

drivers/gpu/drm/i915/gvt/gvt.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,26 @@ struct intel_gvt_firmware {
294294
bool firmware_loaded;
295295
};
296296

297+
struct intel_vgpu_config {
298+
unsigned int low_mm;
299+
unsigned int high_mm;
300+
unsigned int fence;
301+
302+
/*
303+
* A vGPU with a weight of 8 will get twice as much GPU as a vGPU with
304+
* a weight of 4 on a contended host, different vGPU type has different
305+
* weight set. Legal weights range from 1 to 16.
306+
*/
307+
unsigned int weight;
308+
enum intel_vgpu_edid edid;
309+
const char *name;
310+
};
311+
297312
#define NR_MAX_INTEL_VGPU_TYPES 20
298313
struct intel_vgpu_type {
299314
char name[16];
315+
const struct intel_vgpu_config *conf;
300316
unsigned int avail_instance;
301-
unsigned int low_gm_size;
302-
unsigned int high_gm_size;
303-
unsigned int fence;
304-
unsigned int weight;
305-
enum intel_vgpu_edid resolution;
306317
};
307318

308319
struct intel_gvt {
@@ -436,19 +447,8 @@ int intel_gvt_load_firmware(struct intel_gvt *gvt);
436447
/* ring context size i.e. the first 0x50 dwords*/
437448
#define RING_CTX_SIZE 320
438449

439-
struct intel_vgpu_creation_params {
440-
__u64 low_gm_sz; /* in MB */
441-
__u64 high_gm_sz; /* in MB */
442-
__u64 fence_sz;
443-
__u64 resolution;
444-
__s32 primary;
445-
__u64 vgpu_id;
446-
447-
__u32 weight;
448-
};
449-
450450
int intel_vgpu_alloc_resource(struct intel_vgpu *vgpu,
451-
struct intel_vgpu_creation_params *param);
451+
const struct intel_vgpu_config *conf);
452452
void intel_vgpu_reset_resource(struct intel_vgpu *vgpu);
453453
void intel_vgpu_free_resource(struct intel_vgpu *vgpu);
454454
void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
@@ -494,7 +494,8 @@ void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
494494

495495
struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
496496
void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
497-
int intel_gvt_create_vgpu(struct intel_vgpu *vgpu, struct intel_vgpu_type *type);
497+
int intel_gvt_create_vgpu(struct intel_vgpu *vgpu,
498+
const struct intel_vgpu_config *conf);
498499
void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
499500
void intel_gvt_release_vgpu(struct intel_vgpu *vgpu);
500501
void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,

drivers/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ static ssize_t description_show(struct mdev_type *mtype,
151151
return sprintf(buf, "low_gm_size: %dMB\nhigh_gm_size: %dMB\n"
152152
"fence: %d\nresolution: %s\n"
153153
"weight: %d\n",
154-
BYTES_TO_MB(type->low_gm_size),
155-
BYTES_TO_MB(type->high_gm_size),
156-
type->fence, vgpu_edid_str(type->resolution),
157-
type->weight);
154+
BYTES_TO_MB(type->conf->low_mm),
155+
BYTES_TO_MB(type->conf->high_mm),
156+
type->conf->fence, vgpu_edid_str(type->conf->edid),
157+
type->conf->weight);
158158
}
159159

160160
static ssize_t name_show(struct mdev_type *mtype,
@@ -1559,7 +1559,7 @@ static int intel_vgpu_init_dev(struct vfio_device *vfio_dev)
15591559
return -EINVAL;
15601560

15611561
vgpu->gvt = gvt;
1562-
return intel_gvt_create_vgpu(vgpu, type);
1562+
return intel_gvt_create_vgpu(vgpu, type->conf);
15631563
}
15641564

15651565
static void intel_vgpu_release_dev(struct vfio_device *vfio_dev)

0 commit comments

Comments
 (0)