Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/libsaio/gma.c

1/*
2Original patch by Nawcom
3http://forum.voodooprojects.org/index.php/topic,1029.0.html
4*/
5
6#include "libsa.h"
7#include "saio_internal.h"
8#include "bootstruct.h"
9#include "pci.h"
10#include "platform.h"
11#include "device_inject.h"
12#include "gma.h"
13#include "graphics.h"
14
15#ifndef DEBUG_GMA
16#define DEBUG_GMA 0
17#endif
18
19#if DEBUG_GMA
20#define DBG(x...)verbose(x)
21#else
22#define DBG(x...)
23#endif
24
25uint8_t GMAX3100_vals[23][4] = {
26{ 0x01,0x00,0x00,0x00 },//0 "AAPL,HasPanel"
27{ 0x01,0x00,0x00,0x00 },//1 "AAPL,SelfRefreshSupported"
28{ 0x01,0x00,0x00,0x00 },//2 "AAPL,aux-power-connected"
29{ 0x01,0x00,0x00,0x08 },//3 "AAPL,backlight-control"
30{ 0x00,0x00,0x00,0x00 },//4 "AAPL00,blackscreen-preferences"
31{ 0x56,0x00,0x00,0x08 },//5 "AAPL01,BacklightIntensity"
32{ 0x00,0x00,0x00,0x00 },//6 "AAPL01,blackscreen-preferences"
33{ 0x01,0x00,0x00,0x00 },//7 "AAPL01,DataJustify"
34{ 0x20,0x00,0x00,0x00 },//8 "AAPL01,Depth"
35{ 0x01,0x00,0x00,0x00 },//9 "AAPL01,Dither"
36{ 0x20,0x03,0x00,0x00 },//10 "AAPL01,Height"
37{ 0x00,0x00,0x00,0x00 },//11 "AAPL01,Interlace"
38{ 0x00,0x00,0x00,0x00 },//12 "AAPL01,Inverter"
39{ 0x08,0x52,0x00,0x00 },//13 "AAPL01,InverterCurrent"
40{ 0x00,0x00,0x00,0x00 },//14 "AAPL01,LinkFormat"
41{ 0x00,0x00,0x00,0x00 },//15 "AAPL01,LinkType"
42{ 0x01,0x00,0x00,0x00 },//16 "AAPL01,Pipe"
43{ 0x01,0x00,0x00,0x00 },//17 "AAPL01,PixelFormat"
44{ 0x01,0x00,0x00,0x00 },//18 "AAPL01,Refresh"
45{ 0x3B,0x00,0x00,0x00 },//19 "AAPL01,Stretch"
46{ 0xc8,0x95,0x00,0x00 },//20 "AAPL01,InverterFrequency"
47{ 0x6B,0x10,0x00,0x00 },//21 "subsystem-vendor-id"
48{ 0xA2,0x00,0x00,0x00 },//22 "subsystem-id"};
49};
50
51uint8_t HD2000_vals[16][4] = {
52{ 0x00,0x00,0x00,0x00 },
53{ 0x00,0x00,0x00,0x00 },
54{ 0x14,0x00,0x00,0x00 },
55{ 0xfa,0x00,0x00,0x00 },
56{ 0x2c,0x01,0x00,0x00 },
57{ 0x00,0x00,0x00,0x00 },
58{ 0x14,0x00,0x00,0x00 },
59{ 0xf4,0x01,0x00,0x00 },
60{ 0x00,0x00,0x00,0x00 },
61{ 0x00,0x00,0x00,0x00 },
62{ 0x00,0x00,0x00,0x00 },
63{ 0x00,0x00,0x00,0x00 },
64{ 0x00,0x00,0x00,0x00 },
65{ 0x00,0x00,0x00,0x00 },
66{ 0x00,0x00,0x00,0x00 },
67{ 0x01,0x00,0x00,0x00 },
68};
69
70uint8_t HD3000_vals[16][4] = {
71{ 0x00,0x00,0x00,0x00 },
72{ 0x00,0x00,0x00,0x00 },
73{ 0x14,0x00,0x00,0x00 },
74{ 0xfa,0x00,0x00,0x00 },
75{ 0x2c,0x01,0x00,0x00 },
76{ 0x00,0x00,0x00,0x00 },
77{ 0x14,0x00,0x00,0x00 },
78{ 0xf4,0x01,0x00,0x00 },
79{ 0x00,0x00,0x00,0x00 },
80{ 0x00,0x00,0x00,0x00 },
81{ 0x00,0x00,0x00,0x00 },
82{ 0x00,0x00,0x00,0x00 },
83{ 0x00,0x00,0x00,0x00 },
84{ 0x00,0x00,0x00,0x00 },
85{ 0x00,0x00,0x00,0x00 },
86{ 0x01,0x00,0x00,0x00 },
87};
88
89uint8_t HD2000_tbl_info[18] = {
900x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
910x00,0x01,0x02,0x02,0x02,0x00,0x01,0x02,0x02
92};
93uint8_t HD2000_os_info[20] = {
940x30,0x49,0x01,0x11,0x11,0x11,0x08,0x00,0x00,0x01,
950xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
96};
97
98// The following values came from a Sandy Bridge MacBook Air
99uint8_t HD3000_tbl_info[18] = {
1000x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
1010x00,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01
102};
103
104// The following values came from a Sandy Bridge MacBook Air
105uint8_t HD3000_os_info[20] = {
1060x30,0x49,0x01,0x12,0x12,0x12,0x08,0x00,0x00,0x01,
1070xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
108};
109
110uint8_t reg_TRUE[]= { 0x01, 0x00, 0x00, 0x00 };
111uint8_t reg_FALSE[] = { 0x00, 0x00, 0x00, 0x00 };
112
113static struct gma_gpu_t KnownGPUS[] = {
114{ 0x00000000, "Unknown"},
115{ 0x80860042, "HD2000" },
116//{ 0x80860044, "HD2000" }, //host bridge
117{ 0x80860046, "HD2000" },
118{ 0x80862582, "GMA 915"},
119{ 0x80862592, "GMA 915"},
120{ 0x808627A2, "Mobile GMA950"},
121{ 0x808627AE, "Mobile GMA950"},
122//{ 0x808627A6, "Mobile GMA950"}, //not a GPU
123{ 0x8086A011, "Mobile GMA3150"},
124{ 0x8086A012, "Mobile GMA3150"},
125{ 0x80862772, "Desktop GMA950"},
126//{ 0x80862776, "Desktop GMA950"}, //not a GPU
127//{ 0x8086A001, "Desktop GMA3150" },
128{ 0x8086A001, "Mobile GMA3150"},
129{ 0x8086A002, "Desktop GMA3150" },
130{ 0x80862A02, "GMAX3100"},
131//{ 0x80862A03, "GMAX3100"}, //not a GPU
132{ 0x80862A12, "GMAX3100"},
133{ 0x80862A13, "GMAX3100"},
134{ 0x80862A42, "GMAX3100"},
135{ 0x80862A43, "GMAX3100"},
136{ 0x80860102, "Intel HD Graphics 2000"},
137{ 0x80860106, "Intel HD Graphics 2000 Mobile"},
138{ 0x80860112, "Intel HD Graphics 3000"},
139{ 0x80860116, "Intel HD Graphics 3000 Mobile"},
140{ 0x80860122, "Intel HD Graphics 3000"},
141{ 0x80860126, "Intel HD Graphics 3000 Mobile"},
142};
143
144char *get_gma_model(uint32_t id) {
145int i = 0;
146
147for (i = 0; i < (sizeof(KnownGPUS) / sizeof(KnownGPUS[0])); i++)
148{
149if (KnownGPUS[i].device == id)
150return KnownGPUS[i].name;
151}
152return KnownGPUS[0].name;
153}
154
155bool setup_gma_devprop(pci_dt_t *gma_dev)
156{
157char*devicepath;
158volatile uint8_t*regs;
159uint32_tbar[7];
160char*model;
161uint8_t BuiltIn =0x00;
162uint8_t ClassFix[4] ={ 0x00, 0x00, 0x03, 0x00 };
163unsigned intdevice_id;
164
165devicepath = get_pci_dev_path(gma_dev);
166
167bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10);
168regs = (uint8_t *) (bar[0] & ~0x0f);
169
170model = get_gma_model((gma_dev->vendor_id << 16) | gma_dev->device_id);
171device_id = gma_dev->device_id;
172
173verbose("Intel %s [%04x:%04x] :: %s\n",
174model, gma_dev->vendor_id, gma_dev->device_id, devicepath);
175
176if (!string)
177string = devprop_create_string();
178
179struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice));
180device = devprop_add_device(string, devicepath);
181
182if (!device)
183{
184printf("Failed initializing dev-prop string dev-entry.\n");
185pause();
186return false;
187}
188
189devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
190devprop_add_value(device, "device_type", (uint8_t*)"display", 8);
191
192if ((model == (char *)"Mobile GMA950") || (model == (char *)"Mobile GMA3150"))
193{
194devprop_add_value(device, "AAPL,HasPanel", reg_TRUE, 4);
195devprop_add_value(device, "built-in", &BuiltIn, 1);
196devprop_add_value(device, "class-code", ClassFix, 4);
197}
198else if ((model == (char *)"Desktop GMA950") || (model == (char *)"Desktop GMA3150"))
199{
200BuiltIn = 0x01;
201devprop_add_value(device, "built-in", &BuiltIn, 1);
202devprop_add_value(device, "class-code", ClassFix, 4);
203}
204else if (model == (char *)"GMAX3100")
205{
206BuiltIn = gDualLink;
207devprop_add_value(device, "AAPL,HasPanel",GMAX3100_vals[0], 4);
208devprop_add_value(device, "AAPL,SelfRefreshSupported",GMAX3100_vals[1], 4);
209devprop_add_value(device, "AAPL,aux-power-connected",GMAX3100_vals[2], 4);
210devprop_add_value(device, "AAPL,backlight-control",GMAX3100_vals[3], 4);
211devprop_add_value(device, "AAPL00,blackscreen-preferences",GMAX3100_vals[4], 4);
212devprop_add_value(device, "AAPL01,BacklightIntensity",GMAX3100_vals[5], 4);
213devprop_add_value(device, "AAPL01,blackscreen-preferences",GMAX3100_vals[6], 4);
214devprop_add_value(device, "AAPL01,DataJustify",GMAX3100_vals[7], 4);
215devprop_add_value(device, "AAPL01,Depth",GMAX3100_vals[8], 4);
216devprop_add_value(device, "AAPL01,Dither",GMAX3100_vals[9], 4);
217devprop_add_value(device, "AAPL01,DualLink",&BuiltIn, 1);//GMAX3100_vals[10]
218devprop_add_value(device, "AAPL01,Height",GMAX3100_vals[10], 4);
219devprop_add_value(device, "AAPL01,Interlace",GMAX3100_vals[11], 4);
220devprop_add_value(device, "AAPL01,Inverter",GMAX3100_vals[12], 4);
221devprop_add_value(device, "AAPL01,InverterCurrent",GMAX3100_vals[13], 4);
222//devprop_add_value(device, "AAPL01,InverterCurrency",GMAX3100_vals[15], 4);
223devprop_add_value(device, "AAPL01,LinkFormat",GMAX3100_vals[14], 4);
224devprop_add_value(device, "AAPL01,LinkType",GMAX3100_vals[15], 4);
225devprop_add_value(device, "AAPL01,Pipe",GMAX3100_vals[16], 4);
226devprop_add_value(device, "AAPL01,PixelFormat",GMAX3100_vals[17], 4);
227devprop_add_value(device, "AAPL01,Refresh",GMAX3100_vals[18], 4);
228devprop_add_value(device, "AAPL01,Stretch",GMAX3100_vals[19], 4);
229devprop_add_value(device, "AAPL01,InverterFrequency",GMAX3100_vals[20], 4);
230devprop_add_value(device, "class-code",ClassFix, 4);
231devprop_add_value(device, "subsystem-vendor-id",GMAX3100_vals[21], 4);
232devprop_add_value(device, "subsystem-id",GMAX3100_vals[22], 4);
233}
234else if (model == (char *)"Intel HD Graphics 2000 Mobile")
235{
236devprop_add_value(device, "class-code", ClassFix, 4);
237devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
238devprop_add_value(device, "AAPL00,PixelFormat",HD2000_vals[0], 4);
239devprop_add_value(device, "AAPL00,T1",HD2000_vals[1], 4);
240devprop_add_value(device, "AAPL00,T2",HD2000_vals[2], 4);
241devprop_add_value(device, "AAPL00,T3",HD2000_vals[3], 4);
242devprop_add_value(device, "AAPL00,T4",HD2000_vals[4], 4);
243devprop_add_value(device, "AAPL00,T5",HD2000_vals[5], 4);
244devprop_add_value(device, "AAPL00,T6",HD2000_vals[6], 4);
245devprop_add_value(device, "AAPL00,T7",HD2000_vals[7], 4);
246devprop_add_value(device, "AAPL00,LinkType",HD2000_vals[8], 4);
247devprop_add_value(device, "AAPL00,LinkFormat",HD2000_vals[9], 4);
248devprop_add_value(device, "AAPL00,DualLink",HD2000_vals[10], 4);
249devprop_add_value(device, "AAPL00,Dither",HD2000_vals[11], 4);
250devprop_add_value(device, "AAPL00,DataJustify",HD3000_vals[12], 4);
251devprop_add_value(device, "graphic-options",HD2000_vals[13], 4);
252devprop_add_value(device, "AAPL,tbl-info",HD2000_tbl_info, 18);
253devprop_add_value(device, "AAPL,os-info",HD2000_os_info, 20);
254}
255else if (model == (char *)"Intel HD Graphics 3000 Mobile")
256{
257devprop_add_value(device, "class-code",ClassFix, 4);
258devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
259devprop_add_value(device, "AAPL00,PixelFormat",HD3000_vals[0], 4);
260devprop_add_value(device, "AAPL00,T1",HD3000_vals[1], 4);
261devprop_add_value(device, "AAPL00,T2",HD3000_vals[2], 4);
262devprop_add_value(device, "AAPL00,T3",HD3000_vals[3], 4);
263devprop_add_value(device, "AAPL00,T4",HD3000_vals[4], 4);
264devprop_add_value(device, "AAPL00,T5",HD3000_vals[5], 4);
265devprop_add_value(device, "AAPL00,T6",HD3000_vals[6], 4);
266devprop_add_value(device, "AAPL00,T7",HD3000_vals[7], 4);
267devprop_add_value(device, "AAPL00,LinkType",HD3000_vals[8], 4);
268devprop_add_value(device, "AAPL00,LinkFormat",HD3000_vals[9], 4);
269devprop_add_value(device, "AAPL00,DualLink",HD3000_vals[10], 4);
270devprop_add_value(device, "AAPL00,Dither",HD3000_vals[11], 4);
271devprop_add_value(device, "AAPL00,DataJustify",HD3000_vals[12], 4);
272devprop_add_value(device, "graphic-options",HD3000_vals[13], 4);
273devprop_add_value(device, "AAPL,tbl-info",HD3000_tbl_info, 18);
274devprop_add_value(device, "AAPL,os-info",HD3000_os_info, 20);
275}
276else if (model == (char *)"Intel HD Graphics 2000")
277{
278devprop_add_value(device, "built-in",&BuiltIn, 1);
279devprop_add_value(device, "class-code",ClassFix, 4);
280devprop_add_value(device, "device-id",(uint8_t*)&device_id, sizeof(device_id));
281devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
282devprop_add_value(device, "AAPL,tbl-info",HD2000_tbl_info, 18);
283devprop_add_value(device, "AAPL,os-info",HD2000_os_info, 20);
284}
285else if (model == (char *)"Intel HD Graphics 3000")
286{
287devprop_add_value(device, "built-in",&BuiltIn, 1);
288devprop_add_value(device, "class-code",ClassFix, 4);
289device_id = 0x00000126;// Inject a valid mobile GPU device id instead of patching kexts
290devprop_add_value(device, "device-id",(uint8_t*)&device_id, sizeof(device_id));
291devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
292devprop_add_value(device, "AAPL,tbl-info",HD3000_tbl_info, 18);
293devprop_add_value(device, "AAPL,os-info",HD3000_os_info, 20);
294}
295
296stringdata = malloc(sizeof(uint8_t) * string->length);
297if (!stringdata)
298{
299printf("No stringdata.\n");
300pause();
301return false;
302}
303
304memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
305stringlength = string->length;
306
307return true;
308}
309

Archive Download this file

Revision: 1987