diff --git a/src/add-ons/accelerants/radeon_hd/Jamfile b/src/add-ons/accelerants/radeon_hd/Jamfile index dbb86e5983..c6ce582dda 100644 --- a/src/add-ons/accelerants/radeon_hd/Jamfile +++ b/src/add-ons/accelerants/radeon_hd/Jamfile @@ -9,7 +9,7 @@ UsePrivateHeaders [ FDirName graphics radeon_hd ] ; UsePrivateHeaders [ FDirName graphics common ] ; Addon radeon_hd.accelerant : - #atombios/atom.c + atombios/atom.cpp accelerant.cpp engine.cpp hooks.cpp diff --git a/src/add-ons/accelerants/radeon_hd/accelerant.cpp b/src/add-ons/accelerants/radeon_hd/accelerant.cpp index 55d44c10f4..e721c5c646 100644 --- a/src/add-ons/accelerants/radeon_hd/accelerant.cpp +++ b/src/add-ons/accelerants/radeon_hd/accelerant.cpp @@ -218,6 +218,9 @@ radeon_init_accelerant(int device) init_lock(&info.accelerant_lock, "radeon hd accelerant"); init_lock(&info.engine_lock, "radeon hd engine"); + // Init AtomBIOS + bios_init(); + status = detect_displays(); //if (status != B_OK) // return status; diff --git a/src/add-ons/accelerants/radeon_hd/atombios/atom-bits.h b/src/add-ons/accelerants/radeon_hd/atombios/atom-bits.h index f94d2e2721..eba08ea9dd 100644 --- a/src/add-ons/accelerants/radeon_hd/atombios/atom-bits.h +++ b/src/add-ons/accelerants/radeon_hd/atombios/atom-bits.h @@ -25,21 +25,21 @@ #ifndef ATOM_BITS_H #define ATOM_BITS_H -static inline uint8_t get_u8(void *bios, int ptr) +static inline uint8 get_u8(void *bios, int ptr) { return ((unsigned char *)bios)[ptr]; } #define U8(ptr) get_u8(ctx->ctx->bios,(ptr)) #define CU8(ptr) get_u8(ctx->bios,(ptr)) -static inline uint16_t get_u16(void *bios, int ptr) +static inline uint16 get_u16(void *bios, int ptr) { - return get_u8(bios,ptr)|(((uint16_t)get_u8(bios,ptr+1))<<8); + return get_u8(bios,ptr)|(((uint16)get_u8(bios,ptr+1))<<8); } #define U16(ptr) get_u16(ctx->ctx->bios,(ptr)) #define CU16(ptr) get_u16(ctx->bios,(ptr)) -static inline uint32_t get_u32(void *bios, int ptr) +static inline uint32 get_u32(void *bios, int ptr) { - return get_u16(bios,ptr)|(((uint32_t)get_u16(bios,ptr+2))<<16); + return get_u16(bios,ptr)|(((uint32)get_u16(bios,ptr+2))<<16); } #define U32(ptr) get_u32(ctx->ctx->bios,(ptr)) #define CU32(ptr) get_u32(ctx->bios,(ptr)) diff --git a/src/add-ons/accelerants/radeon_hd/atombios/atom.c b/src/add-ons/accelerants/radeon_hd/atombios/atom.c deleted file mode 100644 index d3952e3041..0000000000 --- a/src/add-ons/accelerants/radeon_hd/atombios/atom.c +++ /dev/null @@ -1,1114 +0,0 @@ -/* - * Copyright 2008 Advanced Micro Devices, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * Author: Stanislaw Skowronek - */ - -#ifndef __HAIKU__ -#include -#include -#endif - -#include "atom.h" -#include "atom-names.h" -#include "atom-bits.h" - -#define ATOM_COND_ABOVE 0 -#define ATOM_COND_ABOVEOREQUAL 1 -#define ATOM_COND_ALWAYS 2 -#define ATOM_COND_BELOW 3 -#define ATOM_COND_BELOWOREQUAL 4 -#define ATOM_COND_EQUAL 5 -#define ATOM_COND_NOTEQUAL 6 - -#define ATOM_PORT_ATI 0 -#define ATOM_PORT_PCI 1 -#define ATOM_PORT_SYSIO 2 - -#define ATOM_UNIT_MICROSEC 0 -#define ATOM_UNIT_MILLISEC 1 - -#define PLL_INDEX 2 -#define PLL_DATA 3 - -typedef struct { - atom_context *ctx; - - uint32_t *ps, *ws; - int ps_shift; - uint16_t start; -} atom_exec_context; - -int atom_debug = 0; -void atom_execute_table(atom_context *ctx, int index, uint32_t *params); - -static uint32_t atom_arg_mask[8] = {0xFFFFFFFF, 0xFFFF, 0xFFFF00, 0xFFFF0000, 0xFF, 0xFF00, 0xFF0000, 0xFF000000}; -static int atom_arg_shift[8] = {0, 0, 8, 16, 0, 8, 16, 24}; -static int atom_dst_to_src[8][4] = { // translate destination alignment field to the source alignment encoding - { 0, 0, 0, 0 }, - { 1, 2, 3, 0 }, - { 1, 2, 3, 0 }, - { 1, 2, 3, 0 }, - { 4, 5, 6, 7 }, - { 4, 5, 6, 7 }, - { 4, 5, 6, 7 }, - { 4, 5, 6, 7 }, -}; -static int atom_def_dst[8] = { 0, 0, 1, 2, 0, 1, 2, 3 }; - -static int debug_depth = 0; -#ifdef ATOM_DEBUG -static void debug_print_spaces(int n) -{ - while(n--) - printk(" "); -} -#define DEBUG(...) do if(atom_debug) { printk(KERN_DEBUG __VA_ARGS__); } while(0) -#define SDEBUG(...) do if(atom_debug) { printk(KERN_DEBUG); debug_print_spaces(debug_depth); printk(__VA_ARGS__); } while(0) -#else -#define DEBUG(...) do { } while(0) -#define SDEBUG(...) do { } while(0) -#endif - -static uint32_t atom_iio_execute(atom_context *ctx, int base, uint32_t index, uint32_t data) -{ - uint32_t temp = 0xCDCDCDCD; - while(1) - switch(CU8(base)) { - case ATOM_IIO_NOP: - base++; - break; - case ATOM_IIO_READ: - temp = ctx->card->reg_read(ctx->card, CU16(base+1)); - base+=3; - break; - case ATOM_IIO_WRITE: - ctx->card->reg_write(ctx->card, CU16(base+1), temp); - base+=3; - break; - case ATOM_IIO_CLEAR: - temp &= ~((0xFFFFFFFF >> (32-CU8(base+1))) << CU8(base+2)); - base+=3; - break; - case ATOM_IIO_SET: - temp |= (0xFFFFFFFF >> (32-CU8(base+1))) << CU8(base+2); - base+=3; - break; - case ATOM_IIO_MOVE_INDEX: - temp &= ~((0xFFFFFFFF >> (32-CU8(base+1))) << CU8(base+2)); - temp |= ((index >> CU8(base+2)) & (0xFFFFFFFF >> (32-CU8(base+1)))) << CU8(base+3); - base+=4; - break; - case ATOM_IIO_MOVE_DATA: - temp &= ~((0xFFFFFFFF >> (32-CU8(base+1))) << CU8(base+2)); - temp |= ((data >> CU8(base+2)) & (0xFFFFFFFF >> (32-CU8(base+1)))) << CU8(base+3); - base+=4; - break; - case ATOM_IIO_MOVE_ATTR: - temp &= ~((0xFFFFFFFF >> (32-CU8(base+1))) << CU8(base+2)); - temp |= ((ctx->io_attr >> CU8(base+2)) & (0xFFFFFFFF >> (32-CU8(base+1)))) << CU8(base+3); - base+=4; - break; - case ATOM_IIO_END: - return temp; - default: - printk(KERN_INFO "Unknown IIO opcode.\n"); - return 0; - } -} - -static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr, uint32_t *saved, int print) -{ - uint32_t idx, val = 0xCDCDCDCD, align, arg; - atom_context *gctx = ctx->ctx; - arg = attr & 7; - align = (attr >> 3) & 7; - switch(arg) { - case ATOM_ARG_REG: - idx = U16(*ptr); - (*ptr)+=2; - if(print) - DEBUG("REG[0x%04X]", idx); - idx += gctx->reg_block; - switch(gctx->io_mode) { - case ATOM_IO_MM: - val = gctx->card->reg_read(gctx->card, idx); - break; - case ATOM_IO_PCI: - printk(KERN_INFO "PCI registers are not implemented.\n"); - return 0; - case ATOM_IO_SYSIO: - printk(KERN_INFO "SYSIO registers are not implemented.\n"); - return 0; - default: - if(!(gctx->io_mode&0x80)) { - printk(KERN_INFO "Bad IO mode.\n"); - return 0; - } - if(!gctx->iio[gctx->io_mode&0x7F]) { - printk(KERN_INFO "Undefined indirect IO read method %d.\n", gctx->io_mode&0x7F); - return 0; - } - val = atom_iio_execute(gctx, gctx->iio[gctx->io_mode&0x7F], idx, 0); - } - break; - case ATOM_ARG_PS: - idx = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("PS[0x%02X]", idx); - val = ctx->ps[idx]; - break; - case ATOM_ARG_WS: - idx = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("WS[0x%02X]", idx); - switch(idx) { - case ATOM_WS_QUOTIENT: - val = gctx->divmul[0]; - break; - case ATOM_WS_REMAINDER: - val = gctx->divmul[1]; - break; - case ATOM_WS_DATAPTR: - val = gctx->data_block; - break; - case ATOM_WS_SHIFT: - val = gctx->shift; - break; - case ATOM_WS_OR_MASK: - val = 1<shift; - break; - case ATOM_WS_AND_MASK: - val = ~(1<shift); - break; - case ATOM_WS_FB_WINDOW: - val = gctx->fb_base; - break; - case ATOM_WS_ATTRIBUTES: - val = gctx->io_attr; - break; - default: - val = ctx->ws[idx]; - } - break; - case ATOM_ARG_ID: - idx = U16(*ptr); - (*ptr)+=2; - if(print) { - if(gctx->data_block) - DEBUG("ID[0x%04X+%04X]", idx, gctx->data_block); - else - DEBUG("ID[0x%04X]", idx); - } - val = U32(idx + gctx->data_block); - break; - case ATOM_ARG_FB: - idx = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("FB[0x%02X]", idx); - printk(KERN_INFO "FB access is not implemented.\n"); - return 0; - case ATOM_ARG_IMM: - switch(align) { - case ATOM_SRC_DWORD: - val = U32(*ptr); - (*ptr)+=4; - if(print) - DEBUG("IMM 0x%08X\n", val); - return val; - case ATOM_SRC_WORD0: - case ATOM_SRC_WORD8: - case ATOM_SRC_WORD16: - val = U16(*ptr); - (*ptr)+=2; - if(print) - DEBUG("IMM 0x%04X\n", val); - return val; - case ATOM_SRC_BYTE0: - case ATOM_SRC_BYTE8: - case ATOM_SRC_BYTE16: - case ATOM_SRC_BYTE24: - val = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("IMM 0x%02X\n", val); - return val; - } - return 0; - case ATOM_ARG_PLL: - idx = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("PLL[0x%02X]", idx); - gctx->card->reg_write(gctx->card, PLL_INDEX, idx); - val = gctx->card->reg_read(gctx->card, PLL_DATA); - break; - case ATOM_ARG_MC: - idx = U8(*ptr); - (*ptr)++; - if(print) - DEBUG("MC[0x%02X]", idx); - printk(KERN_INFO "MC registers are not implemented.\n"); - return 0; - } - if(saved) - *saved = val; - val &= atom_arg_mask[align]; - val >>= atom_arg_shift[align]; - if(print) - switch(align) { - case ATOM_SRC_DWORD: - DEBUG(".[31:0] -> 0x%08X\n", val); - break; - case ATOM_SRC_WORD0: - DEBUG(".[15:0] -> 0x%04X\n", val); - break; - case ATOM_SRC_WORD8: - DEBUG(".[23:8] -> 0x%04X\n", val); - break; - case ATOM_SRC_WORD16: - DEBUG(".[31:16] -> 0x%04X\n", val); - break; - case ATOM_SRC_BYTE0: - DEBUG(".[7:0] -> 0x%02X\n", val); - break; - case ATOM_SRC_BYTE8: - DEBUG(".[15:8] -> 0x%02X\n", val); - break; - case ATOM_SRC_BYTE16: - DEBUG(".[23:16] -> 0x%02X\n", val); - break; - case ATOM_SRC_BYTE24: - DEBUG(".[31:24] -> 0x%02X\n", val); - break; - } - return val; -} - -static void atom_skip_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr) -{ - uint32_t align = (attr >> 3) & 7, arg = attr & 7; - switch(arg) { - case ATOM_ARG_REG: - case ATOM_ARG_ID: - (*ptr)+=2; - break; - case ATOM_ARG_PLL: - case ATOM_ARG_MC: - case ATOM_ARG_PS: - case ATOM_ARG_WS: - case ATOM_ARG_FB: - (*ptr)++; - break; - case ATOM_ARG_IMM: - switch(align) { - case ATOM_SRC_DWORD: - (*ptr)+=4; - return; - case ATOM_SRC_WORD0: - case ATOM_SRC_WORD8: - case ATOM_SRC_WORD16: - (*ptr)+=2; - return; - case ATOM_SRC_BYTE0: - case ATOM_SRC_BYTE8: - case ATOM_SRC_BYTE16: - case ATOM_SRC_BYTE24: - (*ptr)++; - return; - } - return; - } -} - -static uint32_t atom_get_src(atom_exec_context *ctx, uint8_t attr, int *ptr) -{ - return atom_get_src_int(ctx, attr, ptr, NULL, 1); -} - -static uint32_t atom_get_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr, uint32_t *saved, int print) -{ - return atom_get_src_int(ctx, arg|atom_dst_to_src[(attr>>3)&7][(attr>>6)&3]<<3, ptr, saved, print); -} - -static void atom_skip_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr) -{ - atom_skip_src_int(ctx, arg|atom_dst_to_src[(attr>>3)&7][(attr>>6)&3]<<3, ptr); -} - -static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr, uint32_t val, uint32_t saved) -{ - uint32_t align = atom_dst_to_src[(attr>>3)&7][(attr>>6)&3], old_val = val, idx; - atom_context *gctx = ctx->ctx; - old_val &= atom_arg_mask[align] >> atom_arg_shift[align]; - val <<= atom_arg_shift[align]; - val &= atom_arg_mask[align]; - saved &= ~atom_arg_mask[align]; - val |= saved; - switch(arg) { - case ATOM_ARG_REG: - idx = U16(*ptr); - (*ptr)+=2; - DEBUG("REG[0x%04X]", idx); - idx += gctx->reg_block; - switch(gctx->io_mode) { - case ATOM_IO_MM: - if(idx == 0) - gctx->card->reg_write(gctx->card, idx, val<<2); - else - gctx->card->reg_write(gctx->card, idx, val); - break; - case ATOM_IO_PCI: - printk(KERN_INFO "PCI registers are not implemented.\n"); - return; - case ATOM_IO_SYSIO: - printk(KERN_INFO "SYSIO registers are not implemented.\n"); - return; - default: - if(!(gctx->io_mode&0x80)) { - printk(KERN_INFO "Bad IO mode.\n"); - return; - } - if(!gctx->iio[gctx->io_mode&0xFF]) { - printk(KERN_INFO "Undefined indirect IO write method %d.\n", gctx->io_mode&0x7F); - return; - } - atom_iio_execute(gctx, gctx->iio[gctx->io_mode&0xFF], idx, val); - } - break; - case ATOM_ARG_PS: - idx = U8(*ptr); - (*ptr)++; - DEBUG("PS[0x%02X]", idx); - ctx->ps[idx] = val; - break; - case ATOM_ARG_WS: - idx = U8(*ptr); - (*ptr)++; - DEBUG("WS[0x%02X]", idx); - switch(idx) { - case ATOM_WS_QUOTIENT: - gctx->divmul[0] = val; - break; - case ATOM_WS_REMAINDER: - gctx->divmul[1] = val; - break; - case ATOM_WS_DATAPTR: - gctx->data_block = val; - break; - case ATOM_WS_SHIFT: - gctx->shift = val; - break; - case ATOM_WS_OR_MASK: - case ATOM_WS_AND_MASK: - break; - case ATOM_WS_FB_WINDOW: - gctx->fb_base = val; - break; - case ATOM_WS_ATTRIBUTES: - gctx->io_attr = val; - break; - default: - ctx->ws[idx] = val; - } - break; - case ATOM_ARG_FB: - idx = U8(*ptr); - (*ptr)++; - DEBUG("FB[0x%02X]", idx); - printk(KERN_INFO "FB access is not implemented.\n"); - return; - case ATOM_ARG_PLL: - idx = U8(*ptr); - (*ptr)++; - DEBUG("PLL[0x%02X]", idx); - gctx->card->reg_write(gctx->card, PLL_INDEX, idx); - gctx->card->reg_write(gctx->card, PLL_DATA, val); - break; - case ATOM_ARG_MC: - idx = U8(*ptr); - (*ptr)++; - printk(KERN_INFO "MC registers are not implemented.\n"); - return; - } - switch(align) { - case ATOM_SRC_DWORD: - DEBUG(".[31:0] <- 0x%08X\n", old_val); - break; - case ATOM_SRC_WORD0: - DEBUG(".[15:0] <- 0x%04X\n", old_val); - break; - case ATOM_SRC_WORD8: - DEBUG(".[23:8] <- 0x%04X\n", old_val); - break; - case ATOM_SRC_WORD16: - DEBUG(".[31:16] <- 0x%04X\n", old_val); - break; - case ATOM_SRC_BYTE0: - DEBUG(".[7:0] <- 0x%02X\n", old_val); - break; - case ATOM_SRC_BYTE8: - DEBUG(".[15:8] <- 0x%02X\n", old_val); - break; - case ATOM_SRC_BYTE16: - DEBUG(".[23:16] <- 0x%02X\n", old_val); - break; - case ATOM_SRC_BYTE24: - DEBUG(".[31:24] <- 0x%02X\n", old_val); - break; - } -} - -static void atom_op_add(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - dst += src; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_and(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - dst &= src; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg) -{ - printk("ATOM BIOS beeped!\n"); -} - -static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg) -{ - int idx = U8((*ptr)++); - if(idx < ATOM_TABLE_NAMES_CNT) - SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]); - else - SDEBUG(" table: %d\n", idx); - if(U16(ctx->ctx->cmd_table + 4 + 2*idx)) - atom_execute_table(ctx->ctx, idx, ctx->ps+ctx->ps_shift); -} - -static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t saved; - int dptr = *ptr; - attr &= 0x38; - attr |= atom_def_dst[attr>>3]<<6; - atom_get_dst(ctx, arg, attr, ptr, &saved, 0); - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, 0, saved); -} - -static void atom_op_compare(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src; - SDEBUG(" src1: "); - dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); - SDEBUG(" src2: "); - src = atom_get_src(ctx, attr, ptr); - ctx->ctx->cs_equal = (dst == src); - ctx->ctx->cs_above = (dst > src); - SDEBUG(" result: %s %s\n", ctx->ctx->cs_equal?"EQ":"NE", ctx->ctx->cs_above?"GT":"LE"); -} - -static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t count = U8((*ptr)++); - SDEBUG(" count: %d\n", count); - if(arg == ATOM_UNIT_MICROSEC) - schedule_timeout_uninterruptible(usecs_to_jiffies(count)); - else - schedule_timeout_uninterruptible(msecs_to_jiffies(count)); -} - -static void atom_op_div(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src; - SDEBUG(" src1: "); - dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); - SDEBUG(" src2: "); - src = atom_get_src(ctx, attr, ptr); - if(src != 0) { - ctx->ctx->divmul[0] = dst/src; - ctx->ctx->divmul[1] = dst%src; - } else { - ctx->ctx->divmul[0] = 0; - ctx->ctx->divmul[1] = 0; - } -} - -static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg) -{ - /* functionally, a nop */ -} - -static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) -{ - int execute = 0, target = U16(*ptr); - (*ptr)+=2; - switch(arg) { - case ATOM_COND_ABOVE: - execute = ctx->ctx->cs_above; - break; - case ATOM_COND_ABOVEOREQUAL: - execute = ctx->ctx->cs_above || ctx->ctx->cs_equal; - break; - case ATOM_COND_ALWAYS: - execute = 1; - break; - case ATOM_COND_BELOW: - execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal); - break; - case ATOM_COND_BELOWOREQUAL: - execute = !ctx->ctx->cs_above; - break; - case ATOM_COND_EQUAL: - execute = ctx->ctx->cs_equal; - break; - case ATOM_COND_NOTEQUAL: - execute = !ctx->ctx->cs_equal; - break; - } - if(arg != ATOM_COND_ALWAYS) - SDEBUG(" taken: %s\n", execute?"yes":"no"); - SDEBUG(" target: 0x%04X\n", target); - if(execute) - *ptr = ctx->start+target; -} - -static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src1, src2, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src1: "); - src1 = atom_get_src(ctx, attr, ptr); - SDEBUG(" src2: "); - src2 = atom_get_src(ctx, attr, ptr); - dst &= src1; - dst |= src2; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_move(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t src, saved; - int dptr = *ptr; - if(((attr>>3)&7) != ATOM_SRC_DWORD) - atom_get_dst(ctx, arg, attr, ptr, &saved, 0); - else { - atom_skip_dst(ctx, arg, attr, ptr); - saved = 0xCDCDCDCD; - } - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, src, saved); -} - -static void atom_op_mul(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src; - SDEBUG(" src1: "); - dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); - SDEBUG(" src2: "); - src = atom_get_src(ctx, attr, ptr); - ctx->ctx->divmul[0] = dst*src; -} - -static void atom_op_nop(atom_exec_context *ctx, int *ptr, int arg) -{ - /* nothing */ -} - -static void atom_op_or(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - dst |= src; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t val = U8((*ptr)++); - SDEBUG("POST card output: 0x%02X\n", val); -} - -static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg) -{ - printk(KERN_INFO "unimplemented!\n"); -} - -static void atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg) -{ - printk(KERN_INFO "unimplemented!\n"); -} - -static void atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg) -{ - printk(KERN_INFO "unimplemented!\n"); -} - -static void atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg) -{ - int idx = U8(*ptr); - (*ptr)++; - SDEBUG(" block: %d\n", idx); - if(!idx) - ctx->ctx->data_block = 0; - else if(idx==255) - ctx->ctx->data_block = ctx->start; - else - ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2*idx); - SDEBUG(" base: 0x%04X\n", ctx->ctx->data_block); -} - -static void atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - SDEBUG(" fb_base: "); - ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr); -} - -static void atom_op_setport(atom_exec_context *ctx, int *ptr, int arg) -{ - int port; - switch(arg) { - case ATOM_PORT_ATI: - port = U16(*ptr); - if(port < ATOM_IO_NAMES_CNT) - SDEBUG(" port: %d (%s)\n", port, atom_io_names[port]); - else - SDEBUG(" port: %d\n", port); - if(!port) - ctx->ctx->io_mode = ATOM_IO_MM; - else - ctx->ctx->io_mode = ATOM_IO_IIO|port; - (*ptr)+=2; - break; - case ATOM_PORT_PCI: - ctx->ctx->io_mode = ATOM_IO_PCI; - (*ptr)++; - break; - case ATOM_PORT_SYSIO: - ctx->ctx->io_mode = ATOM_IO_SYSIO; - (*ptr)++; - break; - } -} - -static void atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg) -{ - ctx->ctx->reg_block = U16(*ptr); - (*ptr)+=2; - SDEBUG(" base: 0x%04X\n", ctx->ctx->reg_block); -} - -static void atom_op_shl(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++), shift; - uint32_t saved, dst; - int dptr = *ptr; - attr &= 0x38; - attr |= atom_def_dst[attr>>3]<<6; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - shift = U8((*ptr)++); - SDEBUG(" shift: %d\n", shift); - dst <<= shift; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_shr(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++), shift; - uint32_t saved, dst; - int dptr = *ptr; - attr &= 0x38; - attr |= atom_def_dst[attr>>3]<<6; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - shift = U8((*ptr)++); - SDEBUG(" shift: %d\n", shift); - dst >>= shift; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_sub(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - dst -= src; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_switch(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t src, val, target; - SDEBUG(" switch: "); - src = atom_get_src(ctx, attr, ptr); - while(U16(*ptr) != ATOM_CASE_END) - if(U8(*ptr) == ATOM_CASE_MAGIC) { - (*ptr)++; - SDEBUG(" case: "); - val = atom_get_src(ctx, (attr&0x38)|ATOM_ARG_IMM, ptr); - target = U16(*ptr); - if(val == src) { - SDEBUG(" target: %04X\n", target); - *ptr = ctx->start+target; - return; - } - (*ptr) += 2; - } else { - printk(KERN_INFO "Bad case.\n"); - return; - } - (*ptr) += 2; -} - -static void atom_op_test(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src; - SDEBUG(" src1: "); - dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); - SDEBUG(" src2: "); - src = atom_get_src(ctx, attr, ptr); - ctx->ctx->cs_equal = ((dst & src) == 0); - SDEBUG(" result: %s\n", ctx->ctx->cs_equal?"EQ":"NE"); -} - -static void atom_op_xor(atom_exec_context *ctx, int *ptr, int arg) -{ - uint8_t attr = U8((*ptr)++); - uint32_t dst, src, saved; - int dptr = *ptr; - SDEBUG(" dst: "); - dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); - SDEBUG(" src: "); - src = atom_get_src(ctx, attr, ptr); - dst ^= src; - SDEBUG(" dst: "); - atom_put_dst(ctx, arg, attr, &dptr, dst, saved); -} - -static void atom_op_debug(atom_exec_context *ctx, int *ptr, int arg) -{ - printk(KERN_INFO "unimplemented!\n"); -} - -static struct { - void (*func)(atom_exec_context *, int *, int); - int arg; -} opcode_table[ATOM_OP_CNT] = { - { NULL, 0 }, - { atom_op_move, ATOM_ARG_REG }, - { atom_op_move, ATOM_ARG_PS }, - { atom_op_move, ATOM_ARG_WS }, - { atom_op_move, ATOM_ARG_FB }, - { atom_op_move, ATOM_ARG_PLL }, - { atom_op_move, ATOM_ARG_MC }, - { atom_op_and, ATOM_ARG_REG }, - { atom_op_and, ATOM_ARG_PS }, - { atom_op_and, ATOM_ARG_WS }, - { atom_op_and, ATOM_ARG_FB }, - { atom_op_and, ATOM_ARG_PLL }, - { atom_op_and, ATOM_ARG_MC }, - { atom_op_or, ATOM_ARG_REG }, - { atom_op_or, ATOM_ARG_PS }, - { atom_op_or, ATOM_ARG_WS }, - { atom_op_or, ATOM_ARG_FB }, - { atom_op_or, ATOM_ARG_PLL }, - { atom_op_or, ATOM_ARG_MC }, - { atom_op_shl, ATOM_ARG_REG }, - { atom_op_shl, ATOM_ARG_PS }, - { atom_op_shl, ATOM_ARG_WS }, - { atom_op_shl, ATOM_ARG_FB }, - { atom_op_shl, ATOM_ARG_PLL }, - { atom_op_shl, ATOM_ARG_MC }, - { atom_op_shr, ATOM_ARG_REG }, - { atom_op_shr, ATOM_ARG_PS }, - { atom_op_shr, ATOM_ARG_WS }, - { atom_op_shr, ATOM_ARG_FB }, - { atom_op_shr, ATOM_ARG_PLL }, - { atom_op_shr, ATOM_ARG_MC }, - { atom_op_mul, ATOM_ARG_REG }, - { atom_op_mul, ATOM_ARG_PS }, - { atom_op_mul, ATOM_ARG_WS }, - { atom_op_mul, ATOM_ARG_FB }, - { atom_op_mul, ATOM_ARG_PLL }, - { atom_op_mul, ATOM_ARG_MC }, - { atom_op_div, ATOM_ARG_REG }, - { atom_op_div, ATOM_ARG_PS }, - { atom_op_div, ATOM_ARG_WS }, - { atom_op_div, ATOM_ARG_FB }, - { atom_op_div, ATOM_ARG_PLL }, - { atom_op_div, ATOM_ARG_MC }, - { atom_op_add, ATOM_ARG_REG }, - { atom_op_add, ATOM_ARG_PS }, - { atom_op_add, ATOM_ARG_WS }, - { atom_op_add, ATOM_ARG_FB }, - { atom_op_add, ATOM_ARG_PLL }, - { atom_op_add, ATOM_ARG_MC }, - { atom_op_sub, ATOM_ARG_REG }, - { atom_op_sub, ATOM_ARG_PS }, - { atom_op_sub, ATOM_ARG_WS }, - { atom_op_sub, ATOM_ARG_FB }, - { atom_op_sub, ATOM_ARG_PLL }, - { atom_op_sub, ATOM_ARG_MC }, - { atom_op_setport, ATOM_PORT_ATI }, - { atom_op_setport, ATOM_PORT_PCI }, - { atom_op_setport, ATOM_PORT_SYSIO }, - { atom_op_setregblock, 0 }, - { atom_op_setfbbase, 0 }, - { atom_op_compare, ATOM_ARG_REG }, - { atom_op_compare, ATOM_ARG_PS }, - { atom_op_compare, ATOM_ARG_WS }, - { atom_op_compare, ATOM_ARG_FB }, - { atom_op_compare, ATOM_ARG_PLL }, - { atom_op_compare, ATOM_ARG_MC }, - { atom_op_switch, 0 }, - { atom_op_jump, ATOM_COND_ALWAYS }, - { atom_op_jump, ATOM_COND_EQUAL }, - { atom_op_jump, ATOM_COND_BELOW }, - { atom_op_jump, ATOM_COND_ABOVE }, - { atom_op_jump, ATOM_COND_BELOWOREQUAL }, - { atom_op_jump, ATOM_COND_ABOVEOREQUAL }, - { atom_op_jump, ATOM_COND_NOTEQUAL }, - { atom_op_test, ATOM_ARG_REG }, - { atom_op_test, ATOM_ARG_PS }, - { atom_op_test, ATOM_ARG_WS }, - { atom_op_test, ATOM_ARG_FB }, - { atom_op_test, ATOM_ARG_PLL }, - { atom_op_test, ATOM_ARG_MC }, - { atom_op_delay, ATOM_UNIT_MILLISEC }, - { atom_op_delay, ATOM_UNIT_MICROSEC }, - { atom_op_calltable, 0 }, - { atom_op_repeat, 0 }, - { atom_op_clear, ATOM_ARG_REG }, - { atom_op_clear, ATOM_ARG_PS }, - { atom_op_clear, ATOM_ARG_WS }, - { atom_op_clear, ATOM_ARG_FB }, - { atom_op_clear, ATOM_ARG_PLL }, - { atom_op_clear, ATOM_ARG_MC }, - { atom_op_nop, 0 }, - { atom_op_eot, 0 }, - { atom_op_mask, ATOM_ARG_REG }, - { atom_op_mask, ATOM_ARG_PS }, - { atom_op_mask, ATOM_ARG_WS }, - { atom_op_mask, ATOM_ARG_FB }, - { atom_op_mask, ATOM_ARG_PLL }, - { atom_op_mask, ATOM_ARG_MC }, - { atom_op_postcard, 0 }, - { atom_op_beep, 0 }, - { atom_op_savereg, 0 }, - { atom_op_restorereg, 0 }, - { atom_op_setdatablock, 0 }, - { atom_op_xor, ATOM_ARG_REG }, - { atom_op_xor, ATOM_ARG_PS }, - { atom_op_xor, ATOM_ARG_WS }, - { atom_op_xor, ATOM_ARG_FB }, - { atom_op_xor, ATOM_ARG_PLL }, - { atom_op_xor, ATOM_ARG_MC }, - { atom_op_shl, ATOM_ARG_REG }, - { atom_op_shl, ATOM_ARG_PS }, - { atom_op_shl, ATOM_ARG_WS }, - { atom_op_shl, ATOM_ARG_FB }, - { atom_op_shl, ATOM_ARG_PLL }, - { atom_op_shl, ATOM_ARG_MC }, - { atom_op_shr, ATOM_ARG_REG }, - { atom_op_shr, ATOM_ARG_PS }, - { atom_op_shr, ATOM_ARG_WS }, - { atom_op_shr, ATOM_ARG_FB }, - { atom_op_shr, ATOM_ARG_PLL }, - { atom_op_shr, ATOM_ARG_MC }, - { atom_op_debug, 0 }, -}; - -void atom_execute_table(atom_context *ctx, int index, uint32_t *params) -{ - int base = CU16(ctx->cmd_table+4+2*index); - int len, ws, ps, ptr; - unsigned char op; - atom_exec_context ectx; - - if(!base) - return; - - len = CU16(base+ATOM_CT_SIZE_PTR); - ws = CU8(base+ATOM_CT_WS_PTR); - ps = CU8(base+ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK; - ptr = base+ATOM_CT_CODE_PTR; - - SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base, len, ws, ps); - - /* reset reg block */ - ctx->reg_block = 0; - ectx.ctx = ctx; - ectx.ps_shift = ps/4; - ectx.start = base; - ectx.ps = params; - if(ws) - ectx.ws = kzalloc(4*ws, GFP_KERNEL); - else - ectx.ws = NULL; - - debug_depth++; - while(1) { - op = CU8(ptr++); - if(op0) - opcode_table[op].func(&ectx, &ptr, opcode_table[op].arg); - else - break; - - if(op == ATOM_OP_EOT) - break; - } - debug_depth--; - SDEBUG("<<\n"); - - if(ws) - kfree(ectx.ws); -} - -static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; -static void atom_index_iio(atom_context *ctx, int base) -{ - ctx->iio = kzalloc(2*256, GFP_KERNEL); - while(CU8(base) == ATOM_IIO_START) { - ctx->iio[CU8(base+1)] = base+2; - base += 2; - while(CU8(base) != ATOM_IIO_END) - base += atom_iio_len[CU8(base)]; - base += 3; - } -} - -atom_context *atom_parse(card_info *card, void *bios) -{ - int base; - atom_context *ctx = kzalloc(sizeof(atom_context), GFP_KERNEL); - char *str; - - ctx->card = card; - ctx->bios = bios; - - if(CU16(0) != ATOM_BIOS_MAGIC) { - printk(KERN_INFO "Invalid BIOS magic.\n"); - kfree(ctx); - return NULL; - } - if(strncmp(CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC, strlen(ATOM_ATI_MAGIC))) { - printk(KERN_INFO "Invalid ATI magic.\n"); - kfree(ctx); - return NULL; - } - - base = CU16(ATOM_ROM_TABLE_PTR); - if(strncmp(CSTR(base+ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC, strlen(ATOM_ROM_MAGIC))) { - printk(KERN_INFO "Invalid ATOM magic.\n"); - kfree(ctx); - return NULL; - } - - ctx->cmd_table = CU16(base+ATOM_ROM_CMD_PTR); - ctx->data_table = CU16(base+ATOM_ROM_DATA_PTR); - atom_index_iio(ctx, CU16(ctx->data_table+ATOM_DATA_IIO_PTR)+4); - - str = CSTR(CU16(base+ATOM_ROM_MSG_PTR)); - while(*str && ((*str == '\n') || (*str == '\r'))) - str++; - printk(KERN_INFO "ATOM BIOS: %s", str); - - return ctx; -} - -int atom_asic_init(atom_context *ctx) -{ - int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR); - uint32_t ps[16]; - memset(ps, 0, 64); - - ps[0] = CU32(hwi + ATOM_FWI_DEFSCLK_PTR); - ps[1] = CU32(hwi + ATOM_FWI_DEFMCLK_PTR); - if(!ps[0] || !ps[1]) - return 1; - - if(!CU16(ctx->cmd_table+4+2*ATOM_CMD_INIT)) - return 1; - atom_execute_table(ctx, ATOM_CMD_INIT, ps); - - return 0; -} - -void atom_destroy(atom_context *ctx) -{ - if(ctx->iio) - kfree(ctx->iio); - kfree(ctx); -} diff --git a/src/add-ons/accelerants/radeon_hd/atombios/atom.cpp b/src/add-ons/accelerants/radeon_hd/atombios/atom.cpp new file mode 100644 index 0000000000..66fffd66bd --- /dev/null +++ b/src/add-ons/accelerants/radeon_hd/atombios/atom.cpp @@ -0,0 +1,1121 @@ +/* + * Copyright 2008 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Author: Stanislaw Skowronek + */ + +/* Reworked for the Haiku Operating System Radeon HD driver + * Author: + * Alexander von Gluck, kallisti5@unixzen.com + */ + + +#include + +#include "atom.h" +#include "atom-names.h" +#include "atom-bits.h" + + +#undef TRACE + +#define TRACE_ATOM +#ifdef TRACE_ATOM +# define TRACE(x...) _sPrintf("radeon_hd: " x) +#else +# define TRACE(x...) ; +#endif + + +#define ATOM_COND_ABOVE 0 +#define ATOM_COND_ABOVEOREQUAL 1 +#define ATOM_COND_ALWAYS 2 +#define ATOM_COND_BELOW 3 +#define ATOM_COND_BELOWOREQUAL 4 +#define ATOM_COND_EQUAL 5 +#define ATOM_COND_NOTEQUAL 6 + +#define ATOM_PORT_ATI 0 +#define ATOM_PORT_PCI 1 +#define ATOM_PORT_SYSIO 2 + +#define ATOM_UNIT_MICROSEC 0 +#define ATOM_UNIT_MILLISEC 1 + +#define PLL_INDEX 2 +#define PLL_DATA 3 + +typedef struct { + atom_context *ctx; + + uint32 *ps, *ws; + int ps_shift; + uint16 start; +} atom_exec_context; + +int atom_debug = 0; +void atom_execute_table(atom_context *ctx, int index, uint32 *params); + +static uint32 atom_arg_mask[8] = {0xFFFFFFFF, 0xFFFF, 0xFFFF00, 0xFFFF0000, + 0xFF, 0xFF00, 0xFF0000, 0xFF000000}; +static int atom_arg_shift[8] = {0, 0, 8, 16, 0, 8, 16, 24}; +static int atom_dst_to_src[8][4] = { + // translate destination alignment field to the source alignment encoding + { 0, 0, 0, 0 }, + { 1, 2, 3, 0 }, + { 1, 2, 3, 0 }, + { 1, 2, 3, 0 }, + { 4, 5, 6, 7 }, + { 4, 5, 6, 7 }, + { 4, 5, 6, 7 }, + { 4, 5, 6, 7 }, +}; +static int atom_def_dst[8] = { 0, 0, 1, 2, 0, 1, 2, 3 }; + +static int debug_depth = 0; + +static uint32 +atom_iio_execute(atom_context *ctx, int base, uint32 index, uint32 data) +{ + uint32 temp = 0xCDCDCDCD; + while (1) + switch(CU8(base)) { + case ATOM_IIO_NOP: + base++; + break; + case ATOM_IIO_READ: + temp = ctx->card->reg_read(CU16(base + 1)); + base+=3; + break; + case ATOM_IIO_WRITE: + ctx->card->reg_write(CU16(base + 1), temp); + base+=3; + break; + case ATOM_IIO_CLEAR: + temp &= ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + 2)); + base+=3; + break; + case ATOM_IIO_SET: + temp |= (0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + 2); + base+=3; + break; + case ATOM_IIO_MOVE_INDEX: + temp &= ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + 2)); + temp |= ((index >> CU8(base + 2)) + & (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + 3); + base+=4; + break; + case ATOM_IIO_MOVE_DATA: + temp &= ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + 2)); + temp |= ((data >> CU8(base + 2)) + & (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + 3); + base+=4; + break; + case ATOM_IIO_MOVE_ATTR: + temp &= ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + 2)); + temp |= ((ctx->io_attr >> CU8(base + 2)) + & (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + 3); + base+=4; + break; + case ATOM_IIO_END: + return temp; + default: + TRACE("Unknown IIO opcode.\n"); + return 0; + } +} + + +static uint32 +atom_get_src_int(atom_exec_context *ctx, uint8 attr, int *ptr, + uint32 *saved, int print) +{ + uint32 idx, val = 0xCDCDCDCD, align, arg; + atom_context *gctx = ctx->ctx; + arg = attr & 7; + align = (attr >> 3) & 7; + switch(arg) { + case ATOM_ARG_REG: + idx = U16(*ptr); + (*ptr)+=2; + idx += gctx->reg_block; + switch(gctx->io_mode) { + case ATOM_IO_MM: + val = gctx->card->reg_read(idx); + break; + case ATOM_IO_PCI: + TRACE("PCI registers are not implemented.\n"); + return 0; + case ATOM_IO_SYSIO: + TRACE("SYSIO registers are not implemented.\n"); + return 0; + default: + if (!(gctx->io_mode&0x80)) { + TRACE("Bad IO mode.\n"); + return 0; + } + if (!gctx->iio[gctx->io_mode&0x7F]) { + TRACE("Undefined indirect IO read method %d.\n", gctx->io_mode&0x7F); + return 0; + } + val = atom_iio_execute(gctx, gctx->iio[gctx->io_mode&0x7F], idx, 0); + } + break; + case ATOM_ARG_PS: + idx = U8(*ptr); + (*ptr)++; + val = ctx->ps[idx]; + break; + case ATOM_ARG_WS: + idx = U8(*ptr); + (*ptr)++; + switch(idx) { + case ATOM_WS_QUOTIENT: + val = gctx->divmul[0]; + break; + case ATOM_WS_REMAINDER: + val = gctx->divmul[1]; + break; + case ATOM_WS_DATAPTR: + val = gctx->data_block; + break; + case ATOM_WS_SHIFT: + val = gctx->shift; + break; + case ATOM_WS_OR_MASK: + val = 1<shift; + break; + case ATOM_WS_AND_MASK: + val = ~(1<shift); + break; + case ATOM_WS_FB_WINDOW: + val = gctx->fb_base; + break; + case ATOM_WS_ATTRIBUTES: + val = gctx->io_attr; + break; + default: + val = ctx->ws[idx]; + } + break; + case ATOM_ARG_ID: + idx = U16(*ptr); + (*ptr)+=2; + val = U32(idx + gctx->data_block); + break; + case ATOM_ARG_FB: + idx = U8(*ptr); + (*ptr)++; + TRACE("FB access is not implemented.\n"); + return 0; + case ATOM_ARG_IMM: + switch(align) { + case ATOM_SRC_DWORD: + val = U32(*ptr); + (*ptr)+=4; + return val; + case ATOM_SRC_WORD0: + case ATOM_SRC_WORD8: + case ATOM_SRC_WORD16: + val = U16(*ptr); + (*ptr)+=2; + return val; + case ATOM_SRC_BYTE0: + case ATOM_SRC_BYTE8: + case ATOM_SRC_BYTE16: + case ATOM_SRC_BYTE24: + val = U8(*ptr); + (*ptr)++; + return val; + } + return 0; + case ATOM_ARG_PLL: + idx = U8(*ptr); + (*ptr)++; + gctx->card->reg_write(PLL_INDEX, idx); + val = gctx->card->reg_read(PLL_DATA); + break; + case ATOM_ARG_MC: + idx = U8(*ptr); + (*ptr)++; + TRACE("MC registers are not implemented.\n"); + return 0; + } + if (saved) + *saved = val; + val &= atom_arg_mask[align]; + val >>= atom_arg_shift[align]; + return val; +} + + +static void +atom_skip_src_int(atom_exec_context *ctx, uint8 attr, int *ptr) +{ + uint32 align = (attr >> 3) & 7, arg = attr & 7; + switch(arg) { + case ATOM_ARG_REG: + case ATOM_ARG_ID: + (*ptr)+=2; + break; + case ATOM_ARG_PLL: + case ATOM_ARG_MC: + case ATOM_ARG_PS: + case ATOM_ARG_WS: + case ATOM_ARG_FB: + (*ptr)++; + break; + case ATOM_ARG_IMM: + switch(align) { + case ATOM_SRC_DWORD: + (*ptr)+=4; + return; + case ATOM_SRC_WORD0: + case ATOM_SRC_WORD8: + case ATOM_SRC_WORD16: + (*ptr)+=2; + return; + case ATOM_SRC_BYTE0: + case ATOM_SRC_BYTE8: + case ATOM_SRC_BYTE16: + case ATOM_SRC_BYTE24: + (*ptr)++; + return; + } + return; + } +} + + +static uint32 +atom_get_src(atom_exec_context *ctx, uint8 attr, int *ptr) +{ + return atom_get_src_int(ctx, attr, ptr, NULL, 1); +} + + +static uint32 +atom_get_dst(atom_exec_context *ctx, int arg, uint8 attr, + int *ptr, uint32 *saved, int print) +{ + return atom_get_src_int(ctx, + arg|atom_dst_to_src[(attr>>3)&7][(attr>>6)&3]<<3, ptr, saved, print); +} + + +static void +atom_skip_dst(atom_exec_context *ctx, int arg, uint8 attr, int *ptr) +{ + atom_skip_src_int(ctx, + arg|atom_dst_to_src[(attr>>3)&7][(attr>>6)&3]<<3, ptr); +} + + +static void +atom_put_dst(atom_exec_context *ctx, int arg, uint8 attr, + int *ptr, uint32 val, uint32 saved) +{ + uint32 align = atom_dst_to_src[(attr>>3)&7][(attr>>6)&3], + old_val = val, idx; + atom_context *gctx = ctx->ctx; + old_val &= atom_arg_mask[align] >> atom_arg_shift[align]; + val <<= atom_arg_shift[align]; + val &= atom_arg_mask[align]; + saved &= ~atom_arg_mask[align]; + val |= saved; + switch(arg) { + case ATOM_ARG_REG: + idx = U16(*ptr); + (*ptr)+=2; + idx += gctx->reg_block; + switch(gctx->io_mode) { + case ATOM_IO_MM: + if (idx == 0) + gctx->card->reg_write(idx, val<<2); + else + gctx->card->reg_write(idx, val); + break; + case ATOM_IO_PCI: + TRACE("PCI registers are not implemented.\n"); + return; + case ATOM_IO_SYSIO: + TRACE("SYSIO registers are not implemented.\n"); + return; + default: + if (!(gctx->io_mode&0x80)) { + TRACE("Bad IO mode.\n"); + return; + } + if (!gctx->iio[gctx->io_mode&0xFF]) { + return; + } + atom_iio_execute(gctx, gctx->iio[gctx->io_mode&0xFF], idx, val); + } + break; + case ATOM_ARG_PS: + idx = U8(*ptr); + (*ptr)++; + ctx->ps[idx] = val; + break; + case ATOM_ARG_WS: + idx = U8(*ptr); + (*ptr)++; + switch(idx) { + case ATOM_WS_QUOTIENT: + gctx->divmul[0] = val; + break; + case ATOM_WS_REMAINDER: + gctx->divmul[1] = val; + break; + case ATOM_WS_DATAPTR: + gctx->data_block = val; + break; + case ATOM_WS_SHIFT: + gctx->shift = val; + break; + case ATOM_WS_OR_MASK: + case ATOM_WS_AND_MASK: + break; + case ATOM_WS_FB_WINDOW: + gctx->fb_base = val; + break; + case ATOM_WS_ATTRIBUTES: + gctx->io_attr = val; + break; + default: + ctx->ws[idx] = val; + } + break; + case ATOM_ARG_FB: + idx = U8(*ptr); + (*ptr)++; + TRACE("FB access is not implemented.\n"); + return; + case ATOM_ARG_PLL: + idx = U8(*ptr); + (*ptr)++; + gctx->card->reg_write(PLL_INDEX, idx); + gctx->card->reg_write(PLL_DATA, val); + break; + case ATOM_ARG_MC: + idx = U8(*ptr); + (*ptr)++; + TRACE("MC registers are not implemented.\n"); + return; + } +} + + +static void +atom_op_add(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + dst += src; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_and(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + dst &= src; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_beep(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("ATOM BIOS beeped!\n"); +} + + +static void +atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg) +{ + int idx = U8((*ptr)++); + TRACE(" table: %d\n", idx); + if (U16(ctx->ctx->cmd_table + 4 + 2 * idx)) + atom_execute_table(ctx->ctx, idx, ctx->ps + ctx->ps_shift); +} + + +static void +atom_op_clear(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 saved; + int dptr = *ptr; + attr &= 0x38; + attr |= atom_def_dst[attr>>3]<<6; + atom_get_dst(ctx, arg, attr, ptr, &saved, 0); + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, 0, saved); +} + + +static void +atom_op_compare(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src; + TRACE(" src1: "); + dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); + TRACE(" src2: "); + src = atom_get_src(ctx, attr, ptr); + ctx->ctx->cs_equal = (dst == src); + ctx->ctx->cs_above = (dst > src); + TRACE(" result: %s %s\n", ctx->ctx->cs_equal ? "EQ" : "NE", + ctx->ctx->cs_above ? "GT" : "LE"); +} + + +static void +atom_op_delay(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 count = U8((*ptr)++); + TRACE(" count: %d\n", count); + if (arg == ATOM_UNIT_MICROSEC) { + // Microseconds + usleep(count); + } else { + // TODO : check + // Milliseconds + usleep(count); + } +} + + +static void +atom_op_div(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src; + TRACE(" src1: "); + dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); + TRACE(" src2: "); + src = atom_get_src(ctx, attr, ptr); + if (src != 0) { + ctx->ctx->divmul[0] = dst / src; + ctx->ctx->divmul[1] = dst%src; + } else { + ctx->ctx->divmul[0] = 0; + ctx->ctx->divmul[1] = 0; + } +} + + +static void +atom_op_eot(atom_exec_context *ctx, int *ptr, int arg) +{ + /* functionally, a nop */ +} + + +static void +atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) +{ + int execute = 0, target = U16(*ptr); + (*ptr)+=2; + switch(arg) { + case ATOM_COND_ABOVE: + execute = ctx->ctx->cs_above; + break; + case ATOM_COND_ABOVEOREQUAL: + execute = ctx->ctx->cs_above || ctx->ctx->cs_equal; + break; + case ATOM_COND_ALWAYS: + execute = 1; + break; + case ATOM_COND_BELOW: + execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal); + break; + case ATOM_COND_BELOWOREQUAL: + execute = !ctx->ctx->cs_above; + break; + case ATOM_COND_EQUAL: + execute = ctx->ctx->cs_equal; + break; + case ATOM_COND_NOTEQUAL: + execute = !ctx->ctx->cs_equal; + break; + } + if (arg != ATOM_COND_ALWAYS) + TRACE(" taken: %s\n", execute?"yes":"no"); + TRACE(" target: 0x%04X\n", target); + if (execute) + *ptr = ctx->start + target; +} + + +static void +atom_op_mask(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src1, src2, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src1: "); + src1 = atom_get_src(ctx, attr, ptr); + TRACE(" src2: "); + src2 = atom_get_src(ctx, attr, ptr); + dst &= src1; + dst |= src2; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_move(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 src, saved; + int dptr = *ptr; + if (((attr>>3)&7) != ATOM_SRC_DWORD) + atom_get_dst(ctx, arg, attr, ptr, &saved, 0); + else { + atom_skip_dst(ctx, arg, attr, ptr); + saved = 0xCDCDCDCD; + } + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, src, saved); +} + + +static void +atom_op_mul(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src; + TRACE(" src1: "); + dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); + TRACE(" src2: "); + src = atom_get_src(ctx, attr, ptr); + ctx->ctx->divmul[0] = dst * src; +} + + +static void +atom_op_nop(atom_exec_context *ctx, int *ptr, int arg) +{ + /* nothing */ +} + + +static void +atom_op_or(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + dst |= src; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("unimplemented!\n"); +} + + +static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("unimplemented!\n"); +} + + +static void +atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("unimplemented!\n"); +} + + +static void +atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("unimplemented!\n"); +} + + +static void +atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg) +{ + int idx = U8(*ptr); + (*ptr)++; + TRACE(" block: %d\n", idx); + if (!idx) + ctx->ctx->data_block = 0; + else if (idx==255) + ctx->ctx->data_block = ctx->start; + else + ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2 * idx); +} + + +static void +atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + TRACE(" fb_base: "); + ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr); +} + + +static void +atom_op_setport(atom_exec_context *ctx, int *ptr, int arg) +{ + int port; + switch(arg) { + case ATOM_PORT_ATI: + port = U16(*ptr); + TRACE(" port: %d\n", port); + if (!port) + ctx->ctx->io_mode = ATOM_IO_MM; + else + ctx->ctx->io_mode = ATOM_IO_IIO|port; + (*ptr)+=2; + break; + case ATOM_PORT_PCI: + ctx->ctx->io_mode = ATOM_IO_PCI; + (*ptr)++; + break; + case ATOM_PORT_SYSIO: + ctx->ctx->io_mode = ATOM_IO_SYSIO; + (*ptr)++; + break; + } +} + + +static void +atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg) +{ + ctx->ctx->reg_block = U16(*ptr); + (*ptr)+=2; +} + + +static void +atom_op_shl(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++), shift; + uint32 saved, dst; + int dptr = *ptr; + attr &= 0x38; + attr |= atom_def_dst[attr>>3]<<6; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + shift = U8((*ptr)++); + TRACE(" shift: %d\n", shift); + dst <<= shift; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_shr(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++), shift; + uint32 saved, dst; + int dptr = *ptr; + attr &= 0x38; + attr |= atom_def_dst[attr>>3]<<6; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + shift = U8((*ptr)++); + TRACE(" shift: %d\n", shift); + dst >>= shift; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_sub(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + dst -= src; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_switch(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 src, val, target; + TRACE(" switch: "); + src = atom_get_src(ctx, attr, ptr); + while (U16(*ptr) != ATOM_CASE_END) + if (U8(*ptr) == ATOM_CASE_MAGIC) { + (*ptr)++; + TRACE(" case: "); + val = atom_get_src(ctx, (attr&0x38)|ATOM_ARG_IMM, ptr); + target = U16(*ptr); + if (val == src) { + *ptr = ctx->start + target; + return; + } + (*ptr) += 2; + } else { + TRACE("Bad case.\n"); + return; + } + (*ptr) += 2; +} + + +static void +atom_op_test(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src; + TRACE(" src1: "); + dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); + TRACE(" src2: "); + src = atom_get_src(ctx, attr, ptr); + ctx->ctx->cs_equal = ((dst & src) == 0); + TRACE(" result: %s\n", ctx->ctx->cs_equal?"EQ":"NE"); +} + + +static void +atom_op_xor(atom_exec_context *ctx, int *ptr, int arg) +{ + uint8 attr = U8((*ptr)++); + uint32 dst, src, saved; + int dptr = *ptr; + TRACE(" dst: "); + dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); + TRACE(" src: "); + src = atom_get_src(ctx, attr, ptr); + dst ^= src; + TRACE(" dst: "); + atom_put_dst(ctx, arg, attr, &dptr, dst, saved); +} + + +static void +atom_op_debug(atom_exec_context *ctx, int *ptr, int arg) +{ + TRACE("unimplemented!\n"); +} + + +static struct { + void (*func)(atom_exec_context *, int *, int); + int arg; +} opcode_table[ATOM_OP_CNT] = { + { NULL, 0 }, + { atom_op_move, ATOM_ARG_REG }, + { atom_op_move, ATOM_ARG_PS }, + { atom_op_move, ATOM_ARG_WS }, + { atom_op_move, ATOM_ARG_FB }, + { atom_op_move, ATOM_ARG_PLL }, + { atom_op_move, ATOM_ARG_MC }, + { atom_op_and, ATOM_ARG_REG }, + { atom_op_and, ATOM_ARG_PS }, + { atom_op_and, ATOM_ARG_WS }, + { atom_op_and, ATOM_ARG_FB }, + { atom_op_and, ATOM_ARG_PLL }, + { atom_op_and, ATOM_ARG_MC }, + { atom_op_or, ATOM_ARG_REG }, + { atom_op_or, ATOM_ARG_PS }, + { atom_op_or, ATOM_ARG_WS }, + { atom_op_or, ATOM_ARG_FB }, + { atom_op_or, ATOM_ARG_PLL }, + { atom_op_or, ATOM_ARG_MC }, + { atom_op_shl, ATOM_ARG_REG }, + { atom_op_shl, ATOM_ARG_PS }, + { atom_op_shl, ATOM_ARG_WS }, + { atom_op_shl, ATOM_ARG_FB }, + { atom_op_shl, ATOM_ARG_PLL }, + { atom_op_shl, ATOM_ARG_MC }, + { atom_op_shr, ATOM_ARG_REG }, + { atom_op_shr, ATOM_ARG_PS }, + { atom_op_shr, ATOM_ARG_WS }, + { atom_op_shr, ATOM_ARG_FB }, + { atom_op_shr, ATOM_ARG_PLL }, + { atom_op_shr, ATOM_ARG_MC }, + { atom_op_mul, ATOM_ARG_REG }, + { atom_op_mul, ATOM_ARG_PS }, + { atom_op_mul, ATOM_ARG_WS }, + { atom_op_mul, ATOM_ARG_FB }, + { atom_op_mul, ATOM_ARG_PLL }, + { atom_op_mul, ATOM_ARG_MC }, + { atom_op_div, ATOM_ARG_REG }, + { atom_op_div, ATOM_ARG_PS }, + { atom_op_div, ATOM_ARG_WS }, + { atom_op_div, ATOM_ARG_FB }, + { atom_op_div, ATOM_ARG_PLL }, + { atom_op_div, ATOM_ARG_MC }, + { atom_op_add, ATOM_ARG_REG }, + { atom_op_add, ATOM_ARG_PS }, + { atom_op_add, ATOM_ARG_WS }, + { atom_op_add, ATOM_ARG_FB }, + { atom_op_add, ATOM_ARG_PLL }, + { atom_op_add, ATOM_ARG_MC }, + { atom_op_sub, ATOM_ARG_REG }, + { atom_op_sub, ATOM_ARG_PS }, + { atom_op_sub, ATOM_ARG_WS }, + { atom_op_sub, ATOM_ARG_FB }, + { atom_op_sub, ATOM_ARG_PLL }, + { atom_op_sub, ATOM_ARG_MC }, + { atom_op_setport, ATOM_PORT_ATI }, + { atom_op_setport, ATOM_PORT_PCI }, + { atom_op_setport, ATOM_PORT_SYSIO }, + { atom_op_setregblock, 0 }, + { atom_op_setfbbase, 0 }, + { atom_op_compare, ATOM_ARG_REG }, + { atom_op_compare, ATOM_ARG_PS }, + { atom_op_compare, ATOM_ARG_WS }, + { atom_op_compare, ATOM_ARG_FB }, + { atom_op_compare, ATOM_ARG_PLL }, + { atom_op_compare, ATOM_ARG_MC }, + { atom_op_switch, 0 }, + { atom_op_jump, ATOM_COND_ALWAYS }, + { atom_op_jump, ATOM_COND_EQUAL }, + { atom_op_jump, ATOM_COND_BELOW }, + { atom_op_jump, ATOM_COND_ABOVE }, + { atom_op_jump, ATOM_COND_BELOWOREQUAL }, + { atom_op_jump, ATOM_COND_ABOVEOREQUAL }, + { atom_op_jump, ATOM_COND_NOTEQUAL }, + { atom_op_test, ATOM_ARG_REG }, + { atom_op_test, ATOM_ARG_PS }, + { atom_op_test, ATOM_ARG_WS }, + { atom_op_test, ATOM_ARG_FB }, + { atom_op_test, ATOM_ARG_PLL }, + { atom_op_test, ATOM_ARG_MC }, + { atom_op_delay, ATOM_UNIT_MILLISEC }, + { atom_op_delay, ATOM_UNIT_MICROSEC }, + { atom_op_calltable, 0 }, + { atom_op_repeat, 0 }, + { atom_op_clear, ATOM_ARG_REG }, + { atom_op_clear, ATOM_ARG_PS }, + { atom_op_clear, ATOM_ARG_WS }, + { atom_op_clear, ATOM_ARG_FB }, + { atom_op_clear, ATOM_ARG_PLL }, + { atom_op_clear, ATOM_ARG_MC }, + { atom_op_nop, 0 }, + { atom_op_eot, 0 }, + { atom_op_mask, ATOM_ARG_REG }, + { atom_op_mask, ATOM_ARG_PS }, + { atom_op_mask, ATOM_ARG_WS }, + { atom_op_mask, ATOM_ARG_FB }, + { atom_op_mask, ATOM_ARG_PLL }, + { atom_op_mask, ATOM_ARG_MC }, + { atom_op_postcard, 0 }, + { atom_op_beep, 0 }, + { atom_op_savereg, 0 }, + { atom_op_restorereg, 0 }, + { atom_op_setdatablock, 0 }, + { atom_op_xor, ATOM_ARG_REG }, + { atom_op_xor, ATOM_ARG_PS }, + { atom_op_xor, ATOM_ARG_WS }, + { atom_op_xor, ATOM_ARG_FB }, + { atom_op_xor, ATOM_ARG_PLL }, + { atom_op_xor, ATOM_ARG_MC }, + { atom_op_shl, ATOM_ARG_REG }, + { atom_op_shl, ATOM_ARG_PS }, + { atom_op_shl, ATOM_ARG_WS }, + { atom_op_shl, ATOM_ARG_FB }, + { atom_op_shl, ATOM_ARG_PLL }, + { atom_op_shl, ATOM_ARG_MC }, + { atom_op_shr, ATOM_ARG_REG }, + { atom_op_shr, ATOM_ARG_PS }, + { atom_op_shr, ATOM_ARG_WS }, + { atom_op_shr, ATOM_ARG_FB }, + { atom_op_shr, ATOM_ARG_PLL }, + { atom_op_shr, ATOM_ARG_MC }, + { atom_op_debug, 0 }, +}; + + +void +atom_execute_table(atom_context *ctx, int index, uint32 *params) +{ + int base = CU16(ctx->cmd_table + 4 + 2 * index); + int len, ws, ps, ptr; + unsigned char op; + atom_exec_context ectx; + + if (!base) + return; + + len = CU16(base + ATOM_CT_SIZE_PTR); + ws = CU8(base + ATOM_CT_WS_PTR); + ps = CU8(base + ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK; + ptr = base + ATOM_CT_CODE_PTR; + + /* reset reg block */ + ctx->reg_block = 0; + ectx.ctx = ctx; + ectx.ps_shift = ps / 4; + ectx.start = base; + ectx.ps = params; + if (ws) + ectx.ws = (uint32*)malloc(4 * ws); + else + ectx.ws = NULL; + + debug_depth++; + while (1) { + op = CU8(ptr++); + + if (op 0) + opcode_table[op].func(&ectx, &ptr, opcode_table[op].arg); + else + break; + + if (op == ATOM_OP_EOT) + break; + } + debug_depth--; + TRACE("<<\n"); + + if (ws) + free(ectx.ws); +} + + +static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; + + +static void +atom_index_iio(atom_context *ctx, int base) +{ + ctx->iio = (uint16*)malloc(2 * 256); + while (CU8(base) == ATOM_IIO_START) { + ctx->iio[CU8(base + 1)] = base + 2; + base += 2; + while (CU8(base) != ATOM_IIO_END) + base += atom_iio_len[CU8(base)]; + base += 3; + } +} + + +atom_context +*atom_parse(card_info *card, void *bios) +{ + int base; + atom_context *ctx = (atom_context*)malloc(sizeof(atom_context)); + char *str; + + ctx->card = card; + ctx->bios = bios; + + if (CU16(0) != ATOM_BIOS_MAGIC) { + TRACE("Invalid BIOS magic.\n"); + free(ctx); + return NULL; + } + if (strncmp(CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC, + strlen(ATOM_ATI_MAGIC))) { + TRACE("Invalid ATI magic.\n"); + free(ctx); + return NULL; + } + + base = CU16(ATOM_ROM_TABLE_PTR); + if (strncmp(CSTR(base + ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC, + strlen(ATOM_ROM_MAGIC))) { + TRACE("Invalid ATOM magic.\n"); + free(ctx); + return NULL; + } + + ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR); + ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR); + atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4); + + str = CSTR(CU16(base + ATOM_ROM_MSG_PTR)); + while (*str && ((*str == '\n') || (*str == '\r'))) + str++; + TRACE("ATOM BIOS: %s", str); + + return ctx; +} + + +int +atom_asic_init(atom_context *ctx) +{ + int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR); + uint32 ps[16]; + memset(ps, 0, 64); + + ps[0] = CU32(hwi + ATOM_FWI_DEFSCLK_PTR); + ps[1] = CU32(hwi + ATOM_FWI_DEFMCLK_PTR); + if (!ps[0] || !ps[1]) + return 1; + + if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT)) + return 1; + + atom_execute_table(ctx, ATOM_CMD_INIT, ps); + + return 0; +} + + +void +atom_destroy(atom_context *ctx) +{ + if (ctx->iio) + free(ctx->iio); + free(ctx); +} diff --git a/src/add-ons/accelerants/radeon_hd/atombios/atom.h b/src/add-ons/accelerants/radeon_hd/atombios/atom.h index 79f6f1f2cb..8a57c45859 100644 --- a/src/add-ons/accelerants/radeon_hd/atombios/atom.h +++ b/src/add-ons/accelerants/radeon_hd/atombios/atom.h @@ -21,27 +21,26 @@ * * Author: Stanislaw Skowronek */ - #ifndef ATOM_H #define ATOM_H -#ifndef __HAIKU__ -#include -#include "card.h" -#else +#include +#include + + struct card_info { - struct drm_device *dev; - void (* reg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ - uint32_t (* reg_read)(struct card_info *, uint32_t); /* filled by driver */ - void (* ioreg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ - uint32_t (* ioreg_read)(struct card_info *, uint32_t); /* filled by driver */ - void (* mc_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ - uint32_t (* mc_read)(struct card_info *, uint32_t); /* filled by driver */ - void (* pll_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ - uint32_t (* pll_read)(struct card_info *, uint32_t); /* filled by driver */ + // Filled by driver + void (*reg_write)(uint32 offset, uint32 data); + uint32 (*reg_read)(uint32 offset); + void (*ioreg_write)(uint32 offset, uint32 data); + uint32 (*ioreg_read)(uint32 offset); + void (*mc_write)(uint32 offset, uint32 data); + uint32 (*mc_read)(uint32 offset); + void (*pll_write)(uint32 offset, uint32 data); + uint32 (*pll_read)(uint32 offset); }; -#endif + #define ATOM_BIOS_MAGIC 0xAA55 #define ATOM_ATI_MAGIC_PTR 0x30 @@ -124,25 +123,25 @@ struct card_info { #define ATOM_IO_IIO 0x80 typedef struct atom_context_s { - card_info *card; - void *bios; - uint32_t cmd_table, data_table; - uint16_t *iio; + card_info *card; + void *bios; + uint32 cmd_table, data_table; + uint16 *iio; - uint16_t data_block; - uint32_t fb_base; - uint32_t divmul[2]; - uint16_t io_attr; - uint16_t reg_block; - uint8_t shift; - int cs_equal, cs_above; - int io_mode; + uint16 data_block; + uint32 fb_base; + uint32 divmul[2]; + uint16 io_attr; + uint16 reg_block; + uint8 shift; + int cs_equal, cs_above; + int io_mode; } atom_context; extern int atom_debug; atom_context *atom_parse(card_info *, void *); -void atom_execute_table(atom_context *, int, uint32_t *); +void atom_execute_table(atom_context *, int, uint32 *); int atom_asic_init(atom_context *); void atom_destroy(atom_context *); diff --git a/src/add-ons/accelerants/radeon_hd/bios.cpp b/src/add-ons/accelerants/radeon_hd/bios.cpp index a14ca7fff6..406d222de8 100644 --- a/src/add-ons/accelerants/radeon_hd/bios.cpp +++ b/src/add-ons/accelerants/radeon_hd/bios.cpp @@ -24,3 +24,46 @@ # define TRACE(x...) ; #endif + +// AtomBios related calls + + +status_t +bios_init() +{ + struct card_info *atom_card_info + = (card_info*)malloc(sizeof(card_info)); + + if (!atom_card_info) + return B_NO_MEMORY; + + atom_card_info->reg_read = _read32; + atom_card_info->reg_write = _write32; + + if (false) { + // TODO : if rio_mem, use ioreg + //atom_card_info->ioreg_read = cail_ioreg_read; + //atom_card_info->ioreg_write = cail_ioreg_write; + } else { + TRACE("%s: Cannot find PCI I/O BAR; using MMIO\n", __func__); + atom_card_info->ioreg_read = _read32; + atom_card_info->ioreg_write = _write32; + } + atom_card_info->mc_read = _read32; + atom_card_info->mc_write = _write32; + atom_card_info->pll_read = _read32; + atom_card_info->pll_write = _write32; + + // System VGA shadow bios? Why not (temporary) + atom_parse(atom_card_info, (void*)0xC0000); + + // TODO : we need to get a copy of the VGA bios :( + #if 0 + rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios); + mutex_init(&rdev->mode_info.atom_context->mutex); + radeon_atom_initialize_bios_scratch_regs(rdev->ddev); + atom_allocate_fb_scratch(rdev->mode_info.atom_context); + #endif + + return B_OK; +} diff --git a/src/add-ons/accelerants/radeon_hd/bios.h b/src/add-ons/accelerants/radeon_hd/bios.h index 80f8ca57c6..fd45b0546d 100644 --- a/src/add-ons/accelerants/radeon_hd/bios.h +++ b/src/add-ons/accelerants/radeon_hd/bios.h @@ -11,10 +11,7 @@ #include -// AtomBios includes -extern "C" { - #include "atom.h" -} +#include "atom.h" struct bios_info { @@ -23,8 +20,7 @@ struct bios_info { }; -status_t AtomParser(void *parameterSpace, uint8_t index, - void *handle, void *biosBase); +status_t bios_init(); #endif /* RADEON_HD_BIOS_H */