Chameleon

Chameleon Svn Source Tree

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

1/*
2Original patch by Nawcom
3http://forum.voodooprojects.org/index.php/topic,1029.0.html
4
5Original Intel HDx000 code from valv
6*/
7
8#include "libsa.h"
9#include "saio_internal.h"
10#include "bootstruct.h"
11#include "pci.h"
12#include "platform.h"
13#include "device_inject.h"
14#include "gma.h"
15
16#ifndef DEBUG_GMA
17#define DEBUG_GMA 0
18#endif
19
20#if DEBUG_GMA
21#define DBG(x...)printf(x)
22#else
23#define DBG(x...)
24#endif
25
26uint8_t GMAX3100_vals[22][4] = {
27{ 0x01,0x00,0x00,0x00 },// "AAPL,HasPanel"
28{ 0x01,0x00,0x00,0x00 },// "AAPL,SelfRefreshSupported"
29{ 0x01,0x00,0x00,0x00 },
30{ 0x00,0x00,0x00,0x08 },
31{ 0x64,0x00,0x00,0x00 },
32{ 0x00,0x00,0x00,0x08 },// "AAPL01,blackscreen-preferences"
33{ 0x01,0x00,0x00,0x00 },// "AAPL01,DataJustify"
34{ 0x20,0x00,0x00,0x00 },// "AAPL01,Depth"
35{ 0x00,0x00,0x00,0x00 },
36{ 0x01,0x00,0x00,0x00 },
37{ 0x20,0x03,0x00,0x00 },// "AAPL01,Height"
38{ 0x00,0x00,0x00,0x00 },
39{ 0x00,0x00,0x00,0x00 },
40{ 0x00,0x00,0x00,0x00 },// "AAPL01,Inverter"
41{ 0x08,0x52,0x00,0x00 },// "AAPL01,InverterCurrent"
42{ 0x00,0x00,0x00,0x00 },// "AAPL01,LinkFormat"
43{ 0x00,0x00,0x00,0x00 },// "AAPL01,LinkType"
44{ 0x01,0x00,0x00,0x00 },// "AAPL01,Pipe"
45{ 0x01,0x00,0x00,0x00 },
46{ 0x3B,0x00,0x00,0x00 },// "AAPL01,Stretch"
47{ 0x00,0x00,0x00,0x00 }
48};
49
50uint8_t HD2000_vals[16][4] = {
51{ 0x00,0x00,0x00,0x00 },
52{ 0x00,0x00,0x00,0x00 },
53{ 0x14,0x00,0x00,0x00 },
54{ 0xfa,0x00,0x00,0x00 },
55{ 0x2c,0x01,0x00,0x00 },
56{ 0x00,0x00,0x00,0x00 },
57{ 0x14,0x00,0x00,0x00 },
58{ 0xf4,0x01,0x00,0x00 },
59{ 0x00,0x00,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{ 0x01,0x00,0x00,0x00 },
67};
68
69uint8_t HD3000_vals[16][4] = {
70{ 0x00,0x00,0x00,0x00 },
71{ 0x00,0x00,0x00,0x00 },
72{ 0x14,0x00,0x00,0x00 },
73{ 0xfa,0x00,0x00,0x00 },
74{ 0x2c,0x01,0x00,0x00 },
75{ 0x00,0x00,0x00,0x00 },
76{ 0x14,0x00,0x00,0x00 },
77{ 0xf4,0x01,0x00,0x00 },
78{ 0x00,0x00,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{ 0x01,0x00,0x00,0x00 },
86};
87
88uint8_t HD2000_tbl_info[18] = {
890x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
900x00,0x01,0x02,0x02,0x02,0x00,0x01,0x02,0x02
91};
92uint8_t HD2000_os_info[20] = {
930x30,0x49,0x01,0x11,0x11,0x11,0x08,0x00,0x00,0x01,
940xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
95};
96
97// The following values came from a Sandy Bridge MacBook Air
98uint8_t HD3000_tbl_info[18] = {
990x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
1000x00,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01
101};
102
103// The following values came from a Sandy Bridge MacBook Air
104uint8_t HD3000_os_info[20] = {
1050x30,0x49,0x01,0x12,0x12,0x12,0x08,0x00,0x00,0x01,
1060xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
107};
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{ 0x80860152, "Intel HD Graphics 2500"},
143{ 0x80860156, "Intel HD Graphics 2500 Mobile"},
144{ 0x80860162, "Intel HD Graphics 4000"},
145{ 0x80860166, "Intel HD Graphics 4000 Mobile"},
146};
147
148char *get_gma_model(uint32_t id) {
149int i;
150
151for (i = 0; i < (sizeof(KnownGPUS) / sizeof(KnownGPUS[0])); i++)
152{
153if (KnownGPUS[i].device == id)
154return KnownGPUS[i].name;
155}
156return KnownGPUS[0].name;
157}
158
159bool setup_gma_devprop(pci_dt_t *gma_dev)
160{
161char*devicepath;
162volatile uint8_t*regs;
163uint32_tbar[7];
164char*model;
165uint8_t BuiltIn =0x00;
166uint8_t ClassFix[4] = { 0x00, 0x00, 0x03, 0x00 };
167unsigned intdevice_id;
168structDevPropDevice *device = NULL;
169
170devicepath = get_pci_dev_path(gma_dev);
171
172bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10);
173regs = (uint8_t *) (bar[0] & ~0x0f);
174
175model = get_gma_model((gma_dev->vendor_id << 16) | gma_dev->device_id);
176device_id = gma_dev->device_id;
177
178verbose("Intel %s [%04x:%04x] :: %s\n",
179model, gma_dev->vendor_id, gma_dev->device_id, devicepath);
180
181if (!string)
182{
183string = devprop_create_string();
184}
185
186device = devprop_add_device(string, devicepath);
187
188if (!device)
189{
190printf("Failed initializing dev-prop string dev-entry.\n");
191pause();
192return false;
193}
194
195devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
196devprop_add_value(device, "device_type", (uint8_t*)"display", 8);
197
198
199if ((model == (char *)&"Mobile GMA950") || (model == (char *)&"Mobile GMA3150"))
200{
201devprop_add_value(device, "AAPL,HasPanel", reg_TRUE, 4);
202devprop_add_value(device, "built-in", &BuiltIn, 1);
203devprop_add_value(device, "class-code", ClassFix, 4);
204}
205else if ((model == (char *)&"Desktop GMA950") || (model == (char *)&"Desktop GMA3150"))
206{
207BuiltIn = 0x01;
208devprop_add_value(device, "built-in", &BuiltIn, 1);
209devprop_add_value(device, "class-code", ClassFix, 4);
210}
211else if (model == (char *)&"GMAX3100")
212{
213devprop_add_value(device, "AAPL,HasPanel",GMAX3100_vals[0], 4);
214devprop_add_value(device, "AAPL,SelfRefreshSupported",GMAX3100_vals[1], 4);
215devprop_add_value(device, "AAPL,aux-power-connected",GMAX3100_vals[2], 4);
216devprop_add_value(device, "AAPL,backlight-control",GMAX3100_vals[3], 4);
217devprop_add_value(device, "AAPL00,blackscreen-preferences",GMAX3100_vals[4], 4);
218devprop_add_value(device, "AAPL01,BacklightIntensity",GMAX3100_vals[5], 4);
219devprop_add_value(device, "AAPL01,blackscreen-preferences",GMAX3100_vals[6], 4);
220devprop_add_value(device, "AAPL01,DataJustify",GMAX3100_vals[7], 4);
221devprop_add_value(device, "AAPL01,Depth",GMAX3100_vals[8], 4);
222devprop_add_value(device, "AAPL01,Dither",GMAX3100_vals[9], 4);
223devprop_add_value(device, "AAPL01,DualLink",GMAX3100_vals[10], 4);
224devprop_add_value(device, "AAPL01,Height",GMAX3100_vals[11], 4);
225devprop_add_value(device, "AAPL01,Interlace",GMAX3100_vals[12], 4);
226devprop_add_value(device, "AAPL01,Inverter",GMAX3100_vals[13], 4);
227devprop_add_value(device, "AAPL01,InverterCurrent",GMAX3100_vals[14], 4);
228devprop_add_value(device, "AAPL01,InverterCurrency",GMAX3100_vals[15], 4);
229devprop_add_value(device, "AAPL01,LinkFormat",GMAX3100_vals[16], 4);
230devprop_add_value(device, "AAPL01,LinkType",GMAX3100_vals[17], 4);
231devprop_add_value(device, "AAPL01,Pipe",GMAX3100_vals[18], 4);
232devprop_add_value(device, "AAPL01,PixelFormat",GMAX3100_vals[19], 4);
233devprop_add_value(device, "AAPL01,Refresh",GMAX3100_vals[20], 4);
234devprop_add_value(device, "AAPL01,Stretch",GMAX3100_vals[21], 4);
235devprop_add_value(device, "class-code",ClassFix, 4);
236}
237else if (model == (char *)&"Intel HD Graphics 2000 Mobile")
238{
239devprop_add_value(device, "class-code", ClassFix, 4);
240devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
241devprop_add_value(device, "AAPL00,PixelFormat",HD2000_vals[0], 4);
242devprop_add_value(device, "AAPL00,T1",HD2000_vals[1], 4);
243devprop_add_value(device, "AAPL00,T2",HD2000_vals[2], 4);
244devprop_add_value(device, "AAPL00,T3",HD2000_vals[3], 4);
245devprop_add_value(device, "AAPL00,T4",HD2000_vals[4], 4);
246devprop_add_value(device, "AAPL00,T5",HD2000_vals[5], 4);
247devprop_add_value(device, "AAPL00,T6",HD2000_vals[6], 4);
248devprop_add_value(device, "AAPL00,T7",HD2000_vals[7], 4);
249devprop_add_value(device, "AAPL00,LinkType",HD2000_vals[8], 4);
250devprop_add_value(device, "AAPL00,LinkFormat",HD2000_vals[9], 4);
251devprop_add_value(device, "AAPL00,DualLink",HD2000_vals[10], 4);
252devprop_add_value(device, "AAPL00,Dither",HD2000_vals[11], 4);
253devprop_add_value(device, "AAPL00,DataJustify",HD3000_vals[12], 4);
254devprop_add_value(device, "graphic-options",HD2000_vals[13], 4);
255devprop_add_value(device, "AAPL,tbl-info",HD2000_tbl_info, 18);
256devprop_add_value(device, "AAPL,os-info",HD2000_os_info, 20);
257}
258else if (model == (char *)&"Intel HD Graphics 3000 Mobile")
259{
260devprop_add_value(device, "class-code",ClassFix, 4);
261devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
262devprop_add_value(device, "AAPL00,PixelFormat",HD3000_vals[0], 4);
263devprop_add_value(device, "AAPL00,T1",HD3000_vals[1], 4);
264devprop_add_value(device, "AAPL00,T2",HD3000_vals[2], 4);
265devprop_add_value(device, "AAPL00,T3",HD3000_vals[3], 4);
266devprop_add_value(device, "AAPL00,T4",HD3000_vals[4], 4);
267devprop_add_value(device, "AAPL00,T5",HD3000_vals[5], 4);
268devprop_add_value(device, "AAPL00,T6",HD3000_vals[6], 4);
269devprop_add_value(device, "AAPL00,T7",HD3000_vals[7], 4);
270devprop_add_value(device, "AAPL00,LinkType",HD3000_vals[8], 4);
271devprop_add_value(device, "AAPL00,LinkFormat",HD3000_vals[9], 4);
272devprop_add_value(device, "AAPL00,DualLink",HD3000_vals[10], 4);
273devprop_add_value(device, "AAPL00,Dither",HD3000_vals[11], 4);
274devprop_add_value(device, "AAPL00,DataJustify",HD3000_vals[12], 4);
275devprop_add_value(device, "graphic-options",HD3000_vals[13], 4);
276devprop_add_value(device, "AAPL,tbl-info",HD3000_tbl_info, 18);
277devprop_add_value(device, "AAPL,os-info",HD3000_os_info, 20);
278}
279else if (model == (char *)&"Intel HD Graphics 4000")
280{
281devprop_add_value(device, "built-in",&BuiltIn, 1);
282devprop_add_value(device, "class-code",ClassFix, 4);
283devprop_add_value(device, "device-id",(uint8_t*)&device_id, sizeof(device_id));
284devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
285devprop_add_value(device, "AAPL,tbl-info",HD2000_tbl_info, 18);
286devprop_add_value(device, "AAPL,os-info",HD2000_os_info, 20);
287}
288else if (model == (char *)&"Intel HD Graphics 3000")
289{
290devprop_add_value(device, "built-in",&BuiltIn, 1);
291devprop_add_value(device, "class-code",ClassFix, 4);
292device_id = 0x00000126;// Inject a valid mobile GPU device id instead of patching kexts
293devprop_add_value(device, "device-id",(uint8_t*)&device_id, sizeof(device_id));
294devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
295devprop_add_value(device, "AAPL,tbl-info",HD3000_tbl_info, 18);
296devprop_add_value(device, "AAPL,os-info",HD3000_os_info, 20);
297}
298else if (!strncmp(model, "Intel HD Graphics 2500", 12U) || !strncmp(model, "Intel HD Graphics 4000", 12U))
299{
300uint32_t ig_platform_id = 0U;// Default to 0x01660000
301getIntForKey("IGPlatformId",(int*)&ig_platform_id, &bootInfo->chameleonConfig);
302if (ig_platform_id > 11U)
303{
304ig_platform_id = 0U;
305}
306
307if (ig_platform_id >= 5U && ig_platform_id <= 7U)
308{
309ig_platform_id |= 0x01620000U;
310}
311else
312{
313ig_platform_id |= 0x01660000U;
314}
315devprop_add_value(device, "AAPL,ig-platform-id",(uint8_t*)&ig_platform_id, sizeof ig_platform_id);
316#if 0
317devprop_add_value(device, "built-in",&BuiltIn, 1);
318devprop_add_value(device, "class-code",ClassFix, 4);
319devprop_add_value(device, "hda-gfx",(uint8_t *)"onboard-1", 10);
320#endif
321
322#if 0
323{
324DevPropDevice *meiDevice = NULL;
325uint32_t mei_device_id = 0x1e3aU;
326meiDevice = devprop_add_device(string, "PciRoot(0x0)/Pci(0x16,0x0)");
327if (meiDevice)
328{
329devprop_add_value(meiDevice, "device-id",(uint8_t*)&mei_device_id, sizeof mei_device_id);
330}
331else
332{
333printf("Failed initializing dev-prop MEIDevice.\n");
334}
335}
336#endif
337}
338
339stringdata = malloc(sizeof(uint8_t) * string->length);
340if (!stringdata)
341{
342printf("No stringdata.\n");
343pause();
344return false;
345}
346
347memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
348stringlength = string->length;
349
350return true;
351}
352

Archive Download this file

Revision: 2142