Chameleon

Chameleon Commit Details

Date:2012-07-18 16:50:34 (11 years 9 months ago)
Author:armel cadet-petit
Commit:2018
Parents: 2017
Message:Ported the nvidia plist helper
Changes:
A/trunk/i386/libsaio/nvidia_helper.c
A/trunk/i386/libsaio/nvidia_helper.h
A/trunk/doc/org.chameleon.Boot.nvidia.plist
M/trunk/Chameleon.xcodeproj/project.pbxproj
M/trunk/i386/libsaio/nvidia.c
M/trunk/CHANGES
M/trunk/i386/libsaio/Makefile

File differences

trunk/Chameleon.xcodeproj/project.pbxproj
11191119
11201120
11211121
1122
1123
1124
11221125
11231126
11241127
......
32533256
32543257
32553258
3259
3260
32563261
32573262
32583263
......
34793484
34803485
34813486
3487
34823488
34833489
34843490
AB1DE71815B6E2D00088E06B /* Cconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cconfig; sourceTree = "<group>"; };
AB1DE71A15B6E2D00088E06B /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
AB1DE71B15B6E2D00088E06B /* Sata.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Sata.c; sourceTree = "<group>"; };
AB47D38A15B702F00083D898 /* org.chameleon.Boot.nvidia.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = org.chameleon.Boot.nvidia.plist; sourceTree = "<group>"; };
ABE4A59C15B6EA73007812A6 /* nvidia_helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nvidia_helper.h; sourceTree = "<group>"; };
ABE4A59D15B6EA73007812A6 /* nvidia_helper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nvidia_helper.c; sourceTree = "<group>"; };
B0056CE711F3868000754B65 /* boot0.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = boot0.s; sourceTree = "<group>"; };
B0056CE811F3868000754B65 /* chain0.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = chain0.s; sourceTree = "<group>"; };
B0056CE911F3868000754B65 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
B0056D5811F3868000754B65 /* ntfs_private.h */,
B0056D5911F3868000754B65 /* nvidia.c */,
B0056D5A11F3868000754B65 /* nvidia.h */,
ABE4A59C15B6EA73007812A6 /* nvidia_helper.h */,
ABE4A59D15B6EA73007812A6 /* nvidia_helper.c */,
B0056D5B11F3868000754B65 /* pci.c */,
B0056D5C11F3868000754B65 /* pci.h */,
B0056D5D11F3868000754B65 /* pci_root.c */,
children = (
B0056E0711F3868000754B65 /* archive */,
B0056E0B11F3868000754B65 /* BootHelp.txt */,
AB47D38A15B702F00083D898 /* org.chameleon.Boot.nvidia.plist */,
B0056E0C11F3868000754B65 /* README */,
B0056E0D11F3868000754B65 /* themeinfo.png */,
B0056E0E11F3868000754B65 /* User_Guide_src */,
trunk/i386/libsaio/Makefile
3838
3939
4040
41
41
4242
4343
4444
smbios.o smbios_getters.o smbios_decode.o \
fake_efi.o ext2fs.o \
hpet.o dram_controllers.o spd.o usb.o pci_setup.o \
device_inject.o nvidia.o ati.o gma.o pci_root.o \
device_inject.o nvidia_helper.o nvidia.o ati.o gma.o pci_root.o \
convert.o aml_generator.o console.o exfat.o
SAIO_OBJS := $(addprefix $(OBJROOT)/, $(SAIO_OBJS))
trunk/i386/libsaio/nvidia.c
5353
5454
5555
56
5657
5758
5859
......
25172518
25182519
25192520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
25202532
25212533
25222534
......
26232635
26242636
26252637
2626
2638
26272639
26282640
26292641
2630
2642
2643
2644
26312645
2632
2633
2646
2647
2648
2649
2650
2651
26342652
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
26462653
2647
2654
2655
26482656
26492657
26502658
26512659
26522660
2653
2654
2655
2661
2662
2663
26562664
26572665
26582666
......
26692677
26702678
26712679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
26722700
26732701
26742702
......
26982726
26992727
27002728
2729
2730
27012731
27022732
27032733
......
27052735
27062736
27072737
2708
2709
27102738
27112739
2712
2713
2714
2715
2716
2740
2741
27172742
27182743
27192744
......
27992824
28002825
28012826
2827
2828
2829
2830
28022831
28032832
28042833
28052834
28062835
28072836
2837
2838
2839
2840
2841
2842
28082843
28092844
28102845
#include "platform.h"
#include "device_inject.h"
#include "nvidia.h"
#include "nvidia_helper.h"
#ifndef DEBUG_NVIDIA
#define DEBUG_NVIDIA 0
static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id)
{
int i;
// First check in the plist, (for e.g this can override any hardcoded devices)
cardList_t * nvcard = FindCardWithIds(device_id, subsys_id);
if (nvcard)
{
if (nvcard->model)
{
return nvcard->model;
}
}
for (i = 1; i < (sizeof(nvidia_cards) / sizeof(nvidia_cards[0])); i++) // size of nvidia_cards array for-loop
{
if ((nvidia_cards[i].device == device_id) && (nvidia_cards[i].subdev == subsys_id))
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 device_id, uint32_t subsys_id)
{
unsigned long long vram_size = 0;
if (nvCardType < NV_ARCH_50)
// First check if any value exist in the plist
cardList_t * nvcard = FindCardWithIds(device_id, subsys_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 9600M GT, GT 210/420/430/440/525M/540M & GTX 560M
// Then, Workaround for 9600M GT, GT 210/420/430/440/525M/540M & GTX 560M
switch (nvda_dev->device_id)
{
case 0x0647: // 9600M GT 0647
vram_size = 512*1024*1024;
break;
/*case 0x0649:// 9600M GT 0649
vram_size = 1024*1024*1024;
break;*/
/*case 0x0649:// 9600M GT 0649
vram_size = 1024*1024*1024;
break;*/
case 0x0A65: // GT 210
case 0x0DE0: // GT 440
case 0x0DE1: // GT 430
break;
}
if (!vram_size)
{ // Finally, if vram_size still not set do the calculation with our own method
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;
}
const char*value;
booldoit;
fill_card_list();
devicepath = get_pci_dev_path(nvda_dev);
bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 );
regs = (uint8_t *) (bar[0] & ~0x0f);
// get card type
nvCardType = (REG32(0) >> 20) & 0x1ff;
// 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),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id));
verbose("%s %dMB NV%02x [%04x:%04x]-[%04x:%04x] :: %s device number: %d\n",
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id,
devicepath, devices_number);
// Amount of VRAM in kilobytes
videoRam = mem_detect(regs, nvCardType, nvda_dev,((nvda_dev->vendor_id << 16) | nvda_dev->device_id),((nvda_dev->subsys_id.subsys.vendor_id << 16) | nvda_dev->subsys_id.subsys.device_id) );
rom = malloc(NVIDIA_ROM_SIZE);
sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id,
{
// Get Model from the OpROM
model = get_nvidia_model(((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), NV_SUB_IDS);
// Get VRAM again
videoRam = mem_detect(regs, nvCardType, nvda_dev,((rom_pci_header->vendor_id << 16) | rom_pci_header->device_id), NV_SUB_IDS );
}
else
{
printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature);
}
}
verbose("%s %dMB NV%02x [%04x:%04x]-[%04x:%04x] :: %s device number: %d\n",
model, (uint32_t)(videoRam / 1024 / 1024),
(REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id,
nvda_dev->subsys_id.subsys.vendor_id, nvda_dev->subsys_id.subsys.device_id,
devicepath, devices_number);
if (!string) {
string = devprop_create_string();
trunk/i386/libsaio/nvidia_helper.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright (c) 2012 cparm <armelcadetpetit@gmail.com>. All rights reserved.
*
*/
#include "libsaio.h"
#include "bootstruct.h"
#include "xml.h"
#include "nvidia_helper.h"
#include "pci.h"
#include "nvidia.h"
/*
NVIDIA card injection usage e.g (to be placed in the boot.plist):
<key>NVIDIA</key>
<array>
<dict>
<key>Chipset Name</key>
<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>IOPCISubDevId</key>
<string>YOUR_CARD_SUB_ID(if necessary)</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>IOPCISubDevId</key>
<string>YOUR_SECOND_CARD_SUB_ID(if necessary)</string>
<key>VRam Size</key>
<string>YOUR_SECOND_CARD_VRAM_SIZE</string>
</dict>
.
.
.
.
</array>
*/
cardList_t* cardList = NULL;
void add_card(char* model, uint32_t id, uint32_t subid, 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->subid = subid;
new_card->videoRam = videoRam;
new_card->model = model;
}
}
cardList_t* FindCardWithIds(uint32_t id, uint32_t subid)
{
cardList_t* entry = cardList;
while(entry)
{
if((entry->id == id) && (entry->subid == subid))
{
return entry;
}
else
{
entry = entry->next;
}
}
// LET A SECOND CHANCE by seaching only for the device-id
entry = cardList;
while(entry)
{
if((entry->id == id))
{
return entry;
}
else
{
entry = entry->next;
}
}
return NULL;
}
void fill_card_list(void)
{
unsigned inti, count;
TagPtr NVDIATag;
char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL;
uint32_t dev_id = 0, subdev_id = NV_SUB_IDS;
uint64_t VramSize = 0;
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (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")); //device-id
sub_id = XMLCastString(XMLGetProperty(element, (const char*)"IOPCISubDevId")); //sub device-id
model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));
vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size"));
if (match_id) {
dev_id = strtoul(match_id, NULL, 16);
}
if (sub_id) {
subdev_id = strtoul(sub_id, NULL, 16);
}
if (vram_size) {
VramSize = strtoul(vram_size, NULL, 10);
}
add_card(model_name, dev_id, subdev_id, VramSize);
}
}
}
}
trunk/i386/libsaio/nvidia_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* Copyright (c) 2012 cparm <armelcadetpetit@gmail.com>. All rights reserved.
*
*/
#ifndef __LIBSAIO_NVIDIA_HELPER_H
#define __LIBSAIO_NVIDIA_HELPER_H
typedef struct cardList_t
{
char* model;
uint32_t id;
uint32_t subid;
uint64_t videoRam;
struct cardList_t* next;
} cardList_t;
void add_card(char* model, uint32_t id, uint32_t subid, uint64_t videoRam);
void fill_card_list(void);
cardList_t* FindCardWithIds(uint32_t id, uint32_t subid);
#endif //__LIBSAIO_NVIDIA_HELPER_H
trunk/doc/org.chameleon.Boot.nvidia.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
<?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>Default Partition</key>
<string></string>
<key>GraphicsEnabler</key>
<string>Yes</string>
<key>Kernel</key>
<string>mach_kernel</string>
<key>Kernel Flags</key>
<string></string>
<key>NVIDIA</key>
<array>
<dict>
<key>Chipset Name</key>
<string>Quadro FX 380</string>
<key>IOPCIPrimaryMatch</key>
<string>0x10DE0658</string>
<key>IOPCISubDevId</key>
<string>0x00000000</string>
<key>VRam Size</key>
<string>256</string>
</dict>
</array>
<key>Quiet Boot</key>
<string>No</string>
<key>Timeout</key>
<string>5</string>
</dict>
</plist>
trunk/CHANGES
1
12
23
34
- cparm : Ported the nvidia plist helper (less time to spend on the device id more time to code :-) )
- cparm : Added a Sata module, known as YellowIconFixer in my branch, useful to fix yellow icon issue (can also fix an issue with the apple's dvd player application in moutain lion)
, for now not added in the pkg script !!!

Archive Download the corresponding diff file

Revision: 2018