Subversion Repositories Kolibri OS

Rev

Rev 1428 | Rev 1963 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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