1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2026, Advanced Micro Devices, Inc. 4 */ 5 6 #include <drm/amdxdna_accel.h> 7 #include <drm/drm_print.h> 8 #include <linux/mutex.h> 9 10 #include "aie.h" 11 #include "aie4_msg_priv.h" 12 #include "aie4_pci.h" 13 #include "amdxdna_mailbox.h" 14 #include "amdxdna_mailbox_helper.h" 15 #include "amdxdna_pci_drv.h" 16 17 int aie4_suspend_fw(struct amdxdna_dev_hdl *ndev) 18 { 19 DECLARE_AIE_MSG(aie4_msg_suspend, AIE4_MSG_OP_SUSPEND); 20 int ret; 21 22 ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg); 23 if (ret) 24 XDNA_ERR(ndev->aie.xdna, "Failed to suspend fw, ret %d", ret); 25 26 return ret; 27 } 28 29 int aie4_query_aie_metadata(struct amdxdna_dev_hdl *ndev, 30 struct amdxdna_drm_query_aie_metadata *metadata) 31 { 32 DECLARE_AIE_MSG(aie4_msg_aie4_tile_info, AIE4_MSG_OP_AIE_TILE_INFO); 33 int ret; 34 35 ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg); 36 if (ret) 37 return ret; 38 39 metadata->col_size = resp.info.size; 40 metadata->cols = resp.info.cols; 41 metadata->rows = resp.info.rows; 42 43 metadata->version.major = resp.info.major; 44 metadata->version.minor = resp.info.minor; 45 46 metadata->core.row_count = resp.info.core_rows; 47 metadata->core.row_start = resp.info.core_row_start; 48 metadata->core.dma_channel_count = resp.info.core_dma_channels; 49 metadata->core.lock_count = resp.info.core_locks; 50 metadata->core.event_reg_count = resp.info.core_events; 51 52 metadata->mem.row_count = resp.info.mem_rows; 53 metadata->mem.row_start = resp.info.mem_row_start; 54 metadata->mem.dma_channel_count = resp.info.mem_dma_channels; 55 metadata->mem.lock_count = resp.info.mem_locks; 56 metadata->mem.event_reg_count = resp.info.mem_events; 57 58 metadata->shim.row_count = resp.info.shim_rows; 59 metadata->shim.row_start = resp.info.shim_row_start; 60 metadata->shim.dma_channel_count = resp.info.shim_dma_channels; 61 metadata->shim.lock_count = resp.info.shim_locks; 62 metadata->shim.event_reg_count = resp.info.shim_events; 63 64 return 0; 65 } 66 67 int aie4_attach_work_buffer(struct amdxdna_dev_hdl *ndev) 68 { 69 DECLARE_AIE_MSG(aie4_msg_attach_work_buffer, AIE4_MSG_OP_ATTACH_WORK_BUFFER); 70 struct amdxdna_dev *xdna = ndev->aie.xdna; 71 int ret; 72 73 req.buff_addr = ndev->work_buf_addr; 74 req.buff_size = AIE4_WORK_BUFFER_MIN_SIZE; 75 76 ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg); 77 if (ret) 78 XDNA_ERR(xdna, "Failed to attach work buffer, ret %d", ret); 79 else 80 XDNA_DBG(xdna, "Attached work buffer"); 81 82 return ret; 83 } 84