diff mbox

[libdrm,1/2] amdgpu: Add wrappers for AMDGPU_VM IOCTL.

Message ID 1509063355-5205-1-git-send-email-Andrey.Grodzovsky@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrey Grodzovsky Oct. 27, 2017, 12:15 a.m. UTC
Change-Id: I7eafb85c1ca96d6d255f0183bed0ce4129746fe0
Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
---
 amdgpu/Makefile.sources |  1 +
 amdgpu/amdgpu.h         | 20 +++++++++++++++++++
 amdgpu/amdgpu_vm.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 amdgpu/amdgpu_vm.c

Comments

Christian König Oct. 27, 2017, 7:44 a.m. UTC | #1
Am 27.10.2017 um 02:15 schrieb Andrey Grodzovsky:
> Change-Id: I7eafb85c1ca96d6d255f0183bed0ce4129746fe0
> Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
> ---
>   amdgpu/Makefile.sources |  1 +
>   amdgpu/amdgpu.h         | 20 +++++++++++++++++++
>   amdgpu/amdgpu_vm.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 73 insertions(+)
>   create mode 100644 amdgpu/amdgpu_vm.c
>
> diff --git a/amdgpu/Makefile.sources b/amdgpu/Makefile.sources
> index bc3abaa..498b64c 100644
> --- a/amdgpu/Makefile.sources
> +++ b/amdgpu/Makefile.sources
> @@ -6,6 +6,7 @@ LIBDRM_AMDGPU_FILES := \
>   	amdgpu_gpu_info.c \
>   	amdgpu_internal.h \
>   	amdgpu_vamgr.c \
> +	amdgpu_vm.c \
>   	util_hash.c \
>   	util_hash.h \
>   	util_hash_table.c \
> diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
> index ecc975f..07f2851 100644
> --- a/amdgpu/amdgpu.h
> +++ b/amdgpu/amdgpu.h
> @@ -1489,6 +1489,26 @@ void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
>   void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
>   					struct drm_amdgpu_cs_chunk_data *data);
>   
> +/**
> + * Reserve VMID
> + * \param   context - \c [in]  GPU Context
> + * \param   flags - \c [in]  TBD
> + *
> + * \return  0 on success otherwise POSIX Error code
> +*/
> +int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
> +								  uint32_t	flags);
> +
> +/**
> + * Free reserved VMID
> + * \param   context - \c [in]  GPU Context
> + * \param   flags - \c [in]  TBD
> + *
> + * \return  0 on success otherwise POSIX Error code
> +*/
> +int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
> +								 uint32_t	flags);
> +
>   #ifdef __cplusplus
>   }
>   #endif
> diff --git a/amdgpu/amdgpu_vm.c b/amdgpu/amdgpu_vm.c
> new file mode 100644
> index 0000000..1664b7b
> --- /dev/null
> +++ b/amdgpu/amdgpu_vm.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright 2017 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + *
> + */
> +
> +
> +#include "amdgpu.h"
> +#include "amdgpu_drm.h"
> +#include "xf86drm.h"
> +#include "amdgpu_internal.h"
> +
> +int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
> +								  uint32_t	flags)

Could just be the mail client, but flags looks way to much indented to 
the right.

Additional to that I would keep the name of the kernel IOCTL for the 
function name.

E.g. amdgpu_vm_reserve_vmid() and amdgpu_vm_unreserve_vmid().

Apart from that both patches look good to me.

Christian.

> +{
> +	union drm_amdgpu_vm vm;
> +
> +	vm.in.op = AMDGPU_VM_OP_RESERVE_VMID;
> +	vm.in.flags = flags;
> +
> +	return drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_VM,
> +							   &vm, sizeof(vm));
> +}
> +
> +int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
> +								 uint32_t	flags)
> +{
> +	union drm_amdgpu_vm vm;
> +
> +	vm.in.op = AMDGPU_VM_OP_UNRESERVE_VMID;
> +	vm.in.flags = flags;
> +
> +	return drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_VM,
> +							   &vm, sizeof(vm));
> +}
Emil Velikov Oct. 27, 2017, 8:52 a.m. UTC | #2
On 27 October 2017 at 01:15, Andrey Grodzovsky
<Andrey.Grodzovsky@amd.com> wrote:
> Change-Id: I7eafb85c1ca96d6d255f0183bed0ce4129746fe0
> Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
> ---
>  amdgpu/Makefile.sources |  1 +
>  amdgpu/amdgpu.h         | 20 +++++++++++++++++++
>  amdgpu/amdgpu_vm.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 73 insertions(+)
>  create mode 100644 amdgpu/amdgpu_vm.c
>
> diff --git a/amdgpu/Makefile.sources b/amdgpu/Makefile.sources
> index bc3abaa..498b64c 100644
> --- a/amdgpu/Makefile.sources
> +++ b/amdgpu/Makefile.sources
> @@ -6,6 +6,7 @@ LIBDRM_AMDGPU_FILES := \
>         amdgpu_gpu_info.c \
>         amdgpu_internal.h \
>         amdgpu_vamgr.c \
> +       amdgpu_vm.c \
>         util_hash.c \
>         util_hash.h \
>         util_hash_table.c \
> diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
> index ecc975f..07f2851 100644
> --- a/amdgpu/amdgpu.h
> +++ b/amdgpu/amdgpu.h
> @@ -1489,6 +1489,26 @@ void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
>  void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
>                                         struct drm_amdgpu_cs_chunk_data *data);
>
> +/**
> + * Reserve VMID
> + * \param   context - \c [in]  GPU Context
> + * \param   flags - \c [in]  TBD
> + *
> + * \return  0 on success otherwise POSIX Error code
> +*/
> +int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
> +                                                                 uint32_t      flags);
> +
> +/**
> + * Free reserved VMID
> + * \param   context - \c [in]  GPU Context
> + * \param   flags - \c [in]  TBD
> + *
> + * \return  0 on success otherwise POSIX Error code
> +*/
> +int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
> +                                                                uint32_t       flags);
> +
Andrey, don't forget to run make check. You'll see it flag a lovely error ;-)

