18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2015 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci#ifndef _CGS_COMMON_H 258c2ecf20Sopenharmony_ci#define _CGS_COMMON_H 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include "amd_shared.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct cgs_device; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/** 328c2ecf20Sopenharmony_ci * enum cgs_ind_reg - Indirect register spaces 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cienum cgs_ind_reg { 358c2ecf20Sopenharmony_ci CGS_IND_REG__PCIE, 368c2ecf20Sopenharmony_ci CGS_IND_REG__SMC, 378c2ecf20Sopenharmony_ci CGS_IND_REG__UVD_CTX, 388c2ecf20Sopenharmony_ci CGS_IND_REG__DIDT, 398c2ecf20Sopenharmony_ci CGS_IND_REG_GC_CAC, 408c2ecf20Sopenharmony_ci CGS_IND_REG_SE_CAC, 418c2ecf20Sopenharmony_ci CGS_IND_REG__AUDIO_ENDPT 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * enum cgs_ucode_id - Firmware types for different IPs 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cienum cgs_ucode_id { 488c2ecf20Sopenharmony_ci CGS_UCODE_ID_SMU = 0, 498c2ecf20Sopenharmony_ci CGS_UCODE_ID_SMU_SK, 508c2ecf20Sopenharmony_ci CGS_UCODE_ID_SDMA0, 518c2ecf20Sopenharmony_ci CGS_UCODE_ID_SDMA1, 528c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_CE, 538c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_PFP, 548c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_ME, 558c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_MEC, 568c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_MEC_JT1, 578c2ecf20Sopenharmony_ci CGS_UCODE_ID_CP_MEC_JT2, 588c2ecf20Sopenharmony_ci CGS_UCODE_ID_GMCON_RENG, 598c2ecf20Sopenharmony_ci CGS_UCODE_ID_RLC_G, 608c2ecf20Sopenharmony_ci CGS_UCODE_ID_STORAGE, 618c2ecf20Sopenharmony_ci CGS_UCODE_ID_MAXIMUM, 628c2ecf20Sopenharmony_ci}; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * struct cgs_firmware_info - Firmware information 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_cistruct cgs_firmware_info { 688c2ecf20Sopenharmony_ci uint16_t version; 698c2ecf20Sopenharmony_ci uint16_t fw_version; 708c2ecf20Sopenharmony_ci uint16_t feature_version; 718c2ecf20Sopenharmony_ci uint32_t image_size; 728c2ecf20Sopenharmony_ci uint64_t mc_addr; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci /* only for smc firmware */ 758c2ecf20Sopenharmony_ci uint32_t ucode_start_address; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci void *kptr; 788c2ecf20Sopenharmony_ci bool is_kicker; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_citypedef unsigned long cgs_handle_t; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/** 848c2ecf20Sopenharmony_ci * cgs_read_register() - Read an MMIO register 858c2ecf20Sopenharmony_ci * @cgs_device: opaque device handle 868c2ecf20Sopenharmony_ci * @offset: register offset 878c2ecf20Sopenharmony_ci * 888c2ecf20Sopenharmony_ci * Return: register value 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_citypedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/** 938c2ecf20Sopenharmony_ci * cgs_write_register() - Write an MMIO register 948c2ecf20Sopenharmony_ci * @cgs_device: opaque device handle 958c2ecf20Sopenharmony_ci * @offset: register offset 968c2ecf20Sopenharmony_ci * @value: register value 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_citypedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset, 998c2ecf20Sopenharmony_ci uint32_t value); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/** 1028c2ecf20Sopenharmony_ci * cgs_read_ind_register() - Read an indirect register 1038c2ecf20Sopenharmony_ci * @cgs_device: opaque device handle 1048c2ecf20Sopenharmony_ci * @offset: register offset 1058c2ecf20Sopenharmony_ci * 1068c2ecf20Sopenharmony_ci * Return: register value 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_citypedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space, 1098c2ecf20Sopenharmony_ci unsigned index); 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci/** 1128c2ecf20Sopenharmony_ci * cgs_write_ind_register() - Write an indirect register 1138c2ecf20Sopenharmony_ci * @cgs_device: opaque device handle 1148c2ecf20Sopenharmony_ci * @offset: register offset 1158c2ecf20Sopenharmony_ci * @value: register value 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_citypedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space, 1188c2ecf20Sopenharmony_ci unsigned index, uint32_t value); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 1218c2ecf20Sopenharmony_ci#define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \ 1248c2ecf20Sopenharmony_ci (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \ 1258c2ecf20Sopenharmony_ci (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field)))) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define CGS_REG_GET_FIELD(value, reg, field) \ 1288c2ecf20Sopenharmony_ci (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field)) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#define CGS_WREG32_FIELD(device, reg, field, val) \ 1318c2ecf20Sopenharmony_ci cgs_write_register(device, mm##reg, (cgs_read_register(device, mm##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field)) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \ 1348c2ecf20Sopenharmony_ci cgs_write_ind_register(device, space, ix##reg, (cgs_read_ind_register(device, space, ix##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field)) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_citypedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device, 1378c2ecf20Sopenharmony_ci enum cgs_ucode_id type, 1388c2ecf20Sopenharmony_ci struct cgs_firmware_info *info); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistruct cgs_ops { 1418c2ecf20Sopenharmony_ci /* MMIO access */ 1428c2ecf20Sopenharmony_ci cgs_read_register_t read_register; 1438c2ecf20Sopenharmony_ci cgs_write_register_t write_register; 1448c2ecf20Sopenharmony_ci cgs_read_ind_register_t read_ind_register; 1458c2ecf20Sopenharmony_ci cgs_write_ind_register_t write_ind_register; 1468c2ecf20Sopenharmony_ci /* Firmware Info */ 1478c2ecf20Sopenharmony_ci cgs_get_firmware_info get_firmware_info; 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistruct cgs_os_ops; /* To be define in OS-specific CGS header */ 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_cistruct cgs_device 1538c2ecf20Sopenharmony_ci{ 1548c2ecf20Sopenharmony_ci const struct cgs_ops *ops; 1558c2ecf20Sopenharmony_ci /* to be embedded at the start of driver private structure */ 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci/* Convenience macros that make CGS indirect function calls look like 1598c2ecf20Sopenharmony_ci * normal function calls */ 1608c2ecf20Sopenharmony_ci#define CGS_CALL(func,dev,...) \ 1618c2ecf20Sopenharmony_ci (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__)) 1628c2ecf20Sopenharmony_ci#define CGS_OS_CALL(func,dev,...) \ 1638c2ecf20Sopenharmony_ci (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__)) 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci#define cgs_read_register(dev,offset) \ 1668c2ecf20Sopenharmony_ci CGS_CALL(read_register,dev,offset) 1678c2ecf20Sopenharmony_ci#define cgs_write_register(dev,offset,value) \ 1688c2ecf20Sopenharmony_ci CGS_CALL(write_register,dev,offset,value) 1698c2ecf20Sopenharmony_ci#define cgs_read_ind_register(dev,space,index) \ 1708c2ecf20Sopenharmony_ci CGS_CALL(read_ind_register,dev,space,index) 1718c2ecf20Sopenharmony_ci#define cgs_write_ind_register(dev,space,index,value) \ 1728c2ecf20Sopenharmony_ci CGS_CALL(write_ind_register,dev,space,index,value) 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#define cgs_get_firmware_info(dev, type, info) \ 1758c2ecf20Sopenharmony_ci CGS_CALL(get_firmware_info, dev, type, info) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#endif /* _CGS_COMMON_H */ 178