mga_warp.c 4.7 KB

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