Skip to content

Commit 5e6876c

Browse files
Iouri Tarassovchessturo
authored andcommitted
drivers: hv: dxgkrnl: Implement D3DDKMTIsFeatureEnabled API
D3DKMTIsFeatureEnabled is used to query if a particular feature is supported by the given adapter. Signed-off-by: Iouri Tarassov <iourit@linux.microsoft.com> [kms: forward port to 6.6 from 6.1. No code changes made.] Signed-off-by: Kelsey Steele <kelseysteele@microsoft.com>
1 parent 06e98fd commit 5e6876c

5 files changed

Lines changed: 163 additions & 5 deletions

File tree

drivers/hv/dxgkrnl/dxgkrnl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ int dxgvmb_send_share_object_with_host(struct dxgprocess *process,
994994
int dxgvmb_send_invalidate_cache(struct dxgprocess *process,
995995
struct dxgadapter *adapter,
996996
struct d3dkmt_invalidatecache *args);
997+
int dxgvmb_send_is_feature_enabled(struct dxgadapter *adapter,
998+
struct d3dkmt_isfeatureenabled *args);
997999

9981000
void signal_host_cpu_event(struct dxghostevent *eventhdr);
9991001
int ntstatus2int(struct ntstatus status);

drivers/hv/dxgkrnl/dxgvmbus.c

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ static int init_message_res(struct dxgvmbusmsgres *msg,
135135
if (use_ext_header) {
136136
msg->msg = (char *)&msg->hdr[1];
137137
msg->hdr->command_offset = sizeof(msg->hdr[0]);
138-
msg->hdr->vgpu_luid = adapter->host_vgpu_luid;
138+
if (adapter)
139+
msg->hdr->vgpu_luid = adapter->host_vgpu_luid;
139140
} else {
140141
msg->msg = (char *)msg->hdr;
141142
}
142143
msg->res = (char *)msg->hdr + msg->size;
143-
if (dxgglobal->async_msg_enabled)
144-
msg->channel = &dxgglobal->channel;
145-
else
144+
if (adapter && !dxgglobal->async_msg_enabled)
146145
msg->channel = &adapter->channel;
146+
else
147+
msg->channel = &dxgglobal->channel;
147148
return 0;
148149
}
149150

@@ -2049,6 +2050,55 @@ int dxgvmb_send_invalidate_cache(struct dxgprocess *process,
20492050
return ret;
20502051
}
20512052

2053+
int dxgvmb_send_is_feature_enabled(struct dxgadapter *adapter,
2054+
struct d3dkmt_isfeatureenabled *args)
2055+
{
2056+
int ret;
2057+
struct dxgkvmb_command_isfeatureenabled_return *result;
2058+
struct dxgvmbusmsgres msg = {.hdr = NULL};
2059+
int res_size = sizeof(*result);
2060+
2061+
if (adapter) {
2062+
struct dxgkvmb_command_isfeatureenabled *command;
2063+
2064+
ret = init_message_res(&msg, adapter, sizeof(*command),
2065+
res_size);
2066+
if (ret)
2067+
goto cleanup;
2068+
command = (void *)msg.msg;
2069+
command->feature_id = args->feature_id;
2070+
result = msg.res;
2071+
command_vgpu_to_host_init1(&command->hdr,
2072+
DXGK_VMBCOMMAND_ISFEATUREENABLED);
2073+
} else {
2074+
struct dxgkvmb_command_isfeatureenabled_gbl *command;
2075+
2076+
ret = init_message_res(&msg, adapter, sizeof(*command),
2077+
res_size);
2078+
if (ret)
2079+
goto cleanup;
2080+
command = (void *)msg.msg;
2081+
command->feature_id = args->feature_id;
2082+
result = msg.res;
2083+
command_vm_to_host_init1(&command->hdr,
2084+
DXGK_VMBCOMMAND_ISFEATUREENABLED_GLOBAL);
2085+
}
2086+
ret = dxgvmb_send_sync_msg(msg.channel, msg.hdr, msg.size,
2087+
result, res_size);
2088+
if (ret == 0) {
2089+
ret = ntstatus2int(result->status);
2090+
if (ret == 0)
2091+
args->result = result->result;
2092+
goto cleanup;
2093+
}
2094+
2095+
cleanup:
2096+
free_message((struct dxgvmbusmsg *)&msg);
2097+
if (ret)
2098+
DXG_TRACE("err: %d", ret);
2099+
return ret;
2100+
}
2101+
20522102
int dxgvmb_send_query_alloc_residency(struct dxgprocess *process,
20532103
struct dxgadapter *adapter,
20542104
struct d3dkmt_queryallocationresidency

drivers/hv/dxgkrnl/dxgvmbus.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum dxgkvmb_commandtype_global {
4848
DXGK_VMBCOMMAND_SETIOSPACEREGION = 1010,
4949
DXGK_VMBCOMMAND_COMPLETETRANSACTION = 1011,
5050
DXGK_VMBCOMMAND_SHAREOBJECTWITHHOST = 1021,
51+
DXGK_VMBCOMMAND_ISFEATUREENABLED_GLOBAL = 1022,
5152
DXGK_VMBCOMMAND_INVALID_VM_TO_HOST
5253
};
5354

@@ -126,6 +127,7 @@ enum dxgkvmb_commandtype {
126127
DXGK_VMBCOMMAND_LOGEVENT = 65,
127128
DXGK_VMBCOMMAND_SETEXISTINGSYSMEMPAGES = 66,
128129
DXGK_VMBCOMMAND_INVALIDATECACHE = 67,
130+
DXGK_VMBCOMMAND_ISFEATUREENABLED = 68,
129131
DXGK_VMBCOMMAND_INVALID
130132
};
131133

@@ -871,6 +873,35 @@ struct dxgkvmb_command_shareobjectwithhost_return {
871873
u64 vail_nt_handle;
872874
};
873875

876+
struct dxgk_feature_desc {
877+
u16 min_supported_version;
878+
u16 max_supported_version;
879+
struct {
880+
u16 supported : 1;
881+
u16 virtualization_mode : 3;
882+
u16 global : 1;
883+
u16 driver_feature : 1;
884+
u16 internal : 1;
885+
u16 reserved : 9;
886+
};
887+
};
888+
889+
struct dxgkvmb_command_isfeatureenabled {
890+
struct dxgkvmb_command_vgpu_to_host hdr;
891+
enum dxgk_feature_id feature_id;
892+
};
893+
894+
struct dxgkvmb_command_isfeatureenabled_gbl {
895+
struct dxgkvmb_command_vm_to_host hdr;
896+
enum dxgk_feature_id feature_id;
897+
};
898+
899+
struct dxgkvmb_command_isfeatureenabled_return {
900+
struct ntstatus status;
901+
struct dxgk_feature_desc descriptor;
902+
struct dxgk_isfeatureenabled_result result;
903+
};
904+
874905
int
875906
dxgvmb_send_sync_msg(struct dxgvmbuschannel *channel,
876907
void *command, u32 command_size, void *result,

drivers/hv/dxgkrnl/ioctl.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5318,6 +5318,51 @@ dxgkio_enum_processes(struct dxgprocess *process, void *__user inargs)
53185318
return ret;
53195319
}
53205320

5321+
static int
5322+
dxgkio_is_feature_enabled(struct dxgprocess *process, void *__user inargs)
5323+
{
5324+
struct d3dkmt_isfeatureenabled args;
5325+
struct dxgadapter *adapter = NULL;
5326+
struct dxgglobal *dxgglobal = dxggbl();
5327+
struct d3dkmt_isfeatureenabled *__user uargs = inargs;
5328+
int ret;
5329+
5330+
ret = copy_from_user(&args, inargs, sizeof(args));
5331+
if (ret) {
5332+
DXG_ERR("failed to copy input args");
5333+
ret = -EFAULT;
5334+
goto cleanup;
5335+
}
5336+
5337+
adapter = dxgprocess_adapter_by_handle(process, args.adapter);
5338+
if (adapter == NULL) {
5339+
ret = -EINVAL;
5340+
goto cleanup;
5341+
}
5342+
5343+
if (adapter) {
5344+
ret = dxgadapter_acquire_lock_shared(adapter);
5345+
if (ret < 0)
5346+
goto cleanup;
5347+
}
5348+
5349+
ret = dxgvmb_send_is_feature_enabled(adapter, &args);
5350+
if (ret)
5351+
goto cleanup;
5352+
5353+
ret = copy_to_user(&uargs->result, &args.result, sizeof(args.result));
5354+
5355+
cleanup:
5356+
5357+
if (adapter) {
5358+
dxgadapter_release_lock_shared(adapter);
5359+
kref_put(&adapter->adapter_kref, dxgadapter_release);
5360+
}
5361+
5362+
DXG_TRACE_IOCTL_END(ret);
5363+
return ret;
5364+
}
5365+
53215366
static struct ioctl_desc ioctls[] = {
53225367
/* 0x00 */ {},
53235368
/* 0x01 */ {dxgkio_open_adapter_from_luid, LX_DXOPENADAPTERFROMLUID},
@@ -5406,6 +5451,7 @@ static struct ioctl_desc ioctls[] = {
54065451
/* 0x47 */ {dxgkio_open_syncobj_from_syncfile,
54075452
LX_DXOPENSYNCOBJECTFROMSYNCFILE},
54085453
/* 0x48 */ {dxgkio_enum_processes, LX_DXENUMPROCESSES},
5454+
/* 0x49 */ {dxgkio_is_feature_enabled, LX_ISFEATUREENABLED},
54095455
};
54105456

54115457
/*

include/uapi/misc/d3dkmthk.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ struct d3dkmt_opensyncobjectfromsyncfile {
15801580
__u64 fence_value_gpu_va; /* out */
15811581
};
15821582

1583-
struct d3dkmt_enumprocesses {
1583+
struct d3dkmt_enumprocesses {
15841584
struct winluid adapter_luid;
15851585
#ifdef __KERNEL__
15861586
__u32 *buffer;
@@ -1590,6 +1590,33 @@ struct d3dkmt_opensyncobjectfromsyncfile {
15901590
__u64 buffer_count;
15911591
};
15921592

1593+
enum dxgk_feature_id {
1594+
_DXGK_FEATURE_HWSCH = 0,
1595+
_DXGK_FEATURE_PAGE_BASED_MEMORY_MANAGER = 32,
1596+
_DXGK_FEATURE_KERNEL_MODE_TESTING = 33,
1597+
_DXGK_FEATURE_MAX
1598+
};
1599+
1600+
struct dxgk_isfeatureenabled_result {
1601+
__u16 version;
1602+
union {
1603+
struct {
1604+
__u16 enabled : 1;
1605+
__u16 known_feature : 1;
1606+
__u16 supported_by_driver : 1;
1607+
__u16 supported_on_config : 1;
1608+
__u16 reserved : 12;
1609+
};
1610+
__u16 value;
1611+
};
1612+
};
1613+
1614+
struct d3dkmt_isfeatureenabled {
1615+
struct d3dkmthandle adapter;
1616+
enum dxgk_feature_id feature_id;
1617+
struct dxgk_isfeatureenabled_result result;
1618+
};
1619+
15931620
struct d3dkmt_invalidatecache {
15941621
struct d3dkmthandle device;
15951622
struct d3dkmthandle allocation;
@@ -1730,5 +1757,7 @@ struct d3dkmt_invalidatecache {
17301757
_IOWR(0x47, 0x47, struct d3dkmt_opensyncobjectfromsyncfile)
17311758
#define LX_DXENUMPROCESSES \
17321759
_IOWR(0x47, 0x48, struct d3dkmt_enumprocesses)
1760+
#define LX_ISFEATUREENABLED \
1761+
_IOWR(0x47, 0x49, struct d3dkmt_isfeatureenabled)
17331762

17341763
#endif /* _D3DKMTHK_H */

0 commit comments

Comments
 (0)