mga_warp.c 4.7 KB

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