blob: 9c1af8976befea20cf371cc4a15f226dbe434d75 [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)
Alex Deucherd38ceaf2015-04-20 16:55:21 -040053 */
54#define KMS_DRIVER_MAJOR 3
Marek Olšák6055f372015-08-18 23:58:47 +020055#define KMS_DRIVER_MINOR 1
Alex Deucherd38ceaf2015-04-20 16:55:21 -040056#define KMS_DRIVER_PATCHLEVEL 0
57
58int amdgpu_vram_limit = 0;
59int amdgpu_gart_size = -1; /* auto */
60int amdgpu_benchmarking = 0;
61int amdgpu_testing = 0;
62int amdgpu_audio = -1;
63int amdgpu_disp_priority = 0;
64int amdgpu_hw_i2c = 0;
65int amdgpu_pcie_gen2 = -1;
66int amdgpu_msi = -1;
Alex Deuchera895c222015-08-13 13:20:20 -040067int amdgpu_lockup_timeout = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040068int amdgpu_dpm = -1;
69int amdgpu_smc_load_fw = 1;
70int amdgpu_aspm = -1;
71int amdgpu_runtime_pm = -1;
72int amdgpu_hard_reset = 0;
73unsigned amdgpu_ip_block_mask = 0xffffffff;
74int amdgpu_bapm = -1;
75int amdgpu_deep_color = 0;
Christian Königed885b22015-10-15 17:34:20 +020076int amdgpu_vm_size = 64;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040077int amdgpu_vm_block_size = -1;
Christian Königd9c13152015-09-28 12:31:26 +020078int amdgpu_vm_fault_stop = 0;
Christian Königb495bd32015-09-10 14:00:35 +020079int amdgpu_vm_debug = 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040080int amdgpu_exp_hw_support = 0;
Chunming Zhou36b4ba02015-09-15 16:56:10 +080081int amdgpu_enable_scheduler = 1;
Chunming Zhoub70f0142015-12-10 15:46:50 +080082int amdgpu_sched_jobs = 32;
Jammy Zhou4afcb302015-07-30 16:44:05 +080083int amdgpu_sched_hw_submission = 2;
Alex Deucherd4edda32015-09-30 12:24:19 -040084int amdgpu_enable_semaphores = 0;
Jammy Zhoue61710c2015-11-10 18:31:08 -050085int amdgpu_powerplay = -1;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040086
87MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
88module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
89
90MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32, 64, etc., -1 = auto)");
91module_param_named(gartsize, amdgpu_gart_size, int, 0600);
92
93MODULE_PARM_DESC(benchmark, "Run benchmark");
94module_param_named(benchmark, amdgpu_benchmarking, int, 0444);
95
96MODULE_PARM_DESC(test, "Run tests");
97module_param_named(test, amdgpu_testing, int, 0444);
98
99MODULE_PARM_DESC(audio, "Audio enable (-1 = auto, 0 = disable, 1 = enable)");
100module_param_named(audio, amdgpu_audio, int, 0444);
101
102MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
103module_param_named(disp_priority, amdgpu_disp_priority, int, 0444);
104
105MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
106module_param_named(hw_i2c, amdgpu_hw_i2c, int, 0444);
107
108MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (-1 = auto, 0 = disable, 1 = enable)");
109module_param_named(pcie_gen2, amdgpu_pcie_gen2, int, 0444);
110
111MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
112module_param_named(msi, amdgpu_msi, int, 0444);
113
Alex Deuchera895c222015-08-13 13:20:20 -0400114MODULE_PARM_DESC(lockup_timeout, "GPU lockup timeout in ms (default 0 = disable)");
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400115module_param_named(lockup_timeout, amdgpu_lockup_timeout, int, 0444);
116
117MODULE_PARM_DESC(dpm, "DPM support (1 = enable, 0 = disable, -1 = auto)");
118module_param_named(dpm, amdgpu_dpm, int, 0444);
119
120MODULE_PARM_DESC(smc_load_fw, "SMC firmware loading(1 = enable, 0 = disable)");
121module_param_named(smc_load_fw, amdgpu_smc_load_fw, int, 0444);
122
123MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)");
124module_param_named(aspm, amdgpu_aspm, int, 0444);
125
126MODULE_PARM_DESC(runpm, "PX runtime pm (1 = force enable, 0 = disable, -1 = PX only default)");
127module_param_named(runpm, amdgpu_runtime_pm, int, 0444);
128
129MODULE_PARM_DESC(hard_reset, "PCI config reset (1 = force enable, 0 = disable (default))");
130module_param_named(hard_reset, amdgpu_hard_reset, int, 0444);
131
132MODULE_PARM_DESC(ip_block_mask, "IP Block Mask (all blocks enabled (default))");
133module_param_named(ip_block_mask, amdgpu_ip_block_mask, uint, 0444);
134
135MODULE_PARM_DESC(bapm, "BAPM support (1 = enable, 0 = disable, -1 = auto)");
136module_param_named(bapm, amdgpu_bapm, int, 0444);
137
138MODULE_PARM_DESC(deep_color, "Deep Color support (1 = enable, 0 = disable (default))");
139module_param_named(deep_color, amdgpu_deep_color, int, 0444);
140
Christian Königed885b22015-10-15 17:34:20 +0200141MODULE_PARM_DESC(vm_size, "VM address space size in gigabytes (default 64GB)");
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400142module_param_named(vm_size, amdgpu_vm_size, int, 0444);
143
144MODULE_PARM_DESC(vm_block_size, "VM page table size in bits (default depending on vm_size)");
145module_param_named(vm_block_size, amdgpu_vm_block_size, int, 0444);
146
Christian Königd9c13152015-09-28 12:31:26 +0200147MODULE_PARM_DESC(vm_fault_stop, "Stop on VM fault (0 = never (default), 1 = print first, 2 = always)");
148module_param_named(vm_fault_stop, amdgpu_vm_fault_stop, int, 0444);
149
Christian Königb495bd32015-09-10 14:00:35 +0200150MODULE_PARM_DESC(vm_debug, "Debug VM handling (0 = disabled (default), 1 = enabled)");
151module_param_named(vm_debug, amdgpu_vm_debug, int, 0644);
152
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400153MODULE_PARM_DESC(exp_hw_support, "experimental hw support (1 = enable, 0 = disable (default))");
154module_param_named(exp_hw_support, amdgpu_exp_hw_support, int, 0444);
155
Chunming Zhou36b4ba02015-09-15 16:56:10 +0800156MODULE_PARM_DESC(enable_scheduler, "enable SW GPU scheduler (1 = enable (default), 0 = disable)");
Jammy Zhou02b9f0b2015-05-27 18:23:34 +0800157module_param_named(enable_scheduler, amdgpu_enable_scheduler, int, 0444);
158
Chunming Zhoub70f0142015-12-10 15:46:50 +0800159MODULE_PARM_DESC(sched_jobs, "the max number of jobs supported in the sw queue (default 32)");
Jammy Zhou1333f722015-07-30 16:36:58 +0800160module_param_named(sched_jobs, amdgpu_sched_jobs, int, 0444);
161
Jammy Zhou4afcb302015-07-30 16:44:05 +0800162MODULE_PARM_DESC(sched_hw_submission, "the max number of HW submissions (default 2)");
163module_param_named(sched_hw_submission, amdgpu_sched_hw_submission, int, 0444);
164
Alex Deucherd4edda32015-09-30 12:24:19 -0400165MODULE_PARM_DESC(enable_semaphores, "Enable semaphores (1 = enable, 0 = disable (default))");
Christian König3daea9e3d2015-09-05 11:12:27 +0200166module_param_named(enable_semaphores, amdgpu_enable_semaphores, int, 0644);
167
Jammy Zhou3a74f6f2015-07-21 14:01:50 +0800168#ifdef CONFIG_DRM_AMD_POWERPLAY
Jammy Zhoue61710c2015-11-10 18:31:08 -0500169MODULE_PARM_DESC(powerplay, "Powerplay component (1 = enable, 0 = disable, -1 = auto (default))");
Jammy Zhou3a74f6f2015-07-21 14:01:50 +0800170module_param_named(powerplay, amdgpu_powerplay, int, 0444);
171#endif
172
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400173static struct pci_device_id pciidlist[] = {
Alex Deucher89330c32015-04-20 17:36:52 -0400174#ifdef CONFIG_DRM_AMDGPU_CIK
175 /* Kaveri */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800176 {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
177 {0x1002, 0x1305, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
178 {0x1002, 0x1306, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
179 {0x1002, 0x1307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
180 {0x1002, 0x1309, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
181 {0x1002, 0x130A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
182 {0x1002, 0x130B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
183 {0x1002, 0x130C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
184 {0x1002, 0x130D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
185 {0x1002, 0x130E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
186 {0x1002, 0x130F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
187 {0x1002, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
188 {0x1002, 0x1311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
189 {0x1002, 0x1312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
190 {0x1002, 0x1313, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
191 {0x1002, 0x1315, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
192 {0x1002, 0x1316, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
193 {0x1002, 0x1317, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
194 {0x1002, 0x1318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
195 {0x1002, 0x131B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
196 {0x1002, 0x131C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
197 {0x1002, 0x131D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
Alex Deucher89330c32015-04-20 17:36:52 -0400198 /* Bonaire */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800199 {0x1002, 0x6640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
200 {0x1002, 0x6641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
201 {0x1002, 0x6646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
202 {0x1002, 0x6647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
Alex Deucher89330c32015-04-20 17:36:52 -0400203 {0x1002, 0x6649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
204 {0x1002, 0x6650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
205 {0x1002, 0x6651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
206 {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
207 {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
208 {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
Alex Deucherfb4f1732015-05-12 13:06:45 -0400209 {0x1002, 0x665f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
Alex Deucher89330c32015-04-20 17:36:52 -0400210 /* Hawaii */
211 {0x1002, 0x67A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
212 {0x1002, 0x67A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
213 {0x1002, 0x67A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
214 {0x1002, 0x67A8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
215 {0x1002, 0x67A9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
216 {0x1002, 0x67AA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
217 {0x1002, 0x67B0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
218 {0x1002, 0x67B1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
219 {0x1002, 0x67B8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
220 {0x1002, 0x67B9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
221 {0x1002, 0x67BA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
222 {0x1002, 0x67BE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
223 /* Kabini */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800224 {0x1002, 0x9830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
225 {0x1002, 0x9831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
226 {0x1002, 0x9832, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
227 {0x1002, 0x9833, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
228 {0x1002, 0x9834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
229 {0x1002, 0x9835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
230 {0x1002, 0x9836, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
231 {0x1002, 0x9837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
232 {0x1002, 0x9838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
233 {0x1002, 0x9839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
234 {0x1002, 0x983a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
235 {0x1002, 0x983b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
236 {0x1002, 0x983c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
237 {0x1002, 0x983d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
238 {0x1002, 0x983e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
239 {0x1002, 0x983f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
Alex Deucher89330c32015-04-20 17:36:52 -0400240 /* mullins */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800241 {0x1002, 0x9850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
242 {0x1002, 0x9851, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
243 {0x1002, 0x9852, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
244 {0x1002, 0x9853, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
245 {0x1002, 0x9854, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
246 {0x1002, 0x9855, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
247 {0x1002, 0x9856, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
248 {0x1002, 0x9857, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
249 {0x1002, 0x9858, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
250 {0x1002, 0x9859, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
251 {0x1002, 0x985A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
252 {0x1002, 0x985B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
253 {0x1002, 0x985C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
254 {0x1002, 0x985D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
255 {0x1002, 0x985E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
256 {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 -0400257#endif
Alex Deucher1256a8b2015-04-20 17:37:54 -0400258 /* topaz */
Alex Deucherdba280b2016-02-02 16:24:20 -0500259 {0x1002, 0x6900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
260 {0x1002, 0x6901, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
261 {0x1002, 0x6902, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
262 {0x1002, 0x6903, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
263 {0x1002, 0x6907, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400264 /* tonga */
265 {0x1002, 0x6920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
266 {0x1002, 0x6921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
267 {0x1002, 0x6928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1f8d9622015-05-12 13:10:05 -0400268 {0x1002, 0x6929, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400269 {0x1002, 0x692B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
270 {0x1002, 0x692F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1f8d9622015-05-12 13:10:05 -0400271 {0x1002, 0x6930, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400272 {0x1002, 0x6938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
273 {0x1002, 0x6939, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
David Zhang2da78e22015-07-11 23:13:40 +0800274 /* fiji */
275 {0x1002, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_FIJI},
Alex Deucher1256a8b2015-04-20 17:37:54 -0400276 /* carrizo */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800277 {0x1002, 0x9870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
278 {0x1002, 0x9874, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
279 {0x1002, 0x9875, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
280 {0x1002, 0x9876, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
281 {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
Samuel Li81b15092015-10-08 16:32:03 -0400282 /* stoney */
283 {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU},
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400284
285 {0, 0, 0}
286};
287
288MODULE_DEVICE_TABLE(pci, pciidlist);
289
290static struct drm_driver kms_driver;
291
292static int amdgpu_kick_out_firmware_fb(struct pci_dev *pdev)
293{
294 struct apertures_struct *ap;
295 bool primary = false;
296
297 ap = alloc_apertures(1);
298 if (!ap)
299 return -ENOMEM;
300
301 ap->ranges[0].base = pci_resource_start(pdev, 0);
302 ap->ranges[0].size = pci_resource_len(pdev, 0);
303
304#ifdef CONFIG_X86
305 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
306#endif
307 remove_conflicting_framebuffers(ap, "amdgpudrmfb", primary);
308 kfree(ap);
309
310 return 0;
311}
312
313static int amdgpu_pci_probe(struct pci_dev *pdev,
314 const struct pci_device_id *ent)
315{
316 unsigned long flags = ent->driver_data;
317 int ret;
318
Jammy Zhou2f7d10b2015-07-22 11:29:01 +0800319 if ((flags & AMD_EXP_HW_SUPPORT) && !amdgpu_exp_hw_support) {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400320 DRM_INFO("This hardware requires experimental hardware support.\n"
321 "See modparam exp_hw_support\n");
322 return -ENODEV;
323 }
324
325 /* Get rid of things like offb */
326 ret = amdgpu_kick_out_firmware_fb(pdev);
327 if (ret)
328 return ret;
329
330 return drm_get_pci_dev(pdev, ent, &kms_driver);
331}
332
333static void
334amdgpu_pci_remove(struct pci_dev *pdev)
335{
336 struct drm_device *dev = pci_get_drvdata(pdev);
337
338 drm_put_dev(dev);
339}
340
341static int amdgpu_pmops_suspend(struct device *dev)
342{
343 struct pci_dev *pdev = to_pci_dev(dev);
344 struct drm_device *drm_dev = pci_get_drvdata(pdev);
345 return amdgpu_suspend_kms(drm_dev, true, true);
346}
347
348static int amdgpu_pmops_resume(struct device *dev)
349{
350 struct pci_dev *pdev = to_pci_dev(dev);
351 struct drm_device *drm_dev = pci_get_drvdata(pdev);
352 return amdgpu_resume_kms(drm_dev, true, true);
353}
354
355static int amdgpu_pmops_freeze(struct device *dev)
356{
357 struct pci_dev *pdev = to_pci_dev(dev);
358 struct drm_device *drm_dev = pci_get_drvdata(pdev);
359 return amdgpu_suspend_kms(drm_dev, false, true);
360}
361
362static int amdgpu_pmops_thaw(struct device *dev)
363{
364 struct pci_dev *pdev = to_pci_dev(dev);
365 struct drm_device *drm_dev = pci_get_drvdata(pdev);
366 return amdgpu_resume_kms(drm_dev, false, true);
367}
368
369static int amdgpu_pmops_runtime_suspend(struct device *dev)
370{
371 struct pci_dev *pdev = to_pci_dev(dev);
372 struct drm_device *drm_dev = pci_get_drvdata(pdev);
373 int ret;
374
375 if (!amdgpu_device_is_px(drm_dev)) {
376 pm_runtime_forbid(dev);
377 return -EBUSY;
378 }
379
380 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
381 drm_kms_helper_poll_disable(drm_dev);
382 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
383
384 ret = amdgpu_suspend_kms(drm_dev, false, false);
385 pci_save_state(pdev);
386 pci_disable_device(pdev);
387 pci_ignore_hotplug(pdev);
388 pci_set_power_state(pdev, PCI_D3cold);
389 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
390
391 return 0;
392}
393
394static int amdgpu_pmops_runtime_resume(struct device *dev)
395{
396 struct pci_dev *pdev = to_pci_dev(dev);
397 struct drm_device *drm_dev = pci_get_drvdata(pdev);
398 int ret;
399
400 if (!amdgpu_device_is_px(drm_dev))
401 return -EINVAL;
402
403 drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
404
405 pci_set_power_state(pdev, PCI_D0);
406 pci_restore_state(pdev);
407 ret = pci_enable_device(pdev);
408 if (ret)
409 return ret;
410 pci_set_master(pdev);
411
412 ret = amdgpu_resume_kms(drm_dev, false, false);
413 drm_kms_helper_poll_enable(drm_dev);
414 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_ON);
415 drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
416 return 0;
417}
418
419static int amdgpu_pmops_runtime_idle(struct device *dev)
420{
421 struct pci_dev *pdev = to_pci_dev(dev);
422 struct drm_device *drm_dev = pci_get_drvdata(pdev);
423 struct drm_crtc *crtc;
424
425 if (!amdgpu_device_is_px(drm_dev)) {
426 pm_runtime_forbid(dev);
427 return -EBUSY;
428 }
429
430 list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
431 if (crtc->enabled) {
432 DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
433 return -EBUSY;
434 }
435 }
436
437 pm_runtime_mark_last_busy(dev);
438 pm_runtime_autosuspend(dev);
439 /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
440 return 1;
441}
442
443long amdgpu_drm_ioctl(struct file *filp,
444 unsigned int cmd, unsigned long arg)
445{
446 struct drm_file *file_priv = filp->private_data;
447 struct drm_device *dev;
448 long ret;
449 dev = file_priv->minor->dev;
450 ret = pm_runtime_get_sync(dev->dev);
451 if (ret < 0)
452 return ret;
453
454 ret = drm_ioctl(filp, cmd, arg);
455
456 pm_runtime_mark_last_busy(dev->dev);
457 pm_runtime_put_autosuspend(dev->dev);
458 return ret;
459}
460
461static const struct dev_pm_ops amdgpu_pm_ops = {
462 .suspend = amdgpu_pmops_suspend,
463 .resume = amdgpu_pmops_resume,
464 .freeze = amdgpu_pmops_freeze,
465 .thaw = amdgpu_pmops_thaw,
466 .poweroff = amdgpu_pmops_freeze,
467 .restore = amdgpu_pmops_resume,
468 .runtime_suspend = amdgpu_pmops_runtime_suspend,
469 .runtime_resume = amdgpu_pmops_runtime_resume,
470 .runtime_idle = amdgpu_pmops_runtime_idle,
471};
472
473static const struct file_operations amdgpu_driver_kms_fops = {
474 .owner = THIS_MODULE,
475 .open = drm_open,
476 .release = drm_release,
477 .unlocked_ioctl = amdgpu_drm_ioctl,
478 .mmap = amdgpu_mmap,
479 .poll = drm_poll,
480 .read = drm_read,
481#ifdef CONFIG_COMPAT
482 .compat_ioctl = amdgpu_kms_compat_ioctl,
483#endif
484};
485
486static struct drm_driver kms_driver = {
487 .driver_features =
488 DRIVER_USE_AGP |
489 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
490 DRIVER_PRIME | DRIVER_RENDER,
491 .dev_priv_size = 0,
492 .load = amdgpu_driver_load_kms,
493 .open = amdgpu_driver_open_kms,
494 .preclose = amdgpu_driver_preclose_kms,
495 .postclose = amdgpu_driver_postclose_kms,
496 .lastclose = amdgpu_driver_lastclose_kms,
497 .set_busid = drm_pci_set_busid,
498 .unload = amdgpu_driver_unload_kms,
499 .get_vblank_counter = amdgpu_get_vblank_counter_kms,
500 .enable_vblank = amdgpu_enable_vblank_kms,
501 .disable_vblank = amdgpu_disable_vblank_kms,
502 .get_vblank_timestamp = amdgpu_get_vblank_timestamp_kms,
503 .get_scanout_position = amdgpu_get_crtc_scanoutpos,
504#if defined(CONFIG_DEBUG_FS)
505 .debugfs_init = amdgpu_debugfs_init,
506 .debugfs_cleanup = amdgpu_debugfs_cleanup,
507#endif
508 .irq_preinstall = amdgpu_irq_preinstall,
509 .irq_postinstall = amdgpu_irq_postinstall,
510 .irq_uninstall = amdgpu_irq_uninstall,
511 .irq_handler = amdgpu_irq_handler,
512 .ioctls = amdgpu_ioctls_kms,
513 .gem_free_object = amdgpu_gem_object_free,
514 .gem_open_object = amdgpu_gem_object_open,
515 .gem_close_object = amdgpu_gem_object_close,
516 .dumb_create = amdgpu_mode_dumb_create,
517 .dumb_map_offset = amdgpu_mode_dumb_mmap,
518 .dumb_destroy = drm_gem_dumb_destroy,
519 .fops = &amdgpu_driver_kms_fops,
520
521 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
522 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
523 .gem_prime_export = amdgpu_gem_prime_export,
524 .gem_prime_import = drm_gem_prime_import,
525 .gem_prime_pin = amdgpu_gem_prime_pin,
526 .gem_prime_unpin = amdgpu_gem_prime_unpin,
527 .gem_prime_res_obj = amdgpu_gem_prime_res_obj,
528 .gem_prime_get_sg_table = amdgpu_gem_prime_get_sg_table,
529 .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
530 .gem_prime_vmap = amdgpu_gem_prime_vmap,
531 .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
532
533 .name = DRIVER_NAME,
534 .desc = DRIVER_DESC,
535 .date = DRIVER_DATE,
536 .major = KMS_DRIVER_MAJOR,
537 .minor = KMS_DRIVER_MINOR,
538 .patchlevel = KMS_DRIVER_PATCHLEVEL,
539};
540
541static struct drm_driver *driver;
542static struct pci_driver *pdriver;
543
544static struct pci_driver amdgpu_kms_pci_driver = {
545 .name = DRIVER_NAME,
546 .id_table = pciidlist,
547 .probe = amdgpu_pci_probe,
548 .remove = amdgpu_pci_remove,
549 .driver.pm = &amdgpu_pm_ops,
550};
551
552static int __init amdgpu_init(void)
553{
554#ifdef CONFIG_VGA_CONSOLE
555 if (vgacon_text_force()) {
556 DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n");
557 return -EINVAL;
558 }
559#endif
560 DRM_INFO("amdgpu kernel modesetting enabled.\n");
561 driver = &kms_driver;
562 pdriver = &amdgpu_kms_pci_driver;
563 driver->driver_features |= DRIVER_MODESET;
564 driver->num_ioctls = amdgpu_max_kms_ioctl;
565 amdgpu_register_atpx_handler();
566
Oded Gabbay130e0372015-06-12 21:35:14 +0300567 amdgpu_amdkfd_init();
568
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400569 /* let modprobe override vga console setting */
570 return drm_pci_init(driver, pdriver);
571}
572
573static void __exit amdgpu_exit(void)
574{
Oded Gabbay130e0372015-06-12 21:35:14 +0300575 amdgpu_amdkfd_fini();
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400576 drm_pci_exit(driver, pdriver);
577 amdgpu_unregister_atpx_handler();
578}
579
580module_init(amdgpu_init);
581module_exit(amdgpu_exit);
582
583MODULE_AUTHOR(DRIVER_AUTHOR);
584MODULE_DESCRIPTION(DRIVER_DESC);
585MODULE_LICENSE("GPL and additional rights");