5 * \author Gareth Hughes <gareth@valinux.com>
9 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
10 * All Rights Reserved.
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:
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
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.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include <dev/drm2/drmP.h>
36 #include <dev/drm2/radeon/radeon_drm.h>
37 #include "radeon_drv.h"
38 #include "radeon_gem.h"
39 #include "radeon_kms.h"
40 #include "radeon_irq_kms.h"
42 #include <dev/drm2/drm_pciids.h>
48 * - 2.0.0 - initial interface
49 * - 2.1.0 - add square tiling interface
50 * - 2.2.0 - add r6xx/r7xx const buffer support
51 * - 2.3.0 - add MSPOS + 3D texture + r500 VAP regs
52 * - 2.4.0 - add crtc id query
53 * - 2.5.0 - add get accel 2 to work around ddx breakage for evergreen
54 * - 2.6.0 - add tiling config query (r6xx+), add initial HiZ support (r300->r500)
55 * 2.7.0 - fixups for r600 2D tiling support. (no external ABI change), add eg dyn gpr regs
56 * 2.8.0 - pageflip support, r500 US_FORMAT regs. r500 ARGB2101010 colorbuf, r300->r500 CMASK, clock crystal query
57 * 2.9.0 - r600 tiling (s3tc,rgtc) working, SET_PREDICATION packet 3 on r600 + eg, backend query
58 * 2.10.0 - fusion 2D tiling
59 * 2.11.0 - backend map, initial compute support for the CS checker
60 * 2.12.0 - RADEON_CS_KEEP_TILING_FLAGS
61 * 2.13.0 - virtual memory support, streamout
62 * 2.14.0 - add evergreen tiling informations
63 * 2.15.0 - add max_pipes query
64 * 2.16.0 - fix evergreen 2D tiled surface calculation
65 * 2.17.0 - add STRMOUT_BASE_UPDATE for r7xx
66 * 2.18.0 - r600-eg: allow "invalid" DB formats
67 * 2.19.0 - r600-eg: MSAA textures
68 * 2.20.0 - r600-si: RADEON_INFO_TIMESTAMP query
69 * 2.21.0 - r600-r700: FMASK and CMASK
70 * 2.22.0 - r600 only: RESOLVE_BOX allowed
71 * 2.23.0 - allow STRMOUT_BASE_UPDATE on RS780 and RS880
72 * 2.24.0 - eg only: allow MIP_ADDRESS=0 for MSAA textures
73 * 2.25.0 - eg+: new info request for num SE and num SH
74 * 2.26.0 - r600-eg: fix htile size computation
75 * 2.27.0 - r600-SI: Add CS ioctl support for async DMA
76 * 2.28.0 - r600-eg: Add MEM_WRITE packet support
77 * 2.29.0 - R500 FP16 color clear registers
79 #define KMS_DRIVER_MAJOR 2
80 #define KMS_DRIVER_MINOR 29
81 #define KMS_DRIVER_PATCHLEVEL 0
82 int radeon_suspend_kms(struct drm_device *dev);
83 int radeon_resume_kms(struct drm_device *dev);
84 extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc,
85 int *vpos, int *hpos);
86 extern struct drm_ioctl_desc radeon_ioctls_kms[];
87 extern int radeon_max_kms_ioctl;
89 int radeon_mmap(struct file *filp, struct vm_area_struct *vma);
90 #endif /* FREEBSD_WIP */
91 int radeon_mode_dumb_mmap(struct drm_file *filp,
92 struct drm_device *dev,
93 uint32_t handle, uint64_t *offset_p);
94 int radeon_mode_dumb_create(struct drm_file *file_priv,
95 struct drm_device *dev,
96 struct drm_mode_create_dumb *args);
97 int radeon_mode_dumb_destroy(struct drm_file *file_priv,
98 struct drm_device *dev,
100 struct dma_buf *radeon_gem_prime_export(struct drm_device *dev,
101 struct drm_gem_object *obj,
103 struct drm_gem_object *radeon_gem_prime_import(struct drm_device *dev,
104 struct dma_buf *dma_buf);
106 #if defined(CONFIG_DEBUG_FS)
107 int radeon_debugfs_init(struct drm_minor *minor);
108 void radeon_debugfs_cleanup(struct drm_minor *minor);
113 int radeon_modeset = 1;
114 int radeon_dynclks = -1;
115 int radeon_r4xx_atom = 0;
116 int radeon_agpmode = 0;
117 int radeon_vram_limit = 0;
118 int radeon_gart_size = 512; /* default gart size */
119 int radeon_benchmarking = 0;
120 int radeon_testing = 0;
121 int radeon_connector_table = 0;
123 int radeon_audio = 0;
124 int radeon_disp_priority = 0;
125 int radeon_hw_i2c = 0;
126 int radeon_pcie_gen2 = -1;
128 int radeon_lockup_timeout = 10000;
130 MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers");
131 module_param_named(no_wb, radeon_no_wb, int, 0444);
133 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
134 module_param_named(modeset, radeon_modeset, int, 0400);
136 MODULE_PARM_DESC(dynclks, "Disable/Enable dynamic clocks");
137 module_param_named(dynclks, radeon_dynclks, int, 0444);
139 MODULE_PARM_DESC(r4xx_atom, "Enable ATOMBIOS modesetting for R4xx");
140 module_param_named(r4xx_atom, radeon_r4xx_atom, int, 0444);
142 MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing");
143 module_param_named(vramlimit, radeon_vram_limit, int, 0600);
145 MODULE_PARM_DESC(agpmode, "AGP Mode (-1 == PCI)");
146 module_param_named(agpmode, radeon_agpmode, int, 0444);
148 MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32, 64, etc)");
149 module_param_named(gartsize, radeon_gart_size, int, 0600);
151 MODULE_PARM_DESC(benchmark, "Run benchmark");
152 module_param_named(benchmark, radeon_benchmarking, int, 0444);
154 MODULE_PARM_DESC(test, "Run tests");
155 module_param_named(test, radeon_testing, int, 0444);
157 MODULE_PARM_DESC(connector_table, "Force connector table");
158 module_param_named(connector_table, radeon_connector_table, int, 0444);
160 MODULE_PARM_DESC(tv, "TV enable (0 = disable)");
161 module_param_named(tv, radeon_tv, int, 0444);
163 MODULE_PARM_DESC(audio, "Audio enable (1 = enable)");
164 module_param_named(audio, radeon_audio, int, 0444);
166 MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
167 module_param_named(disp_priority, radeon_disp_priority, int, 0444);
169 MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
170 module_param_named(hw_i2c, radeon_hw_i2c, int, 0444);
172 MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (-1 = auto, 0 = disable, 1 = enable)");
173 module_param_named(pcie_gen2, radeon_pcie_gen2, int, 0444);
175 MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
176 module_param_named(msi, radeon_msi, int, 0444);
178 MODULE_PARM_DESC(lockup_timeout, "GPU lockup timeout in ms (defaul 10000 = 10 seconds, 0 = disable)");
179 module_param_named(lockup_timeout, radeon_lockup_timeout, int, 0444);
181 static drm_pci_id_list_t pciidlist[] = {
185 static struct drm_driver kms_driver;
187 static int radeon_sysctl_init(struct drm_device *dev, struct sysctl_ctx_list *ctx,
188 struct sysctl_oid *top)
190 return drm_add_busid_modesetting(dev, ctx, top);
193 static struct drm_driver kms_driver = {
195 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
196 DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED | DRIVER_GEM |
200 #endif /* FREEBSD_WIP */
201 .load = radeon_driver_load_kms,
202 .firstopen = radeon_driver_firstopen_kms,
203 .open = radeon_driver_open_kms,
204 .preclose = radeon_driver_preclose_kms,
205 .postclose = radeon_driver_postclose_kms,
206 .lastclose = radeon_driver_lastclose_kms,
207 .unload = radeon_driver_unload_kms,
209 .suspend = radeon_suspend_kms,
210 .resume = radeon_resume_kms,
211 #endif /* FREEBSD_WIP */
212 .get_vblank_counter = radeon_get_vblank_counter_kms,
213 .enable_vblank = radeon_enable_vblank_kms,
214 .disable_vblank = radeon_disable_vblank_kms,
215 .get_vblank_timestamp = radeon_get_vblank_timestamp_kms,
216 .get_scanout_position = radeon_get_crtc_scanoutpos,
217 #if defined(CONFIG_DEBUG_FS)
218 .debugfs_init = radeon_debugfs_init,
219 .debugfs_cleanup = radeon_debugfs_cleanup,
221 .irq_preinstall = radeon_driver_irq_preinstall_kms,
222 .irq_postinstall = radeon_driver_irq_postinstall_kms,
223 .irq_uninstall = radeon_driver_irq_uninstall_kms,
224 .irq_handler = radeon_driver_irq_handler_kms,
225 .sysctl_init = radeon_sysctl_init,
226 .ioctls = radeon_ioctls_kms,
227 .gem_init_object = radeon_gem_object_init,
228 .gem_free_object = radeon_gem_object_free,
229 .gem_open_object = radeon_gem_object_open,
230 .gem_close_object = radeon_gem_object_close,
231 .dma_ioctl = radeon_dma_ioctl_kms,
232 .dumb_create = radeon_mode_dumb_create,
233 .dumb_map_offset = radeon_mode_dumb_mmap,
234 .dumb_destroy = radeon_mode_dumb_destroy,
236 .fops = &radeon_driver_kms_fops,
237 #endif /* FREEBSD_WIP */
240 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
241 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
242 .gem_prime_export = radeon_gem_prime_export,
243 .gem_prime_import = radeon_gem_prime_import,
244 #endif /* FREEBSD_WIP */
249 .major = KMS_DRIVER_MAJOR,
250 .minor = KMS_DRIVER_MINOR,
251 .patchlevel = KMS_DRIVER_PATCHLEVEL,
255 static int __init radeon_init(void)
257 driver = &driver_old;
258 pdriver = &radeon_pci_driver;
259 driver->num_ioctls = radeon_max_ioctl;
260 #ifdef CONFIG_VGA_CONSOLE
261 if (vgacon_text_force() && radeon_modeset == -1) {
262 DRM_INFO("VGACON disable radeon kernel modesetting.\n");
263 driver = &driver_old;
264 pdriver = &radeon_pci_driver;
265 driver->driver_features &= ~DRIVER_MODESET;
269 /* if enabled by default */
270 if (radeon_modeset == -1) {
271 #ifdef CONFIG_DRM_RADEON_KMS
272 DRM_INFO("radeon defaulting to kernel modesetting.\n");
275 DRM_INFO("radeon defaulting to userspace modesetting.\n");
279 if (radeon_modeset == 1) {
280 DRM_INFO("radeon kernel modesetting enabled.\n");
281 driver = &kms_driver;
282 pdriver = &radeon_kms_pci_driver;
283 driver->driver_features |= DRIVER_MODESET;
284 driver->num_ioctls = radeon_max_kms_ioctl;
285 radeon_register_atpx_handler();
287 /* if the vga console setting is enabled still
288 * let modprobe override it */
289 return drm_pci_init(driver, pdriver);
292 static void __exit radeon_exit(void)
294 drm_pci_exit(driver, pdriver);
295 radeon_unregister_atpx_handler();
297 #endif /* FREEBSD_WIP */
299 /* =================================================================== */
302 radeon_probe(device_t kdev)
305 return (-drm_probe_helper(kdev, pciidlist));
309 radeon_attach(device_t kdev)
312 if (radeon_modeset == 1) {
313 kms_driver.driver_features |= DRIVER_MODESET;
314 kms_driver.num_ioctls = radeon_max_kms_ioctl;
315 #ifdef COMPAT_FREEBSD32
316 kms_driver.compat_ioctls = radeon_compat_ioctls;
317 kms_driver.num_compat_ioctls = &radeon_num_compat_ioctls;
319 radeon_register_atpx_handler();
321 return (-drm_attach_helper(kdev, pciidlist, &kms_driver));
325 radeon_suspend(device_t kdev)
327 struct drm_device *dev;
330 dev = device_get_softc(kdev);
331 ret = radeon_suspend_kms(dev);
335 ret = bus_generic_suspend(kdev);
341 radeon_resume(device_t kdev)
343 struct drm_device *dev;
346 dev = device_get_softc(kdev);
347 ret = radeon_resume_kms(dev);
351 ret = bus_generic_resume(kdev);
356 extern struct fb_info * radeon_fb_helper_getinfo(device_t kdev);
358 static device_method_t radeon_methods[] = {
359 /* Device interface */
360 DEVMETHOD(device_probe, radeon_probe),
361 DEVMETHOD(device_attach, radeon_attach),
362 DEVMETHOD(device_suspend, radeon_suspend),
363 DEVMETHOD(device_resume, radeon_resume),
364 DEVMETHOD(device_detach, drm_generic_detach),
366 /* Framebuffer service methods */
367 DEVMETHOD(fb_getinfo, radeon_fb_helper_getinfo),
372 static driver_t radeon_driver = {
375 sizeof(struct drm_device)
378 extern devclass_t drm_devclass;
379 DRIVER_MODULE_ORDERED(radeonkms, vgapci, radeon_driver, drm_devclass,
380 NULL, NULL, SI_ORDER_ANY);
381 MODULE_DEPEND(radeonkms, drmn, 1, 1, 1);
382 MODULE_DEPEND(radeonkms, agp, 1, 1, 1);
383 MODULE_DEPEND(radeonkms, iicbus, 1, 1, 1);
384 MODULE_DEPEND(radeonkms, iic, 1, 1, 1);
385 MODULE_DEPEND(radeonkms, iicbb, 1, 1, 1);
386 MODULE_DEPEND(radeonkms, firmware, 1, 1, 1);