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