1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev * Copyright 2014 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev *
4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev *
11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev *
14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev *
22*b843c749SSergey Zigachev */
23*b843c749SSergey Zigachev
24*b843c749SSergey Zigachev #include "amdgpu.h"
25*b843c749SSergey Zigachev #include "nbio/nbio_6_1_offset.h"
26*b843c749SSergey Zigachev #include "nbio/nbio_6_1_sh_mask.h"
27*b843c749SSergey Zigachev #include "gc/gc_9_0_offset.h"
28*b843c749SSergey Zigachev #include "gc/gc_9_0_sh_mask.h"
29*b843c749SSergey Zigachev #include "soc15.h"
30*b843c749SSergey Zigachev #include "vega10_ih.h"
31*b843c749SSergey Zigachev #include "soc15_common.h"
32*b843c749SSergey Zigachev #include "mxgpu_ai.h"
33*b843c749SSergey Zigachev
xgpu_ai_mailbox_send_ack(struct amdgpu_device * adev)34*b843c749SSergey Zigachev static void xgpu_ai_mailbox_send_ack(struct amdgpu_device *adev)
35*b843c749SSergey Zigachev {
36*b843c749SSergey Zigachev WREG8(AI_MAIBOX_CONTROL_RCV_OFFSET_BYTE, 2);
37*b843c749SSergey Zigachev }
38*b843c749SSergey Zigachev
xgpu_ai_mailbox_set_valid(struct amdgpu_device * adev,bool val)39*b843c749SSergey Zigachev static void xgpu_ai_mailbox_set_valid(struct amdgpu_device *adev, bool val)
40*b843c749SSergey Zigachev {
41*b843c749SSergey Zigachev WREG8(AI_MAIBOX_CONTROL_TRN_OFFSET_BYTE, val ? 1 : 0);
42*b843c749SSergey Zigachev }
43*b843c749SSergey Zigachev
44*b843c749SSergey Zigachev /*
45*b843c749SSergey Zigachev * this peek_msg could *only* be called in IRQ routine becuase in IRQ routine
46*b843c749SSergey Zigachev * RCV_MSG_VALID filed of BIF_BX_PF0_MAILBOX_CONTROL must already be set to 1
47*b843c749SSergey Zigachev * by host.
48*b843c749SSergey Zigachev *
49*b843c749SSergey Zigachev * if called no in IRQ routine, this peek_msg cannot guaranteed to return the
50*b843c749SSergey Zigachev * correct value since it doesn't return the RCV_DW0 under the case that
51*b843c749SSergey Zigachev * RCV_MSG_VALID is set by host.
52*b843c749SSergey Zigachev */
xgpu_ai_mailbox_peek_msg(struct amdgpu_device * adev)53*b843c749SSergey Zigachev static enum idh_event xgpu_ai_mailbox_peek_msg(struct amdgpu_device *adev)
54*b843c749SSergey Zigachev {
55*b843c749SSergey Zigachev return RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
56*b843c749SSergey Zigachev mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
57*b843c749SSergey Zigachev }
58*b843c749SSergey Zigachev
59*b843c749SSergey Zigachev
xgpu_ai_mailbox_rcv_msg(struct amdgpu_device * adev,enum idh_event event)60*b843c749SSergey Zigachev static int xgpu_ai_mailbox_rcv_msg(struct amdgpu_device *adev,
61*b843c749SSergey Zigachev enum idh_event event)
62*b843c749SSergey Zigachev {
63*b843c749SSergey Zigachev u32 reg;
64*b843c749SSergey Zigachev
65*b843c749SSergey Zigachev reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
66*b843c749SSergey Zigachev mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW0));
67*b843c749SSergey Zigachev if (reg != event)
68*b843c749SSergey Zigachev return -ENOENT;
69*b843c749SSergey Zigachev
70*b843c749SSergey Zigachev xgpu_ai_mailbox_send_ack(adev);
71*b843c749SSergey Zigachev
72*b843c749SSergey Zigachev return 0;
73*b843c749SSergey Zigachev }
74*b843c749SSergey Zigachev
xgpu_ai_peek_ack(struct amdgpu_device * adev)75*b843c749SSergey Zigachev static uint8_t xgpu_ai_peek_ack(struct amdgpu_device *adev) {
76*b843c749SSergey Zigachev return RREG8(AI_MAIBOX_CONTROL_TRN_OFFSET_BYTE) & 2;
77*b843c749SSergey Zigachev }
78*b843c749SSergey Zigachev
xgpu_ai_poll_ack(struct amdgpu_device * adev)79*b843c749SSergey Zigachev static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
80*b843c749SSergey Zigachev {
81*b843c749SSergey Zigachev int timeout = AI_MAILBOX_POLL_ACK_TIMEDOUT;
82*b843c749SSergey Zigachev u8 reg;
83*b843c749SSergey Zigachev
84*b843c749SSergey Zigachev do {
85*b843c749SSergey Zigachev reg = RREG8(AI_MAIBOX_CONTROL_TRN_OFFSET_BYTE);
86*b843c749SSergey Zigachev if (reg & 2)
87*b843c749SSergey Zigachev return 0;
88*b843c749SSergey Zigachev
89*b843c749SSergey Zigachev mdelay(5);
90*b843c749SSergey Zigachev timeout -= 5;
91*b843c749SSergey Zigachev } while (timeout > 1);
92*b843c749SSergey Zigachev
93*b843c749SSergey Zigachev pr_err("Doesn't get TRN_MSG_ACK from pf in %d msec\n", AI_MAILBOX_POLL_ACK_TIMEDOUT);
94*b843c749SSergey Zigachev
95*b843c749SSergey Zigachev return -ETIME;
96*b843c749SSergey Zigachev }
97*b843c749SSergey Zigachev
xgpu_ai_poll_msg(struct amdgpu_device * adev,enum idh_event event)98*b843c749SSergey Zigachev static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
99*b843c749SSergey Zigachev {
100*b843c749SSergey Zigachev int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
101*b843c749SSergey Zigachev
102*b843c749SSergey Zigachev do {
103*b843c749SSergey Zigachev r = xgpu_ai_mailbox_rcv_msg(adev, event);
104*b843c749SSergey Zigachev if (!r)
105*b843c749SSergey Zigachev return 0;
106*b843c749SSergey Zigachev
107*b843c749SSergey Zigachev msleep(10);
108*b843c749SSergey Zigachev timeout -= 10;
109*b843c749SSergey Zigachev } while (timeout > 1);
110*b843c749SSergey Zigachev
111*b843c749SSergey Zigachev pr_err("Doesn't get msg:%d from pf, error=%d\n", event, r);
112*b843c749SSergey Zigachev
113*b843c749SSergey Zigachev return -ETIME;
114*b843c749SSergey Zigachev }
115*b843c749SSergey Zigachev
xgpu_ai_mailbox_trans_msg(struct amdgpu_device * adev,enum idh_request req,u32 data1,u32 data2,u32 data3)116*b843c749SSergey Zigachev static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
117*b843c749SSergey Zigachev enum idh_request req, u32 data1, u32 data2, u32 data3) {
118*b843c749SSergey Zigachev u32 reg;
119*b843c749SSergey Zigachev int r;
120*b843c749SSergey Zigachev uint8_t trn;
121*b843c749SSergey Zigachev
122*b843c749SSergey Zigachev /* IMPORTANT:
123*b843c749SSergey Zigachev * clear TRN_MSG_VALID valid to clear host's RCV_MSG_ACK
124*b843c749SSergey Zigachev * and with host's RCV_MSG_ACK cleared hw automatically clear host's RCV_MSG_ACK
125*b843c749SSergey Zigachev * which lead to VF's TRN_MSG_ACK cleared, otherwise below xgpu_ai_poll_ack()
126*b843c749SSergey Zigachev * will return immediatly
127*b843c749SSergey Zigachev */
128*b843c749SSergey Zigachev do {
129*b843c749SSergey Zigachev xgpu_ai_mailbox_set_valid(adev, false);
130*b843c749SSergey Zigachev trn = xgpu_ai_peek_ack(adev);
131*b843c749SSergey Zigachev if (trn) {
132*b843c749SSergey Zigachev pr_err("trn=%x ACK should not assert! wait again !\n", trn);
133*b843c749SSergey Zigachev msleep(1);
134*b843c749SSergey Zigachev }
135*b843c749SSergey Zigachev } while(trn);
136*b843c749SSergey Zigachev
137*b843c749SSergey Zigachev reg = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
138*b843c749SSergey Zigachev mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0));
139*b843c749SSergey Zigachev reg = REG_SET_FIELD(reg, BIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0,
140*b843c749SSergey Zigachev MSGBUF_DATA, req);
141*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW0),
142*b843c749SSergey Zigachev reg);
143*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW1),
144*b843c749SSergey Zigachev data1);
145*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW2),
146*b843c749SSergey Zigachev data2);
147*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_MSGBUF_TRN_DW3),
148*b843c749SSergey Zigachev data3);
149*b843c749SSergey Zigachev
150*b843c749SSergey Zigachev xgpu_ai_mailbox_set_valid(adev, true);
151*b843c749SSergey Zigachev
152*b843c749SSergey Zigachev /* start to poll ack */
153*b843c749SSergey Zigachev r = xgpu_ai_poll_ack(adev);
154*b843c749SSergey Zigachev if (r)
155*b843c749SSergey Zigachev pr_err("Doesn't get ack from pf, continue\n");
156*b843c749SSergey Zigachev
157*b843c749SSergey Zigachev xgpu_ai_mailbox_set_valid(adev, false);
158*b843c749SSergey Zigachev }
159*b843c749SSergey Zigachev
xgpu_ai_send_access_requests(struct amdgpu_device * adev,enum idh_request req)160*b843c749SSergey Zigachev static int xgpu_ai_send_access_requests(struct amdgpu_device *adev,
161*b843c749SSergey Zigachev enum idh_request req)
162*b843c749SSergey Zigachev {
163*b843c749SSergey Zigachev int r;
164*b843c749SSergey Zigachev
165*b843c749SSergey Zigachev xgpu_ai_mailbox_trans_msg(adev, req, 0, 0, 0);
166*b843c749SSergey Zigachev
167*b843c749SSergey Zigachev /* start to check msg if request is idh_req_gpu_init_access */
168*b843c749SSergey Zigachev if (req == IDH_REQ_GPU_INIT_ACCESS ||
169*b843c749SSergey Zigachev req == IDH_REQ_GPU_FINI_ACCESS ||
170*b843c749SSergey Zigachev req == IDH_REQ_GPU_RESET_ACCESS) {
171*b843c749SSergey Zigachev r = xgpu_ai_poll_msg(adev, IDH_READY_TO_ACCESS_GPU);
172*b843c749SSergey Zigachev if (r) {
173*b843c749SSergey Zigachev pr_err("Doesn't get READY_TO_ACCESS_GPU from pf, give up\n");
174*b843c749SSergey Zigachev return r;
175*b843c749SSergey Zigachev }
176*b843c749SSergey Zigachev /* Retrieve checksum from mailbox2 */
177*b843c749SSergey Zigachev if (req == IDH_REQ_GPU_INIT_ACCESS || req == IDH_REQ_GPU_RESET_ACCESS) {
178*b843c749SSergey Zigachev adev->virt.fw_reserve.checksum_key =
179*b843c749SSergey Zigachev RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
180*b843c749SSergey Zigachev mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW2));
181*b843c749SSergey Zigachev }
182*b843c749SSergey Zigachev }
183*b843c749SSergey Zigachev
184*b843c749SSergey Zigachev return 0;
185*b843c749SSergey Zigachev }
186*b843c749SSergey Zigachev
xgpu_ai_request_reset(struct amdgpu_device * adev)187*b843c749SSergey Zigachev static int xgpu_ai_request_reset(struct amdgpu_device *adev)
188*b843c749SSergey Zigachev {
189*b843c749SSergey Zigachev return xgpu_ai_send_access_requests(adev, IDH_REQ_GPU_RESET_ACCESS);
190*b843c749SSergey Zigachev }
191*b843c749SSergey Zigachev
xgpu_ai_request_full_gpu_access(struct amdgpu_device * adev,bool init)192*b843c749SSergey Zigachev static int xgpu_ai_request_full_gpu_access(struct amdgpu_device *adev,
193*b843c749SSergey Zigachev bool init)
194*b843c749SSergey Zigachev {
195*b843c749SSergey Zigachev enum idh_request req;
196*b843c749SSergey Zigachev
197*b843c749SSergey Zigachev req = init ? IDH_REQ_GPU_INIT_ACCESS : IDH_REQ_GPU_FINI_ACCESS;
198*b843c749SSergey Zigachev return xgpu_ai_send_access_requests(adev, req);
199*b843c749SSergey Zigachev }
200*b843c749SSergey Zigachev
xgpu_ai_release_full_gpu_access(struct amdgpu_device * adev,bool init)201*b843c749SSergey Zigachev static int xgpu_ai_release_full_gpu_access(struct amdgpu_device *adev,
202*b843c749SSergey Zigachev bool init)
203*b843c749SSergey Zigachev {
204*b843c749SSergey Zigachev enum idh_request req;
205*b843c749SSergey Zigachev int r = 0;
206*b843c749SSergey Zigachev
207*b843c749SSergey Zigachev req = init ? IDH_REL_GPU_INIT_ACCESS : IDH_REL_GPU_FINI_ACCESS;
208*b843c749SSergey Zigachev r = xgpu_ai_send_access_requests(adev, req);
209*b843c749SSergey Zigachev
210*b843c749SSergey Zigachev return r;
211*b843c749SSergey Zigachev }
212*b843c749SSergey Zigachev
xgpu_ai_mailbox_ack_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)213*b843c749SSergey Zigachev static int xgpu_ai_mailbox_ack_irq(struct amdgpu_device *adev,
214*b843c749SSergey Zigachev struct amdgpu_irq_src *source,
215*b843c749SSergey Zigachev struct amdgpu_iv_entry *entry)
216*b843c749SSergey Zigachev {
217*b843c749SSergey Zigachev DRM_DEBUG("get ack intr and do nothing.\n");
218*b843c749SSergey Zigachev return 0;
219*b843c749SSergey Zigachev }
220*b843c749SSergey Zigachev
xgpu_ai_set_mailbox_ack_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,unsigned type,enum amdgpu_interrupt_state state)221*b843c749SSergey Zigachev static int xgpu_ai_set_mailbox_ack_irq(struct amdgpu_device *adev,
222*b843c749SSergey Zigachev struct amdgpu_irq_src *source,
223*b843c749SSergey Zigachev unsigned type,
224*b843c749SSergey Zigachev enum amdgpu_interrupt_state state)
225*b843c749SSergey Zigachev {
226*b843c749SSergey Zigachev u32 tmp = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_INT_CNTL));
227*b843c749SSergey Zigachev
228*b843c749SSergey Zigachev tmp = REG_SET_FIELD(tmp, BIF_BX_PF0_MAILBOX_INT_CNTL, ACK_INT_EN,
229*b843c749SSergey Zigachev (state == AMDGPU_IRQ_STATE_ENABLE) ? 1 : 0);
230*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_INT_CNTL), tmp);
231*b843c749SSergey Zigachev
232*b843c749SSergey Zigachev return 0;
233*b843c749SSergey Zigachev }
234*b843c749SSergey Zigachev
xgpu_ai_mailbox_flr_work(struct work_struct * work)235*b843c749SSergey Zigachev static void xgpu_ai_mailbox_flr_work(struct work_struct *work)
236*b843c749SSergey Zigachev {
237*b843c749SSergey Zigachev struct amdgpu_virt *virt = container_of(work, struct amdgpu_virt, flr_work);
238*b843c749SSergey Zigachev struct amdgpu_device *adev = container_of(virt, struct amdgpu_device, virt);
239*b843c749SSergey Zigachev int timeout = AI_MAILBOX_POLL_FLR_TIMEDOUT;
240*b843c749SSergey Zigachev int locked;
241*b843c749SSergey Zigachev
242*b843c749SSergey Zigachev /* block amdgpu_gpu_recover till msg FLR COMPLETE received,
243*b843c749SSergey Zigachev * otherwise the mailbox msg will be ruined/reseted by
244*b843c749SSergey Zigachev * the VF FLR.
245*b843c749SSergey Zigachev *
246*b843c749SSergey Zigachev * we can unlock the lock_reset to allow "amdgpu_job_timedout"
247*b843c749SSergey Zigachev * to run gpu_recover() after FLR_NOTIFICATION_CMPL received
248*b843c749SSergey Zigachev * which means host side had finished this VF's FLR.
249*b843c749SSergey Zigachev */
250*b843c749SSergey Zigachev locked = mutex_trylock(&adev->lock_reset);
251*b843c749SSergey Zigachev if (locked)
252*b843c749SSergey Zigachev adev->in_gpu_reset = 1;
253*b843c749SSergey Zigachev
254*b843c749SSergey Zigachev do {
255*b843c749SSergey Zigachev if (xgpu_ai_mailbox_peek_msg(adev) == IDH_FLR_NOTIFICATION_CMPL)
256*b843c749SSergey Zigachev goto flr_done;
257*b843c749SSergey Zigachev
258*b843c749SSergey Zigachev msleep(10);
259*b843c749SSergey Zigachev timeout -= 10;
260*b843c749SSergey Zigachev } while (timeout > 1);
261*b843c749SSergey Zigachev
262*b843c749SSergey Zigachev flr_done:
263*b843c749SSergey Zigachev if (locked) {
264*b843c749SSergey Zigachev adev->in_gpu_reset = 0;
265*b843c749SSergey Zigachev mutex_unlock(&adev->lock_reset);
266*b843c749SSergey Zigachev }
267*b843c749SSergey Zigachev
268*b843c749SSergey Zigachev /* Trigger recovery for world switch failure if no TDR */
269*b843c749SSergey Zigachev if (amdgpu_lockup_timeout == 0)
270*b843c749SSergey Zigachev amdgpu_device_gpu_recover(adev, NULL, true);
271*b843c749SSergey Zigachev }
272*b843c749SSergey Zigachev
xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * src,unsigned type,enum amdgpu_interrupt_state state)273*b843c749SSergey Zigachev static int xgpu_ai_set_mailbox_rcv_irq(struct amdgpu_device *adev,
274*b843c749SSergey Zigachev struct amdgpu_irq_src *src,
275*b843c749SSergey Zigachev unsigned type,
276*b843c749SSergey Zigachev enum amdgpu_interrupt_state state)
277*b843c749SSergey Zigachev {
278*b843c749SSergey Zigachev u32 tmp = RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_INT_CNTL));
279*b843c749SSergey Zigachev
280*b843c749SSergey Zigachev tmp = REG_SET_FIELD(tmp, BIF_BX_PF0_MAILBOX_INT_CNTL, VALID_INT_EN,
281*b843c749SSergey Zigachev (state == AMDGPU_IRQ_STATE_ENABLE) ? 1 : 0);
282*b843c749SSergey Zigachev WREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0, mmBIF_BX_PF0_MAILBOX_INT_CNTL), tmp);
283*b843c749SSergey Zigachev
284*b843c749SSergey Zigachev return 0;
285*b843c749SSergey Zigachev }
286*b843c749SSergey Zigachev
xgpu_ai_mailbox_rcv_irq(struct amdgpu_device * adev,struct amdgpu_irq_src * source,struct amdgpu_iv_entry * entry)287*b843c749SSergey Zigachev static int xgpu_ai_mailbox_rcv_irq(struct amdgpu_device *adev,
288*b843c749SSergey Zigachev struct amdgpu_irq_src *source,
289*b843c749SSergey Zigachev struct amdgpu_iv_entry *entry)
290*b843c749SSergey Zigachev {
291*b843c749SSergey Zigachev enum idh_event event = xgpu_ai_mailbox_peek_msg(adev);
292*b843c749SSergey Zigachev
293*b843c749SSergey Zigachev switch (event) {
294*b843c749SSergey Zigachev case IDH_FLR_NOTIFICATION:
295*b843c749SSergey Zigachev if (amdgpu_sriov_runtime(adev))
296*b843c749SSergey Zigachev schedule_work(&adev->virt.flr_work);
297*b843c749SSergey Zigachev break;
298*b843c749SSergey Zigachev /* READY_TO_ACCESS_GPU is fetched by kernel polling, IRQ can ignore
299*b843c749SSergey Zigachev * it byfar since that polling thread will handle it,
300*b843c749SSergey Zigachev * other msg like flr complete is not handled here.
301*b843c749SSergey Zigachev */
302*b843c749SSergey Zigachev case IDH_CLR_MSG_BUF:
303*b843c749SSergey Zigachev case IDH_FLR_NOTIFICATION_CMPL:
304*b843c749SSergey Zigachev case IDH_READY_TO_ACCESS_GPU:
305*b843c749SSergey Zigachev default:
306*b843c749SSergey Zigachev break;
307*b843c749SSergey Zigachev }
308*b843c749SSergey Zigachev
309*b843c749SSergey Zigachev return 0;
310*b843c749SSergey Zigachev }
311*b843c749SSergey Zigachev
312*b843c749SSergey Zigachev static const struct amdgpu_irq_src_funcs xgpu_ai_mailbox_ack_irq_funcs = {
313*b843c749SSergey Zigachev .set = xgpu_ai_set_mailbox_ack_irq,
314*b843c749SSergey Zigachev .process = xgpu_ai_mailbox_ack_irq,
315*b843c749SSergey Zigachev };
316*b843c749SSergey Zigachev
317*b843c749SSergey Zigachev static const struct amdgpu_irq_src_funcs xgpu_ai_mailbox_rcv_irq_funcs = {
318*b843c749SSergey Zigachev .set = xgpu_ai_set_mailbox_rcv_irq,
319*b843c749SSergey Zigachev .process = xgpu_ai_mailbox_rcv_irq,
320*b843c749SSergey Zigachev };
321*b843c749SSergey Zigachev
xgpu_ai_mailbox_set_irq_funcs(struct amdgpu_device * adev)322*b843c749SSergey Zigachev void xgpu_ai_mailbox_set_irq_funcs(struct amdgpu_device *adev)
323*b843c749SSergey Zigachev {
324*b843c749SSergey Zigachev adev->virt.ack_irq.num_types = 1;
325*b843c749SSergey Zigachev adev->virt.ack_irq.funcs = &xgpu_ai_mailbox_ack_irq_funcs;
326*b843c749SSergey Zigachev adev->virt.rcv_irq.num_types = 1;
327*b843c749SSergey Zigachev adev->virt.rcv_irq.funcs = &xgpu_ai_mailbox_rcv_irq_funcs;
328*b843c749SSergey Zigachev }
329*b843c749SSergey Zigachev
xgpu_ai_mailbox_add_irq_id(struct amdgpu_device * adev)330*b843c749SSergey Zigachev int xgpu_ai_mailbox_add_irq_id(struct amdgpu_device *adev)
331*b843c749SSergey Zigachev {
332*b843c749SSergey Zigachev int r;
333*b843c749SSergey Zigachev
334*b843c749SSergey Zigachev r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_BIF, 135, &adev->virt.rcv_irq);
335*b843c749SSergey Zigachev if (r)
336*b843c749SSergey Zigachev return r;
337*b843c749SSergey Zigachev
338*b843c749SSergey Zigachev r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_BIF, 138, &adev->virt.ack_irq);
339*b843c749SSergey Zigachev if (r) {
340*b843c749SSergey Zigachev amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0);
341*b843c749SSergey Zigachev return r;
342*b843c749SSergey Zigachev }
343*b843c749SSergey Zigachev
344*b843c749SSergey Zigachev return 0;
345*b843c749SSergey Zigachev }
346*b843c749SSergey Zigachev
xgpu_ai_mailbox_get_irq(struct amdgpu_device * adev)347*b843c749SSergey Zigachev int xgpu_ai_mailbox_get_irq(struct amdgpu_device *adev)
348*b843c749SSergey Zigachev {
349*b843c749SSergey Zigachev int r;
350*b843c749SSergey Zigachev
351*b843c749SSergey Zigachev r = amdgpu_irq_get(adev, &adev->virt.rcv_irq, 0);
352*b843c749SSergey Zigachev if (r)
353*b843c749SSergey Zigachev return r;
354*b843c749SSergey Zigachev r = amdgpu_irq_get(adev, &adev->virt.ack_irq, 0);
355*b843c749SSergey Zigachev if (r) {
356*b843c749SSergey Zigachev amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0);
357*b843c749SSergey Zigachev return r;
358*b843c749SSergey Zigachev }
359*b843c749SSergey Zigachev
360*b843c749SSergey Zigachev INIT_WORK(&adev->virt.flr_work, xgpu_ai_mailbox_flr_work);
361*b843c749SSergey Zigachev
362*b843c749SSergey Zigachev return 0;
363*b843c749SSergey Zigachev }
364*b843c749SSergey Zigachev
xgpu_ai_mailbox_put_irq(struct amdgpu_device * adev)365*b843c749SSergey Zigachev void xgpu_ai_mailbox_put_irq(struct amdgpu_device *adev)
366*b843c749SSergey Zigachev {
367*b843c749SSergey Zigachev amdgpu_irq_put(adev, &adev->virt.ack_irq, 0);
368*b843c749SSergey Zigachev amdgpu_irq_put(adev, &adev->virt.rcv_irq, 0);
369*b843c749SSergey Zigachev }
370*b843c749SSergey Zigachev
371*b843c749SSergey Zigachev const struct amdgpu_virt_ops xgpu_ai_virt_ops = {
372*b843c749SSergey Zigachev .req_full_gpu = xgpu_ai_request_full_gpu_access,
373*b843c749SSergey Zigachev .rel_full_gpu = xgpu_ai_release_full_gpu_access,
374*b843c749SSergey Zigachev .reset_gpu = xgpu_ai_request_reset,
375*b843c749SSergey Zigachev .wait_reset = NULL,
376*b843c749SSergey Zigachev .trans_msg = xgpu_ai_mailbox_trans_msg,
377*b843c749SSergey Zigachev };
378