blob: 722a91b69b0cc55d0ac4658de03e67f912d4d2d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Ben Hutchingsece2be72009-08-23 18:34:25 +010030#include <linux/firmware.h>
31#include <linux/ihex.h>
32#include <linux/platform_device.h>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040033#include <linux/module.h>
Ben Hutchingsece2be72009-08-23 18:34:25 +010034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "drmP.h"
36#include "drm.h"
37#include "mga_drm.h"
38#include "mga_drv.h"
Ben Hutchingsece2be72009-08-23 18:34:25 +010039
40#define FIRMWARE_G200 "matrox/g200_warp.fw"
41#define FIRMWARE_G400 "matrox/g400_warp.fw"
42
43MODULE_FIRMWARE(FIRMWARE_G200);
44MODULE_FIRMWARE(FIRMWARE_G400);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Dave Airlieb5e89ed2005-09-25 14:28:13 +100046#define MGA_WARP_CODE_ALIGN 256 /* in bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Ben Hutchingsece2be72009-08-23 18:34:25 +010048#define WARP_UCODE_SIZE(size) ALIGN(size, MGA_WARP_CODE_ALIGN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +020050int mga_warp_install_microcode(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Ben Hutchingsece2be72009-08-23 18:34:25 +010052 unsigned char *vcbase = dev_priv->warp->handle;
53 unsigned long pcbase = dev_priv->warp->offset;
54 const char *firmware_name;
55 struct platform_device *pdev;
56 const struct firmware *fw = NULL;
57 const struct ihex_binrec *rec;
58 unsigned int size;
59 int n_pipes, where;
60 int rc = 0;
Dave Airlie6795c982005-07-10 18:20:09 +100061
Ben Hutchingsece2be72009-08-23 18:34:25 +010062 switch (dev_priv->chipset) {
63 case MGA_CARD_TYPE_G400:
64 case MGA_CARD_TYPE_G550:
65 firmware_name = FIRMWARE_G400;
66 n_pipes = MGA_MAX_G400_PIPES;
67 break;
68 case MGA_CARD_TYPE_G200:
69 firmware_name = FIRMWARE_G200;
70 n_pipes = MGA_MAX_G200_PIPES;
71 break;
72 default:
73 return -EINVAL;
74 }
75
76 pdev = platform_device_register_simple("mga_warp", 0, NULL, 0);
77 if (IS_ERR(pdev)) {
78 DRM_ERROR("mga: Failed to register microcode\n");
79 return PTR_ERR(pdev);
80 }
81 rc = request_ihex_firmware(&fw, firmware_name, &pdev->dev);
82 platform_device_unregister(pdev);
83 if (rc) {
84 DRM_ERROR("mga: Failed to load microcode \"%s\"\n",
85 firmware_name);
86 return rc;
87 }
88
89 size = 0;
90 where = 0;
91 for (rec = (const struct ihex_binrec *)fw->data;
92 rec;
93 rec = ihex_next_binrec(rec)) {
94 size += WARP_UCODE_SIZE(be16_to_cpu(rec->len));
95 where++;
96 }
97
98 if (where != n_pipes) {
99 DRM_ERROR("mga: Invalid microcode \"%s\"\n", firmware_name);
100 rc = -EINVAL;
101 goto out;
102 }
103 size = PAGE_ALIGN(size);
Dave Airlie6795c982005-07-10 18:20:09 +1000104 DRM_DEBUG("MGA ucode size = %d bytes\n", size);
105 if (size > dev_priv->warp->size) {
106 DRM_ERROR("microcode too large! (%u > %lu)\n",
107 size, dev_priv->warp->size);
Ben Hutchingsece2be72009-08-23 18:34:25 +0100108 rc = -ENOMEM;
109 goto out;
Dave Airlie6795c982005-07-10 18:20:09 +1000110 }
111
Ben Hutchingsece2be72009-08-23 18:34:25 +0100112 memset(dev_priv->warp_pipe_phys, 0, sizeof(dev_priv->warp_pipe_phys));
113
114 where = 0;
115 for (rec = (const struct ihex_binrec *)fw->data;
116 rec;
117 rec = ihex_next_binrec(rec)) {
118 unsigned int src_size, dst_size;
119
120 DRM_DEBUG(" pcbase = 0x%08lx vcbase = %p\n", pcbase, vcbase);
121 dev_priv->warp_pipe_phys[where] = pcbase;
122 src_size = be16_to_cpu(rec->len);
123 dst_size = WARP_UCODE_SIZE(src_size);
124 memcpy(vcbase, rec->data, src_size);
125 pcbase += dst_size;
126 vcbase += dst_size;
127 where++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
Ben Hutchingsece2be72009-08-23 18:34:25 +0100129
130out:
131 release_firmware(fw);
132 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135#define WMISC_EXPECTED (MGA_WUCODECACHE_ENABLE | MGA_WMASTER_ENABLE)
136
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200137int mga_warp_init(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 u32 wmisc;
140
141 /* FIXME: Get rid of these damned magic numbers...
142 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000143 switch (dev_priv->chipset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 case MGA_CARD_TYPE_G400:
Dave Airlie6795c982005-07-10 18:20:09 +1000145 case MGA_CARD_TYPE_G550:
146 MGA_WRITE(MGA_WIADDR2, MGA_WMODE_SUSPEND);
147 MGA_WRITE(MGA_WGETMSB, 0x00000E00);
148 MGA_WRITE(MGA_WVRTXSZ, 0x00001807);
149 MGA_WRITE(MGA_WACCEPTSEQ, 0x18000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 break;
151 case MGA_CARD_TYPE_G200:
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000152 MGA_WRITE(MGA_WIADDR, MGA_WMODE_SUSPEND);
153 MGA_WRITE(MGA_WGETMSB, 0x1606);
154 MGA_WRITE(MGA_WVRTXSZ, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 break;
156 default:
Eric Anholt20caafa2007-08-25 19:22:43 +1000157 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000160 MGA_WRITE(MGA_WMISC, (MGA_WUCODECACHE_ENABLE |
161 MGA_WMASTER_ENABLE | MGA_WCACHEFLUSH_ENABLE));
162 wmisc = MGA_READ(MGA_WMISC);
163 if (wmisc != WMISC_EXPECTED) {
164 DRM_ERROR("WARP engine config failed! 0x%x != 0x%x\n",
165 wmisc, WMISC_EXPECTED);
Eric Anholt20caafa2007-08-25 19:22:43 +1000166 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 }
168
169 return 0;
170}