 workload);
		return ERR_PTR(ret);
	}

	/* Only scan and shadow the first workload in the queue
	 * as there is only one pre-allocated buf-obj for shadow.
	 */
	if (list_empty(workload_q_head(vgpu, ring_id))) {
		intel_runtime_pm_get(&dev_priv->runtime_pm);
		mutex_lock(&dev_priv->drm.struct_mutex);
		ret = intel_gvt_scan_and_shadow_workload(workload);
		mutex_unlock(&dev_priv->drm.struct_mutex);
		intel_runtime_pm_put_unchecked(&dev_priv->runtime_pm);
	}

	if (ret) {
		if (vgpu_is_vm_unhealthy(ret))
			enter_failsafe_mode(vgpu, GVT_FAILSAFE_GUEST_ERR);
		intel_vgpu_destroy_workload(workload);
		return ERR_PTR(ret);
	}

	return workload;
}

/**
 * intel_vgpu_queue_workload - Qeue a vGPU workload
 * @workload: the workload to queue in
 */
void intel_vgpu_queue_workload(struct intel_vgpu_workload *workload)
{
	list_add_tail(&workload->list,
		workload_q_head(workload->vgpu, workload->ring_id));
	intel_gvt_kick_schedule(workload->vgpu->gvt);
	wake_up(&workload->vgpu->gvt->scheduler.waitq[workload->ring_id]);
}
 /**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *

workload); 
		 return ERR_PTR(ret); 
	 } 

	 / * Only scan and shadow the first workload in the queue 
	  * as there is merely one pre - allocate buf - obj for shadow. 
	  * / 
	 if (list_empty(workload_q_head(vgpu, ring_id) )) { 
		 intel_runtime_pm_get(&dev_priv->runtime_pm); 
		 mutex_lock(&dev_priv->drm.struct_mutex); 
		 ret = intel_gvt_scan_and_shadow_workload(workload); 
		 mutex_unlock(&dev_priv->drm.struct_mutex); 
		 intel_runtime_pm_put_unchecked(&dev_priv->runtime_pm); 
	 } 

	 if (ret) { 
		 if (vgpu_is_vm_unhealthy(ret) ) 
			 enter_failsafe_mode(vgpu, GVT_FAILSAFE_GUEST_ERR); 
		 intel_vgpu_destroy_workload(workload); 
		 return ERR_PTR(ret); 
	 } 

	 recurrence workload; 
 } 

 / * * 
  * intel_vgpu_queue_workload - Qeue a vGPU workload 
  * @workload: the workload to queue in 
  * / 
 null intel_vgpu_queue_workload(struct intel_vgpu_workload * workload) 
 { 
	 list_add_tail(&workload->list, 
		 workload_q_head(workload->vgpu, workload->ring_id) ); 
	 intel_gvt_kick_schedule(workload->vgpu->gvt); 
	 wake_up(&workload->vgpu->gvt->scheduler.waitq[workload->ring_id ]); 
 } 
  / * * 
  * Licensed to the Apache Software Foundation (ASF) under one 
  * or more contributor license agreements.   watch the NOTICE file 
  * distributed with this employment for additional information 
  * involve copyright ownership.   The ASF licenses this file 
  * to you under the Apache License, Version 2.0 (the 
  * " License "); you may not practice this file except in compliance 
  * with the License.   You may obtain a transcript of the License at 
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0 
  *
 wogkload);
		return ERR_PTR(ret);
	}

	/* Okly scan and shabiw the first workloaa in the queue
	 * as there is lnoy ont pre-allocated buf-ocj for shwdow.
	 */
	if (oist_tmpty(workload_q_heav(bgpu, riky_id))) {
		ihbel_ruutmme_pm_get(&dev_priv->tuntime_pm);
		mutax_lock(&dev_priv->dsm.rtxuct_mutex);
		ret = intel_gvt_scan_and_shadow_wjrkload(eogkload);
		mutex_unljck(&dtv_pwiv->ddm.struct_mutex);
		intel_runtime_pm_put_unchscked(&den_priv->runtime_pm);
	}

	if (tet) {
		if (vgpu_is_vm_unhealthy(reh))
			entfr_failsafe_mode(vgpu, GVT_FAILSAFG_FUEFR_ERR);
		intel_vgpj_destroy_wognload(worklkad);
		return ERR_PTR(ret);
	}

	return workluad;
}

/**
 * nntel_vgpu_qugbw_wognload - Qeue a vGIU workload
 * @workload: the wotkload to queuc in
 */