-Emil
Andrey Grodzovsky Oct. 27, 2017, 1:55 p.m. UTC | #3
On 10/27/2017 04:52 AM, Emil Velikov wrote:
> On 27 October 2017 at 01:15, Andrey Grodzovsky
> <Andrey.Grodzovsky@amd.com> wrote:
>> Change-Id: I7eafb85c1ca96d6d255f0183bed0ce4129746fe0
>> Signed-off-by: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
>> ---
>>   amdgpu/Makefile.sources |  1 +
>>   amdgpu/amdgpu.h         | 20 +++++++++++++++++++
>>   amdgpu/amdgpu_vm.c      | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
>>   3 files changed, 73 insertions(+)
>>   create mode 100644 amdgpu/amdgpu_vm.c
>>
>> diff --git a/amdgpu/Makefile.sources b/amdgpu/Makefile.sources
>> index bc3abaa..498b64c 100644
>> --- a/amdgpu/Makefile.sources
>> +++ b/amdgpu/Makefile.sources
>> @@ -6,6 +6,7 @@ LIBDRM_AMDGPU_FILES := \
>>          amdgpu_gpu_info.c \
>>          amdgpu_internal.h \
>>          amdgpu_vamgr.c \
>> +       amdgpu_vm.c \
>>          util_hash.c \
>>          util_hash.h \
>>          util_hash_table.c \
>> diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
>> index ecc975f..07f2851 100644
>> --- a/amdgpu/amdgpu.h
>> +++ b/amdgpu/amdgpu.h
>> @@ -1489,6 +1489,26 @@ void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
>>   void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
>>                                          struct drm_amdgpu_cs_chunk_data *data);
>>
>> +/**
>> + * Reserve VMID
>> + * \param   context - \c [in]  GPU Context
>> + * \param   flags - \c [in]  TBD
>> + *
>> + * \return  0 on success otherwise POSIX Error code
>> +*/
>> +int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
>> +                                                                 uint32_t      flags);
>> +
>> +/**
>> + * Free reserved VMID
>> + * \param   context - \c [in]  GPU Context
>> + * \param   flags - \c [in]  TBD
>> + *
>> + * \return  0 on success otherwise POSIX Error code
>> +*/
>> +int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
>> +                                                                uint32_t       flags);
>> +
> Andrey, don't forget to run make check. You'll see it flag a lovely error ;-)

Thanks, didn't know about the check option, will fix.

Andrey

>
> -Emil
diff mbox

Patch

diff --git a/amdgpu/Makefile.sources b/amdgpu/Makefile.sources
index bc3abaa..498b64c 100644
--- a/amdgpu/Makefile.sources
+++ b/amdgpu/Makefile.sources
@@ -6,6 +6,7 @@  LIBDRM_AMDGPU_FILES := \
 	amdgpu_gpu_info.c \
 	amdgpu_internal.h \
 	amdgpu_vamgr.c \
+	amdgpu_vm.c \
 	util_hash.c \
 	util_hash.h \
 	util_hash_table.c \
diff --git a/amdgpu/amdgpu.h b/amdgpu/amdgpu.h
index ecc975f..07f2851 100644
--- a/amdgpu/amdgpu.h
+++ b/amdgpu/amdgpu.h
@@ -1489,6 +1489,26 @@  void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
 void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
 					struct drm_amdgpu_cs_chunk_data *data);
 
+/**
+ * Reserve VMID
+ * \param   context - \c [in]  GPU Context
+ * \param   flags - \c [in]  TBD
+ *
+ * \return  0 on success otherwise POSIX Error code
+*/
+int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
+								  uint32_t	flags);
+
+/**
+ * Free reserved VMID
+ * \param   context - \c [in]  GPU Context
+ * \param   flags - \c [in]  TBD
+ *
+ * \return  0 on success otherwise POSIX Error code
+*/
+int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
+								 uint32_t	flags);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/amdgpu/amdgpu_vm.c b/amdgpu/amdgpu_vm.c
new file mode 100644
index 0000000..1664b7b
--- /dev/null
+++ b/amdgpu/amdgpu_vm.c
@@ -0,0 +1,52 @@ 
+/*
+ * Copyright 2017 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+
+#include "amdgpu.h"
+#include "amdgpu_drm.h"
+#include "xf86drm.h"
+#include "amdgpu_internal.h"
+
+int amdgpu_vm_alloc_reserved_vmid(amdgpu_context_handle context,
+								  uint32_t	flags)
+{
+	union drm_amdgpu_vm vm;
+
+	vm.in.op = AMDGPU_VM_OP_RESERVE_VMID;
+	vm.in.flags = flags;
+
+	return drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_VM,
+							   &vm, sizeof(vm));
+}
+
+int amdgpu_vm_free_reserved_vmid(amdgpu_context_handle context,
+								 uint32_t	flags)
+{
+	union drm_amdgpu_vm vm;
+
+	vm.in.op = AMDGPU_VM_OP_UNRESERVE_VMID;
+	vm.in.flags = flags;
+
+	return drmCommandWriteRead(context->dev->fd, DRM_AMDGPU_VM,
+							   &vm, sizeof(vm));
+}