mga_warp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "drmP.h"
  34. #include "drm.h"
  35. #include "mga_drm.h"
  36. #include "mga_drv.h"
  37. #define FIRMWARE_G200 "matrox/g200_warp.fw"
  38. #define FIRMWARE_G400 "matrox/g400_warp.fw"
  39. MODULE_FIRMWARE(FIRMWARE_G200);
  40. MODULE_FIRMWARE(FIRMWARE_G400);
  41. #define MGA_WARP_CODE_ALIGN 256 /* in bytes */
  42. #define WARP_UCODE_SIZE(size) ALIGN(size, MGA_WARP_CODE_ALIGN)
  43. int mga_warp_install_microcode(drm_mga_private_t *dev_priv)
  44. {
  45. unsigned char *vcbase = dev_priv->warp->handle;
  46. unsigned long pcbase = dev_priv->warp->offset;
  47. const char *firmware_name;
  48. struct platform_device *pdev;
  49. const struct firmware *fw = NULL;
  50. const struct ihex_binrec *rec;
  51. unsigned int size;
  52. int n_pipes, where;
  53. int rc = 0;
  54. switch (dev_priv->chipset) {
  55. case MGA_CARD_TYPE_G400:
  56. case MGA_CARD_TYPE_G550:
  57. firmware_name = FIRMWARE_G400;
  58. n_pipes = MGA_MAX_G400_PIPES;
  59. break;
  60. case MGA_CARD_TYPE_G200:
  61. firmware_name = FIRMWARE_G200;
  62. n_pipes = MGA_MAX_G200_PIPES;
  63. break;
  64. default:
  65. return -EINVAL;
  66. }
  67. pdev = platform_device_register_simple("mga_warp", 0, NULL, 0);
  68. if (IS_ERR(pdev)) {
  69. DRM_ERROR("mga: Failed to register microcode\n");
  70. return PTR_ERR(pdev);
  71. }
  72. rc = request_ihex_firmware(&fw, firmware_name, &pdev->dev);
  73. platform_device_unregister(pdev);
  74. if (rc) {
  75. DRM_ERROR("mga: Failed to load microcode \"%s\"\n",
  76. firmware_name);
  77. return rc;
  78. }
  79. size = 0;
  80. where = 0;
  81. for (rec = (const struct ihex_binrec *)fw->data;
  82. rec;
  83. rec = ihex_next_binrec(rec)) {
  84. size += WARP_UCODE_SIZE(be16_to_cpu(rec->len));
  85. where++;
  86. }
  87. if (where != n_pipes) {
  88. DRM_ERROR("mga: Invalid microcode \"%s\"\n", firmware_name);
  89. rc = -EINVAL;
  90. goto out;
  91. }
  92. size = PAGE_ALIGN(size);
  93. DRM_DEBUG("MGA ucode size = %d bytes\n", size);
  94. if (size > dev_priv->warp->size) {
  95. DRM_ERROR("microcode too large! (%u > %lu)\n",
  96. size, dev_priv->warp->size);
  97. rc = -ENOMEM;
  98. goto out;
  99. }
  100. memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
  101. where = 0;
  102. for (rec = (const struct ihex_binrec *)fw->data;
  103. rec;
  104. rec = ihex_next_binrec(rec)) {
  105. unsigned int src_size, dst_size;
  106. DRM_DEBUG(" pcbase = 0x%08lx vcbase = %p\n", pcbase, vcbase);
  107. dev_priv->warp_pipe_phys[where] = pcbase;
  108. src_size = be16_to_cpu(rec->len);
  109. dst_size = WARP_UCODE_SIZE(src_size);
  110. memcpy(vcbase, rec->data, src_size);
  111. pcbase += dst_size;
  112. vcbase += dst_size;
  113. where++;
  114. }
  115. out:
  116. release_firmware(fw);
  117. return rc;
  118. }
  119. #define WMISC_EXPECTED (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
  120. int mga_warp_init(drm_mga_private_t *dev_priv)
  121. {
  122. u32 wmisc;
  123. /* FIXME: Get rid of these damned magic numbers...
  124. */
  125. switch (dev_priv->chipset) {
  126. case MGA_CARD_TYPE_G400:
  127. case MGA_CARD_TYPE_G550:
  128. MGA_WRITE(MGA_WIADDR2, MGA_WMODE_SUSPEND);
  129. MGA_WRITE(MGA_WGETMSB, 0x00000E00);
  130. MGA_WRITE(MGA_WVRTXSZ, 0x00001807);
  131. MGA_WRITE(MGA_WACCEPTSEQ, 0x18000000);
  132. break;
  133. case MGA_CARD_TYPE_G200:
  134. MGA_WRITE(MGA_WIADDR, MGA_WMODE_SUSPEND);
  135. MGA_WRITE(MGA_WGETMSB, 0x1606);
  136. MGA_WRITE(MGA_WVRTXSZ, 7);
  137. break;
  138. default:
  139. return -EINVAL;
  140. }
  141. MGA_WRITE(MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
  142. MGA_WMASTER_ENABLE | MGA_WCACHEFLUSH_ENABLE));
  143. wmisc = MGA_READ(MGA_WMISC);
  144. if (wmisc != WMISC_EXPECTED) {
  145. DRM_ERROR("WARP engine config failed! 0x%x != 0x%x\n",
  146. wmisc, WMISC_EXPECTED);
  147. return -EINVAL;
  148. }
  149. return 0;
  150. }