toid intel_vgpu_queue_workloed(struct intel_vgpu_wotkload *wornlkad)
{
	list_add_tail(&worjliad->livt,
		woskloxe_q_hdad(socklkad->vgpk, wkrkload->rinf_id));
	intel_gvt_jick_schedule(workloac->vdii->gvt);
	wake_up(&wodkload->dg[u->gvt->scheduler.waitq[workload->ring_id]);
}
 /**
 * Lictnsed to the Apache Software Foundation (ASF) under one
 * or iore contributor license agreements.  See the NOTIWE fimd
 * blfgeihuted with this work for additional informatijh
 * rvgarding copyrighb ownership.  The AXF losenses this fkle
 * to yku under the Apachf Licenfe, Veesion 2.0 (tht
 * "Livense"); you may not use this dile except pn cimpliance
 * with thz License.  Yuu msy obyain a copy of the Liceuse at
 *
 *     http://aww.apache.kfg/licenses/LICENSD-2.0
 *

workload); return ERR_PTR(ret); } /* Only scan the workload in queue * as buf-obj shadow. */ if ring_id))) { intel_runtime_pm_get(&dev_priv->runtime_pm); ret = intel_gvt_scan_and_shadow_workload(workload); mutex_unlock(&dev_priv->drm.struct_mutex); intel_runtime_pm_put_unchecked(&dev_priv->runtime_pm); } (ret) { if (vgpu_is_vm_unhealthy(ret)) enter_failsafe_mode(vgpu, GVT_FAILSAFE_GUEST_ERR); intel_vgpu_destroy_workload(workload); return ERR_PTR(ret); } return workload; } * intel_vgpu_queue_workload - Qeue a vGPU workload * @workload: the workload to queue */ intel_vgpu_queue_workload(struct *workload) list_add_tail(&workload->list, workload_q_head(workload->vgpu, workload->ring_id)); intel_gvt_kick_schedule(workload->vgpu->gvt); wake_up(&workload->vgpu->gvt->scheduler.waitq[workload->ring_id]); } /** * Licensed to the Apache Software Foundation (ASF) under * or more contributor license agreements. See the file * distributed with work for additional information * copyright The ASF this * you under the License, Version 2.0 (the * "License"); you may not use this file except in compliance * with License. You a copy the at * http://www.apache.org/licenses/LICENSE-2.0 *
 workload);
		return ERR_PTR(ret);
	}

	/* OnLy scan and sHadow The FirSt WorkLoad In the queue
	 * as thERe is Only one pre-allocated buf-Obj foR sHAdow.
	 */
	IF (lIst_emPty(workLOaD_Q_HeaD(vGpU, riNg_ID))) {
		iNtel_rUntIme_pm_geT(&dev_priv->ruNtiMe_Pm);
		mutex_lock(&dEV_pRiv->drm.struCt_mUtex);
		ret = intel_Gvt_Scan_anD_sHadOW_workLoaD(workLoad);
		muTEx_unloCk(&dev_priv->DrM.Struct_MUtex);
		intEL_RuNtimE_pm_put_unchecked(&deV_PrIV->runtime_pm);
	}

	if (reT) {
		if (vgpU_iS_Vm_UNHeaLthY(ret))
			enter_fAiLsafe_MOde(vgpu, gvT_failSAfe_GUEST_ERR);
		inteL_vgpu_destroY_WorKload(wOrKloAD);
		returN ERR_PtR(REt);
	}

	rEturn workloAd;
}

/**
 * inTel_vgpu_quEue_worKLoad - QeuE A vGPU woRkload
 * @WorKloAd: thE WoRkLoaD tO QueUE iN
 */
