blob: e7ae67234a7bc4e9428e38ab5762cf056f884e6c [file] [log] [blame]
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001/**
2 * \file amdgpu_drv.c
3 * AMD Amdgpu driver
4 *
5 * \author Gareth Hughes <gareth@valinux.com>
6 */
7
8/*
9 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
10 * All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice (including the next
20 * paragraph) shall be included in all copies or substantial portions of the
21 * Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
27 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
29 * OTHER DEALINGS IN THE SOFTWARE.
30 */
31
32#include <drm/drmP.h>
33#include <drm/amdgpu_drm.h>
34#include <drm/drm_gem.h>
35#include "amdgpu_drv.h"
36
37#include <drm/drm_pciids.h>
38#include <linux/console.h>
39#include <linux/module.h>
40#include <linux/pm_runtime.h>
41#include <linux/vga_switcheroo.h>
42#include "drm_crtc_helper.h"
43
44#include "amdgpu.h"
45#include "amdgpu_irq.h"
46
Oded Gabbay130e0372015-06-12 21:35:14 +030047#include "amdgpu_amdkfd.h"
48
Alex Deucherd38ceaf2015-04-20 16:55:21 -040049/*
50 * KMS wrapper.
51 * - 3.0.0 - initial driver
Marek Olšák6055f372015-08-18 23:58:47 +020052 * - 3.1.0 - allow reading more status registers (GRBM, SRBM, SDMA, CP)
Marek Olšákf84e63f2016-04-28 14:32:44 +020053 * - 3.2.0 - GFX8: Uses EOP_TC_WB_ACTION_EN, so UMDs don't have to do the same
54 * at the end of IBs.
Christian Königd347ce62016-07-14 14:34:17 +020055 * - 3.3.0 - Add VM support for UVD on supported hardware.
Marek Olšák83a59b62016-08-17 23:58:58 +020056 * - 3.4.0 - Add AMDGPU_INFO_NUM_EVICTIONS.
Alex Deucher8dd31d72016-08-22 17:58:14 -040057 * - 3.5.0 - Add support for new UVD_NO_OP register.
Monk Liu753ad492016-08-26 13:28:28 +080058 * - 3.6.0 - kmd involves use CONTEXT_CONTROL in ring buffer.
Alex Deucher9cee3c1f2016-09-21 18:04:50 -040059 * - 3.7.0 - Add support for VCE clock list packet
Alex Deucherd38ceaf2015-04-20 16:55:21 -040060 */
61#define KMS_DRIVER_MAJOR 3
Alex Deucher9cee3c1f2016-09-21 18:04:50 -040062#define KMS_DRIVER_MINOR 7
Alex Deucherd38ceaf2015-04-20 16:55:21 -040063#define KMS_DRIVER_PATCHLEVEL 0
64
65int amdgpu_vram_limit = 0;
66int amdgpu_gart_size = -1; /* auto */
Marek Olšák95844d22016-08-17 23:49:27 +020067int amdgpu_moverate = -1; /* auto */
Alex Deucherd38ceaf2015-04-20 16:55:21 -040068int amdgpu_benchmarking = 0;
69int amdgpu_testing = 0;
70int amdgpu_audio = -1;
71int amdgpu_disp_priority = 0;
72int amdgpu_hw_i2c = 0;
73int amdgpu_pcie_gen2 = -1;
74int amdgpu_msi = -1;
Alex Deuchera895c222015-08-13 13:20:20 -040075int amdgpu_lockup_timeout = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040076int amdgpu_dpm = -1;
77int amdgpu_smc_load_fw = 1;
78int amdgpu_aspm = -1;
79int amdgpu_runtime_pm = -1;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040080unsigned amdgpu_ip_block_mask = 0xffffffff;
81int amdgpu_bapm = -1;
82int amdgpu_deep_color = 0;
Christian Königed885b22015-10-15 17:34:20 +020083int amdgpu_vm_size = 64;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040084int amdgpu_vm_block_size = -1;
Christian Königd9c13152015-09-28 12:31:26 +020085int amdgpu_vm_fault_stop = 0;
Christian Königb495bd32015-09-10 14:00:35 +020086int amdgpu_vm_debug = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040087int amdgpu_exp_hw_support = 0;
Chunming Zhoub70f0142015-12-10 15:46:50 +080088int amdgpu_sched_jobs = 32;
Jammy Zhou4afcb302015-07-30 16:44:05 +080089int amdgpu_sched_hw_submission = 2;
Jammy Zhoue61710c2015-11-10 18:31:08 -050090int amdgpu_powerplay = -1;
Huang Rui6bb6b292016-05-24 13:47:05 +080091int amdgpu_powercontainment = 1;
Rex Zhuaf223df2016-07-28 16:51:47 +080092int amdgpu_sclk_deep_sleep_en = 1;
Alex Deuchercd474ba2016-02-04 10:21:23 -050093unsigned amdgpu_pcie_gen_cap = 0;
94unsigned amdgpu_pcie_lane_cap = 0;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020095unsigned amdgpu_cg_mask = 0xffffffff;
96unsigned amdgpu_pg_mask = 0xffffffff;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020097char *amdgpu_disable_cu = NULL;
Emily Deng9accf2f2016-08-10 16:01:25 +080098char *amdgpu_virtual_display = NULL;
Rex Zhu5141e9d2016-09-06 16:34:37 +080099unsigned amdgpu_pp_feature_mask = 0xffffffff;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400100
101MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
102module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
103
104MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32, 64, etc., -1 = auto)");
105module_param_named(gartsize, amdgpu_gart_size, int, 0600);
106
Marek Olšák95844d22016-08-17 23:49:27 +0200107MODULE_PARM_DESC(moverate, "Maximum buffer migration rate in MB/s. (32, 64, etc., -1=auto, 0=1=disabled)");
108module_param_named(moverate, amdgpu_moverate, int, 0600);
109
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400110MODULE_PARM_DESC(benchmark, "Run benchmark");
111module_param_named(benchmark, amdgpu_benchmarking, int, 0444);
112
113MODULE_PARM_DESC(test, "Run tests");
114module_param_named(test, amdgpu_testing, int, 0444);
115
116MODULE_PARM_DESC(audio, "Audio enable (-1 = auto, 0 = disable, 1 = enable)");
117module_param_named(audio, amdgpu_audio, int, 0444);
118
119MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
120module_param_named(disp_priority, amdgpu_disp_priority, int, 0444);
121
122MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
123module_param_named(hw_i2c, amdgpu_hw_i2c, int, 0444);
124
125MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (-1 = auto, 0 = disable, 1 = enable)");
126module_param_named(pcie_gen2, amdgpu_pcie_gen2, int, 0444);
127
128MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
129module_param_named(msi, amdgpu_msi, int, 0444);
130
Alex Deuchera895c222015-08-13 13:20:20 -0400131MODULE_PARM_DESC(lockup_timeout, "GPU lockup timeout in ms (default 0 = disable)");
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400132module_param_named(lockup_timeout, amdgpu_lockup_timeout, int, 0444);
133
134MODULE_PARM_DESC(dpm, "DPM support (1 = enable, 0 = disable, -1 = auto)");
135module_param_named(dpm, amdgpu_dpm, int, 0444);
136
137MODULE_PARM_DESC(smc_load_fw, "SMC firmware loading(1 = enable, 0 = disable)");
138module_param_named(smc_load_fw, amdgpu_smc_load_fw, int, 0444);
139
140MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)");
141module_param_named(aspm, amdgpu_aspm, int, 0444);
142
143MODULE_PARM_DESC(runpm, "PX runtime pm (1 = force enable, 0 = disable, -1 = PX only default)");
144module_param_named(runpm, amdgpu_runtime_pm, int, 0444);
145
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400146MODULE_PARM_DESC(ip_block_mask, "IP Block Mask (all blocks enabled (default))");
147module_param_named(ip_block_mask, amdgpu_ip_block_mask, uint, 0444);
148
149MODULE_PARM_DESC(bapm, "BAPM support (1 = enable, 0 = disable, -1 = auto)");
150module_param_named(bapm, amdgpu_bapm, int, 0444);
151
152MODULE_PARM_DESC(deep_color, "Deep Color support (1 = enable, 0 = disable (default))");
153module_param_named(deep_color, amdgpu_deep_color, int, 0444);
154
Christian Königed885b22015-10-15 17:34:20 +0200155MODULE_PARM_DESC(vm_size, "VM address space size in gigabytes (default 64GB)");
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400156module_param_named(vm_size, amdgpu_vm_size, int, 0444);
157
158MODULE_PARM_DESC(vm_block_size, "VM page table size in bits (default depending on vm_size)");
159module_param_named(vm_block_size, amdgpu_vm_block_size, int, 0444);
160
Christian Königd9c13152015-09-28 12:31:26 +0200161MODULE_PARM_DESC(vm_fault_stop, "Stop on VM fault (0 = never (default), 1 = print first, 2 = always)");
162module_param_named(vm_fault_stop, amdgpu_vm_fault_stop, int, 0444);
163
Christian Königb495bd32015-09-10 14:00:35 +0200164MODULE_PARM_DESC(vm_debug, "Debug VM handling (0 = disabled (default), 1 = enabled)");
165module_param_named(vm_debug, amdgpu_vm_debug, int, 0644);
166
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400167MODULE_PARM_DESC(exp_hw_support, "experimental hw support (1 = enable, 0 = disable (default))");
168module_param_named(exp_hw_support, amdgpu_exp_hw_support, int, 0444);
169
Chunming Zhoub70f0142015-12-10 15:46:50 +0800170MODULE_PARM_DESC(sched_jobs, "the max number of jobs supported in the sw queue (default 32)");
Jammy Zhou1333f722015-07-30 16:36:58 +0800171module_param_named(sched_jobs, amdgpu_sched_jobs, int, 0444);
172
Jammy Zhou4afcb302015-07-30 16:44:05 +0800173MODULE_PARM_DESC(sched_hw_submission, "the max number of HW submissions (default 2)");
174module_param_named(sched_hw_submission, amdgpu_sched_hw_submission, int, 0444);
175
Jammy Zhou3a74f6f2015-07-21 14:01:50 +0800176#ifdef CONFIG_DRM_AMD_POWERPLAY
Jammy Zhoue61710c2015-11-10 18:31:08 -0500177MODULE_PARM_DESC(powerplay, "Powerplay component (1 = enable, 0 = disable, -1 = auto (default))");
Jammy Zhou3a74f6f2015-07-21 14:01:50 +0800178module_param_named(powerplay, amdgpu_powerplay, int, 0444);
Huang Rui6bb6b292016-05-24 13:47:05 +0800179
180MODULE_PARM_DESC(powercontainment, "Power Containment (1 = enable (default), 0 = disable)");
181module_param_named(powercontainment, amdgpu_powercontainment, int, 0444);
Rex Zhu5141e9d2016-09-06 16:34:37 +0800182
183MODULE_PARM_DESC(ppfeaturemask, "all power features enabled (default))");
184module_param_named(ppfeaturemask, amdgpu_pp_feature_mask, int, 0444);
Jammy Zhou3a74f6f2015-07-21 14:01:50 +0800185#endif
186
Rex Zhuaf223df2016-07-28 16:51:47 +0800187MODULE_PARM_DESC(sclkdeepsleep, "SCLK Deep Sleep (1 = enable (default), 0 = disable)");
188module_param_named(sclkdeepsleep, amdgpu_sclk_deep_sleep_en, int, 0444);
189
Alex Deuchercd474ba2016-02-04 10:21:23 -0500190MODULE_PARM_DESC(pcie_gen_cap, "PCIE Gen Caps (0: autodetect (default))");
191module_param_named(pcie_gen_cap, amdgpu_pcie_gen_cap, uint, 0444);
192
193MODULE_PARM_DESC(pcie_lane_cap, "PCIE Lane Caps (0: autodetect (default))");
194module_param_named(pcie_lane_cap, amdgpu_pcie_lane_cap, uint, 0444);
195
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +0200196MODULE_PARM_DESC(cg_mask, "Clockgating flags mask (0 = disable clock gating)");
197module_param_named(cg_mask, amdgpu_cg_mask, uint, 0444);
198
199MODULE_PARM_DESC(pg_mask, "Powergating flags mask (0 = disable power gating)");
200module_param_named(pg_mask, amdgpu_pg_mask, uint, 0444);
201
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +0200202MODULE_PARM_DESC(disable_cu, "Disable CUs (se.sh.cu,...)");
203module_param_named(disable_cu, amdgpu_disable_cu, charp, 0444);
204
Emily Deng9accf2f2016-08-10 16:01:25 +0800205MODULE_PARM_DESC(virtual_display, "Enable virtual display feature (the virtual_display will be set like xxxx:xx:xx.x;xxxx:xx:xx.x)");
206module_param_named(virtual_display, amdgpu_virtual_display, charp, 0444);
Emily Denge4430592016-08-08 11:37:29 +0800207
Nils Wallméniusf498d9e2016-04-10 16:29:59 +0200208static const struct pci_device_id pciidlist[] = {
Ken Wang78fbb682016-01-21 17:33:00 +0800209#ifdef CONFIG_DRM_AMDGPU_SI
210 {0x1002, 0x6780, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
211 {0x1002, 0x6784, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
212 {0x1002, 0x6788, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
213 {0x1002, 0x678A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
214 {0x1002, 0x6790, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
215 {0x1002, 0x6791, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
216 {0x1002, 0x6792, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
217 {0x1002, 0x6798, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
218 {0x1002, 0x6799, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
219 {0x1002, 0x679A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
220 {0x1002, 0x679B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
221 {0x1002, 0x679E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
222 {0x1002, 0x679F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TAHITI},
223 {0x1002, 0x6800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
224 {0x1002, 0x6801, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
225 {0x1002, 0x6802, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN|AMD_IS_MOBILITY},
226 {0x1002, 0x6806, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
227 {0x1002, 0x6808, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
228 {0x1002, 0x6809, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
229 {0x1002, 0x6810, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
230 {0x1002, 0x6811, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
231 {0x1002, 0x6816, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
232 {0x1002, 0x6817, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
233 {0x1002, 0x6818, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
234 {0x1002, 0x6819, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PITCAIRN},
235 {0x1002, 0x6600, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
236 {0x1002, 0x6601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
237 {0x1002, 0x6602, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
238 {0x1002, 0x6603, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
239 {0x1002, 0x6604, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
240 {0x1002, 0x6605, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
241 {0x1002, 0x6606, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
242 {0x1002, 0x6607, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
243 {0x1002, 0x6608, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
244 {0x1002, 0x6610, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
245 {0x1002, 0x6611, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
246 {0x1002, 0x6613, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
247 {0x1002, 0x6617, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
248 {0x1002, 0x6620, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
249 {0x1002, 0x6621, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
250 {0x1002, 0x6623, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND|AMD_IS_MOBILITY},
251 {0x1002, 0x6631, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_OLAND},
252 {0x1002, 0x6820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
253 {0x1002, 0x6821, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
254 {0x1002, 0x6822, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
255 {0x1002, 0x6823, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
256 {0x1002, 0x6824, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
257 {0x1002, 0x6825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
258 {0x1002, 0x6826, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
259 {0x1002, 0x6827, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
260 {0x1002, 0x6828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
261 {0x1002, 0x6829, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
262 {0x1002, 0x682A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
263 {0x1002, 0x682B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
264 {0x1002, 0x682C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
265 {0x1002, 0x682D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
266 {0x1002, 0x682F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
267 {0x1002, 0x6830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
268 {0x1002, 0x6831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE|AMD_IS_MOBILITY},
269 {0x1002, 0x6835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
270 {0x1002, 0x6837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
271 {0x1002, 0x6838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
272 {0x1002, 0x6839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
273 {0x1002, 0x683B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
274 {0x1002, 0x683D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
275 {0x1002, 0x683F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_VERDE},
276 {0x1002, 0x6660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
277 {0x1002, 0x6663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
278 {0x1002, 0x6664, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
279 {0x1002, 0x6665, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
280 {0x1002, 0x6667, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
281 {0x1002, 0x666F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAINAN|AMD_IS_MOBILITY},
282#endif
Alex Deucher89330c32015-04-20 17:36:52 -0400283#ifdef CONFIG_DRM_AMDGPU_CIK
284 /* Kaveri */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800285 {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
286 {0x1002, 0x1305, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
287 {0x1002, 0x1306, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
288 {0x1002, 0x1307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
289 {0x1002, 0x1309, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
290 {0x1002, 0x130A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
291 {0x1002, 0x130B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
292 {0x1002, 0x130C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
293 {0x1002, 0x130D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
294 {0x1002, 0x130E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
295 {0x1002, 0x130F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
296 {0x1002, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
297 {0x1002, 0x1311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
298 {0x1002, 0x1312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
299 {0x1002, 0x1313, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
300 {0x1002, 0x1315, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
301 {0x1002, 0x1316, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
302 {0x1002, 0x1317, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
303 {0x1002, 0x1318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
304 {0x1002, 0x131B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
305 {0x1002, 0x131C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
306 {0x1002, 0x131D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
Alex Deucher89330c32015-04-20 17:36:52 -0400307 /* Bonaire */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800308 {0x1002, 0x6640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
309 {0x1002, 0x6641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
310 {0x1002, 0x6646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
311 {0x1002, 0x6647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
Alex Deucher89330c32015-04-20 17:36:52 -0400312 {0x1002, 0x6649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
313 {0x1002, 0x6650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
314 {0x1002, 0x6651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
315 {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
316 {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
317 {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
Alex Deucherfb4f1732015-05-12 13:06:45 -0400318 {0x1002, 0x665f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
Alex Deucher89330c32015-04-20 17:36:52 -0400319 /* Hawaii */
320 {0x1002, 0x67A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
321 {0x1002, 0x67A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
322 {0x1002, 0x67A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
323 {0x1002, 0x67A8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
324 {0x1002, 0x67A9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
325 {0x1002, 0x67AA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
326 {0x1002, 0x67B0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
327 {0x1002, 0x67B1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
328 {0x1002, 0x67B8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
329 {0x1002, 0x67B9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
330 {0x1002, 0x67BA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
331 {0x1002, 0x67BE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
332 /* Kabini */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800333 {0x1002, 0x9830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
334 {0x1002, 0x9831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
335 {0x1002, 0x9832, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
336 {0x1002, 0x9833, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
337 {0x1002, 0x9834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
338 {0x1002, 0x9835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
339 {0x1002, 0x9836, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
340 {0x1002, 0x9837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
341 {0x1002, 0x9838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
342 {0x1002, 0x9839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
343 {0x1002, 0x983a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
344 {0x1002, 0x983b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
345 {0x1002, 0x983c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
346 {0x1002, 0x983d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
347 {0x1002, 0x983e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
348 {0x1002, 0x983f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
Alex Deucher89330c32015-04-20 17:36:52 -0400349 /* mullins */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800350 {0x1002, 0x9850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
351 {0x1002, 0x9851, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
352 {0x1002, 0x9852, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
353 {0x1002, 0x9853, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
354 {0x1002, 0x9854, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
355 {0x1002, 0x9855, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
356 {0x1002, 0x9856, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
357 {0x1002, 0x9857, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
358 {0x1002, 0x9858, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
359 {0x1002, 0x9859, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
360 {0x1002, 0x985A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
361 {0x1002, 0x985B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
362 {0x1002, 0x985C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
363 {0x1002, 0x985D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
364 {0x1002, 0x985E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
365 {0x1002, 0x985F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
Alex Deucher89330c32015-04-20 17:36:52 -0400366#endif
Alex Deucher1256a8b2015-04-20 17:37:54 -0400367 /* topaz */
Alex Deucherdba280b2016-02-02 16:24:20 -0500368 {0x1002, 0x6900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
369 {0x1002, 0x6901, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
370 {0x1002, 0x6902, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
371 {0x1002, 0x6903, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
372 {0x1002, 0x6907, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400373 /* tonga */
374 {0x1002, 0x6920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
375 {0x1002, 0x6921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
376 {0x1002, 0x6928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1f8d9622015-05-12 13:10:05 -0400377 {0x1002, 0x6929, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400378 {0x1002, 0x692B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
379 {0x1002, 0x692F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1f8d9622015-05-12 13:10:05 -0400380 {0x1002, 0x6930, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400381 {0x1002, 0x6938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
382 {0x1002, 0x6939, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
David Zhang2da78e22015-07-11 23:13:40 +0800383 /* fiji */
384 {0x1002, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_FIJI},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400385 /* carrizo */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800386 {0x1002, 0x9870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
387 {0x1002, 0x9874, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
388 {0x1002, 0x9875, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
389 {0x1002, 0x9876, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
390 {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
Samuel Li81b15092015-10-08 16:32:03 -0400391 /* stoney */
392 {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400393 /* Polaris11 */
394 {0x1002, 0x67E0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui35621b82016-05-17 09:52:02 +0800395 {0x1002, 0x67E3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400396 {0x1002, 0x67E8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400397 {0x1002, 0x67EB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui35621b82016-05-17 09:52:02 +0800398 {0x1002, 0x67EF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400399 {0x1002, 0x67FF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui35621b82016-05-17 09:52:02 +0800400 {0x1002, 0x67E1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
401 {0x1002, 0x67E7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
402 {0x1002, 0x67E9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS11},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400403 /* Polaris10 */
404 {0x1002, 0x67C0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
Flora Cui1dcf4802016-05-16 17:17:41 +0800405 {0x1002, 0x67C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
406 {0x1002, 0x67C2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
407 {0x1002, 0x67C4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
408 {0x1002, 0x67C7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
Flora Cui2cc0c0b2016-03-14 18:33:29 -0400409 {0x1002, 0x67DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
Flora Cui1dcf4802016-05-16 17:17:41 +0800410 {0x1002, 0x67C8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
411 {0x1002, 0x67C9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
412 {0x1002, 0x67CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
413 {0x1002, 0x67CC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
414 {0x1002, 0x67CF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_POLARIS10},
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400415
416 {0, 0, 0}
417};
418
419MODULE_DEVICE_TABLE(pci, pciidlist);
420
421static struct drm_driver kms_driver;
422
423static int amdgpu_kick_out_firmware_fb(struct pci_dev *pdev)
424{
425 struct apertures_struct *ap;
426 bool primary = false;
427
428 ap = alloc_apertures(1);
429 if (!ap)
430 return -ENOMEM;
431
432 ap->ranges[0].base = pci_resource_start(pdev, 0);
433 ap->ranges[0].size = pci_resource_len(pdev, 0);
434
435#ifdef CONFIG_X86
436 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
437#endif
438 remove_conflicting_framebuffers(ap, "amdgpudrmfb", primary);
439 kfree(ap);
440
441 return 0;
442}
443
444static int amdgpu_pci_probe(struct pci_dev *pdev,
445 const struct pci_device_id *ent)
446{
447 unsigned long flags = ent->driver_data;
448 int ret;
449
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800450 if ((flags & AMD_EXP_HW_SUPPORT) && !amdgpu_exp_hw_support) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400451 DRM_INFO("This hardware requires experimental hardware support.\n"
452 "See modparam exp_hw_support\n");
453 return -ENODEV;
454 }
455
Oded Gabbayefb1c652016-02-09 13:30:12 +0200456 /*
457 * Initialize amdkfd before starting radeon. If it was not loaded yet,
458 * defer radeon probing
459 */
460 ret = amdgpu_amdkfd_init();
461 if (ret == -EPROBE_DEFER)
462 return ret;
463
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400464 /* Get rid of things like offb */
465 ret = amdgpu_kick_out_firmware_fb(pdev);
466 if (ret)
467 return ret;
468
469 return drm_get_pci_dev(pdev, ent, &kms_driver);
470}
471
472static void
473amdgpu_pci_remove(struct pci_dev *pdev)
474{
475 struct drm_device *dev = pci_get_drvdata(pdev);
476
477 drm_put_dev(dev);
478}
479
Alex Deucher61e11302016-08-22 13:50:22 -0400480static void
481amdgpu_pci_shutdown(struct pci_dev *pdev)
482{
483 struct drm_device *dev = pci_get_drvdata(pdev);
484 struct amdgpu_device *adev = dev->dev_private;
485
486 /* if we are running in a VM, make sure the device
487 * torn down properly on reboot/shutdown
488 */
Monk Liu4e99a442016-03-31 13:26:59 +0800489 if (amdgpu_passthrough(adev))
Alex Deucher61e11302016-08-22 13:50:22 -0400490 amdgpu_pci_remove(pdev);
491}
492
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400493static int amdgpu_pmops_suspend(struct device *dev)
494{
495 struct pci_dev *pdev = to_pci_dev(dev);
jimqu74b0b152016-09-07 17:09:12 +0800496
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400497 struct drm_device *drm_dev = pci_get_drvdata(pdev);
Alex Deucher810ddc32016-08-23 13:25:49 -0400498 return amdgpu_device_suspend(drm_dev, true, true);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400499}
500
501static int amdgpu_pmops_resume(struct device *dev)
502{
503 struct pci_dev *pdev = to_pci_dev(dev);
504 struct drm_device *drm_dev = pci_get_drvdata(pdev);
Alex Deucher85e154c2016-08-27 14:53:08 -0400505
506 /* GPU comes up enabled by the bios on resume */
507 if (amdgpu_device_is_px(drm_dev)) {
508 pm_runtime_disable(dev);
509 pm_runtime_set_active(dev);
510 pm_runtime_enable(dev);
511 }
512
Alex Deucher810ddc32016-08-23 13:25:49 -0400513 return amdgpu_device_resume(drm_dev, true, true);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400514}
515
516static int amdgpu_pmops_freeze(struct device *dev)
517{
518 struct pci_dev *pdev = to_pci_dev(dev);
jimqu74b0b152016-09-07 17:09:12 +0800519
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400520 struct drm_device *drm_dev = pci_get_drvdata(pdev);
Alex Deucher810ddc32016-08-23 13:25:49 -0400521 return amdgpu_device_suspend(drm_dev, false, true);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400522}
523
524static int amdgpu_pmops_thaw(struct device *dev)
525{
526 struct pci_dev *pdev = to_pci_dev(dev);
jimqu74b0b152016-09-07 17:09:12 +0800527
528 struct drm_device *drm_dev = pci_get_drvdata(pdev);
529 return amdgpu_device_resume(drm_dev, false, true);
530}
531
532static int amdgpu_pmops_poweroff(struct device *dev)
533{
534 struct pci_dev *pdev = to_pci_dev(dev);
535
536 struct drm_device *drm_dev = pci_get_drvdata(pdev);
537 return amdgpu_device_suspend(drm_dev, true, true);
538}
539
540static int amdgpu_pmops_restore(struct device *dev)
541{
542 struct pci_dev *pdev = to_pci_dev(dev);
543
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400544 struct drm_device *drm_dev = pci_get_drvdata(pdev);
Alex Deucher810ddc32016-08-23 13:25:49 -0400545 return amdgpu_device_resume(drm_dev, false, true);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400546}
547
548static int amdgpu_pmops_runtime_suspend(struct device *dev)
549{
550 struct pci_dev *pdev = to_pci_dev(dev);
551 struct drm_device *drm_dev = pci_get_drvdata(pdev);
552 int ret;
553
554 if (!amdgpu_device_is_px(drm_dev)) {
555 pm_runtime_forbid(dev);
556 return -EBUSY;
557 }
558
559 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
560 drm_kms_helper_poll_disable(drm_dev);
561 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
562
Alex Deucher810ddc32016-08-23 13:25:49 -0400563 ret = amdgpu_device_suspend(drm_dev, false, false);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400564 pci_save_state(pdev);
565 pci_disable_device(pdev);
566 pci_ignore_hotplug(pdev);
Alex Deucher11670972016-06-02 09:08:32 -0400567 if (amdgpu_is_atpx_hybrid())
568 pci_set_power_state(pdev, PCI_D3cold);
Alex Deucher522761c2016-06-02 09:18:34 -0400569 else if (!amdgpu_has_atpx_dgpu_power_cntl())
Alex Deucher7e32aa62016-06-01 13:12:25 -0400570 pci_set_power_state(pdev, PCI_D3hot);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400571 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
572
573 return 0;
574}
575
576static int amdgpu_pmops_runtime_resume(struct device *dev)
577{
578 struct pci_dev *pdev = to_pci_dev(dev);
579 struct drm_device *drm_dev = pci_get_drvdata(pdev);
580 int ret;
581
582 if (!amdgpu_device_is_px(drm_dev))
583 return -EINVAL;
584
585 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
586
Alex Deucher522761c2016-06-02 09:18:34 -0400587 if (amdgpu_is_atpx_hybrid() ||
588 !amdgpu_has_atpx_dgpu_power_cntl())
589 pci_set_power_state(pdev, PCI_D0);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400590 pci_restore_state(pdev);
591 ret = pci_enable_device(pdev);
592 if (ret)
593 return ret;
594 pci_set_master(pdev);
595
Alex Deucher810ddc32016-08-23 13:25:49 -0400596 ret = amdgpu_device_resume(drm_dev, false, false);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400597 drm_kms_helper_poll_enable(drm_dev);
598 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_ON);
599 drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
600 return 0;
601}
602
603static int amdgpu_pmops_runtime_idle(struct device *dev)
604{
605 struct pci_dev *pdev = to_pci_dev(dev);
606 struct drm_device *drm_dev = pci_get_drvdata(pdev);
607 struct drm_crtc *crtc;
608
609 if (!amdgpu_device_is_px(drm_dev)) {
610 pm_runtime_forbid(dev);
611 return -EBUSY;
612 }
613
614 list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
615 if (crtc->enabled) {
616 DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
617 return -EBUSY;
618 }
619 }
620
621 pm_runtime_mark_last_busy(dev);
622 pm_runtime_autosuspend(dev);
623 /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
624 return 1;
625}
626
627long amdgpu_drm_ioctl(struct file *filp,
628 unsigned int cmd, unsigned long arg)
629{
630 struct drm_file *file_priv = filp->private_data;
631 struct drm_device *dev;
632 long ret;
633 dev = file_priv->minor->dev;
634 ret = pm_runtime_get_sync(dev->dev);
635 if (ret < 0)
636 return ret;
637
638 ret = drm_ioctl(filp, cmd, arg);
639
640 pm_runtime_mark_last_busy(dev->dev);
641 pm_runtime_put_autosuspend(dev->dev);
642 return ret;
643}
644
645static const struct dev_pm_ops amdgpu_pm_ops = {
646 .suspend = amdgpu_pmops_suspend,
647 .resume = amdgpu_pmops_resume,
648 .freeze = amdgpu_pmops_freeze,
649 .thaw = amdgpu_pmops_thaw,
jimqu74b0b152016-09-07 17:09:12 +0800650 .poweroff = amdgpu_pmops_poweroff,
651 .restore = amdgpu_pmops_restore,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400652 .runtime_suspend = amdgpu_pmops_runtime_suspend,
653 .runtime_resume = amdgpu_pmops_runtime_resume,
654 .runtime_idle = amdgpu_pmops_runtime_idle,
655};
656
657static const struct file_operations amdgpu_driver_kms_fops = {
658 .owner = THIS_MODULE,
659 .open = drm_open,
660 .release = drm_release,
661 .unlocked_ioctl = amdgpu_drm_ioctl,
662 .mmap = amdgpu_mmap,
663 .poll = drm_poll,
664 .read = drm_read,
665#ifdef CONFIG_COMPAT
666 .compat_ioctl = amdgpu_kms_compat_ioctl,
667#endif
668};
669
670static struct drm_driver kms_driver = {
671 .driver_features =
672 DRIVER_USE_AGP |
673 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
Frank Binns7056bb52016-06-24 18:15:17 +0100674 DRIVER_PRIME | DRIVER_RENDER | DRIVER_MODESET,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400675 .dev_priv_size = 0,
676 .load = amdgpu_driver_load_kms,
677 .open = amdgpu_driver_open_kms,
678 .preclose = amdgpu_driver_preclose_kms,
679 .postclose = amdgpu_driver_postclose_kms,
680 .lastclose = amdgpu_driver_lastclose_kms,
681 .set_busid = drm_pci_set_busid,
682 .unload = amdgpu_driver_unload_kms,
683 .get_vblank_counter = amdgpu_get_vblank_counter_kms,
684 .enable_vblank = amdgpu_enable_vblank_kms,
685 .disable_vblank = amdgpu_disable_vblank_kms,
686 .get_vblank_timestamp = amdgpu_get_vblank_timestamp_kms,
687 .get_scanout_position = amdgpu_get_crtc_scanoutpos,
688#if defined(CONFIG_DEBUG_FS)
689 .debugfs_init = amdgpu_debugfs_init,
690 .debugfs_cleanup = amdgpu_debugfs_cleanup,
691#endif
692 .irq_preinstall = amdgpu_irq_preinstall,
693 .irq_postinstall = amdgpu_irq_postinstall,
694 .irq_uninstall = amdgpu_irq_uninstall,
695 .irq_handler = amdgpu_irq_handler,
696 .ioctls = amdgpu_ioctls_kms,
Daniel Vettere7294de2016-04-26 19:29:43 +0200697 .gem_free_object_unlocked = amdgpu_gem_object_free,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400698 .gem_open_object = amdgpu_gem_object_open,
699 .gem_close_object = amdgpu_gem_object_close,
700 .dumb_create = amdgpu_mode_dumb_create,
701 .dumb_map_offset = amdgpu_mode_dumb_mmap,
702 .dumb_destroy = drm_gem_dumb_destroy,
703 .fops = &amdgpu_driver_kms_fops,
704
705 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
706 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
707 .gem_prime_export = amdgpu_gem_prime_export,
708 .gem_prime_import = drm_gem_prime_import,
709 .gem_prime_pin = amdgpu_gem_prime_pin,
710 .gem_prime_unpin = amdgpu_gem_prime_unpin,
711 .gem_prime_res_obj = amdgpu_gem_prime_res_obj,
712 .gem_prime_get_sg_table = amdgpu_gem_prime_get_sg_table,
713 .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
714 .gem_prime_vmap = amdgpu_gem_prime_vmap,
715 .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
716
717 .name = DRIVER_NAME,
718 .desc = DRIVER_DESC,
719 .date = DRIVER_DATE,
720 .major = KMS_DRIVER_MAJOR,
721 .minor = KMS_DRIVER_MINOR,
722 .patchlevel = KMS_DRIVER_PATCHLEVEL,
723};
724
725static struct drm_driver *driver;
726static struct pci_driver *pdriver;
727
728static struct pci_driver amdgpu_kms_pci_driver = {
729 .name = DRIVER_NAME,
730 .id_table = pciidlist,
731 .probe = amdgpu_pci_probe,
732 .remove = amdgpu_pci_remove,
Alex Deucher61e11302016-08-22 13:50:22 -0400733 .shutdown = amdgpu_pci_shutdown,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400734 .driver.pm = &amdgpu_pm_ops,
735};
736
Rex Zhud573de22016-05-12 13:27:28 +0800737
738
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400739static int __init amdgpu_init(void)
740{
Christian König257bf152016-02-16 11:24:58 +0100741 amdgpu_sync_init();
Rex Zhud573de22016-05-12 13:27:28 +0800742 amdgpu_fence_slab_init();
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400743 if (vgacon_text_force()) {
744 DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n");
745 return -EINVAL;
746 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400747 DRM_INFO("amdgpu kernel modesetting enabled.\n");
748 driver = &kms_driver;
749 pdriver = &amdgpu_kms_pci_driver;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400750 driver->num_ioctls = amdgpu_max_kms_ioctl;
751 amdgpu_register_atpx_handler();
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400752 /* let modprobe override vga console setting */
753 return drm_pci_init(driver, pdriver);
754}
755
756static void __exit amdgpu_exit(void)
757{
Oded Gabbay130e0372015-06-12 21:35:14 +0300758 amdgpu_amdkfd_fini();
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400759 drm_pci_exit(driver, pdriver);
760 amdgpu_unregister_atpx_handler();
Christian König257bf152016-02-16 11:24:58 +0100761 amdgpu_sync_fini();
Rex Zhud573de22016-05-12 13:27:28 +0800762 amdgpu_fence_slab_fini();
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400763}
764
765module_init(amdgpu_init);
766module_exit(amdgpu_exit);
767
768MODULE_AUTHOR(DRIVER_AUTHOR);
769MODULE_DESCRIPTION(DRIVER_DESC);
770MODULE_LICENSE("GPL and additional rights");