1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2008 Advanced Micro Devices, Inc.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun * all copies or substantial portions of the Software.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * Author: Stanislaw Skowronek
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include <linux/module.h>
26*4882a593Smuzhiyun #include <linux/sched.h>
27*4882a593Smuzhiyun #include <linux/slab.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include <asm/unaligned.h>
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <drm/drm_device.h>
32*4882a593Smuzhiyun #include <drm/drm_util.h>
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define ATOM_DEBUG
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include "atom.h"
37*4882a593Smuzhiyun #include "atom-names.h"
38*4882a593Smuzhiyun #include "atom-bits.h"
39*4882a593Smuzhiyun #include "radeon.h"
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #define ATOM_COND_ABOVE 0
42*4882a593Smuzhiyun #define ATOM_COND_ABOVEOREQUAL 1
43*4882a593Smuzhiyun #define ATOM_COND_ALWAYS 2
44*4882a593Smuzhiyun #define ATOM_COND_BELOW 3
45*4882a593Smuzhiyun #define ATOM_COND_BELOWOREQUAL 4
46*4882a593Smuzhiyun #define ATOM_COND_EQUAL 5
47*4882a593Smuzhiyun #define ATOM_COND_NOTEQUAL 6
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #define ATOM_PORT_ATI 0
50*4882a593Smuzhiyun #define ATOM_PORT_PCI 1
51*4882a593Smuzhiyun #define ATOM_PORT_SYSIO 2
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #define ATOM_UNIT_MICROSEC 0
54*4882a593Smuzhiyun #define ATOM_UNIT_MILLISEC 1
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun #define PLL_INDEX 2
57*4882a593Smuzhiyun #define PLL_DATA 3
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun typedef struct {
60*4882a593Smuzhiyun struct atom_context *ctx;
61*4882a593Smuzhiyun uint32_t *ps, *ws;
62*4882a593Smuzhiyun int ps_shift;
63*4882a593Smuzhiyun uint16_t start;
64*4882a593Smuzhiyun unsigned last_jump;
65*4882a593Smuzhiyun unsigned long last_jump_jiffies;
66*4882a593Smuzhiyun bool abort;
67*4882a593Smuzhiyun } atom_exec_context;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun int atom_debug = 0;
70*4882a593Smuzhiyun static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params);
71*4882a593Smuzhiyun int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params);
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static uint32_t atom_arg_mask[8] = {
74*4882a593Smuzhiyun 0xFFFFFFFF, 0x0000FFFF, 0x00FFFF00, 0xFFFF0000,
75*4882a593Smuzhiyun 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun static int atom_arg_shift[8] = { 0, 0, 8, 16, 0, 8, 16, 24 };
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun static int atom_dst_to_src[8][4] = {
80*4882a593Smuzhiyun /* translate destination alignment field to the source alignment encoding */
81*4882a593Smuzhiyun {0, 0, 0, 0},
82*4882a593Smuzhiyun {1, 2, 3, 0},
83*4882a593Smuzhiyun {1, 2, 3, 0},
84*4882a593Smuzhiyun {1, 2, 3, 0},
85*4882a593Smuzhiyun {4, 5, 6, 7},
86*4882a593Smuzhiyun {4, 5, 6, 7},
87*4882a593Smuzhiyun {4, 5, 6, 7},
88*4882a593Smuzhiyun {4, 5, 6, 7},
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun static int atom_def_dst[8] = { 0, 0, 1, 2, 0, 1, 2, 3 };
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun static int debug_depth = 0;
93*4882a593Smuzhiyun #ifdef ATOM_DEBUG
debug_print_spaces(int n)94*4882a593Smuzhiyun static void debug_print_spaces(int n)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun while (n--)
97*4882a593Smuzhiyun printk(" ");
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #define DEBUG(...) do if (atom_debug) { printk(KERN_DEBUG __VA_ARGS__); } while (0)
101*4882a593Smuzhiyun #define SDEBUG(...) do if (atom_debug) { printk(KERN_DEBUG); debug_print_spaces(debug_depth); printk(__VA_ARGS__); } while (0)
102*4882a593Smuzhiyun #else
103*4882a593Smuzhiyun #define DEBUG(...) do { } while (0)
104*4882a593Smuzhiyun #define SDEBUG(...) do { } while (0)
105*4882a593Smuzhiyun #endif
106*4882a593Smuzhiyun
atom_iio_execute(struct atom_context * ctx,int base,uint32_t index,uint32_t data)107*4882a593Smuzhiyun static uint32_t atom_iio_execute(struct atom_context *ctx, int base,
108*4882a593Smuzhiyun uint32_t index, uint32_t data)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun struct radeon_device *rdev = ctx->card->dev->dev_private;
111*4882a593Smuzhiyun uint32_t temp = 0xCDCDCDCD;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun while (1)
114*4882a593Smuzhiyun switch (CU8(base)) {
115*4882a593Smuzhiyun case ATOM_IIO_NOP:
116*4882a593Smuzhiyun base++;
117*4882a593Smuzhiyun break;
118*4882a593Smuzhiyun case ATOM_IIO_READ:
119*4882a593Smuzhiyun temp = ctx->card->ioreg_read(ctx->card, CU16(base + 1));
120*4882a593Smuzhiyun base += 3;
121*4882a593Smuzhiyun break;
122*4882a593Smuzhiyun case ATOM_IIO_WRITE:
123*4882a593Smuzhiyun if (rdev->family == CHIP_RV515)
124*4882a593Smuzhiyun (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1));
125*4882a593Smuzhiyun ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp);
126*4882a593Smuzhiyun base += 3;
127*4882a593Smuzhiyun break;
128*4882a593Smuzhiyun case ATOM_IIO_CLEAR:
129*4882a593Smuzhiyun temp &=
130*4882a593Smuzhiyun ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
131*4882a593Smuzhiyun CU8(base + 2));
132*4882a593Smuzhiyun base += 3;
133*4882a593Smuzhiyun break;
134*4882a593Smuzhiyun case ATOM_IIO_SET:
135*4882a593Smuzhiyun temp |=
136*4882a593Smuzhiyun (0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base +
137*4882a593Smuzhiyun 2);
138*4882a593Smuzhiyun base += 3;
139*4882a593Smuzhiyun break;
140*4882a593Smuzhiyun case ATOM_IIO_MOVE_INDEX:
141*4882a593Smuzhiyun temp &=
142*4882a593Smuzhiyun ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
143*4882a593Smuzhiyun CU8(base + 3));
144*4882a593Smuzhiyun temp |=
145*4882a593Smuzhiyun ((index >> CU8(base + 2)) &
146*4882a593Smuzhiyun (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base +
147*4882a593Smuzhiyun 3);
148*4882a593Smuzhiyun base += 4;
149*4882a593Smuzhiyun break;
150*4882a593Smuzhiyun case ATOM_IIO_MOVE_DATA:
151*4882a593Smuzhiyun temp &=
152*4882a593Smuzhiyun ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
153*4882a593Smuzhiyun CU8(base + 3));
154*4882a593Smuzhiyun temp |=
155*4882a593Smuzhiyun ((data >> CU8(base + 2)) &
156*4882a593Smuzhiyun (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base +
157*4882a593Smuzhiyun 3);
158*4882a593Smuzhiyun base += 4;
159*4882a593Smuzhiyun break;
160*4882a593Smuzhiyun case ATOM_IIO_MOVE_ATTR:
161*4882a593Smuzhiyun temp &=
162*4882a593Smuzhiyun ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
163*4882a593Smuzhiyun CU8(base + 3));
164*4882a593Smuzhiyun temp |=
165*4882a593Smuzhiyun ((ctx->
166*4882a593Smuzhiyun io_attr >> CU8(base + 2)) & (0xFFFFFFFF >> (32 -
167*4882a593Smuzhiyun CU8
168*4882a593Smuzhiyun (base
169*4882a593Smuzhiyun +
170*4882a593Smuzhiyun 1))))
171*4882a593Smuzhiyun << CU8(base + 3);
172*4882a593Smuzhiyun base += 4;
173*4882a593Smuzhiyun break;
174*4882a593Smuzhiyun case ATOM_IIO_END:
175*4882a593Smuzhiyun return temp;
176*4882a593Smuzhiyun default:
177*4882a593Smuzhiyun pr_info("Unknown IIO opcode\n");
178*4882a593Smuzhiyun return 0;
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun
atom_get_src_int(atom_exec_context * ctx,uint8_t attr,int * ptr,uint32_t * saved,int print)182*4882a593Smuzhiyun static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr,
183*4882a593Smuzhiyun int *ptr, uint32_t *saved, int print)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun uint32_t idx, val = 0xCDCDCDCD, align, arg;
186*4882a593Smuzhiyun struct atom_context *gctx = ctx->ctx;
187*4882a593Smuzhiyun arg = attr & 7;
188*4882a593Smuzhiyun align = (attr >> 3) & 7;
189*4882a593Smuzhiyun switch (arg) {
190*4882a593Smuzhiyun case ATOM_ARG_REG:
191*4882a593Smuzhiyun idx = U16(*ptr);
192*4882a593Smuzhiyun (*ptr) += 2;
193*4882a593Smuzhiyun if (print)
194*4882a593Smuzhiyun DEBUG("REG[0x%04X]", idx);
195*4882a593Smuzhiyun idx += gctx->reg_block;
196*4882a593Smuzhiyun switch (gctx->io_mode) {
197*4882a593Smuzhiyun case ATOM_IO_MM:
198*4882a593Smuzhiyun val = gctx->card->reg_read(gctx->card, idx);
199*4882a593Smuzhiyun break;
200*4882a593Smuzhiyun case ATOM_IO_PCI:
201*4882a593Smuzhiyun pr_info("PCI registers are not implemented\n");
202*4882a593Smuzhiyun return 0;
203*4882a593Smuzhiyun case ATOM_IO_SYSIO:
204*4882a593Smuzhiyun pr_info("SYSIO registers are not implemented\n");
205*4882a593Smuzhiyun return 0;
206*4882a593Smuzhiyun default:
207*4882a593Smuzhiyun if (!(gctx->io_mode & 0x80)) {
208*4882a593Smuzhiyun pr_info("Bad IO mode\n");
209*4882a593Smuzhiyun return 0;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun if (!gctx->iio[gctx->io_mode & 0x7F]) {
212*4882a593Smuzhiyun pr_info("Undefined indirect IO read method %d\n",
213*4882a593Smuzhiyun gctx->io_mode & 0x7F);
214*4882a593Smuzhiyun return 0;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun val =
217*4882a593Smuzhiyun atom_iio_execute(gctx,
218*4882a593Smuzhiyun gctx->iio[gctx->io_mode & 0x7F],
219*4882a593Smuzhiyun idx, 0);
220*4882a593Smuzhiyun }
221*4882a593Smuzhiyun break;
222*4882a593Smuzhiyun case ATOM_ARG_PS:
223*4882a593Smuzhiyun idx = U8(*ptr);
224*4882a593Smuzhiyun (*ptr)++;
225*4882a593Smuzhiyun /* get_unaligned_le32 avoids unaligned accesses from atombios
226*4882a593Smuzhiyun * tables, noticed on a DEC Alpha. */
227*4882a593Smuzhiyun val = get_unaligned_le32((u32 *)&ctx->ps[idx]);
228*4882a593Smuzhiyun if (print)
229*4882a593Smuzhiyun DEBUG("PS[0x%02X,0x%04X]", idx, val);
230*4882a593Smuzhiyun break;
231*4882a593Smuzhiyun case ATOM_ARG_WS:
232*4882a593Smuzhiyun idx = U8(*ptr);
233*4882a593Smuzhiyun (*ptr)++;
234*4882a593Smuzhiyun if (print)
235*4882a593Smuzhiyun DEBUG("WS[0x%02X]", idx);
236*4882a593Smuzhiyun switch (idx) {
237*4882a593Smuzhiyun case ATOM_WS_QUOTIENT:
238*4882a593Smuzhiyun val = gctx->divmul[0];
239*4882a593Smuzhiyun break;
240*4882a593Smuzhiyun case ATOM_WS_REMAINDER:
241*4882a593Smuzhiyun val = gctx->divmul[1];
242*4882a593Smuzhiyun break;
243*4882a593Smuzhiyun case ATOM_WS_DATAPTR:
244*4882a593Smuzhiyun val = gctx->data_block;
245*4882a593Smuzhiyun break;
246*4882a593Smuzhiyun case ATOM_WS_SHIFT:
247*4882a593Smuzhiyun val = gctx->shift;
248*4882a593Smuzhiyun break;
249*4882a593Smuzhiyun case ATOM_WS_OR_MASK:
250*4882a593Smuzhiyun val = 1 << gctx->shift;
251*4882a593Smuzhiyun break;
252*4882a593Smuzhiyun case ATOM_WS_AND_MASK:
253*4882a593Smuzhiyun val = ~(1 << gctx->shift);
254*4882a593Smuzhiyun break;
255*4882a593Smuzhiyun case ATOM_WS_FB_WINDOW:
256*4882a593Smuzhiyun val = gctx->fb_base;
257*4882a593Smuzhiyun break;
258*4882a593Smuzhiyun case ATOM_WS_ATTRIBUTES:
259*4882a593Smuzhiyun val = gctx->io_attr;
260*4882a593Smuzhiyun break;
261*4882a593Smuzhiyun case ATOM_WS_REGPTR:
262*4882a593Smuzhiyun val = gctx->reg_block;
263*4882a593Smuzhiyun break;
264*4882a593Smuzhiyun default:
265*4882a593Smuzhiyun val = ctx->ws[idx];
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun break;
268*4882a593Smuzhiyun case ATOM_ARG_ID:
269*4882a593Smuzhiyun idx = U16(*ptr);
270*4882a593Smuzhiyun (*ptr) += 2;
271*4882a593Smuzhiyun if (print) {
272*4882a593Smuzhiyun if (gctx->data_block)
273*4882a593Smuzhiyun DEBUG("ID[0x%04X+%04X]", idx, gctx->data_block);
274*4882a593Smuzhiyun else
275*4882a593Smuzhiyun DEBUG("ID[0x%04X]", idx);
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun val = U32(idx + gctx->data_block);
278*4882a593Smuzhiyun break;
279*4882a593Smuzhiyun case ATOM_ARG_FB:
280*4882a593Smuzhiyun idx = U8(*ptr);
281*4882a593Smuzhiyun (*ptr)++;
282*4882a593Smuzhiyun if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) {
283*4882a593Smuzhiyun DRM_ERROR("ATOM: fb read beyond scratch region: %d vs. %d\n",
284*4882a593Smuzhiyun gctx->fb_base + (idx * 4), gctx->scratch_size_bytes);
285*4882a593Smuzhiyun val = 0;
286*4882a593Smuzhiyun } else
287*4882a593Smuzhiyun val = gctx->scratch[(gctx->fb_base / 4) + idx];
288*4882a593Smuzhiyun if (print)
289*4882a593Smuzhiyun DEBUG("FB[0x%02X]", idx);
290*4882a593Smuzhiyun break;
291*4882a593Smuzhiyun case ATOM_ARG_IMM:
292*4882a593Smuzhiyun switch (align) {
293*4882a593Smuzhiyun case ATOM_SRC_DWORD:
294*4882a593Smuzhiyun val = U32(*ptr);
295*4882a593Smuzhiyun (*ptr) += 4;
296*4882a593Smuzhiyun if (print)
297*4882a593Smuzhiyun DEBUG("IMM 0x%08X\n", val);
298*4882a593Smuzhiyun return val;
299*4882a593Smuzhiyun case ATOM_SRC_WORD0:
300*4882a593Smuzhiyun case ATOM_SRC_WORD8:
301*4882a593Smuzhiyun case ATOM_SRC_WORD16:
302*4882a593Smuzhiyun val = U16(*ptr);
303*4882a593Smuzhiyun (*ptr) += 2;
304*4882a593Smuzhiyun if (print)
305*4882a593Smuzhiyun DEBUG("IMM 0x%04X\n", val);
306*4882a593Smuzhiyun return val;
307*4882a593Smuzhiyun case ATOM_SRC_BYTE0:
308*4882a593Smuzhiyun case ATOM_SRC_BYTE8:
309*4882a593Smuzhiyun case ATOM_SRC_BYTE16:
310*4882a593Smuzhiyun case ATOM_SRC_BYTE24:
311*4882a593Smuzhiyun val = U8(*ptr);
312*4882a593Smuzhiyun (*ptr)++;
313*4882a593Smuzhiyun if (print)
314*4882a593Smuzhiyun DEBUG("IMM 0x%02X\n", val);
315*4882a593Smuzhiyun return val;
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun return 0;
318*4882a593Smuzhiyun case ATOM_ARG_PLL:
319*4882a593Smuzhiyun idx = U8(*ptr);
320*4882a593Smuzhiyun (*ptr)++;
321*4882a593Smuzhiyun if (print)
322*4882a593Smuzhiyun DEBUG("PLL[0x%02X]", idx);
323*4882a593Smuzhiyun val = gctx->card->pll_read(gctx->card, idx);
324*4882a593Smuzhiyun break;
325*4882a593Smuzhiyun case ATOM_ARG_MC:
326*4882a593Smuzhiyun idx = U8(*ptr);
327*4882a593Smuzhiyun (*ptr)++;
328*4882a593Smuzhiyun if (print)
329*4882a593Smuzhiyun DEBUG("MC[0x%02X]", idx);
330*4882a593Smuzhiyun val = gctx->card->mc_read(gctx->card, idx);
331*4882a593Smuzhiyun break;
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun if (saved)
334*4882a593Smuzhiyun *saved = val;
335*4882a593Smuzhiyun val &= atom_arg_mask[align];
336*4882a593Smuzhiyun val >>= atom_arg_shift[align];
337*4882a593Smuzhiyun if (print)
338*4882a593Smuzhiyun switch (align) {
339*4882a593Smuzhiyun case ATOM_SRC_DWORD:
340*4882a593Smuzhiyun DEBUG(".[31:0] -> 0x%08X\n", val);
341*4882a593Smuzhiyun break;
342*4882a593Smuzhiyun case ATOM_SRC_WORD0:
343*4882a593Smuzhiyun DEBUG(".[15:0] -> 0x%04X\n", val);
344*4882a593Smuzhiyun break;
345*4882a593Smuzhiyun case ATOM_SRC_WORD8:
346*4882a593Smuzhiyun DEBUG(".[23:8] -> 0x%04X\n", val);
347*4882a593Smuzhiyun break;
348*4882a593Smuzhiyun case ATOM_SRC_WORD16:
349*4882a593Smuzhiyun DEBUG(".[31:16] -> 0x%04X\n", val);
350*4882a593Smuzhiyun break;
351*4882a593Smuzhiyun case ATOM_SRC_BYTE0:
352*4882a593Smuzhiyun DEBUG(".[7:0] -> 0x%02X\n", val);
353*4882a593Smuzhiyun break;
354*4882a593Smuzhiyun case ATOM_SRC_BYTE8:
355*4882a593Smuzhiyun DEBUG(".[15:8] -> 0x%02X\n", val);
356*4882a593Smuzhiyun break;
357*4882a593Smuzhiyun case ATOM_SRC_BYTE16:
358*4882a593Smuzhiyun DEBUG(".[23:16] -> 0x%02X\n", val);
359*4882a593Smuzhiyun break;
360*4882a593Smuzhiyun case ATOM_SRC_BYTE24:
361*4882a593Smuzhiyun DEBUG(".[31:24] -> 0x%02X\n", val);
362*4882a593Smuzhiyun break;
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun return val;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun
atom_skip_src_int(atom_exec_context * ctx,uint8_t attr,int * ptr)367*4882a593Smuzhiyun static void atom_skip_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr)
368*4882a593Smuzhiyun {
369*4882a593Smuzhiyun uint32_t align = (attr >> 3) & 7, arg = attr & 7;
370*4882a593Smuzhiyun switch (arg) {
371*4882a593Smuzhiyun case ATOM_ARG_REG:
372*4882a593Smuzhiyun case ATOM_ARG_ID:
373*4882a593Smuzhiyun (*ptr) += 2;
374*4882a593Smuzhiyun break;
375*4882a593Smuzhiyun case ATOM_ARG_PLL:
376*4882a593Smuzhiyun case ATOM_ARG_MC:
377*4882a593Smuzhiyun case ATOM_ARG_PS:
378*4882a593Smuzhiyun case ATOM_ARG_WS:
379*4882a593Smuzhiyun case ATOM_ARG_FB:
380*4882a593Smuzhiyun (*ptr)++;
381*4882a593Smuzhiyun break;
382*4882a593Smuzhiyun case ATOM_ARG_IMM:
383*4882a593Smuzhiyun switch (align) {
384*4882a593Smuzhiyun case ATOM_SRC_DWORD:
385*4882a593Smuzhiyun (*ptr) += 4;
386*4882a593Smuzhiyun return;
387*4882a593Smuzhiyun case ATOM_SRC_WORD0:
388*4882a593Smuzhiyun case ATOM_SRC_WORD8:
389*4882a593Smuzhiyun case ATOM_SRC_WORD16:
390*4882a593Smuzhiyun (*ptr) += 2;
391*4882a593Smuzhiyun return;
392*4882a593Smuzhiyun case ATOM_SRC_BYTE0:
393*4882a593Smuzhiyun case ATOM_SRC_BYTE8:
394*4882a593Smuzhiyun case ATOM_SRC_BYTE16:
395*4882a593Smuzhiyun case ATOM_SRC_BYTE24:
396*4882a593Smuzhiyun (*ptr)++;
397*4882a593Smuzhiyun return;
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun return;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun
atom_get_src(atom_exec_context * ctx,uint8_t attr,int * ptr)403*4882a593Smuzhiyun static uint32_t atom_get_src(atom_exec_context *ctx, uint8_t attr, int *ptr)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun return atom_get_src_int(ctx, attr, ptr, NULL, 1);
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun
atom_get_src_direct(atom_exec_context * ctx,uint8_t align,int * ptr)408*4882a593Smuzhiyun static uint32_t atom_get_src_direct(atom_exec_context *ctx, uint8_t align, int *ptr)
409*4882a593Smuzhiyun {
410*4882a593Smuzhiyun uint32_t val = 0xCDCDCDCD;
411*4882a593Smuzhiyun
412*4882a593Smuzhiyun switch (align) {
413*4882a593Smuzhiyun case ATOM_SRC_DWORD:
414*4882a593Smuzhiyun val = U32(*ptr);
415*4882a593Smuzhiyun (*ptr) += 4;
416*4882a593Smuzhiyun break;
417*4882a593Smuzhiyun case ATOM_SRC_WORD0:
418*4882a593Smuzhiyun case ATOM_SRC_WORD8:
419*4882a593Smuzhiyun case ATOM_SRC_WORD16:
420*4882a593Smuzhiyun val = U16(*ptr);
421*4882a593Smuzhiyun (*ptr) += 2;
422*4882a593Smuzhiyun break;
423*4882a593Smuzhiyun case ATOM_SRC_BYTE0:
424*4882a593Smuzhiyun case ATOM_SRC_BYTE8:
425*4882a593Smuzhiyun case ATOM_SRC_BYTE16:
426*4882a593Smuzhiyun case ATOM_SRC_BYTE24:
427*4882a593Smuzhiyun val = U8(*ptr);
428*4882a593Smuzhiyun (*ptr)++;
429*4882a593Smuzhiyun break;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun return val;
432*4882a593Smuzhiyun }
433*4882a593Smuzhiyun
atom_get_dst(atom_exec_context * ctx,int arg,uint8_t attr,int * ptr,uint32_t * saved,int print)434*4882a593Smuzhiyun static uint32_t atom_get_dst(atom_exec_context *ctx, int arg, uint8_t attr,
435*4882a593Smuzhiyun int *ptr, uint32_t *saved, int print)
436*4882a593Smuzhiyun {
437*4882a593Smuzhiyun return atom_get_src_int(ctx,
438*4882a593Smuzhiyun arg | atom_dst_to_src[(attr >> 3) &
439*4882a593Smuzhiyun 7][(attr >> 6) & 3] << 3,
440*4882a593Smuzhiyun ptr, saved, print);
441*4882a593Smuzhiyun }
442*4882a593Smuzhiyun
atom_skip_dst(atom_exec_context * ctx,int arg,uint8_t attr,int * ptr)443*4882a593Smuzhiyun static void atom_skip_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr)
444*4882a593Smuzhiyun {
445*4882a593Smuzhiyun atom_skip_src_int(ctx,
446*4882a593Smuzhiyun arg | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) &
447*4882a593Smuzhiyun 3] << 3, ptr);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
atom_put_dst(atom_exec_context * ctx,int arg,uint8_t attr,int * ptr,uint32_t val,uint32_t saved)450*4882a593Smuzhiyun static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr,
451*4882a593Smuzhiyun int *ptr, uint32_t val, uint32_t saved)
452*4882a593Smuzhiyun {
453*4882a593Smuzhiyun uint32_t align =
454*4882a593Smuzhiyun atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3], old_val =
455*4882a593Smuzhiyun val, idx;
456*4882a593Smuzhiyun struct atom_context *gctx = ctx->ctx;
457*4882a593Smuzhiyun old_val &= atom_arg_mask[align] >> atom_arg_shift[align];
458*4882a593Smuzhiyun val <<= atom_arg_shift[align];
459*4882a593Smuzhiyun val &= atom_arg_mask[align];
460*4882a593Smuzhiyun saved &= ~atom_arg_mask[align];
461*4882a593Smuzhiyun val |= saved;
462*4882a593Smuzhiyun switch (arg) {
463*4882a593Smuzhiyun case ATOM_ARG_REG:
464*4882a593Smuzhiyun idx = U16(*ptr);
465*4882a593Smuzhiyun (*ptr) += 2;
466*4882a593Smuzhiyun DEBUG("REG[0x%04X]", idx);
467*4882a593Smuzhiyun idx += gctx->reg_block;
468*4882a593Smuzhiyun switch (gctx->io_mode) {
469*4882a593Smuzhiyun case ATOM_IO_MM:
470*4882a593Smuzhiyun if (idx == 0)
471*4882a593Smuzhiyun gctx->card->reg_write(gctx->card, idx,
472*4882a593Smuzhiyun val << 2);
473*4882a593Smuzhiyun else
474*4882a593Smuzhiyun gctx->card->reg_write(gctx->card, idx, val);
475*4882a593Smuzhiyun break;
476*4882a593Smuzhiyun case ATOM_IO_PCI:
477*4882a593Smuzhiyun pr_info("PCI registers are not implemented\n");
478*4882a593Smuzhiyun return;
479*4882a593Smuzhiyun case ATOM_IO_SYSIO:
480*4882a593Smuzhiyun pr_info("SYSIO registers are not implemented\n");
481*4882a593Smuzhiyun return;
482*4882a593Smuzhiyun default:
483*4882a593Smuzhiyun if (!(gctx->io_mode & 0x80)) {
484*4882a593Smuzhiyun pr_info("Bad IO mode\n");
485*4882a593Smuzhiyun return;
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun if (!gctx->iio[gctx->io_mode & 0xFF]) {
488*4882a593Smuzhiyun pr_info("Undefined indirect IO write method %d\n",
489*4882a593Smuzhiyun gctx->io_mode & 0x7F);
490*4882a593Smuzhiyun return;
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun atom_iio_execute(gctx, gctx->iio[gctx->io_mode & 0xFF],
493*4882a593Smuzhiyun idx, val);
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun break;
496*4882a593Smuzhiyun case ATOM_ARG_PS:
497*4882a593Smuzhiyun idx = U8(*ptr);
498*4882a593Smuzhiyun (*ptr)++;
499*4882a593Smuzhiyun DEBUG("PS[0x%02X]", idx);
500*4882a593Smuzhiyun ctx->ps[idx] = cpu_to_le32(val);
501*4882a593Smuzhiyun break;
502*4882a593Smuzhiyun case ATOM_ARG_WS:
503*4882a593Smuzhiyun idx = U8(*ptr);
504*4882a593Smuzhiyun (*ptr)++;
505*4882a593Smuzhiyun DEBUG("WS[0x%02X]", idx);
506*4882a593Smuzhiyun switch (idx) {
507*4882a593Smuzhiyun case ATOM_WS_QUOTIENT:
508*4882a593Smuzhiyun gctx->divmul[0] = val;
509*4882a593Smuzhiyun break;
510*4882a593Smuzhiyun case ATOM_WS_REMAINDER:
511*4882a593Smuzhiyun gctx->divmul[1] = val;
512*4882a593Smuzhiyun break;
513*4882a593Smuzhiyun case ATOM_WS_DATAPTR:
514*4882a593Smuzhiyun gctx->data_block = val;
515*4882a593Smuzhiyun break;
516*4882a593Smuzhiyun case ATOM_WS_SHIFT:
517*4882a593Smuzhiyun gctx->shift = val;
518*4882a593Smuzhiyun break;
519*4882a593Smuzhiyun case ATOM_WS_OR_MASK:
520*4882a593Smuzhiyun case ATOM_WS_AND_MASK:
521*4882a593Smuzhiyun break;
522*4882a593Smuzhiyun case ATOM_WS_FB_WINDOW:
523*4882a593Smuzhiyun gctx->fb_base = val;
524*4882a593Smuzhiyun break;
525*4882a593Smuzhiyun case ATOM_WS_ATTRIBUTES:
526*4882a593Smuzhiyun gctx->io_attr = val;
527*4882a593Smuzhiyun break;
528*4882a593Smuzhiyun case ATOM_WS_REGPTR:
529*4882a593Smuzhiyun gctx->reg_block = val;
530*4882a593Smuzhiyun break;
531*4882a593Smuzhiyun default:
532*4882a593Smuzhiyun ctx->ws[idx] = val;
533*4882a593Smuzhiyun }
534*4882a593Smuzhiyun break;
535*4882a593Smuzhiyun case ATOM_ARG_FB:
536*4882a593Smuzhiyun idx = U8(*ptr);
537*4882a593Smuzhiyun (*ptr)++;
538*4882a593Smuzhiyun if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) {
539*4882a593Smuzhiyun DRM_ERROR("ATOM: fb write beyond scratch region: %d vs. %d\n",
540*4882a593Smuzhiyun gctx->fb_base + (idx * 4), gctx->scratch_size_bytes);
541*4882a593Smuzhiyun } else
542*4882a593Smuzhiyun gctx->scratch[(gctx->fb_base / 4) + idx] = val;
543*4882a593Smuzhiyun DEBUG("FB[0x%02X]", idx);
544*4882a593Smuzhiyun break;
545*4882a593Smuzhiyun case ATOM_ARG_PLL:
546*4882a593Smuzhiyun idx = U8(*ptr);
547*4882a593Smuzhiyun (*ptr)++;
548*4882a593Smuzhiyun DEBUG("PLL[0x%02X]", idx);
549*4882a593Smuzhiyun gctx->card->pll_write(gctx->card, idx, val);
550*4882a593Smuzhiyun break;
551*4882a593Smuzhiyun case ATOM_ARG_MC:
552*4882a593Smuzhiyun idx = U8(*ptr);
553*4882a593Smuzhiyun (*ptr)++;
554*4882a593Smuzhiyun DEBUG("MC[0x%02X]", idx);
555*4882a593Smuzhiyun gctx->card->mc_write(gctx->card, idx, val);
556*4882a593Smuzhiyun return;
557*4882a593Smuzhiyun }
558*4882a593Smuzhiyun switch (align) {
559*4882a593Smuzhiyun case ATOM_SRC_DWORD:
560*4882a593Smuzhiyun DEBUG(".[31:0] <- 0x%08X\n", old_val);
561*4882a593Smuzhiyun break;
562*4882a593Smuzhiyun case ATOM_SRC_WORD0:
563*4882a593Smuzhiyun DEBUG(".[15:0] <- 0x%04X\n", old_val);
564*4882a593Smuzhiyun break;
565*4882a593Smuzhiyun case ATOM_SRC_WORD8:
566*4882a593Smuzhiyun DEBUG(".[23:8] <- 0x%04X\n", old_val);
567*4882a593Smuzhiyun break;
568*4882a593Smuzhiyun case ATOM_SRC_WORD16:
569*4882a593Smuzhiyun DEBUG(".[31:16] <- 0x%04X\n", old_val);
570*4882a593Smuzhiyun break;
571*4882a593Smuzhiyun case ATOM_SRC_BYTE0:
572*4882a593Smuzhiyun DEBUG(".[7:0] <- 0x%02X\n", old_val);
573*4882a593Smuzhiyun break;
574*4882a593Smuzhiyun case ATOM_SRC_BYTE8:
575*4882a593Smuzhiyun DEBUG(".[15:8] <- 0x%02X\n", old_val);
576*4882a593Smuzhiyun break;
577*4882a593Smuzhiyun case ATOM_SRC_BYTE16:
578*4882a593Smuzhiyun DEBUG(".[23:16] <- 0x%02X\n", old_val);
579*4882a593Smuzhiyun break;
580*4882a593Smuzhiyun case ATOM_SRC_BYTE24:
581*4882a593Smuzhiyun DEBUG(".[31:24] <- 0x%02X\n", old_val);
582*4882a593Smuzhiyun break;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun }
585*4882a593Smuzhiyun
atom_op_add(atom_exec_context * ctx,int * ptr,int arg)586*4882a593Smuzhiyun static void atom_op_add(atom_exec_context *ctx, int *ptr, int arg)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
589*4882a593Smuzhiyun uint32_t dst, src, saved;
590*4882a593Smuzhiyun int dptr = *ptr;
591*4882a593Smuzhiyun SDEBUG(" dst: ");
592*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
593*4882a593Smuzhiyun SDEBUG(" src: ");
594*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
595*4882a593Smuzhiyun dst += src;
596*4882a593Smuzhiyun SDEBUG(" dst: ");
597*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun
atom_op_and(atom_exec_context * ctx,int * ptr,int arg)600*4882a593Smuzhiyun static void atom_op_and(atom_exec_context *ctx, int *ptr, int arg)
601*4882a593Smuzhiyun {
602*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
603*4882a593Smuzhiyun uint32_t dst, src, saved;
604*4882a593Smuzhiyun int dptr = *ptr;
605*4882a593Smuzhiyun SDEBUG(" dst: ");
606*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
607*4882a593Smuzhiyun SDEBUG(" src: ");
608*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
609*4882a593Smuzhiyun dst &= src;
610*4882a593Smuzhiyun SDEBUG(" dst: ");
611*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun
atom_op_beep(atom_exec_context * ctx,int * ptr,int arg)614*4882a593Smuzhiyun static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg)
615*4882a593Smuzhiyun {
616*4882a593Smuzhiyun printk("ATOM BIOS beeped!\n");
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun
atom_op_calltable(atom_exec_context * ctx,int * ptr,int arg)619*4882a593Smuzhiyun static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg)
620*4882a593Smuzhiyun {
621*4882a593Smuzhiyun int idx = U8((*ptr)++);
622*4882a593Smuzhiyun int r = 0;
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun if (idx < ATOM_TABLE_NAMES_CNT)
625*4882a593Smuzhiyun SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]);
626*4882a593Smuzhiyun else
627*4882a593Smuzhiyun SDEBUG(" table: %d\n", idx);
628*4882a593Smuzhiyun if (U16(ctx->ctx->cmd_table + 4 + 2 * idx))
629*4882a593Smuzhiyun r = atom_execute_table_locked(ctx->ctx, idx, ctx->ps + ctx->ps_shift);
630*4882a593Smuzhiyun if (r) {
631*4882a593Smuzhiyun ctx->abort = true;
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun
atom_op_clear(atom_exec_context * ctx,int * ptr,int arg)635*4882a593Smuzhiyun static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
638*4882a593Smuzhiyun uint32_t saved;
639*4882a593Smuzhiyun int dptr = *ptr;
640*4882a593Smuzhiyun attr &= 0x38;
641*4882a593Smuzhiyun attr |= atom_def_dst[attr >> 3] << 6;
642*4882a593Smuzhiyun atom_get_dst(ctx, arg, attr, ptr, &saved, 0);
643*4882a593Smuzhiyun SDEBUG(" dst: ");
644*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, 0, saved);
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun
atom_op_compare(atom_exec_context * ctx,int * ptr,int arg)647*4882a593Smuzhiyun static void atom_op_compare(atom_exec_context *ctx, int *ptr, int arg)
648*4882a593Smuzhiyun {
649*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
650*4882a593Smuzhiyun uint32_t dst, src;
651*4882a593Smuzhiyun SDEBUG(" src1: ");
652*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
653*4882a593Smuzhiyun SDEBUG(" src2: ");
654*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
655*4882a593Smuzhiyun ctx->ctx->cs_equal = (dst == src);
656*4882a593Smuzhiyun ctx->ctx->cs_above = (dst > src);
657*4882a593Smuzhiyun SDEBUG(" result: %s %s\n", ctx->ctx->cs_equal ? "EQ" : "NE",
658*4882a593Smuzhiyun ctx->ctx->cs_above ? "GT" : "LE");
659*4882a593Smuzhiyun }
660*4882a593Smuzhiyun
atom_op_delay(atom_exec_context * ctx,int * ptr,int arg)661*4882a593Smuzhiyun static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg)
662*4882a593Smuzhiyun {
663*4882a593Smuzhiyun unsigned count = U8((*ptr)++);
664*4882a593Smuzhiyun SDEBUG(" count: %d\n", count);
665*4882a593Smuzhiyun if (arg == ATOM_UNIT_MICROSEC)
666*4882a593Smuzhiyun udelay(count);
667*4882a593Smuzhiyun else if (!drm_can_sleep())
668*4882a593Smuzhiyun mdelay(count);
669*4882a593Smuzhiyun else
670*4882a593Smuzhiyun msleep(count);
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun
atom_op_div(atom_exec_context * ctx,int * ptr,int arg)673*4882a593Smuzhiyun static void atom_op_div(atom_exec_context *ctx, int *ptr, int arg)
674*4882a593Smuzhiyun {
675*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
676*4882a593Smuzhiyun uint32_t dst, src;
677*4882a593Smuzhiyun SDEBUG(" src1: ");
678*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
679*4882a593Smuzhiyun SDEBUG(" src2: ");
680*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
681*4882a593Smuzhiyun if (src != 0) {
682*4882a593Smuzhiyun ctx->ctx->divmul[0] = dst / src;
683*4882a593Smuzhiyun ctx->ctx->divmul[1] = dst % src;
684*4882a593Smuzhiyun } else {
685*4882a593Smuzhiyun ctx->ctx->divmul[0] = 0;
686*4882a593Smuzhiyun ctx->ctx->divmul[1] = 0;
687*4882a593Smuzhiyun }
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun
atom_op_eot(atom_exec_context * ctx,int * ptr,int arg)690*4882a593Smuzhiyun static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg)
691*4882a593Smuzhiyun {
692*4882a593Smuzhiyun /* functionally, a nop */
693*4882a593Smuzhiyun }
694*4882a593Smuzhiyun
atom_op_jump(atom_exec_context * ctx,int * ptr,int arg)695*4882a593Smuzhiyun static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg)
696*4882a593Smuzhiyun {
697*4882a593Smuzhiyun int execute = 0, target = U16(*ptr);
698*4882a593Smuzhiyun unsigned long cjiffies;
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun (*ptr) += 2;
701*4882a593Smuzhiyun switch (arg) {
702*4882a593Smuzhiyun case ATOM_COND_ABOVE:
703*4882a593Smuzhiyun execute = ctx->ctx->cs_above;
704*4882a593Smuzhiyun break;
705*4882a593Smuzhiyun case ATOM_COND_ABOVEOREQUAL:
706*4882a593Smuzhiyun execute = ctx->ctx->cs_above || ctx->ctx->cs_equal;
707*4882a593Smuzhiyun break;
708*4882a593Smuzhiyun case ATOM_COND_ALWAYS:
709*4882a593Smuzhiyun execute = 1;
710*4882a593Smuzhiyun break;
711*4882a593Smuzhiyun case ATOM_COND_BELOW:
712*4882a593Smuzhiyun execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal);
713*4882a593Smuzhiyun break;
714*4882a593Smuzhiyun case ATOM_COND_BELOWOREQUAL:
715*4882a593Smuzhiyun execute = !ctx->ctx->cs_above;
716*4882a593Smuzhiyun break;
717*4882a593Smuzhiyun case ATOM_COND_EQUAL:
718*4882a593Smuzhiyun execute = ctx->ctx->cs_equal;
719*4882a593Smuzhiyun break;
720*4882a593Smuzhiyun case ATOM_COND_NOTEQUAL:
721*4882a593Smuzhiyun execute = !ctx->ctx->cs_equal;
722*4882a593Smuzhiyun break;
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun if (arg != ATOM_COND_ALWAYS)
725*4882a593Smuzhiyun SDEBUG(" taken: %s\n", execute ? "yes" : "no");
726*4882a593Smuzhiyun SDEBUG(" target: 0x%04X\n", target);
727*4882a593Smuzhiyun if (execute) {
728*4882a593Smuzhiyun if (ctx->last_jump == (ctx->start + target)) {
729*4882a593Smuzhiyun cjiffies = jiffies;
730*4882a593Smuzhiyun if (time_after(cjiffies, ctx->last_jump_jiffies)) {
731*4882a593Smuzhiyun cjiffies -= ctx->last_jump_jiffies;
732*4882a593Smuzhiyun if ((jiffies_to_msecs(cjiffies) > 5000)) {
733*4882a593Smuzhiyun DRM_ERROR("atombios stuck in loop for more than 5secs aborting\n");
734*4882a593Smuzhiyun ctx->abort = true;
735*4882a593Smuzhiyun }
736*4882a593Smuzhiyun } else {
737*4882a593Smuzhiyun /* jiffies wrap around we will just wait a little longer */
738*4882a593Smuzhiyun ctx->last_jump_jiffies = jiffies;
739*4882a593Smuzhiyun }
740*4882a593Smuzhiyun } else {
741*4882a593Smuzhiyun ctx->last_jump = ctx->start + target;
742*4882a593Smuzhiyun ctx->last_jump_jiffies = jiffies;
743*4882a593Smuzhiyun }
744*4882a593Smuzhiyun *ptr = ctx->start + target;
745*4882a593Smuzhiyun }
746*4882a593Smuzhiyun }
747*4882a593Smuzhiyun
atom_op_mask(atom_exec_context * ctx,int * ptr,int arg)748*4882a593Smuzhiyun static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg)
749*4882a593Smuzhiyun {
750*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
751*4882a593Smuzhiyun uint32_t dst, mask, src, saved;
752*4882a593Smuzhiyun int dptr = *ptr;
753*4882a593Smuzhiyun SDEBUG(" dst: ");
754*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
755*4882a593Smuzhiyun mask = atom_get_src_direct(ctx, ((attr >> 3) & 7), ptr);
756*4882a593Smuzhiyun SDEBUG(" mask: 0x%08x", mask);
757*4882a593Smuzhiyun SDEBUG(" src: ");
758*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
759*4882a593Smuzhiyun dst &= mask;
760*4882a593Smuzhiyun dst |= src;
761*4882a593Smuzhiyun SDEBUG(" dst: ");
762*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
763*4882a593Smuzhiyun }
764*4882a593Smuzhiyun
atom_op_move(atom_exec_context * ctx,int * ptr,int arg)765*4882a593Smuzhiyun static void atom_op_move(atom_exec_context *ctx, int *ptr, int arg)
766*4882a593Smuzhiyun {
767*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
768*4882a593Smuzhiyun uint32_t src, saved;
769*4882a593Smuzhiyun int dptr = *ptr;
770*4882a593Smuzhiyun if (((attr >> 3) & 7) != ATOM_SRC_DWORD)
771*4882a593Smuzhiyun atom_get_dst(ctx, arg, attr, ptr, &saved, 0);
772*4882a593Smuzhiyun else {
773*4882a593Smuzhiyun atom_skip_dst(ctx, arg, attr, ptr);
774*4882a593Smuzhiyun saved = 0xCDCDCDCD;
775*4882a593Smuzhiyun }
776*4882a593Smuzhiyun SDEBUG(" src: ");
777*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
778*4882a593Smuzhiyun SDEBUG(" dst: ");
779*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, src, saved);
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun
atom_op_mul(atom_exec_context * ctx,int * ptr,int arg)782*4882a593Smuzhiyun static void atom_op_mul(atom_exec_context *ctx, int *ptr, int arg)
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
785*4882a593Smuzhiyun uint32_t dst, src;
786*4882a593Smuzhiyun SDEBUG(" src1: ");
787*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
788*4882a593Smuzhiyun SDEBUG(" src2: ");
789*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
790*4882a593Smuzhiyun ctx->ctx->divmul[0] = dst * src;
791*4882a593Smuzhiyun }
792*4882a593Smuzhiyun
atom_op_nop(atom_exec_context * ctx,int * ptr,int arg)793*4882a593Smuzhiyun static void atom_op_nop(atom_exec_context *ctx, int *ptr, int arg)
794*4882a593Smuzhiyun {
795*4882a593Smuzhiyun /* nothing */
796*4882a593Smuzhiyun }
797*4882a593Smuzhiyun
atom_op_or(atom_exec_context * ctx,int * ptr,int arg)798*4882a593Smuzhiyun static void atom_op_or(atom_exec_context *ctx, int *ptr, int arg)
799*4882a593Smuzhiyun {
800*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
801*4882a593Smuzhiyun uint32_t dst, src, saved;
802*4882a593Smuzhiyun int dptr = *ptr;
803*4882a593Smuzhiyun SDEBUG(" dst: ");
804*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
805*4882a593Smuzhiyun SDEBUG(" src: ");
806*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
807*4882a593Smuzhiyun dst |= src;
808*4882a593Smuzhiyun SDEBUG(" dst: ");
809*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
810*4882a593Smuzhiyun }
811*4882a593Smuzhiyun
atom_op_postcard(atom_exec_context * ctx,int * ptr,int arg)812*4882a593Smuzhiyun static void atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg)
813*4882a593Smuzhiyun {
814*4882a593Smuzhiyun uint8_t val = U8((*ptr)++);
815*4882a593Smuzhiyun SDEBUG("POST card output: 0x%02X\n", val);
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun
atom_op_repeat(atom_exec_context * ctx,int * ptr,int arg)818*4882a593Smuzhiyun static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg)
819*4882a593Smuzhiyun {
820*4882a593Smuzhiyun pr_info("unimplemented!\n");
821*4882a593Smuzhiyun }
822*4882a593Smuzhiyun
atom_op_restorereg(atom_exec_context * ctx,int * ptr,int arg)823*4882a593Smuzhiyun static void atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun pr_info("unimplemented!\n");
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun
atom_op_savereg(atom_exec_context * ctx,int * ptr,int arg)828*4882a593Smuzhiyun static void atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg)
829*4882a593Smuzhiyun {
830*4882a593Smuzhiyun pr_info("unimplemented!\n");
831*4882a593Smuzhiyun }
832*4882a593Smuzhiyun
atom_op_setdatablock(atom_exec_context * ctx,int * ptr,int arg)833*4882a593Smuzhiyun static void atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg)
834*4882a593Smuzhiyun {
835*4882a593Smuzhiyun int idx = U8(*ptr);
836*4882a593Smuzhiyun (*ptr)++;
837*4882a593Smuzhiyun SDEBUG(" block: %d\n", idx);
838*4882a593Smuzhiyun if (!idx)
839*4882a593Smuzhiyun ctx->ctx->data_block = 0;
840*4882a593Smuzhiyun else if (idx == 255)
841*4882a593Smuzhiyun ctx->ctx->data_block = ctx->start;
842*4882a593Smuzhiyun else
843*4882a593Smuzhiyun ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2 * idx);
844*4882a593Smuzhiyun SDEBUG(" base: 0x%04X\n", ctx->ctx->data_block);
845*4882a593Smuzhiyun }
846*4882a593Smuzhiyun
atom_op_setfbbase(atom_exec_context * ctx,int * ptr,int arg)847*4882a593Smuzhiyun static void atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg)
848*4882a593Smuzhiyun {
849*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
850*4882a593Smuzhiyun SDEBUG(" fb_base: ");
851*4882a593Smuzhiyun ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr);
852*4882a593Smuzhiyun }
853*4882a593Smuzhiyun
atom_op_setport(atom_exec_context * ctx,int * ptr,int arg)854*4882a593Smuzhiyun static void atom_op_setport(atom_exec_context *ctx, int *ptr, int arg)
855*4882a593Smuzhiyun {
856*4882a593Smuzhiyun int port;
857*4882a593Smuzhiyun switch (arg) {
858*4882a593Smuzhiyun case ATOM_PORT_ATI:
859*4882a593Smuzhiyun port = U16(*ptr);
860*4882a593Smuzhiyun if (port < ATOM_IO_NAMES_CNT)
861*4882a593Smuzhiyun SDEBUG(" port: %d (%s)\n", port, atom_io_names[port]);
862*4882a593Smuzhiyun else
863*4882a593Smuzhiyun SDEBUG(" port: %d\n", port);
864*4882a593Smuzhiyun if (!port)
865*4882a593Smuzhiyun ctx->ctx->io_mode = ATOM_IO_MM;
866*4882a593Smuzhiyun else
867*4882a593Smuzhiyun ctx->ctx->io_mode = ATOM_IO_IIO | port;
868*4882a593Smuzhiyun (*ptr) += 2;
869*4882a593Smuzhiyun break;
870*4882a593Smuzhiyun case ATOM_PORT_PCI:
871*4882a593Smuzhiyun ctx->ctx->io_mode = ATOM_IO_PCI;
872*4882a593Smuzhiyun (*ptr)++;
873*4882a593Smuzhiyun break;
874*4882a593Smuzhiyun case ATOM_PORT_SYSIO:
875*4882a593Smuzhiyun ctx->ctx->io_mode = ATOM_IO_SYSIO;
876*4882a593Smuzhiyun (*ptr)++;
877*4882a593Smuzhiyun break;
878*4882a593Smuzhiyun }
879*4882a593Smuzhiyun }
880*4882a593Smuzhiyun
atom_op_setregblock(atom_exec_context * ctx,int * ptr,int arg)881*4882a593Smuzhiyun static void atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg)
882*4882a593Smuzhiyun {
883*4882a593Smuzhiyun ctx->ctx->reg_block = U16(*ptr);
884*4882a593Smuzhiyun (*ptr) += 2;
885*4882a593Smuzhiyun SDEBUG(" base: 0x%04X\n", ctx->ctx->reg_block);
886*4882a593Smuzhiyun }
887*4882a593Smuzhiyun
atom_op_shift_left(atom_exec_context * ctx,int * ptr,int arg)888*4882a593Smuzhiyun static void atom_op_shift_left(atom_exec_context *ctx, int *ptr, int arg)
889*4882a593Smuzhiyun {
890*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++), shift;
891*4882a593Smuzhiyun uint32_t saved, dst;
892*4882a593Smuzhiyun int dptr = *ptr;
893*4882a593Smuzhiyun attr &= 0x38;
894*4882a593Smuzhiyun attr |= atom_def_dst[attr >> 3] << 6;
895*4882a593Smuzhiyun SDEBUG(" dst: ");
896*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
897*4882a593Smuzhiyun shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr);
898*4882a593Smuzhiyun SDEBUG(" shift: %d\n", shift);
899*4882a593Smuzhiyun dst <<= shift;
900*4882a593Smuzhiyun SDEBUG(" dst: ");
901*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
902*4882a593Smuzhiyun }
903*4882a593Smuzhiyun
atom_op_shift_right(atom_exec_context * ctx,int * ptr,int arg)904*4882a593Smuzhiyun static void atom_op_shift_right(atom_exec_context *ctx, int *ptr, int arg)
905*4882a593Smuzhiyun {
906*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++), shift;
907*4882a593Smuzhiyun uint32_t saved, dst;
908*4882a593Smuzhiyun int dptr = *ptr;
909*4882a593Smuzhiyun attr &= 0x38;
910*4882a593Smuzhiyun attr |= atom_def_dst[attr >> 3] << 6;
911*4882a593Smuzhiyun SDEBUG(" dst: ");
912*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
913*4882a593Smuzhiyun shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr);
914*4882a593Smuzhiyun SDEBUG(" shift: %d\n", shift);
915*4882a593Smuzhiyun dst >>= shift;
916*4882a593Smuzhiyun SDEBUG(" dst: ");
917*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
918*4882a593Smuzhiyun }
919*4882a593Smuzhiyun
atom_op_shl(atom_exec_context * ctx,int * ptr,int arg)920*4882a593Smuzhiyun static void atom_op_shl(atom_exec_context *ctx, int *ptr, int arg)
921*4882a593Smuzhiyun {
922*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++), shift;
923*4882a593Smuzhiyun uint32_t saved, dst;
924*4882a593Smuzhiyun int dptr = *ptr;
925*4882a593Smuzhiyun uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3];
926*4882a593Smuzhiyun SDEBUG(" dst: ");
927*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
928*4882a593Smuzhiyun /* op needs to full dst value */
929*4882a593Smuzhiyun dst = saved;
930*4882a593Smuzhiyun shift = atom_get_src(ctx, attr, ptr);
931*4882a593Smuzhiyun SDEBUG(" shift: %d\n", shift);
932*4882a593Smuzhiyun dst <<= shift;
933*4882a593Smuzhiyun dst &= atom_arg_mask[dst_align];
934*4882a593Smuzhiyun dst >>= atom_arg_shift[dst_align];
935*4882a593Smuzhiyun SDEBUG(" dst: ");
936*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
937*4882a593Smuzhiyun }
938*4882a593Smuzhiyun
atom_op_shr(atom_exec_context * ctx,int * ptr,int arg)939*4882a593Smuzhiyun static void atom_op_shr(atom_exec_context *ctx, int *ptr, int arg)
940*4882a593Smuzhiyun {
941*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++), shift;
942*4882a593Smuzhiyun uint32_t saved, dst;
943*4882a593Smuzhiyun int dptr = *ptr;
944*4882a593Smuzhiyun uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3];
945*4882a593Smuzhiyun SDEBUG(" dst: ");
946*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
947*4882a593Smuzhiyun /* op needs to full dst value */
948*4882a593Smuzhiyun dst = saved;
949*4882a593Smuzhiyun shift = atom_get_src(ctx, attr, ptr);
950*4882a593Smuzhiyun SDEBUG(" shift: %d\n", shift);
951*4882a593Smuzhiyun dst >>= shift;
952*4882a593Smuzhiyun dst &= atom_arg_mask[dst_align];
953*4882a593Smuzhiyun dst >>= atom_arg_shift[dst_align];
954*4882a593Smuzhiyun SDEBUG(" dst: ");
955*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
956*4882a593Smuzhiyun }
957*4882a593Smuzhiyun
atom_op_sub(atom_exec_context * ctx,int * ptr,int arg)958*4882a593Smuzhiyun static void atom_op_sub(atom_exec_context *ctx, int *ptr, int arg)
959*4882a593Smuzhiyun {
960*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
961*4882a593Smuzhiyun uint32_t dst, src, saved;
962*4882a593Smuzhiyun int dptr = *ptr;
963*4882a593Smuzhiyun SDEBUG(" dst: ");
964*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
965*4882a593Smuzhiyun SDEBUG(" src: ");
966*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
967*4882a593Smuzhiyun dst -= src;
968*4882a593Smuzhiyun SDEBUG(" dst: ");
969*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
970*4882a593Smuzhiyun }
971*4882a593Smuzhiyun
atom_op_switch(atom_exec_context * ctx,int * ptr,int arg)972*4882a593Smuzhiyun static void atom_op_switch(atom_exec_context *ctx, int *ptr, int arg)
973*4882a593Smuzhiyun {
974*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
975*4882a593Smuzhiyun uint32_t src, val, target;
976*4882a593Smuzhiyun SDEBUG(" switch: ");
977*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
978*4882a593Smuzhiyun while (U16(*ptr) != ATOM_CASE_END)
979*4882a593Smuzhiyun if (U8(*ptr) == ATOM_CASE_MAGIC) {
980*4882a593Smuzhiyun (*ptr)++;
981*4882a593Smuzhiyun SDEBUG(" case: ");
982*4882a593Smuzhiyun val =
983*4882a593Smuzhiyun atom_get_src(ctx, (attr & 0x38) | ATOM_ARG_IMM,
984*4882a593Smuzhiyun ptr);
985*4882a593Smuzhiyun target = U16(*ptr);
986*4882a593Smuzhiyun if (val == src) {
987*4882a593Smuzhiyun SDEBUG(" target: %04X\n", target);
988*4882a593Smuzhiyun *ptr = ctx->start + target;
989*4882a593Smuzhiyun return;
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun (*ptr) += 2;
992*4882a593Smuzhiyun } else {
993*4882a593Smuzhiyun pr_info("Bad case\n");
994*4882a593Smuzhiyun return;
995*4882a593Smuzhiyun }
996*4882a593Smuzhiyun (*ptr) += 2;
997*4882a593Smuzhiyun }
998*4882a593Smuzhiyun
atom_op_test(atom_exec_context * ctx,int * ptr,int arg)999*4882a593Smuzhiyun static void atom_op_test(atom_exec_context *ctx, int *ptr, int arg)
1000*4882a593Smuzhiyun {
1001*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
1002*4882a593Smuzhiyun uint32_t dst, src;
1003*4882a593Smuzhiyun SDEBUG(" src1: ");
1004*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
1005*4882a593Smuzhiyun SDEBUG(" src2: ");
1006*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
1007*4882a593Smuzhiyun ctx->ctx->cs_equal = ((dst & src) == 0);
1008*4882a593Smuzhiyun SDEBUG(" result: %s\n", ctx->ctx->cs_equal ? "EQ" : "NE");
1009*4882a593Smuzhiyun }
1010*4882a593Smuzhiyun
atom_op_xor(atom_exec_context * ctx,int * ptr,int arg)1011*4882a593Smuzhiyun static void atom_op_xor(atom_exec_context *ctx, int *ptr, int arg)
1012*4882a593Smuzhiyun {
1013*4882a593Smuzhiyun uint8_t attr = U8((*ptr)++);
1014*4882a593Smuzhiyun uint32_t dst, src, saved;
1015*4882a593Smuzhiyun int dptr = *ptr;
1016*4882a593Smuzhiyun SDEBUG(" dst: ");
1017*4882a593Smuzhiyun dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
1018*4882a593Smuzhiyun SDEBUG(" src: ");
1019*4882a593Smuzhiyun src = atom_get_src(ctx, attr, ptr);
1020*4882a593Smuzhiyun dst ^= src;
1021*4882a593Smuzhiyun SDEBUG(" dst: ");
1022*4882a593Smuzhiyun atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
1023*4882a593Smuzhiyun }
1024*4882a593Smuzhiyun
atom_op_debug(atom_exec_context * ctx,int * ptr,int arg)1025*4882a593Smuzhiyun static void atom_op_debug(atom_exec_context *ctx, int *ptr, int arg)
1026*4882a593Smuzhiyun {
1027*4882a593Smuzhiyun pr_info("unimplemented!\n");
1028*4882a593Smuzhiyun }
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun static struct {
1031*4882a593Smuzhiyun void (*func) (atom_exec_context *, int *, int);
1032*4882a593Smuzhiyun int arg;
1033*4882a593Smuzhiyun } opcode_table[ATOM_OP_CNT] = {
1034*4882a593Smuzhiyun {
1035*4882a593Smuzhiyun NULL, 0}, {
1036*4882a593Smuzhiyun atom_op_move, ATOM_ARG_REG}, {
1037*4882a593Smuzhiyun atom_op_move, ATOM_ARG_PS}, {
1038*4882a593Smuzhiyun atom_op_move, ATOM_ARG_WS}, {
1039*4882a593Smuzhiyun atom_op_move, ATOM_ARG_FB}, {
1040*4882a593Smuzhiyun atom_op_move, ATOM_ARG_PLL}, {
1041*4882a593Smuzhiyun atom_op_move, ATOM_ARG_MC}, {
1042*4882a593Smuzhiyun atom_op_and, ATOM_ARG_REG}, {
1043*4882a593Smuzhiyun atom_op_and, ATOM_ARG_PS}, {
1044*4882a593Smuzhiyun atom_op_and, ATOM_ARG_WS}, {
1045*4882a593Smuzhiyun atom_op_and, ATOM_ARG_FB}, {
1046*4882a593Smuzhiyun atom_op_and, ATOM_ARG_PLL}, {
1047*4882a593Smuzhiyun atom_op_and, ATOM_ARG_MC}, {
1048*4882a593Smuzhiyun atom_op_or, ATOM_ARG_REG}, {
1049*4882a593Smuzhiyun atom_op_or, ATOM_ARG_PS}, {
1050*4882a593Smuzhiyun atom_op_or, ATOM_ARG_WS}, {
1051*4882a593Smuzhiyun atom_op_or, ATOM_ARG_FB}, {
1052*4882a593Smuzhiyun atom_op_or, ATOM_ARG_PLL}, {
1053*4882a593Smuzhiyun atom_op_or, ATOM_ARG_MC}, {
1054*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_REG}, {
1055*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_PS}, {
1056*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_WS}, {
1057*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_FB}, {
1058*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_PLL}, {
1059*4882a593Smuzhiyun atom_op_shift_left, ATOM_ARG_MC}, {
1060*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_REG}, {
1061*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_PS}, {
1062*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_WS}, {
1063*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_FB}, {
1064*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_PLL}, {
1065*4882a593Smuzhiyun atom_op_shift_right, ATOM_ARG_MC}, {
1066*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_REG}, {
1067*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_PS}, {
1068*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_WS}, {
1069*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_FB}, {
1070*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_PLL}, {
1071*4882a593Smuzhiyun atom_op_mul, ATOM_ARG_MC}, {
1072*4882a593Smuzhiyun atom_op_div, ATOM_ARG_REG}, {
1073*4882a593Smuzhiyun atom_op_div, ATOM_ARG_PS}, {
1074*4882a593Smuzhiyun atom_op_div, ATOM_ARG_WS}, {
1075*4882a593Smuzhiyun atom_op_div, ATOM_ARG_FB}, {
1076*4882a593Smuzhiyun atom_op_div, ATOM_ARG_PLL}, {
1077*4882a593Smuzhiyun atom_op_div, ATOM_ARG_MC}, {
1078*4882a593Smuzhiyun atom_op_add, ATOM_ARG_REG}, {
1079*4882a593Smuzhiyun atom_op_add, ATOM_ARG_PS}, {
1080*4882a593Smuzhiyun atom_op_add, ATOM_ARG_WS}, {
1081*4882a593Smuzhiyun atom_op_add, ATOM_ARG_FB}, {
1082*4882a593Smuzhiyun atom_op_add, ATOM_ARG_PLL}, {
1083*4882a593Smuzhiyun atom_op_add, ATOM_ARG_MC}, {
1084*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_REG}, {
1085*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_PS}, {
1086*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_WS}, {
1087*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_FB}, {
1088*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_PLL}, {
1089*4882a593Smuzhiyun atom_op_sub, ATOM_ARG_MC}, {
1090*4882a593Smuzhiyun atom_op_setport, ATOM_PORT_ATI}, {
1091*4882a593Smuzhiyun atom_op_setport, ATOM_PORT_PCI}, {
1092*4882a593Smuzhiyun atom_op_setport, ATOM_PORT_SYSIO}, {
1093*4882a593Smuzhiyun atom_op_setregblock, 0}, {
1094*4882a593Smuzhiyun atom_op_setfbbase, 0}, {
1095*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_REG}, {
1096*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_PS}, {
1097*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_WS}, {
1098*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_FB}, {
1099*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_PLL}, {
1100*4882a593Smuzhiyun atom_op_compare, ATOM_ARG_MC}, {
1101*4882a593Smuzhiyun atom_op_switch, 0}, {
1102*4882a593Smuzhiyun atom_op_jump, ATOM_COND_ALWAYS}, {
1103*4882a593Smuzhiyun atom_op_jump, ATOM_COND_EQUAL}, {
1104*4882a593Smuzhiyun atom_op_jump, ATOM_COND_BELOW}, {
1105*4882a593Smuzhiyun atom_op_jump, ATOM_COND_ABOVE}, {
1106*4882a593Smuzhiyun atom_op_jump, ATOM_COND_BELOWOREQUAL}, {
1107*4882a593Smuzhiyun atom_op_jump, ATOM_COND_ABOVEOREQUAL}, {
1108*4882a593Smuzhiyun atom_op_jump, ATOM_COND_NOTEQUAL}, {
1109*4882a593Smuzhiyun atom_op_test, ATOM_ARG_REG}, {
1110*4882a593Smuzhiyun atom_op_test, ATOM_ARG_PS}, {
1111*4882a593Smuzhiyun atom_op_test, ATOM_ARG_WS}, {
1112*4882a593Smuzhiyun atom_op_test, ATOM_ARG_FB}, {
1113*4882a593Smuzhiyun atom_op_test, ATOM_ARG_PLL}, {
1114*4882a593Smuzhiyun atom_op_test, ATOM_ARG_MC}, {
1115*4882a593Smuzhiyun atom_op_delay, ATOM_UNIT_MILLISEC}, {
1116*4882a593Smuzhiyun atom_op_delay, ATOM_UNIT_MICROSEC}, {
1117*4882a593Smuzhiyun atom_op_calltable, 0}, {
1118*4882a593Smuzhiyun atom_op_repeat, 0}, {
1119*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_REG}, {
1120*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_PS}, {
1121*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_WS}, {
1122*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_FB}, {
1123*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_PLL}, {
1124*4882a593Smuzhiyun atom_op_clear, ATOM_ARG_MC}, {
1125*4882a593Smuzhiyun atom_op_nop, 0}, {
1126*4882a593Smuzhiyun atom_op_eot, 0}, {
1127*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_REG}, {
1128*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_PS}, {
1129*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_WS}, {
1130*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_FB}, {
1131*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_PLL}, {
1132*4882a593Smuzhiyun atom_op_mask, ATOM_ARG_MC}, {
1133*4882a593Smuzhiyun atom_op_postcard, 0}, {
1134*4882a593Smuzhiyun atom_op_beep, 0}, {
1135*4882a593Smuzhiyun atom_op_savereg, 0}, {
1136*4882a593Smuzhiyun atom_op_restorereg, 0}, {
1137*4882a593Smuzhiyun atom_op_setdatablock, 0}, {
1138*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_REG}, {
1139*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_PS}, {
1140*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_WS}, {
1141*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_FB}, {
1142*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_PLL}, {
1143*4882a593Smuzhiyun atom_op_xor, ATOM_ARG_MC}, {
1144*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_REG}, {
1145*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_PS}, {
1146*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_WS}, {
1147*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_FB}, {
1148*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_PLL}, {
1149*4882a593Smuzhiyun atom_op_shl, ATOM_ARG_MC}, {
1150*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_REG}, {
1151*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_PS}, {
1152*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_WS}, {
1153*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_FB}, {
1154*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_PLL}, {
1155*4882a593Smuzhiyun atom_op_shr, ATOM_ARG_MC}, {
1156*4882a593Smuzhiyun atom_op_debug, 0},};
1157*4882a593Smuzhiyun
atom_execute_table_locked(struct atom_context * ctx,int index,uint32_t * params)1158*4882a593Smuzhiyun static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params)
1159*4882a593Smuzhiyun {
1160*4882a593Smuzhiyun int base = CU16(ctx->cmd_table + 4 + 2 * index);
1161*4882a593Smuzhiyun int len, ws, ps, ptr;
1162*4882a593Smuzhiyun unsigned char op;
1163*4882a593Smuzhiyun atom_exec_context ectx;
1164*4882a593Smuzhiyun int ret = 0;
1165*4882a593Smuzhiyun
1166*4882a593Smuzhiyun if (!base)
1167*4882a593Smuzhiyun return -EINVAL;
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun len = CU16(base + ATOM_CT_SIZE_PTR);
1170*4882a593Smuzhiyun ws = CU8(base + ATOM_CT_WS_PTR);
1171*4882a593Smuzhiyun ps = CU8(base + ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK;
1172*4882a593Smuzhiyun ptr = base + ATOM_CT_CODE_PTR;
1173*4882a593Smuzhiyun
1174*4882a593Smuzhiyun SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base, len, ws, ps);
1175*4882a593Smuzhiyun
1176*4882a593Smuzhiyun ectx.ctx = ctx;
1177*4882a593Smuzhiyun ectx.ps_shift = ps / 4;
1178*4882a593Smuzhiyun ectx.start = base;
1179*4882a593Smuzhiyun ectx.ps = params;
1180*4882a593Smuzhiyun ectx.abort = false;
1181*4882a593Smuzhiyun ectx.last_jump = 0;
1182*4882a593Smuzhiyun if (ws)
1183*4882a593Smuzhiyun ectx.ws = kcalloc(4, ws, GFP_KERNEL);
1184*4882a593Smuzhiyun else
1185*4882a593Smuzhiyun ectx.ws = NULL;
1186*4882a593Smuzhiyun
1187*4882a593Smuzhiyun debug_depth++;
1188*4882a593Smuzhiyun while (1) {
1189*4882a593Smuzhiyun op = CU8(ptr++);
1190*4882a593Smuzhiyun if (op < ATOM_OP_NAMES_CNT)
1191*4882a593Smuzhiyun SDEBUG("%s @ 0x%04X\n", atom_op_names[op], ptr - 1);
1192*4882a593Smuzhiyun else
1193*4882a593Smuzhiyun SDEBUG("[%d] @ 0x%04X\n", op, ptr - 1);
1194*4882a593Smuzhiyun if (ectx.abort) {
1195*4882a593Smuzhiyun DRM_ERROR("atombios stuck executing %04X (len %d, WS %d, PS %d) @ 0x%04X\n",
1196*4882a593Smuzhiyun base, len, ws, ps, ptr - 1);
1197*4882a593Smuzhiyun ret = -EINVAL;
1198*4882a593Smuzhiyun goto free;
1199*4882a593Smuzhiyun }
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun if (op < ATOM_OP_CNT && op > 0)
1202*4882a593Smuzhiyun opcode_table[op].func(&ectx, &ptr,
1203*4882a593Smuzhiyun opcode_table[op].arg);
1204*4882a593Smuzhiyun else
1205*4882a593Smuzhiyun break;
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun if (op == ATOM_OP_EOT)
1208*4882a593Smuzhiyun break;
1209*4882a593Smuzhiyun }
1210*4882a593Smuzhiyun debug_depth--;
1211*4882a593Smuzhiyun SDEBUG("<<\n");
1212*4882a593Smuzhiyun
1213*4882a593Smuzhiyun free:
1214*4882a593Smuzhiyun kfree(ectx.ws);
1215*4882a593Smuzhiyun return ret;
1216*4882a593Smuzhiyun }
1217*4882a593Smuzhiyun
atom_execute_table_scratch_unlocked(struct atom_context * ctx,int index,uint32_t * params)1218*4882a593Smuzhiyun int atom_execute_table_scratch_unlocked(struct atom_context *ctx, int index, uint32_t * params)
1219*4882a593Smuzhiyun {
1220*4882a593Smuzhiyun int r;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun mutex_lock(&ctx->mutex);
1223*4882a593Smuzhiyun /* reset data block */
1224*4882a593Smuzhiyun ctx->data_block = 0;
1225*4882a593Smuzhiyun /* reset reg block */
1226*4882a593Smuzhiyun ctx->reg_block = 0;
1227*4882a593Smuzhiyun /* reset fb window */
1228*4882a593Smuzhiyun ctx->fb_base = 0;
1229*4882a593Smuzhiyun /* reset io mode */
1230*4882a593Smuzhiyun ctx->io_mode = ATOM_IO_MM;
1231*4882a593Smuzhiyun /* reset divmul */
1232*4882a593Smuzhiyun ctx->divmul[0] = 0;
1233*4882a593Smuzhiyun ctx->divmul[1] = 0;
1234*4882a593Smuzhiyun r = atom_execute_table_locked(ctx, index, params);
1235*4882a593Smuzhiyun mutex_unlock(&ctx->mutex);
1236*4882a593Smuzhiyun return r;
1237*4882a593Smuzhiyun }
1238*4882a593Smuzhiyun
atom_execute_table(struct atom_context * ctx,int index,uint32_t * params)1239*4882a593Smuzhiyun int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
1240*4882a593Smuzhiyun {
1241*4882a593Smuzhiyun int r;
1242*4882a593Smuzhiyun mutex_lock(&ctx->scratch_mutex);
1243*4882a593Smuzhiyun r = atom_execute_table_scratch_unlocked(ctx, index, params);
1244*4882a593Smuzhiyun mutex_unlock(&ctx->scratch_mutex);
1245*4882a593Smuzhiyun return r;
1246*4882a593Smuzhiyun }
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 };
1249*4882a593Smuzhiyun
atom_index_iio(struct atom_context * ctx,int base)1250*4882a593Smuzhiyun static void atom_index_iio(struct atom_context *ctx, int base)
1251*4882a593Smuzhiyun {
1252*4882a593Smuzhiyun ctx->iio = kzalloc(2 * 256, GFP_KERNEL);
1253*4882a593Smuzhiyun if (!ctx->iio)
1254*4882a593Smuzhiyun return;
1255*4882a593Smuzhiyun while (CU8(base) == ATOM_IIO_START) {
1256*4882a593Smuzhiyun ctx->iio[CU8(base + 1)] = base + 2;
1257*4882a593Smuzhiyun base += 2;
1258*4882a593Smuzhiyun while (CU8(base) != ATOM_IIO_END)
1259*4882a593Smuzhiyun base += atom_iio_len[CU8(base)];
1260*4882a593Smuzhiyun base += 3;
1261*4882a593Smuzhiyun }
1262*4882a593Smuzhiyun }
1263*4882a593Smuzhiyun
atom_parse(struct card_info * card,void * bios)1264*4882a593Smuzhiyun struct atom_context *atom_parse(struct card_info *card, void *bios)
1265*4882a593Smuzhiyun {
1266*4882a593Smuzhiyun int base;
1267*4882a593Smuzhiyun struct atom_context *ctx =
1268*4882a593Smuzhiyun kzalloc(sizeof(struct atom_context), GFP_KERNEL);
1269*4882a593Smuzhiyun char *str;
1270*4882a593Smuzhiyun char name[512];
1271*4882a593Smuzhiyun int i;
1272*4882a593Smuzhiyun
1273*4882a593Smuzhiyun if (!ctx)
1274*4882a593Smuzhiyun return NULL;
1275*4882a593Smuzhiyun
1276*4882a593Smuzhiyun ctx->card = card;
1277*4882a593Smuzhiyun ctx->bios = bios;
1278*4882a593Smuzhiyun
1279*4882a593Smuzhiyun if (CU16(0) != ATOM_BIOS_MAGIC) {
1280*4882a593Smuzhiyun pr_info("Invalid BIOS magic\n");
1281*4882a593Smuzhiyun kfree(ctx);
1282*4882a593Smuzhiyun return NULL;
1283*4882a593Smuzhiyun }
1284*4882a593Smuzhiyun if (strncmp
1285*4882a593Smuzhiyun (CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC,
1286*4882a593Smuzhiyun strlen(ATOM_ATI_MAGIC))) {
1287*4882a593Smuzhiyun pr_info("Invalid ATI magic\n");
1288*4882a593Smuzhiyun kfree(ctx);
1289*4882a593Smuzhiyun return NULL;
1290*4882a593Smuzhiyun }
1291*4882a593Smuzhiyun
1292*4882a593Smuzhiyun base = CU16(ATOM_ROM_TABLE_PTR);
1293*4882a593Smuzhiyun if (strncmp
1294*4882a593Smuzhiyun (CSTR(base + ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC,
1295*4882a593Smuzhiyun strlen(ATOM_ROM_MAGIC))) {
1296*4882a593Smuzhiyun pr_info("Invalid ATOM magic\n");
1297*4882a593Smuzhiyun kfree(ctx);
1298*4882a593Smuzhiyun return NULL;
1299*4882a593Smuzhiyun }
1300*4882a593Smuzhiyun
1301*4882a593Smuzhiyun ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR);
1302*4882a593Smuzhiyun ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR);
1303*4882a593Smuzhiyun atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4);
1304*4882a593Smuzhiyun if (!ctx->iio) {
1305*4882a593Smuzhiyun atom_destroy(ctx);
1306*4882a593Smuzhiyun return NULL;
1307*4882a593Smuzhiyun }
1308*4882a593Smuzhiyun
1309*4882a593Smuzhiyun str = CSTR(CU16(base + ATOM_ROM_MSG_PTR));
1310*4882a593Smuzhiyun while (*str && ((*str == '\n') || (*str == '\r')))
1311*4882a593Smuzhiyun str++;
1312*4882a593Smuzhiyun /* name string isn't always 0 terminated */
1313*4882a593Smuzhiyun for (i = 0; i < 511; i++) {
1314*4882a593Smuzhiyun name[i] = str[i];
1315*4882a593Smuzhiyun if (name[i] < '.' || name[i] > 'z') {
1316*4882a593Smuzhiyun name[i] = 0;
1317*4882a593Smuzhiyun break;
1318*4882a593Smuzhiyun }
1319*4882a593Smuzhiyun }
1320*4882a593Smuzhiyun pr_info("ATOM BIOS: %s\n", name);
1321*4882a593Smuzhiyun
1322*4882a593Smuzhiyun return ctx;
1323*4882a593Smuzhiyun }
1324*4882a593Smuzhiyun
atom_asic_init(struct atom_context * ctx)1325*4882a593Smuzhiyun int atom_asic_init(struct atom_context *ctx)
1326*4882a593Smuzhiyun {
1327*4882a593Smuzhiyun struct radeon_device *rdev = ctx->card->dev->dev_private;
1328*4882a593Smuzhiyun int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
1329*4882a593Smuzhiyun uint32_t ps[16];
1330*4882a593Smuzhiyun int ret;
1331*4882a593Smuzhiyun
1332*4882a593Smuzhiyun memset(ps, 0, 64);
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
1335*4882a593Smuzhiyun ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR));
1336*4882a593Smuzhiyun if (!ps[0] || !ps[1])
1337*4882a593Smuzhiyun return 1;
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
1340*4882a593Smuzhiyun return 1;
1341*4882a593Smuzhiyun ret = atom_execute_table(ctx, ATOM_CMD_INIT, ps);
1342*4882a593Smuzhiyun if (ret)
1343*4882a593Smuzhiyun return ret;
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun memset(ps, 0, 64);
1346*4882a593Smuzhiyun
1347*4882a593Smuzhiyun if (rdev->family < CHIP_R600) {
1348*4882a593Smuzhiyun if (CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_SPDFANCNTL))
1349*4882a593Smuzhiyun atom_execute_table(ctx, ATOM_CMD_SPDFANCNTL, ps);
1350*4882a593Smuzhiyun }
1351*4882a593Smuzhiyun return ret;
1352*4882a593Smuzhiyun }
1353*4882a593Smuzhiyun
atom_destroy(struct atom_context * ctx)1354*4882a593Smuzhiyun void atom_destroy(struct atom_context *ctx)
1355*4882a593Smuzhiyun {
1356*4882a593Smuzhiyun kfree(ctx->iio);
1357*4882a593Smuzhiyun kfree(ctx);
1358*4882a593Smuzhiyun }
1359*4882a593Smuzhiyun
atom_parse_data_header(struct atom_context * ctx,int index,uint16_t * size,uint8_t * frev,uint8_t * crev,uint16_t * data_start)1360*4882a593Smuzhiyun bool atom_parse_data_header(struct atom_context *ctx, int index,
1361*4882a593Smuzhiyun uint16_t * size, uint8_t * frev, uint8_t * crev,
1362*4882a593Smuzhiyun uint16_t * data_start)
1363*4882a593Smuzhiyun {
1364*4882a593Smuzhiyun int offset = index * 2 + 4;
1365*4882a593Smuzhiyun int idx = CU16(ctx->data_table + offset);
1366*4882a593Smuzhiyun u16 *mdt = (u16 *)(ctx->bios + ctx->data_table + 4);
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun if (!mdt[index])
1369*4882a593Smuzhiyun return false;
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun if (size)
1372*4882a593Smuzhiyun *size = CU16(idx);
1373*4882a593Smuzhiyun if (frev)
1374*4882a593Smuzhiyun *frev = CU8(idx + 2);
1375*4882a593Smuzhiyun if (crev)
1376*4882a593Smuzhiyun *crev = CU8(idx + 3);
1377*4882a593Smuzhiyun *data_start = idx;
1378*4882a593Smuzhiyun return true;
1379*4882a593Smuzhiyun }
1380*4882a593Smuzhiyun
atom_parse_cmd_header(struct atom_context * ctx,int index,uint8_t * frev,uint8_t * crev)1381*4882a593Smuzhiyun bool atom_parse_cmd_header(struct atom_context *ctx, int index, uint8_t * frev,
1382*4882a593Smuzhiyun uint8_t * crev)
1383*4882a593Smuzhiyun {
1384*4882a593Smuzhiyun int offset = index * 2 + 4;
1385*4882a593Smuzhiyun int idx = CU16(ctx->cmd_table + offset);
1386*4882a593Smuzhiyun u16 *mct = (u16 *)(ctx->bios + ctx->cmd_table + 4);
1387*4882a593Smuzhiyun
1388*4882a593Smuzhiyun if (!mct[index])
1389*4882a593Smuzhiyun return false;
1390*4882a593Smuzhiyun
1391*4882a593Smuzhiyun if (frev)
1392*4882a593Smuzhiyun *frev = CU8(idx + 2);
1393*4882a593Smuzhiyun if (crev)
1394*4882a593Smuzhiyun *crev = CU8(idx + 3);
1395*4882a593Smuzhiyun return true;
1396*4882a593Smuzhiyun }
1397*4882a593Smuzhiyun
atom_allocate_fb_scratch(struct atom_context * ctx)1398*4882a593Smuzhiyun int atom_allocate_fb_scratch(struct atom_context *ctx)
1399*4882a593Smuzhiyun {
1400*4882a593Smuzhiyun int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware);
1401*4882a593Smuzhiyun uint16_t data_offset;
1402*4882a593Smuzhiyun int usage_bytes = 0;
1403*4882a593Smuzhiyun struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage;
1404*4882a593Smuzhiyun
1405*4882a593Smuzhiyun if (atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
1406*4882a593Smuzhiyun firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset);
1407*4882a593Smuzhiyun
1408*4882a593Smuzhiyun DRM_DEBUG("atom firmware requested %08x %dkb\n",
1409*4882a593Smuzhiyun le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware),
1410*4882a593Smuzhiyun le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb));
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
1413*4882a593Smuzhiyun }
1414*4882a593Smuzhiyun ctx->scratch_size_bytes = 0;
1415*4882a593Smuzhiyun if (usage_bytes == 0)
1416*4882a593Smuzhiyun usage_bytes = 20 * 1024;
1417*4882a593Smuzhiyun /* allocate some scratch memory */
1418*4882a593Smuzhiyun ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
1419*4882a593Smuzhiyun if (!ctx->scratch)
1420*4882a593Smuzhiyun return -ENOMEM;
1421*4882a593Smuzhiyun ctx->scratch_size_bytes = usage_bytes;
1422*4882a593Smuzhiyun return 0;
1423*4882a593Smuzhiyun }
1424