radeon_drv.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /**
  2. * \file radeon_drv.c
  3. * ATI Radeon driver
  4. *
  5. * \author Gareth Hughes <gareth@valinux.com>
  6. */
  7. /*
  8. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  9. * All Rights Reserved.
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice (including the next
  19. * paragraph) shall be included in all copies or substantial portions of the
  20. * Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  26. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  27. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. * OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "radeon_drm.h"
  33. #include "radeon_drv.h"
  34. #include "drm_pciids.h"
  35. #include <linux/console.h>
  36. /*
  37. * KMS wrapper.
  38. * - 2.0.0 - initial interface
  39. * - 2.1.0 - add square tiling interface
  40. * - 2.2.0 - add r6xx/r7xx const buffer support
  41. * - 2.3.0 - add MSPOS + 3D texture + r500 VAP regs
  42. * - 2.4.0 - add crtc id query
  43. * - 2.5.0 - add get accel 2 to work around ddx breakage for evergreen
  44. * - 2.6.0 - add tiling config query (r6xx+), add initial HiZ support (r300->r500)
  45. * 2.7.0 - fixups for r600 2D tiling support. (no external ABI change), add eg dyn gpr regs
  46. * 2.8.0 - pageflip support, r500 US_FORMAT regs. r500 ARGB2101010 colorbuf, r300->r500 CMASK, clock crystal query
  47. * 2.9.0 - r600 tiling (s3tc,rgtc) working, SET_PREDICATION packet 3 on r600 + eg, backend query
  48. * 2.10.0 - fusion 2D tiling
  49. */
  50. #define KMS_DRIVER_MAJOR 2
  51. #define KMS_DRIVER_MINOR 10
  52. #define KMS_DRIVER_PATCHLEVEL 0
  53. int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags);
  54. int radeon_driver_unload_kms(struct drm_device *dev);
  55. int radeon_driver_firstopen_kms(struct drm_device *dev);
  56. void radeon_driver_lastclose_kms(struct drm_device *dev);
  57. int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
  58. void radeon_driver_postclose_kms(struct drm_device *dev,
  59. struct drm_file *file_priv);
  60. void radeon_driver_preclose_kms(struct drm_device *dev,
  61. struct drm_file *file_priv);
  62. int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  63. int radeon_resume_kms(struct drm_device *dev);
  64. u32 radeon_get_vblank_counter_kms(struct drm_device *dev, int crtc);
  65. int radeon_enable_vblank_kms(struct drm_device *dev, int crtc);
  66. void radeon_disable_vblank_kms(struct drm_device *dev, int crtc);
  67. int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
  68. int *max_error,
  69. struct timeval *vblank_time,
  70. unsigned flags);
  71. void radeon_driver_irq_preinstall_kms(struct drm_device *dev);
  72. int radeon_driver_irq_postinstall_kms(struct drm_device *dev);
  73. void radeon_driver_irq_uninstall_kms(struct drm_device *dev);
  74. irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS);
  75. int radeon_dma_ioctl_kms(struct drm_device *dev, void *data,
  76. struct drm_file *file_priv);
  77. int radeon_gem_object_init(struct drm_gem_object *obj);
  78. void radeon_gem_object_free(struct drm_gem_object *obj);
  79. extern int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc,
  80. int *vpos, int *hpos);
  81. extern struct drm_ioctl_desc radeon_ioctls_kms[];
  82. extern int radeon_max_kms_ioctl;
  83. int radeon_mmap(struct file *filp, struct vm_area_struct *vma);
  84. int radeon_mode_dumb_mmap(struct drm_file *filp,
  85. struct drm_device *dev,
  86. uint32_t handle, uint64_t *offset_p);
  87. int radeon_mode_dumb_create(struct drm_file *file_priv,
  88. struct drm_device *dev,
  89. struct drm_mode_create_dumb *args);
  90. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  91. struct drm_device *dev,
  92. uint32_t handle);
  93. #if defined(CONFIG_DEBUG_FS)
  94. int radeon_debugfs_init(struct drm_minor *minor);
  95. void radeon_debugfs_cleanup(struct drm_minor *minor);
  96. #endif
  97. int radeon_no_wb;
  98. int radeon_modeset = -1;
  99. int radeon_dynclks = -1;
  100. int radeon_r4xx_atom = 0;
  101. int radeon_agpmode = 0;
  102. int radeon_vram_limit = 0;
  103. int radeon_gart_size = 512; /* default gart size */
  104. int radeon_benchmarking = 0;
  105. int radeon_testing = 0;
  106. int radeon_connector_table = 0;
  107. int radeon_tv = 1;
  108. int radeon_audio = 0;
  109. int radeon_disp_priority = 0;
  110. int radeon_hw_i2c = 0;
  111. int radeon_pcie_gen2 = 0;
  112. int radeon_msi = -1;
  113. MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers");
  114. module_param_named(no_wb, radeon_no_wb, int, 0444);
  115. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  116. module_param_named(modeset, radeon_modeset, int, 0400);
  117. MODULE_PARM_DESC(dynclks, "Disable/Enable dynamic clocks");
  118. module_param_named(dynclks, radeon_dynclks, int, 0444);
  119. MODULE_PARM_DESC(r4xx_atom, "Enable ATOMBIOS modesetting for R4xx");
  120. module_param_named(r4xx_atom, radeon_r4xx_atom, int, 0444);
  121. MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing");
  122. module_param_named(vramlimit, radeon_vram_limit, int, 0600);
  123. MODULE_PARM_DESC(agpmode, "AGP Mode (-1 == PCI)");
  124. module_param_named(agpmode, radeon_agpmode, int, 0444);
  125. MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32,64, etc)\n");
  126. module_param_named(gartsize, radeon_gart_size, int, 0600);
  127. MODULE_PARM_DESC(benchmark, "Run benchmark");
  128. module_param_named(benchmark, radeon_benchmarking, int, 0444);
  129. MODULE_PARM_DESC(test, "Run tests");
  130. module_param_named(test, radeon_testing, int, 0444);
  131. MODULE_PARM_DESC(connector_table, "Force connector table");
  132. module_param_named(connector_table, radeon_connector_table, int, 0444);
  133. MODULE_PARM_DESC(tv, "TV enable (0 = disable)");
  134. module_param_named(tv, radeon_tv, int, 0444);
  135. MODULE_PARM_DESC(audio, "Audio enable (1 = enable)");
  136. module_param_named(audio, radeon_audio, int, 0444);
  137. MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
  138. module_param_named(disp_priority, radeon_disp_priority, int, 0444);
  139. MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
  140. module_param_named(hw_i2c, radeon_hw_i2c, int, 0444);
  141. MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (1 = enable)");
  142. module_param_named(pcie_gen2, radeon_pcie_gen2, int, 0444);
  143. MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
  144. module_param_named(msi, radeon_msi, int, 0444);
  145. static int radeon_suspend(struct drm_device *dev, pm_message_t state)
  146. {
  147. drm_radeon_private_t *dev_priv = dev->dev_private;
  148. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  149. return 0;
  150. /* Disable *all* interrupts */
  151. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600)
  152. RADEON_WRITE(R500_DxMODE_INT_MASK, 0);
  153. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  154. return 0;
  155. }
  156. static int radeon_resume(struct drm_device *dev)
  157. {
  158. drm_radeon_private_t *dev_priv = dev->dev_private;
  159. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600)
  160. return 0;
  161. /* Restore interrupt registers */
  162. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600)
  163. RADEON_WRITE(R500_DxMODE_INT_MASK, dev_priv->r500_disp_irq_reg);
  164. RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg);
  165. return 0;
  166. }
  167. static struct pci_device_id pciidlist[] = {
  168. radeon_PCI_IDS
  169. };
  170. #if defined(CONFIG_DRM_RADEON_KMS)
  171. MODULE_DEVICE_TABLE(pci, pciidlist);
  172. #endif
  173. static struct drm_driver driver_old = {
  174. .driver_features =
  175. DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
  176. DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED,
  177. .dev_priv_size = sizeof(drm_radeon_buf_priv_t),
  178. .load = radeon_driver_load,
  179. .firstopen = radeon_driver_firstopen,
  180. .open = radeon_driver_open,
  181. .preclose = radeon_driver_preclose,
  182. .postclose = radeon_driver_postclose,
  183. .lastclose = radeon_driver_lastclose,
  184. .unload = radeon_driver_unload,
  185. .suspend = radeon_suspend,
  186. .resume = radeon_resume,
  187. .get_vblank_counter = radeon_get_vblank_counter,
  188. .enable_vblank = radeon_enable_vblank,
  189. .disable_vblank = radeon_disable_vblank,
  190. .master_create = radeon_master_create,
  191. .master_destroy = radeon_master_destroy,
  192. .irq_preinstall = radeon_driver_irq_preinstall,
  193. .irq_postinstall = radeon_driver_irq_postinstall,
  194. .irq_uninstall = radeon_driver_irq_uninstall,
  195. .irq_handler = radeon_driver_irq_handler,
  196. .reclaim_buffers = drm_core_reclaim_buffers,
  197. .ioctls = radeon_ioctls,
  198. .dma_ioctl = radeon_cp_buffers,
  199. .fops = {
  200. .owner = THIS_MODULE,
  201. .open = drm_open,
  202. .release = drm_release,
  203. .unlocked_ioctl = drm_ioctl,
  204. .mmap = drm_mmap,
  205. .poll = drm_poll,
  206. .fasync = drm_fasync,
  207. .read = drm_read,
  208. #ifdef CONFIG_COMPAT
  209. .compat_ioctl = radeon_compat_ioctl,
  210. #endif
  211. .llseek = noop_llseek,
  212. },
  213. .name = DRIVER_NAME,
  214. .desc = DRIVER_DESC,
  215. .date = DRIVER_DATE,
  216. .major = DRIVER_MAJOR,
  217. .minor = DRIVER_MINOR,
  218. .patchlevel = DRIVER_PATCHLEVEL,
  219. };
  220. static struct drm_driver kms_driver;
  221. static void radeon_kick_out_firmware_fb(struct pci_dev *pdev)
  222. {
  223. struct apertures_struct *ap;
  224. bool primary = false;
  225. ap = alloc_apertures(1);
  226. ap->ranges[0].base = pci_resource_start(pdev, 0);
  227. ap->ranges[0].size = pci_resource_len(pdev, 0);
  228. #ifdef CONFIG_X86
  229. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  230. #endif
  231. remove_conflicting_framebuffers(ap, "radeondrmfb", primary);
  232. kfree(ap);
  233. }
  234. static int __devinit
  235. radeon_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  236. {
  237. /* Get rid of things like offb */
  238. radeon_kick_out_firmware_fb(pdev);
  239. return drm_get_pci_dev(pdev, ent, &kms_driver);
  240. }
  241. static void
  242. radeon_pci_remove(struct pci_dev *pdev)
  243. {
  244. struct drm_device *dev = pci_get_drvdata(pdev);
  245. drm_put_dev(dev);
  246. }
  247. static int
  248. radeon_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  249. {
  250. struct drm_device *dev = pci_get_drvdata(pdev);
  251. return radeon_suspend_kms(dev, state);
  252. }
  253. static int
  254. radeon_pci_resume(struct pci_dev *pdev)
  255. {
  256. struct drm_device *dev = pci_get_drvdata(pdev);
  257. return radeon_resume_kms(dev);
  258. }
  259. static struct drm_driver kms_driver = {
  260. .driver_features =
  261. DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
  262. DRIVER_HAVE_IRQ | DRIVER_HAVE_DMA | DRIVER_IRQ_SHARED | DRIVER_GEM,
  263. .dev_priv_size = 0,
  264. .load = radeon_driver_load_kms,
  265. .firstopen = radeon_driver_firstopen_kms,
  266. .open = radeon_driver_open_kms,
  267. .preclose = radeon_driver_preclose_kms,
  268. .postclose = radeon_driver_postclose_kms,
  269. .lastclose = radeon_driver_lastclose_kms,
  270. .unload = radeon_driver_unload_kms,
  271. .suspend = radeon_suspend_kms,
  272. .resume = radeon_resume_kms,
  273. .get_vblank_counter = radeon_get_vblank_counter_kms,
  274. .enable_vblank = radeon_enable_vblank_kms,
  275. .disable_vblank = radeon_disable_vblank_kms,
  276. .get_vblank_timestamp = radeon_get_vblank_timestamp_kms,
  277. .get_scanout_position = radeon_get_crtc_scanoutpos,
  278. #if defined(CONFIG_DEBUG_FS)
  279. .debugfs_init = radeon_debugfs_init,
  280. .debugfs_cleanup = radeon_debugfs_cleanup,
  281. #endif
  282. .irq_preinstall = radeon_driver_irq_preinstall_kms,
  283. .irq_postinstall = radeon_driver_irq_postinstall_kms,
  284. .irq_uninstall = radeon_driver_irq_uninstall_kms,
  285. .irq_handler = radeon_driver_irq_handler_kms,
  286. .reclaim_buffers = drm_core_reclaim_buffers,
  287. .ioctls = radeon_ioctls_kms,
  288. .gem_init_object = radeon_gem_object_init,
  289. .gem_free_object = radeon_gem_object_free,
  290. .dma_ioctl = radeon_dma_ioctl_kms,
  291. .dumb_create = radeon_mode_dumb_create,
  292. .dumb_map_offset = radeon_mode_dumb_mmap,
  293. .dumb_destroy = radeon_mode_dumb_destroy,
  294. .fops = {
  295. .owner = THIS_MODULE,
  296. .open = drm_open,
  297. .release = drm_release,
  298. .unlocked_ioctl = drm_ioctl,
  299. .mmap = radeon_mmap,
  300. .poll = drm_poll,
  301. .fasync = drm_fasync,
  302. .read = drm_read,
  303. #ifdef CONFIG_COMPAT
  304. .compat_ioctl = radeon_kms_compat_ioctl,
  305. #endif
  306. },
  307. .name = DRIVER_NAME,
  308. .desc = DRIVER_DESC,
  309. .date = DRIVER_DATE,
  310. .major = KMS_DRIVER_MAJOR,
  311. .minor = KMS_DRIVER_MINOR,
  312. .patchlevel = KMS_DRIVER_PATCHLEVEL,
  313. };
  314. static struct drm_driver *driver;
  315. static struct pci_driver *pdriver;
  316. static struct pci_driver radeon_pci_driver = {
  317. .name = DRIVER_NAME,
  318. .id_table = pciidlist,
  319. };
  320. static struct pci_driver radeon_kms_pci_driver = {
  321. .name = DRIVER_NAME,
  322. .id_table = pciidlist,
  323. .probe = radeon_pci_probe,
  324. .remove = radeon_pci_remove,
  325. .suspend = radeon_pci_suspend,
  326. .resume = radeon_pci_resume,
  327. };
  328. static int __init radeon_init(void)
  329. {
  330. driver = &driver_old;
  331. pdriver = &radeon_pci_driver;
  332. driver->num_ioctls = radeon_max_ioctl;
  333. #ifdef CONFIG_VGA_CONSOLE
  334. if (vgacon_text_force() && radeon_modeset == -1) {
  335. DRM_INFO("VGACON disable radeon kernel modesetting.\n");
  336. driver = &driver_old;
  337. pdriver = &radeon_pci_driver;
  338. driver->driver_features &= ~DRIVER_MODESET;
  339. radeon_modeset = 0;
  340. }
  341. #endif
  342. /* if enabled by default */
  343. if (radeon_modeset == -1) {
  344. #ifdef CONFIG_DRM_RADEON_KMS
  345. DRM_INFO("radeon defaulting to kernel modesetting.\n");
  346. radeon_modeset = 1;
  347. #else
  348. DRM_INFO("radeon defaulting to userspace modesetting.\n");
  349. radeon_modeset = 0;
  350. #endif
  351. }
  352. if (radeon_modeset == 1) {
  353. DRM_INFO("radeon kernel modesetting enabled.\n");
  354. driver = &kms_driver;
  355. pdriver = &radeon_kms_pci_driver;
  356. driver->driver_features |= DRIVER_MODESET;
  357. driver->num_ioctls = radeon_max_kms_ioctl;
  358. radeon_register_atpx_handler();
  359. }
  360. /* if the vga console setting is enabled still
  361. * let modprobe override it */
  362. return drm_pci_init(driver, pdriver);
  363. }
  364. static void __exit radeon_exit(void)
  365. {
  366. drm_pci_exit(driver, pdriver);
  367. radeon_unregister_atpx_handler();
  368. }
  369. module_init(radeon_init);
  370. module_exit(radeon_exit);
  371. MODULE_AUTHOR(DRIVER_AUTHOR);
  372. MODULE_DESCRIPTION(DRIVER_DESC);
  373. MODULE_LICENSE("GPL and additional rights");