1 /* 2 * Copyright 2008 Advanced Micro Devices, Inc. 3 * Copyright 2008 Red Hat Inc. 4 * Copyright 2009 Jerome Glisse. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Dave Airlie 25 * Alex Deucher 26 * Jerome Glisse 27 */ 28 #ifndef __AMDGPU_H__ 29 #define __AMDGPU_H__ 30 31 #ifdef pr_fmt 32 #undef pr_fmt 33 #endif 34 35 #define pr_fmt(fmt) "amdgpu: " fmt 36 37 #include "amdgpu_ctx.h" 38 39 #include <linux/atomic.h> 40 #include <linux/wait.h> 41 #include <linux/list.h> 42 #include <linux/kref.h> 43 #include <linux/rbtree.h> 44 #include <linux/hashtable.h> 45 #include <linux/dma-fence.h> 46 #include <linux/pci.h> 47 #include <linux/xarray.h> 48 49 #include <drm/ttm/ttm_bo.h> 50 #include <drm/ttm/ttm_placement.h> 51 52 #include <drm/amdgpu_drm.h> 53 #include <drm/drm_gem.h> 54 #include <drm/drm_ioctl.h> 55 56 #include <kgd_kfd_interface.h> 57 #include "dm_pp_interface.h" 58 #include "kgd_pp_interface.h" 59 60 #include "amd_shared.h" 61 #include "amdgpu_utils.h" 62 #include "amdgpu_mode.h" 63 #include "amdgpu_ih.h" 64 #include "amdgpu_irq.h" 65 #include "amdgpu_ucode.h" 66 #include "amdgpu_ttm.h" 67 #include "amdgpu_psp.h" 68 #include "amdgpu_gds.h" 69 #include "amdgpu_sync.h" 70 #include "amdgpu_ring.h" 71 #include "amdgpu_vm.h" 72 #include "amdgpu_dpm.h" 73 #include "amdgpu_acp.h" 74 #include "amdgpu_uvd.h" 75 #include "amdgpu_vce.h" 76 #include "amdgpu_vcn.h" 77 #include "amdgpu_jpeg.h" 78 #include "amdgpu_vpe.h" 79 #include "amdgpu_umsch_mm.h" 80 #include "amdgpu_gmc.h" 81 #include "amdgpu_gfx.h" 82 #include "amdgpu_sdma_types.h" 83 #include "amdgpu_lsdma.h" 84 #include "amdgpu_nbio.h" 85 #include "amdgpu_reg_access.h" 86 #include "amdgpu_hdp.h" 87 #include "amdgpu_dm.h" 88 #include "amdgpu_virt.h" 89 #include "amdgpu_csa.h" 90 #include "amdgpu_mes_ctx.h" 91 #include "amdgpu_gart.h" 92 #include "amdgpu_debugfs.h" 93 #include "amdgpu_job.h" 94 #include "amdgpu_bo_list.h" 95 #include "amdgpu_gem.h" 96 #include "amdgpu_doorbell.h" 97 #include "amdgpu_amdkfd.h" 98 #include "amdgpu_discovery.h" 99 #include "amdgpu_umc.h" 100 #include "amdgpu_mmhub.h" 101 #include "amdgpu_gfxhub.h" 102 #include "amdgpu_df.h" 103 #include "amdgpu_smuio.h" 104 #include "amdgpu_fdinfo.h" 105 #include "amdgpu_mca.h" 106 #include "amdgpu_ras.h" 107 #include "amdgpu_lockdep.h" 108 #include "amdgpu_cper.h" 109 #include "amdgpu_xcp.h" 110 #include "amdgpu_seq64.h" 111 #include "amdgpu_reg_state.h" 112 #include "amdgpu_userq.h" 113 #include "amdgpu_eviction_fence.h" 114 #include "amdgpu_wb.h" 115 #include "amdgpu_ip.h" 116 #include "amdgpu_mes.h" 117 #include "amdgpu_sa.h" 118 #include "amdgpu_acpi.h" 119 #include "amdgpu_ualink.h" 120 #if defined(CONFIG_DRM_AMD_ISP) 121 #include "amdgpu_isp.h" 122 #endif 123 124 #define MAX_GPU_INSTANCE 64 125 126 #define GFX_SLICE_PERIOD_MS 250 127 128 struct amdgpu_gpu_instance { 129 struct amdgpu_device *adev; 130 int mgpu_fan_enabled; 131 }; 132 133 struct amdgpu_mgpu_info { 134 struct amdgpu_gpu_instance gpu_ins[MAX_GPU_INSTANCE]; 135 struct mutex mutex; 136 uint32_t num_gpu; 137 uint32_t num_dgpu; 138 uint32_t num_apu; 139 }; 140 141 struct amdgpu_hwip_reg_entry { 142 u32 hwip; 143 u32 inst; 144 u32 seg; 145 u32 reg_offset; 146 const char *reg_name; 147 }; 148 149 struct amdgpu_watchdog_timer { 150 bool timeout_fatal_disable; 151 uint32_t period; /* maxCycles = (1 << period), the number of cycles before a timeout */ 152 }; 153 154 #define AMDGPU_MAX_TIMEOUT_PARAM_LENGTH 256 155 156 /* 157 * Modules parameters. 158 */ 159 extern int amdgpu_modeset; 160 extern unsigned int amdgpu_vram_limit; 161 extern int amdgpu_vis_vram_limit; 162 extern int amdgpu_gart_size; 163 extern int amdgpu_gtt_size; 164 extern int amdgpu_moverate; 165 extern int amdgpu_audio; 166 extern int amdgpu_disp_priority; 167 extern int amdgpu_hw_i2c; 168 extern int amdgpu_pcie_gen2; 169 extern int amdgpu_msi; 170 extern char amdgpu_lockup_timeout[AMDGPU_MAX_TIMEOUT_PARAM_LENGTH]; 171 extern int amdgpu_dpm; 172 extern int amdgpu_fw_load_type; 173 extern int amdgpu_aspm; 174 extern int amdgpu_runtime_pm; 175 extern uint amdgpu_ip_block_mask; 176 extern int amdgpu_bapm; 177 extern int amdgpu_deep_color; 178 extern int amdgpu_vm_size; 179 extern int amdgpu_vm_block_size; 180 extern int amdgpu_vm_fragment_size; 181 extern int amdgpu_vm_fault_stop; 182 extern int amdgpu_vm_debug; 183 extern int amdgpu_vm_update_mode; 184 extern int amdgpu_exp_hw_support; 185 extern int amdgpu_dc; 186 extern int amdgpu_sched_jobs; 187 extern int amdgpu_sched_hw_submission; 188 extern uint amdgpu_pcie_gen_cap; 189 extern uint amdgpu_pcie_lane_cap; 190 extern u64 amdgpu_cg_mask; 191 extern uint amdgpu_pg_mask; 192 extern uint amdgpu_sdma_phase_quantum; 193 extern char *amdgpu_disable_cu; 194 extern char *amdgpu_virtual_display; 195 extern uint amdgpu_pp_feature_mask; 196 extern uint amdgpu_force_long_training; 197 extern int amdgpu_lbpw; 198 extern int amdgpu_compute_multipipe; 199 extern int amdgpu_gpu_recovery; 200 extern int amdgpu_emu_mode; 201 extern uint amdgpu_smu_memory_pool_size; 202 extern int amdgpu_smu_pptable_id; 203 extern uint amdgpu_dc_feature_mask; 204 extern uint amdgpu_freesync_vid_mode; 205 extern uint amdgpu_dc_debug_mask; 206 extern uint amdgpu_dc_visual_confirm; 207 extern int amdgpu_dm_abm_level; 208 extern int amdgpu_backlight; 209 extern int amdgpu_damage_clips; 210 extern struct amdgpu_mgpu_info mgpu_info; 211 extern int amdgpu_ras_enable; 212 extern u64 amdgpu_ras_mask; 213 extern int amdgpu_bad_page_threshold; 214 extern bool amdgpu_ignore_bad_page_threshold; 215 extern struct amdgpu_watchdog_timer amdgpu_watchdog_timer; 216 extern int amdgpu_async_gfx_ring; 217 extern int amdgpu_mcbp; 218 extern int amdgpu_discovery; 219 extern int amdgpu_mes_log_enable; 220 extern int amdgpu_mes_dbgext_buffer_size; 221 extern int amdgpu_mes_dbgext_options; 222 extern int amdgpu_uni_mes; 223 extern int amdgpu_noretry; 224 extern int amdgpu_force_asic_type; 225 extern int amdgpu_smartshift_bias; 226 extern int amdgpu_use_xgmi_p2p; 227 extern int amdgpu_mtype_local; 228 extern int amdgpu_mtype_remote; 229 extern int amdgpu_enforce_isolation; 230 extern uint amdgpu_debug_mask; 231 #ifdef CONFIG_HSA_AMD 232 extern int sched_policy; 233 extern bool debug_evictions; 234 extern bool no_system_mem_limit; 235 extern int halt_if_hws_hang; 236 extern uint amdgpu_svm_default_granularity; 237 #else 238 static const int __maybe_unused sched_policy = KFD_SCHED_POLICY_HWS; 239 static const bool __maybe_unused debug_evictions; /* = false */ 240 static const bool __maybe_unused no_system_mem_limit; 241 static const int __maybe_unused halt_if_hws_hang; 242 #endif 243 #ifdef CONFIG_HSA_AMD_P2P 244 extern bool pcie_p2p; 245 #endif 246 247 extern int amdgpu_tmz; 248 extern int amdgpu_reset_method; 249 250 #ifdef CONFIG_DRM_AMDGPU_SI 251 extern int amdgpu_si_support; 252 #endif 253 #ifdef CONFIG_DRM_AMDGPU_CIK 254 extern int amdgpu_cik_support; 255 #endif 256 extern int amdgpu_num_kcq; 257 258 #define AMDGPU_VCNFW_LOG_SIZE (32 * 1024) 259 #define AMDGPU_UMSCHFW_LOG_SIZE (32 * 1024) 260 extern int amdgpu_vcnfw_log; 261 extern int amdgpu_sg_display; 262 extern int amdgpu_umsch_mm; 263 extern int amdgpu_seamless; 264 extern int amdgpu_umsch_mm_fwlog; 265 266 extern int amdgpu_user_partt_mode; 267 extern int amdgpu_agp; 268 extern int amdgpu_rebar; 269 270 extern int amdgpu_wbrf; 271 extern int amdgpu_user_queue; 272 extern int amdgpu_ptl; 273 274 extern uint amdgpu_hdmi_hpd_debounce_delay_ms; 275 276 #define AMDGPU_SG_THRESHOLD (256*1024*1024) 277 #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000 278 #define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 279 #define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2) 280 #define AMDGPU_DEBUGFS_MAX_COMPONENTS 32 281 #define AMDGPUFB_CONN_LIMIT 4 282 #define AMDGPU_BIOS_NUM_SCRATCH 16 283 284 #define AMDGPU_VBIOS_VGA_ALLOCATION (9 * 1024 * 1024) /* reserve 8MB for vga emulator and 1 MB for FB */ 285 286 /* hard reset data */ 287 #define AMDGPU_ASIC_RESET_DATA 0x39d5e86b 288 289 /* reset flags */ 290 #define AMDGPU_RESET_GFX (1 << 0) 291 #define AMDGPU_RESET_COMPUTE (1 << 1) 292 #define AMDGPU_RESET_DMA (1 << 2) 293 #define AMDGPU_RESET_CP (1 << 3) 294 #define AMDGPU_RESET_GRBM (1 << 4) 295 #define AMDGPU_RESET_DMA1 (1 << 5) 296 #define AMDGPU_RESET_RLC (1 << 6) 297 #define AMDGPU_RESET_SEM (1 << 7) 298 #define AMDGPU_RESET_IH (1 << 8) 299 #define AMDGPU_RESET_VMC (1 << 9) 300 #define AMDGPU_RESET_MC (1 << 10) 301 #define AMDGPU_RESET_DISPLAY (1 << 11) 302 #define AMDGPU_RESET_UVD (1 << 12) 303 #define AMDGPU_RESET_VCE (1 << 13) 304 #define AMDGPU_RESET_VCE1 (1 << 14) 305 306 /* reset mask */ 307 #define AMDGPU_RESET_TYPE_FULL (1 << 0) /* full adapter reset, mode1/mode2/BACO/etc. */ 308 #define AMDGPU_RESET_TYPE_SOFT_RECOVERY (1 << 1) /* soft recovery, eg. kill shaders */ 309 #define AMDGPU_RESET_TYPE_PER_QUEUE (1 << 2) /* per queue */ 310 #define AMDGPU_RESET_TYPE_PER_PIPE (1 << 3) /* per pipe */ 311 #define AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET (1 << 4) /* soft-resets an IP block */ 312 313 /* max cursor sizes (in pixels) */ 314 #define CIK_CURSOR_WIDTH 128 315 #define CIK_CURSOR_HEIGHT 128 316 317 /* smart shift bias level limits */ 318 #define AMDGPU_SMARTSHIFT_MAX_BIAS (100) 319 #define AMDGPU_SMARTSHIFT_MIN_BIAS (-100) 320 321 /* Extra time delay(in ms) to eliminate the influence of temperature momentary fluctuation */ 322 #define AMDGPU_SWCTF_EXTRA_DELAY 50 323 324 struct amdgpu_xcp_mgr; 325 struct amdgpu_device; 326 struct amdgpu_irq_src; 327 struct amdgpu_fpriv; 328 struct amdgpu_bo_va_mapping; 329 struct kfd_vm_fault_info; 330 struct amdgpu_hive_info; 331 struct amdgpu_reset_context; 332 struct amdgpu_reset_control; 333 struct amdgpu_coredump_info; 334 struct amdgpu_video_codecs; 335 336 enum amdgpu_cp_irq { 337 AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0, 338 AMDGPU_CP_IRQ_GFX_ME0_PIPE1_EOP, 339 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP, 340 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP, 341 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP, 342 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP, 343 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP, 344 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP, 345 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP, 346 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP, 347 348 AMDGPU_CP_IRQ_LAST 349 }; 350 351 enum amdgpu_thermal_irq { 352 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0, 353 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW, 354 355 AMDGPU_THERMAL_IRQ_LAST 356 }; 357 358 enum amdgpu_kiq_irq { 359 AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0, 360 AMDGPU_CP_KIQ_IRQ_LAST 361 }; 362 #define MAX_KIQ_REG_WAIT 5000 /* in usecs, 5ms */ 363 #define MAX_KIQ_REG_BAILOUT_INTERVAL 5 /* in msecs, 5ms */ 364 #define MAX_KIQ_REG_TRY 1000 365 366 /* 367 * BIOS. 368 */ 369 bool amdgpu_get_bios(struct amdgpu_device *adev); 370 bool amdgpu_read_bios(struct amdgpu_device *adev); 371 bool amdgpu_soc15_read_bios_from_rom(struct amdgpu_device *adev, 372 u8 *bios, u32 length_bytes); 373 void amdgpu_bios_release(struct amdgpu_device *adev); 374 /* 375 * Clocks 376 */ 377 378 #define AMDGPU_MAX_PPLL 3 379 380 struct amdgpu_clock { 381 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL]; 382 struct amdgpu_pll spll; 383 struct amdgpu_pll mpll; 384 /* 10 Khz units */ 385 uint32_t default_mclk; 386 uint32_t default_sclk; 387 uint32_t default_dispclk; 388 uint32_t dp_extclk; 389 uint32_t max_pixel_clock; 390 }; 391 392 /* 393 * IRQS. 394 */ 395 396 struct amdgpu_flip_work { 397 struct delayed_work flip_work; 398 struct work_struct unpin_work; 399 struct amdgpu_device *adev; 400 int crtc_id; 401 u32 target_vblank; 402 uint64_t base; 403 struct drm_pending_vblank_event *event; 404 struct amdgpu_bo *old_abo; 405 unsigned shared_count; 406 struct dma_fence **shared; 407 struct dma_fence_cb cb; 408 bool async; 409 }; 410 411 /* 412 * file private structure 413 */ 414 415 struct amdgpu_fpriv { 416 struct amdgpu_vm vm; 417 struct amdgpu_bo_va *prt_va; 418 struct amdgpu_bo_va *csa_va; 419 struct amdgpu_bo_va *seq64_va; 420 struct xarray bo_list_handles; 421 struct amdgpu_ctx_mgr ctx_mgr; 422 struct amdgpu_userq_mgr userq_mgr; 423 424 /* Eviction fence infra */ 425 struct amdgpu_eviction_fence_mgr evf_mgr; 426 427 /** GPU partition selection */ 428 uint32_t xcp_id; 429 }; 430 431 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv); 432 433 /* 434 * Benchmarking 435 */ 436 int amdgpu_benchmark(struct amdgpu_device *adev, int test_number); 437 438 /* 439 * ASIC specific functions. 440 */ 441 struct amdgpu_asic_funcs { 442 bool (*read_disabled_bios)(struct amdgpu_device *adev); 443 bool (*read_bios_from_rom)(struct amdgpu_device *adev, 444 u8 *bios, u32 length_bytes); 445 int (*read_register)(struct amdgpu_device *adev, u32 se_num, 446 u32 sh_num, u32 reg_offset, u32 *value); 447 void (*set_vga_state)(struct amdgpu_device *adev, bool state); 448 int (*reset)(struct amdgpu_device *adev); 449 enum amd_reset_method (*reset_method)(struct amdgpu_device *adev); 450 /* get the reference clock */ 451 u32 (*get_xclk)(struct amdgpu_device *adev); 452 /* MM block clocks */ 453 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 454 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 455 /* static power management */ 456 int (*get_pcie_lanes)(struct amdgpu_device *adev); 457 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes); 458 /* get config memsize register */ 459 u32 (*get_config_memsize)(struct amdgpu_device *adev); 460 /* flush hdp write queue */ 461 void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring); 462 /* invalidate hdp read cache */ 463 void (*invalidate_hdp)(struct amdgpu_device *adev, 464 struct amdgpu_ring *ring); 465 /* initialize doorbell layout for specific asic*/ 466 void (*init_doorbell_index)(struct amdgpu_device *adev); 467 /* PCIe bandwidth usage */ 468 void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t *count0, 469 uint64_t *count1); 470 /* do we need to reset the asic at init time (e.g., kexec) */ 471 bool (*need_reset_on_init)(struct amdgpu_device *adev); 472 /* PCIe replay counter */ 473 uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev); 474 /* device supports BACO */ 475 int (*supports_baco)(struct amdgpu_device *adev); 476 /* pre asic_init quirks */ 477 void (*pre_asic_init)(struct amdgpu_device *adev); 478 /* enter/exit umd stable pstate */ 479 int (*update_umd_stable_pstate)(struct amdgpu_device *adev, bool enter); 480 /* query video codecs */ 481 int (*query_video_codecs)(struct amdgpu_device *adev, bool encode, 482 const struct amdgpu_video_codecs **codecs); 483 /* encode "> 32bits" smn addressing */ 484 u64 (*encode_ext_smn_addressing)(int ext_id); 485 486 ssize_t (*get_reg_state)(struct amdgpu_device *adev, 487 enum amdgpu_reg_state reg_state, void *buf, 488 size_t max_size); 489 /* query FW reserved region (size/offset) from discovery */ 490 void (*get_fw_reserved_info)(struct amdgpu_device *adev, 491 u64 *reserve_size, u64 *offset); 492 }; 493 494 /* 495 * IOCTL. 496 */ 497 int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, 498 struct drm_file *filp); 499 500 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 501 int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, 502 struct drm_file *filp); 503 int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); 504 int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, 505 struct drm_file *filp); 506 507 /* VRAM scratch page for HDP bug, default vram page */ 508 struct amdgpu_mem_scratch { 509 struct amdgpu_bo *robj; 510 uint32_t *ptr; 511 u64 gpu_addr; 512 }; 513 514 /* 515 * CGS 516 */ 517 struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev); 518 void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 519 520 /* 521 * Core structure, functions and helpers. 522 */ 523 struct amdgpu_mmio_remap { 524 u32 reg_offset; 525 resource_size_t bus_addr; 526 struct amdgpu_bo *bo; 527 }; 528 529 enum amdgpu_uid_type { 530 AMDGPU_UID_TYPE_XCD, 531 AMDGPU_UID_TYPE_AID, 532 AMDGPU_UID_TYPE_SOC, 533 AMDGPU_UID_TYPE_MID, 534 AMDGPU_UID_TYPE_MAX 535 }; 536 537 #define AMDGPU_UID_INST_MAX 8 /* max number of instances for each UID type */ 538 539 struct amdgpu_uid { 540 uint64_t uid[AMDGPU_UID_TYPE_MAX][AMDGPU_UID_INST_MAX]; 541 struct amdgpu_device *adev; 542 }; 543 544 struct amd_powerplay { 545 void *pp_handle; 546 const struct amd_pm_funcs *pp_funcs; 547 }; 548 549 /* polaris10 kickers */ 550 #define ASICID_IS_P20(did, rid) (((did == 0x67DF) && \ 551 ((rid == 0xE3) || \ 552 (rid == 0xE4) || \ 553 (rid == 0xE5) || \ 554 (rid == 0xE7) || \ 555 (rid == 0xEF))) || \ 556 ((did == 0x6FDF) && \ 557 ((rid == 0xE7) || \ 558 (rid == 0xEF) || \ 559 (rid == 0xFF)))) 560 561 #define ASICID_IS_P30(did, rid) ((did == 0x67DF) && \ 562 ((rid == 0xE1) || \ 563 (rid == 0xF7))) 564 565 /* polaris11 kickers */ 566 #define ASICID_IS_P21(did, rid) (((did == 0x67EF) && \ 567 ((rid == 0xE0) || \ 568 (rid == 0xE5))) || \ 569 ((did == 0x67FF) && \ 570 ((rid == 0xCF) || \ 571 (rid == 0xEF) || \ 572 (rid == 0xFF)))) 573 574 #define ASICID_IS_P31(did, rid) ((did == 0x67EF) && \ 575 ((rid == 0xE2))) 576 577 /* polaris12 kickers */ 578 #define ASICID_IS_P23(did, rid) (((did == 0x6987) && \ 579 ((rid == 0xC0) || \ 580 (rid == 0xC1) || \ 581 (rid == 0xC3) || \ 582 (rid == 0xC7))) || \ 583 ((did == 0x6981) && \ 584 ((rid == 0x00) || \ 585 (rid == 0x01) || \ 586 (rid == 0x10)))) 587 588 struct amdgpu_pcie_reset_ctx { 589 bool in_link_reset; 590 bool occurs_dpc; 591 bool audio_suspended; 592 struct pci_dev *swus; 593 struct pci_saved_state *swus_pcistate; 594 struct pci_saved_state *swds_pcistate; 595 }; 596 597 /* 598 * Custom Init levels could be defined for different situations where a full 599 * initialization of all hardware blocks are not expected. Sample cases are 600 * custom init sequences after resume after S0i3/S3, reset on initialization, 601 * partial reset of blocks etc. Presently, this defines only two levels. Levels 602 * are described in corresponding struct definitions - amdgpu_init_default, 603 * amdgpu_init_minimal_xgmi. 604 */ 605 enum amdgpu_init_lvl_id { 606 AMDGPU_INIT_LEVEL_DEFAULT, 607 AMDGPU_INIT_LEVEL_MINIMAL_XGMI, 608 AMDGPU_INIT_LEVEL_RESET_RECOVERY, 609 }; 610 611 struct amdgpu_init_level { 612 enum amdgpu_init_lvl_id level; 613 uint32_t hwini_ip_block_mask; 614 }; 615 616 #define AMDGPU_RESET_MAGIC_NUM 64 617 #define AMDGPU_MAX_DF_PERFMONS 4 618 struct amdgpu_reset_domain; 619 struct amdgpu_fru_info; 620 621 enum amdgpu_enforce_isolation_mode { 622 AMDGPU_ENFORCE_ISOLATION_DISABLE = 0, 623 AMDGPU_ENFORCE_ISOLATION_ENABLE = 1, 624 AMDGPU_ENFORCE_ISOLATION_ENABLE_LEGACY = 2, 625 AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER = 3, 626 }; 627 628 struct amdgpu_device { 629 struct device *dev; 630 struct pci_dev *pdev; 631 /* The two ends of the physical PCIe link outside the device. */ 632 struct pci_dev *link_dev; 633 struct pci_dev *link_partner; 634 struct drm_device ddev; 635 636 #ifdef CONFIG_DRM_AMD_ACP 637 struct amdgpu_acp acp; 638 #endif 639 struct amdgpu_hive_info *hive; 640 struct amdgpu_xcp_mgr *xcp_mgr; 641 /* ASIC */ 642 enum amd_asic_type asic_type; 643 uint32_t family; 644 uint32_t rev_id; 645 uint32_t external_rev_id; 646 unsigned long flags; 647 unsigned long apu_flags; 648 int usec_timeout; 649 const struct amdgpu_asic_funcs *asic_funcs; 650 bool shutdown; 651 bool need_swiotlb; 652 bool accel_working; 653 struct notifier_block acpi_nb; 654 struct notifier_block pm_nb; 655 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS]; 656 struct debugfs_blob_wrapper debugfs_vbios_blob; 657 struct mutex srbm_mutex; 658 /* GRBM index mutex. Protects concurrent access to GRBM index */ 659 struct mutex grbm_idx_mutex; 660 struct dev_pm_domain vga_pm_domain; 661 bool have_disp_power_ref; 662 bool have_atomics_support; 663 bool is_sw_smu; 664 665 /* BIOS */ 666 bool is_atom_fw; 667 uint8_t *bios; 668 uint32_t bios_size; 669 uint32_t bios_scratch_reg_offset; 670 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH]; 671 672 /* Register/doorbell mmio */ 673 resource_size_t rmmio_base; 674 resource_size_t rmmio_size; 675 void __iomem *rmmio; 676 /* protects concurrent MM_INDEX/DATA based register access */ 677 spinlock_t mmio_idx_lock; 678 struct amdgpu_mmio_remap rmmio_remap; 679 /* Indirect register access blocks */ 680 struct amdgpu_reg_access reg; 681 struct amdgpu_doorbell doorbell; 682 683 /* clock/pll info */ 684 struct amdgpu_clock clock; 685 686 /* MC */ 687 struct amdgpu_gmc gmc; 688 struct amdgpu_gart gart; 689 dma_addr_t dummy_page_addr; 690 struct amdgpu_vm_manager vm_manager; 691 struct amdgpu_vmhub vmhub[AMDGPU_MAX_VMHUBS]; 692 DECLARE_BITMAP(vmhubs_mask, AMDGPU_MAX_VMHUBS); 693 694 /* memory management */ 695 struct amdgpu_mman mman; 696 struct amdgpu_mem_scratch mem_scratch; 697 struct amdgpu_wb wb; 698 atomic64_t num_bytes_moved; 699 atomic64_t num_evictions; 700 atomic64_t num_vram_cpu_page_faults; 701 atomic_t gpu_reset_counter; 702 atomic_t vram_lost_counter; 703 704 /* data for buffer migration throttling */ 705 struct { 706 spinlock_t lock; 707 s64 last_update_us; 708 s64 accum_us; /* accumulated microseconds */ 709 s64 accum_us_vis; /* for visible VRAM */ 710 u32 log2_max_MBps; 711 } mm_stats; 712 713 /* discovery*/ 714 struct amdgpu_discovery_info discovery; 715 716 /* display */ 717 bool enable_virtual_display; 718 struct amdgpu_vkms_output *amdgpu_vkms_output; 719 struct amdgpu_mode_info mode_info; 720 /* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */ 721 struct delayed_work hotplug_work; 722 struct amdgpu_irq_src crtc_irq; 723 struct amdgpu_irq_src vline0_irq; 724 struct amdgpu_irq_src vupdate_irq; 725 struct amdgpu_irq_src pageflip_irq; 726 struct amdgpu_irq_src hpd_irq; 727 struct amdgpu_irq_src dmub_trace_irq; 728 struct amdgpu_irq_src dmub_outbox_irq; 729 730 /* rings */ 731 u64 fence_context; 732 unsigned num_rings; 733 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS]; 734 struct dma_fence __rcu *gang_submit; 735 bool ib_pool_ready; 736 struct amdgpu_sa_manager ib_pools[AMDGPU_IB_POOL_MAX]; 737 struct amdgpu_sched gpu_sched[AMDGPU_HW_IP_NUM][AMDGPU_RING_PRIO_MAX]; 738 739 /* interrupts */ 740 struct amdgpu_irq irq; 741 742 /* powerplay */ 743 struct amd_powerplay powerplay; 744 struct amdgpu_pm pm; 745 u64 cg_flags; 746 u32 pg_flags; 747 748 /* nbio */ 749 struct amdgpu_nbio nbio; 750 751 /* hdp */ 752 struct amdgpu_hdp hdp; 753 754 /* smuio */ 755 struct amdgpu_smuio smuio; 756 757 /* mmhub */ 758 struct amdgpu_mmhub mmhub; 759 760 /* gfxhub */ 761 struct amdgpu_gfxhub gfxhub; 762 763 /* gfx */ 764 struct amdgpu_gfx gfx; 765 766 /* sdma */ 767 struct amdgpu_sdma sdma; 768 769 /* lsdma */ 770 struct amdgpu_lsdma lsdma; 771 772 /* uvd */ 773 struct amdgpu_uvd uvd; 774 775 /* vce */ 776 struct amdgpu_vce vce; 777 778 /* vcn */ 779 struct amdgpu_vcn vcn; 780 781 /* jpeg */ 782 struct amdgpu_jpeg jpeg; 783 784 /* vpe */ 785 struct amdgpu_vpe vpe; 786 787 /* umsch */ 788 struct amdgpu_umsch_mm umsch_mm; 789 bool enable_umsch_mm; 790 791 /* firmwares */ 792 struct amdgpu_firmware firmware; 793 794 /* PSP */ 795 struct psp_context psp; 796 797 /* GDS */ 798 struct amdgpu_gds gds; 799 800 /* for userq and VM fences */ 801 struct amdgpu_seq64 seq64; 802 803 /* UMC */ 804 struct amdgpu_umc umc; 805 806 /* display related functionality */ 807 struct amdgpu_display_manager dm; 808 809 /* UALink manager */ 810 struct amdgpu_ualink_mgr ualink; 811 812 #if defined(CONFIG_DRM_AMD_ISP) 813 /* isp */ 814 struct amdgpu_isp isp; 815 #endif 816 817 /* mes */ 818 bool enable_mes; 819 bool enable_mes_kiq; 820 bool enable_uni_mes; 821 struct amdgpu_mes mes; 822 struct amdgpu_mqd mqds[AMDGPU_HW_IP_NUM]; 823 const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM]; 824 825 /** 826 * @userq_doorbell_xa: Global user queue map (doorbell index → queue) 827 * Key: doorbell_index (unique global identifier for the queue) 828 * Value: struct amdgpu_usermode_queue 829 */ 830 struct xarray userq_doorbell_xa; 831 832 /* df */ 833 struct amdgpu_df df; 834 835 /* MCA */ 836 struct amdgpu_mca mca; 837 838 /* CPER */ 839 struct amdgpu_cper cper; 840 841 struct amdgpu_ip_block ip_blocks[AMDGPU_MAX_IP_NUM]; 842 uint32_t harvest_ip_mask; 843 int num_ip_blocks; 844 struct mutex mn_lock; 845 DECLARE_HASHTABLE(mn_hash, 7); 846 847 /* tracking pinned memory 848 * 849 * vram_pin_size = sum(vram_pin_size_xcp[]) + vram_pin_size_common 850 * 851 * vram_pin_size total pin size in device 852 * vram_pin_size_xcp[i] pins owned by partition i (bo->xcp_id = i, i >= 0) 853 * vram_pin_size_common pins not owned by any partition, bo->xcp_id = -1 854 */ 855 atomic64_t vram_pin_size; 856 atomic64_t vram_pin_size_xcp[MAX_XCP]; 857 atomic64_t vram_pin_size_common; 858 atomic64_t visible_pin_size; 859 atomic64_t gart_pin_size; 860 861 /* soc15 register offset based on ip, instance and segment */ 862 uint32_t *reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE]; 863 struct amdgpu_ip_map_info ip_map; 864 865 /* delayed work_func for deferring clockgating during resume */ 866 struct delayed_work delayed_init_work; 867 868 struct amdgpu_virt virt; 869 870 /* record hw reset is performed */ 871 bool has_hw_reset; 872 u8 reset_magic[AMDGPU_RESET_MAGIC_NUM]; 873 874 /* s3/s4 mask */ 875 bool in_suspend; 876 bool in_s3; 877 bool in_s4; 878 bool in_s0ix; 879 suspend_state_t last_suspend_state; 880 881 enum pp_mp1_state mp1_state; 882 struct amdgpu_doorbell_index doorbell_index; 883 884 struct mutex notifier_lock; 885 886 int asic_reset_res; 887 struct work_struct xgmi_reset_work; 888 struct list_head reset_list; 889 890 long gfx_timeout; 891 long sdma_timeout; 892 long video_timeout; 893 long compute_timeout; 894 long psp_timeout; 895 896 uint64_t unique_id; 897 uint8_t unitid; 898 uint64_t df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS]; 899 900 /* enable runtime pm on the device */ 901 bool in_runpm; 902 bool has_pr3; 903 904 bool ucode_sysfs_en; 905 906 struct amdgpu_fru_info *fru_info; 907 atomic_t throttling_logging_enabled; 908 struct ratelimit_state throttling_logging_rs; 909 uint32_t ras_hw_enabled; 910 uint32_t ras_enabled; 911 bool ras_default_ecc_enabled; 912 913 bool no_hw_access; 914 struct pci_saved_state *pci_state; 915 pci_channel_state_t pci_channel_state; 916 917 struct amdgpu_pcie_reset_ctx pcie_reset_ctx; 918 919 /* Track auto wait count on s_barrier settings */ 920 bool barrier_has_auto_waitcnt; 921 922 struct amdgpu_reset_control *reset_cntl; 923 uint32_t ip_versions[MAX_HWIP][HWIP_MAX_INSTANCE]; 924 925 bool ram_is_direct_mapped; 926 927 struct list_head ras_list; 928 929 struct amdgpu_reset_domain *reset_domain; 930 931 #ifdef CONFIG_DEV_COREDUMP 932 struct amdgpu_coredump_info *coredump; 933 struct work_struct coredump_work; 934 #endif 935 936 struct mutex benchmark_mutex; 937 938 bool scpm_enabled; 939 uint32_t scpm_status; 940 941 struct work_struct reset_work; 942 943 bool dc_enabled; 944 /* Mask of active clusters */ 945 uint32_t aid_mask; 946 947 /* Debug */ 948 bool debug_vm; 949 bool debug_largebar; 950 bool debug_disable_soft_recovery; 951 bool debug_use_vram_fw_buf; 952 bool debug_exp_resets; 953 bool debug_disable_gpu_ring_reset; 954 bool debug_vm_userptr; 955 bool debug_disable_ce_logs; 956 bool debug_enable_ce_cs; 957 bool debug_hibernation_thaw_resume_gpu; 958 bool debug_disable_ip_block_soft_reset; 959 960 /* Protection for the following isolation structure */ 961 struct mutex enforce_isolation_mutex; 962 enum amdgpu_enforce_isolation_mode enforce_isolation[MAX_XCP]; 963 struct amdgpu_isolation { 964 void *owner; 965 struct dma_fence *spearhead; 966 struct amdgpu_sync active; 967 struct amdgpu_sync prev; 968 } isolation[MAX_XCP]; 969 970 struct amdgpu_init_level *init_lvl; 971 972 /* This flag is used to determine how VRAM allocations are handled for APUs 973 * in KFD: VRAM or GTT. 974 */ 975 bool apu_prefer_gtt; 976 977 bool userq_halt_for_enforce_isolation; 978 struct amdgpu_uid *uid_info; 979 980 struct amdgpu_uma_carveout_info uma_info; 981 982 /* KFD 983 * Must be last --ends in a flexible-array member. 984 */ 985 struct amdgpu_kfd_dev kfd; 986 }; 987 988 static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev, 989 uint8_t ip, uint8_t inst) 990 { 991 /* This considers only major/minor/rev and ignores 992 * subrevision/variant fields. 993 */ 994 return adev->ip_versions[ip][inst] & ~0xFFU; 995 } 996 997 static inline uint32_t amdgpu_ip_version_full(const struct amdgpu_device *adev, 998 uint8_t ip, uint8_t inst) 999 { 1000 /* This returns full version - major/minor/rev/variant/subrevision */ 1001 return adev->ip_versions[ip][inst]; 1002 } 1003 1004 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev) 1005 { 1006 return container_of(ddev, struct amdgpu_device, ddev); 1007 } 1008 1009 static inline struct drm_device *adev_to_drm(struct amdgpu_device *adev) 1010 { 1011 return &adev->ddev; 1012 } 1013 1014 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_device *bdev) 1015 { 1016 return container_of(bdev, struct amdgpu_device, mman.bdev); 1017 } 1018 1019 static inline bool amdgpu_is_multi_aid(struct amdgpu_device *adev) 1020 { 1021 return !!adev->aid_mask; 1022 } 1023 1024 int amdgpu_device_init(struct amdgpu_device *adev, 1025 uint32_t flags); 1026 void amdgpu_device_fini_hw(struct amdgpu_device *adev); 1027 void amdgpu_device_fini_sw(struct amdgpu_device *adev); 1028 1029 int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev); 1030 1031 void amdgpu_device_mm_access(struct amdgpu_device *adev, loff_t pos, 1032 void *buf, size_t size, bool write); 1033 size_t amdgpu_device_aper_access(struct amdgpu_device *adev, loff_t pos, 1034 void *buf, size_t size, bool write); 1035 1036 void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos, 1037 void *buf, size_t size, bool write); 1038 u32 amdgpu_device_get_rev_id(struct amdgpu_device *adev); 1039 bool amdgpu_device_asic_has_dc_support(struct pci_dev *pdev, 1040 enum amd_asic_type asic_type); 1041 bool amdgpu_device_has_dc_support(struct amdgpu_device *adev); 1042 1043 void amdgpu_device_set_sriov_virtual_display(struct amdgpu_device *adev); 1044 1045 int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev, 1046 struct amdgpu_reset_context *reset_context); 1047 1048 int amdgpu_do_asic_reset(struct list_head *device_list_handle, 1049 struct amdgpu_reset_context *reset_context); 1050 1051 int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context); 1052 1053 int emu_soc_asic_init(struct amdgpu_device *adev); 1054 1055 /* 1056 * Registers read & write functions. 1057 */ 1058 #define AMDGPU_REGS_NO_KIQ (1<<1) 1059 #define AMDGPU_REGS_RLC (1<<2) 1060 1061 #define RREG32_NO_KIQ(reg) amdgpu_device_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ) 1062 #define WREG32_NO_KIQ(reg, v) amdgpu_device_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ) 1063 1064 #define RREG32_KIQ(reg) amdgpu_kiq_rreg(adev, (reg), 0) 1065 #define WREG32_KIQ(reg, v) amdgpu_kiq_wreg(adev, (reg), (v), 0) 1066 1067 #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg)) 1068 #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v)) 1069 1070 #define RREG32(reg) amdgpu_device_rreg(adev, (reg), 0) 1071 #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_device_rreg(adev, (reg), 0)) 1072 #define WREG32(reg, v) amdgpu_device_wreg(adev, (reg), (v), 0) 1073 #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 1074 #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK) 1075 #define RREG32_XCC(reg, inst) amdgpu_device_xcc_rreg(adev, (reg), 0, inst) 1076 #define WREG32_XCC(reg, v, inst) amdgpu_device_xcc_wreg(adev, (reg), (v), 0, inst) 1077 #define RREG32_PCIE(reg) amdgpu_reg_pcie_rd32(adev, (reg)) 1078 #define WREG32_PCIE(reg, v) amdgpu_reg_pcie_wr32(adev, (reg), (v)) 1079 #define RREG32_PCIE_PORT(reg) amdgpu_reg_pciep_rd32(adev, (reg)) 1080 #define WREG32_PCIE_PORT(reg, v) amdgpu_reg_pciep_wr32(adev, (reg), (v)) 1081 #define RREG32_PCIE_EXT(reg) amdgpu_reg_pcie_ext_rd32(adev, (reg)) 1082 #define WREG32_PCIE_EXT(reg, v) amdgpu_reg_pcie_ext_wr32(adev, (reg), (v)) 1083 #define RREG64_PCIE(reg) amdgpu_reg_pcie_rd64(adev, (reg)) 1084 #define WREG64_PCIE(reg, v) amdgpu_reg_pcie_wr64(adev, (reg), (v)) 1085 #define RREG64_PCIE_EXT(reg) amdgpu_reg_pcie_ext_rd64(adev, (reg)) 1086 #define WREG64_PCIE_EXT(reg, v) amdgpu_reg_pcie_ext_wr64(adev, (reg), (v)) 1087 #define RREG32_SMC(reg) amdgpu_reg_smc_rd32(adev, (reg)) 1088 #define WREG32_SMC(reg, v) amdgpu_reg_smc_wr32(adev, (reg), (v)) 1089 #define RREG32_UVD_CTX(reg) amdgpu_reg_uvd_ctx_rd32(adev, (reg)) 1090 #define WREG32_UVD_CTX(reg, v) amdgpu_reg_uvd_ctx_wr32(adev, (reg), (v)) 1091 #define RREG32_DIDT(reg) amdgpu_reg_didt_rd32(adev, (reg)) 1092 #define WREG32_DIDT(reg, v) amdgpu_reg_didt_wr32(adev, (reg), (v)) 1093 #define RREG32_GC_CAC(reg) amdgpu_reg_gc_cac_rd32(adev, (reg)) 1094 #define WREG32_GC_CAC(reg, v) amdgpu_reg_gc_cac_wr32(adev, (reg), (v)) 1095 #define RREG32_SE_CAC(reg) amdgpu_reg_se_cac_rd32(adev, (reg)) 1096 #define WREG32_SE_CAC(reg, v) amdgpu_reg_se_cac_wr32(adev, (reg), (v)) 1097 #define RREG32_AUDIO_ENDPT(block, reg) \ 1098 amdgpu_reg_audio_endpt_rd32(adev, (block), (reg)) 1099 #define WREG32_AUDIO_ENDPT(block, reg, v) \ 1100 amdgpu_reg_audio_endpt_wr32(adev, (block), (reg), (v)) 1101 #define WREG32_P(reg, val, mask) \ 1102 do { \ 1103 uint32_t tmp_ = RREG32(reg); \ 1104 tmp_ &= (mask); \ 1105 tmp_ |= ((val) & ~(mask)); \ 1106 WREG32(reg, tmp_); \ 1107 } while (0) 1108 #define WREG32_AND(reg, and) WREG32_P(reg, 0, and) 1109 #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or)) 1110 #define WREG32_PLL_P(reg, val, mask) \ 1111 do { \ 1112 uint32_t tmp_ = RREG32_PLL(reg); \ 1113 tmp_ &= (mask); \ 1114 tmp_ |= ((val) & ~(mask)); \ 1115 WREG32_PLL(reg, tmp_); \ 1116 } while (0) 1117 1118 #define WREG32_SMC_P(_Reg, _Val, _Mask) \ 1119 do { \ 1120 u32 tmp = RREG32_SMC(_Reg); \ 1121 tmp &= (_Mask); \ 1122 tmp |= ((_Val) & ~(_Mask)); \ 1123 WREG32_SMC(_Reg, tmp); \ 1124 } while (0) 1125 1126 #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_device_rreg((adev), (reg), false)) 1127 1128 #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT 1129 #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK 1130 1131 #define REG_SET_FIELD(orig_val, reg, field, field_val) \ 1132 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \ 1133 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field)))) 1134 1135 #define REG_GET_FIELD(value, reg, field) \ 1136 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field)) 1137 1138 #define WREG32_FIELD(reg, field, val) \ 1139 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 1140 1141 #define WREG32_FIELD_OFFSET(reg, offset, field, val) \ 1142 WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field)) 1143 1144 #define AMDGPU_GET_REG_FIELD(x, h, l) (((x) & GENMASK_ULL(h, l)) >> (l)) 1145 /* 1146 * BIOS helpers. 1147 */ 1148 #define RBIOS8(i) (adev->bios[i]) 1149 #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8)) 1150 #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16)) 1151 1152 #include "amdgpu_reset.h" 1153 1154 /* 1155 * ASICs macro. 1156 */ 1157 #define amdgpu_asic_set_vga_state(adev, state) \ 1158 ((adev)->asic_funcs->set_vga_state ? (adev)->asic_funcs->set_vga_state((adev), (state)) : 0) 1159 #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev)) 1160 #define amdgpu_asic_reset_method(adev) (adev)->asic_funcs->reset_method((adev)) 1161 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 1162 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 1163 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 1164 #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev)) 1165 #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l)) 1166 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) 1167 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 1168 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 1169 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 1170 #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev)) 1171 #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev)) 1172 #define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1))) 1173 #define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev)) 1174 #define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev))) 1175 #define amdgpu_asic_supports_baco(adev) \ 1176 ((adev)->asic_funcs->supports_baco ? (adev)->asic_funcs->supports_baco((adev)) : 0) 1177 #define amdgpu_asic_pre_asic_init(adev) \ 1178 { \ 1179 if ((adev)->asic_funcs && (adev)->asic_funcs->pre_asic_init) \ 1180 (adev)->asic_funcs->pre_asic_init((adev)); \ 1181 } 1182 #define amdgpu_asic_update_umd_stable_pstate(adev, enter) \ 1183 ((adev)->asic_funcs->update_umd_stable_pstate ? (adev)->asic_funcs->update_umd_stable_pstate((adev), (enter)) : 0) 1184 #define amdgpu_asic_query_video_codecs(adev, e, c) (adev)->asic_funcs->query_video_codecs((adev), (e), (c)) 1185 1186 #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter)) 1187 1188 #define BIT_MASK_UPPER(i) ((i) >= BITS_PER_LONG ? 0 : ~0UL << (i)) 1189 #define for_each_inst(i, inst_mask) \ 1190 for (i = ffs(inst_mask); i-- != 0; \ 1191 i = ffs(inst_mask & BIT_MASK_UPPER(i + 1))) 1192 1193 /* Common functions */ 1194 bool amdgpu_device_has_job_running(struct amdgpu_device *adev); 1195 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev); 1196 int amdgpu_device_gpu_recover(struct amdgpu_device *adev, 1197 struct amdgpu_job *job, 1198 struct amdgpu_reset_context *reset_context); 1199 void amdgpu_device_pci_config_reset(struct amdgpu_device *adev); 1200 int amdgpu_device_pci_reset(struct amdgpu_device *adev); 1201 bool amdgpu_device_need_post(struct amdgpu_device *adev); 1202 bool amdgpu_device_seamless_boot_supported(struct amdgpu_device *adev); 1203 bool amdgpu_device_should_use_aspm(struct amdgpu_device *adev); 1204 1205 void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes, 1206 u64 num_vis_bytes); 1207 int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev); 1208 void amdgpu_device_program_register_sequence(struct amdgpu_device *adev, 1209 const u32 *registers, 1210 const u32 array_size); 1211 1212 int amdgpu_device_mode1_reset(struct amdgpu_device *adev); 1213 int amdgpu_device_link_reset(struct amdgpu_device *adev); 1214 bool amdgpu_device_supports_atpx(struct amdgpu_device *adev); 1215 bool amdgpu_device_supports_px(struct amdgpu_device *adev); 1216 bool amdgpu_device_supports_boco(struct amdgpu_device *adev); 1217 bool amdgpu_device_supports_smart_shift(struct amdgpu_device *adev); 1218 int amdgpu_device_supports_baco(struct amdgpu_device *adev); 1219 void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev); 1220 bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, 1221 struct amdgpu_device *peer_adev); 1222 int amdgpu_device_baco_enter(struct amdgpu_device *adev); 1223 int amdgpu_device_baco_exit(struct amdgpu_device *adev); 1224 1225 void amdgpu_device_flush_hdp(struct amdgpu_device *adev, 1226 struct amdgpu_ring *ring); 1227 void amdgpu_device_invalidate_hdp(struct amdgpu_device *adev, 1228 struct amdgpu_ring *ring); 1229 1230 void amdgpu_device_halt(struct amdgpu_device *adev); 1231 struct dma_fence *amdgpu_device_get_gang(struct amdgpu_device *adev); 1232 struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev, 1233 struct dma_fence *gang); 1234 struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev, 1235 struct amdgpu_ring *ring, 1236 struct amdgpu_job *job); 1237 bool amdgpu_device_has_display_hardware(struct amdgpu_device *adev); 1238 ssize_t amdgpu_get_soft_full_reset_mask(struct amdgpu_ring *ring); 1239 ssize_t amdgpu_show_reset_mask(char *buf, uint32_t supported_reset); 1240 void amdgpu_sdma_set_vm_pte_scheds(struct amdgpu_device *adev, 1241 const struct amdgpu_vm_pte_funcs *vm_pte_funcs); 1242 void amdgpu_sdma_set_buffer_funcs_scheds(struct amdgpu_device *adev, 1243 const struct amdgpu_buffer_funcs *buffer_funcs); 1244 1245 /* atpx handler */ 1246 #if defined(CONFIG_VGA_SWITCHEROO) 1247 void amdgpu_register_atpx_handler(void); 1248 void amdgpu_unregister_atpx_handler(void); 1249 bool amdgpu_has_atpx_dgpu_power_cntl(void); 1250 bool amdgpu_is_atpx_hybrid(void); 1251 bool amdgpu_has_atpx(void); 1252 #else 1253 static inline void amdgpu_register_atpx_handler(void) {} 1254 static inline void amdgpu_unregister_atpx_handler(void) {} 1255 static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; } 1256 static inline bool amdgpu_is_atpx_hybrid(void) { return false; } 1257 static inline bool amdgpu_has_atpx(void) { return false; } 1258 #endif 1259 1260 /* 1261 * KMS 1262 */ 1263 extern const struct drm_ioctl_desc amdgpu_ioctls_kms[]; 1264 extern const int amdgpu_max_kms_ioctl; 1265 1266 int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags); 1267 void amdgpu_driver_unload_kms(struct drm_device *dev); 1268 int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv); 1269 void amdgpu_driver_postclose_kms(struct drm_device *dev, 1270 struct drm_file *file_priv); 1271 void amdgpu_driver_release_kms(struct drm_device *dev); 1272 1273 int amdgpu_device_prepare(struct drm_device *dev); 1274 void amdgpu_device_complete(struct drm_device *dev); 1275 int amdgpu_device_suspend(struct drm_device *dev, bool fbcon); 1276 int amdgpu_device_resume(struct drm_device *dev, bool fbcon); 1277 u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc); 1278 int amdgpu_enable_vblank_kms(struct drm_crtc *crtc); 1279 void amdgpu_disable_vblank_kms(struct drm_crtc *crtc); 1280 int amdgpu_info_ioctl(struct drm_device *dev, void *data, 1281 struct drm_file *filp); 1282 int amdgpu_proc_options_ioctl(struct drm_device *dev, void *data, 1283 struct drm_file *filp); 1284 1285 /* 1286 * functions used by amdgpu_encoder.c 1287 */ 1288 struct amdgpu_afmt_acr { 1289 u32 clock; 1290 1291 int n_32khz; 1292 int cts_32khz; 1293 1294 int n_44_1khz; 1295 int cts_44_1khz; 1296 1297 int n_48khz; 1298 int cts_48khz; 1299 1300 }; 1301 1302 struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock); 1303 1304 void amdgpu_register_gpu_instance(struct amdgpu_device *adev); 1305 void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev); 1306 1307 pci_ers_result_t amdgpu_pci_error_detected(struct pci_dev *pdev, 1308 pci_channel_state_t state); 1309 pci_ers_result_t amdgpu_pci_mmio_enabled(struct pci_dev *pdev); 1310 pci_ers_result_t amdgpu_pci_slot_reset(struct pci_dev *pdev); 1311 void amdgpu_pci_resume(struct pci_dev *pdev); 1312 1313 bool amdgpu_device_cache_pci_state(struct pci_dev *pdev); 1314 bool amdgpu_device_load_pci_state(struct pci_dev *pdev); 1315 1316 bool amdgpu_device_skip_hw_access(struct amdgpu_device *adev); 1317 1318 int amdgpu_device_set_cg_state(struct amdgpu_device *adev, 1319 enum amd_clockgating_state state); 1320 int amdgpu_device_set_pg_state(struct amdgpu_device *adev, 1321 enum amd_powergating_state state); 1322 1323 static inline bool amdgpu_device_has_timeouts_enabled(struct amdgpu_device *adev) 1324 { 1325 return amdgpu_gpu_recovery != 0 && 1326 adev->gfx_timeout != MAX_SCHEDULE_TIMEOUT && 1327 adev->compute_timeout != MAX_SCHEDULE_TIMEOUT && 1328 adev->sdma_timeout != MAX_SCHEDULE_TIMEOUT && 1329 adev->video_timeout != MAX_SCHEDULE_TIMEOUT; 1330 } 1331 1332 #include "amdgpu_object.h" 1333 1334 static inline bool amdgpu_is_tmz(struct amdgpu_device *adev) 1335 { 1336 return adev->gmc.tmz_enabled; 1337 } 1338 1339 int amdgpu_in_reset(struct amdgpu_device *adev); 1340 1341 extern const struct attribute_group amdgpu_vram_mgr_attr_group; 1342 extern const struct attribute_group amdgpu_gtt_mgr_attr_group; 1343 extern const struct attribute_group amdgpu_flash_attr_group; 1344 1345 void amdgpu_set_init_level(struct amdgpu_device *adev, 1346 enum amdgpu_init_lvl_id lvl); 1347 1348 static inline int amdgpu_device_bus_status_check(struct amdgpu_device *adev) 1349 { 1350 u32 status; 1351 int r; 1352 1353 r = pci_read_config_dword(adev->pdev, PCI_COMMAND, &status); 1354 if (r || PCI_POSSIBLE_ERROR(status)) { 1355 dev_err(adev->dev, "device lost from bus!"); 1356 return -ENODEV; 1357 } 1358 1359 return 0; 1360 } 1361 1362 void amdgpu_device_set_uid(struct amdgpu_uid *uid_info, 1363 enum amdgpu_uid_type type, uint8_t inst, 1364 uint64_t uid); 1365 uint64_t amdgpu_device_get_uid(struct amdgpu_uid *uid_info, 1366 enum amdgpu_uid_type type, uint8_t inst); 1367 #endif 1368