2 * Copyright 2008 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Author: Stanislaw Skowronek
25 #include <linux/module.h>
26 #include <linux/sched.h>
31 #include "atom-names.h"
32 #include "atom-bits.h"
34 #define ATOM_COND_ABOVE 0
35 #define ATOM_COND_ABOVEOREQUAL 1
36 #define ATOM_COND_ALWAYS 2
37 #define ATOM_COND_BELOW 3
38 #define ATOM_COND_BELOWOREQUAL 4
39 #define ATOM_COND_EQUAL 5
40 #define ATOM_COND_NOTEQUAL 6
42 #define ATOM_PORT_ATI 0
43 #define ATOM_PORT_PCI 1
44 #define ATOM_PORT_SYSIO 2
46 #define ATOM_UNIT_MICROSEC 0
47 #define ATOM_UNIT_MILLISEC 1
53 struct atom_context
*ctx
;
61 void atom_execute_table(struct atom_context
*ctx
, int index
, uint32_t * params
);
63 static uint32_t atom_arg_mask
[8] =
64 { 0xFFFFFFFF, 0xFFFF, 0xFFFF00, 0xFFFF0000, 0xFF, 0xFF00, 0xFF0000,
66 static int atom_arg_shift
[8] = { 0, 0, 8, 16, 0, 8, 16, 24 };
68 static int atom_dst_to_src
[8][4] = {
69 /* translate destination alignment field to the source alignment encoding */
79 static int atom_def_dst
[8] = { 0, 0, 1, 2, 0, 1, 2, 3 };
81 static int debug_depth
= 0;
83 static void debug_print_spaces(int n
)
89 #define DEBUG(...) do if (atom_debug) { printk(KERN_DEBUG __VA_ARGS__); } while (0)
90 #define SDEBUG(...) do if (atom_debug) { printk(KERN_DEBUG); debug_print_spaces(debug_depth); printk(__VA_ARGS__); } while (0)
92 #define DEBUG(...) do { } while (0)
93 #define SDEBUG(...) do { } while (0)
96 static uint32_t atom_iio_execute(struct atom_context
*ctx
, int base
,
97 uint32_t index
, uint32_t data
)
99 uint32_t temp
= 0xCDCDCDCD;
106 temp
= ctx
->card
->reg_read(ctx
->card
, CU16(base
+ 1));
110 ctx
->card
->reg_write(ctx
->card
, CU16(base
+ 1), temp
);
115 ~((0xFFFFFFFF >> (32 - CU8(base
+ 1))) <<
121 (0xFFFFFFFF >> (32 - CU8(base
+ 1))) << CU8(base
+
125 case ATOM_IIO_MOVE_INDEX
:
127 ~((0xFFFFFFFF >> (32 - CU8(base
+ 1))) <<
130 ((index
>> CU8(base
+ 2)) &
131 (0xFFFFFFFF >> (32 - CU8(base
+ 1)))) << CU8(base
+
135 case ATOM_IIO_MOVE_DATA
:
137 ~((0xFFFFFFFF >> (32 - CU8(base
+ 1))) <<
140 ((data
>> CU8(base
+ 2)) &
141 (0xFFFFFFFF >> (32 - CU8(base
+ 1)))) << CU8(base
+
145 case ATOM_IIO_MOVE_ATTR
:
147 ~((0xFFFFFFFF >> (32 - CU8(base
+ 1))) <<
151 io_attr
>> CU8(base
+ 2)) & (0xFFFFFFFF >> (32 -
162 printk(KERN_INFO
"Unknown IIO opcode.\n");
167 static uint32_t atom_get_src_int(atom_exec_context
*ctx
, uint8_t attr
,
168 int *ptr
, uint32_t *saved
, int print
)
170 uint32_t idx
, val
= 0xCDCDCDCD, align
, arg
;
171 struct atom_context
*gctx
= ctx
->ctx
;
173 align
= (attr
>> 3) & 7;
179 DEBUG("REG[0x%04X]", idx
);
180 idx
+= gctx
->reg_block
;
181 switch (gctx
->io_mode
) {
183 val
= gctx
->card
->reg_read(gctx
->card
, idx
);
187 "PCI registers are not implemented.\n");
191 "SYSIO registers are not implemented.\n");
194 if (!(gctx
->io_mode
& 0x80)) {
195 printk(KERN_INFO
"Bad IO mode.\n");
198 if (!gctx
->iio
[gctx
->io_mode
& 0x7F]) {
200 "Undefined indirect IO read method %d.\n",
201 gctx
->io_mode
& 0x7F);
205 atom_iio_execute(gctx
,
206 gctx
->iio
[gctx
->io_mode
& 0x7F],
213 val
= le32_to_cpu(ctx
->ps
[idx
]);
215 DEBUG("PS[0x%02X,0x%04X]", idx
, val
);
221 DEBUG("WS[0x%02X]", idx
);
223 case ATOM_WS_QUOTIENT
:
224 val
= gctx
->divmul
[0];
226 case ATOM_WS_REMAINDER
:
227 val
= gctx
->divmul
[1];
229 case ATOM_WS_DATAPTR
:
230 val
= gctx
->data_block
;
235 case ATOM_WS_OR_MASK
:
236 val
= 1 << gctx
->shift
;
238 case ATOM_WS_AND_MASK
:
239 val
= ~(1 << gctx
->shift
);
241 case ATOM_WS_FB_WINDOW
:
244 case ATOM_WS_ATTRIBUTES
:
255 if (gctx
->data_block
)
256 DEBUG("ID[0x%04X+%04X]", idx
, gctx
->data_block
);
258 DEBUG("ID[0x%04X]", idx
);
260 val
= U32(idx
+ gctx
->data_block
);
266 DEBUG("FB[0x%02X]", idx
);
267 printk(KERN_INFO
"FB access is not implemented.\n");
275 DEBUG("IMM 0x%08X\n", val
);
279 case ATOM_SRC_WORD16
:
283 DEBUG("IMM 0x%04X\n", val
);
287 case ATOM_SRC_BYTE16
:
288 case ATOM_SRC_BYTE24
:
292 DEBUG("IMM 0x%02X\n", val
);
300 DEBUG("PLL[0x%02X]", idx
);
301 val
= gctx
->card
->pll_read(gctx
->card
, idx
);
307 DEBUG("MC[0x%02X]", idx
);
308 val
= gctx
->card
->mc_read(gctx
->card
, idx
);
313 val
&= atom_arg_mask
[align
];
314 val
>>= atom_arg_shift
[align
];
318 DEBUG(".[31:0] -> 0x%08X\n", val
);
321 DEBUG(".[15:0] -> 0x%04X\n", val
);
324 DEBUG(".[23:8] -> 0x%04X\n", val
);
326 case ATOM_SRC_WORD16
:
327 DEBUG(".[31:16] -> 0x%04X\n", val
);
330 DEBUG(".[7:0] -> 0x%02X\n", val
);
333 DEBUG(".[15:8] -> 0x%02X\n", val
);
335 case ATOM_SRC_BYTE16
:
336 DEBUG(".[23:16] -> 0x%02X\n", val
);
338 case ATOM_SRC_BYTE24
:
339 DEBUG(".[31:24] -> 0x%02X\n", val
);
345 static void atom_skip_src_int(atom_exec_context
*ctx
, uint8_t attr
, int *ptr
)
347 uint32_t align
= (attr
>> 3) & 7, arg
= attr
& 7;
367 case ATOM_SRC_WORD16
:
372 case ATOM_SRC_BYTE16
:
373 case ATOM_SRC_BYTE24
:
381 static uint32_t atom_get_src(atom_exec_context
*ctx
, uint8_t attr
, int *ptr
)
383 return atom_get_src_int(ctx
, attr
, ptr
, NULL
, 1);
386 static uint32_t atom_get_dst(atom_exec_context
*ctx
, int arg
, uint8_t attr
,
387 int *ptr
, uint32_t *saved
, int print
)
389 return atom_get_src_int(ctx
,
390 arg
| atom_dst_to_src
[(attr
>> 3) &
391 7][(attr
>> 6) & 3] << 3,
395 static void atom_skip_dst(atom_exec_context
*ctx
, int arg
, uint8_t attr
, int *ptr
)
397 atom_skip_src_int(ctx
,
398 arg
| atom_dst_to_src
[(attr
>> 3) & 7][(attr
>> 6) &
402 static void atom_put_dst(atom_exec_context
*ctx
, int arg
, uint8_t attr
,
403 int *ptr
, uint32_t val
, uint32_t saved
)
406 atom_dst_to_src
[(attr
>> 3) & 7][(attr
>> 6) & 3], old_val
=
408 struct atom_context
*gctx
= ctx
->ctx
;
409 old_val
&= atom_arg_mask
[align
] >> atom_arg_shift
[align
];
410 val
<<= atom_arg_shift
[align
];
411 val
&= atom_arg_mask
[align
];
412 saved
&= ~atom_arg_mask
[align
];
418 DEBUG("REG[0x%04X]", idx
);
419 idx
+= gctx
->reg_block
;
420 switch (gctx
->io_mode
) {
423 gctx
->card
->reg_write(gctx
->card
, idx
,
426 gctx
->card
->reg_write(gctx
->card
, idx
, val
);
430 "PCI registers are not implemented.\n");
434 "SYSIO registers are not implemented.\n");
437 if (!(gctx
->io_mode
& 0x80)) {
438 printk(KERN_INFO
"Bad IO mode.\n");
441 if (!gctx
->iio
[gctx
->io_mode
& 0xFF]) {
443 "Undefined indirect IO write method %d.\n",
444 gctx
->io_mode
& 0x7F);
447 atom_iio_execute(gctx
, gctx
->iio
[gctx
->io_mode
& 0xFF],
454 DEBUG("PS[0x%02X]", idx
);
455 ctx
->ps
[idx
] = cpu_to_le32(val
);
460 DEBUG("WS[0x%02X]", idx
);
462 case ATOM_WS_QUOTIENT
:
463 gctx
->divmul
[0] = val
;
465 case ATOM_WS_REMAINDER
:
466 gctx
->divmul
[1] = val
;
468 case ATOM_WS_DATAPTR
:
469 gctx
->data_block
= val
;
474 case ATOM_WS_OR_MASK
:
475 case ATOM_WS_AND_MASK
:
477 case ATOM_WS_FB_WINDOW
:
480 case ATOM_WS_ATTRIBUTES
:
490 DEBUG("FB[0x%02X]", idx
);
491 printk(KERN_INFO
"FB access is not implemented.\n");
496 DEBUG("PLL[0x%02X]", idx
);
497 gctx
->card
->pll_write(gctx
->card
, idx
, val
);
502 DEBUG("MC[0x%02X]", idx
);
503 gctx
->card
->mc_write(gctx
->card
, idx
, val
);
508 DEBUG(".[31:0] <- 0x%08X\n", old_val
);
511 DEBUG(".[15:0] <- 0x%04X\n", old_val
);
514 DEBUG(".[23:8] <- 0x%04X\n", old_val
);
516 case ATOM_SRC_WORD16
:
517 DEBUG(".[31:16] <- 0x%04X\n", old_val
);
520 DEBUG(".[7:0] <- 0x%02X\n", old_val
);
523 DEBUG(".[15:8] <- 0x%02X\n", old_val
);
525 case ATOM_SRC_BYTE16
:
526 DEBUG(".[23:16] <- 0x%02X\n", old_val
);
528 case ATOM_SRC_BYTE24
:
529 DEBUG(".[31:24] <- 0x%02X\n", old_val
);
534 static void atom_op_add(atom_exec_context
*ctx
, int *ptr
, int arg
)
536 uint8_t attr
= U8((*ptr
)++);
537 uint32_t dst
, src
, saved
;
540 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
542 src
= atom_get_src(ctx
, attr
, ptr
);
545 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
548 static void atom_op_and(atom_exec_context
*ctx
, int *ptr
, int arg
)
550 uint8_t attr
= U8((*ptr
)++);
551 uint32_t dst
, src
, saved
;
554 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
556 src
= atom_get_src(ctx
, attr
, ptr
);
559 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
562 static void atom_op_beep(atom_exec_context
*ctx
, int *ptr
, int arg
)
564 printk("ATOM BIOS beeped!\n");
567 static void atom_op_calltable(atom_exec_context
*ctx
, int *ptr
, int arg
)
569 int idx
= U8((*ptr
)++);
570 if (idx
< ATOM_TABLE_NAMES_CNT
)
571 SDEBUG(" table: %d (%s)\n", idx
, atom_table_names
[idx
]);
573 SDEBUG(" table: %d\n", idx
);
574 if (U16(ctx
->ctx
->cmd_table
+ 4 + 2 * idx
))
575 atom_execute_table(ctx
->ctx
, idx
, ctx
->ps
+ ctx
->ps_shift
);
578 static void atom_op_clear(atom_exec_context
*ctx
, int *ptr
, int arg
)
580 uint8_t attr
= U8((*ptr
)++);
584 attr
|= atom_def_dst
[attr
>> 3] << 6;
585 atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 0);
587 atom_put_dst(ctx
, arg
, attr
, &dptr
, 0, saved
);
590 static void atom_op_compare(atom_exec_context
*ctx
, int *ptr
, int arg
)
592 uint8_t attr
= U8((*ptr
)++);
595 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, NULL
, 1);
597 src
= atom_get_src(ctx
, attr
, ptr
);
598 ctx
->ctx
->cs_equal
= (dst
== src
);
599 ctx
->ctx
->cs_above
= (dst
> src
);
600 SDEBUG(" result: %s %s\n", ctx
->ctx
->cs_equal
? "EQ" : "NE",
601 ctx
->ctx
->cs_above
? "GT" : "LE");
604 static void atom_op_delay(atom_exec_context
*ctx
, int *ptr
, int arg
)
606 uint8_t count
= U8((*ptr
)++);
607 SDEBUG(" count: %d\n", count
);
608 if (arg
== ATOM_UNIT_MICROSEC
)
609 schedule_timeout_uninterruptible(usecs_to_jiffies(count
));
611 schedule_timeout_uninterruptible(msecs_to_jiffies(count
));
614 static void atom_op_div(atom_exec_context
*ctx
, int *ptr
, int arg
)
616 uint8_t attr
= U8((*ptr
)++);
619 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, NULL
, 1);
621 src
= atom_get_src(ctx
, attr
, ptr
);
623 ctx
->ctx
->divmul
[0] = dst
/ src
;
624 ctx
->ctx
->divmul
[1] = dst
% src
;
626 ctx
->ctx
->divmul
[0] = 0;
627 ctx
->ctx
->divmul
[1] = 0;
631 static void atom_op_eot(atom_exec_context
*ctx
, int *ptr
, int arg
)
633 /* functionally, a nop */
636 static void atom_op_jump(atom_exec_context
*ctx
, int *ptr
, int arg
)
638 int execute
= 0, target
= U16(*ptr
);
641 case ATOM_COND_ABOVE
:
642 execute
= ctx
->ctx
->cs_above
;
644 case ATOM_COND_ABOVEOREQUAL
:
645 execute
= ctx
->ctx
->cs_above
|| ctx
->ctx
->cs_equal
;
647 case ATOM_COND_ALWAYS
:
650 case ATOM_COND_BELOW
:
651 execute
= !(ctx
->ctx
->cs_above
|| ctx
->ctx
->cs_equal
);
653 case ATOM_COND_BELOWOREQUAL
:
654 execute
= !ctx
->ctx
->cs_above
;
656 case ATOM_COND_EQUAL
:
657 execute
= ctx
->ctx
->cs_equal
;
659 case ATOM_COND_NOTEQUAL
:
660 execute
= !ctx
->ctx
->cs_equal
;
663 if (arg
!= ATOM_COND_ALWAYS
)
664 SDEBUG(" taken: %s\n", execute
? "yes" : "no");
665 SDEBUG(" target: 0x%04X\n", target
);
667 *ptr
= ctx
->start
+ target
;
670 static void atom_op_mask(atom_exec_context
*ctx
, int *ptr
, int arg
)
672 uint8_t attr
= U8((*ptr
)++);
673 uint32_t dst
, src1
, src2
, saved
;
676 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
678 src1
= atom_get_src(ctx
, attr
, ptr
);
680 src2
= atom_get_src(ctx
, attr
, ptr
);
684 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
687 static void atom_op_move(atom_exec_context
*ctx
, int *ptr
, int arg
)
689 uint8_t attr
= U8((*ptr
)++);
692 if (((attr
>> 3) & 7) != ATOM_SRC_DWORD
)
693 atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 0);
695 atom_skip_dst(ctx
, arg
, attr
, ptr
);
699 src
= atom_get_src(ctx
, attr
, ptr
);
701 atom_put_dst(ctx
, arg
, attr
, &dptr
, src
, saved
);
704 static void atom_op_mul(atom_exec_context
*ctx
, int *ptr
, int arg
)
706 uint8_t attr
= U8((*ptr
)++);
709 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, NULL
, 1);
711 src
= atom_get_src(ctx
, attr
, ptr
);
712 ctx
->ctx
->divmul
[0] = dst
* src
;
715 static void atom_op_nop(atom_exec_context
*ctx
, int *ptr
, int arg
)
720 static void atom_op_or(atom_exec_context
*ctx
, int *ptr
, int arg
)
722 uint8_t attr
= U8((*ptr
)++);
723 uint32_t dst
, src
, saved
;
726 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
728 src
= atom_get_src(ctx
, attr
, ptr
);
731 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
734 static void atom_op_postcard(atom_exec_context
*ctx
, int *ptr
, int arg
)
736 uint8_t val
= U8((*ptr
)++);
737 SDEBUG("POST card output: 0x%02X\n", val
);
740 static void atom_op_repeat(atom_exec_context
*ctx
, int *ptr
, int arg
)
742 printk(KERN_INFO
"unimplemented!\n");
745 static void atom_op_restorereg(atom_exec_context
*ctx
, int *ptr
, int arg
)
747 printk(KERN_INFO
"unimplemented!\n");
750 static void atom_op_savereg(atom_exec_context
*ctx
, int *ptr
, int arg
)
752 printk(KERN_INFO
"unimplemented!\n");
755 static void atom_op_setdatablock(atom_exec_context
*ctx
, int *ptr
, int arg
)
759 SDEBUG(" block: %d\n", idx
);
761 ctx
->ctx
->data_block
= 0;
763 ctx
->ctx
->data_block
= ctx
->start
;
765 ctx
->ctx
->data_block
= U16(ctx
->ctx
->data_table
+ 4 + 2 * idx
);
766 SDEBUG(" base: 0x%04X\n", ctx
->ctx
->data_block
);
769 static void atom_op_setfbbase(atom_exec_context
*ctx
, int *ptr
, int arg
)
771 uint8_t attr
= U8((*ptr
)++);
772 SDEBUG(" fb_base: ");
773 ctx
->ctx
->fb_base
= atom_get_src(ctx
, attr
, ptr
);
776 static void atom_op_setport(atom_exec_context
*ctx
, int *ptr
, int arg
)
782 if (port
< ATOM_IO_NAMES_CNT
)
783 SDEBUG(" port: %d (%s)\n", port
, atom_io_names
[port
]);
785 SDEBUG(" port: %d\n", port
);
787 ctx
->ctx
->io_mode
= ATOM_IO_MM
;
789 ctx
->ctx
->io_mode
= ATOM_IO_IIO
| port
;
793 ctx
->ctx
->io_mode
= ATOM_IO_PCI
;
796 case ATOM_PORT_SYSIO
:
797 ctx
->ctx
->io_mode
= ATOM_IO_SYSIO
;
803 static void atom_op_setregblock(atom_exec_context
*ctx
, int *ptr
, int arg
)
805 ctx
->ctx
->reg_block
= U16(*ptr
);
807 SDEBUG(" base: 0x%04X\n", ctx
->ctx
->reg_block
);
810 static void atom_op_shl(atom_exec_context
*ctx
, int *ptr
, int arg
)
812 uint8_t attr
= U8((*ptr
)++), shift
;
816 attr
|= atom_def_dst
[attr
>> 3] << 6;
818 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
819 shift
= U8((*ptr
)++);
820 SDEBUG(" shift: %d\n", shift
);
823 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
826 static void atom_op_shr(atom_exec_context
*ctx
, int *ptr
, int arg
)
828 uint8_t attr
= U8((*ptr
)++), shift
;
832 attr
|= atom_def_dst
[attr
>> 3] << 6;
834 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
835 shift
= U8((*ptr
)++);
836 SDEBUG(" shift: %d\n", shift
);
839 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
842 static void atom_op_sub(atom_exec_context
*ctx
, int *ptr
, int arg
)
844 uint8_t attr
= U8((*ptr
)++);
845 uint32_t dst
, src
, saved
;
848 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
850 src
= atom_get_src(ctx
, attr
, ptr
);
853 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
856 static void atom_op_switch(atom_exec_context
*ctx
, int *ptr
, int arg
)
858 uint8_t attr
= U8((*ptr
)++);
859 uint32_t src
, val
, target
;
861 src
= atom_get_src(ctx
, attr
, ptr
);
862 while (U16(*ptr
) != ATOM_CASE_END
)
863 if (U8(*ptr
) == ATOM_CASE_MAGIC
) {
867 atom_get_src(ctx
, (attr
& 0x38) | ATOM_ARG_IMM
,
871 SDEBUG(" target: %04X\n", target
);
872 *ptr
= ctx
->start
+ target
;
877 printk(KERN_INFO
"Bad case.\n");
883 static void atom_op_test(atom_exec_context
*ctx
, int *ptr
, int arg
)
885 uint8_t attr
= U8((*ptr
)++);
888 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, NULL
, 1);
890 src
= atom_get_src(ctx
, attr
, ptr
);
891 ctx
->ctx
->cs_equal
= ((dst
& src
) == 0);
892 SDEBUG(" result: %s\n", ctx
->ctx
->cs_equal
? "EQ" : "NE");
895 static void atom_op_xor(atom_exec_context
*ctx
, int *ptr
, int arg
)
897 uint8_t attr
= U8((*ptr
)++);
898 uint32_t dst
, src
, saved
;
901 dst
= atom_get_dst(ctx
, arg
, attr
, ptr
, &saved
, 1);
903 src
= atom_get_src(ctx
, attr
, ptr
);
906 atom_put_dst(ctx
, arg
, attr
, &dptr
, dst
, saved
);
909 static void atom_op_debug(atom_exec_context
*ctx
, int *ptr
, int arg
)
911 printk(KERN_INFO
"unimplemented!\n");
915 void (*func
) (atom_exec_context
*, int *, int);
917 } opcode_table
[ATOM_OP_CNT
] = {
920 atom_op_move
, ATOM_ARG_REG
}, {
921 atom_op_move
, ATOM_ARG_PS
}, {
922 atom_op_move
, ATOM_ARG_WS
}, {
923 atom_op_move
, ATOM_ARG_FB
}, {
924 atom_op_move
, ATOM_ARG_PLL
}, {
925 atom_op_move
, ATOM_ARG_MC
}, {
926 atom_op_and
, ATOM_ARG_REG
}, {
927 atom_op_and
, ATOM_ARG_PS
}, {
928 atom_op_and
, ATOM_ARG_WS
}, {
929 atom_op_and
, ATOM_ARG_FB
}, {
930 atom_op_and
, ATOM_ARG_PLL
}, {
931 atom_op_and
, ATOM_ARG_MC
}, {
932 atom_op_or
, ATOM_ARG_REG
}, {
933 atom_op_or
, ATOM_ARG_PS
}, {
934 atom_op_or
, ATOM_ARG_WS
}, {
935 atom_op_or
, ATOM_ARG_FB
}, {
936 atom_op_or
, ATOM_ARG_PLL
}, {
937 atom_op_or
, ATOM_ARG_MC
}, {
938 atom_op_shl
, ATOM_ARG_REG
}, {
939 atom_op_shl
, ATOM_ARG_PS
}, {
940 atom_op_shl
, ATOM_ARG_WS
}, {
941 atom_op_shl
, ATOM_ARG_FB
}, {
942 atom_op_shl
, ATOM_ARG_PLL
}, {
943 atom_op_shl
, ATOM_ARG_MC
}, {
944 atom_op_shr
, ATOM_ARG_REG
}, {
945 atom_op_shr
, ATOM_ARG_PS
}, {
946 atom_op_shr
, ATOM_ARG_WS
}, {
947 atom_op_shr
, ATOM_ARG_FB
}, {
948 atom_op_shr
, ATOM_ARG_PLL
}, {
949 atom_op_shr
, ATOM_ARG_MC
}, {
950 atom_op_mul
, ATOM_ARG_REG
}, {
951 atom_op_mul
, ATOM_ARG_PS
}, {
952 atom_op_mul
, ATOM_ARG_WS
}, {
953 atom_op_mul
, ATOM_ARG_FB
}, {
954 atom_op_mul
, ATOM_ARG_PLL
}, {
955 atom_op_mul
, ATOM_ARG_MC
}, {
956 atom_op_div
, ATOM_ARG_REG
}, {
957 atom_op_div
, ATOM_ARG_PS
}, {
958 atom_op_div
, ATOM_ARG_WS
}, {
959 atom_op_div
, ATOM_ARG_FB
}, {
960 atom_op_div
, ATOM_ARG_PLL
}, {
961 atom_op_div
, ATOM_ARG_MC
}, {
962 atom_op_add
, ATOM_ARG_REG
}, {
963 atom_op_add
, ATOM_ARG_PS
}, {
964 atom_op_add
, ATOM_ARG_WS
}, {
965 atom_op_add
, ATOM_ARG_FB
}, {
966 atom_op_add
, ATOM_ARG_PLL
}, {
967 atom_op_add
, ATOM_ARG_MC
}, {
968 atom_op_sub
, ATOM_ARG_REG
}, {
969 atom_op_sub
, ATOM_ARG_PS
}, {
970 atom_op_sub
, ATOM_ARG_WS
}, {
971 atom_op_sub
, ATOM_ARG_FB
}, {
972 atom_op_sub
, ATOM_ARG_PLL
}, {
973 atom_op_sub
, ATOM_ARG_MC
}, {
974 atom_op_setport
, ATOM_PORT_ATI
}, {
975 atom_op_setport
, ATOM_PORT_PCI
}, {
976 atom_op_setport
, ATOM_PORT_SYSIO
}, {
977 atom_op_setregblock
, 0}, {
978 atom_op_setfbbase
, 0}, {
979 atom_op_compare
, ATOM_ARG_REG
}, {
980 atom_op_compare
, ATOM_ARG_PS
}, {
981 atom_op_compare
, ATOM_ARG_WS
}, {
982 atom_op_compare
, ATOM_ARG_FB
}, {
983 atom_op_compare
, ATOM_ARG_PLL
}, {
984 atom_op_compare
, ATOM_ARG_MC
}, {
985 atom_op_switch
, 0}, {
986 atom_op_jump
, ATOM_COND_ALWAYS
}, {
987 atom_op_jump
, ATOM_COND_EQUAL
}, {
988 atom_op_jump
, ATOM_COND_BELOW
}, {
989 atom_op_jump
, ATOM_COND_ABOVE
}, {
990 atom_op_jump
, ATOM_COND_BELOWOREQUAL
}, {
991 atom_op_jump
, ATOM_COND_ABOVEOREQUAL
}, {
992 atom_op_jump
, ATOM_COND_NOTEQUAL
}, {
993 atom_op_test
, ATOM_ARG_REG
}, {
994 atom_op_test
, ATOM_ARG_PS
}, {
995 atom_op_test
, ATOM_ARG_WS
}, {
996 atom_op_test
, ATOM_ARG_FB
}, {
997 atom_op_test
, ATOM_ARG_PLL
}, {
998 atom_op_test
, ATOM_ARG_MC
}, {
999 atom_op_delay
, ATOM_UNIT_MILLISEC
}, {
1000 atom_op_delay
, ATOM_UNIT_MICROSEC
}, {
1001 atom_op_calltable
, 0}, {
1002 atom_op_repeat
, 0}, {
1003 atom_op_clear
, ATOM_ARG_REG
}, {
1004 atom_op_clear
, ATOM_ARG_PS
}, {
1005 atom_op_clear
, ATOM_ARG_WS
}, {
1006 atom_op_clear
, ATOM_ARG_FB
}, {
1007 atom_op_clear
, ATOM_ARG_PLL
}, {
1008 atom_op_clear
, ATOM_ARG_MC
}, {
1011 atom_op_mask
, ATOM_ARG_REG
}, {
1012 atom_op_mask
, ATOM_ARG_PS
}, {
1013 atom_op_mask
, ATOM_ARG_WS
}, {
1014 atom_op_mask
, ATOM_ARG_FB
}, {
1015 atom_op_mask
, ATOM_ARG_PLL
}, {
1016 atom_op_mask
, ATOM_ARG_MC
}, {
1017 atom_op_postcard
, 0}, {
1019 atom_op_savereg
, 0}, {
1020 atom_op_restorereg
, 0}, {
1021 atom_op_setdatablock
, 0}, {
1022 atom_op_xor
, ATOM_ARG_REG
}, {
1023 atom_op_xor
, ATOM_ARG_PS
}, {
1024 atom_op_xor
, ATOM_ARG_WS
}, {
1025 atom_op_xor
, ATOM_ARG_FB
}, {
1026 atom_op_xor
, ATOM_ARG_PLL
}, {
1027 atom_op_xor
, ATOM_ARG_MC
}, {
1028 atom_op_shl
, ATOM_ARG_REG
}, {
1029 atom_op_shl
, ATOM_ARG_PS
}, {
1030 atom_op_shl
, ATOM_ARG_WS
}, {
1031 atom_op_shl
, ATOM_ARG_FB
}, {
1032 atom_op_shl
, ATOM_ARG_PLL
}, {
1033 atom_op_shl
, ATOM_ARG_MC
}, {
1034 atom_op_shr
, ATOM_ARG_REG
}, {
1035 atom_op_shr
, ATOM_ARG_PS
}, {
1036 atom_op_shr
, ATOM_ARG_WS
}, {
1037 atom_op_shr
, ATOM_ARG_FB
}, {
1038 atom_op_shr
, ATOM_ARG_PLL
}, {
1039 atom_op_shr
, ATOM_ARG_MC
}, {
1040 atom_op_debug
, 0},};
1042 void atom_execute_table(struct atom_context
*ctx
, int index
, uint32_t * params
)
1044 int base
= CU16(ctx
->cmd_table
+ 4 + 2 * index
);
1045 int len
, ws
, ps
, ptr
;
1047 atom_exec_context ectx
;
1052 len
= CU16(base
+ ATOM_CT_SIZE_PTR
);
1053 ws
= CU8(base
+ ATOM_CT_WS_PTR
);
1054 ps
= CU8(base
+ ATOM_CT_PS_PTR
) & ATOM_CT_PS_MASK
;
1055 ptr
= base
+ ATOM_CT_CODE_PTR
;
1057 SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base
, len
, ws
, ps
);
1059 /* reset reg block */
1062 ectx
.ps_shift
= ps
/ 4;
1066 ectx
.ws
= kzalloc(4 * ws
, GFP_KERNEL
);
1073 if (op
< ATOM_OP_NAMES_CNT
)
1074 SDEBUG("%s @ 0x%04X\n", atom_op_names
[op
], ptr
- 1);
1076 SDEBUG("[%d] @ 0x%04X\n", op
, ptr
- 1);
1078 if (op
< ATOM_OP_CNT
&& op
> 0)
1079 opcode_table
[op
].func(&ectx
, &ptr
,
1080 opcode_table
[op
].arg
);
1084 if (op
== ATOM_OP_EOT
)
1094 static int atom_iio_len
[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 };
1096 static void atom_index_iio(struct atom_context
*ctx
, int base
)
1098 ctx
->iio
= kzalloc(2 * 256, GFP_KERNEL
);
1099 while (CU8(base
) == ATOM_IIO_START
) {
1100 ctx
->iio
[CU8(base
+ 1)] = base
+ 2;
1102 while (CU8(base
) != ATOM_IIO_END
)
1103 base
+= atom_iio_len
[CU8(base
)];
1108 struct atom_context
*atom_parse(struct card_info
*card
, void *bios
)
1111 struct atom_context
*ctx
=
1112 kzalloc(sizeof(struct atom_context
), GFP_KERNEL
);
1120 if (CU16(0) != ATOM_BIOS_MAGIC
) {
1121 printk(KERN_INFO
"Invalid BIOS magic.\n");
1126 (CSTR(ATOM_ATI_MAGIC_PTR
), ATOM_ATI_MAGIC
,
1127 strlen(ATOM_ATI_MAGIC
))) {
1128 printk(KERN_INFO
"Invalid ATI magic.\n");
1133 base
= CU16(ATOM_ROM_TABLE_PTR
);
1135 (CSTR(base
+ ATOM_ROM_MAGIC_PTR
), ATOM_ROM_MAGIC
,
1136 strlen(ATOM_ROM_MAGIC
))) {
1137 printk(KERN_INFO
"Invalid ATOM magic.\n");
1142 ctx
->cmd_table
= CU16(base
+ ATOM_ROM_CMD_PTR
);
1143 ctx
->data_table
= CU16(base
+ ATOM_ROM_DATA_PTR
);
1144 atom_index_iio(ctx
, CU16(ctx
->data_table
+ ATOM_DATA_IIO_PTR
) + 4);
1146 str
= CSTR(CU16(base
+ ATOM_ROM_MSG_PTR
));
1147 while (*str
&& ((*str
== '\n') || (*str
== '\r')))
1149 /* name string isn't always 0 terminated */
1150 for (i
= 0; i
< 511; i
++) {
1152 if (name
[i
] < '.' || name
[i
] > 'z') {
1157 printk(KERN_INFO
"ATOM BIOS: %s\n", name
);
1162 int atom_asic_init(struct atom_context
*ctx
)
1164 int hwi
= CU16(ctx
->data_table
+ ATOM_DATA_FWI_PTR
);
1168 ps
[0] = cpu_to_le32(CU32(hwi
+ ATOM_FWI_DEFSCLK_PTR
));
1169 ps
[1] = cpu_to_le32(CU32(hwi
+ ATOM_FWI_DEFMCLK_PTR
));
1170 if (!ps
[0] || !ps
[1])
1173 if (!CU16(ctx
->cmd_table
+ 4 + 2 * ATOM_CMD_INIT
))
1175 atom_execute_table(ctx
, ATOM_CMD_INIT
, ps
);
1180 void atom_destroy(struct atom_context
*ctx
)
1187 void atom_parse_data_header(struct atom_context
*ctx
, int index
,
1188 uint16_t * size
, uint8_t * frev
, uint8_t * crev
,
1189 uint16_t * data_start
)
1191 int offset
= index
* 2 + 4;
1192 int idx
= CU16(ctx
->data_table
+ offset
);
1197 *frev
= CU8(idx
+ 2);
1199 *crev
= CU8(idx
+ 3);
1204 void atom_parse_cmd_header(struct atom_context
*ctx
, int index
, uint8_t * frev
,
1207 int offset
= index
* 2 + 4;
1208 int idx
= CU16(ctx
->cmd_table
+ offset
);
1211 *frev
= CU8(idx
+ 2);
1213 *crev
= CU8(idx
+ 3);