2 * Copyright 2010 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Alex Deucher
24 #include <linux/firmware.h>
25 #include <linux/platform_device.h>
26 #include <linux/slab.h>
29 #include "radeon_asic.h"
30 #include "radeon_drm.h"
35 #define EVERGREEN_PFP_UCODE_SIZE 1120
36 #define EVERGREEN_PM4_UCODE_SIZE 1376
37 #define EVERGREEN_RLC_UCODE_SIZE 768
38 #define BTC_MC_UCODE_SIZE 6024
41 MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
42 MODULE_FIRMWARE("radeon/BARTS_me.bin");
43 MODULE_FIRMWARE("radeon/BARTS_mc.bin");
44 MODULE_FIRMWARE("radeon/BTC_rlc.bin");
45 MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
46 MODULE_FIRMWARE("radeon/TURKS_me.bin");
47 MODULE_FIRMWARE("radeon/TURKS_mc.bin");
48 MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
49 MODULE_FIRMWARE("radeon/CAICOS_me.bin");
50 MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
52 #define BTC_IO_MC_REGS_SIZE 29
54 static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
55 {0x00000077, 0xff010100},
56 {0x00000078, 0x00000000},
57 {0x00000079, 0x00001434},
58 {0x0000007a, 0xcc08ec08},
59 {0x0000007b, 0x00040000},
60 {0x0000007c, 0x000080c0},
61 {0x0000007d, 0x09000000},
62 {0x0000007e, 0x00210404},
63 {0x00000081, 0x08a8e800},
64 {0x00000082, 0x00030444},
65 {0x00000083, 0x00000000},
66 {0x00000085, 0x00000001},
67 {0x00000086, 0x00000002},
68 {0x00000087, 0x48490000},
69 {0x00000088, 0x20244647},
70 {0x00000089, 0x00000005},
71 {0x0000008b, 0x66030000},
72 {0x0000008c, 0x00006603},
73 {0x0000008d, 0x00000100},
74 {0x0000008f, 0x00001c0a},
75 {0x00000090, 0xff000001},
76 {0x00000094, 0x00101101},
77 {0x00000095, 0x00000fff},
78 {0x00000096, 0x00116fff},
79 {0x00000097, 0x60010000},
80 {0x00000098, 0x10010000},
81 {0x00000099, 0x00006000},
82 {0x0000009a, 0x00001000},
83 {0x0000009f, 0x00946a00}
86 static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
87 {0x00000077, 0xff010100},
88 {0x00000078, 0x00000000},
89 {0x00000079, 0x00001434},
90 {0x0000007a, 0xcc08ec08},
91 {0x0000007b, 0x00040000},
92 {0x0000007c, 0x000080c0},
93 {0x0000007d, 0x09000000},
94 {0x0000007e, 0x00210404},
95 {0x00000081, 0x08a8e800},
96 {0x00000082, 0x00030444},
97 {0x00000083, 0x00000000},
98 {0x00000085, 0x00000001},
99 {0x00000086, 0x00000002},
100 {0x00000087, 0x48490000},
101 {0x00000088, 0x20244647},
102 {0x00000089, 0x00000005},
103 {0x0000008b, 0x66030000},
104 {0x0000008c, 0x00006603},
105 {0x0000008d, 0x00000100},
106 {0x0000008f, 0x00001c0a},
107 {0x00000090, 0xff000001},
108 {0x00000094, 0x00101101},
109 {0x00000095, 0x00000fff},
110 {0x00000096, 0x00116fff},
111 {0x00000097, 0x60010000},
112 {0x00000098, 0x10010000},
113 {0x00000099, 0x00006000},
114 {0x0000009a, 0x00001000},
115 {0x0000009f, 0x00936a00}
118 static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
119 {0x00000077, 0xff010100},
120 {0x00000078, 0x00000000},
121 {0x00000079, 0x00001434},
122 {0x0000007a, 0xcc08ec08},
123 {0x0000007b, 0x00040000},
124 {0x0000007c, 0x000080c0},
125 {0x0000007d, 0x09000000},
126 {0x0000007e, 0x00210404},
127 {0x00000081, 0x08a8e800},
128 {0x00000082, 0x00030444},
129 {0x00000083, 0x00000000},
130 {0x00000085, 0x00000001},
131 {0x00000086, 0x00000002},
132 {0x00000087, 0x48490000},
133 {0x00000088, 0x20244647},
134 {0x00000089, 0x00000005},
135 {0x0000008b, 0x66030000},
136 {0x0000008c, 0x00006603},
137 {0x0000008d, 0x00000100},
138 {0x0000008f, 0x00001c0a},
139 {0x00000090, 0xff000001},
140 {0x00000094, 0x00101101},
141 {0x00000095, 0x00000fff},
142 {0x00000096, 0x00116fff},
143 {0x00000097, 0x60010000},
144 {0x00000098, 0x10010000},
145 {0x00000099, 0x00006000},
146 {0x0000009a, 0x00001000},
147 {0x0000009f, 0x00916a00}
150 int btc_mc_load_microcode(struct radeon_device *rdev)
152 const __be32 *fw_data;
153 u32 mem_type, running, blackout = 0;
160 switch (rdev->family) {
162 io_mc_regs = (u32 *)&barts_io_mc_regs;
165 io_mc_regs = (u32 *)&turks_io_mc_regs;
169 io_mc_regs = (u32 *)&caicos_io_mc_regs;
173 mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
174 running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
176 if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
178 blackout = RREG32(MC_SHARED_BLACKOUT_CNTL);
179 WREG32(MC_SHARED_BLACKOUT_CNTL, 1);
182 /* reset the engine and set to writable */
183 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
184 WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
186 /* load mc io regs */
187 for (i = 0; i < BTC_IO_MC_REGS_SIZE; i++) {
188 WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
189 WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
191 /* load the MC ucode */
192 fw_data = (const __be32 *)rdev->mc_fw->data;
193 for (i = 0; i < BTC_MC_UCODE_SIZE; i++)
194 WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
196 /* put the engine back into the active state */
197 WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
198 WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
199 WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
201 /* wait for training to complete */
202 while (!(RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD))
206 WREG32(MC_SHARED_BLACKOUT_CNTL, blackout);
212 int ni_init_microcode(struct radeon_device *rdev)
214 struct platform_device *pdev;
215 const char *chip_name;
216 const char *rlc_chip_name;
217 size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
223 pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
226 printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
230 switch (rdev->family) {
233 rlc_chip_name = "BTC";
237 rlc_chip_name = "BTC";
240 chip_name = "CAICOS";
241 rlc_chip_name = "BTC";
246 pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
247 me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
248 rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
249 mc_req_size = BTC_MC_UCODE_SIZE * 4;
251 DRM_INFO("Loading %s Microcode\n", chip_name);
253 snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
254 err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
257 if (rdev->pfp_fw->size != pfp_req_size) {
259 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
260 rdev->pfp_fw->size, fw_name);
265 snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
266 err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
269 if (rdev->me_fw->size != me_req_size) {
271 "ni_cp: Bogus length %zu in firmware \"%s\"\n",
272 rdev->me_fw->size, fw_name);
276 snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
277 err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
280 if (rdev->rlc_fw->size != rlc_req_size) {
282 "ni_rlc: Bogus length %zu in firmware \"%s\"\n",
283 rdev->rlc_fw->size, fw_name);
287 snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
288 err = request_firmware(&rdev->mc_fw, fw_name, &pdev->dev);
291 if (rdev->mc_fw->size != mc_req_size) {
293 "ni_mc: Bogus length %zu in firmware \"%s\"\n",
294 rdev->mc_fw->size, fw_name);
298 platform_device_unregister(pdev);
303 "ni_cp: Failed to load firmware \"%s\"\n",
305 release_firmware(rdev->pfp_fw);
307 release_firmware(rdev->me_fw);
309 release_firmware(rdev->rlc_fw);
311 release_firmware(rdev->mc_fw);