Merge tag 'for-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power...
[linux-block.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_drv.c
1 /*
2  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * 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  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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
25 #include <drm/amdgpu_drm.h>
26 #include <drm/drm_drv.h>
27 #include <drm/drm_gem.h>
28 #include <drm/drm_vblank.h>
29 #include "amdgpu_drv.h"
30
31 #include <drm/drm_pciids.h>
32 #include <linux/console.h>
33 #include <linux/module.h>
34 #include <linux/pci.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/vga_switcheroo.h>
37 #include <drm/drm_probe_helper.h>
38 #include <linux/mmu_notifier.h>
39
40 #include "amdgpu.h"
41 #include "amdgpu_irq.h"
42 #include "amdgpu_dma_buf.h"
43
44 #include "amdgpu_amdkfd.h"
45
46 /*
47  * KMS wrapper.
48  * - 3.0.0 - initial driver
49  * - 3.1.0 - allow reading more status registers (GRBM, SRBM, SDMA, CP)
50  * - 3.2.0 - GFX8: Uses EOP_TC_WB_ACTION_EN, so UMDs don't have to do the same
51  *           at the end of IBs.
52  * - 3.3.0 - Add VM support for UVD on supported hardware.
53  * - 3.4.0 - Add AMDGPU_INFO_NUM_EVICTIONS.
54  * - 3.5.0 - Add support for new UVD_NO_OP register.
55  * - 3.6.0 - kmd involves use CONTEXT_CONTROL in ring buffer.
56  * - 3.7.0 - Add support for VCE clock list packet
57  * - 3.8.0 - Add support raster config init in the kernel
58  * - 3.9.0 - Add support for memory query info about VRAM and GTT.
59  * - 3.10.0 - Add support for new fences ioctl, new gem ioctl flags
60  * - 3.11.0 - Add support for sensor query info (clocks, temp, etc).
61  * - 3.12.0 - Add query for double offchip LDS buffers
62  * - 3.13.0 - Add PRT support
63  * - 3.14.0 - Fix race in amdgpu_ctx_get_fence() and note new functionality
64  * - 3.15.0 - Export more gpu info for gfx9
65  * - 3.16.0 - Add reserved vmid support
66  * - 3.17.0 - Add AMDGPU_NUM_VRAM_CPU_PAGE_FAULTS.
67  * - 3.18.0 - Export gpu always on cu bitmap
68  * - 3.19.0 - Add support for UVD MJPEG decode
69  * - 3.20.0 - Add support for local BOs
70  * - 3.21.0 - Add DRM_AMDGPU_FENCE_TO_HANDLE ioctl
71  * - 3.22.0 - Add DRM_AMDGPU_SCHED ioctl
72  * - 3.23.0 - Add query for VRAM lost counter
73  * - 3.24.0 - Add high priority compute support for gfx9
74  * - 3.25.0 - Add support for sensor query info (stable pstate sclk/mclk).
75  * - 3.26.0 - GFX9: Process AMDGPU_IB_FLAG_TC_WB_NOT_INVALIDATE.
76  * - 3.27.0 - Add new chunk to to AMDGPU_CS to enable BO_LIST creation.
77  * - 3.28.0 - Add AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES
78  * - 3.29.0 - Add AMDGPU_IB_FLAG_RESET_GDS_MAX_WAVE_ID
79  * - 3.30.0 - Add AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE.
80  * - 3.31.0 - Add support for per-flip tiling attribute changes with DC
81  * - 3.32.0 - Add syncobj timeline support to AMDGPU_CS.
82  * - 3.33.0 - Fixes for GDS ENOMEM failures in AMDGPU_CS.
83  * - 3.34.0 - Non-DC can flip correctly between buffers with different pitches
84  */
85 #define KMS_DRIVER_MAJOR        3
86 #define KMS_DRIVER_MINOR        34
87 #define KMS_DRIVER_PATCHLEVEL   0
88
89 #define AMDGPU_MAX_TIMEOUT_PARAM_LENTH  256
90
91 int amdgpu_vram_limit = 0;
92 int amdgpu_vis_vram_limit = 0;
93 int amdgpu_gart_size = -1; /* auto */
94 int amdgpu_gtt_size = -1; /* auto */
95 int amdgpu_moverate = -1; /* auto */
96 int amdgpu_benchmarking = 0;
97 int amdgpu_testing = 0;
98 int amdgpu_audio = -1;
99 int amdgpu_disp_priority = 0;
100 int amdgpu_hw_i2c = 0;
101 int amdgpu_pcie_gen2 = -1;
102 int amdgpu_msi = -1;
103 char amdgpu_lockup_timeout[AMDGPU_MAX_TIMEOUT_PARAM_LENTH];
104 int amdgpu_dpm = -1;
105 int amdgpu_fw_load_type = -1;
106 int amdgpu_aspm = -1;
107 int amdgpu_runtime_pm = -1;
108 uint amdgpu_ip_block_mask = 0xffffffff;
109 int amdgpu_bapm = -1;
110 int amdgpu_deep_color = 0;
111 int amdgpu_vm_size = -1;
112 int amdgpu_vm_fragment_size = -1;
113 int amdgpu_vm_block_size = -1;
114 int amdgpu_vm_fault_stop = 0;
115 int amdgpu_vm_debug = 0;
116 int amdgpu_vm_update_mode = -1;
117 int amdgpu_exp_hw_support = 0;
118 int amdgpu_dc = -1;
119 int amdgpu_sched_jobs = 32;
120 int amdgpu_sched_hw_submission = 2;
121 uint amdgpu_pcie_gen_cap = 0;
122 uint amdgpu_pcie_lane_cap = 0;
123 uint amdgpu_cg_mask = 0xffffffff;
124 uint amdgpu_pg_mask = 0xffffffff;
125 uint amdgpu_sdma_phase_quantum = 32;
126 char *amdgpu_disable_cu = NULL;
127 char *amdgpu_virtual_display = NULL;
128 /* OverDrive(bit 14) disabled by default*/
129 uint amdgpu_pp_feature_mask = 0xffffbfff;
130 int amdgpu_ngg = 0;
131 int amdgpu_prim_buf_per_se = 0;
132 int amdgpu_pos_buf_per_se = 0;
133 int amdgpu_cntl_sb_buf_per_se = 0;
134 int amdgpu_param_buf_per_se = 0;
135 int amdgpu_job_hang_limit = 0;
136 int amdgpu_lbpw = -1;
137 int amdgpu_compute_multipipe = -1;
138 int amdgpu_gpu_recovery = -1; /* auto */
139 int amdgpu_emu_mode = 0;
140 uint amdgpu_smu_memory_pool_size = 0;
141 /* FBC (bit 0) disabled by default*/
142 uint amdgpu_dc_feature_mask = 0;
143 int amdgpu_async_gfx_ring = 1;
144 int amdgpu_mcbp = 0;
145 int amdgpu_discovery = -1;
146 int amdgpu_mes = 0;
147 int amdgpu_noretry = 1;
148
149 struct amdgpu_mgpu_info mgpu_info = {
150         .mutex = __MUTEX_INITIALIZER(mgpu_info.mutex),
151 };
152 int amdgpu_ras_enable = -1;
153 uint amdgpu_ras_mask = 0xfffffffb;
154
155 /**
156  * DOC: vramlimit (int)
157  * Restrict the total amount of VRAM in MiB for testing.  The default is 0 (Use full VRAM).
158  */
159 MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
160 module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
161
162 /**
163  * DOC: vis_vramlimit (int)
164  * Restrict the amount of CPU visible VRAM in MiB for testing.  The default is 0 (Use full CPU visible VRAM).
165  */
166 MODULE_PARM_DESC(vis_vramlimit, "Restrict visible VRAM for testing, in megabytes");
167 module_param_named(vis_vramlimit, amdgpu_vis_vram_limit, int, 0444);
168
169 /**
170  * DOC: gartsize (uint)
171  * Restrict the size of GART in Mib (32, 64, etc.) for testing. The default is -1 (The size depends on asic).
172  */
173 MODULE_PARM_DESC(gartsize, "Size of GART to setup in megabytes (32, 64, etc., -1=auto)");
174 module_param_named(gartsize, amdgpu_gart_size, uint, 0600);
175
176 /**
177  * DOC: gttsize (int)
178  * Restrict the size of GTT domain in MiB for testing. The default is -1 (It's VRAM size if 3GB < VRAM < 3/4 RAM,
179  * otherwise 3/4 RAM size).
180  */
181 MODULE_PARM_DESC(gttsize, "Size of the GTT domain in megabytes (-1 = auto)");
182 module_param_named(gttsize, amdgpu_gtt_size, int, 0600);
183
184 /**
185  * DOC: moverate (int)
186  * Set maximum buffer migration rate in MB/s. The default is -1 (8 MB/s).
187  */
188 MODULE_PARM_DESC(moverate, "Maximum buffer migration rate in MB/s. (32, 64, etc., -1=auto, 0=1=disabled)");
189 module_param_named(moverate, amdgpu_moverate, int, 0600);
190
191 /**
192  * DOC: benchmark (int)
193  * Run benchmarks. The default is 0 (Skip benchmarks).
194  */
195 MODULE_PARM_DESC(benchmark, "Run benchmark");
196 module_param_named(benchmark, amdgpu_benchmarking, int, 0444);
197
198 /**
199  * DOC: test (int)
200  * Test BO GTT->VRAM and VRAM->GTT GPU copies. The default is 0 (Skip test, only set 1 to run test).
201  */
202 MODULE_PARM_DESC(test, "Run tests");
203 module_param_named(test, amdgpu_testing, int, 0444);
204
205 /**
206  * DOC: audio (int)
207  * Set HDMI/DPAudio. Only affects non-DC display handling. The default is -1 (Enabled), set 0 to disabled it.
208  */
209 MODULE_PARM_DESC(audio, "Audio enable (-1 = auto, 0 = disable, 1 = enable)");
210 module_param_named(audio, amdgpu_audio, int, 0444);
211
212 /**
213  * DOC: disp_priority (int)
214  * Set display Priority (1 = normal, 2 = high). Only affects non-DC display handling. The default is 0 (auto).
215  */
216 MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
217 module_param_named(disp_priority, amdgpu_disp_priority, int, 0444);
218
219 /**
220  * DOC: hw_i2c (int)
221  * To enable hw i2c engine. Only affects non-DC display handling. The default is 0 (Disabled).
222  */
223 MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
224 module_param_named(hw_i2c, amdgpu_hw_i2c, int, 0444);
225
226 /**
227  * DOC: pcie_gen2 (int)
228  * To disable PCIE Gen2/3 mode (0 = disable, 1 = enable). The default is -1 (auto, enabled).
229  */
230 MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (-1 = auto, 0 = disable, 1 = enable)");
231 module_param_named(pcie_gen2, amdgpu_pcie_gen2, int, 0444);
232
233 /**
234  * DOC: msi (int)
235  * To disable Message Signaled Interrupts (MSI) functionality (1 = enable, 0 = disable). The default is -1 (auto, enabled).
236  */
237 MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
238 module_param_named(msi, amdgpu_msi, int, 0444);
239
240 /**
241  * DOC: lockup_timeout (string)
242  * Set GPU scheduler timeout value in ms.
243  *
244  * The format can be [Non-Compute] or [GFX,Compute,SDMA,Video]. That is there can be one or
245  * multiple values specified. 0 and negative values are invalidated. They will be adjusted
246  * to default timeout.
247  *  - With one value specified, the setting will apply to all non-compute jobs.
248  *  - With multiple values specified, the first one will be for GFX. The second one is for Compute.
249  *    And the third and fourth ones are for SDMA and Video.
250  * By default(with no lockup_timeout settings), the timeout for all non-compute(GFX, SDMA and Video)
251  * jobs is 10000. And there is no timeout enforced on compute jobs.
252  */
253 MODULE_PARM_DESC(lockup_timeout, "GPU lockup timeout in ms (default: 10000 for non-compute jobs and infinity timeout for compute jobs."
254                 " 0: keep default value. negative: infinity timeout), "
255                 "format is [Non-Compute] or [GFX,Compute,SDMA,Video]");
256 module_param_string(lockup_timeout, amdgpu_lockup_timeout, sizeof(amdgpu_lockup_timeout), 0444);
257
258 /**
259  * DOC: dpm (int)
260  * Override for dynamic power management setting
261  * (0 = disable, 1 = enable, 2 = enable sw smu driver for vega20)
262  * The default is -1 (auto).
263  */
264 MODULE_PARM_DESC(dpm, "DPM support (1 = enable, 0 = disable, -1 = auto)");
265 module_param_named(dpm, amdgpu_dpm, int, 0444);
266
267 /**
268  * DOC: fw_load_type (int)
269  * Set different firmware loading type for debugging (0 = direct, 1 = SMU, 2 = PSP). The default is -1 (auto).
270  */
271 MODULE_PARM_DESC(fw_load_type, "firmware loading type (0 = direct, 1 = SMU, 2 = PSP, -1 = auto)");
272 module_param_named(fw_load_type, amdgpu_fw_load_type, int, 0444);
273
274 /**
275  * DOC: aspm (int)
276  * To disable ASPM (1 = enable, 0 = disable). The default is -1 (auto, enabled).
277  */
278 MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)");
279 module_param_named(aspm, amdgpu_aspm, int, 0444);
280
281 /**
282  * DOC: runpm (int)
283  * Override for runtime power management control for dGPUs in PX/HG laptops. The amdgpu driver can dynamically power down
284  * the dGPU on PX/HG laptops when it is idle. The default is -1 (auto enable). Setting the value to 0 disables this functionality.
285  */
286 MODULE_PARM_DESC(runpm, "PX runtime pm (1 = force enable, 0 = disable, -1 = PX only default)");
287 module_param_named(runpm, amdgpu_runtime_pm, int, 0444);
288
289 /**
290  * DOC: ip_block_mask (uint)
291  * Override what IP blocks are enabled on the GPU. Each GPU is a collection of IP blocks (gfx, display, video, etc.).
292  * Use this parameter to disable specific blocks. Note that the IP blocks do not have a fixed index. Some asics may not have
293  * some IPs or may include multiple instances of an IP so the ordering various from asic to asic. See the driver output in
294  * the kernel log for the list of IPs on the asic. The default is 0xffffffff (enable all blocks on a device).
295  */
296 MODULE_PARM_DESC(ip_block_mask, "IP Block Mask (all blocks enabled (default))");
297 module_param_named(ip_block_mask, amdgpu_ip_block_mask, uint, 0444);
298
299 /**
300  * DOC: bapm (int)
301  * Bidirectional Application Power Management (BAPM) used to dynamically share TDP between CPU and GPU. Set value 0 to disable it.
302  * The default -1 (auto, enabled)
303  */
304 MODULE_PARM_DESC(bapm, "BAPM support (1 = enable, 0 = disable, -1 = auto)");
305 module_param_named(bapm, amdgpu_bapm, int, 0444);
306
307 /**
308  * DOC: deep_color (int)
309  * Set 1 to enable Deep Color support. Only affects non-DC display handling. The default is 0 (disabled).
310  */
311 MODULE_PARM_DESC(deep_color, "Deep Color support (1 = enable, 0 = disable (default))");
312 module_param_named(deep_color, amdgpu_deep_color, int, 0444);
313
314 /**
315  * DOC: vm_size (int)
316  * Override the size of the GPU's per client virtual address space in GiB.  The default is -1 (automatic for each asic).
317  */
318 MODULE_PARM_DESC(vm_size, "VM address space size in gigabytes (default 64GB)");
319 module_param_named(vm_size, amdgpu_vm_size, int, 0444);
320
321 /**
322  * DOC: vm_fragment_size (int)
323  * Override VM fragment size in bits (4, 5, etc. 4 = 64K, 9 = 2M). The default is -1 (automatic for each asic).
324  */
325 MODULE_PARM_DESC(vm_fragment_size, "VM fragment size in bits (4, 5, etc. 4 = 64K (default), Max 9 = 2M)");
326 module_param_named(vm_fragment_size, amdgpu_vm_fragment_size, int, 0444);
327
328 /**
329  * DOC: vm_block_size (int)
330  * Override VM page table size in bits (default depending on vm_size and hw setup). The default is -1 (automatic for each asic).
331  */
332 MODULE_PARM_DESC(vm_block_size, "VM page table size in bits (default depending on vm_size)");
333 module_param_named(vm_block_size, amdgpu_vm_block_size, int, 0444);
334
335 /**
336  * DOC: vm_fault_stop (int)
337  * Stop on VM fault for debugging (0 = never, 1 = print first, 2 = always). The default is 0 (No stop).
338  */
339 MODULE_PARM_DESC(vm_fault_stop, "Stop on VM fault (0 = never (default), 1 = print first, 2 = always)");
340 module_param_named(vm_fault_stop, amdgpu_vm_fault_stop, int, 0444);
341
342 /**
343  * DOC: vm_debug (int)
344  * Debug VM handling (0 = disabled, 1 = enabled). The default is 0 (Disabled).
345  */
346 MODULE_PARM_DESC(vm_debug, "Debug VM handling (0 = disabled (default), 1 = enabled)");
347 module_param_named(vm_debug, amdgpu_vm_debug, int, 0644);
348
349 /**
350  * DOC: vm_update_mode (int)
351  * Override VM update mode. VM updated by using CPU (0 = never, 1 = Graphics only, 2 = Compute only, 3 = Both). The default
352  * is -1 (Only in large BAR(LB) systems Compute VM tables will be updated by CPU, otherwise 0, never).
353  */
354 MODULE_PARM_DESC(vm_update_mode, "VM update using CPU (0 = never (default except for large BAR(LB)), 1 = Graphics only, 2 = Compute only (default for LB), 3 = Both");
355 module_param_named(vm_update_mode, amdgpu_vm_update_mode, int, 0444);
356
357 /**
358  * DOC: exp_hw_support (int)
359  * Enable experimental hw support (1 = enable). The default is 0 (disabled).
360  */
361 MODULE_PARM_DESC(exp_hw_support, "experimental hw support (1 = enable, 0 = disable (default))");
362 module_param_named(exp_hw_support, amdgpu_exp_hw_support, int, 0444);
363
364 /**
365  * DOC: dc (int)
366  * Disable/Enable Display Core driver for debugging (1 = enable, 0 = disable). The default is -1 (automatic for each asic).
367  */
368 MODULE_PARM_DESC(dc, "Display Core driver (1 = enable, 0 = disable, -1 = auto (default))");
369 module_param_named(dc, amdgpu_dc, int, 0444);
370
371 /**
372  * DOC: sched_jobs (int)
373  * Override the max number of jobs supported in the sw queue. The default is 32.
374  */
375 MODULE_PARM_DESC(sched_jobs, "the max number of jobs supported in the sw queue (default 32)");
376 module_param_named(sched_jobs, amdgpu_sched_jobs, int, 0444);
377
378 /**
379  * DOC: sched_hw_submission (int)
380  * Override the max number of HW submissions. The default is 2.
381  */
382 MODULE_PARM_DESC(sched_hw_submission, "the max number of HW submissions (default 2)");
383 module_param_named(sched_hw_submission, amdgpu_sched_hw_submission, int, 0444);
384
385 /**
386  * DOC: ppfeaturemask (uint)
387  * Override power features enabled. See enum PP_FEATURE_MASK in drivers/gpu/drm/amd/include/amd_shared.h.
388  * The default is the current set of stable power features.
389  */
390 MODULE_PARM_DESC(ppfeaturemask, "all power features enabled (default))");
391 module_param_named(ppfeaturemask, amdgpu_pp_feature_mask, uint, 0444);
392
393 /**
394  * DOC: pcie_gen_cap (uint)
395  * Override PCIE gen speed capabilities. See the CAIL flags in drivers/gpu/drm/amd/include/amd_pcie.h.
396  * The default is 0 (automatic for each asic).
397  */
398 MODULE_PARM_DESC(pcie_gen_cap, "PCIE Gen Caps (0: autodetect (default))");
399 module_param_named(pcie_gen_cap, amdgpu_pcie_gen_cap, uint, 0444);
400
401 /**
402  * DOC: pcie_lane_cap (uint)
403  * Override PCIE lanes capabilities. See the CAIL flags in drivers/gpu/drm/amd/include/amd_pcie.h.
404  * The default is 0 (automatic for each asic).
405  */
406 MODULE_PARM_DESC(pcie_lane_cap, "PCIE Lane Caps (0: autodetect (default))");
407 module_param_named(pcie_lane_cap, amdgpu_pcie_lane_cap, uint, 0444);
408
409 /**
410  * DOC: cg_mask (uint)
411  * Override Clockgating features enabled on GPU (0 = disable clock gating). See the AMD_CG_SUPPORT flags in
412  * drivers/gpu/drm/amd/include/amd_shared.h. The default is 0xffffffff (all enabled).
413  */
414 MODULE_PARM_DESC(cg_mask, "Clockgating flags mask (0 = disable clock gating)");
415 module_param_named(cg_mask, amdgpu_cg_mask, uint, 0444);
416
417 /**
418  * DOC: pg_mask (uint)
419  * Override Powergating features enabled on GPU (0 = disable power gating). See the AMD_PG_SUPPORT flags in
420  * drivers/gpu/drm/amd/include/amd_shared.h. The default is 0xffffffff (all enabled).
421  */
422 MODULE_PARM_DESC(pg_mask, "Powergating flags mask (0 = disable power gating)");
423 module_param_named(pg_mask, amdgpu_pg_mask, uint, 0444);
424
425 /**
426  * DOC: sdma_phase_quantum (uint)
427  * Override SDMA context switch phase quantum (x 1K GPU clock cycles, 0 = no change). The default is 32.
428  */
429 MODULE_PARM_DESC(sdma_phase_quantum, "SDMA context switch phase quantum (x 1K GPU clock cycles, 0 = no change (default 32))");
430 module_param_named(sdma_phase_quantum, amdgpu_sdma_phase_quantum, uint, 0444);
431
432 /**
433  * DOC: disable_cu (charp)
434  * Set to disable CUs (It's set like se.sh.cu,...). The default is NULL.
435  */
436 MODULE_PARM_DESC(disable_cu, "Disable CUs (se.sh.cu,...)");
437 module_param_named(disable_cu, amdgpu_disable_cu, charp, 0444);
438
439 /**
440  * DOC: virtual_display (charp)
441  * Set to enable virtual display feature. This feature provides a virtual display hardware on headless boards
442  * or in virtualized environments. It will be set like xxxx:xx:xx.x,x;xxxx:xx:xx.x,x. It's the pci address of
443  * the device, plus the number of crtcs to expose. E.g., 0000:26:00.0,4 would enable 4 virtual crtcs on the pci
444  * device at 26:00.0. The default is NULL.
445  */
446 MODULE_PARM_DESC(virtual_display,
447                  "Enable virtual display feature (the virtual_display will be set like xxxx:xx:xx.x,x;xxxx:xx:xx.x,x)");
448 module_param_named(virtual_display, amdgpu_virtual_display, charp, 0444);
449
450 /**
451  * DOC: ngg (int)
452  * Set to enable Next Generation Graphics (1 = enable). The default is 0 (disabled).
453  */
454 MODULE_PARM_DESC(ngg, "Next Generation Graphics (1 = enable, 0 = disable(default depending on gfx))");
455 module_param_named(ngg, amdgpu_ngg, int, 0444);
456
457 /**
458  * DOC: prim_buf_per_se (int)
459  * Override the size of Primitive Buffer per Shader Engine in Byte. The default is 0 (depending on gfx).
460  */
461 MODULE_PARM_DESC(prim_buf_per_se, "the size of Primitive Buffer per Shader Engine (default depending on gfx)");
462 module_param_named(prim_buf_per_se, amdgpu_prim_buf_per_se, int, 0444);
463
464 /**
465  * DOC: pos_buf_per_se (int)
466  * Override the size of Position Buffer per Shader Engine in Byte. The default is 0 (depending on gfx).
467  */
468 MODULE_PARM_DESC(pos_buf_per_se, "the size of Position Buffer per Shader Engine (default depending on gfx)");
469 module_param_named(pos_buf_per_se, amdgpu_pos_buf_per_se, int, 0444);
470
471 /**
472  * DOC: cntl_sb_buf_per_se (int)
473  * Override the size of Control Sideband per Shader Engine in Byte. The default is 0 (depending on gfx).
474  */
475 MODULE_PARM_DESC(cntl_sb_buf_per_se, "the size of Control Sideband per Shader Engine (default depending on gfx)");
476 module_param_named(cntl_sb_buf_per_se, amdgpu_cntl_sb_buf_per_se, int, 0444);
477
478 /**
479  * DOC: param_buf_per_se (int)
480  * Override the size of Off-Chip Parameter Cache per Shader Engine in Byte.
481  * The default is 0 (depending on gfx).
482  */
483 MODULE_PARM_DESC(param_buf_per_se, "the size of Off-Chip Parameter Cache per Shader Engine (default depending on gfx)");
484 module_param_named(param_buf_per_se, amdgpu_param_buf_per_se, int, 0444);
485
486 /**
487  * DOC: job_hang_limit (int)
488  * Set how much time allow a job hang and not drop it. The default is 0.
489  */
490 MODULE_PARM_DESC(job_hang_limit, "how much time allow a job hang and not drop it (default 0)");
491 module_param_named(job_hang_limit, amdgpu_job_hang_limit, int ,0444);
492
493 /**
494  * DOC: lbpw (int)
495  * Override Load Balancing Per Watt (LBPW) support (1 = enable, 0 = disable). The default is -1 (auto, enabled).
496  */
497 MODULE_PARM_DESC(lbpw, "Load Balancing Per Watt (LBPW) support (1 = enable, 0 = disable, -1 = auto)");
498 module_param_named(lbpw, amdgpu_lbpw, int, 0444);
499
500 MODULE_PARM_DESC(compute_multipipe, "Force compute queues to be spread across pipes (1 = enable, 0 = disable, -1 = auto)");
501 module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);
502
503 /**
504  * DOC: gpu_recovery (int)
505  * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV).
506  */
507 MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)");
508 module_param_named(gpu_recovery, amdgpu_gpu_recovery, int, 0444);
509
510 /**
511  * DOC: emu_mode (int)
512  * Set value 1 to enable emulation mode. This is only needed when running on an emulator. The default is 0 (disabled).
513  */
514 MODULE_PARM_DESC(emu_mode, "Emulation mode, (1 = enable, 0 = disable)");
515 module_param_named(emu_mode, amdgpu_emu_mode, int, 0444);
516
517 /**
518  * DOC: ras_enable (int)
519  * Enable RAS features on the GPU (0 = disable, 1 = enable, -1 = auto (default))
520  */
521 MODULE_PARM_DESC(ras_enable, "Enable RAS features on the GPU (0 = disable, 1 = enable, -1 = auto (default))");
522 module_param_named(ras_enable, amdgpu_ras_enable, int, 0444);
523
524 /**
525  * DOC: ras_mask (uint)
526  * Mask of RAS features to enable (default 0xffffffff), only valid when ras_enable == 1
527  * See the flags in drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
528  */
529 MODULE_PARM_DESC(ras_mask, "Mask of RAS features to enable (default 0xffffffff), only valid when ras_enable == 1");
530 module_param_named(ras_mask, amdgpu_ras_mask, uint, 0444);
531
532 /**
533  * DOC: si_support (int)
534  * Set SI support driver. This parameter works after set config CONFIG_DRM_AMDGPU_SI. For SI asic, when radeon driver is enabled,
535  * set value 0 to use radeon driver, while set value 1 to use amdgpu driver. The default is using radeon driver when it available,
536  * otherwise using amdgpu driver.
537  */
538 #ifdef CONFIG_DRM_AMDGPU_SI
539
540 #if defined(CONFIG_DRM_RADEON) || defined(CONFIG_DRM_RADEON_MODULE)
541 int amdgpu_si_support = 0;
542 MODULE_PARM_DESC(si_support, "SI support (1 = enabled, 0 = disabled (default))");
543 #else
544 int amdgpu_si_support = 1;
545 MODULE_PARM_DESC(si_support, "SI support (1 = enabled (default), 0 = disabled)");
546 #endif
547
548 module_param_named(si_support, amdgpu_si_support, int, 0444);
549 #endif
550
551 /**
552  * DOC: cik_support (int)
553  * Set CIK support driver. This parameter works after set config CONFIG_DRM_AMDGPU_CIK. For CIK asic, when radeon driver is enabled,
554  * set value 0 to use radeon driver, while set value 1 to use amdgpu driver. The default is using radeon driver when it available,
555  * otherwise using amdgpu driver.
556  */
557 #ifdef CONFIG_DRM_AMDGPU_CIK
558
559 #if defined(CONFIG_DRM_RADEON) || defined(CONFIG_DRM_RADEON_MODULE)
560 int amdgpu_cik_support = 0;
561 MODULE_PARM_DESC(cik_support, "CIK support (1 = enabled, 0 = disabled (default))");
562 #else
563 int amdgpu_cik_support = 1;
564 MODULE_PARM_DESC(cik_support, "CIK support (1 = enabled (default), 0 = disabled)");
565 #endif
566
567 module_param_named(cik_support, amdgpu_cik_support, int, 0444);
568 #endif
569
570 /**
571  * DOC: smu_memory_pool_size (uint)
572  * It is used to reserve gtt for smu debug usage, setting value 0 to disable it. The actual size is value * 256MiB.
573  * E.g. 0x1 = 256Mbyte, 0x2 = 512Mbyte, 0x4 = 1 Gbyte, 0x8 = 2GByte. The default is 0 (disabled).
574  */
575 MODULE_PARM_DESC(smu_memory_pool_size,
576         "reserve gtt for smu debug usage, 0 = disable,"
577                 "0x1 = 256Mbyte, 0x2 = 512Mbyte, 0x4 = 1 Gbyte, 0x8 = 2GByte");
578 module_param_named(smu_memory_pool_size, amdgpu_smu_memory_pool_size, uint, 0444);
579
580 /**
581  * DOC: async_gfx_ring (int)
582  * It is used to enable gfx rings that could be configured with different prioritites or equal priorities
583  */
584 MODULE_PARM_DESC(async_gfx_ring,
585         "Asynchronous GFX rings that could be configured with either different priorities (HP3D ring and LP3D ring), or equal priorities (0 = disabled, 1 = enabled (default))");
586 module_param_named(async_gfx_ring, amdgpu_async_gfx_ring, int, 0444);
587
588 /**
589  * DOC: mcbp (int)
590  * It is used to enable mid command buffer preemption. (0 = disabled (default), 1 = enabled)
591  */
592 MODULE_PARM_DESC(mcbp,
593         "Enable Mid-command buffer preemption (0 = disabled (default), 1 = enabled)");
594 module_param_named(mcbp, amdgpu_mcbp, int, 0444);
595
596 /**
597  * DOC: discovery (int)
598  * Allow driver to discover hardware IP information from IP Discovery table at the top of VRAM.
599  * (-1 = auto (default), 0 = disabled, 1 = enabled)
600  */
601 MODULE_PARM_DESC(discovery,
602         "Allow driver to discover hardware IPs from IP Discovery table at the top of VRAM");
603 module_param_named(discovery, amdgpu_discovery, int, 0444);
604
605 /**
606  * DOC: mes (int)
607  * Enable Micro Engine Scheduler. This is a new hw scheduling engine for gfx, sdma, and compute.
608  * (0 = disabled (default), 1 = enabled)
609  */
610 MODULE_PARM_DESC(mes,
611         "Enable Micro Engine Scheduler (0 = disabled (default), 1 = enabled)");
612 module_param_named(mes, amdgpu_mes, int, 0444);
613
614 MODULE_PARM_DESC(noretry,
615         "Disable retry faults (0 = retry enabled, 1 = retry disabled (default))");
616 module_param_named(noretry, amdgpu_noretry, int, 0644);
617
618 #ifdef CONFIG_HSA_AMD
619 /**
620  * DOC: sched_policy (int)
621  * Set scheduling policy. Default is HWS(hardware scheduling) with over-subscription.
622  * Setting 1 disables over-subscription. Setting 2 disables HWS and statically
623  * assigns queues to HQDs.
624  */
625 int sched_policy = KFD_SCHED_POLICY_HWS;
626 module_param(sched_policy, int, 0444);
627 MODULE_PARM_DESC(sched_policy,
628         "Scheduling policy (0 = HWS (Default), 1 = HWS without over-subscription, 2 = Non-HWS (Used for debugging only)");
629
630 /**
631  * DOC: hws_max_conc_proc (int)
632  * Maximum number of processes that HWS can schedule concurrently. The maximum is the
633  * number of VMIDs assigned to the HWS, which is also the default.
634  */
635 int hws_max_conc_proc = 8;
636 module_param(hws_max_conc_proc, int, 0444);
637 MODULE_PARM_DESC(hws_max_conc_proc,
638         "Max # processes HWS can execute concurrently when sched_policy=0 (0 = no concurrency, #VMIDs for KFD = Maximum(default))");
639
640 /**
641  * DOC: cwsr_enable (int)
642  * CWSR(compute wave store and resume) allows the GPU to preempt shader execution in
643  * the middle of a compute wave. Default is 1 to enable this feature. Setting 0
644  * disables it.
645  */
646 int cwsr_enable = 1;
647 module_param(cwsr_enable, int, 0444);
648 MODULE_PARM_DESC(cwsr_enable, "CWSR enable (0 = Off, 1 = On (Default))");
649
650 /**
651  * DOC: max_num_of_queues_per_device (int)
652  * Maximum number of queues per device. Valid setting is between 1 and 4096. Default
653  * is 4096.
654  */
655 int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
656 module_param(max_num_of_queues_per_device, int, 0444);
657 MODULE_PARM_DESC(max_num_of_queues_per_device,
658         "Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
659
660 /**
661  * DOC: send_sigterm (int)
662  * Send sigterm to HSA process on unhandled exceptions. Default is not to send sigterm
663  * but just print errors on dmesg. Setting 1 enables sending sigterm.
664  */
665 int send_sigterm;
666 module_param(send_sigterm, int, 0444);
667 MODULE_PARM_DESC(send_sigterm,
668         "Send sigterm to HSA process on unhandled exception (0 = disable, 1 = enable)");
669
670 /**
671  * DOC: debug_largebar (int)
672  * Set debug_largebar as 1 to enable simulating large-bar capability on non-large bar
673  * system. This limits the VRAM size reported to ROCm applications to the visible
674  * size, usually 256MB.
675  * Default value is 0, diabled.
676  */
677 int debug_largebar;
678 module_param(debug_largebar, int, 0444);
679 MODULE_PARM_DESC(debug_largebar,
680         "Debug large-bar flag used to simulate large-bar capability on non-large bar machine (0 = disable, 1 = enable)");
681
682 /**
683  * DOC: ignore_crat (int)
684  * Ignore CRAT table during KFD initialization. By default, KFD uses the ACPI CRAT
685  * table to get information about AMD APUs. This option can serve as a workaround on
686  * systems with a broken CRAT table.
687  */
688 int ignore_crat;
689 module_param(ignore_crat, int, 0444);
690 MODULE_PARM_DESC(ignore_crat,
691         "Ignore CRAT table during KFD initialization (0 = use CRAT (default), 1 = ignore CRAT)");
692
693 /**
694  * DOC: halt_if_hws_hang (int)
695  * Halt if HWS hang is detected. Default value, 0, disables the halt on hang.
696  * Setting 1 enables halt on hang.
697  */
698 int halt_if_hws_hang;
699 module_param(halt_if_hws_hang, int, 0644);
700 MODULE_PARM_DESC(halt_if_hws_hang, "Halt if HWS hang is detected (0 = off (default), 1 = on)");
701
702 /**
703  * DOC: hws_gws_support(bool)
704  * Whether HWS support gws barriers. Default value: false (not supported)
705  * This will be replaced with a MEC firmware version check once firmware
706  * is ready
707  */
708 bool hws_gws_support;
709 module_param(hws_gws_support, bool, 0444);
710 MODULE_PARM_DESC(hws_gws_support, "MEC FW support gws barriers (false = not supported (Default), true = supported)");
711
712 /**
713   * DOC: queue_preemption_timeout_ms (int)
714   * queue preemption timeout in ms (1 = Minimum, 9000 = default)
715   */
716 int queue_preemption_timeout_ms = 9000;
717 module_param(queue_preemption_timeout_ms, int, 0644);
718 MODULE_PARM_DESC(queue_preemption_timeout_ms, "queue preemption timeout in ms (1 = Minimum, 9000 = default)");
719 #endif
720
721 /**
722  * DOC: dcfeaturemask (uint)
723  * Override display features enabled. See enum DC_FEATURE_MASK in drivers/gpu/drm/amd/include/amd_shared.h.
724  * The default is the current set of stable display features.
725  */
726 MODULE_PARM_DESC(dcfeaturemask, "all stable DC features enabled (default))");
727 module_param_named(dcfeaturemask, amdgpu_dc_feature_mask, uint, 0444);
728
729 /**
730  * DOC: abmlevel (uint)
731  * Override the default ABM (Adaptive Backlight Management) level used for DC
732  * enabled hardware. Requires DMCU to be supported and loaded.
733  * Valid levels are 0-4. A value of 0 indicates that ABM should be disabled by
734  * default. Values 1-4 control the maximum allowable brightness reduction via
735  * the ABM algorithm, with 1 being the least reduction and 4 being the most
736  * reduction.
737  *
738  * Defaults to 0, or disabled. Userspace can still override this level later
739  * after boot.
740  */
741 uint amdgpu_dm_abm_level = 0;
742 MODULE_PARM_DESC(abmlevel, "ABM level (0 = off (default), 1-4 = backlight reduction level) ");
743 module_param_named(abmlevel, amdgpu_dm_abm_level, uint, 0444);
744
745 static const struct pci_device_id pciidlist[] = {
746 #ifdef  CONFIG_DRM_AMDGPU_SI
747         {0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
748         {0x1002, 0x6784, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
749         {0x1002, 0x6788, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
750         {0x1002, 0x678A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
751         {0x1002, 0x6790, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
752         {0x1002, 0x6791, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
753         {0x1002, 0x6792, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
754         {0x1002, 0x6798, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
755         {0x1002, 0x6799, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
756         {0x1002, 0x679A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
757         {0x1002, 0x679B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
758         {0x1002, 0x679E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
759         {0x1002, 0x679F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
760         {0x1002, 0x6800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
761         {0x1002, 0x6801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
762         {0x1002, 0x6802, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
763         {0x1002, 0x6806, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
764         {0x1002, 0x6808, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
765         {0x1002, 0x6809, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
766         {0x1002, 0x6810, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
767         {0x1002, 0x6811, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
768         {0x1002, 0x6816, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
769         {0x1002, 0x6817, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
770         {0x1002, 0x6818, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
771         {0x1002, 0x6819, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
772         {0x1002, 0x6600, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
773         {0x1002, 0x6601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
774         {0x1002, 0x6602, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
775         {0x1002, 0x6603, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
776         {0x1002, 0x6604, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
777         {0x1002, 0x6605, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
778         {0x1002, 0x6606, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
779         {0x1002, 0x6607, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
780         {0x1002, 0x6608, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
781         {0x1002, 0x6610, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
782         {0x1002, 0x6611, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
783         {0x1002, 0x6613, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
784         {0x1002, 0x6617, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
785         {0x1002, 0x6620, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
786         {0x1002, 0x6621, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
787         {0x1002, 0x6623, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
788         {0x1002, 0x6631, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
789         {0x1002, 0x6820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
790         {0x1002, 0x6821, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
791         {0x1002, 0x6822, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
792         {0x1002, 0x6823, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
793         {0x1002, 0x6824, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
794         {0x1002, 0x6825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
795         {0x1002, 0x6826, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
796         {0x1002, 0x6827, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
797         {0x1002, 0x6828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
798         {0x1002, 0x6829, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
799         {0x1002, 0x682A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
800         {0x1002, 0x682B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
801         {0x1002, 0x682C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
802         {0x1002, 0x682D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
803         {0x1002, 0x682F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
804         {0x1002, 0x6830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
805         {0x1002, 0x6831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
806         {0x1002, 0x6835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
807         {0x1002, 0x6837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
808         {0x1002, 0x6838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
809         {0x1002, 0x6839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
810         {0x1002, 0x683B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
811         {0x1002, 0x683D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
812         {0x1002, 0x683F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
813         {0x1002, 0x6660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
814         {0x1002, 0x6663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
815         {0x1002, 0x6664, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
816         {0x1002, 0x6665, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
817         {0x1002, 0x6667, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
818         {0x1002, 0x666F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
819 #endif
820 #ifdef CONFIG_DRM_AMDGPU_CIK
821         /* Kaveri */
822         {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
823         {0x1002, 0x1305, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
824         {0x1002, 0x1306, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
825         {0x1002, 0x1307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
826         {0x1002, 0x1309, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
827         {0x1002, 0x130A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
828         {0x1002, 0x130B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
829         {0x1002, 0x130C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
830         {0x1002, 0x130D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
831         {0x1002, 0x130E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
832         {0x1002, 0x130F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
833         {0x1002, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
834         {0x1002, 0x1311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
835         {0x1002, 0x1312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
836         {0x1002, 0x1313, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
837         {0x1002, 0x1315, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
838         {0x1002, 0x1316, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
839         {0x1002, 0x1317, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
840         {0x1002, 0x1318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
841         {0x1002, 0x131B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
842         {0x1002, 0x131C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
843         {0x1002, 0x131D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
844         /* Bonaire */
845         {0x1002, 0x6640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
846         {0x1002, 0x6641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
847         {0x1002, 0x6646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
848         {0x1002, 0x6647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
849         {0x1002, 0x6649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
850         {0x1002, 0x6650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
851         {0x1002, 0x6651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
852         {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
853         {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
854         {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
855         {0x1002, 0x665f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
856         /* Hawaii */
857         {0x1002, 0x67A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
858         {0x1002, 0x67A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
859         {0x1002, 0x67A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
860         {0x1002, 0x67A8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
861         {0x1002, 0x67A9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
862         {0x1002, 0x67AA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
863         {0x1002, 0x67B0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
864         {0x1002, 0x67B1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
865         {0x1002, 0x67B8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
866         {0x1002, 0x67B9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
867         {0x1002, 0x67BA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
868         {0x1002, 0x67BE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
869         /* Kabini */
870         {0x1002, 0x9830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
871         {0x1002, 0x9831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
872         {0x1002, 0x9832, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
873         {0x1002, 0x9833, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
874         {0x1002, 0x9834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
875         {0x1002, 0x9835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
876         {0x1002, 0x9836, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
877         {0x1002, 0x9837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
878         {0x1002, 0x9838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
879         {0x1002, 0x9839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
880         {0x1002, 0x983a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
881         {0x1002, 0x983b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
882         {0x1002, 0x983c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
883         {0x1002, 0x983d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
884         {0x1002, 0x983e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
885         {0x1002, 0x983f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
886         /* mullins */
887         {0x1002, 0x9850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
888         {0x1002, 0x9851, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
889         {0x1002, 0x9852, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
890         {0x1002, 0x9853, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
891         {0x1002, 0x9854, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
892         {0x1002, 0x9855, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
893         {0x1002, 0x9856, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
894         {0x1002, 0x9857, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
895         {0x1002, 0x9858, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
896         {0x1002, 0x9859, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
897         {0x1002, 0x985A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
898         {0x1002, 0x985B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
899         {0x1002, 0x985C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
900         {0x1002, 0x985D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
901         {0x1002, 0x985E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
902         {0x1002, 0x985F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
903 #endif
904         /* topaz */
905         {0x1002, 0x6900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
906         {0x1002, 0x6901, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
907         {0x1002, 0x6902, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
908         {0x1002, 0x6903, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
909         {0x1002, 0x6907, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
910         /* tonga */
911         {0x1002, 0x6920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
912         {0x1002, 0x6921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
913         {0x1002, 0x6928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
914         {0x1002, 0x6929, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
915         {0x1002, 0x692B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
916         {0x1002, 0x692F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
917         {0x1002, 0x6930, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
918         {0x1002, 0x6938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
919         {0x1002, 0x6939, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
920         /* fiji */
921         {0x1002, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_FIJI},
922         {0x1002, 0x730F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_FIJI},
923         /* carrizo */
924         {0x1002, 0x9870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
925         {0x1002, 0x9874, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
926         {0x1002, 0x9875, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
927         {0x1002, 0x9876, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
928         {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
929         /* stoney */
930         {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU},
931         /* Polaris11 */
932         {0x1002, 0x67E0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
933         {0x1002, 0x67E3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
934         {0x1002, 0x67E8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
935         {0x1002, 0x67EB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
936         {0x1002, 0x67EF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
937         {0x1002, 0x67FF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
938         {0x1002, 0x67E1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
939         {0x1002, 0x67E7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
940         {0x1002, 0x67E9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
941         /* Polaris10 */
942         {0x1002, 0x67C0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
943         {0x1002, 0x67C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
944         {0x1002, 0x67C2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
945         {0x1002, 0x67C4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
946         {0x1002, 0x67C7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
947         {0x1002, 0x67D0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
948         {0x1002, 0x67DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
949         {0x1002, 0x67C8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
950         {0x1002, 0x67C9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
951         {0x1002, 0x67CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
952         {0x1002, 0x67CC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
953         {0x1002, 0x67CF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
954         {0x1002, 0x6FDF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
955         /* Polaris12 */
956         {0x1002, 0x6980, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
957         {0x1002, 0x6981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
958         {0x1002, 0x6985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
959         {0x1002, 0x6986, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
960         {0x1002, 0x6987, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
961         {0x1002, 0x6995, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
962         {0x1002, 0x6997, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
963         {0x1002, 0x699F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS12},
964         /* VEGAM */
965         {0x1002, 0x694C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGAM},
966         {0x1002, 0x694E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGAM},
967         {0x1002, 0x694F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGAM},
968         /* Vega 10 */
969         {0x1002, 0x6860, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
970         {0x1002, 0x6861, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
971         {0x1002, 0x6862, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
972         {0x1002, 0x6863, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
973         {0x1002, 0x6864, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
974         {0x1002, 0x6867, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
975         {0x1002, 0x6868, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
976         {0x1002, 0x6869, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
977         {0x1002, 0x686a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
978         {0x1002, 0x686b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
979         {0x1002, 0x686c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
980         {0x1002, 0x686d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
981         {0x1002, 0x686e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
982         {0x1002, 0x686f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
983         {0x1002, 0x687f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA10},
984         /* Vega 12 */
985         {0x1002, 0x69A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA12},
986         {0x1002, 0x69A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA12},
987         {0x1002, 0x69A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA12},
988         {0x1002, 0x69A3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA12},
989         {0x1002, 0x69AF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA12},
990         /* Vega 20 */
991         {0x1002, 0x66A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
992         {0x1002, 0x66A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
993         {0x1002, 0x66A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
994         {0x1002, 0x66A3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
995         {0x1002, 0x66A4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
996         {0x1002, 0x66A7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
997         {0x1002, 0x66AF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VEGA20},
998         /* Raven */
999         {0x1002, 0x15dd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RAVEN|AMD_IS_APU},
1000         {0x1002, 0x15d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RAVEN|AMD_IS_APU},
1001         /* Arcturus */
1002         {0x1002, 0x738C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
1003         {0x1002, 0x7388, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
1004         {0x1002, 0x738E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
1005         {0x1002, 0x7390, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_ARCTURUS|AMD_EXP_HW_SUPPORT},
1006         /* Navi10 */
1007         {0x1002, 0x7310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1008         {0x1002, 0x7312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1009         {0x1002, 0x7318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1010         {0x1002, 0x7319, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1011         {0x1002, 0x731A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1012         {0x1002, 0x731B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1013         {0x1002, 0x731F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI10},
1014         /* Navi14 */
1015         {0x1002, 0x7340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI14},
1016
1017         /* Renoir */
1018         {0x1002, 0x1636, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RENOIR|AMD_IS_APU|AMD_EXP_HW_SUPPORT},
1019
1020         {0, 0, 0}
1021 };
1022
1023 MODULE_DEVICE_TABLE(pci, pciidlist);
1024
1025 static struct drm_driver kms_driver;
1026
1027 static int amdgpu_pci_probe(struct pci_dev *pdev,
1028                             const struct pci_device_id *ent)
1029 {
1030         struct drm_device *dev;
1031         unsigned long flags = ent->driver_data;
1032         int ret, retry = 0;
1033         bool supports_atomic = false;
1034
1035         if (!amdgpu_virtual_display &&
1036             amdgpu_device_asic_has_dc_support(flags & AMD_ASIC_MASK))
1037                 supports_atomic = true;
1038
1039         if ((flags & AMD_EXP_HW_SUPPORT) && !amdgpu_exp_hw_support) {
1040                 DRM_INFO("This hardware requires experimental hardware support.\n"
1041                          "See modparam exp_hw_support\n");
1042                 return -ENODEV;
1043         }
1044
1045         /* Get rid of things like offb */
1046         ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "amdgpudrmfb");
1047         if (ret)
1048                 return ret;
1049
1050         dev = drm_dev_alloc(&kms_driver, &pdev->dev);
1051         if (IS_ERR(dev))
1052                 return PTR_ERR(dev);
1053
1054         if (!supports_atomic)
1055                 dev->driver_features &= ~DRIVER_ATOMIC;
1056
1057         ret = pci_enable_device(pdev);
1058         if (ret)
1059                 goto err_free;
1060
1061         dev->pdev = pdev;
1062
1063         pci_set_drvdata(pdev, dev);
1064
1065 retry_init:
1066         ret = drm_dev_register(dev, ent->driver_data);
1067         if (ret == -EAGAIN && ++retry <= 3) {
1068                 DRM_INFO("retry init %d\n", retry);
1069                 /* Don't request EX mode too frequently which is attacking */
1070                 msleep(5000);
1071                 goto retry_init;
1072         } else if (ret)
1073                 goto err_pci;
1074
1075         return 0;
1076
1077 err_pci:
1078         pci_disable_device(pdev);
1079 err_free:
1080         drm_dev_put(dev);
1081         return ret;
1082 }
1083
1084 static void
1085 amdgpu_pci_remove(struct pci_dev *pdev)
1086 {
1087         struct drm_device *dev = pci_get_drvdata(pdev);
1088
1089         DRM_ERROR("Device removal is currently not supported outside of fbcon\n");
1090         drm_dev_unplug(dev);
1091         drm_dev_put(dev);
1092         pci_disable_device(pdev);
1093         pci_set_drvdata(pdev, NULL);
1094 }
1095
1096 static void
1097 amdgpu_pci_shutdown(struct pci_dev *pdev)
1098 {
1099         struct drm_device *dev = pci_get_drvdata(pdev);
1100         struct amdgpu_device *adev = dev->dev_private;
1101
1102         /* if we are running in a VM, make sure the device
1103          * torn down properly on reboot/shutdown.
1104          * unfortunately we can't detect certain
1105          * hypervisors so just do this all the time.
1106          */
1107         adev->mp1_state = PP_MP1_STATE_UNLOAD;
1108         amdgpu_device_ip_suspend(adev);
1109         adev->mp1_state = PP_MP1_STATE_NONE;
1110 }
1111
1112 static int amdgpu_pmops_suspend(struct device *dev)
1113 {
1114         struct drm_device *drm_dev = dev_get_drvdata(dev);
1115
1116         return amdgpu_device_suspend(drm_dev, true, true);
1117 }
1118
1119 static int amdgpu_pmops_resume(struct device *dev)
1120 {
1121         struct drm_device *drm_dev = dev_get_drvdata(dev);
1122
1123         /* GPU comes up enabled by the bios on resume */
1124         if (amdgpu_device_is_px(drm_dev)) {
1125                 pm_runtime_disable(dev);
1126                 pm_runtime_set_active(dev);
1127                 pm_runtime_enable(dev);
1128         }
1129
1130         return amdgpu_device_resume(drm_dev, true, true);
1131 }
1132
1133 static int amdgpu_pmops_freeze(struct device *dev)
1134 {
1135         struct drm_device *drm_dev = dev_get_drvdata(dev);
1136
1137         return amdgpu_device_suspend(drm_dev, false, true);
1138 }
1139
1140 static int amdgpu_pmops_thaw(struct device *dev)
1141 {
1142         struct drm_device *drm_dev = dev_get_drvdata(dev);
1143
1144         return amdgpu_device_resume(drm_dev, false, true);
1145 }
1146
1147 static int amdgpu_pmops_poweroff(struct device *dev)
1148 {
1149         struct drm_device *drm_dev = dev_get_drvdata(dev);
1150
1151         return amdgpu_device_suspend(drm_dev, true, true);
1152 }
1153
1154 static int amdgpu_pmops_restore(struct device *dev)
1155 {
1156         struct drm_device *drm_dev = dev_get_drvdata(dev);
1157
1158         return amdgpu_device_resume(drm_dev, false, true);
1159 }
1160
1161 static int amdgpu_pmops_runtime_suspend(struct device *dev)
1162 {
1163         struct pci_dev *pdev = to_pci_dev(dev);
1164         struct drm_device *drm_dev = pci_get_drvdata(pdev);
1165         int ret;
1166
1167         if (!amdgpu_device_is_px(drm_dev)) {
1168                 pm_runtime_forbid(dev);
1169                 return -EBUSY;
1170         }
1171
1172         drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
1173         drm_kms_helper_poll_disable(drm_dev);
1174
1175         ret = amdgpu_device_suspend(drm_dev, false, false);
1176         pci_save_state(pdev);
1177         pci_disable_device(pdev);
1178         pci_ignore_hotplug(pdev);
1179         if (amdgpu_is_atpx_hybrid())
1180                 pci_set_power_state(pdev, PCI_D3cold);
1181         else if (!amdgpu_has_atpx_dgpu_power_cntl())
1182                 pci_set_power_state(pdev, PCI_D3hot);
1183         drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
1184
1185         return 0;
1186 }
1187
1188 static int amdgpu_pmops_runtime_resume(struct device *dev)
1189 {
1190         struct pci_dev *pdev = to_pci_dev(dev);
1191         struct drm_device *drm_dev = pci_get_drvdata(pdev);
1192         int ret;
1193
1194         if (!amdgpu_device_is_px(drm_dev))
1195                 return -EINVAL;
1196
1197         drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
1198
1199         if (amdgpu_is_atpx_hybrid() ||
1200             !amdgpu_has_atpx_dgpu_power_cntl())
1201                 pci_set_power_state(pdev, PCI_D0);
1202         pci_restore_state(pdev);
1203         ret = pci_enable_device(pdev);
1204         if (ret)
1205                 return ret;
1206         pci_set_master(pdev);
1207
1208         ret = amdgpu_device_resume(drm_dev, false, false);
1209         drm_kms_helper_poll_enable(drm_dev);
1210         drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
1211         return 0;
1212 }
1213
1214 static int amdgpu_pmops_runtime_idle(struct device *dev)
1215 {
1216         struct drm_device *drm_dev = dev_get_drvdata(dev);
1217         struct drm_crtc *crtc;
1218
1219         if (!amdgpu_device_is_px(drm_dev)) {
1220                 pm_runtime_forbid(dev);
1221                 return -EBUSY;
1222         }
1223
1224         list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
1225                 if (crtc->enabled) {
1226                         DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
1227                         return -EBUSY;
1228                 }
1229         }
1230
1231         pm_runtime_mark_last_busy(dev);
1232         pm_runtime_autosuspend(dev);
1233         /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
1234         return 1;
1235 }
1236
1237 long amdgpu_drm_ioctl(struct file *filp,
1238                       unsigned int cmd, unsigned long arg)
1239 {
1240         struct drm_file *file_priv = filp->private_data;
1241         struct drm_device *dev;
1242         long ret;
1243         dev = file_priv->minor->dev;
1244         ret = pm_runtime_get_sync(dev->dev);
1245         if (ret < 0)
1246                 return ret;
1247
1248         ret = drm_ioctl(filp, cmd, arg);
1249
1250         pm_runtime_mark_last_busy(dev->dev);
1251         pm_runtime_put_autosuspend(dev->dev);
1252         return ret;
1253 }
1254
1255 static const struct dev_pm_ops amdgpu_pm_ops = {
1256         .suspend = amdgpu_pmops_suspend,
1257         .resume = amdgpu_pmops_resume,
1258         .freeze = amdgpu_pmops_freeze,
1259         .thaw = amdgpu_pmops_thaw,
1260         .poweroff = amdgpu_pmops_poweroff,
1261         .restore = amdgpu_pmops_restore,
1262         .runtime_suspend = amdgpu_pmops_runtime_suspend,
1263         .runtime_resume = amdgpu_pmops_runtime_resume,
1264         .runtime_idle = amdgpu_pmops_runtime_idle,
1265 };
1266
1267 static int amdgpu_flush(struct file *f, fl_owner_t id)
1268 {
1269         struct drm_file *file_priv = f->private_data;
1270         struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
1271         long timeout = MAX_WAIT_SCHED_ENTITY_Q_EMPTY;
1272
1273         timeout = amdgpu_ctx_mgr_entity_flush(&fpriv->ctx_mgr, timeout);
1274         timeout = amdgpu_vm_wait_idle(&fpriv->vm, timeout);
1275
1276         return timeout >= 0 ? 0 : timeout;
1277 }
1278
1279 static const struct file_operations amdgpu_driver_kms_fops = {
1280         .owner = THIS_MODULE,
1281         .open = drm_open,
1282         .flush = amdgpu_flush,
1283         .release = drm_release,
1284         .unlocked_ioctl = amdgpu_drm_ioctl,
1285         .mmap = amdgpu_mmap,
1286         .poll = drm_poll,
1287         .read = drm_read,
1288 #ifdef CONFIG_COMPAT
1289         .compat_ioctl = amdgpu_kms_compat_ioctl,
1290 #endif
1291 };
1292
1293 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv)
1294 {
1295         struct drm_file *file;
1296
1297         if (!filp)
1298                 return -EINVAL;
1299
1300         if (filp->f_op != &amdgpu_driver_kms_fops) {
1301                 return -EINVAL;
1302         }
1303
1304         file = filp->private_data;
1305         *fpriv = file->driver_priv;
1306         return 0;
1307 }
1308
1309 int amdgpu_device_get_job_timeout_settings(struct amdgpu_device *adev)
1310 {
1311         char *input = amdgpu_lockup_timeout;
1312         char *timeout_setting = NULL;
1313         int index = 0;
1314         long timeout;
1315         int ret = 0;
1316
1317         /*
1318          * By default timeout for non compute jobs is 10000.
1319          * And there is no timeout enforced on compute jobs.
1320          */
1321         adev->gfx_timeout = msecs_to_jiffies(10000);
1322         adev->sdma_timeout = adev->video_timeout = adev->gfx_timeout;
1323         adev->compute_timeout = MAX_SCHEDULE_TIMEOUT;
1324
1325         if (strnlen(input, AMDGPU_MAX_TIMEOUT_PARAM_LENTH)) {
1326                 while ((timeout_setting = strsep(&input, ",")) &&
1327                                 strnlen(timeout_setting, AMDGPU_MAX_TIMEOUT_PARAM_LENTH)) {
1328                         ret = kstrtol(timeout_setting, 0, &timeout);
1329                         if (ret)
1330                                 return ret;
1331
1332                         if (timeout == 0) {
1333                                 index++;
1334                                 continue;
1335                         } else if (timeout < 0) {
1336                                 timeout = MAX_SCHEDULE_TIMEOUT;
1337                         } else {
1338                                 timeout = msecs_to_jiffies(timeout);
1339                         }
1340
1341                         switch (index++) {
1342                         case 0:
1343                                 adev->gfx_timeout = timeout;
1344                                 break;
1345                         case 1:
1346                                 adev->compute_timeout = timeout;
1347                                 break;
1348                         case 2:
1349                                 adev->sdma_timeout = timeout;
1350                                 break;
1351                         case 3:
1352                                 adev->video_timeout = timeout;
1353                                 break;
1354                         default:
1355                                 break;
1356                         }
1357                 }
1358                 /*
1359                  * There is only one value specified and
1360                  * it should apply to all non-compute jobs.
1361                  */
1362                 if (index == 1)
1363                         adev->sdma_timeout = adev->video_timeout = adev->gfx_timeout;
1364         }
1365
1366         return ret;
1367 }
1368
1369 static bool
1370 amdgpu_get_crtc_scanout_position(struct drm_device *dev, unsigned int pipe,
1371                                  bool in_vblank_irq, int *vpos, int *hpos,
1372                                  ktime_t *stime, ktime_t *etime,
1373                                  const struct drm_display_mode *mode)
1374 {
1375         return amdgpu_display_get_crtc_scanoutpos(dev, pipe, 0, vpos, hpos,
1376                                                   stime, etime, mode);
1377 }
1378
1379 static struct drm_driver kms_driver = {
1380         .driver_features =
1381             DRIVER_USE_AGP | DRIVER_ATOMIC |
1382             DRIVER_GEM |
1383             DRIVER_RENDER | DRIVER_MODESET | DRIVER_SYNCOBJ,
1384         .load = amdgpu_driver_load_kms,
1385         .open = amdgpu_driver_open_kms,
1386         .postclose = amdgpu_driver_postclose_kms,
1387         .lastclose = amdgpu_driver_lastclose_kms,
1388         .unload = amdgpu_driver_unload_kms,
1389         .get_vblank_counter = amdgpu_get_vblank_counter_kms,
1390         .enable_vblank = amdgpu_enable_vblank_kms,
1391         .disable_vblank = amdgpu_disable_vblank_kms,
1392         .get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos,
1393         .get_scanout_position = amdgpu_get_crtc_scanout_position,
1394         .irq_handler = amdgpu_irq_handler,
1395         .ioctls = amdgpu_ioctls_kms,
1396         .gem_free_object_unlocked = amdgpu_gem_object_free,
1397         .gem_open_object = amdgpu_gem_object_open,
1398         .gem_close_object = amdgpu_gem_object_close,
1399         .dumb_create = amdgpu_mode_dumb_create,
1400         .dumb_map_offset = amdgpu_mode_dumb_mmap,
1401         .fops = &amdgpu_driver_kms_fops,
1402
1403         .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
1404         .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
1405         .gem_prime_export = amdgpu_gem_prime_export,
1406         .gem_prime_import = amdgpu_gem_prime_import,
1407         .gem_prime_get_sg_table = amdgpu_gem_prime_get_sg_table,
1408         .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
1409         .gem_prime_vmap = amdgpu_gem_prime_vmap,
1410         .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
1411         .gem_prime_mmap = amdgpu_gem_prime_mmap,
1412
1413         .name = DRIVER_NAME,
1414         .desc = DRIVER_DESC,
1415         .date = DRIVER_DATE,
1416         .major = KMS_DRIVER_MAJOR,
1417         .minor = KMS_DRIVER_MINOR,
1418         .patchlevel = KMS_DRIVER_PATCHLEVEL,
1419 };
1420
1421 static struct pci_driver amdgpu_kms_pci_driver = {
1422         .name = DRIVER_NAME,
1423         .id_table = pciidlist,
1424         .probe = amdgpu_pci_probe,
1425         .remove = amdgpu_pci_remove,
1426         .shutdown = amdgpu_pci_shutdown,
1427         .driver.pm = &amdgpu_pm_ops,
1428 };
1429
1430
1431
1432 static int __init amdgpu_init(void)
1433 {
1434         int r;
1435
1436         if (vgacon_text_force()) {
1437                 DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n");
1438                 return -EINVAL;
1439         }
1440
1441         r = amdgpu_sync_init();
1442         if (r)
1443                 goto error_sync;
1444
1445         r = amdgpu_fence_slab_init();
1446         if (r)
1447                 goto error_fence;
1448
1449         DRM_INFO("amdgpu kernel modesetting enabled.\n");
1450         kms_driver.num_ioctls = amdgpu_max_kms_ioctl;
1451         amdgpu_register_atpx_handler();
1452
1453         /* Ignore KFD init failures. Normal when CONFIG_HSA_AMD is not set. */
1454         amdgpu_amdkfd_init();
1455
1456         /* let modprobe override vga console setting */
1457         return pci_register_driver(&amdgpu_kms_pci_driver);
1458
1459 error_fence:
1460         amdgpu_sync_fini();
1461
1462 error_sync:
1463         return r;
1464 }
1465
1466 static void __exit amdgpu_exit(void)
1467 {
1468         amdgpu_amdkfd_fini();
1469         pci_unregister_driver(&amdgpu_kms_pci_driver);
1470         amdgpu_unregister_atpx_handler();
1471         amdgpu_sync_fini();
1472         amdgpu_fence_slab_fini();
1473         mmu_notifier_synchronize();
1474 }
1475
1476 module_init(amdgpu_init);
1477 module_exit(amdgpu_exit);
1478
1479 MODULE_AUTHOR(DRIVER_AUTHOR);
1480 MODULE_DESCRIPTION(DRIVER_DESC);
1481 MODULE_LICENSE("GPL and additional rights");