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 (void)ctx->card->reg_read(ctx->card, CU16(base + 1));
111 ctx->card->reg_write(ctx->card, CU16(base + 1), temp);
116 ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
122 (0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base +
126 case ATOM_IIO_MOVE_INDEX:
128 ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
131 ((index >> CU8(base + 2)) &
132 (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base +
136 case ATOM_IIO_MOVE_DATA:
138 ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
141 ((data >> CU8(base + 2)) &
142 (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base +
146 case ATOM_IIO_MOVE_ATTR:
148 ~((0xFFFFFFFF >> (32 - CU8(base + 1))) <<
152 io_attr >> CU8(base + 2)) & (0xFFFFFFFF >> (32 -
163 printk(KERN_INFO "Unknown IIO opcode.\n");
168 static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr,
169 int *ptr, uint32_t *saved, int print)
171 uint32_t idx, val = 0xCDCDCDCD, align, arg;
172 struct atom_context *gctx = ctx->ctx;
174 align = (attr >> 3) & 7;
180 DEBUG("REG[0x%04X]", idx);
181 idx += gctx->reg_block;
182 switch (gctx->io_mode) {
184 val = gctx->card->reg_read(gctx->card, idx);
188 "PCI registers are not implemented.\n");
192 "SYSIO registers are not implemented.\n");
195 if (!(gctx->io_mode & 0x80)) {
196 printk(KERN_INFO "Bad IO mode.\n");
199 if (!gctx->iio[gctx->io_mode & 0x7F]) {
201 "Undefined indirect IO read method %d.\n",
202 gctx->io_mode & 0x7F);
206 atom_iio_execute(gctx,
207 gctx->iio[gctx->io_mode & 0x7F],
214 val = le32_to_cpu(ctx->ps[idx]);
216 DEBUG("PS[0x%02X,0x%04X]", idx, val);
222 DEBUG("WS[0x%02X]", idx);
224 case ATOM_WS_QUOTIENT:
225 val = gctx->divmul[0];
227 case ATOM_WS_REMAINDER:
228 val = gctx->divmul[1];
230 case ATOM_WS_DATAPTR:
231 val = gctx->data_block;
236 case ATOM_WS_OR_MASK:
237 val = 1 << gctx->shift;
239 case ATOM_WS_AND_MASK:
240 val = ~(1 << gctx->shift);
242 case ATOM_WS_FB_WINDOW:
245 case ATOM_WS_ATTRIBUTES:
256 if (gctx->data_block)
257 DEBUG("ID[0x%04X+%04X]", idx, gctx->data_block);
259 DEBUG("ID[0x%04X]", idx);
261 val = U32(idx + gctx->data_block);
267 DEBUG("FB[0x%02X]", idx);
268 printk(KERN_INFO "FB access is not implemented.\n");
276 DEBUG("IMM 0x%08X\n", val);
280 case ATOM_SRC_WORD16:
284 DEBUG("IMM 0x%04X\n", val);
288 case ATOM_SRC_BYTE16:
289 case ATOM_SRC_BYTE24:
293 DEBUG("IMM 0x%02X\n", val);
301 DEBUG("PLL[0x%02X]", idx);
302 val = gctx->card->pll_read(gctx->card, idx);
308 DEBUG("MC[0x%02X]", idx);
309 val = gctx->card->mc_read(gctx->card, idx);
314 val &= atom_arg_mask[align];
315 val >>= atom_arg_shift[align];
319 DEBUG(".[31:0] -> 0x%08X\n", val);
322 DEBUG(".[15:0] -> 0x%04X\n", val);
325 DEBUG(".[23:8] -> 0x%04X\n", val);
327 case ATOM_SRC_WORD16:
328 DEBUG(".[31:16] -> 0x%04X\n", val);
331 DEBUG(".[7:0] -> 0x%02X\n", val);
334 DEBUG(".[15:8] -> 0x%02X\n", val);
336 case ATOM_SRC_BYTE16:
337 DEBUG(".[23:16] -> 0x%02X\n", val);
339 case ATOM_SRC_BYTE24:
340 DEBUG(".[31:24] -> 0x%02X\n", val);
346 static void atom_skip_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr)
348 uint32_t align = (attr >> 3) & 7, arg = attr & 7;
368 case ATOM_SRC_WORD16:
373 case ATOM_SRC_BYTE16:
374 case ATOM_SRC_BYTE24:
382 static uint32_t atom_get_src(atom_exec_context *ctx, uint8_t attr, int *ptr)
384 return atom_get_src_int(ctx, attr, ptr, NULL, 1);
387 static uint32_t atom_get_dst(atom_exec_context *ctx, int arg, uint8_t attr,
388 int *ptr, uint32_t *saved, int print)
390 return atom_get_src_int(ctx,
391 arg | atom_dst_to_src[(attr >> 3) &
392 7][(attr >> 6) & 3] << 3,
396 static void atom_skip_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr)
398 atom_skip_src_int(ctx,
399 arg | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) &
403 static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr,
404 int *ptr, uint32_t val, uint32_t saved)
407 atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3], old_val =
409 struct atom_context *gctx = ctx->ctx;
410 old_val &= atom_arg_mask[align] >> atom_arg_shift[align];
411 val <<= atom_arg_shift[align];
412 val &= atom_arg_mask[align];
413 saved &= ~atom_arg_mask[align];
419 DEBUG("REG[0x%04X]", idx);
420 idx += gctx->reg_block;
421 switch (gctx->io_mode) {
424 gctx->card->reg_write(gctx->card, idx,
427 gctx->card->reg_write(gctx->card, idx, val);
431 "PCI registers are not implemented.\n");
435 "SYSIO registers are not implemented.\n");
438 if (!(gctx->io_mode & 0x80)) {
439 printk(KERN_INFO "Bad IO mode.\n");
442 if (!gctx->iio[gctx->io_mode & 0xFF]) {
444 "Undefined indirect IO write method %d.\n",
445 gctx->io_mode & 0x7F);
448 atom_iio_execute(gctx, gctx->iio[gctx->io_mode & 0xFF],
455 DEBUG("PS[0x%02X]", idx);
456 ctx->ps[idx] = cpu_to_le32(val);
461 DEBUG("WS[0x%02X]", idx);
463 case ATOM_WS_QUOTIENT:
464 gctx->divmul[0] = val;
466 case ATOM_WS_REMAINDER:
467 gctx->divmul[1] = val;
469 case ATOM_WS_DATAPTR:
470 gctx->data_block = val;
475 case ATOM_WS_OR_MASK:
476 case ATOM_WS_AND_MASK:
478 case ATOM_WS_FB_WINDOW:
481 case ATOM_WS_ATTRIBUTES:
491 DEBUG("FB[0x%02X]", idx);
492 printk(KERN_INFO "FB access is not implemented.\n");
497 DEBUG("PLL[0x%02X]", idx);
498 gctx->card->pll_write(gctx->card, idx, val);
503 DEBUG("MC[0x%02X]", idx);
504 gctx->card->mc_write(gctx->card, idx, val);
509 DEBUG(".[31:0] <- 0x%08X\n", old_val);
512 DEBUG(".[15:0] <- 0x%04X\n", old_val);
515 DEBUG(".[23:8] <- 0x%04X\n", old_val);
517 case ATOM_SRC_WORD16:
518 DEBUG(".[31:16] <- 0x%04X\n", old_val);
521 DEBUG(".[7:0] <- 0x%02X\n", old_val);
524 DEBUG(".[15:8] <- 0x%02X\n", old_val);
526 case ATOM_SRC_BYTE16:
527 DEBUG(".[23:16] <- 0x%02X\n", old_val);
529 case ATOM_SRC_BYTE24:
530 DEBUG(".[31:24] <- 0x%02X\n", old_val);
535 static void atom_op_add(atom_exec_context *ctx, int *ptr, int arg)
537 uint8_t attr = U8((*ptr)++);
538 uint32_t dst, src, saved;
541 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
543 src = atom_get_src(ctx, attr, ptr);
546 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
549 static void atom_op_and(atom_exec_context *ctx, int *ptr, int arg)
551 uint8_t attr = U8((*ptr)++);
552 uint32_t dst, src, saved;
555 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
557 src = atom_get_src(ctx, attr, ptr);
560 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
563 static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg)
565 printk("ATOM BIOS beeped!\n");
568 static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg)
570 int idx = U8((*ptr)++);
571 if (idx < ATOM_TABLE_NAMES_CNT)
572 SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]);
574 SDEBUG(" table: %d\n", idx);
575 if (U16(ctx->ctx->cmd_table + 4 + 2 * idx))
576 atom_execute_table(ctx->ctx, idx, ctx->ps + ctx->ps_shift);
579 static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg)
581 uint8_t attr = U8((*ptr)++);
585 attr |= atom_def_dst[attr >> 3] << 6;
586 atom_get_dst(ctx, arg, attr, ptr, &saved, 0);
588 atom_put_dst(ctx, arg, attr, &dptr, 0, saved);
591 static void atom_op_compare(atom_exec_context *ctx, int *ptr, int arg)
593 uint8_t attr = U8((*ptr)++);
596 dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
598 src = atom_get_src(ctx, attr, ptr);
599 ctx->ctx->cs_equal = (dst == src);
600 ctx->ctx->cs_above = (dst > src);
601 SDEBUG(" result: %s %s\n", ctx->ctx->cs_equal ? "EQ" : "NE",
602 ctx->ctx->cs_above ? "GT" : "LE");
605 static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg)
607 uint8_t count = U8((*ptr)++);
608 SDEBUG(" count: %d\n", count);
609 if (arg == ATOM_UNIT_MICROSEC)
610 schedule_timeout_uninterruptible(usecs_to_jiffies(count));
612 schedule_timeout_uninterruptible(msecs_to_jiffies(count));
615 static void atom_op_div(atom_exec_context *ctx, int *ptr, int arg)
617 uint8_t attr = U8((*ptr)++);
620 dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
622 src = atom_get_src(ctx, attr, ptr);
624 ctx->ctx->divmul[0] = dst / src;
625 ctx->ctx->divmul[1] = dst % src;
627 ctx->ctx->divmul[0] = 0;
628 ctx->ctx->divmul[1] = 0;
632 static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg)
634 /* functionally, a nop */
637 static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg)
639 int execute = 0, target = U16(*ptr);
642 case ATOM_COND_ABOVE:
643 execute = ctx->ctx->cs_above;
645 case ATOM_COND_ABOVEOREQUAL:
646 execute = ctx->ctx->cs_above || ctx->ctx->cs_equal;
648 case ATOM_COND_ALWAYS:
651 case ATOM_COND_BELOW:
652 execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal);
654 case ATOM_COND_BELOWOREQUAL:
655 execute = !ctx->ctx->cs_above;
657 case ATOM_COND_EQUAL:
658 execute = ctx->ctx->cs_equal;
660 case ATOM_COND_NOTEQUAL:
661 execute = !ctx->ctx->cs_equal;
664 if (arg != ATOM_COND_ALWAYS)
665 SDEBUG(" taken: %s\n", execute ? "yes" : "no");
666 SDEBUG(" target: 0x%04X\n", target);
668 *ptr = ctx->start + target;
671 static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg)
673 uint8_t attr = U8((*ptr)++);
674 uint32_t dst, src1, src2, saved;
677 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
679 src1 = atom_get_src(ctx, attr, ptr);
681 src2 = atom_get_src(ctx, attr, ptr);
685 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
688 static void atom_op_move(atom_exec_context *ctx, int *ptr, int arg)
690 uint8_t attr = U8((*ptr)++);
693 if (((attr >> 3) & 7) != ATOM_SRC_DWORD)
694 atom_get_dst(ctx, arg, attr, ptr, &saved, 0);
696 atom_skip_dst(ctx, arg, attr, ptr);
700 src = atom_get_src(ctx, attr, ptr);
702 atom_put_dst(ctx, arg, attr, &dptr, src, saved);
705 static void atom_op_mul(atom_exec_context *ctx, int *ptr, int arg)
707 uint8_t attr = U8((*ptr)++);
710 dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
712 src = atom_get_src(ctx, attr, ptr);
713 ctx->ctx->divmul[0] = dst * src;
716 static void atom_op_nop(atom_exec_context *ctx, int *ptr, int arg)
721 static void atom_op_or(atom_exec_context *ctx, int *ptr, int arg)
723 uint8_t attr = U8((*ptr)++);
724 uint32_t dst, src, saved;
727 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
729 src = atom_get_src(ctx, attr, ptr);
732 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
735 static void atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg)
737 uint8_t val = U8((*ptr)++);
738 SDEBUG("POST card output: 0x%02X\n", val);
741 static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg)
743 printk(KERN_INFO "unimplemented!\n");
746 static void atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg)
748 printk(KERN_INFO "unimplemented!\n");
751 static void atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg)
753 printk(KERN_INFO "unimplemented!\n");
756 static void atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg)
760 SDEBUG(" block: %d\n", idx);
762 ctx->ctx->data_block = 0;
764 ctx->ctx->data_block = ctx->start;
766 ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2 * idx);
767 SDEBUG(" base: 0x%04X\n", ctx->ctx->data_block);
770 static void atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg)
772 uint8_t attr = U8((*ptr)++);
773 SDEBUG(" fb_base: ");
774 ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr);
777 static void atom_op_setport(atom_exec_context *ctx, int *ptr, int arg)
783 if (port < ATOM_IO_NAMES_CNT)
784 SDEBUG(" port: %d (%s)\n", port, atom_io_names[port]);
786 SDEBUG(" port: %d\n", port);
788 ctx->ctx->io_mode = ATOM_IO_MM;
790 ctx->ctx->io_mode = ATOM_IO_IIO | port;
794 ctx->ctx->io_mode = ATOM_IO_PCI;
797 case ATOM_PORT_SYSIO:
798 ctx->ctx->io_mode = ATOM_IO_SYSIO;
804 static void atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg)
806 ctx->ctx->reg_block = U16(*ptr);
808 SDEBUG(" base: 0x%04X\n", ctx->ctx->reg_block);
811 static void atom_op_shl(atom_exec_context *ctx, int *ptr, int arg)
813 uint8_t attr = U8((*ptr)++), shift;
817 attr |= atom_def_dst[attr >> 3] << 6;
819 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
820 shift = U8((*ptr)++);
821 SDEBUG(" shift: %d\n", shift);
824 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
827 static void atom_op_shr(atom_exec_context *ctx, int *ptr, int arg)
829 uint8_t attr = U8((*ptr)++), shift;
833 attr |= atom_def_dst[attr >> 3] << 6;
835 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
836 shift = U8((*ptr)++);
837 SDEBUG(" shift: %d\n", shift);
840 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
843 static void atom_op_sub(atom_exec_context *ctx, int *ptr, int arg)
845 uint8_t attr = U8((*ptr)++);
846 uint32_t dst, src, saved;
849 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
851 src = atom_get_src(ctx, attr, ptr);
854 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
857 static void atom_op_switch(atom_exec_context *ctx, int *ptr, int arg)
859 uint8_t attr = U8((*ptr)++);
860 uint32_t src, val, target;
862 src = atom_get_src(ctx, attr, ptr);
863 while (U16(*ptr) != ATOM_CASE_END)
864 if (U8(*ptr) == ATOM_CASE_MAGIC) {
868 atom_get_src(ctx, (attr & 0x38) | ATOM_ARG_IMM,
872 SDEBUG(" target: %04X\n", target);
873 *ptr = ctx->start + target;
878 printk(KERN_INFO "Bad case.\n");
884 static void atom_op_test(atom_exec_context *ctx, int *ptr, int arg)
886 uint8_t attr = U8((*ptr)++);
889 dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1);
891 src = atom_get_src(ctx, attr, ptr);
892 ctx->ctx->cs_equal = ((dst & src) == 0);
893 SDEBUG(" result: %s\n", ctx->ctx->cs_equal ? "EQ" : "NE");
896 static void atom_op_xor(atom_exec_context *ctx, int *ptr, int arg)
898 uint8_t attr = U8((*ptr)++);
899 uint32_t dst, src, saved;
902 dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1);
904 src = atom_get_src(ctx, attr, ptr);
907 atom_put_dst(ctx, arg, attr, &dptr, dst, saved);
910 static void atom_op_debug(atom_exec_context *ctx, int *ptr, int arg)
912 printk(KERN_INFO "unimplemented!\n");
916 void (*func) (atom_exec_context *, int *, int);
918 } opcode_table[ATOM_OP_CNT] = {
921 atom_op_move, ATOM_ARG_REG}, {
922 atom_op_move, ATOM_ARG_PS}, {
923 atom_op_move, ATOM_ARG_WS}, {
924 atom_op_move, ATOM_ARG_FB}, {
925 atom_op_move, ATOM_ARG_PLL}, {
926 atom_op_move, ATOM_ARG_MC}, {
927 atom_op_and, ATOM_ARG_REG}, {
928 atom_op_and, ATOM_ARG_PS}, {
929 atom_op_and, ATOM_ARG_WS}, {
930 atom_op_and, ATOM_ARG_FB}, {
931 atom_op_and, ATOM_ARG_PLL}, {
932 atom_op_and, ATOM_ARG_MC}, {
933 atom_op_or, ATOM_ARG_REG}, {
934 atom_op_or, ATOM_ARG_PS}, {
935 atom_op_or, ATOM_ARG_WS}, {
936 atom_op_or, ATOM_ARG_FB}, {
937 atom_op_or, ATOM_ARG_PLL}, {
938 atom_op_or, ATOM_ARG_MC}, {
939 atom_op_shl, ATOM_ARG_REG}, {
940 atom_op_shl, ATOM_ARG_PS}, {
941 atom_op_shl, ATOM_ARG_WS}, {
942 atom_op_shl, ATOM_ARG_FB}, {
943 atom_op_shl, ATOM_ARG_PLL}, {
944 atom_op_shl, ATOM_ARG_MC}, {
945 atom_op_shr, ATOM_ARG_REG}, {
946 atom_op_shr, ATOM_ARG_PS}, {
947 atom_op_shr, ATOM_ARG_WS}, {
948 atom_op_shr, ATOM_ARG_FB}, {
949 atom_op_shr, ATOM_ARG_PLL}, {
950 atom_op_shr, ATOM_ARG_MC}, {
951 atom_op_mul, ATOM_ARG_REG}, {
952 atom_op_mul, ATOM_ARG_PS}, {
953 atom_op_mul, ATOM_ARG_WS}, {
954 atom_op_mul, ATOM_ARG_FB}, {
955 atom_op_mul, ATOM_ARG_PLL}, {
956 atom_op_mul, ATOM_ARG_MC}, {
957 atom_op_div, ATOM_ARG_REG}, {
958 atom_op_div, ATOM_ARG_PS}, {
959 atom_op_div, ATOM_ARG_WS}, {
960 atom_op_div, ATOM_ARG_FB}, {
961 atom_op_div, ATOM_ARG_PLL}, {
962 atom_op_div, ATOM_ARG_MC}, {
963 atom_op_add, ATOM_ARG_REG}, {
964 atom_op_add, ATOM_ARG_PS}, {
965 atom_op_add, ATOM_ARG_WS}, {
966 atom_op_add, ATOM_ARG_FB}, {
967 atom_op_add, ATOM_ARG_PLL}, {
968 atom_op_add, ATOM_ARG_MC}, {
969 atom_op_sub, ATOM_ARG_REG}, {
970 atom_op_sub, ATOM_ARG_PS}, {
971 atom_op_sub, ATOM_ARG_WS}, {
972 atom_op_sub, ATOM_ARG_FB}, {
973 atom_op_sub, ATOM_ARG_PLL}, {
974 atom_op_sub, ATOM_ARG_MC}, {
975 atom_op_setport, ATOM_PORT_ATI}, {
976 atom_op_setport, ATOM_PORT_PCI}, {
977 atom_op_setport, ATOM_PORT_SYSIO}, {
978 atom_op_setregblock, 0}, {
979 atom_op_setfbbase, 0}, {
980 atom_op_compare, ATOM_ARG_REG}, {
981 atom_op_compare, ATOM_ARG_PS}, {
982 atom_op_compare, ATOM_ARG_WS}, {
983 atom_op_compare, ATOM_ARG_FB}, {
984 atom_op_compare, ATOM_ARG_PLL}, {
985 atom_op_compare, ATOM_ARG_MC}, {
986 atom_op_switch, 0}, {
987 atom_op_jump, ATOM_COND_ALWAYS}, {
988 atom_op_jump, ATOM_COND_EQUAL}, {
989 atom_op_jump, ATOM_COND_BELOW}, {
990 atom_op_jump, ATOM_COND_ABOVE}, {
991 atom_op_jump, ATOM_COND_BELOWOREQUAL}, {
992 atom_op_jump, ATOM_COND_ABOVEOREQUAL}, {
993 atom_op_jump, ATOM_COND_NOTEQUAL}, {
994 atom_op_test, ATOM_ARG_REG}, {
995 atom_op_test, ATOM_ARG_PS}, {
996 atom_op_test, ATOM_ARG_WS}, {
997 atom_op_test, ATOM_ARG_FB}, {
998 atom_op_test, ATOM_ARG_PLL}, {
999 atom_op_test, ATOM_ARG_MC}, {
1000 atom_op_delay, ATOM_UNIT_MILLISEC}, {
1001 atom_op_delay, ATOM_UNIT_MICROSEC}, {
1002 atom_op_calltable, 0}, {
1003 atom_op_repeat, 0}, {
1004 atom_op_clear, ATOM_ARG_REG}, {
1005 atom_op_clear, ATOM_ARG_PS}, {
1006 atom_op_clear, ATOM_ARG_WS}, {
1007 atom_op_clear, ATOM_ARG_FB}, {
1008 atom_op_clear, ATOM_ARG_PLL}, {
1009 atom_op_clear, ATOM_ARG_MC}, {
1012 atom_op_mask, ATOM_ARG_REG}, {
1013 atom_op_mask, ATOM_ARG_PS}, {
1014 atom_op_mask, ATOM_ARG_WS}, {
1015 atom_op_mask, ATOM_ARG_FB}, {
1016 atom_op_mask, ATOM_ARG_PLL}, {
1017 atom_op_mask, ATOM_ARG_MC}, {
1018 atom_op_postcard, 0}, {
1020 atom_op_savereg, 0}, {
1021 atom_op_restorereg, 0}, {
1022 atom_op_setdatablock, 0}, {
1023 atom_op_xor, ATOM_ARG_REG}, {
1024 atom_op_xor, ATOM_ARG_PS}, {
1025 atom_op_xor, ATOM_ARG_WS}, {
1026 atom_op_xor, ATOM_ARG_FB}, {
1027 atom_op_xor, ATOM_ARG_PLL}, {
1028 atom_op_xor, ATOM_ARG_MC}, {
1029 atom_op_shl, ATOM_ARG_REG}, {
1030 atom_op_shl, ATOM_ARG_PS}, {
1031 atom_op_shl, ATOM_ARG_WS}, {
1032 atom_op_shl, ATOM_ARG_FB}, {
1033 atom_op_shl, ATOM_ARG_PLL}, {
1034 atom_op_shl, ATOM_ARG_MC}, {
1035 atom_op_shr, ATOM_ARG_REG}, {
1036 atom_op_shr, ATOM_ARG_PS}, {
1037 atom_op_shr, ATOM_ARG_WS}, {
1038 atom_op_shr, ATOM_ARG_FB}, {
1039 atom_op_shr, ATOM_ARG_PLL}, {
1040 atom_op_shr, ATOM_ARG_MC}, {
1041 atom_op_debug, 0},};
1043 void atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
1045 int base = CU16(ctx->cmd_table + 4 + 2 * index);
1046 int len, ws, ps, ptr;
1048 atom_exec_context ectx;
1053 len = CU16(base + ATOM_CT_SIZE_PTR);
1054 ws = CU8(base + ATOM_CT_WS_PTR);
1055 ps = CU8(base + ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK;
1056 ptr = base + ATOM_CT_CODE_PTR;
1058 SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base, len, ws, ps);
1060 /* reset reg block */
1063 ectx.ps_shift = ps / 4;
1067 ectx.ws = kzalloc(4 * ws, GFP_KERNEL);
1074 if (op < ATOM_OP_NAMES_CNT)
1075 SDEBUG("%s @ 0x%04X\n", atom_op_names[op], ptr - 1);
1077 SDEBUG("[%d] @ 0x%04X\n", op, ptr - 1);
1079 if (op < ATOM_OP_CNT && op > 0)
1080 opcode_table[op].func(&ectx, &ptr,
1081 opcode_table[op].arg);
1085 if (op == ATOM_OP_EOT)
1095 static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 };
1097 static void atom_index_iio(struct atom_context *ctx, int base)
1099 ctx->iio = kzalloc(2 * 256, GFP_KERNEL);
1100 while (CU8(base) == ATOM_IIO_START) {
1101 ctx->iio[CU8(base + 1)] = base + 2;
1103 while (CU8(base) != ATOM_IIO_END)
1104 base += atom_iio_len[CU8(base)];
1109 struct atom_context *atom_parse(struct card_info *card, void *bios)
1112 struct atom_context *ctx =
1113 kzalloc(sizeof(struct atom_context), GFP_KERNEL);
1121 if (CU16(0) != ATOM_BIOS_MAGIC) {
1122 printk(KERN_INFO "Invalid BIOS magic.\n");
1127 (CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC,
1128 strlen(ATOM_ATI_MAGIC))) {
1129 printk(KERN_INFO "Invalid ATI magic.\n");
1134 base = CU16(ATOM_ROM_TABLE_PTR);
1136 (CSTR(base + ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC,
1137 strlen(ATOM_ROM_MAGIC))) {
1138 printk(KERN_INFO "Invalid ATOM magic.\n");
1143 ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR);
1144 ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR);
1145 atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4);
1147 str = CSTR(CU16(base + ATOM_ROM_MSG_PTR));
1148 while (*str && ((*str == '\n') || (*str == '\r')))
1150 /* name string isn't always 0 terminated */
1151 for (i = 0; i < 511; i++) {
1153 if (name[i] < '.' || name[i] > 'z') {
1158 printk(KERN_INFO "ATOM BIOS: %s\n", name);
1163 int atom_asic_init(struct atom_context *ctx)
1165 int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR);
1169 ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR));
1170 ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR));
1171 if (!ps[0] || !ps[1])
1174 if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT))
1176 atom_execute_table(ctx, ATOM_CMD_INIT, ps);
1181 void atom_destroy(struct atom_context *ctx)
1188 void atom_parse_data_header(struct atom_context *ctx, int index,
1189 uint16_t * size, uint8_t * frev, uint8_t * crev,
1190 uint16_t * data_start)
1192 int offset = index * 2 + 4;
1193 int idx = CU16(ctx->data_table + offset);
1198 *frev = CU8(idx + 2);
1200 *crev = CU8(idx + 3);
1205 void atom_parse_cmd_header(struct atom_context *ctx, int index, uint8_t * frev,
1208 int offset = index * 2 + 4;
1209 int idx = CU16(ctx->cmd_table + offset);
1212 *frev = CU8(idx + 2);
1214 *crev = CU8(idx + 3);