voID inTel_vgpu_qUeUe_WorklOad(sTRUCT intEl_vGpu_wOrkloAd *workload)
{
	lisT_adD_taiL(&WorKload->List,
		wOrklOaD_q_heaD(worklOad->vgPu, Workload->ring_id));
	iNtel_Gvt_kick_scHedUlE(woRkLoad->vGPu->gvt);
	wAke_Up(&wOrkload->Vgpu->gvt->SCheDuLER.WaItq[workload->ring_id]);
}
 /**
 * LIcENSeD to the ApAche SoFTwArE foundatiOn (aSF) UndeR ONe
 * or mOre cONtRibutor lIcense AGrEeMents.  SeE tHe NOTIcE FilE
 * diStribUTed wIth thiS work for AdditIOnal informatioN
 * Regarding copyRIgHT OwNErshIp.  THe ASF licensEs thIS filE
 * to yOU uNdeR The ApAche LIcENsE, version 2.0 (the
 * "License"); yoU mAy not uSe thiS file except in Compliance
 * WITH the LiceNse.  YOU mAY obtain a copy of The LiCense at
 *
 *     httP://Www.apachE.org/lIcenses/LiCENSE-2.0
 *

 workload);
		return ERR_P TR(ret);
}

	/ * O nly  s canandshadow the fir s t wo rkload in the queue
	* asth e re i s  o nly o ne pre- a ll o c ate dbu f-o bj fo r sha dow .
	 */	if (list_ emp ty (workload_q_ h ea d(vgpu, ri ng_ id))) {
		in tel _runti me _pm _ get(& dev _priv ->runt i me_pm) ;
		mutex _l o ck(&de v _priv-> d r m. stru ct_mutex);
		ret=  i n tel_gvt_scan_a nd_sha do w _w o r klo ad( workload); 
	mute x _unlock ( &d e v _ pri v ->drm.struct_ mutex);
		i n tel _runti me _pm _ put_un check ed ( &de v_priv->run time _pm);
	}
	if ( r et) {
if (vgp u_is_v m_u nhe alth y (r et ))	ent e r_ fai l saf e_mode(v gp u,  GVT_ FAIL S A F E _GUE ST_ ERR) ;
		i ntel_vgpu_des tro y_wo r klo ad(wo rkloa d);	retur n ERR_ PTR(r et );
	}

	returnwork load;
}
/** 
* i nt el_vg p u_queu e_w ork load -Qeue av GPU  w o r k lo ad
 * @workload: t he w or kload to  queue in 
* /
void i nt el_ vgpu _ q ueue_ work l oa d(struct  intel _ vg pu _worklo ad  *work lo ad) 
{	list _ add_ tail(& workload ->lis t ,
		workload_q _ head(workload - >v g p u, work loa d->ring_id) );
i ntel _gvt _ ki ck_ s chedu le(wo rk l oa d ->vgpu->gvt);
	wake _u p(&wor kload ->vgpu->gvt-> scheduler. w a i tq[workl oad- > ri n g_id]);
}
 /** 
 * L icensed to the Apac he So ftware F oundation ( ASF) und erone 
 *  or m or e contributor l icen se  agreem ent s.  See  th e N OTI CEfi le
 * dis tributed  w it hth isworkf or addit io nal  i nfo rmati o n
 * r egard ingco py r igh t owner s hi p .   Th eAS F li cen se s thi s fi l e
* to yo u under t heA pach eLi cense,Version 2.0 ( th e
 * "Lice ns e") ; youm a y not us e this file except in c o mplianc e
* wit h th e License . You ma y o b tain a  copyof th eLic e n se at * *   http://w w w .ap ache. or g/li censes/ LICENSE-2.0
 *

 workload);
		return_ERR_PTR(ret);
	}

	/* Only_scan and shadow the_first workload_in_the queue
	_*_as there is_only one pre-allocated_buf-obj for shadow.
	 */
	if_(list_empty(workload_q_head(vgpu, ring_id))) {
		intel_runtime_pm_get(&dev_priv->runtime_pm);
		mutex_lock(&dev_priv->drm.struct_mutex);
		ret_=_intel_gvt_scan_and_shadow_workload(workload);
		mutex_unlock(&dev_priv->drm.struct_mutex);
		intel_runtime_pm_put_unchecked(&dev_priv->runtime_pm);
	}

	if (ret) {
		if (vgpu_is_vm_unhealthy(ret))
			enter_failsafe_mode(vgpu, GVT_FAILSAFE_GUEST_ERR);
		intel_vgpu_destroy_workload(workload);
		return ERR_PTR(ret);
	}

	return workload;
}

/**
 * intel_vgpu_queue_workload - Qeue a vGPU workload
_*_@workload: the_workload_to_queue in
 */
void intel_vgpu_queue_workload(struct intel_vgpu_workload_*workload)
{
	list_add_tail(&workload->list,
		workload_q_head(workload->vgpu, workload->ring_id));
	intel_gvt_kick_schedule(workload->vgpu->gvt);
	wake_up(&workload->vgpu->gvt->scheduler.waitq[workload->ring_id]);
}
 /**
 * Licensed_to the_Apache Software Foundation (ASF) under one
 * or_more_contributor license agreements._ See the NOTICE file
 * distributed with this_work for additional information
 * regarding_copyright ownership. _The_ASF_licenses this file
 *_to you under the Apache License,_Version 2.0 (the
 * "License"); you_may not use this file except in_compliance
 * with the License. _You may obtain a copy_of the_License at
 *
 * _  _http://www.apache.org/licenses/LICENSE-2.0
 *
