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

Archive Download this file

Revision: 1342