ast_main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sub license, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  15. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  16. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  17. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  18. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. *
  20. * The above copyright notice and this permission notice (including the
  21. * next paragraph) shall be included in all copies or substantial portions
  22. * of the Software.
  23. *
  24. */
  25. /*
  26. * Authors: Dave Airlie <airlied@redhat.com>
  27. */
  28. #include <drm/drmP.h>
  29. #include "ast_drv.h"
  30. #include <drm/drm_fb_helper.h>
  31. #include <drm/drm_crtc_helper.h>
  32. #include "ast_dram_tables.h"
  33. void ast_set_index_reg_mask(struct ast_private *ast,
  34. uint32_t base, uint8_t index,
  35. uint8_t mask, uint8_t val)
  36. {
  37. u8 tmp;
  38. ast_io_write8(ast, base, index);
  39. tmp = (ast_io_read8(ast, base + 1) & mask) | val;
  40. ast_set_index_reg(ast, base, index, tmp);
  41. }
  42. uint8_t ast_get_index_reg(struct ast_private *ast,
  43. uint32_t base, uint8_t index)
  44. {
  45. uint8_t ret;
  46. ast_io_write8(ast, base, index);
  47. ret = ast_io_read8(ast, base + 1);
  48. return ret;
  49. }
  50. uint8_t ast_get_index_reg_mask(struct ast_private *ast,
  51. uint32_t base, uint8_t index, uint8_t mask)
  52. {
  53. uint8_t ret;
  54. ast_io_write8(ast, base, index);
  55. ret = ast_io_read8(ast, base + 1) & mask;
  56. return ret;
  57. }
  58. static void ast_detect_config_mode(struct drm_device *dev, u32 *scu_rev)
  59. {
  60. struct device_node *np = dev->pdev->dev.of_node;
  61. struct ast_private *ast = dev->dev_private;
  62. uint32_t data, jregd0, jregd1;
  63. /* Defaults */
  64. ast->config_mode = ast_use_defaults;
  65. *scu_rev = 0xffffffff;
  66. /* Check if we have device-tree properties */
  67. if (np && !of_property_read_u32(np, "aspeed,scu-revision-id",
  68. scu_rev)) {
  69. /* We do, disable P2A access */
  70. ast->config_mode = ast_use_dt;
  71. DRM_INFO("Using device-tree for configuration\n");
  72. return;
  73. }
  74. /* Not all families have a P2A bridge */
  75. if (dev->pdev->device != PCI_CHIP_AST2000)
  76. return;
  77. /*
  78. * The BMC will set SCU 0x40 D[12] to 1 if the P2 bridge
  79. * is disabled. We force using P2A if VGA only mode bit
  80. * is set D[7]
  81. */
  82. jregd0 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  83. jregd1 = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
  84. if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) {
  85. /* Double check it's actually working */
  86. data = ast_read32(ast, 0xf004);
  87. if (data != 0xFFFFFFFF) {
  88. /* P2A works, grab silicon revision */
  89. ast->config_mode = ast_use_p2a;
  90. DRM_INFO("Using P2A bridge for configuration\n");
  91. /* Read SCU7c (silicon revision register) */
  92. ast_write32(ast, 0xf004, 0x1e6e0000);
  93. ast_write32(ast, 0xf000, 0x1);
  94. *scu_rev = ast_read32(ast, 0x1207c);
  95. return;
  96. }
  97. }
  98. /* We have a P2A bridge but it's disabled */
  99. DRM_INFO("P2A bridge disabled, using default configuration\n");
  100. }
  101. static int ast_detect_chip(struct drm_device *dev, bool *need_post)
  102. {
  103. struct ast_private *ast = dev->dev_private;
  104. uint32_t jreg, scu_rev;
  105. /*
  106. * If VGA isn't enabled, we need to enable now or subsequent
  107. * access to the scratch registers will fail. We also inform
  108. * our caller that it needs to POST the chip
  109. * (Assumption: VGA not enabled -> need to POST)
  110. */
  111. if (!ast_is_vga_enabled(dev)) {
  112. ast_enable_vga(dev);
  113. DRM_INFO("VGA not enabled on entry, requesting chip POST\n");
  114. *need_post = true;
  115. } else
  116. *need_post = false;
  117. /* Enable extended register access */
  118. ast_enable_mmio(dev);
  119. ast_open_key(ast);
  120. /* Find out whether P2A works or whether to use device-tree */
  121. ast_detect_config_mode(dev, &scu_rev);
  122. /* Identify chipset */
  123. if (dev->pdev->device == PCI_CHIP_AST1180) {
  124. ast->chip = AST1100;
  125. DRM_INFO("AST 1180 detected\n");
  126. } else {
  127. if (dev->pdev->revision >= 0x30) {
  128. ast->chip = AST2400;
  129. DRM_INFO("AST 2400 detected\n");
  130. } else if (dev->pdev->revision >= 0x20) {
  131. ast->chip = AST2300;
  132. DRM_INFO("AST 2300 detected\n");
  133. } else if (dev->pdev->revision >= 0x10) {
  134. switch (scu_rev & 0x0300) {
  135. case 0x0200:
  136. ast->chip = AST1100;
  137. DRM_INFO("AST 1100 detected\n");
  138. break;
  139. case 0x0100:
  140. ast->chip = AST2200;
  141. DRM_INFO("AST 2200 detected\n");
  142. break;
  143. case 0x0000:
  144. ast->chip = AST2150;
  145. DRM_INFO("AST 2150 detected\n");
  146. break;
  147. default:
  148. ast->chip = AST2100;
  149. DRM_INFO("AST 2100 detected\n");
  150. break;
  151. }
  152. ast->vga2_clone = false;
  153. } else {
  154. ast->chip = AST2000;
  155. DRM_INFO("AST 2000 detected\n");
  156. }
  157. }
  158. /* Check if we support wide screen */
  159. switch (ast->chip) {
  160. case AST1180:
  161. ast->support_wide_screen = true;
  162. break;
  163. case AST2000:
  164. ast->support_wide_screen = false;
  165. break;
  166. default:
  167. jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd0, 0xff);
  168. if (!(jreg & 0x80))
  169. ast->support_wide_screen = true;
  170. else if (jreg & 0x01)
  171. ast->support_wide_screen = true;
  172. else {
  173. ast->support_wide_screen = false;
  174. if (ast->chip == AST2300 &&
  175. (scu_rev & 0x300) == 0x0) /* ast1300 */
  176. ast->support_wide_screen = true;
  177. if (ast->chip == AST2400 &&
  178. (scu_rev & 0x300) == 0x100) /* ast1400 */
  179. ast->support_wide_screen = true;
  180. }
  181. break;
  182. }
  183. /* Check 3rd Tx option (digital output afaik) */
  184. ast->tx_chip_type = AST_TX_NONE;
  185. /*
  186. * VGACRA3 Enhanced Color Mode Register, check if DVO is already
  187. * enabled, in that case, assume we have a SIL164 TMDS transmitter
  188. *
  189. * Don't make that assumption if we the chip wasn't enabled and
  190. * is at power-on reset, otherwise we'll incorrectly "detect" a
  191. * SIL164 when there is none.
  192. */
  193. if (!*need_post) {
  194. jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xa3, 0xff);
  195. if (jreg & 0x80)
  196. ast->tx_chip_type = AST_TX_SIL164;
  197. }
  198. if ((ast->chip == AST2300) || (ast->chip == AST2400)) {
  199. /*
  200. * On AST2300 and 2400, look the configuration set by the SoC in
  201. * the SOC scratch register #1 bits 11:8 (interestingly marked
  202. * as "reserved" in the spec)
  203. */
  204. jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
  205. switch (jreg) {
  206. case 0x04:
  207. ast->tx_chip_type = AST_TX_SIL164;
  208. break;
  209. case 0x08:
  210. ast->dp501_fw_addr = kzalloc(32*1024, GFP_KERNEL);
  211. if (ast->dp501_fw_addr) {
  212. /* backup firmware */
  213. if (ast_backup_fw(dev, ast->dp501_fw_addr, 32*1024)) {
  214. kfree(ast->dp501_fw_addr);
  215. ast->dp501_fw_addr = NULL;
  216. }
  217. }
  218. /* fallthrough */
  219. case 0x0c:
  220. ast->tx_chip_type = AST_TX_DP501;
  221. }
  222. }
  223. /* Print stuff for diagnostic purposes */
  224. switch(ast->tx_chip_type) {
  225. case AST_TX_SIL164:
  226. DRM_INFO("Using Sil164 TMDS transmitter\n");
  227. break;
  228. case AST_TX_DP501:
  229. DRM_INFO("Using DP501 DisplayPort transmitter\n");
  230. break;
  231. default:
  232. DRM_INFO("Analog VGA only\n");
  233. }
  234. return 0;
  235. }
  236. static int ast_get_dram_info(struct drm_device *dev)
  237. {
  238. struct device_node *np = dev->pdev->dev.of_node;
  239. struct ast_private *ast = dev->dev_private;
  240. uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;
  241. uint32_t denum, num, div, ref_pll, dsel;
  242. switch (ast->config_mode) {
  243. case ast_use_dt:
  244. /*
  245. * If some properties are missing, use reasonable
  246. * defaults for AST2400
  247. */
  248. if (of_property_read_u32(np, "aspeed,mcr-configuration",
  249. &mcr_cfg))
  250. mcr_cfg = 0x00000577;
  251. if (of_property_read_u32(np, "aspeed,mcr-scu-mpll",
  252. &mcr_scu_mpll))
  253. mcr_scu_mpll = 0x000050C0;
  254. if (of_property_read_u32(np, "aspeed,mcr-scu-strap",
  255. &mcr_scu_strap))
  256. mcr_scu_strap = 0;
  257. break;
  258. case ast_use_p2a:
  259. ast_write32(ast, 0xf004, 0x1e6e0000);
  260. ast_write32(ast, 0xf000, 0x1);
  261. mcr_cfg = ast_read32(ast, 0x10004);
  262. mcr_scu_mpll = ast_read32(ast, 0x10120);
  263. mcr_scu_strap = ast_read32(ast, 0x10170);
  264. break;
  265. case ast_use_defaults:
  266. default:
  267. ast->dram_bus_width = 16;
  268. ast->dram_type = AST_DRAM_1Gx16;
  269. ast->mclk = 396;
  270. return 0;
  271. }
  272. if (mcr_cfg & 0x40)
  273. ast->dram_bus_width = 16;
  274. else
  275. ast->dram_bus_width = 32;
  276. if (ast->chip == AST2300 || ast->chip == AST2400) {
  277. switch (mcr_cfg & 0x03) {
  278. case 0:
  279. ast->dram_type = AST_DRAM_512Mx16;
  280. break;
  281. default:
  282. case 1:
  283. ast->dram_type = AST_DRAM_1Gx16;
  284. break;
  285. case 2:
  286. ast->dram_type = AST_DRAM_2Gx16;
  287. break;
  288. case 3:
  289. ast->dram_type = AST_DRAM_4Gx16;
  290. break;
  291. }
  292. } else {
  293. switch (mcr_cfg & 0x0c) {
  294. case 0:
  295. case 4:
  296. ast->dram_type = AST_DRAM_512Mx16;
  297. break;
  298. case 8:
  299. if (mcr_cfg & 0x40)
  300. ast->dram_type = AST_DRAM_1Gx16;
  301. else
  302. ast->dram_type = AST_DRAM_512Mx32;
  303. break;
  304. case 0xc:
  305. ast->dram_type = AST_DRAM_1Gx32;
  306. break;
  307. }
  308. }
  309. if (mcr_scu_strap & 0x2000)
  310. ref_pll = 14318;
  311. else
  312. ref_pll = 12000;
  313. denum = mcr_scu_mpll & 0x1f;
  314. num = (mcr_scu_mpll & 0x3fe0) >> 5;
  315. dsel = (mcr_scu_mpll & 0xc000) >> 14;
  316. switch (dsel) {
  317. case 3:
  318. div = 0x4;
  319. break;
  320. case 2:
  321. case 1:
  322. div = 0x2;
  323. break;
  324. default:
  325. div = 0x1;
  326. break;
  327. }
  328. ast->mclk = ref_pll * (num + 2) / (denum + 2) * (div * 1000);
  329. return 0;
  330. }
  331. static void ast_user_framebuffer_destroy(struct drm_framebuffer *fb)
  332. {
  333. struct ast_framebuffer *ast_fb = to_ast_framebuffer(fb);
  334. if (ast_fb->obj)
  335. drm_gem_object_unreference_unlocked(ast_fb->obj);
  336. drm_framebuffer_cleanup(fb);
  337. kfree(fb);
  338. }
  339. static const struct drm_framebuffer_funcs ast_fb_funcs = {
  340. .destroy = ast_user_framebuffer_destroy,
  341. };
  342. int ast_framebuffer_init(struct drm_device *dev,
  343. struct ast_framebuffer *ast_fb,
  344. struct drm_mode_fb_cmd2 *mode_cmd,
  345. struct drm_gem_object *obj)
  346. {
  347. int ret;
  348. drm_helper_mode_fill_fb_struct(&ast_fb->base, mode_cmd);
  349. ast_fb->obj = obj;
  350. ret = drm_framebuffer_init(dev, &ast_fb->base, &ast_fb_funcs);
  351. if (ret) {
  352. DRM_ERROR("framebuffer init failed %d\n", ret);
  353. return ret;
  354. }
  355. return 0;
  356. }
  357. static struct drm_framebuffer *
  358. ast_user_framebuffer_create(struct drm_device *dev,
  359. struct drm_file *filp,
  360. struct drm_mode_fb_cmd2 *mode_cmd)
  361. {
  362. struct drm_gem_object *obj;
  363. struct ast_framebuffer *ast_fb;
  364. int ret;
  365. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handles[0]);
  366. if (obj == NULL)
  367. return ERR_PTR(-ENOENT);
  368. ast_fb = kzalloc(sizeof(*ast_fb), GFP_KERNEL);
  369. if (!ast_fb) {
  370. drm_gem_object_unreference_unlocked(obj);
  371. return ERR_PTR(-ENOMEM);
  372. }
  373. ret = ast_framebuffer_init(dev, ast_fb, mode_cmd, obj);
  374. if (ret) {
  375. drm_gem_object_unreference_unlocked(obj);
  376. kfree(ast_fb);
  377. return ERR_PTR(ret);
  378. }
  379. return &ast_fb->base;
  380. }
  381. static const struct drm_mode_config_funcs ast_mode_funcs = {
  382. .fb_create = ast_user_framebuffer_create,
  383. };
  384. static u32 ast_get_vram_info(struct drm_device *dev)
  385. {
  386. struct ast_private *ast = dev->dev_private;
  387. u8 jreg;
  388. u32 vram_size;
  389. ast_open_key(ast);
  390. vram_size = AST_VIDMEM_DEFAULT_SIZE;
  391. jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xaa, 0xff);
  392. switch (jreg & 3) {
  393. case 0: vram_size = AST_VIDMEM_SIZE_8M; break;
  394. case 1: vram_size = AST_VIDMEM_SIZE_16M; break;
  395. case 2: vram_size = AST_VIDMEM_SIZE_32M; break;
  396. case 3: vram_size = AST_VIDMEM_SIZE_64M; break;
  397. }
  398. jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0x99, 0xff);
  399. switch (jreg & 0x03) {
  400. case 1:
  401. vram_size -= 0x100000;
  402. break;
  403. case 2:
  404. vram_size -= 0x200000;
  405. break;
  406. case 3:
  407. vram_size -= 0x400000;
  408. break;
  409. }
  410. return vram_size;
  411. }
  412. int ast_driver_load(struct drm_device *dev, unsigned long flags)
  413. {
  414. struct ast_private *ast;
  415. bool need_post;
  416. int ret = 0;
  417. ast = kzalloc(sizeof(struct ast_private), GFP_KERNEL);
  418. if (!ast)
  419. return -ENOMEM;
  420. dev->dev_private = ast;
  421. ast->dev = dev;
  422. ast->regs = pci_iomap(dev->pdev, 1, 0);
  423. if (!ast->regs) {
  424. ret = -EIO;
  425. goto out_free;
  426. }
  427. /*
  428. * If we don't have IO space at all, use MMIO now and
  429. * assume the chip has MMIO enabled by default (rev 0x20
  430. * and higher).
  431. */
  432. if (!(pci_resource_flags(dev->pdev, 2) & IORESOURCE_IO)) {
  433. DRM_INFO("platform has no IO space, trying MMIO\n");
  434. ast->ioregs = ast->regs + AST_IO_MM_OFFSET;
  435. }
  436. /* "map" IO regs if the above hasn't done so already */
  437. if (!ast->ioregs) {
  438. ast->ioregs = pci_iomap(dev->pdev, 2, 0);
  439. if (!ast->ioregs) {
  440. ret = -EIO;
  441. goto out_free;
  442. }
  443. }
  444. ast_detect_chip(dev, &need_post);
  445. if (ast->chip != AST1180) {
  446. ret = ast_get_dram_info(dev);
  447. if (ret)
  448. goto out_free;
  449. ast->vram_size = ast_get_vram_info(dev);
  450. DRM_INFO("dram %d %d %d %08x\n", ast->mclk, ast->dram_type, ast->dram_bus_width, ast->vram_size);
  451. }
  452. if (need_post)
  453. ast_post_gpu(dev);
  454. ret = ast_mm_init(ast);
  455. if (ret)
  456. goto out_free;
  457. drm_mode_config_init(dev);
  458. dev->mode_config.funcs = (void *)&ast_mode_funcs;
  459. dev->mode_config.min_width = 0;
  460. dev->mode_config.min_height = 0;
  461. dev->mode_config.preferred_depth = 24;
  462. dev->mode_config.prefer_shadow = 1;
  463. dev->mode_config.fb_base = pci_resource_start(ast->dev->pdev, 0);
  464. if (ast->chip == AST2100 ||
  465. ast->chip == AST2200 ||
  466. ast->chip == AST2300 ||
  467. ast->chip == AST2400 ||
  468. ast->chip == AST1180) {
  469. dev->mode_config.max_width = 1920;
  470. dev->mode_config.max_height = 2048;
  471. } else {
  472. dev->mode_config.max_width = 1600;
  473. dev->mode_config.max_height = 1200;
  474. }
  475. ret = ast_mode_init(dev);
  476. if (ret)
  477. goto out_free;
  478. ret = ast_fbdev_init(dev);
  479. if (ret)
  480. goto out_free;
  481. return 0;
  482. out_free:
  483. kfree(ast);
  484. dev->dev_private = NULL;
  485. return ret;
  486. }
  487. int ast_driver_unload(struct drm_device *dev)
  488. {
  489. struct ast_private *ast = dev->dev_private;
  490. kfree(ast->dp501_fw_addr);
  491. ast_mode_fini(dev);
  492. ast_fbdev_fini(dev);
  493. drm_mode_config_cleanup(dev);
  494. ast_mm_fini(ast);
  495. if (ast->ioregs != ast->regs + AST_IO_MM_OFFSET)
  496. pci_iounmap(dev->pdev, ast->ioregs);
  497. pci_iounmap(dev->pdev, ast->regs);
  498. kfree(ast);
  499. return 0;
  500. }
  501. int ast_gem_create(struct drm_device *dev,
  502. u32 size, bool iskernel,
  503. struct drm_gem_object **obj)
  504. {
  505. struct ast_bo *astbo;
  506. int ret;
  507. *obj = NULL;
  508. size = roundup(size, PAGE_SIZE);
  509. if (size == 0)
  510. return -EINVAL;
  511. ret = ast_bo_create(dev, size, 0, 0, &astbo);
  512. if (ret) {
  513. if (ret != -ERESTARTSYS)
  514. DRM_ERROR("failed to allocate GEM object\n");
  515. return ret;
  516. }
  517. *obj = &astbo->gem;
  518. return 0;
  519. }
  520. int ast_dumb_create(struct drm_file *file,
  521. struct drm_device *dev,
  522. struct drm_mode_create_dumb *args)
  523. {
  524. int ret;
  525. struct drm_gem_object *gobj;
  526. u32 handle;
  527. args->pitch = args->width * ((args->bpp + 7) / 8);
  528. args->size = args->pitch * args->height;
  529. ret = ast_gem_create(dev, args->size, false,
  530. &gobj);
  531. if (ret)
  532. return ret;
  533. ret = drm_gem_handle_create(file, gobj, &handle);
  534. drm_gem_object_unreference_unlocked(gobj);
  535. if (ret)
  536. return ret;
  537. args->handle = handle;
  538. return 0;
  539. }
  540. static void ast_bo_unref(struct ast_bo **bo)
  541. {
  542. struct ttm_buffer_object *tbo;
  543. if ((*bo) == NULL)
  544. return;
  545. tbo = &((*bo)->bo);
  546. ttm_bo_unref(&tbo);
  547. *bo = NULL;
  548. }
  549. void ast_gem_free_object(struct drm_gem_object *obj)
  550. {
  551. struct ast_bo *ast_bo = gem_to_ast_bo(obj);
  552. ast_bo_unref(&ast_bo);
  553. }
  554. static inline u64 ast_bo_mmap_offset(struct ast_bo *bo)
  555. {
  556. return drm_vma_node_offset_addr(&bo->bo.vma_node);
  557. }
  558. int
  559. ast_dumb_mmap_offset(struct drm_file *file,
  560. struct drm_device *dev,
  561. uint32_t handle,
  562. uint64_t *offset)
  563. {
  564. struct drm_gem_object *obj;
  565. struct ast_bo *bo;
  566. obj = drm_gem_object_lookup(dev, file, handle);
  567. if (obj == NULL)
  568. return -ENOENT;
  569. bo = gem_to_ast_bo(obj);
  570. *offset = ast_bo_mmap_offset(bo);
  571. drm_gem_object_unreference_unlocked(obj);
  572. return 0;
  573. }