Chameleon

Chameleon Commit Details

Date:2012-07-17 16:34:20 (6 years 11 months ago)
Author:armel cadet-petit
Commit:2016
Parents: 2015
Message:added memory info to the nvidia plist stucture
Changes:
A/branches/cparm/doc/com.apple.Boot.example.plist
M/branches/cparm/i386/libsaio/pci.h
M/branches/cparm/xcode3_sym.zip
M/branches/cparm/doc/ModuleHelp.txt
M/branches/cparm/i386/modules/ACPICodec/acpi_codec.c
M/branches/cparm/i386/modules/GraphicsEnabler/nvidia.c
M/branches/cparm/i386/modules/ACPICodec/ACPICodec.c
M/branches/cparm/i386/libsaio/device_inject.c
M/branches/cparm/i386/libsaio/pci.c
M/branches/cparm/CHANGES
M/branches/cparm/i386/libsaio/Makefile
M/branches/cparm/i386/libsaio/saio_internal.h
M/branches/cparm/i386/modules/ACPIPatcher/AcpiPatcher.c

File differences

branches/cparm/doc/com.apple.Boot.example.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ACPIDropTables</key>
<dict>
<key>SSDT</key>
<string></string>
<key>TAMG</key>
<string></string>
</dict>
<key>Default Partition</key>
<string>Snow Leopard</string>
<key>DropSSDT</key>
<string>Yes</string>
<key>EHCIhard</key>
<string>No</string>
<key>EnableC4State</key>
<string>Yes</string>
<key>EnableSpeedStep</key>
<string>Yes</string>
<key>GenerateCStates</key>
<string>No</string>
<key>GeneratePStates</key>
<string>No</string>
<key>GraphicsEnabler</key>
<string>Yes</string>
<key>Kernel</key>
<string>mach_kernel</string>
<key>Kernel Flags</key>
<string></string>
<key>Kernel Flags debug</key>
<string>-v acpi_debug=0xfffffff io=0xfffffffe trace=4096 keepsyms=1</string>
<key>KeyboardType</key>
<string>AZERTY</string>
<key>Legacy Logo</key>
<string>Yes</string>
<key>NVIDIA</key>
<array>
<dict>
<key>Chipset Name</key>
<string>Lenovo Quadro FX 380</string>
<key>IOPCIPrimaryMatch</key>
<string>0x10DE0658</string>
<key>VRam Size</key>
<string>256</string>
</dict>
</array>
<key>Quiet Boot</key>
<string>No</string>
<key>RandomTheme</key>
<string>Yes</string>
<key>ResetType</key>
<string>0</string>
<key>TDP</key>
<string>80</string>
<key>Theme</key>
<string>graphite</string>
<key>Timeout</key>
<string>5</string>
<key>UpdateACPI</key>
<string>Yes</string>
<key>quickSSDTsearch</key>
<string>Yes</string>
</dict>
</plist>
branches/cparm/doc/ModuleHelp.txt
1717
1818
1919
20
20
2121
2222
2323
......
2626
2727
2828
29
30
2931
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
3048
3149
3250
VBIOS=Yes|No Inject VBIOS to device-properties.
NVIDIA card injection usage e.g: // TODO : add memory info for each card to this structure
NVIDIA card injection usage e.g: see doc/com.apple.Boot.example.plist for an example
<key>NVIDIA</key>
<array>
<string>Quadro FX 380</string>
<key>IOPCIPrimaryMatch</key>
<string>0x10DE0658</string>
<key>VRam Size</key>
<string>256</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_CARD_ID</string>
<key>VRam Size</key>
<string>YOUR_CARD_VRAM_SIZE</string>
</dict>
<dict>
<key>Chipset Name</key>
<string>YOUR_SECOND_CARD_NAME</string>
<key>IOPCIPrimaryMatch</key>
<string>YOUR_SECOND_CARD_ID</string>
<key>VRam Size</key>
<string>YOUR_SECOND_CARD_VRAM_SIZE</string>
</dict>
.
.
.
branches/cparm/CHANGES
1
12
23
34
- Added memory info to the nvidia plist structure, so now one can add several cards to the plist and set a customized name and memory info for each cards
- Implemented a method to inject new graphics cards from a plist, no need to hardcode device ids anymore !! (for now, only nvidia cards are supported, see doc/ModuleHelp.txt for usage)
- Moved the smbios detection code to the freebsd one
branches/cparm/i386/libsaio/Makefile
3636
3737
3838
39
39
4040
4141
4242
xml.o md5.o device_tree.o modules.o \
cpu.o platform.o \
fake_efi.o \
device_inject.o pci_root.o \
device_inject.o \
convert.o acpi_tools.o smbios.o uterror.o lzss.o lib.o rtc.o time.o
# Options enabled by default:
branches/cparm/i386/libsaio/device_inject.c
88
99
1010
11
1211
1312
1413
......
3231
3332
3433
35
3634
3735
3836
......
4240
4341
4442
45
43
4644
4745
4846
......
5048
5149
5250
53
51
52
53
54
5455
5556
5657
57
58
5859
5960
6061
#include "libsaio.h"
#include "bootstruct.h"
#include "pci.h"
#include "pci_root.h"
#include "device_inject.h"
#include "convert.h"
#include "platform.h"
*len = string->length;
return devprop_generate_string(string);
}
verbose("efi_inject_get_devprop_string NULL trying stringdata\n");
return NULL;
}
uint8_t *binStr;
uint8_t *kbinStr;
int cnt, cnt2;
int cnt = 0, cnt2 = 0;
static char DEVICE_PROPERTIES_PROP[] = "device-properties";
*/
uint32_t strlength;
char *string = efi_inject_get_devprop_string(&strlength);
if (string == NULL) {
verbose("efi_inject_get_devprop_string NULL trying stringdata\n");
return;
}
/* Use the static "device-properties" boot config key contents if available,
* otheriwse use the generated one.
*/
if (!getValueForKey(kDeviceProperties, &val, &cnt, DEFAULT_BOOT_CONFIG) && string)
if (!getValueForKey(kDeviceProperties, &val, &cnt, DEFAULT_BOOT_CONFIG))
{
val = (const char*)string;
cnt = strlength * 2;
branches/cparm/i386/libsaio/pci.c
77
88
99
10
1110
1211
1312
......
232231
233232
234233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "libsaio.h"
#include "bootstruct.h"
#include "pci.h"
#include "pci_root.h"
#include "modules.h"
#include "device_inject.h"
}
}
#endif
static int rootuid = 10; //value means function wasnt ran yet
/*
* getPciRootUID: Copyright 2009 netkas
*/
int getPciRootUID(void)
{
const char *val;
int len;
if (rootuid < 10) return rootuid;
rootuid = 0;/* default uid = 0 */
if (getValueForKey(kPCIRootUID, &val, &len, DEFAULT_BOOT_CONFIG))
{
if (isdigit(val[0])) rootuid = val[0] - '0';
if ( (rootuid >= 0) && (rootuid < 10) )
goto out;
else
rootuid = 0;
}
/* PCEFI compatibility */
if (getValueForKey("-pci0", &val, &len, DEFAULT_BOOT_CONFIG))
{
rootuid = 0;
}
else if (getValueForKey("-pci1", &val, &len, DEFAULT_BOOT_CONFIG))
{
rootuid = 1;
}
out:
verbose("Using PCI-Root-UID value: %d\n", rootuid);
return rootuid;
}
branches/cparm/i386/libsaio/pci.h
6464
6565
6666
67
68
6769
6870
6971
extern voidbuild_pci_dt(void);
extern voiddump_pci_dt(pci_dt_t *);
extern voidsetup_pci_devs(pci_dt_t *pci_dt);
extern int getPciRootUID(void);
//-----------------------------------------------------------------------------
// added by iNDi
branches/cparm/i386/libsaio/saio_internal.h
183183
184184
185185
186
187
186188
187189
188190
extern BVRef nbpScanBootVolumes(int biosdev, int *count);
#endif
/* platform.c */
extern void scan_platform(void);
extern void SetgRootDevice(const char * str);
branches/cparm/i386/modules/ACPIPatcher/AcpiPatcher.c
1111
1212
1313
14
1514
1615
1716
#include "libsaio.h"
#include "modules.h"
#include "bootstruct.h"
#include "pci_root.h"
#include "acpi_patcher.h"
void AcpiPatcher_start(void);
branches/cparm/i386/modules/GraphicsEnabler/nvidia.c
921921
922922
923923
924
924
925925
926926
927927
......
959959
960960
961961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
9621006
9631007
9641008
......
11401184
11411185
11421186
1143
1187
1188
11441189
11451190
1146
1147
1148
1191
1192
11491193
11501194
11511195
1152
1196
11531197
11541198
11551199
11561200
11571201
11581202
1159
1160
1161
1162
1163
1164
1165
1166
1167
1203
1204
1205
11681206
11691207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
11701222
11711223
11721224
......
12591311
12601312
12611313
1262
1314
12631315
12641316
12651317
1266
1318
1319
12671320
1268
1269
1321
1322
1323
1324
1325
1326
12701327
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
12821328
12831329
12841330
......
12941340
12951341
12961342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
12971362
12981363
12991364
......
13271392
13281393
13291394
1395
1396
13301397
13311398
13321399
......
13431410
13441411
13451412
1346
1347
1413
1414
1415
1416
13481417
13491418
1350
1351
1352
1353
1354
1355
1356
1357
1419
1420
13581421
13591422
13601423
......
14291492
14301493
14311494
1495
1496
1497
1498
1499
14321500
14331501
14341502
......
14361504
14371505
14381506
1439
1507
1508
1509
14401510
14411511
14421512
static uint32_t load_nvidia_bios_file(const char *filename, uint8_t *buf, int bufsize);
static int devprop_add_nvidia_template(struct DevPropDevice *device);
static int hex2bin(const char *hex, uint8_t *bin, int len);
static unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev);
static unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev, uint32_t id);
static uint16_t swap16(uint16_t x)
}
#endif
typedef struct cardList_t
{
char* model;
uint32_t id;
uint64_t videoRam;
struct cardList_t* next;
} cardList_t;
cardList_t* cardList = NULL;
static void add_card(char* model, uint32_t id, uint64_t videoRam)
{
cardList_t* new_card = malloc(sizeof(cardList_t));
if (new_card)
{
new_card->next = cardList;
cardList = new_card;
new_card->id = id;
new_card->videoRam = videoRam;
new_card->model = model;
}
}
static cardList_t* FindCardWithId(uint32_t id)
{
cardList_t* entry = cardList;
while(entry)
{
if(entry->id == id)
{
return entry;
}
else
{
entry = entry->next;
}
}
return NULL;
}
static int patch_nvidia_rom(uint8_t *rom)
{
if (!rom || (rom[0] != 0x55 && rom[1] != 0xaa)) {
return (has_lvds ? PATCH_ROM_SUCCESS_HAS_LVDS : PATCH_ROM_SUCCESS);
}
static char *get_nvidia_model(uint32_t id) {
static void fill_card_list(void)
{
unsigned inti, count;
TagPtr NVDIATag;
char *model_name = NULL, *match_id = NULL;
// First check in the plist, (for e.g this can override any hardcoded devices)
char *model_name = NULL, *match_id = NULL, *vram_size = NULL;
if ((NVDIATag = XMLCastArray(XMLGetProperty(DEFAULT_BOOT_CONFIG_DICT, (const char*)"NVIDIA"))))
{
count = XMLTagCount(NVDIATag);
for (i=0; i<count; i++)
{
TagPtr element = XMLGetElement( NVDIATag, i );
if (element)
{
match_id = XMLCastString(XMLGetProperty(element, (const char*)"IOPCIPrimaryMatch"));
if (strtoul(match_id, NULL, 16) == id)
{
model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));
if (model_name)
{
return model_name;
}
}
model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));
vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size"));
add_card(model_name,strtoul(match_id, NULL, 16),strtoul(vram_size, NULL, 10));
}
}
}
}
static char *get_nvidia_model(uint32_t id) {
unsigned inti;
// First check in the plist, (for e.g this can override any hardcoded devices)
cardList_t * nvcard = FindCardWithId(id);
if (nvcard)
{
if (nvcard->model)
{
return nvcard->model;
}
}
for (i=1; i< (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) {
return 0;
}
unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev)
unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt_t *nvda_dev, uint32_t id)
{
unsigned long long vram_size = 0;
if (nvCardType < NV_ARCH_50)
cardList_t * nvcard = FindCardWithId(id);
if (nvcard)
{
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
if (nvcard->videoRam > 0)
{
vram_size = nvcard->videoRam * 1024 * 1024;
return vram_size;
}
}
else if (nvCardType < NV_ARCH_C0)
{
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
else // >= NV_ARCH_C0
{
vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
// Workaround for GT 420/430 & 9600M GT
switch (nvda_dev->device_id)
break;
}
if (!vram_size) {
if (nvCardType < NV_ARCH_50)
{
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size &= NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK;
}
else if (nvCardType < NV_ARCH_C0)
{
vram_size = REG32(NV04_PFB_FIFO_DATA);
vram_size |= (vram_size & 0xff) << 32;
vram_size &= 0xffffffff00ll;
}
else // >= NV_ARCH_C0
{
vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
}
}
return vram_size;
}
struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString);
fill_card_list();
static const dcfg_t default_dcfg [] = {
{0xff,0xff,0xff,0xff},
};
delay(50);
// get card type
nvCardType = (REG32(0) >> 20) & 0x1ff;
nvCardType = (REG32(0) >> 20) & 0x1ff;
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev);
model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id);
verbose("nVidia %s %dMB NV%02x [%04x:%04x]\n",
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id);
videoRam = mem_detect(regs, nvCardType, nvda_dev, (nvda_dev->vendor_id << 16) | nvda_dev->device_id);
rom = malloc(NVIDIA_ROM_SIZE);
if (!rom) {
printf("Couldn't allocate momory for device rom\n");
if (rom_pci_header->device != nvda_dev->device_id) {
// Get Model from the OpROM
model = get_nvidia_model((rom_pci_header->vendor << 16) | rom_pci_header->device);
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev, (rom_pci_header->vendor << 16) | rom_pci_header->device);
} else {
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
// ??
//return false;
}
}
DBG("nvidia model : %s\n",model);
verbose("nVidia %s %dMB NV%02x [%04x:%04x]\n",
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id);
if (!string)
{
branches/cparm/i386/modules/ACPICodec/acpi_codec.c
4646
4747
4848
49
5049
5150
5251
52
5353
5454
5555
#include "platform.h"
#include "cpu.h"
#include "xml.h"
#include "pci_root.h"
#include "sl.h"
#include "convert.h"
#include "modules.h"
#include "pci.h"
U64 rsd_p;
ACPI_TABLES acpi_tables;
branches/cparm/i386/modules/ACPICodec/ACPICodec.c
66
77
88
9
109
1110
1211
#include "libsaio.h"
#include "modules.h"
#include "bootstruct.h"
#include "pci_root.h"
#include "acpi_codec.h"
void ACPICodec_start(void);

Archive Download the corresponding diff file

Revision: 2016