Commit 52f97df5da1f94d2b7db1bb53a2f053ae162b649

Authored by Ben Hutchings
Committed by Dave Airlie
1 parent ece2be7993

drm/r128: Use request_firmware() to load CCE microcode

Firmware blob looks like this:
    __be32 datah
    __be32 datal

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Dave Airlie <airlied@redhat.com>

Showing 5 changed files with 210 additions and 50 deletions Side-by-side Diff

drivers/gpu/drm/Kconfig
... ... @@ -36,6 +36,7 @@
36 36 config DRM_R128
37 37 tristate "ATI Rage 128"
38 38 depends on DRM && PCI
  39 + select FW_LOADER
39 40 help
40 41 Choose this option if you have an ATI Rage 128 graphics card. If M
41 42 is selected, the module will be called r128. AGP support for
drivers/gpu/drm/r128/r128_cce.c
... ... @@ -29,6 +29,9 @@
29 29 * Gareth Hughes <gareth@valinux.com>
30 30 */
31 31  
  32 +#include <linux/firmware.h>
  33 +#include <linux/platform_device.h>
  34 +
32 35 #include "drmP.h"
33 36 #include "drm.h"
34 37 #include "r128_drm.h"
35 38  
... ... @@ -36,51 +39,10 @@
36 39  
37 40 #define R128_FIFO_DEBUG 0
38 41  
39   -/* CCE microcode (from ATI) */
40   -static u32 r128_cce_microcode[] = {
41   - 0, 276838400, 0, 268449792, 2, 142, 2, 145, 0, 1076765731, 0,
42   - 1617039951, 0, 774592877, 0, 1987540286, 0, 2307490946U, 0,
43   - 599558925, 0, 589505315, 0, 596487092, 0, 589505315, 1,
44   - 11544576, 1, 206848, 1, 311296, 1, 198656, 2, 912273422, 11,
45   - 262144, 0, 0, 1, 33559837, 1, 7438, 1, 14809, 1, 6615, 12, 28,
46   - 1, 6614, 12, 28, 2, 23, 11, 18874368, 0, 16790922, 1, 409600, 9,
47   - 30, 1, 147854772, 16, 420483072, 3, 8192, 0, 10240, 1, 198656,
48   - 1, 15630, 1, 51200, 10, 34858, 9, 42, 1, 33559823, 2, 10276, 1,
49   - 15717, 1, 15718, 2, 43, 1, 15936948, 1, 570480831, 1, 14715071,
50   - 12, 322123831, 1, 33953125, 12, 55, 1, 33559908, 1, 15718, 2,
51   - 46, 4, 2099258, 1, 526336, 1, 442623, 4, 4194365, 1, 509952, 1,
52   - 459007, 3, 0, 12, 92, 2, 46, 12, 176, 1, 15734, 1, 206848, 1,
53   - 18432, 1, 133120, 1, 100670734, 1, 149504, 1, 165888, 1,
54   - 15975928, 1, 1048576, 6, 3145806, 1, 15715, 16, 2150645232U, 2,
55   - 268449859, 2, 10307, 12, 176, 1, 15734, 1, 15735, 1, 15630, 1,
56   - 15631, 1, 5253120, 6, 3145810, 16, 2150645232U, 1, 15864, 2, 82,
57   - 1, 343310, 1, 1064207, 2, 3145813, 1, 15728, 1, 7817, 1, 15729,
58   - 3, 15730, 12, 92, 2, 98, 1, 16168, 1, 16167, 1, 16002, 1, 16008,
59   - 1, 15974, 1, 15975, 1, 15990, 1, 15976, 1, 15977, 1, 15980, 0,
60   - 15981, 1, 10240, 1, 5253120, 1, 15720, 1, 198656, 6, 110, 1,
61   - 180224, 1, 103824738, 2, 112, 2, 3145839, 0, 536885440, 1,
62   - 114880, 14, 125, 12, 206975, 1, 33559995, 12, 198784, 0,
63   - 33570236, 1, 15803, 0, 15804, 3, 294912, 1, 294912, 3, 442370,
64   - 1, 11544576, 0, 811612160, 1, 12593152, 1, 11536384, 1,
65   - 14024704, 7, 310382726, 0, 10240, 1, 14796, 1, 14797, 1, 14793,
66   - 1, 14794, 0, 14795, 1, 268679168, 1, 9437184, 1, 268449792, 1,
67   - 198656, 1, 9452827, 1, 1075854602, 1, 1075854603, 1, 557056, 1,
68   - 114880, 14, 159, 12, 198784, 1, 1109409213, 12, 198783, 1,
69   - 1107312059, 12, 198784, 1, 1109409212, 2, 162, 1, 1075854781, 1,
70   - 1073757627, 1, 1075854780, 1, 540672, 1, 10485760, 6, 3145894,
71   - 16, 274741248, 9, 168, 3, 4194304, 3, 4209949, 0, 0, 0, 256, 14,
72   - 174, 1, 114857, 1, 33560007, 12, 176, 0, 10240, 1, 114858, 1,
73   - 33560018, 1, 114857, 3, 33560007, 1, 16008, 1, 114874, 1,
74   - 33560360, 1, 114875, 1, 33560154, 0, 15963, 0, 256, 0, 4096, 1,
75   - 409611, 9, 188, 0, 10240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
78   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
79   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81   - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
82   -};
  42 +#define FIRMWARE_NAME "r128/r128_cce.bin"
