Chameleon

View gma.c

1/*
2Original patch by Nawcom
3http://forum.voodooprojects.org/index.php/topic,1029.0.html
4
5 Original 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#include "vbe.h"
16#include "graphics.h"
17
18#ifndef DEBUG_GMA
19#define DEBUG_GMA 0
20#endif
21
22#if DEBUG_GMA
23#define DBG(x...)printf(x)
24#else
25#define DBG(x...)
26#endif
27
28uint8_t GMAX3100_vals[22][4] = {
29{ 0x01,0x00,0x00,0x00 },
30{ 0x01,0x00,0x00,0x00 },
31{ 0x01,0x00,0x00,0x00 },
32{ 0x00,0x00,0x00,0x08 },
33{ 0x64,0x00,0x00,0x00 },
34{ 0x00,0x00,0x00,0x08 },
35{ 0x01,0x00,0x00,0x00 },
36{ 0x20,0x00,0x00,0x00 },
37{ 0x00,0x00,0x00,0x00 },
38{ 0x01,0x00,0x00,0x00 },
39{ 0x20,0x03,0x00,0x00 },
40{ 0x00,0x00,0x00,0x00 },
41{ 0x00,0x00,0x00,0x00 },
42{ 0x00,0x00,0x00,0x00 },
43{ 0x08,0x52,0x00,0x00 },
44{ 0x00,0x00,0x00,0x00 },
45{ 0x00,0x00,0x00,0x00 },
46{ 0x01,0x00,0x00,0x00 },
47{ 0x01,0x00,0x00,0x00 },
48{ 0x3B,0x00,0x00,0x00 },
49{ 0x00,0x00,0x00,0x00 }
50};
51
52uint8_t HD2000_vals[16][4] = {
53{ 0x00,0x00,0x00,0x00 },
54{ 0x00,0x00,0x00,0x00 },
55{ 0x14,0x00,0x00,0x00 },
56{ 0xfa,0x00,0x00,0x00 },
57{ 0x2c,0x01,0x00,0x00 },
58{ 0x00,0x00,0x00,0x00 },
59{ 0x14,0x00,0x00,0x00 },
60{ 0xf4,0x01,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{ 0x00,0x00,0x00,0x00 },
68{ 0x01,0x00,0x00,0x00 },
69};
70
71uint8_t HD3000_vals[16][4] = {
72{ 0x00,0x00,0x00,0x00 },
73{ 0x00,0x00,0x00,0x00 },
74{ 0x14,0x00,0x00,0x00 },
75{ 0xfa,0x00,0x00,0x00 },
76{ 0x2c,0x01,0x00,0x00 },
77{ 0x00,0x00,0x00,0x00 },
78{ 0x14,0x00,0x00,0x00 },
79{ 0xf4,0x01,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{ 0x00,0x00,0x00,0x00 },
87{ 0x01,0x00,0x00,0x00 },
88};
89
90uint8_t HD2000_tbl_info[18] = {
910x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
920x00,0x01,0x02,0x02,0x02,0x00,0x01,0x02,0x02
93};
94uint8_t HD2000_os_info[20] = {
950x30,0x49,0x01,0x11,0x11,0x11,0x08,0x00,0x00,0x01,
960xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
97};
98
99// The following values came from a Sandy Bridge MacBook Air
100uint8_t HD3000_tbl_info[18] = {
1010x30,0x44,0x02,0x02,0x02,0x02,0x00,0x00,0x00,
1020x00,0x02,0x02,0x02,0x02,0x01,0x01,0x01,0x01
103};
104
105// The following values came from a Sandy Bridge MacBook Air
106uint8_t HD3000_os_info[20] = {
1070x30,0x49,0x01,0x12,0x12,0x12,0x08,0x00,0x00,0x01,
1080xf0,0x1f,0x01,0x00,0x00,0x00,0x10,0x07,0x00,0x00
109};
110
111
112uint8_t reg_TRUE[]= { 0x01, 0x00, 0x00, 0x00 };
113uint8_t reg_FALSE[] = { 0x00, 0x00, 0x00, 0x00 };
114
115static struct gma_gpu_t KnownGPUS[] = {
116{ 0x00000000, "Unknown"},
117{ 0x808627A2, "Mobile GMA950"},
118{ 0x808627AE, "Mobile GMA950"},
119{ 0x808627A6, "Mobile GMA950"},
120{ 0x8086A011, "Mobile GMA3150"},
121{ 0x8086A012, "Mobile GMA3150"},
122{ 0x80862772, "Desktop GMA950"},
123{ 0x80862776, "Desktop GMA950"},
124//{ 0x8086A001, "Desktop GMA3150" },
125{ 0x8086A001, "Mobile GMA3150"},
126{ 0x8086A002, "Desktop GMA3150" },
127{ 0x80862A02, "GMAX3100"},
128{ 0x80862A03, "GMAX3100"},
129{ 0x80862A12, "GMAX3100"},
130{ 0x80862A13, "GMAX3100"},
131{ 0x80862A42, "GMAX3100"},
132{ 0x80862A43, "GMAX3100"},
133{ 0x80860102, "HD Graphics 2000"},
134{ 0x80860106, "HD Graphics 2000 Mobile"},
135{ 0x80860112, "HD Graphics 3000"},
136{ 0x80860116, "HD Graphics 3000 Mobile"},
137{ 0x80860122, "HD Graphics 3000"},
138{ 0x80860126, "HD Graphics 3000 Mobile"},
139{ 0x80860162, "HD Graphics 4000" },
140{ 0x80860166, "HD Graphics 4000 Mobile" },
141};
142
143char *get_gma_model(uint32_t id) {
144int i = 0;
145
146for (i = 0; i < (sizeof(KnownGPUS) / sizeof(KnownGPUS[0])); i++)
147{
148if (KnownGPUS[i].device == id)
149return KnownGPUS[i].name;
150}
151return KnownGPUS[0].name;
152}
153
154bool setup_gma_devprop(pci_dt_t *gma_dev)
155{
156char*devicepath;
157volatile uint8_t*regs;
158uint32_tbar[7];
159char*model;
160uint8_t BuiltIn =0x00;
161uint8_t ClassFix[4] ={ 0x00, 0x00, 0x03, 0x00 };
162unsigned intdevice_id;
163
164devicepath = get_pci_dev_path(gma_dev);
165
166bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10);
167regs = (uint8_t *) (bar[0] & ~0x0f);
168
169model = get_gma_model((gma_dev->vendor_id << 16) | gma_dev->device_id);
170device_id = gma_dev->device_id;
171
172verbose("Intel %s [%04x:%04x] :: %s\n",
173model, gma_dev->vendor_id, gma_dev->device_id, devicepath);
174
175if (!string)
176string = devprop_create_string();
177
178struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice));
179device = devprop_add_device(string, devicepath);
180
181if (!device)
182{
183printf("Failed initializing dev-prop string dev-entry.\n");
184pause();
185return false;
186}
187
188devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1));
189devprop_add_value(device, "device_type", (uint8_t*)"display", 8);
190
191if ((model == (char *)&"Mobile GMA950")
192|| (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")
199|| (model == (char *)&"Desktop GMA3150"))
200{
201BuiltIn = 0x01;
202devprop_add_value(device, "built-in", &BuiltIn, 1);
203devprop_add_value(device, "class-code", ClassFix, 4);
204}
205else if (model == (char *)&"GMAX3100")
206{
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",GMAX3100_vals[10], 4);
218devprop_add_value(device, "AAPL01,Height",GMAX3100_vals[11], 4);
219devprop_add_value(device, "AAPL01,Interlace",GMAX3100_vals[12], 4);
220devprop_add_value(device, "AAPL01,Inverter",GMAX3100_vals[13], 4);
221devprop_add_value(device, "AAPL01,InverterCurrent",GMAX3100_vals[14], 4);
222devprop_add_value(device, "AAPL01,InverterCurrency",GMAX3100_vals[15], 4);
223devprop_add_value(device, "AAPL01,LinkFormat",GMAX3100_vals[16], 4);
224devprop_add_value(device, "AAPL01,LinkType",GMAX3100_vals[17], 4);
225devprop_add_value(device, "AAPL01,Pipe",GMAX3100_vals[18], 4);
226devprop_add_value(device, "AAPL01,PixelFormat",GMAX3100_vals[19], 4);
227devprop_add_value(device, "AAPL01,Refresh",GMAX3100_vals[20], 4);
228devprop_add_value(device, "AAPL01,Stretch",GMAX3100_vals[21], 4);
229devprop_add_value(device, "class-code",ClassFix, 4);
230}
231else if (model == (char *)&"HD Graphics 2000 Mobile")
232{
233devprop_add_value(device, "class-code", ClassFix, 4);
234devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
235devprop_add_value(device, "AAPL00,PixelFormat", HD2000_vals[0], 4);
236devprop_add_value(device, "AAPL00,T1", HD2000_vals[1], 4);
237devprop_add_value(device, "AAPL00,T2", HD2000_vals[2], 4);
238devprop_add_value(device, "AAPL00,T3", HD2000_vals[3], 4);
239devprop_add_value(device, "AAPL00,T4", HD2000_vals[4], 4);
240devprop_add_value(device, "AAPL00,T5", HD2000_vals[5], 4);
241devprop_add_value(device, "AAPL00,T6", HD2000_vals[6], 4);
242devprop_add_value(device, "AAPL00,T7", HD2000_vals[7], 4);
243devprop_add_value(device, "AAPL00,LinkType", HD2000_vals[8], 4);
244devprop_add_value(device, "AAPL00,LinkFormat", HD2000_vals[9], 4);
245devprop_add_value(device, "AAPL00,DualLink", HD2000_vals[10], 4);
246devprop_add_value(device, "AAPL00,Dither", HD2000_vals[11], 4);
247devprop_add_value(device, "AAPL00,DataJustify", HD3000_vals[12], 4);
248devprop_add_value(device, "graphic-options", HD2000_vals[13], 4);
249devprop_add_value(device, "AAPL,tbl-info", HD2000_tbl_info, 18);
250devprop_add_value(device, "AAPL,os-info", HD2000_os_info, 20);
251}
252else if (model == (char *)&"HD Graphics 3000 Mobile")
253{
254devprop_add_value(device, "class-code", ClassFix, 4);
255devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
256devprop_add_value(device, "AAPL00,PixelFormat", HD3000_vals[0], 4);
257devprop_add_value(device, "AAPL00,T1", HD3000_vals[1], 4);
258devprop_add_value(device, "AAPL00,T2", HD3000_vals[2], 4);
259devprop_add_value(device, "AAPL00,T3", HD3000_vals[3], 4);
260devprop_add_value(device, "AAPL00,T4", HD3000_vals[4], 4);
261devprop_add_value(device, "AAPL00,T5", HD3000_vals[5], 4);
262devprop_add_value(device, "AAPL00,T6", HD3000_vals[6], 4);
263devprop_add_value(device, "AAPL00,T7", HD3000_vals[7], 4);
264devprop_add_value(device, "AAPL00,LinkType", HD3000_vals[8], 4);
265devprop_add_value(device, "AAPL00,LinkFormat", HD3000_vals[9], 4);
266devprop_add_value(device, "AAPL00,DualLink", HD3000_vals[10], 4);
267devprop_add_value(device, "AAPL00,Dither", HD3000_vals[11], 4);
268devprop_add_value(device, "AAPL00,DataJustify", HD3000_vals[12], 4);
269devprop_add_value(device, "graphic-options", HD3000_vals[13], 4);
270devprop_add_value(device, "AAPL,tbl-info", HD3000_tbl_info, 18);
271devprop_add_value(device, "AAPL,os-info", HD3000_os_info, 20);
272}
273else if (model == (char *)&"HD Graphics 2000")
274{
275devprop_add_value(device, "built-in", &BuiltIn, 1);
276devprop_add_value(device, "class-code", ClassFix, 4);
277devprop_add_value(device, "device-id", (uint8_t*)&device_id, sizeof(device_id));
278devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
279devprop_add_value(device, "AAPL,tbl-info", HD2000_tbl_info, 18);
280devprop_add_value(device, "AAPL,os-info", HD2000_os_info, 20);
281}
282else if (model == (char *)&"HD Graphics 3000")
283{
284devprop_add_value(device, "built-in", &BuiltIn, 1);
285devprop_add_value(device, "class-code", ClassFix, 4);
286device_id = 0x00000126;// Inject a valid mobile GPU device id instead of patching kexts
287devprop_add_value(device, "device-id", (uint8_t*)&device_id, sizeof(device_id));
288devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
289devprop_add_value(device, "AAPL,tbl-info", HD3000_tbl_info, 18);
290devprop_add_value(device, "AAPL,os-info", HD3000_os_info, 20);
291}
292else if(model == (char*)&"HD Graphics 4000" ||
293model == (char*)&"HD Graphics 4000 Mobile")
294{
295uint32_t ram = (((getVBEVideoRam() + 512) / 1024) + 512) / 1024;
296uint32_t ig_platform_id;
297
298switch (ram)
299{
300case 96:
301ig_platform_id = 0x01660000; // 96mb
302break;
303
304case 64:
305ig_platform_id = 0x01660009; // 64mb
306break;
307
308case 32:
309ig_platform_id = 0x01620005; // 32mb
310break;
311default:
312printf("Please specify 96, 64, or 32MB RAM for the HD4000 in the bios.\n"
313 "The selected %dMB RAM configuration is not supported for the HD4000.\n", ram);
314pause();
315return false;// Exit early before the AAPL,ig-platform-id property is set.
316break;
317}
318
319devprop_add_value(device, "built-in", &BuiltIn, 1);
320devprop_add_value(device, "class-code", ClassFix, 4);
321devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10);
322devprop_add_value(device, "AAPL,ig-platform-id", (uint8_t*)&ig_platform_id, 4);
323}
324
325stringdata = malloc(sizeof(uint8_t) * string->length);
326if (!stringdata)
327{
328printf("No stringdata.\n");
329pause();
330return false;
331}
332
333memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
334stringlength = string->length;
335
336return true;
337}
338

Archive Download this file

Attachment to issue 312

Created: 6 years 7 months ago by Niresh12495