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 | #include "amdgpu.h" |
| 25 | #include "cgs_linux.h" |
| 26 | |
| 27 | struct amdgpu_cgs_device { |
| 28 | struct cgs_device base; |
| 29 | struct amdgpu_device *adev; |
| 30 | }; |
| 31 | |
| 32 | #define CGS_FUNC_ADEV \ |
| 33 | struct amdgpu_device *adev = \ |
| 34 | ((struct amdgpu_cgs_device *)cgs_device)->adev |
| 35 | |
| 36 | static int amdgpu_cgs_gpu_mem_info(void *cgs_device, enum cgs_gpu_mem_type type, |
| 37 | uint64_t *mc_start, uint64_t *mc_size, |
| 38 | uint64_t *mem_size) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int amdgpu_cgs_gmap_kmem(void *cgs_device, void *kmem, |
| 44 | uint64_t size, |
| 45 | uint64_t min_offset, uint64_t max_offset, |
| 46 | cgs_handle_t *kmem_handle, uint64_t *mcaddr) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int amdgpu_cgs_gunmap_kmem(void *cgs_device, cgs_handle_t kmem_handle) |
| 52 | { |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int amdgpu_cgs_alloc_gpu_mem(void *cgs_device, |
| 57 | enum cgs_gpu_mem_type type, |
| 58 | uint64_t size, uint64_t align, |
| 59 | uint64_t min_offset, uint64_t max_offset, |
| 60 | cgs_handle_t *handle) |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int amdgpu_cgs_import_gpu_mem(void *cgs_device, int dmabuf_fd, |
| 66 | cgs_handle_t *handle) |
| 67 | { |
| 68 | /* TODO */ |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int amdgpu_cgs_free_gpu_mem(void *cgs_device, cgs_handle_t handle) |
| 73 | { |
| 74 | /* TODO */ |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | static int amdgpu_cgs_gmap_gpu_mem(void *cgs_device, cgs_handle_t handle, |
| 79 | uint64_t *mcaddr) |
| 80 | { |
| 81 | /* TODO */ |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int amdgpu_cgs_gunmap_gpu_mem(void *cgs_device, cgs_handle_t handle) |
| 86 | { |
| 87 | /* TODO */ |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static int amdgpu_cgs_kmap_gpu_mem(void *cgs_device, cgs_handle_t handle, |
| 92 | void **map) |
| 93 | { |
| 94 | /* TODO */ |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int amdgpu_cgs_kunmap_gpu_mem(void *cgs_device, cgs_handle_t handle) |
| 99 | { |
| 100 | /* TODO */ |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static uint32_t amdgpu_cgs_read_register(void *cgs_device, unsigned offset) |
| 105 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame^] | 106 | CGS_FUNC_ADEV; |
| 107 | return RREG32(offset); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static void amdgpu_cgs_write_register(void *cgs_device, unsigned offset, |
| 111 | uint32_t value) |
| 112 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame^] | 113 | CGS_FUNC_ADEV; |
| 114 | WREG32(offset, value); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static uint32_t amdgpu_cgs_read_ind_register(void *cgs_device, |
| 118 | enum cgs_ind_reg space, |
| 119 | unsigned index) |
| 120 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame^] | 121 | CGS_FUNC_ADEV; |
| 122 | switch (space) { |
| 123 | case CGS_IND_REG__MMIO: |
| 124 | return RREG32_IDX(index); |
| 125 | case CGS_IND_REG__PCIE: |
| 126 | return RREG32_PCIE(index); |
| 127 | case CGS_IND_REG__SMC: |
| 128 | return RREG32_SMC(index); |
| 129 | case CGS_IND_REG__UVD_CTX: |
| 130 | return RREG32_UVD_CTX(index); |
| 131 | case CGS_IND_REG__DIDT: |
| 132 | return RREG32_DIDT(index); |
| 133 | case CGS_IND_REG__AUDIO_ENDPT: |
| 134 | DRM_ERROR("audio endpt register access not implemented.\n"); |
| 135 | return 0; |
| 136 | } |
| 137 | WARN(1, "Invalid indirect register space"); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static void amdgpu_cgs_write_ind_register(void *cgs_device, |
| 142 | enum cgs_ind_reg space, |
| 143 | unsigned index, uint32_t value) |
| 144 | { |
Chunming Zhou | aba684d | 2015-05-22 11:29:30 -0400 | [diff] [blame^] | 145 | CGS_FUNC_ADEV; |
| 146 | switch (space) { |
| 147 | case CGS_IND_REG__MMIO: |
| 148 | return WREG32_IDX(index, value); |
| 149 | case CGS_IND_REG__PCIE: |
| 150 | return WREG32_PCIE(index, value); |
| 151 | case CGS_IND_REG__SMC: |
| 152 | return WREG32_SMC(index, value); |
| 153 | case CGS_IND_REG__UVD_CTX: |
| 154 | return WREG32_UVD_CTX(index, value); |
| 155 | case CGS_IND_REG__DIDT: |
| 156 | return WREG32_DIDT(index, value); |
| 157 | case CGS_IND_REG__AUDIO_ENDPT: |
| 158 | DRM_ERROR("audio endpt register access not implemented.\n"); |
| 159 | return; |
| 160 | } |
| 161 | WARN(1, "Invalid indirect register space"); |
Chunming Zhou | d03846a | 2015-07-28 14:20:03 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static uint8_t amdgpu_cgs_read_pci_config_byte(void *cgs_device, unsigned addr) |
| 165 | { |
| 166 | /* TODO */ |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static uint16_t amdgpu_cgs_read_pci_config_word(void *cgs_device, unsigned addr) |
| 171 | { |
| 172 | /* TODO */ |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static uint32_t amdgpu_cgs_read_pci_config_dword(void *cgs_device, |
| 177 | unsigned addr) |
| 178 | { |
| 179 | /* TODO */ |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | static void amdgpu_cgs_write_pci_config_byte(void *cgs_device, unsigned addr, |
| 184 | uint8_t value) |
| 185 | { |
| 186 | /* TODO */ |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | static void amdgpu_cgs_write_pci_config_word(void *cgs_device, unsigned addr, |
| 191 | uint16_t value) |
| 192 | { |
| 193 | /* TODO */ |
| 194 | return; |
| 195 | } |
| 196 | |
| 197 | static void amdgpu_cgs_write_pci_config_dword(void *cgs_device, unsigned addr, |
| 198 | uint32_t value) |
| 199 | { |
| 200 | /* TODO */ |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | static const void *amdgpu_cgs_atom_get_data_table(void *cgs_device, |
| 205 | unsigned table, uint16_t *size, |
| 206 | uint8_t *frev, uint8_t *crev) |
| 207 | { |
| 208 | /* TODO */ |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | static int amdgpu_cgs_atom_get_cmd_table_revs(void *cgs_device, unsigned table, |
| 213 | uint8_t *frev, uint8_t *crev) |
| 214 | { |
| 215 | /* TODO */ |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int amdgpu_cgs_atom_exec_cmd_table(void *cgs_device, unsigned table, |
| 220 | void *args) |
| 221 | { |
| 222 | /* TODO */ |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | static int amdgpu_cgs_create_pm_request(void *cgs_device, cgs_handle_t *request) |
| 228 | { |
| 229 | /* TODO */ |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | static int amdgpu_cgs_destroy_pm_request(void *cgs_device, cgs_handle_t request) |
| 234 | { |
| 235 | /* TODO */ |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int amdgpu_cgs_set_pm_request(void *cgs_device, cgs_handle_t request, |
| 240 | int active) |
| 241 | { |
| 242 | /* TODO */ |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int amdgpu_cgs_pm_request_clock(void *cgs_device, cgs_handle_t request, |
| 247 | enum cgs_clock clock, unsigned freq) |
| 248 | { |
| 249 | /* TODO */ |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int amdgpu_cgs_pm_request_engine(void *cgs_device, cgs_handle_t request, |
| 254 | enum cgs_engine engine, int powered) |
| 255 | { |
| 256 | /* TODO */ |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | |
| 261 | |
| 262 | static int amdgpu_cgs_pm_query_clock_limits(void *cgs_device, |
| 263 | enum cgs_clock clock, |
| 264 | struct cgs_clock_limits *limits) |
| 265 | { |
| 266 | /* TODO */ |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int amdgpu_cgs_set_camera_voltages(void *cgs_device, uint32_t mask, |
| 271 | const uint32_t *voltages) |
| 272 | { |
| 273 | DRM_ERROR("not implemented"); |
| 274 | return -EPERM; |
| 275 | } |
| 276 | |
| 277 | static int amdgpu_cgs_add_irq_source(void *cgs_device, unsigned src_id, |
| 278 | unsigned num_types, |
| 279 | cgs_irq_source_set_func_t set, |
| 280 | cgs_irq_handler_func_t handler, |
| 281 | void *private_data) |
| 282 | { |
| 283 | /* TODO */ |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static int amdgpu_cgs_irq_get(void *cgs_device, unsigned src_id, unsigned type) |
| 288 | { |
| 289 | /* TODO */ |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int amdgpu_cgs_irq_put(void *cgs_device, unsigned src_id, unsigned type) |
| 294 | { |
| 295 | /* TODO */ |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static const struct cgs_ops amdgpu_cgs_ops = { |
| 300 | amdgpu_cgs_gpu_mem_info, |
| 301 | amdgpu_cgs_gmap_kmem, |
| 302 | amdgpu_cgs_gunmap_kmem, |
| 303 | amdgpu_cgs_alloc_gpu_mem, |
| 304 | amdgpu_cgs_free_gpu_mem, |
| 305 | amdgpu_cgs_gmap_gpu_mem, |
| 306 | amdgpu_cgs_gunmap_gpu_mem, |
| 307 | amdgpu_cgs_kmap_gpu_mem, |
| 308 | amdgpu_cgs_kunmap_gpu_mem, |
| 309 | amdgpu_cgs_read_register, |
| 310 | amdgpu_cgs_write_register, |
| 311 | amdgpu_cgs_read_ind_register, |
| 312 | amdgpu_cgs_write_ind_register, |
| 313 | amdgpu_cgs_read_pci_config_byte, |
| 314 | amdgpu_cgs_read_pci_config_word, |
| 315 | amdgpu_cgs_read_pci_config_dword, |
| 316 | amdgpu_cgs_write_pci_config_byte, |
| 317 | amdgpu_cgs_write_pci_config_word, |
| 318 | amdgpu_cgs_write_pci_config_dword, |
| 319 | amdgpu_cgs_atom_get_data_table, |
| 320 | amdgpu_cgs_atom_get_cmd_table_revs, |
| 321 | amdgpu_cgs_atom_exec_cmd_table, |
| 322 | amdgpu_cgs_create_pm_request, |
| 323 | amdgpu_cgs_destroy_pm_request, |
| 324 | amdgpu_cgs_set_pm_request, |
| 325 | amdgpu_cgs_pm_request_clock, |
| 326 | amdgpu_cgs_pm_request_engine, |
| 327 | amdgpu_cgs_pm_query_clock_limits, |
| 328 | amdgpu_cgs_set_camera_voltages |
| 329 | }; |
| 330 | |
| 331 | static const struct cgs_os_ops amdgpu_cgs_os_ops = { |
| 332 | amdgpu_cgs_import_gpu_mem, |
| 333 | amdgpu_cgs_add_irq_source, |
| 334 | amdgpu_cgs_irq_get, |
| 335 | amdgpu_cgs_irq_put |
| 336 | }; |
| 337 | |
| 338 | void *amdgpu_cgs_create_device(struct amdgpu_device *adev) |
| 339 | { |
| 340 | struct amdgpu_cgs_device *cgs_device = |
| 341 | kmalloc(sizeof(*cgs_device), GFP_KERNEL); |
| 342 | |
| 343 | if (!cgs_device) { |
| 344 | DRM_ERROR("Couldn't allocate CGS device structure\n"); |
| 345 | return NULL; |
| 346 | } |
| 347 | |
| 348 | cgs_device->base.ops = &amdgpu_cgs_ops; |
| 349 | cgs_device->base.os_ops = &amdgpu_cgs_os_ops; |
| 350 | cgs_device->adev = adev; |
| 351 | |
| 352 | return cgs_device; |
| 353 | } |
| 354 | |
| 355 | void amdgpu_cgs_destroy_device(void *cgs_device) |
| 356 | { |
| 357 | kfree(cgs_device); |
| 358 | } |