Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/trunkGraphicsEnablerModules/i386/modules/GraphicsEnabler/ATiGraphicsEnabler/ati.c

1/*
2 * ATI injector
3 *
4 * Copyright (C) 2009 Jasmin Fazlic, iNDi, netkas
5 *
6 * ATI injector is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ATI driver and injector is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with ATI injector. If not, see <http://www.gnu.org/licenses/>.
18 */
19/*
20 * Alternatively you can choose to comply with APSL
21 */
22
23#include "libsa.h"
24#include "saio_internal.h"
25#include "bootstruct.h"
26#include "pci.h"
27#include "platform.h"
28#include "device_inject.h"
29#include "ati.h"
30
31#ifndef DEBUG_ATI
32#define DEBUG_ATI 0
33#endif
34
35#if DEBUG_ATI
36#define DBG(x...)printf(x)
37#else
38#define DBG(x...)
39#endif
40
41#define kUseAtiROMKey"UseAtiROM"
42
43#define MAX_NUM_DCB_ENTRIES 16
44
45#define TYPE_GROUPED 0xff
46
47extern uint32_t devices_number;
48
49const char *ati_compatible_0[]= { "@0,compatible", "ATY,%s" };
50const char *ati_compatible_1[]= { "@1,compatible", "ATY,%s" };
51const char *ati_device_type_0[]= { "@0,device_type", "display" };
52const char *ati_device_type_1[]= { "@1,device_type", "display" };
53const char *ati_device_type[]= { "device_type", "ATY,%sParent" };
54const char *ati_name_0[]= { "@0,name", "ATY,%s" };
55const char *ati_name_1[]= { "@1,name", "ATY,%s" };
56const char *ati_name[]= { "name", "ATY,%sParent" };
57const char *ati_efidisplay_0[]= { "@0,ATY,EFIDisplay", "TMDSB" };
58struct ati_data_key ati_connector_type_0= { 0x04, "@0,connector-type", {0x00, 0x04, 0x00, 0x00} };
59struct ati_data_key ati_connector_type_1= { 0x04, "@1,connector-type", {0x04, 0x00, 0x00, 0x00} };
60struct ati_data_key ati_display_con_fl_type_0= { 0x04, "@0,display-connect-flags", {0x00, 0x00, 0x04, 0x00} };
61const char *ati_display_type_0[]= { "@0,display-type", "LCD" };
62const char *ati_display_type_1[]= { "@1,display-type", "NONE" };
63struct ati_data_key ati_aux_power_conn= { 0x04, "AAPL,aux-power-connected", {0x01, 0x00, 0x00, 0x00} };
64struct ati_data_key ati_backlight_ctrl= { 0x04, "AAPL,backlight-control", {0x00, 0x00, 0x00, 0x00} };
65struct ati_data_key ati_aapl01_coher= { 0x04, "AAPL01,Coherency", {0x01, 0x00, 0x00, 0x00} };
66const char *ati_card_no[]= { "ATY,Card#", "109-B77101-00" };
67const char *ati_copyright[]= { "ATY,Copyright", "Copyright AMD Inc. All Rights Reserved. 2005-2009" };
68const char *ati_efi_compile_d[]= { "ATY,EFICompileDate", "Jan 26 2009" };
69struct ati_data_key ati_efi_disp_conf= { 0x08, "ATY,EFIDispConfig", {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} };
70struct ati_data_key ati_efi_drv_type= { 0x01, "ATY,EFIDriverType", {0x02} };
71struct ati_data_key ati_efi_enbl_mode= { 0x01, "ATY,EFIEnabledMode", {0x01} };
72struct ati_data_key ati_efi_init_stat= { 0x04, "ATY,EFIHWInitStatus", {0x00, 0x00, 0x00, 0x00} };
73struct ati_data_key ati_efi_orientation= { 0x02, "ATY,EFIOrientation", {0x02, 0x00} };
74const char *ati_efi_version[]= { "ATY,EFIVersion", "01.00.318" };
75const char *ati_efi_versionB[]= { "ATY,EFIVersionB", "113-SBSJ1G04-00R-02" };
76const char *ati_efi_versionE[]= { "ATY,EFIVersionE", "113-B7710A-318" };
77struct ati_data_key ati_mclk= { 0x04, "ATY,MCLK", {0x70, 0x2e, 0x11, 0x00} };
78struct ati_data_key ati_mem_rev_id= { 0x02, "ATY,MemRevisionID", {0x03, 0x00} };
79struct ati_data_key ati_mem_vend_id= { 0x02, "ATY,MemVendorID", {0x02, 0x00} };
80const char *ati_mrt[]= { "ATY,MRT", " " };
81const char *ati_romno[]= { "ATY,Rom#", "113-B7710C-176" };
82struct ati_data_key ati_sclk= { 0x04, "ATY,SCLK", {0x28, 0xdb, 0x0b, 0x00} };
83struct ati_data_key ati_vendor_id= { 0x02, "ATY,VendorID", {0x02, 0x10} };
84struct ati_data_key ati_platform_info= { 0x80, "ATY,PlatformInfo", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
85struct ati_data_key ati_mvad= { 0x40, "MVAD", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03} };
86struct ati_data_key ati_saved_config= { 0x100, "saved-config", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
87///non 48xx keys
88const char *ati_efidisplay_0_n4[]= { "@0,ATY,EFIDisplay", "TMDSA" };
89struct ati_data_key ati_connector_type_0_n4= { 0x04, "@0,connector-type", {0x04, 0x00, 0x00, 0x00} };
90struct ati_data_key ati_connector_type_1_n4= { 0x04, "@1,connector-type", {0x00, 0x02, 0x00, 0x00} };
91struct ati_data_key ati_aapl_emc_disp_list_n4= { 0x40, "AAPL,EMC-Display-List", {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1b, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1c, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
92struct ati_data_key ati_fb_offset_n4= { 0x08, "ATY,FrameBufferOffset", {0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00} };
93struct ati_data_key ati_hwgpio_n4= { 0x04, "ATY,HWGPIO", {0x23, 0xa8, 0x48, 0x00} };
94struct ati_data_key ati_iospace_offset_n4= { 0x08, "ATY,IOSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00} };
95struct ati_data_key ati_mclk_n4= { 0x04, "ATY,MCLK", {0x00, 0x35, 0x0c, 0x00} };
96struct ati_data_key ati_sclk_n4= { 0x04, "ATY,SCLK", {0x60, 0xae, 0x0a, 0x00} };
97struct ati_data_key ati_refclk_n4= { 0x04, "ATY,RefCLK", {0x8c, 0x0a, 0x00, 0x00} };
98struct ati_data_key ati_regspace_offset_n4= { 0x08, "ATY,RegisterSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x90, 0xa2, 0x00, 0x00} };
99struct ati_data_key ati_vram_memsize_0= { 0x08, "@0,VRAM,memsize", {0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00} };
100struct ati_data_key ati_vram_memsize_1= { 0x08, "@1,VRAM,memsize", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
101struct ati_data_key ati_aapl_blackscr_prefs_0_n4= { 0x04, "AAPL00,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} };
102struct ati_data_key ati_aapl_blackscr_prefs_1_n4= { 0x04, "AAPL01,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} };
103struct ati_data_key ati_swgpio_info_n4= { 0x04, "ATY,SWGPIO Info", {0x00, 0x48, 0xa8, 0x23} };
104struct ati_data_key ati_efi_orientation_n4= { 0x01, "ATY,EFIOrientation", {0x08} };
105struct ati_data_key ati_mvad_n4= { 0x100, "MVAD", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
106struct ati_data_key ati_saved_config_n4= { 0x100, "saved-config", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };
107
108struct pcir_s {
109uint32_t signature;
110uint16_t vid;
111uint16_t devid;
112};
113
114// Known cards as of 2008/08/26
115static struct ati_chipsets_t ATIKnownChipsets[] = {
116{ 0x00000000, "Unknown"},
117{ 0x10027181, "ATI Radeon X1600 Series"},
118{ 0x10027183, "ATI Radeon X1550 Series"},
119{ 0x10027183, "ATI Radeon X1300 Series"},
120{ 0x100271C5, "ATI Mobility Radeon X1600"},
121
122{ 0x10029589, "ATI Radeon 2600 Series"} ,
123{ 0x10029588, "ATI Radeon 2600 Series"} ,
124{ 0x100294C3, "ATI Radeon 2400 Series"} ,
125{ 0x100294C4, "ATI Radeon 2400 Series"} ,
126{ 0x100294C6, "ATI Radeon 2400 Series"} ,
127{ 0x10029400, "ATI Radeon 2900 Series"} ,
128{ 0x10029405, "ATI Radeon 2900GT Series"} ,
129{ 0x10029581, "ATI Radeon 2600 Series"} ,
130{ 0x10029583, "ATI Radeon 2600 Series"} ,
131{ 0x10029586, "ATI Radeon 2600 Series"} ,
132{ 0x10029587, "ATI Radeon 2600 Series"} ,
133{ 0x100294C9, "ATI Radeon 2400 Series"} ,
134{ 0x10029501, "ATI Radeon 3800 Series"} ,
135{ 0x10029505, "ATI Radeon 3800 Series"} ,
136{ 0x10029515, "ATI Radeon 3800 Series"} ,
137{ 0x10029507, "ATI Radeon 3800 Series"} ,
138{ 0x10029500, "ATI Radeon 3800 Series"} ,
139{ 0x1002950F, "ATI Radeon 3800X2 Series"} ,
140{ 0x100295C5, "ATI Radeon 3400 Series"} ,
141{ 0x100295C7, "ATI Radeon 3400 Series"} ,
142{ 0x100295C0, "ATI Radeon 3400 Series"} ,
143{ 0x10029596, "ATI Radeon 3600 Series"} ,
144{ 0x10029590, "ATI Radeon 3600 Series"} ,
145{ 0x10029599, "ATI Radeon 3600 Series"} ,
146{ 0x10029597, "ATI Radeon 3600 Series"} ,
147{ 0x10029598, "ATI Radeon 3600 Series"} ,
148{ 0x10029442, "ATI Radeon 4850 Series"} ,
149{ 0x10029440, "ATI Radeon 4870 Series"} ,
150{ 0x1002944C, "ATI Radeon 4830 Series"} ,
151{ 0x10029460, "ATI Radeon 4890 Series"} ,
152{ 0x10029462, "ATI Radeon 4890 Series"} ,
153{ 0x10029441, "ATI Radeon 4870X2 Series"} ,
154{ 0x10029443, "ATI Radeon 4850X2 Series"} ,
155{ 0x10029444, "ATI Radeon 4800 Series"} ,
156{ 0x10029446, "ATI Radeon 4800 Series"} ,
157{ 0x1002944E, "ATI Radeon 4730 Series"} ,
158{ 0x10029450, "ATI Radeon 4800 Series"} ,
159{ 0x10029452, "ATI Radeon 4800 Series"} ,
160{ 0x10029456, "ATI Radeon 4800 Series"} ,
161{ 0x1002944A, "ATI Radeon 4800 Mobility Series"} ,
162{ 0x1002945A, "ATI Radeon 4800 Mobility Series"} ,
163{ 0x1002945B, "ATI Radeon 4800 Mobility Series"} ,
164{ 0x1002944B, "ATI Radeon 4800 Mobility Series"} ,
165 { 0x10029490, "ATI Radeon 4670 Series"} ,
166 { 0x10029498, "ATI Radeon 4650 Series"} ,
167{ 0x10029490, "ATI Radeon 4600 Series"} ,
168{ 0x10029498, "ATI Radeon 4600 Series"} ,
169{ 0x1002949E, "ATI Radeon 4600 Series"} ,
170{ 0x10029480, "ATI Radeon HD 4650M"}, // akbar
171{ 0x10029488, "ATI Radeon 4600 Series"} ,
172{ 0x10029540, "ATI Radeon 4500 Series"} ,
173{ 0x10029541, "ATI Radeon 4500 Series"} ,
174{ 0x1002954E, "ATI Radeon 4500 Series"} ,
175{ 0x10029552, "ATI Radeon 4300 Mobility Series"} ,
176{ 0x10029553, "ATI Radeon 4500 Mobility Series"} ,
177{ 0x1002954F, "ATI Radeon 4300 Series"} ,
178 { 0x100294B3, "ATI Radeon 4770 Series"} ,
179 { 0x100294B5, "ATI Radeon 4770 Series"} ,
180 { 0x100268B8, "ATI Radeon 5700 Series"} ,
181 { 0x100268BE, "ATI Radeon 5700 Series"} ,
182 { 0x10026898, "ATI Radeon 5800 Series"} ,
183 { 0x10026899, "ATI Radeon 5800 Series"}
184};
185
186static struct ati_chipsets_t ATIKnownFramebuffers[] = {
187{ 0x00000000, "Megalodon"},
188{ 0x10027181, "Caretta"},
189{ 0x10027183, "Caretta"},
190{ 0x10027187, "Caretta"},
191{ 0x100271C5, "Wormy"},
192
193{ 0x10029589, "Lamna"} ,
194{ 0x10029588, "Lamna"} ,
195{ 0x100294C3, "Iago"} ,
196{ 0x100294C4, "Iago"} ,
197{ 0x100294C6, "Iago"} ,
198{ 0x10029400, "Franklin"} ,
199{ 0x10029405, "Franklin"} ,
200{ 0x10029581, "Hypoprion"} ,
201{ 0x10029583, "Hypoprion"} ,
202{ 0x10029586, "Hypoprion"} ,
203{ 0x10029587, "Hypoprion"} ,
204{ 0x100294C9, "Iago"} ,
205{ 0x10029501, "Megalodon"} ,
206{ 0x10029505, "Megalodon"} ,
207{ 0x10029515, "Megalodon"} ,
208{ 0x10029507, "Megalodon"} ,
209{ 0x10029500, "Megalodon"} ,
210{ 0x1002950F, "Triakis"} ,
211{ 0x100295C5, "Iago"} ,
212{ 0x100295C7, "Iago"} ,
213{ 0x100295C0, "Iago"} ,
214{ 0x10029596, "Megalodon"} ,
215{ 0x10029590, "Megalodon"} ,
216{ 0x10029599, "Megalodon"} ,
217{ 0x10029597, "Megalodon"} ,
218{ 0x10029598, "Megalodon"} ,
219{ 0x10029442, "Motmot"} ,
220{ 0x10029440, "Motmot"} ,
221{ 0x1002944C, "Motmot"} ,
222{ 0x10029460, "Motmot"} ,
223{ 0x10029462, "Motmot"} ,
224{ 0x10029441, "Motmot"} ,
225{ 0x10029443, "Motmot"} ,
226{ 0x10029444, "Motmot"} ,
227{ 0x10029446, "Motmot"} ,
228{ 0x1002944E, "Motmot"} ,
229{ 0x10029450, "Motmot"} ,
230{ 0x10029452, "Motmot"} ,
231{ 0x10029456, "Motmot"} ,
232{ 0x1002944A, "Motmot"} ,
233{ 0x1002945A, "Motmot"} ,
234{ 0x1002945B, "Motmot"} ,
235{ 0x1002944B, "Motmot"} ,
236 { 0x10029490, "Peregrine"} ,
237 { 0x10029498, "Peregrine"} ,
238 { 0x1002949E, "Peregrine"} ,
239 { 0x10029480, "Gliff"}, // Peregrine <= 10.6.7
240 { 0x10029488, "Peregrine"} ,
241 { 0x10029540, "Peregrine"} ,
242 { 0x10029541, "Peregrine"} ,
243 { 0x1002954E, "Peregrine"} ,
244 { 0x10029552, "Peregrine"} ,
245 { 0x10029553, "Peregrine"} ,
246 { 0x1002954F, "Peregrine"} ,
247 { 0x100294B3, "Peregrine"},
248 { 0x100294B5, "Peregrine"},
249 { 0x100268B8, "Motmot"},
250 { 0x100268BE, "Motmot"},
251 { 0x10026898, "Motmot"},
252 { 0x10026899, "Motmot"}
253};
254
255static uint32_t accessROM(pci_dt_t *ati_dev, unsigned int mode)
256{
257uint32_tbar[7];
258volatile uint32_t*regs;
259
260bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
261regs = (uint32_t *) (bar[2] & ~0x0f);
262
263if (mode) {
264if (mode != 1) {
265return 0xe00002c7;
266}
267REG32W(0x179c, 0x00080000);
268REG32W(0x1798, 0x00080721);
269REG32W(0x17a0, 0x00080621);
270REG32W(0x1600, 0x14030300);
271REG32W(0x1798, 0x21);
272REG32W(0x17a0, 0x21);
273REG32W(0x179c, 0x00);
274REG32W(0x17a0, 0x21);
275REG32W(0x1798, 0x21);
276REG32W(0x1798, 0x21);
277} else {
278REG32W(0x1600, 0x14030302);
279REG32W(0x1798, 0x21);
280REG32W(0x17a0, 0x21);
281REG32W(0x179c, 0x00080000);
282REG32W(0x17a0, 0x00080621);
283REG32W(0x1798, 0x00080721);
284REG32W(0x1798, 0x21);
285REG32W(0x17a0, 0x21);
286REG32W(0x179c, 0x00);
287REG32W(0x1604, 0x0400e9fc);
288REG32W(0x161c, 0x00);
289REG32W(0x1620, 0x9f);
290REG32W(0x1618, 0x00040004);
291REG32W(0x161c, 0x00);
292REG32W(0x1604, 0xe9fc);
293REG32W(0x179c, 0x00080000);
294REG32W(0x1798, 0x00080721);
295REG32W(0x17a0, 0x00080621);
296REG32W(0x1798, 0x21);
297REG32W(0x17a0, 0x21);
298REG32W(0x179c, 0x00);
299}
300return 0;
301}
302
303static uint8_t *readAtomBIOS(pci_dt_t *ati_dev)
304{
305uint32_tbar[7];
306uint32_t*BIOSBase;
307uint32_tcounter;
308volatile uint32_t*regs;
309
310bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
311regs = (volatile uint32_t *) (bar[2] & ~0x0f);
312accessROM(ati_dev, 0);
313REG32W(0xa8, 0);
314REG32R(0xac);
315REG32W(0xa8, 0);
316REG32R(0xac);
317
318BIOSBase = malloc(0x10000);
319REG32W(0xa8, 0);
320BIOSBase[0] = REG32R(0xac);
321counter = 4;
322do {
323REG32W(0xa8, counter);
324BIOSBase[counter/4] = REG32R(0xac);
325counter +=4;
326} while (counter != 0x10000);
327accessROM((pci_dt_t *)regs, 1);
328
329if (*(uint16_t *)BIOSBase != 0xAA55) {
330printf("Wrong BIOS signature: %04x\n", *(uint16_t *)BIOSBase);
331return 0;
332}
333return (uint8_t *)BIOSBase;
334}
335
336#define R5XX_CONFIG_MEMSIZE0x00F8 //Azi:---
337#define R6XX_CONFIG_MEMSIZE0x5428
338
339uint32_t getvramsizekb(pci_dt_t *ati_dev)
340{
341uint32_tbar[7];
342uint32_tsize;
343volatile uint32_t*regs;
344
345bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 );
346regs = (uint32_t *) (bar[2] & ~0x0f);
347if (ati_dev->device_id < 0x9400) {
348size = (REG32R(R5XX_CONFIG_MEMSIZE)) >> 10;
349} else {
350size = (REG32R(R6XX_CONFIG_MEMSIZE)) >> 10;
351}
352return size;
353}
354
355#define AVIVO_D1CRTC_CONTROL0x6080
356#define AVIVO_CRTC_EN(1<<0)
357#define AVIVO_D2CRTC_CONTROL0x6880
358
359static bool radeon_card_posted(pci_dt_t *ati_dev)
360{
361// if devid matches biosimage(from legacy) devid - posted card, fails with X2/crossfire cards.
362/*char *biosimage = 0xC0000;
363
364if ((uint8_t)biosimage[0] == 0x55 && (uint8_t)biosimage[1] == 0xaa)
365{
366option_rom_pci_header_t *rom_pci_header;
367rom_pci_header = (option_rom_pci_header_t*)(biosimage + (uint8_t)biosimage[24] + (uint8_t)biosimage[25]*256);
368
369 if (rom_pci_header->signature == 0x52494350)
370{
371 if (rom_pci_header->device_id == ati_dev->device_id)
372{
373return true;
374printf("Card was POSTed\n");
375}
376}
377}
378return false;
379printf("Card was not POSTed\n");
380*/
381//fails yet
382uint32_tbar[7];
383uint32_tval;
384volatile uint32_t*regs;
385
386bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18);
387regs = (uint32_t *) (bar[2] & ~0x0f);
388
389val = REG32R(AVIVO_D1CRTC_CONTROL) | REG32R(AVIVO_D2CRTC_CONTROL);
390if (val & AVIVO_CRTC_EN) {
391return true;
392} else {
393return false;
394}
395}
396
397static uint32_t load_ati_bios_file(const char *filename, uint8_t *buf, int bufsize)
398{
399intfd;
400intsize;
401
402if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
403return 0;
404}
405size = file_size(fd);
406if (size > bufsize) {
407printf("Filesize of %s is bigger than expected! Truncating to 0x%x Bytes!\n", filename, bufsize);
408size = bufsize;
409}
410size = read(fd, (char *)buf, size);
411close(fd);
412return size > 0 ? size : 0;
413}
414
415static char *get_ati_model(uint32_t id)
416{
417int i;
418
419for (i = 0; i < (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) {
420if (ATIKnownChipsets[i].device == id) {
421return ATIKnownChipsets[i].name;
422}
423}
424return ATIKnownChipsets[0].name;
425}
426
427static char *get_ati_fb(uint32_t id)
428{
429inti;
430
431for (i = 0; i < (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) {
432if (ATIKnownFramebuffers[i].device == id) {
433return ATIKnownFramebuffers[i].name;
434}
435}
436return ATIKnownFramebuffers[0].name;
437}
438
439static int devprop_add_iopciconfigspace(struct DevPropDevice *device, pci_dt_t *ati_dev)
440{
441inti;
442uint8_t*config_space;
443
444if (!device || !ati_dev) {
445return 0;
446}
447verbose("dumping pci config space, 256 bytes\n");
448config_space = malloc(256);
449for (i=0; i<=255; i++) {
450config_space[i] = pci_config_read8( ati_dev->dev.addr, i);
451}
452devprop_add_value(device, "ATY,PCIConfigSpace", config_space, 256);
453free (config_space);
454return 1;
455}
456
457static int devprop_add_ati_template_4xxx(struct DevPropDevice *device)
458{
459if(!device)
460return 0;
461
462//if(!DP_ADD_TEMP_VAL(device, ati_compatible_0))
463//return 0;
464//if(!DP_ADD_TEMP_VAL(device, ati_compatible_1))
465//return 0;
466if(!DP_ADD_TEMP_VAL(device, ati_device_type_0))
467return 0;
468if(!DP_ADD_TEMP_VAL(device, ati_device_type_1))
469return 0;
470//if(!DP_ADD_TEMP_VAL(device, ati_device_type))
471//return 0;
472//if(!DP_ADD_TEMP_VAL(device, ati_name_0))
473//return 0;
474//if(!DP_ADD_TEMP_VAL(device, ati_name_1))
475//return 0;
476//if(!DP_ADD_TEMP_VAL(device, ati_name))
477//return 0;
478if(!DP_ADD_TEMP_VAL(device, ati_efidisplay_0))
479return 0;
480if(!DP_ADD_TEMP_VAL(device, ati_display_type_0))
481return 0;
482if(!DP_ADD_TEMP_VAL(device, ati_display_type_1))
483return 0;
484//if(!DP_ADD_TEMP_VAL(device, ati_slot_name))
485//return 0;
486if(!DP_ADD_TEMP_VAL(device, ati_card_no))
487return 0;
488if(!DP_ADD_TEMP_VAL(device, ati_copyright))
489return 0;
490if(!DP_ADD_TEMP_VAL(device, ati_efi_compile_d))
491return 0;
492if(!DP_ADD_TEMP_VAL(device, ati_efi_version))
493return 0;
494if(!DP_ADD_TEMP_VAL(device, ati_efi_versionB))
495return 0;
496if(!DP_ADD_TEMP_VAL(device, ati_efi_versionE))
497return 0;
498if(!DP_ADD_TEMP_VAL(device, ati_mrt))
499return 0;
500if(!DP_ADD_TEMP_VAL(device, ati_romno))
501return 0;
502if(!DP_ADD_TEMP_VAL(device, ati_name_1))
503return 0;
504if(!DP_ADD_TEMP_VAL_DATA(device, ati_connector_type_0))
505return 0;
506if(!DP_ADD_TEMP_VAL_DATA(device, ati_connector_type_1))
507return 0;
508if(!DP_ADD_TEMP_VAL_DATA(device, ati_display_con_fl_type_0))
509return 0;
510if(!DP_ADD_TEMP_VAL_DATA(device, ati_aux_power_conn))
511return 0;
512if(!DP_ADD_TEMP_VAL_DATA(device, ati_backlight_ctrl))
513return 0;
514if(!DP_ADD_TEMP_VAL_DATA(device, ati_aapl01_coher))
515return 0;
516if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_disp_conf))
517return 0;
518if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_drv_type))
519return 0;
520if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_enbl_mode))
521return 0;
522if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_init_stat))
523return 0;
524if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_orientation))
525return 0;
526if(!DP_ADD_TEMP_VAL_DATA(device, ati_mclk))
527return 0;
528if(!DP_ADD_TEMP_VAL_DATA(device, ati_mem_rev_id))
529return 0;
530if(!DP_ADD_TEMP_VAL_DATA(device, ati_mem_vend_id))
531return 0;
532if(!DP_ADD_TEMP_VAL_DATA(device, ati_sclk))
533return 0;
534if(!DP_ADD_TEMP_VAL_DATA(device, ati_vendor_id))
535return 0;
536if(!DP_ADD_TEMP_VAL_DATA(device, ati_platform_info))
537return 0;
538if(!DP_ADD_TEMP_VAL_DATA(device, ati_mvad))
539return 0;
540if(!DP_ADD_TEMP_VAL_DATA(device, ati_saved_config))
541return 0;
542return 1;
543}
544
545static int devprop_add_ati_template(struct DevPropDevice *device)
546{
547if(!device)
548return 0;
549
550if(!DP_ADD_TEMP_VAL_DATA(device, ati_platform_info))
551return 0;
552if(!DP_ADD_TEMP_VAL(device, ati_device_type_0))
553return 0;
554if(!DP_ADD_TEMP_VAL(device, ati_device_type_1))
555return 0;
556if(!DP_ADD_TEMP_VAL(device, ati_efidisplay_0_n4))
557return 0;
558//if(!DP_ADD_TEMP_VAL(device, ati_slot_name_n4))
559//return 0;
560if(!DP_ADD_TEMP_VAL(device, ati_card_no))
561return 0;
562if(!DP_ADD_TEMP_VAL(device, ati_copyright))
563return 0;
564if(!DP_ADD_TEMP_VAL(device, ati_efi_compile_d))
565return 0;
566if(!DP_ADD_TEMP_VAL(device, ati_efi_version))
567return 0;
568if(!DP_ADD_TEMP_VAL(device, ati_efi_versionB))
569return 0;
570if(!DP_ADD_TEMP_VAL(device, ati_efi_versionE))
571return 0;
572if(!DP_ADD_TEMP_VAL(device, ati_mrt))
573return 0;
574if(!DP_ADD_TEMP_VAL(device, ati_romno))
575return 0;
576if(!DP_ADD_TEMP_VAL(device, ati_name_1))
577return 0;
578if(!DP_ADD_TEMP_VAL_DATA(device, ati_connector_type_0_n4))
579return 0;
580if(!DP_ADD_TEMP_VAL_DATA(device, ati_connector_type_1_n4))
581return 0;
582if(!DP_ADD_TEMP_VAL_DATA(device, ati_aux_power_conn))
583return 0;
584if(!DP_ADD_TEMP_VAL_DATA(device, ati_backlight_ctrl))
585return 0;
586if(!DP_ADD_TEMP_VAL_DATA(device, ati_aapl01_coher))
587return 0;
588if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_drv_type))
589return 0;
590if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_enbl_mode))
591return 0;
592if(!DP_ADD_TEMP_VAL_DATA(device, ati_mem_rev_id))
593return 0;
594if(!DP_ADD_TEMP_VAL_DATA(device, ati_mem_vend_id))
595return 0;
596if(!DP_ADD_TEMP_VAL_DATA(device, ati_vendor_id))
597return 0;
598if(!DP_ADD_TEMP_VAL_DATA(device, ati_aapl_emc_disp_list_n4))
599return 0;
600if(!DP_ADD_TEMP_VAL_DATA(device, ati_fb_offset_n4))
601return 0;
602if(!DP_ADD_TEMP_VAL_DATA(device, ati_hwgpio_n4))
603return 0;
604if(!DP_ADD_TEMP_VAL_DATA(device, ati_iospace_offset_n4))
605return 0;
606if(!DP_ADD_TEMP_VAL_DATA(device, ati_mclk_n4))
607return 0;
608if(!DP_ADD_TEMP_VAL_DATA(device, ati_sclk_n4))
609return 0;
610if(!DP_ADD_TEMP_VAL_DATA(device, ati_refclk_n4))
611return 0;
612if(!DP_ADD_TEMP_VAL_DATA(device, ati_regspace_offset_n4))
613return 0;
614if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_orientation_n4))
615return 0;
616if(!DP_ADD_TEMP_VAL_DATA(device, ati_aapl_blackscr_prefs_0_n4))
617return 0;
618if(!DP_ADD_TEMP_VAL_DATA(device, ati_aapl_blackscr_prefs_1_n4))
619return 0;
620if(!DP_ADD_TEMP_VAL_DATA(device, ati_swgpio_info_n4))
621return 0;
622if(!DP_ADD_TEMP_VAL_DATA(device, ati_efi_orientation_n4))
623return 0;
624if(!DP_ADD_TEMP_VAL_DATA(device, ati_mvad_n4))
625return 0;
626if(!DP_ADD_TEMP_VAL_DATA(device, ati_saved_config_n4))
627return 0;
628return 1;
629}
630
631
632bool setup_ati_devprop(pci_dt_t *ati_dev)
633{
634struct DevPropDevice*device;
635char*devicepath;
636char*model;
637char*framebuffer;
638char tmp[64];
639uint8_t*rom = NULL;
640uint32_t rom_size = 0;
641option_rom_pci_header_t *rom_pci_header;
642uint8_t*bios;
643uint32_t bios_size;
644uint32_t vram_size;
645uint32_t boot_display;
646uint8_t cmd;
647bool doit;
648bool toFree;
649
650devicepath = get_pci_dev_path(ati_dev);
651
652cmd = pci_config_read8(ati_dev->dev.addr, 4);
653verbose("old pci command - %x\n", cmd);
654if (cmd == 0) {
655pci_config_write8(ati_dev->dev.addr, 4, 6);
656cmd = pci_config_read8(ati_dev->dev.addr, 4);
657verbose("new pci command - %x\n", cmd);
658}
659
660model = get_ati_model((ati_dev->vendor_id << 16) | ati_dev->device_id);
661framebuffer = get_ati_fb((ati_dev->vendor_id << 16) | ati_dev->device_id);
662if (!string) {
663string = devprop_create_string();
664}
665device = devprop_add_device(string, devicepath);
666if (!device) {
667printf("Failed initializing dev-prop string dev-entry, press any key...\n");
668getchar();
669return false;
670}
671
672/* FIXME: for primary graphics card only */
673if (radeon_card_posted(ati_dev)) {
674boot_display = 1;
675} else {
676boot_display = 0;
677}
678verbose("boot display - %x\n", boot_display);
679devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4);
680
681if ((framebuffer[0] == 'M' && framebuffer[1] == 'o' && framebuffer[2] == 't') ||
682(framebuffer[0] == 'S' && framebuffer[1] == 'h' && framebuffer[2] == 'r') ||
683(framebuffer[0] == 'P' && framebuffer[1] == 'e' && framebuffer[2] == 'r')) //faster than strcmp ;)
684devprop_add_ati_template_4xxx(device);
685else {
686devprop_add_ati_template(device);
687vram_size = getvramsizekb(ati_dev) * 1024;
688if ((vram_size > 0x80000000) || (vram_size == 0)) {
689vram_size = 0x10000000;//vram reported wrong, defaulting to 256 mb
690}
691devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&vram_size, 4);
692ati_vram_memsize_0.data[6] = (vram_size >> 16) & 0xFF; //4,5 are 0x00 anyway
693ati_vram_memsize_0.data[7] = (vram_size >> 24) & 0xFF;
694ati_vram_memsize_1.data[6] = (vram_size >> 16) & 0xFF; //4,5 are 0x00 anyway
695ati_vram_memsize_1.data[7] = (vram_size >> 24) & 0xFF;
696DP_ADD_TEMP_VAL_DATA(device, ati_vram_memsize_0);
697DP_ADD_TEMP_VAL_DATA(device, ati_vram_memsize_1);
698devprop_add_iopciconfigspace(device, ati_dev);
699}
700devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
701devprop_add_value(device, "ATY,DeviceID", (uint8_t*)&ati_dev->device_id, 2);
702
703//fb setup
704sprintf(tmp, "Slot-%x",devices_number);
705devprop_add_value(device, "AAPL,slot-name", (uint8_t*)tmp, strlen(tmp) + 1);
706devices_number++;
707
708sprintf(tmp, ati_compatible_0[1], framebuffer);
709devprop_add_value(device, (char *) ati_compatible_0[0], (uint8_t *)tmp, strlen(tmp) + 1);
710
711sprintf(tmp, ati_compatible_1[1], framebuffer);
712devprop_add_value(device, (char *) ati_compatible_1[0], (uint8_t *)tmp, strlen(tmp) + 1);
713
714sprintf(tmp, ati_device_type[1], framebuffer);
715devprop_add_value(device, (char *) ati_device_type[0], (uint8_t *)tmp, strlen(tmp) + 1);
716
717sprintf(tmp, ati_name[1], framebuffer);
718devprop_add_value(device, (char *) ati_name[0], (uint8_t *)tmp, strlen(tmp) + 1);
719
720sprintf(tmp, ati_name_0[1], framebuffer);
721devprop_add_value(device, (char *) ati_name_0[0], (uint8_t *)tmp, strlen(tmp) + 1);
722
723sprintf(tmp, ati_name_1[1], framebuffer);
724devprop_add_value(device, (char *) ati_name_1[0], (uint8_t *)tmp, strlen(tmp) + 1);
725
726sprintf(tmp, "bt(0,0)/Extra/%04x_%04x.rom", (uint16_t)ati_dev->vendor_id, (uint16_t)ati_dev->device_id);
727if (getBoolForKey(kUseAtiROMKey, &doit, &bootInfo->chameleonConfig) && doit) {
728verbose("looking for ati video bios file %s\n", tmp);
729rom = malloc(0x20000);
730rom_size = load_ati_bios_file(tmp, rom, 0x20000);
731if (rom_size > 0) {
732verbose("Using ATI Video BIOS File %s (%d Bytes)\n", tmp, rom_size);
733if (rom_size > 0x10000) {
734rom_size = 0x10000; //we dont need rest anyway;
735}
736} else {
737printf("ERROR: unable to open ATI Video BIOS File %s\n", tmp);
738}
739}
740if (rom_size == 0) {
741if (boot_display) {// no custom rom
742bios = NULL;// try to dump from legacy space, otherwise can result in 100% fan speed
743} else {
744// readAtomBios result in bug on some cards (100% fan speed and black screen),
745// not using it for posted card, reading from legacy space instead
746bios = readAtomBIOS(ati_dev);
747}
748} else {
749bios = rom;//going custom rom way
750verbose("Using rom %s\n", tmp);
751}
752if (bios == NULL) {
753bios = (uint8_t *)0x000C0000;
754toFree = false;
755verbose("Not going to use bios image file\n");
756} else {
757toFree = true;
758}
759
760if (bios[0] == 0x55 && bios[1] == 0xaa) {
761verbose("Found bios image\n");
762bios_size = bios[2] * 512;
763
764rom_pci_header = (option_rom_pci_header_t*)(bios + bios[24] + bios[25]*256);
765
766if (rom_pci_header->signature == 0x52494350) {
767if (rom_pci_header->device_id != ati_dev->device_id) {
768verbose("Bios image (%x) doesnt match card (%x), ignoring\n", rom_pci_header->device_id, ati_dev->device_id);
769} else {
770if (toFree)
771{
772verbose("Adding binimage to card %x from mmio space with size %x\n", ati_dev->device_id, bios_size);
773} else {
774verbose("Adding binimage to card %x from legacy space with size %x\n", ati_dev->device_id, bios_size);
775}
776devprop_add_value(device, "ATY,bin_image", bios, bios_size);
777}
778} else {
779verbose("Wrong pci header signature %x\n", rom_pci_header->signature);
780}
781} else {
782verbose("Bios image not found at %x, content %x %x\n", bios, bios[0], bios[1]);
783}
784if (toFree) {
785free(bios);
786}
787stringdata = malloc(sizeof(uint8_t) * string->length);
788memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
789stringlength = string->length;
790
791return true;
792}
793

Archive Download this file

Revision: 1261