1c59a5c48SFrançois Tigeot /* 2c59a5c48SFrançois Tigeot * Copyright 2015 Advanced Micro Devices, Inc. 3c59a5c48SFrançois Tigeot * 4c59a5c48SFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a 5c59a5c48SFrançois Tigeot * copy of this software and associated documentation files (the "Software"), 6c59a5c48SFrançois Tigeot * to deal in the Software without restriction, including without limitation 7c59a5c48SFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c59a5c48SFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the 9c59a5c48SFrançois Tigeot * Software is furnished to do so, subject to the following conditions: 10c59a5c48SFrançois Tigeot * 11c59a5c48SFrançois Tigeot * The above copyright notice and this permission notice shall be included in 12c59a5c48SFrançois Tigeot * all copies or substantial portions of the Software. 13c59a5c48SFrançois Tigeot * 14c59a5c48SFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15c59a5c48SFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16c59a5c48SFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17c59a5c48SFrançois Tigeot * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18c59a5c48SFrançois Tigeot * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19c59a5c48SFrançois Tigeot * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20c59a5c48SFrançois Tigeot * OTHER DEALINGS IN THE SOFTWARE. 21c59a5c48SFrançois Tigeot * 22c59a5c48SFrançois Tigeot * 23c59a5c48SFrançois Tigeot */ 24c59a5c48SFrançois Tigeot #ifndef _CGS_COMMON_H 25c59a5c48SFrançois Tigeot #define _CGS_COMMON_H 26c59a5c48SFrançois Tigeot 27c59a5c48SFrançois Tigeot #include "amd_shared.h" 28c59a5c48SFrançois Tigeot 29d78d3a22SFrançois Tigeot struct cgs_device; 30d78d3a22SFrançois Tigeot 31c59a5c48SFrançois Tigeot /** 32c59a5c48SFrançois Tigeot * enum cgs_ind_reg - Indirect register spaces 33c59a5c48SFrançois Tigeot */ 34c59a5c48SFrançois Tigeot enum cgs_ind_reg { 35c59a5c48SFrançois Tigeot CGS_IND_REG__MMIO, 36c59a5c48SFrançois Tigeot CGS_IND_REG__PCIE, 37c59a5c48SFrançois Tigeot CGS_IND_REG__SMC, 38c59a5c48SFrançois Tigeot CGS_IND_REG__UVD_CTX, 39c59a5c48SFrançois Tigeot CGS_IND_REG__DIDT, 40*b843c749SSergey Zigachev CGS_IND_REG_GC_CAC, 41*b843c749SSergey Zigachev CGS_IND_REG_SE_CAC, 42c59a5c48SFrançois Tigeot CGS_IND_REG__AUDIO_ENDPT 43c59a5c48SFrançois Tigeot }; 44c59a5c48SFrançois Tigeot 45c59a5c48SFrançois Tigeot /* 46c59a5c48SFrançois Tigeot * enum cgs_ucode_id - Firmware types for different IPs 47c59a5c48SFrançois Tigeot */ 48c59a5c48SFrançois Tigeot enum cgs_ucode_id { 49c59a5c48SFrançois Tigeot CGS_UCODE_ID_SMU = 0, 50d78d3a22SFrançois Tigeot CGS_UCODE_ID_SMU_SK, 51c59a5c48SFrançois Tigeot CGS_UCODE_ID_SDMA0, 52c59a5c48SFrançois Tigeot CGS_UCODE_ID_SDMA1, 53c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_CE, 54c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_PFP, 55c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_ME, 56c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_MEC, 57c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_MEC_JT1, 58c59a5c48SFrançois Tigeot CGS_UCODE_ID_CP_MEC_JT2, 59c59a5c48SFrançois Tigeot CGS_UCODE_ID_GMCON_RENG, 60c59a5c48SFrançois Tigeot CGS_UCODE_ID_RLC_G, 61*b843c749SSergey Zigachev CGS_UCODE_ID_STORAGE, 62c59a5c48SFrançois Tigeot CGS_UCODE_ID_MAXIMUM, 63c59a5c48SFrançois Tigeot }; 64c59a5c48SFrançois Tigeot 65c59a5c48SFrançois Tigeot /** 66c59a5c48SFrançois Tigeot * struct cgs_firmware_info - Firmware information 67c59a5c48SFrançois Tigeot */ 68c59a5c48SFrançois Tigeot struct cgs_firmware_info { 69c59a5c48SFrançois Tigeot uint16_t version; 70*b843c749SSergey Zigachev uint16_t fw_version; 71c59a5c48SFrançois Tigeot uint16_t feature_version; 72c59a5c48SFrançois Tigeot uint32_t image_size; 73c59a5c48SFrançois Tigeot uint64_t mc_addr; 74*b843c749SSergey Zigachev 75*b843c749SSergey Zigachev /* only for smc firmware */ 76*b843c749SSergey Zigachev uint32_t ucode_start_address; 77*b843c749SSergey Zigachev 78c59a5c48SFrançois Tigeot void *kptr; 79*b843c749SSergey Zigachev bool is_kicker; 80d78d3a22SFrançois Tigeot }; 81d78d3a22SFrançois Tigeot 82c59a5c48SFrançois Tigeot typedef unsigned long cgs_handle_t; 83c59a5c48SFrançois Tigeot 84c59a5c48SFrançois Tigeot /** 85c59a5c48SFrançois Tigeot * cgs_read_register() - Read an MMIO register 86c59a5c48SFrançois Tigeot * @cgs_device: opaque device handle 87c59a5c48SFrançois Tigeot * @offset: register offset 88c59a5c48SFrançois Tigeot * 89c59a5c48SFrançois Tigeot * Return: register value 90c59a5c48SFrançois Tigeot */ 91d78d3a22SFrançois Tigeot typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset); 92c59a5c48SFrançois Tigeot 93c59a5c48SFrançois Tigeot /** 94c59a5c48SFrançois Tigeot * cgs_write_register() - Write an MMIO register 95c59a5c48SFrançois Tigeot * @cgs_device: opaque device handle 96c59a5c48SFrançois Tigeot * @offset: register offset 97c59a5c48SFrançois Tigeot * @value: register value 98c59a5c48SFrançois Tigeot */ 99d78d3a22SFrançois Tigeot typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset, 100c59a5c48SFrançois Tigeot uint32_t value); 101c59a5c48SFrançois Tigeot 102c59a5c48SFrançois Tigeot /** 103c59a5c48SFrançois Tigeot * cgs_read_ind_register() - Read an indirect register 104c59a5c48SFrançois Tigeot * @cgs_device: opaque device handle 105c59a5c48SFrançois Tigeot * @offset: register offset 106c59a5c48SFrançois Tigeot * 107c59a5c48SFrançois Tigeot * Return: register value 108c59a5c48SFrançois Tigeot */ 109d78d3a22SFrançois Tigeot typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space, 110c59a5c48SFrançois Tigeot unsigned index); 111c59a5c48SFrançois Tigeot 112c59a5c48SFrançois Tigeot /** 113c59a5c48SFrançois Tigeot * cgs_write_ind_register() - Write an indirect register 114c59a5c48SFrançois Tigeot * @cgs_device: opaque device handle 115c59a5c48SFrançois Tigeot * @offset: register offset 116c59a5c48SFrançois Tigeot * @value: register value 117c59a5c48SFrançois Tigeot */ 118d78d3a22SFrançois Tigeot typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space, 119c59a5c48SFrançois Tigeot unsigned index, uint32_t value); 120c59a5c48SFrançois Tigeot 121*b843c749SSergey Zigachev #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 122*b843c749SSergey Zigachev #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK 123c59a5c48SFrançois Tigeot 124*b843c749SSergey Zigachev #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \ 125*b843c749SSergey Zigachev (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \ 126*b843c749SSergey Zigachev (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field)))) 127c59a5c48SFrançois Tigeot 128*b843c749SSergey Zigachev #define CGS_REG_GET_FIELD(value, reg, field) \ 129*b843c749SSergey Zigachev (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field)) 130c59a5c48SFrançois Tigeot 131*b843c749SSergey Zigachev #define CGS_WREG32_FIELD(device, reg, field, val) \ 132*b843c749SSergey Zigachev 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)) 133c59a5c48SFrançois Tigeot 134*b843c749SSergey Zigachev #define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \ 135*b843c749SSergey Zigachev 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)) 136c59a5c48SFrançois Tigeot 137d78d3a22SFrançois Tigeot typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device, 138c59a5c48SFrançois Tigeot enum cgs_ucode_id type, 139c59a5c48SFrançois Tigeot struct cgs_firmware_info *info); 140c59a5c48SFrançois Tigeot 141c59a5c48SFrançois Tigeot struct cgs_ops { 142c59a5c48SFrançois Tigeot /* MMIO access */ 143c59a5c48SFrançois Tigeot cgs_read_register_t read_register; 144c59a5c48SFrançois Tigeot cgs_write_register_t write_register; 145c59a5c48SFrançois Tigeot cgs_read_ind_register_t read_ind_register; 146c59a5c48SFrançois Tigeot cgs_write_ind_register_t write_ind_register; 147c59a5c48SFrançois Tigeot /* Firmware Info */ 148c59a5c48SFrançois Tigeot cgs_get_firmware_info get_firmware_info; 149c59a5c48SFrançois Tigeot }; 150c59a5c48SFrançois Tigeot 151c59a5c48SFrançois Tigeot struct cgs_os_ops; /* To be define in OS-specific CGS header */ 152c59a5c48SFrançois Tigeot 153c59a5c48SFrançois Tigeot struct cgs_device 154c59a5c48SFrançois Tigeot { 155c59a5c48SFrançois Tigeot const struct cgs_ops *ops; 156c59a5c48SFrançois Tigeot /* to be embedded at the start of driver private structure */ 157c59a5c48SFrançois Tigeot }; 158c59a5c48SFrançois Tigeot 159c59a5c48SFrançois Tigeot /* Convenience macros that make CGS indirect function calls look like 160c59a5c48SFrançois Tigeot * normal function calls */ 161c59a5c48SFrançois Tigeot #define CGS_CALL(func,dev,...) \ 162c59a5c48SFrançois Tigeot (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__)) 163c59a5c48SFrançois Tigeot #define CGS_OS_CALL(func,dev,...) \ 164c59a5c48SFrançois Tigeot (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__)) 165c59a5c48SFrançois Tigeot 166c59a5c48SFrançois Tigeot #define cgs_read_register(dev,offset) \ 167c59a5c48SFrançois Tigeot CGS_CALL(read_register,dev,offset) 168c59a5c48SFrançois Tigeot #define cgs_write_register(dev,offset,value) \ 169c59a5c48SFrançois Tigeot CGS_CALL(write_register,dev,offset,value) 170c59a5c48SFrançois Tigeot #define cgs_read_ind_register(dev,space,index) \ 171c59a5c48SFrançois Tigeot CGS_CALL(read_ind_register,dev,space,index) 172c59a5c48SFrançois Tigeot #define cgs_write_ind_register(dev,space,index,value) \ 173c59a5c48SFrançois Tigeot CGS_CALL(write_ind_register,dev,space,index,value) 174c59a5c48SFrançois Tigeot 175c59a5c48SFrançois Tigeot #define cgs_get_firmware_info(dev, type, info) \ 176c59a5c48SFrançois Tigeot CGS_CALL(get_firmware_info, dev, type, info) 177c59a5c48SFrançois Tigeot 178c59a5c48SFrançois Tigeot #endif /* _CGS_COMMON_H */ 179