83 43  
  44 +MODULE_FIRMWARE(FIRMWARE_NAME);
  45 +
84 46 static int R128_READ_PLL(struct drm_device * dev, int addr)
85 47 {
86 48 drm_r128_private_t *dev_priv = dev->dev_private;
87 49  
88 50  
89 51  
90 52  
91 53  
92 54  
... ... @@ -176,20 +138,50 @@
176 138 */
177 139  
178 140 /* Load the microcode for the CCE */
179   -static void r128_cce_load_microcode(drm_r128_private_t * dev_priv)
  141 +static int r128_cce_load_microcode(drm_r128_private_t *dev_priv)
180 142 {
181   - int i;
  143 + struct platform_device *pdev;
  144 + const struct firmware *fw;
  145 + const __be32 *fw_data;
  146 + int rc, i;
182 147  
183 148 DRM_DEBUG("\n");
184 149  
  150 + pdev = platform_device_register_simple("r128_cce", 0, NULL, 0);
  151 + if (IS_ERR(pdev)) {
  152 + printk(KERN_ERR "r128_cce: Failed to register firmware\n");
  153 + return PTR_ERR(pdev);
  154 + }
  155 + rc = request_firmware(&fw, FIRMWARE_NAME, &pdev->dev);
  156 + platform_device_unregister(pdev);
  157 + if (rc) {
  158 + printk(KERN_ERR "r128_cce: Failed to load firmware \"%s\"\n",
  159 + FIRMWARE_NAME);
  160 + return rc;
  161 + }
  162 +
  163 + if (fw->size != 256 * 8) {
  164 + printk(KERN_ERR
  165 + "r128_cce: Bogus length %zu in firmware \"%s\"\n",
  166 + fw->size, FIRMWARE_NAME);
  167 + rc = -EINVAL;
  168 + goto out_release;
  169 + }
  170 +
185 171 r128_do_wait_for_idle(dev_priv);
186 172  
  173 + fw_data = (const __be32 *)fw->data;
187 174 R128_WRITE(R128_PM4_MICROCODE_ADDR, 0);
188 175 for (i = 0; i < 256; i++) {
189   - R128_WRITE(R128_PM4_MICROCODE_DATAH, r128_cce_microcode[i * 2]);
  176 + R128_WRITE(R128_PM4_MICROCODE_DATAH,
  177 + be32_to_cpup(&fw_data[i * 2]));
190 178 R128_WRITE(R128_PM4_MICROCODE_DATAL,
191   - r128_cce_microcode[i * 2 + 1]);
  179 + be32_to_cpup(&fw_data[i * 2 + 1]));
192 180 }
  181 +
  182 +out_release:
  183 + release_firmware(fw);
  184 + return rc;
193 185 }
194 186  
195 187 /* Flush any pending commands to the CCE. This should only be used just
... ... @@ -350,6 +342,7 @@
350 342 static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
351 343 {
352 344 drm_r128_private_t *dev_priv;
  345 + int rc;
353 346  
354 347 DRM_DEBUG("\n");
355 348  
356 349  
... ... @@ -575,13 +568,18 @@
575 568 #endif
576 569  
577 570 r128_cce_init_ring_buffer(dev, dev_priv);
578   - r128_cce_load_microcode(dev_priv);
  571 + rc = r128_cce_load_microcode(dev_priv);
579 572  
580 573 dev->dev_private = (void *)dev_priv;
581 574  
582 575 r128_do_engine_reset(dev);
583 576  
584   - return 0;
  577 + if (rc) {
  578 + DRM_ERROR("Failed to load firmware!\n");
  579 + r128_do_cleanup_cce(dev);
  580 + }
  581 +
  582 + return rc;
585 583 }
586 584  
587 585 int r128_do_cleanup_cce(struct drm_device * dev)
... ... @@ -43,6 +43,7 @@
43 43 cxgb3/t3c_psram-1.1.0.bin \
44 44 cxgb3/t3fw-7.4.0.bin
45 45 fw-shipped-$(CONFIG_DRM_MGA) += matrox/g200_warp.fw matrox/g400_warp.fw
  46 +fw-shipped-$(CONFIG_DRM_R128) += r128/r128_cce.bin
46 47 fw-shipped-$(CONFIG_DVB_AV7110) += av7110/bootcode.bin
47 48 fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin
48 49 fw-shipped-$(CONFIG_E100) += e100/d101m_ucode.bin e100/d101s_ucode.bin \
... ... @@ -730,4 +730,35 @@
730 730 Found in hex form in kernel source.
731 731  
732 732 --------------------------------------------------------------------------
  733 +
  734 +Driver: r128 - ATI Rage 128
  735 +
  736 +File: r128/r128_cce.bin
  737 +
  738 +Licence:
  739 +
  740 +Copyright 2000 Advanced Micro Devices, Inc.
  741 +
  742 + * Permission is hereby granted, free of charge, to any person obtaining a
  743 + * copy of this software and associated documentation files (the "Software"),
  744 + * to deal in the Software without restriction, including without limitation
  745 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  746 + * and/or sell copies of the Software, and to permit persons to whom the
  747 + * Software is furnished to do so, subject to the following conditions:
  748 + *
  749 + * The above copyright notice and this permission notice (including the next
  750 + * paragraph) shall be included in all copies or substantial portions of the
  751 + * Software.
  752 + *
  753 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  754 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  755 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  756 + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  757 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  758 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  759 + * DEALINGS IN THE SOFTWARE.
  760 +
  761 +Found in decimal form in kernel source.
  762 +
  763 +--------------------------------------------------------------------------
firmware/r128/r128_cce.bin.ihex
  1 +:1000000000000000108038000000000010003800E0
  2 +:10001000000000020000008E0000000200000091BD
  3 +:1000200000000000402E2423000000006062124FF8
  4 +:10003000000000002E2B596D000000007677753E01
  5 +:1000400000000000898984820000000023BC8B0D21
  6 +:10005000000000002323232300000000238DABB405
  7 +:1000600000000000232323230000000100B028002B
  8 +:100070000000000100032800000000010004C0008F
  9 +:100080000000000100030800000000023660300E8E
  10 +:100090000000000B00040000000000000000000051
  11 +:1000A000000000010200151D0000000100001D0EEF
  12 +:1000B00000000001000039D900000001000019D73C
  13 +:1000C0000000000C0000001C00000001000019D618
  14 +:1000D0000000000C0000001C0000000200000017DF
  15 +:1000E0000000000B01200000000000000100358A24
  16 +:1000F0000000000100064000000000090000001E92
  17 +:100100000000000108D015B4000000101910100004
  18 +:100110000000000300002000000000000000280094
  19 +:1001200000000001000308000000000100003D0E77
  20 +:10013000000000010000C8000000000A0000882A3A
  21 +:10014000000000090000002A000000010200150F55
  22 +:1001500000000002000028240000000100003D65AE
  23 +:100160000000000100003D66000000020000002BBE
  24 +:100170000000000100F32DB4000000012200D8BFF0
  25 +:100180000000000100E088BF0000000C1333383786
  26 +:1001900000000001020615650000000C0000003799
  27 +:1001A00000000001020015640000000100003D662F
  28 +:1001B000000000020000002E000000040020083AA9
  29 +:1001C0000000000100080800000000010006C0FF58
  30 +:1001D000000000040040003D000000010007C800CE
  31 +:1001E00000000001000700FF000000030000000005
  32 +:1001F0000000000C0000005C000000020000002E67
  33 +:100200000000000C000000B00000000100003D767E
  34 +:100210000000000100032800000000010000480069
  35 +:1002200000000001000208000000000106001D0E91
  36 +:1002300000000001000248000000000100028800E8
  37 +:100240000000000100F3C5F80000000100100000EC
  38 +:10025000000000060030004E0000000100003D6379
  39 +:100260000000001080303DF0000000021000384314
  40 +:1002700000000002000028430000000C000000B055
  41 +:100280000000000100003D760000000100003D7705
  42 +:100290000000000100003D0E0000000100003D0FC5
  43 +:1002A000000000010050280000000006003000524D
  44 +:1002B0000000001080303DF00000000100003DF81B
  45 +:1002C00000000002000000520000000100053D0E89
  46 +:1002D0000000000100103D0F00000002003000553A
  47 +:1002E0000000000100003D700000000100001E89B8
  48 +:1002F0000000000100003D710000000300003D729D
  49 +:100300000000000C0000005C000000020000006221
  50 +:100310000000000100003F280000000100003F270E
  51 +:100320000000000100003E820000000100003E8845
  52 +:100330000000000100003E660000000100003E6772
  53 +:100340000000000100003E760000000100003E6851
  54 +:100350000000000100003E690000000100003E6C4A
  55 +:100360000000000000003E6D0000000100002800B9
  56 +:1003700000000001005028000000000100003D685E
  57 +:100380000000000100030800000000060000006EED
  58 +:10039000000000010002C0000000000106303D62C4
  59 +:1003A0000000000200000070000000020030006F3A
  60 +:1003B00000000000200038C0000000010001C0C0A3
  61 +:1003C0000000000E0000007D0000000C0003287FEC
  62 +:1003D00000000001020015BB0000000C00030880B3
  63 +:1003E0000000000002003DBC0000000100003DBB19
  64 +:1003F0000000000000003DBC00000003000480007D
  65 +:100400000000000100048000000000030006C0029C
  66 +:100410000000000100B0280000000000306038003B
  67 +:100420000000000100C028000000000100B008002A
  68 +:100430000000000100D600000000000712801086B6
  69 +:10044000000000000000280000000001000039CC7E
  70 +:1004500000000001000039CD00000001000039C992
  71 +:1004600000000001000039CA00000000000039CB84
  72 +:10047000000000011003B80000000001009000001F
  73 +:100480000000000110003800000000010003080017
  74 +:100490000000000100903D1B0000000140203D0ACB
  75 +:1004A0000000000140203D0B00000001000880001A
  76 +:1004B000000000010001C0C00000000E0000009F0D
  77 +:1004C0000000000C000308800000000142203DBD38
  78 +:1004D0000000000C0003087F0000000142003DBB4B
  79 +:1004E0000000000C000308800000000142203DBC19
  80 +:1004F00000000002000000A20000000140203DBDFD
  81 +:100500000000000140003DBB0000000140203DBC58
  82 +:1005100000000001000840000000000100A00000F1
  83 +:1005200000000006003000A6000000101060380037
  84 +:1005300000000009000000A80000000300400000C7
  85 +:100540000000000300403D1D00000000000000000E
  86 +:1005500000000000000001000000000E000000AEDE
  87 +:10056000000000010001C0A900000001020015C741
  88 +:100570000000000C000000B0000000000000280097
  89 +:10058000000000010001C0AA00000001020015D215
  90 +:10059000000000010001C0A900000003020015C70F
  91 +:1005A0000000000100003E88000000010001C0BA08
  92 +:1005B0000000000102001728000000010001C0BB7C
  93 +:1005C000000000010200165A0000000000003E5B1F
  94 +:1005D000000000000000010000000000000010000A
  95 +:1005E000000000010006400B00000009000000BCF4
  96 +:1005F00000000000000028000000000000000000D3
  97 +:1006000000000000000000000000000000000000EA
  98 +:1006100000000000000000000000000000000000DA
  99 +:1006200000000000000000000000000000000000CA
  100 +:1006300000000000000000000000000000000000BA
  101 +:1006400000000000000000000000000000000000AA
  102 +:10065000000000000000000000000000000000009A
  103 +:10066000000000000000000000000000000000008A
  104 +:10067000000000000000000000000000000000007A
  105 +:10068000000000000000000000000000000000006A
  106 +:10069000000000000000000000000000000000005A
  107 +:1006A000000000000000000000000000000000004A
  108 +:1006B000000000000000000000000000000000003A
  109 +:1006C000000000000000000000000000000000002A
  110 +:1006D000000000000000000000000000000000001A
  111 +:1006E000000000000000000000000000000000000A
  112 +:1006F00000000000000000000000000000000000FA
  113 +:1007000000000000000000000000000000000000E9
  114 +:1007100000000000000000000000000000000000D9
  115 +:1007200000000000000000000000000000000000C9
  116 +:1007300000000000000000000000000000000000B9
  117 +:1007400000000000000000000000000000000000A9
  118 +:100750000000000000000000000000000000000099
  119 +:100760000000000000000000000000000000000089
  120 +:100770000000000000000000000000000000000079
  121 +:100780000000000000000000000000000000000069
  122 +:100790000000000000000000000000000000000059
  123 +:1007A0000000000000000000000000000000000049
  124 +:1007B0000000000000000000000000000000000039
  125 +:1007C0000000000000000000000000000000000029
  126 +:1007D0000000000000000000000000000000000019
  127 +:1007E0000000000000000000000000000000000009
  128 +:1007F00000000000000000000000000000000000F9
  129 +:00000001FF