Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/GraphicsEnabler/ati.c

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

Archive Download this file

Revision: 519