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