<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">NAK on that whole approach. We
previously had similar handling in radeon for the temporary IB
buffer and it was a pain to support correctly.<br>
<br>
The main problem is that you might then have a mismatch between
the housekeeping structures in the VM and what is really in the
page tables / page directory.<br>
<br>
Additional a concrete problem is that you simply assume that the
PD and PTs are present when the VM is created, but that might not
be correct under memory pressure. In this case the code below will
just fail miserable.<br>
<br>
I suggest that you go a step back and fully implement the support
for the CSA for each context and not just a quick hack like this.
If I remember our internal discussion correctly Monk already had
promising locking patches for this for the general preemption
support.<br>
<br>
Regards,<br>
Christian.<br>
<br>
Am 20.12.2016 um 06:43 schrieb Yu, Xiangliang:<br>
</div>
<blockquote
cite="mid:CY4PR12MB1701351D6DCEA18714735B3DEB900@CY4PR12MB1701.namprd12.prod.outlook.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
<style><!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:宋体;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:宋体;}
p.emailquote, li.emailquote, div.emailquote
{mso-style-name:emailquote;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:1.0pt;
margin-bottom:.0001pt;
border:none;
padding:0in;
font-size:12.0pt;
font-family:宋体;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thank
monk’s detail expanation.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">And
I think this patch is only support virtualization world
switch, not touch whole amdpgu preemption.
<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks!<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Xiangliang
Yu<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in
0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">
Liu, Monk
<br>
<b>Sent:</b> Tuesday, December 20, 2016 11:58 AM<br>
<b>To:</b> Alex Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexdeucher@gmail.com"><alexdeucher@gmail.com></a>;
Yu, Xiangliang <a class="moz-txt-link-rfc2396E" href="mailto:Xiangliang.Yu@amd.com"><Xiangliang.Yu@amd.com></a><br>
<b>Cc:</b> amd-gfx list
<a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a>;
dl.SRDC_SW_GPUVirtualization
<a class="moz-txt-link-rfc2396E" href="mailto:dl.SRDC_SW_GPUVirtualization@amd.com"><dl.SRDC_SW_GPUVirtualization@amd.com></a><br>
<b>Subject:</b> </span><span style="font-size:11.0pt"
lang="ZH-CN">答复</span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">:
[PATCH 11/23] drm/amdgpu: implement context save
area(CSA) feature<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div id="x_divtagdefaultwrapper">
<p><span
style="font-family:"Calibri",sans-serif;color:black">the
CSA is used for world switch, and each amdgpu device
should have one and only one CSA,<o:p></o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black">and
this CSA will pined, and mapped to each virtual memory
/process.<o:p></o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black">CP/RLCV
will use this CSA buffer when preemption occurred, and
will write some hardware status into this CSA buffer,
within the current IB's context (that's why need do
mapping for each virtual memory on CSA)<o:p></o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black"><o:p> </o:p></span></p>
<p><span
style="font-family:"Calibri",sans-serif;color:black">BR
Monk<o:p></o:p></span></p>
</div>
<div class="MsoNormal" style="text-align:center"
align="center">
<hr width="98%" align="center" size="2">
</div>
<div id="x_divRplyFwdMsg">
<p class="MsoNormal"><b><span
style="font-size:11.0pt;color:black" lang="ZH-CN">发件人</span></b><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
Alex Deucher <<a moz-do-not-send="true"
href="mailto:alexdeucher@gmail.com">alexdeucher@gmail.com</a>><br>
</span><b><span style="font-size:11.0pt;color:black"
lang="ZH-CN">发送时间</span></b><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
2016</span><span style="font-size:11.0pt;color:black"
lang="ZH-CN">年</span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">12</span><span
style="font-size:11.0pt;color:black" lang="ZH-CN">月</span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">20</span><span
style="font-size:11.0pt;color:black" lang="ZH-CN">日</span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
7:20:09<br>
</span><b><span style="font-size:11.0pt;color:black"
lang="ZH-CN">收件人</span></b><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
Yu, Xiangliang<br>
</span><b><span style="font-size:11.0pt;color:black"
lang="ZH-CN">抄送</span></b><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
amd-gfx list; dl.SRDC_SW_GPUVirtualization; Liu, Monk<br>
</span><b><span style="font-size:11.0pt;color:black"
lang="ZH-CN">主题</span></b><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">
Re: [PATCH 11/23] drm/amdgpu: implement context save
area(CSA) feature</span> <o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">On Sat,
Dec 17, 2016 at 11:16 AM, Xiangliang Yu <<a
moz-do-not-send="true"
href="mailto:Xiangliang.Yu@amd.com"><a class="moz-txt-link-abbreviated" href="mailto:Xiangliang.Yu@amd.com">Xiangliang.Yu@amd.com</a></a>>
wrote:<br>
> CSA is need by world switch. This patch implement
CSA feature and<br>
> bind it to each VM, so hardware can save the state
into the area<br>
> and restore it when running again.<br>
><br>
> Signed-off-by: Monk Liu <<a
moz-do-not-send="true" href="mailto:Monk.Liu@amd.com"><a class="moz-txt-link-abbreviated" href="mailto:Monk.Liu@amd.com">Monk.Liu@amd.com</a></a>><br>
> Signed-off-by: Xiangliang Yu <<a
moz-do-not-send="true"
href="mailto:Xiangliang.Yu@amd.com"><a class="moz-txt-link-abbreviated" href="mailto:Xiangliang.Yu@amd.com">Xiangliang.Yu@amd.com</a></a>><br>
<br>
Isn't the CSA actually for preemption? Preemption is
useful outside<br>
of the VF case as well so it should be untangled from
the mxgpu code<br>
so it can be utilized independently.<br>
<br>
Alex<br>
<br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h | 14 +++<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 +<br>
> drivers/gpu/drm/amd/mxgpu/amd_mxgpu.h | 12 ++<br>
> drivers/gpu/drm/amd/mxgpu/mxgpu_csa.c | 209
+++++++++++++++++++++++++++++++<br>
> 5 files changed, 247 insertions(+)<br>
> create mode 100644
drivers/gpu/drm/amd/mxgpu/mxgpu_csa.c<br>
><br>
> diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
> index 8ee70f8..dff1248 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h<br>
> @@ -24,6 +24,8 @@<br>
> #ifndef AMDGPU_VIRT_H<br>
> #define AMDGPU_VIRT_H<br>
><br>
> +struct amdgpu_vm;<br>
> +<br>
> #define AMDGPU_SRIOV_CAPS_SRIOV_VBIOS (1 <<
0) /* vBIOS is sr-iov ready */<br>
> #define AMDGPU_SRIOV_CAPS_ENABLE_IOV (1 <<
1) /* sr-iov is enabled on this GPU */<br>
> #define AMDGPU_SRIOV_CAPS_IS_VF (1 <<
2) /* this GPU is a virtual function */<br>
> @@ -33,6 +35,14 @@ struct amdgpu_virtualization {<br>
> uint32_t virtual_caps;<br>
> };<br>
><br>
> +struct amdgpu_csa {<br>
> + struct amdgpu_bo_va *va;<br>
> + struct ttm_validate_buffer tv;<br>
> + uint64_t
reserved_top;<br>
> + uint64_t csa_addr;<br>
> + uint64_t gds_addr;<br>
> +};<br>
> +<br>
> #define amdgpu_sriov_enabled(adev) \<br>
> ((adev)->virtualization.virtual_caps &
AMDGPU_SRIOV_CAPS_ENABLE_IOV)<br>
><br>
> @@ -55,4 +65,8 @@ static inline bool
is_virtual_machine(void)<br>
> }<br>
><br>
> int amd_xgpu_set_ip_blocks(struct amdgpu_device
*adev);<br>
> +<br>
> +/* Context Save Area functions */<br>
> +int amdgpu_vm_map_csa(struct amdgpu_device *adev,
struct amdgpu_vm *vm);<br>
> +void amdgpu_vm_unmap_csa(struct amdgpu_device
*adev, struct amdgpu_vm *vm);<br>
> #endif<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> index d05546e..98540d9 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
> @@ -1539,6 +1539,8 @@ int amdgpu_vm_init(struct
amdgpu_device *adev, struct amdgpu_vm *vm)<br>
> pd_size = amdgpu_vm_directory_size(adev);<br>
> pd_entries = amdgpu_vm_num_pdes(adev);<br>
><br>
> + vm->csa.reserved_top =
AMDGPU_VA_RESERVED_SIZE;<br>
> +<br>
> /* allocate page table array */<br>
> vm->page_tables =
drm_calloc_large(pd_entries, sizeof(struct
amdgpu_vm_pt));<br>
> if (vm->page_tables == NULL) {<br>
> @@ -1576,6 +1578,10 @@ int amdgpu_vm_init(struct
amdgpu_device *adev, struct amdgpu_vm *vm)<br>
> vm->last_eviction_counter =
atomic64_read(&adev->num_evictions);<br>
> amdgpu_bo_unreserve(vm->page_directory);<br>
><br>
> + r = amdgpu_vm_map_csa(adev, vm);<br>
> + if (r)<br>
> + goto error_free_page_directory;<br>
> +<br>
> return 0;<br>
><br>
> error_free_page_directory:<br>
> @@ -1606,6 +1612,8 @@ void amdgpu_vm_fini(struct
amdgpu_device *adev, struct amdgpu_vm *vm)<br>
> struct amdgpu_bo_va_mapping *mapping, *tmp;<br>
> int i;<br>
><br>
> + amdgpu_vm_unmap_csa(adev, vm);<br>
> +<br>
> amd_sched_entity_fini(vm->entity.sched,
&vm->entity);<br>
><br>
> if (!RB_EMPTY_ROOT(&vm->va)) {<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h<br>
> index 42a629b..d90630a 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h<br>
> @@ -29,6 +29,7 @@<br>
> #include "gpu_scheduler.h"<br>
> #include "amdgpu_sync.h"<br>
> #include "amdgpu_ring.h"<br>
> +#include "amdgpu_virt.h"<br>
><br>
> struct amdgpu_bo_va;<br>
> struct amdgpu_job;<br>
> @@ -109,6 +110,9 @@ struct amdgpu_vm {<br>
> /* Scheduler entity for page table updates
*/<br>
> struct amd_sched_entity entity;<br>
><br>
> + /* Context Save Area */<br>
> + struct amdgpu_csa csa;<br>
> +<br>
> /* client id */<br>
> u64 client_id;<br>
> };<br>
> diff --git a/drivers/gpu/drm/amd/mxgpu/amd_mxgpu.h
b/drivers/gpu/drm/amd/mxgpu/amd_mxgpu.h<br>
> index 6ab13bc..a25e07f 100644<br>
> --- a/drivers/gpu/drm/amd/mxgpu/amd_mxgpu.h<br>
> +++ b/drivers/gpu/drm/amd/mxgpu/amd_mxgpu.h<br>
> @@ -26,12 +26,24 @@<br>
><br>
> #include "amdgpu.h"<br>
><br>
> +/* xgpu structures */<br>
> +struct amd_xgpu_csa {<br>
> + struct amdgpu_bo *robj;<br>
> + uint64_t gpu_addr;<br>
> + uint64_t gds_addr;<br>
> + int32_t size;<br>
> +};<br>
> +<br>
> struct amd_xgpu {<br>
> struct amdgpu_device *adev;<br>
> struct mutex lock;<br>
> + struct amd_xgpu_csa sa;<br>
> u32 reg_val_offs;<br>
> };<br>
><br>
> extern int amd_xgpu_alloc(struct amdgpu_device
*adev);<br>
> extern void amd_xgpu_free(struct amd_xgpu *xgpu);<br>
> +<br>
> +extern int xgpu_allocate_csa(struct amd_xgpu
*xgpu);<br>
> +extern void xgpu_destroy_csa(struct amd_xgpu_csa
*csa);<br>
> #endif<br>
> diff --git a/drivers/gpu/drm/amd/mxgpu/mxgpu_csa.c
b/drivers/gpu/drm/amd/mxgpu/mxgpu_csa.c<br>
> new file mode 100644<br>
> index 0000000..246a747<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/amd/mxgpu/mxgpu_csa.c<br>
> @@ -0,0 +1,209 @@<br>
> +/*<br>
> + * Copyright 2016 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge,
to any person obtaining a<br>
> + * copy of this software and associated
documentation files (the "Software"),<br>
> + * to deal in the Software without restriction,
including without limitation<br>
> + * the rights to use, copy, modify, merge,
publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to
permit persons to whom the<br>
> + * Software is furnished to do so, subject to the
following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission
notice shall be included in<br>
> + * all copies or substantial portions of the
Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE
FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors: <a moz-do-not-send="true"
href="mailto:Xiangliang.Yu@amd.com">Xiangliang.Yu@amd.com</a><br>
> + * <a moz-do-not-send="true"
href="mailto:Monk.Liu@amd.com">Monk.Liu@amd.com</a><br>
> + *<br>
> + */<br>
> +#include "amd_mxgpu.h"<br>
> +#include "vid.h"<br>
> +<br>
> +static int xgpu_init_csa(struct amdgpu_device
*adev, struct amd_xgpu_csa *sa)<br>
> +{<br>
> + int r, size;<br>
> + void *ptr;<br>
> +<br>
> + /* meta data (4k) + gds-gfx (4k)*/<br>
> + size = PAGE_SIZE +
adev->gds.mem.gfx_partition_size;<br>
> +<br>
> + r = amdgpu_bo_create(adev, size, PAGE_SIZE,
true,<br>
> + AMDGPU_GEM_DOMAIN_GTT,<br>
> +
AMDGPU_GEM_CREATE_CPU_GTT_USWC,<br>
> + NULL, NULL,
&sa->robj);<br>
> + if (r) {<br>
> + dev_err(adev->dev, "(%d) failed
to allocate csa bo\n", r);<br>
> + return r;<br>
> + }<br>
> +<br>
> + r = amdgpu_bo_reserve(sa->robj, true);<br>
> + if (unlikely(r != 0))<br>
> + goto error_free;<br>
> +<br>
> + r = amdgpu_bo_pin(sa->robj,
AMDGPU_GEM_DOMAIN_GTT, &sa->gpu_addr);<br>
> + if (r)<br>
> + goto error_unreserve;<br>
> +<br>
> + r = amdgpu_bo_kmap(sa->robj, &ptr);<br>
> + if (r)<br>
> + goto error_unpin;<br>
> +<br>
> + memset(ptr, 0, size);<br>
> + amdgpu_bo_unreserve(sa->robj);<br>
> +<br>
> + sa->size = size;<br>
> + sa->gds_addr = sa->gpu_addr +
PAGE_SIZE;<br>
> +<br>
> + return 0;<br>
> +<br>
> +error_unpin:<br>
> + amdgpu_bo_unpin(sa->robj);<br>
> +error_unreserve:<br>
> + amdgpu_bo_unreserve(sa->robj);<br>
> +error_free:<br>
> + amdgpu_bo_unref(&sa->robj);<br>
> + return r;<br>
> +}<br>
> +<br>
> +int xgpu_allocate_csa(struct amd_xgpu *xgpu)<br>
> +{<br>
> + struct amdgpu_device *adev = xgpu->adev;<br>
> + struct amd_xgpu_csa *sa = &xgpu->sa;<br>
> +<br>
> + return xgpu_init_csa(adev, sa);<br>
> +}<br>
> +<br>
> +void xgpu_destroy_csa(struct amd_xgpu_csa *sa)<br>
> +{<br>
> + amdgpu_bo_reserve(sa->robj, true);<br>
> + amdgpu_bo_unpin(sa->robj);<br>
> + amdgpu_bo_unreserve(sa->robj);<br>
> + amdgpu_bo_unref(&sa->robj);<br>
> + sa->gpu_addr = 0;<br>
> + sa->gds_addr = 0;<br>
> +}<br>
> +<br>
> +static int xgpu_vm_map_csa(struct amdgpu_device
*adev, struct amdgpu_vm *vm,<br>
> + struct amd_xgpu_csa *sa)<br>
> +{<br>
> + int r;<br>
> + uint64_t vaddr;<br>
> + struct ww_acquire_ctx ticket;<br>
> + struct list_head list, duplicates;<br>
> + struct amdgpu_bo_list_entry pd;<br>
> + struct amdgpu_bo_va *bo_va;<br>
> +<br>
> + INIT_LIST_HEAD(&list);<br>
> + INIT_LIST_HEAD(&duplicates);<br>
> + INIT_LIST_HEAD(&vm->csa.tv.head);<br>
> + vm->csa.tv.bo =
&sa->robj->tbo;<br>
> + vm->csa.tv.shared = true;<br>
> +<br>
> + list_add(&vm->csa.tv.head,
&list);<br>
> + amdgpu_vm_get_pd_bo(vm, &list,
&pd);<br>
> +<br>
> + spin_lock(&vm->status_lock);<br>
> + vm->csa.reserved_top -= sa->size;<br>
> + vaddr = vm->csa.reserved_top;<br>
> + spin_unlock(&vm->status_lock);<br>
> +<br>
> + r = ttm_eu_reserve_buffers(&ticket,
&list, true, &duplicates);<br>
> + if (r) {<br>
> + DRM_ERROR("failed to reserve global
CSA buffer(%d).\n", r);<br>
> + return r;<br>
> + }<br>
> +<br>
> + bo_va = amdgpu_vm_bo_add(adev, vm,
sa->robj);<br>
> + if (!bo_va) {<br>
> + DRM_ERROR("failed to create bo_va
for global CSA buffer.\n");<br>
> + return -ENOMEM;<br>
> + }<br>
> +<br>
> +<br>
> + r = amdgpu_vm_bo_map(adev, bo_va, vaddr, 0,
sa->size,<br>
> + AMDGPU_PTE_READABLE |
AMDGPU_PTE_WRITEABLE |<br>
> +
AMDGPU_PTE_EXECUTABLE);<br>
> + if (r) {<br>
> + DRM_ERROR("failed to do bo_map on
global CSA buffer(%d).\n", r);<br>
> + amdgpu_vm_bo_rmv(adev, bo_va);<br>
> +
ttm_eu_backoff_reservation(&ticket, &list);<br>
> + kfree(bo_va);<br>
> + return r;<br>
> + }<br>
> +<br>
> + ttm_eu_backoff_reservation(&ticket,
&list);<br>
> + amdgpu_gem_va_update_vm(adev, bo_va,
AMDGPU_VA_OP_MAP);<br>
> +<br>
> + vm->csa.va = bo_va;<br>
> + vm->csa.csa_addr = vaddr;<br>
> + vm->csa.gds_addr = vaddr + PAGE_SIZE;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +int amdgpu_vm_map_csa(struct amdgpu_device *adev,
struct amdgpu_vm *vm)<br>
> +{<br>
> + struct amd_xgpu *xgpu = (struct amd_xgpu
*)adev->priv_data;<br>
> + struct amd_xgpu_csa *sa = NULL;<br>
> +<br>
> + if (!xgpu)<br>
> + return 0;<br>
> +<br>
> + sa = &xgpu->sa;<br>
> +<br>
> + return xgpu_vm_map_csa(adev, vm, sa);<br>
> +}<br>
> +<br>
> +static void xgpu_vm_unmap_csa(struct amdgpu_device
*adev, struct amdgpu_vm *vm,<br>
> + struct amd_xgpu_csa
*sa)<br>
> +{<br>
> + int r;<br>
> + struct ww_acquire_ctx ticket;<br>
> + struct list_head list, duplicates;<br>
> + struct amdgpu_bo_list_entry pd;<br>
> +<br>
> + if (!vm->csa.va)<br>
> + return;<br>
> +<br>
> + INIT_LIST_HEAD(&list);<br>
> + INIT_LIST_HEAD(&duplicates);<br>
> + list_add(&vm->csa.tv.head,
&list);<br>
> + amdgpu_vm_get_pd_bo(vm, &list,
&pd);<br>
> +<br>
> + r = ttm_eu_reserve_buffers(&ticket,
&list, true, &duplicates);<br>
> + if (r) {<br>
> + DRM_ERROR("failed to reserve global
CSA buffer(%d).\n", r);<br>
> + return;<br>
> + }<br>
> +<br>
> + amdgpu_vm_bo_rmv(adev, vm->csa.va);<br>
> + /* maybe we don't need to do real clearing
for the vm will die soon */<br>
> + r = amdgpu_vm_clear_freed(adev, vm);<br>
> + if (r) {<br>
> + DRM_ERROR("failed to clear global
CSA bo(%d).\n", r);<br>
> + return;<br>
> + }<br>
> +<br>
> + ttm_eu_backoff_reservation(&ticket,
&list);<br>
> + vm->csa.va = NULL;<br>
> + vm->csa.csa_addr = vm->csa.gds_addr =
0;<br>
> +}<br>
> +<br>
> +void amdgpu_vm_unmap_csa(struct amdgpu_device
*adev, struct amdgpu_vm *vm)<br>
> +{<br>
> + struct amd_xgpu *xgpu = (struct amd_xgpu
*)adev->priv_data;<br>
> + struct amd_xgpu_csa *sa = NULL;<br>
> +<br>
> + if (!xgpu)<br>
> + return;<br>
> +<br>
> + sa = &xgpu->sa;<br>
> + xgpu_vm_unmap_csa(adev, vm, sa);<br>
> +}<br>
> --<br>
> 2.7.4<br>
><br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> <a moz-do-not-send="true"
href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
> <a moz-do-not-send="true"
href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><o:p></o:p></span></p>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
amd-gfx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>