mga_warp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* mga_warp.c -- Matrox G200/G400 WARP engine management -*- linux-c -*-
  2. * Created: Thu Jan 11 21:29:32 2001 by gareth@valinux.com
  3. *
  4. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the next
  15. * paragraph) shall be included in all copies or substantial portions of the
  16. * Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Authors:
  27. * Gareth Hughes <gareth@valinux.com>
  28. */
  29. #include <linux/firmware.h>
  30. #include <linux/ihex.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/module.h>
  33. #include <drm/drmP.h>
  34. #include <drm/mga_drm.h>
  35. #include "mga_drv.h"
  36. #define FIRMWARE_G200 "/*(DEBLOBBED)*/"
  37. #define FIRMWARE_G400 "/*(DEBLOBBED)*/"
  38. /*(DEBLOBBED)*/
  39. #define MGA_WARP_CODE_ALIGN 256 /* in bytes */
  40. #define WARP_UCODE_SIZE(size) ALIGN(size, MGA_WARP_CODE_ALIGN)
  41. int mga_warp_install_microcode(drm_mga_private_t *dev_priv)
  42. {
  43. unsigned char *vcbase = dev_priv->warp->handle;
  44. unsigned long pcbase = dev_priv->warp->offset;
  45. const char *firmware_name;
  46. struct platform_device *pdev;
  47. const struct firmware *fw = NULL;
  48. const struct ihex_binrec *rec;
  49. unsigned int size;
  50. int n_pipes, where;
  51. int rc = 0;
  52. switch (dev_priv->chipset) {
  53. case MGA_CARD_TYPE_G400:
  54. case MGA_CARD_TYPE_G550:
  55. firmware_name = FIRMWARE_G400;
  56. n_pipes = MGA_MAX_G400_PIPES;
  57. break;
  58. case MGA_CARD_TYPE_G200:
  59. firmware_name = FIRMWARE_G200;
  60. n_pipes = MGA_MAX_G200_PIPES;
  61. break;
  62. default:
  63. return -EINVAL;
  64. }
  65. pdev = platform_device_register_simple("mga_warp", 0, NULL, 0);
  66. if (IS_ERR(pdev)) {
  67. DRM_ERROR("mga: Failed to register microcode\n");
  68. return PTR_ERR(pdev);
  69. }
  70. rc = reject_firmware(&fw, firmware_name, &pdev->dev);
  71. platform_device_unregister(pdev);
  72. if (rc) {
  73. DRM_ERROR("mga: Failed to load microcode \"%s\"\n",
  74. firmware_name);
  75. return rc;
  76. }
  77. size = 0;
  78. where = 0;
  79. for (rec = (const struct ihex_binrec *)fw->data;
  80. rec;
  81. rec = ihex_next_binrec(rec)) {
  82. size += WARP_UCODE_SIZE(be16_to_cpu(rec->len));
  83. where++;
  84. }
  85. if (where != n_pipes) {
  86. DRM_ERROR("mga: Invalid microcode \"%s\"\n", firmware_name);
  87. rc = -EINVAL;
  88. goto out;
  89. }
  90. size = PAGE_ALIGN(size);
  91. DRM_DEBUG("MGA ucode size = %d bytes\n", size);
  92. if (size > dev_priv->warp->size) {
  93. DRM_ERROR("microcode too large! (%u > %lu)\n",
  94. size, dev_priv->warp->size);
  95. rc = -ENOMEM;
  96. goto out;
  97. }
  98. memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
  99. where = 0;
  100. for (rec = (const struct ihex_binrec *)fw->data;
  101. rec;
  102. rec = ihex_next_binrec(rec)) {
  103. unsigned int src_size, dst_size;
  104. DRM_DEBUG(" pcbase = 0x%08lx vcbase = %p\n", pcbase, vcbase);
  105. dev_priv->warp_pipe_phys[where] = pcbase;
  106. src_size = be16_to_cpu(rec->len);
  107. dst_size = WARP_UCODE_SIZE(src_size);
  108. memcpy(vcbase, rec->data, src_size);
  109. pcbase += dst_size;
  110. vcbase += dst_size;
  111. where++;
  112. }
  113. out:
  114. release_firmware(fw);
  115. return rc;
  116. }
  117. #define WMISC_EXPECTED (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
  118. int mga_warp_init(drm_mga_private_t *dev_priv)
  119. {
  120. u32 wmisc;
  121. /* FIXME: Get rid of these damned magic numbers...
  122. */
  123. switch (dev_priv->chipset) {
  124. case MGA_CARD_TYPE_G400:
  125. case MGA_CARD_TYPE_G550:
  126. MGA_WRITE(MGA_WIADDR2, MGA_WMODE_SUSPEND);
  127. MGA_WRITE(MGA_WGETMSB, 0x00000E00);
  128. MGA_WRITE(MGA_WVRTXSZ, 0x00001807);
  129. MGA_WRITE(MGA_WACCEPTSEQ, 0x18000000);
  130. break;
  131. case MGA_CARD_TYPE_G200:
  132. MGA_WRITE(MGA_WIADDR, MGA_WMODE_SUSPEND);
  133. MGA_WRITE(MGA_WGETMSB, 0x1606);
  134. MGA_WRITE(MGA_WVRTXSZ, 7);
  135. break;
  136. default:
  137. return -EINVAL;
  138. }
  139. MGA_WRITE(MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
  140. MGA_WMASTER_ENABLE | MGA_WCACHEFLUSH_ENABLE));
  141. wmisc = MGA_READ(MGA_WMISC);
  142. if (wmisc != WMISC_EXPECTED) {
  143. DRM_ERROR("WARP engine config failed! 0x%x != 0x%x\n",
  144. wmisc, WMISC_EXPECTED);
  145. return -EINVAL;
  146. }
  147. return 0;
  148. }