psb_drv.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /**************************************************************************
  2. * Copyright (c) 2007-2011, Intel Corporation.
  3. * All Rights Reserved.
  4. * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX., USA.
  5. * All Rights Reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. **************************************************************************/
  21. #include <drm/drmP.h>
  22. #include <drm/drm.h>
  23. #include "gma_drm.h"
  24. #include "psb_drv.h"
  25. #include "framebuffer.h"
  26. #include "psb_reg.h"
  27. #include "psb_intel_reg.h"
  28. #include "intel_bios.h"
  29. #include "mid_bios.h"
  30. #include <drm/drm_pciids.h>
  31. #include "power.h"
  32. #include <linux/cpu.h>
  33. #include <linux/notifier.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/pm_runtime.h>
  36. #include <acpi/video.h>
  37. #include <linux/module.h>
  38. static int drm_psb_trap_pagefaults;
  39. static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  40. MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults");
  41. module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600);
  42. static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
  43. { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
  44. { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &psb_chip_ops },
  45. #if defined(CONFIG_DRM_GMA600)
  46. { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  47. { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  48. { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  49. { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  50. { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  51. { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  52. { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  53. { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  54. /* Atom E620 */
  55. { 0x8086, 0x4108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &oaktrail_chip_ops},
  56. #endif
  57. #if defined(CONFIG_DRM_MEDFIELD)
  58. {0x8086, 0x0130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  59. {0x8086, 0x0131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  60. {0x8086, 0x0132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  61. {0x8086, 0x0133, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  62. {0x8086, 0x0134, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  63. {0x8086, 0x0135, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  64. {0x8086, 0x0136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  65. {0x8086, 0x0137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &mdfld_chip_ops},
  66. #endif
  67. #if defined(CONFIG_DRM_GMA3600)
  68. { 0x8086, 0x0be0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  69. { 0x8086, 0x0be1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  70. { 0x8086, 0x0be2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  71. { 0x8086, 0x0be3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  72. { 0x8086, 0x0be4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  73. { 0x8086, 0x0be5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  74. { 0x8086, 0x0be6, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  75. { 0x8086, 0x0be7, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (long) &cdv_chip_ops},
  76. #endif
  77. { 0, }
  78. };
  79. MODULE_DEVICE_TABLE(pci, pciidlist);
  80. /*
  81. * Standard IOCTLs.
  82. */
  83. #define DRM_IOCTL_GMA_ADB \
  84. DRM_IOWR(DRM_GMA_ADB + DRM_COMMAND_BASE, uint32_t)
  85. #define DRM_IOCTL_GMA_MODE_OPERATION \
  86. DRM_IOWR(DRM_GMA_MODE_OPERATION + DRM_COMMAND_BASE, \
  87. struct drm_psb_mode_operation_arg)
  88. #define DRM_IOCTL_GMA_STOLEN_MEMORY \
  89. DRM_IOWR(DRM_GMA_STOLEN_MEMORY + DRM_COMMAND_BASE, \
  90. struct drm_psb_stolen_memory_arg)
  91. #define DRM_IOCTL_GMA_GAMMA \
  92. DRM_IOWR(DRM_GMA_GAMMA + DRM_COMMAND_BASE, \
  93. struct drm_psb_dpst_lut_arg)
  94. #define DRM_IOCTL_GMA_DPST_BL \
  95. DRM_IOWR(DRM_GMA_DPST_BL + DRM_COMMAND_BASE, \
  96. uint32_t)
  97. #define DRM_IOCTL_GMA_GET_PIPE_FROM_CRTC_ID \
  98. DRM_IOWR(DRM_GMA_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \
  99. struct drm_psb_get_pipe_from_crtc_id_arg)
  100. #define DRM_IOCTL_GMA_GEM_CREATE \
  101. DRM_IOWR(DRM_GMA_GEM_CREATE + DRM_COMMAND_BASE, \
  102. struct drm_psb_gem_create)
  103. #define DRM_IOCTL_GMA_GEM_MMAP \
  104. DRM_IOWR(DRM_GMA_GEM_MMAP + DRM_COMMAND_BASE, \
  105. struct drm_psb_gem_mmap)
  106. static int psb_adb_ioctl(struct drm_device *dev, void *data,
  107. struct drm_file *file_priv);
  108. static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
  109. struct drm_file *file_priv);
  110. static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
  111. struct drm_file *file_priv);
  112. static int psb_gamma_ioctl(struct drm_device *dev, void *data,
  113. struct drm_file *file_priv);
  114. static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
  115. struct drm_file *file_priv);
  116. static struct drm_ioctl_desc psb_ioctls[] = {
  117. DRM_IOCTL_DEF_DRV(GMA_ADB, psb_adb_ioctl, DRM_AUTH),
  118. DRM_IOCTL_DEF_DRV(GMA_MODE_OPERATION, psb_mode_operation_ioctl,
  119. DRM_AUTH),
  120. DRM_IOCTL_DEF_DRV(GMA_STOLEN_MEMORY, psb_stolen_memory_ioctl,
  121. DRM_AUTH),
  122. DRM_IOCTL_DEF_DRV(GMA_GAMMA, psb_gamma_ioctl, DRM_AUTH),
  123. DRM_IOCTL_DEF_DRV(GMA_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH),
  124. DRM_IOCTL_DEF_DRV(GMA_GET_PIPE_FROM_CRTC_ID,
  125. psb_intel_get_pipe_from_crtc_id, 0),
  126. DRM_IOCTL_DEF_DRV(GMA_GEM_CREATE, psb_gem_create_ioctl,
  127. DRM_UNLOCKED | DRM_AUTH),
  128. DRM_IOCTL_DEF_DRV(GMA_GEM_MMAP, psb_gem_mmap_ioctl,
  129. DRM_UNLOCKED | DRM_AUTH),
  130. };
  131. static void psb_lastclose(struct drm_device *dev)
  132. {
  133. return;
  134. }
  135. static void psb_do_takedown(struct drm_device *dev)
  136. {
  137. }
  138. static int psb_do_init(struct drm_device *dev)
  139. {
  140. struct drm_psb_private *dev_priv = dev->dev_private;
  141. struct psb_gtt *pg = &dev_priv->gtt;
  142. uint32_t stolen_gtt;
  143. int ret = -ENOMEM;
  144. if (pg->mmu_gatt_start & 0x0FFFFFFF) {
  145. dev_err(dev->dev, "Gatt must be 256M aligned. This is a bug.\n");
  146. ret = -EINVAL;
  147. goto out_err;
  148. }
  149. stolen_gtt = (pg->stolen_size >> PAGE_SHIFT) * 4;
  150. stolen_gtt = (stolen_gtt + PAGE_SIZE - 1) >> PAGE_SHIFT;
  151. stolen_gtt =
  152. (stolen_gtt < pg->gtt_pages) ? stolen_gtt : pg->gtt_pages;
  153. dev_priv->gatt_free_offset = pg->mmu_gatt_start +
  154. (stolen_gtt << PAGE_SHIFT) * 1024;
  155. if (1 || drm_debug) {
  156. uint32_t core_id = PSB_RSGX32(PSB_CR_CORE_ID);
  157. uint32_t core_rev = PSB_RSGX32(PSB_CR_CORE_REVISION);
  158. DRM_INFO("SGX core id = 0x%08x\n", core_id);
  159. DRM_INFO("SGX core rev major = 0x%02x, minor = 0x%02x\n",
  160. (core_rev & _PSB_CC_REVISION_MAJOR_MASK) >>
  161. _PSB_CC_REVISION_MAJOR_SHIFT,
  162. (core_rev & _PSB_CC_REVISION_MINOR_MASK) >>
  163. _PSB_CC_REVISION_MINOR_SHIFT);
  164. DRM_INFO
  165. ("SGX core rev maintenance = 0x%02x, designer = 0x%02x\n",
  166. (core_rev & _PSB_CC_REVISION_MAINTENANCE_MASK) >>
  167. _PSB_CC_REVISION_MAINTENANCE_SHIFT,
  168. (core_rev & _PSB_CC_REVISION_DESIGNER_MASK) >>
  169. _PSB_CC_REVISION_DESIGNER_SHIFT);
  170. }
  171. spin_lock_init(&dev_priv->irqmask_lock);
  172. spin_lock_init(&dev_priv->lock_2d);
  173. PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0);
  174. PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK1);
  175. PSB_RSGX32(PSB_CR_BIF_BANK1);
  176. PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK,
  177. PSB_CR_BIF_CTRL);
  178. psb_spank(dev_priv);
  179. /* mmu_gatt ?? */
  180. PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE);
  181. return 0;
  182. out_err:
  183. psb_do_takedown(dev);
  184. return ret;
  185. }
  186. static int psb_driver_unload(struct drm_device *dev)
  187. {
  188. struct drm_psb_private *dev_priv = dev->dev_private;
  189. /* Kill vblank etc here */
  190. gma_backlight_exit(dev);
  191. psb_modeset_cleanup(dev);
  192. if (dev_priv) {
  193. psb_lid_timer_takedown(dev_priv);
  194. gma_intel_opregion_exit(dev);
  195. if (dev_priv->ops->chip_teardown)
  196. dev_priv->ops->chip_teardown(dev);
  197. psb_do_takedown(dev);
  198. if (dev_priv->pf_pd) {
  199. psb_mmu_free_pagedir(dev_priv->pf_pd);
  200. dev_priv->pf_pd = NULL;
  201. }
  202. if (dev_priv->mmu) {
  203. struct psb_gtt *pg = &dev_priv->gtt;
  204. down_read(&pg->sem);
  205. psb_mmu_remove_pfn_sequence(
  206. psb_mmu_get_default_pd
  207. (dev_priv->mmu),
  208. pg->mmu_gatt_start,
  209. dev_priv->vram_stolen_size >> PAGE_SHIFT);
  210. up_read(&pg->sem);
  211. psb_mmu_driver_takedown(dev_priv->mmu);
  212. dev_priv->mmu = NULL;
  213. }
  214. psb_gtt_takedown(dev);
  215. if (dev_priv->scratch_page) {
  216. __free_page(dev_priv->scratch_page);
  217. dev_priv->scratch_page = NULL;
  218. }
  219. if (dev_priv->vdc_reg) {
  220. iounmap(dev_priv->vdc_reg);
  221. dev_priv->vdc_reg = NULL;
  222. }
  223. if (dev_priv->sgx_reg) {
  224. iounmap(dev_priv->sgx_reg);
  225. dev_priv->sgx_reg = NULL;
  226. }
  227. kfree(dev_priv);
  228. dev->dev_private = NULL;
  229. /*destroy VBT data*/
  230. psb_intel_destroy_bios(dev);
  231. }
  232. gma_power_uninit(dev);
  233. return 0;
  234. }
  235. static int psb_driver_load(struct drm_device *dev, unsigned long chipset)
  236. {
  237. struct drm_psb_private *dev_priv;
  238. unsigned long resource_start;
  239. unsigned long irqflags;
  240. int ret = -ENOMEM;
  241. struct drm_connector *connector;
  242. struct psb_intel_encoder *psb_intel_encoder;
  243. dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
  244. if (dev_priv == NULL)
  245. return -ENOMEM;
  246. dev_priv->ops = (struct psb_ops *)chipset;
  247. dev_priv->dev = dev;
  248. dev->dev_private = (void *) dev_priv;
  249. pci_set_master(dev->pdev);
  250. if (!IS_PSB(dev)) {
  251. if (pci_enable_msi(dev->pdev))
  252. dev_warn(dev->dev, "Enabling MSI failed!\n");
  253. }
  254. dev_priv->num_pipe = dev_priv->ops->pipes;
  255. resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE);
  256. dev_priv->vdc_reg =
  257. ioremap(resource_start + PSB_VDC_OFFSET, PSB_VDC_SIZE);
  258. if (!dev_priv->vdc_reg)
  259. goto out_err;
  260. dev_priv->sgx_reg = ioremap(resource_start + dev_priv->ops->sgx_offset,
  261. PSB_SGX_SIZE);
  262. if (!dev_priv->sgx_reg)
  263. goto out_err;
  264. ret = dev_priv->ops->chip_setup(dev);
  265. if (ret)
  266. goto out_err;
  267. /* Init OSPM support */
  268. gma_power_init(dev);
  269. ret = -ENOMEM;
  270. dev_priv->scratch_page = alloc_page(GFP_DMA32 | __GFP_ZERO);
  271. if (!dev_priv->scratch_page)
  272. goto out_err;
  273. set_pages_uc(dev_priv->scratch_page, 1);
  274. ret = psb_gtt_init(dev, 0);
  275. if (ret)
  276. goto out_err;
  277. dev_priv->mmu = psb_mmu_driver_init((void *)0,
  278. drm_psb_trap_pagefaults, 0,
  279. dev_priv);
  280. if (!dev_priv->mmu)
  281. goto out_err;
  282. dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0);
  283. if (!dev_priv->pf_pd)
  284. goto out_err;
  285. psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0);
  286. psb_mmu_set_pd_context(dev_priv->pf_pd, 1);
  287. ret = psb_do_init(dev);
  288. if (ret)
  289. return ret;
  290. PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE);
  291. PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE);
  292. /* igd_opregion_init(&dev_priv->opregion_dev); */
  293. /* acpi_video_register(); */
  294. if (dev_priv->lid_state)
  295. psb_lid_timer_init(dev_priv);
  296. ret = drm_vblank_init(dev, dev_priv->num_pipe);
  297. if (ret)
  298. goto out_err;
  299. /*
  300. * Install interrupt handlers prior to powering off SGX or else we will
  301. * crash.
  302. */
  303. dev_priv->vdc_irq_mask = 0;
  304. dev_priv->pipestat[0] = 0;
  305. dev_priv->pipestat[1] = 0;
  306. dev_priv->pipestat[2] = 0;
  307. spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags);
  308. PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM);
  309. PSB_WVDC32(0x00000000, PSB_INT_ENABLE_R);
  310. PSB_WVDC32(0xFFFFFFFF, PSB_INT_MASK_R);
  311. spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags);
  312. if (IS_PSB(dev) && drm_core_check_feature(dev, DRIVER_MODESET))
  313. drm_irq_install(dev);
  314. dev->vblank_disable_allowed = 1;
  315. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  316. dev->driver->get_vblank_counter = psb_get_vblank_counter;
  317. psb_modeset_init(dev);
  318. psb_fbdev_init(dev);
  319. drm_kms_helper_poll_init(dev);
  320. /* Only add backlight support if we have LVDS output */
  321. list_for_each_entry(connector, &dev->mode_config.connector_list,
  322. head) {
  323. psb_intel_encoder = psb_intel_attached_encoder(connector);
  324. switch (psb_intel_encoder->type) {
  325. case INTEL_OUTPUT_LVDS:
  326. case INTEL_OUTPUT_MIPI:
  327. ret = gma_backlight_init(dev);
  328. break;
  329. }
  330. }
  331. if (ret)
  332. return ret;
  333. #if 0
  334. /*enable runtime pm at last*/
  335. pm_runtime_enable(&dev->pdev->dev);
  336. pm_runtime_set_active(&dev->pdev->dev);
  337. #endif
  338. /*Intel drm driver load is done, continue doing pvr load*/
  339. return 0;
  340. out_err:
  341. psb_driver_unload(dev);
  342. return ret;
  343. }
  344. static int psb_driver_device_is_agp(struct drm_device *dev)
  345. {
  346. return 0;
  347. }
  348. static inline void get_brightness(struct backlight_device *bd)
  349. {
  350. #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
  351. if (bd) {
  352. bd->props.brightness = bd->ops->get_brightness(bd);
  353. backlight_update_status(bd);
  354. }
  355. #endif
  356. }
  357. static int psb_dpst_bl_ioctl(struct drm_device *dev, void *data,
  358. struct drm_file *file_priv)
  359. {
  360. struct drm_psb_private *dev_priv = psb_priv(dev);
  361. uint32_t *arg = data;
  362. dev_priv->blc_adj2 = *arg;
  363. get_brightness(dev_priv->backlight_device);
  364. return 0;
  365. }
  366. static int psb_adb_ioctl(struct drm_device *dev, void *data,
  367. struct drm_file *file_priv)
  368. {
  369. struct drm_psb_private *dev_priv = psb_priv(dev);
  370. uint32_t *arg = data;
  371. dev_priv->blc_adj1 = *arg;
  372. get_brightness(dev_priv->backlight_device);
  373. return 0;
  374. }
  375. static int psb_gamma_ioctl(struct drm_device *dev, void *data,
  376. struct drm_file *file_priv)
  377. {
  378. struct drm_psb_dpst_lut_arg *lut_arg = data;
  379. struct drm_mode_object *obj;
  380. struct drm_crtc *crtc;
  381. struct drm_connector *connector;
  382. struct psb_intel_crtc *psb_intel_crtc;
  383. int i = 0;
  384. int32_t obj_id;
  385. obj_id = lut_arg->output_id;
  386. obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_CONNECTOR);
  387. if (!obj) {
  388. dev_dbg(dev->dev, "Invalid Connector object.\n");
  389. return -EINVAL;
  390. }
  391. connector = obj_to_connector(obj);
  392. crtc = connector->encoder->crtc;
  393. psb_intel_crtc = to_psb_intel_crtc(crtc);
  394. for (i = 0; i < 256; i++)
  395. psb_intel_crtc->lut_adj[i] = lut_arg->lut[i];
  396. psb_intel_crtc_load_lut(crtc);
  397. return 0;
  398. }
  399. static int psb_mode_operation_ioctl(struct drm_device *dev, void *data,
  400. struct drm_file *file_priv)
  401. {
  402. uint32_t obj_id;
  403. uint16_t op;
  404. struct drm_mode_modeinfo *umode;
  405. struct drm_display_mode *mode = NULL;
  406. struct drm_psb_mode_operation_arg *arg;
  407. struct drm_mode_object *obj;
  408. struct drm_connector *connector;
  409. struct drm_connector_helper_funcs *connector_funcs;
  410. int ret = 0;
  411. int resp = MODE_OK;
  412. arg = (struct drm_psb_mode_operation_arg *)data;
  413. obj_id = arg->obj_id;
  414. op = arg->operation;
  415. switch (op) {
  416. case PSB_MODE_OPERATION_MODE_VALID:
  417. umode = &arg->mode;
  418. mutex_lock(&dev->mode_config.mutex);
  419. obj = drm_mode_object_find(dev, obj_id,
  420. DRM_MODE_OBJECT_CONNECTOR);
  421. if (!obj) {
  422. ret = -EINVAL;
  423. goto mode_op_out;
  424. }
  425. connector = obj_to_connector(obj);
  426. mode = drm_mode_create(dev);
  427. if (!mode) {
  428. ret = -ENOMEM;
  429. goto mode_op_out;
  430. }
  431. /* drm_crtc_convert_umode(mode, umode); */
  432. {
  433. mode->clock = umode->clock;
  434. mode->hdisplay = umode->hdisplay;
  435. mode->hsync_start = umode->hsync_start;
  436. mode->hsync_end = umode->hsync_end;
  437. mode->htotal = umode->htotal;
  438. mode->hskew = umode->hskew;
  439. mode->vdisplay = umode->vdisplay;
  440. mode->vsync_start = umode->vsync_start;
  441. mode->vsync_end = umode->vsync_end;
  442. mode->vtotal = umode->vtotal;
  443. mode->vscan = umode->vscan;
  444. mode->vrefresh = umode->vrefresh;
  445. mode->flags = umode->flags;
  446. mode->type = umode->type;
  447. strncpy(mode->name, umode->name, DRM_DISPLAY_MODE_LEN);
  448. mode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
  449. }
  450. connector_funcs = (struct drm_connector_helper_funcs *)
  451. connector->helper_private;
  452. if (connector_funcs->mode_valid) {
  453. resp = connector_funcs->mode_valid(connector, mode);
  454. arg->data = resp;
  455. }
  456. /*do some clean up work*/
  457. if (mode)
  458. drm_mode_destroy(dev, mode);
  459. mode_op_out:
  460. mutex_unlock(&dev->mode_config.mutex);
  461. return ret;
  462. default:
  463. dev_dbg(dev->dev, "Unsupported psb mode operation\n");
  464. return -EOPNOTSUPP;
  465. }
  466. return 0;
  467. }
  468. static int psb_stolen_memory_ioctl(struct drm_device *dev, void *data,
  469. struct drm_file *file_priv)
  470. {
  471. struct drm_psb_private *dev_priv = psb_priv(dev);
  472. struct drm_psb_stolen_memory_arg *arg = data;
  473. arg->base = dev_priv->stolen_base;
  474. arg->size = dev_priv->vram_stolen_size;
  475. return 0;
  476. }
  477. static int psb_driver_open(struct drm_device *dev, struct drm_file *priv)
  478. {
  479. return 0;
  480. }
  481. static void psb_driver_close(struct drm_device *dev, struct drm_file *priv)
  482. {
  483. }
  484. static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd,
  485. unsigned long arg)
  486. {
  487. struct drm_file *file_priv = filp->private_data;
  488. struct drm_device *dev = file_priv->minor->dev;
  489. struct drm_psb_private *dev_priv = dev->dev_private;
  490. static unsigned int runtime_allowed;
  491. if (runtime_allowed == 1 && dev_priv->is_lvds_on) {
  492. runtime_allowed++;
  493. pm_runtime_allow(&dev->pdev->dev);
  494. dev_priv->rpm_enabled = 1;
  495. }
  496. return drm_ioctl(filp, cmd, arg);
  497. /* FIXME: do we need to wrap the other side of this */
  498. }
  499. /* When a client dies:
  500. * - Check for and clean up flipped page state
  501. */
  502. static void psb_driver_preclose(struct drm_device *dev, struct drm_file *priv)
  503. {
  504. }
  505. static void psb_remove(struct pci_dev *pdev)
  506. {
  507. struct drm_device *dev = pci_get_drvdata(pdev);
  508. drm_put_dev(dev);
  509. }
  510. static const struct dev_pm_ops psb_pm_ops = {
  511. .resume = gma_power_resume,
  512. .suspend = gma_power_suspend,
  513. .runtime_suspend = psb_runtime_suspend,
  514. .runtime_resume = psb_runtime_resume,
  515. .runtime_idle = psb_runtime_idle,
  516. };
  517. static struct vm_operations_struct psb_gem_vm_ops = {
  518. .fault = psb_gem_fault,
  519. .open = drm_gem_vm_open,
  520. .close = drm_gem_vm_close,
  521. };
  522. static const struct file_operations psb_gem_fops = {
  523. .owner = THIS_MODULE,
  524. .open = drm_open,
  525. .release = drm_release,
  526. .unlocked_ioctl = psb_unlocked_ioctl,
  527. .mmap = drm_gem_mmap,
  528. .poll = drm_poll,
  529. .fasync = drm_fasync,
  530. .read = drm_read,
  531. };
  532. static struct drm_driver driver = {
  533. .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
  534. DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
  535. .load = psb_driver_load,
  536. .unload = psb_driver_unload,
  537. .ioctls = psb_ioctls,
  538. .num_ioctls = DRM_ARRAY_SIZE(psb_ioctls),
  539. .device_is_agp = psb_driver_device_is_agp,
  540. .irq_preinstall = psb_irq_preinstall,
  541. .irq_postinstall = psb_irq_postinstall,
  542. .irq_uninstall = psb_irq_uninstall,
  543. .irq_handler = psb_irq_handler,
  544. .enable_vblank = psb_enable_vblank,
  545. .disable_vblank = psb_disable_vblank,
  546. .get_vblank_counter = psb_get_vblank_counter,
  547. .lastclose = psb_lastclose,
  548. .open = psb_driver_open,
  549. .preclose = psb_driver_preclose,
  550. .postclose = psb_driver_close,
  551. .reclaim_buffers = drm_core_reclaim_buffers,
  552. .gem_init_object = psb_gem_init_object,
  553. .gem_free_object = psb_gem_free_object,
  554. .gem_vm_ops = &psb_gem_vm_ops,
  555. .dumb_create = psb_gem_dumb_create,
  556. .dumb_map_offset = psb_gem_dumb_map_gtt,
  557. .dumb_destroy = psb_gem_dumb_destroy,
  558. .fops = &psb_gem_fops,
  559. .name = DRIVER_NAME,
  560. .desc = DRIVER_DESC,
  561. .date = PSB_DRM_DRIVER_DATE,
  562. .major = PSB_DRM_DRIVER_MAJOR,
  563. .minor = PSB_DRM_DRIVER_MINOR,
  564. .patchlevel = PSB_DRM_DRIVER_PATCHLEVEL
  565. };
  566. static struct pci_driver psb_pci_driver = {
  567. .name = DRIVER_NAME,
  568. .id_table = pciidlist,
  569. .probe = psb_probe,
  570. .remove = psb_remove,
  571. .driver = {
  572. .pm = &psb_pm_ops,
  573. }
  574. };
  575. static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  576. {
  577. return drm_get_pci_dev(pdev, ent, &driver);
  578. }
  579. static int __init psb_init(void)
  580. {
  581. return drm_pci_init(&driver, &psb_pci_driver);
  582. }
  583. static void __exit psb_exit(void)
  584. {
  585. drm_pci_exit(&driver, &psb_pci_driver);
  586. }
  587. late_initcall(psb_init);
  588. module_exit(psb_exit);
  589. MODULE_AUTHOR("Alan Cox <alan@linux.intel.com> and others");
  590. MODULE_DESCRIPTION(DRIVER_DESC);
  591. MODULE_LICENSE("GPL");