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

Archive Download this file

Revision: 1335