1 | /*␊ |
2 | * Copyright (c) 2012 cparm <armelcadetpetit@gmail.com>. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "bootstruct.h"␊ |
8 | #include "xml.h"␊ |
9 | #include "nvidia_helper.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "nvidia.h"␊ |
12 | ␊ |
13 | /*␊ |
14 | ␊ |
15 | NVIDIA card injection usage e.g (to be placed in the boot.plist): ␊ |
16 | ␊ |
17 | <key>NVIDIA</key>␊ |
18 | ␉<array>␊ |
19 | ␉␉<dict>␊ |
20 | ␉␉␉<key>Chipset Name</key>␊ |
21 | ␉␉␉<string>Quadro FX 380</string>␊ |
22 | ␉␉␉<key>IOPCIPrimaryMatch</key>␊ |
23 | ␉␉␉<string>0x10DE0658</string>␊ |
24 | ␉␉␉<key>VRam Size</key>␊ |
25 | ␉␉␉<string>256</string>␊ |
26 | ␉␉</dict>␊ |
27 | ␉␉<dict>␊ |
28 | ␉␉␉<key>Chipset Name</key>␊ |
29 | ␉␉␉<string>YOUR_CARD_NAME</string>␊ |
30 | ␉␉␉<key>IOPCIPrimaryMatch</key>␊ |
31 | ␉␉␉<string>YOUR_CARD_ID</string>␊ |
32 | ␉␉␉<key>IOPCISubDevId</key>␊ |
33 | ␉␉␉<string>YOUR_CARD_SUB_ID(if necessary)</string>␊ |
34 | ␉␉␉<key>VRam Size</key>␊ |
35 | ␉␉␉<string>YOUR_CARD_VRAM_SIZE</string>␊ |
36 | ␉␉</dict>␊ |
37 | ␉␉<dict>␊ |
38 | ␉␉␉<key>Chipset Name</key>␊ |
39 | ␉␉␉<string>YOUR_SECOND_CARD_NAME</string>␊ |
40 | ␉␉␉<key>IOPCIPrimaryMatch</key>␊ |
41 | ␉␉␉<string>YOUR_SECOND_CARD_ID</string>␊ |
42 | ␉␉␉<key>IOPCISubDevId</key>␊ |
43 | ␉␉␉<string>YOUR_SECOND_CARD_SUB_ID(if necessary)</string>␊ |
44 | ␉␉␉<key>VRam Size</key>␊ |
45 | ␉␉␉<string>YOUR_SECOND_CARD_VRAM_SIZE</string>␊ |
46 | ␉␉</dict>␊ |
47 | .␊ |
48 | .␊ |
49 | .␊ |
50 | .␊ |
51 | </array>␊ |
52 | ␊ |
53 | */␊ |
54 | ␊ |
55 | cardList_t* cardList = NULL;␊ |
56 | ␊ |
57 | void add_card(char* model, uint32_t id, uint32_t subid, uint64_t videoRam)␊ |
58 | {␊ |
59 | ␉␊ |
60 | ␉cardList_t* new_card = malloc(sizeof(cardList_t));␊ |
61 | ␉if (new_card)␊ |
62 | ␉{␉␊ |
63 | ␉␉new_card->next = cardList;␊ |
64 | ␉␉␊ |
65 | ␉␉cardList = new_card;␊ |
66 | ␉␉␊ |
67 | ␉␉new_card->id = id;␊ |
68 | ␉␉new_card->subid = subid;␊ |
69 | ␉␉new_card->videoRam = videoRam;␊ |
70 | ␉␉new_card->model = model;␊ |
71 | ␉}␉␊ |
72 | }␊ |
73 | ␊ |
74 | cardList_t* FindCardWithIds(uint32_t id, uint32_t subid)␊ |
75 | {␊ |
76 | ␉cardList_t* entry = cardList;␊ |
77 | ␉while(entry)␊ |
78 | ␉{␉␉␊ |
79 | ␉␉if((entry->id == id) && (entry->subid == subid))␊ |
80 | ␉␉{␊ |
81 | ␉␉␉return entry;␊ |
82 | ␉␉}␊ |
83 | ␉␉else␊ |
84 | ␉␉{␊ |
85 | ␉␉␉entry = entry->next;␊ |
86 | ␉␉} ␊ |
87 | ␉␉␊ |
88 | ␉}␊ |
89 | ␉␊ |
90 | ␉// LET A SECOND CHANCE by seaching only for the device-id␊ |
91 | ␉entry = cardList;␊ |
92 | ␉while(entry)␊ |
93 | ␉{␉␉␊ |
94 | ␉␉if(entry->id == id)␊ |
95 | ␉␉{␊ |
96 | ␉␉␉return entry;␊ |
97 | ␉␉}␊ |
98 | ␉␉else␊ |
99 | ␉␉{␊ |
100 | ␉␉␉entry = entry->next;␊ |
101 | ␉␉} ␊ |
102 | ␉␉␊ |
103 | ␉}␊ |
104 | ␉␊ |
105 | ␉return NULL;␊ |
106 | }␊ |
107 | ␊ |
108 | void fill_card_list(void) ␊ |
109 | {␊ |
110 | ␉unsigned int␉i, count;␊ |
111 | ␉TagPtr NVDIATag; ␊ |
112 | ␉char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL;␉␊ |
113 | ␉uint32_t dev_id = 0, subdev_id = 0;␊ |
114 | ␉uint64_t VramSize = 0;␉␊ |
115 | ␉␊ |
116 | ␉if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA"))))␊ |
117 | ␉{␊ |
118 | ␉␉count = XMLTagCount(NVDIATag);␊ |
119 | ␉␉␊ |
120 | ␉␉for (i=0; i<count; i++) ␊ |
121 | ␉␉{␊ |
122 | ␉␉␉TagPtr element = XMLGetElement( NVDIATag, i );␊ |
123 | ␉␉␉if (element) ␊ |
124 | ␉␉␉{␊ |
125 | ␉␉␉␉match_id = XMLCastString(XMLGetProperty(element, (const char*)"IOPCIPrimaryMatch")); //device-id␊ |
126 | ␉␉␉␉sub_id = XMLCastString(XMLGetProperty(element, (const char*)"IOPCISubDevId")); //sub device-id␊ |
127 | ␉␉␉␉model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));␊ |
128 | ␉␉␉␉vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size"));␊ |
129 | ␉␉␉␉␊ |
130 | ␉␉␉␉if (match_id) {␊ |
131 | ␉␉␉␉␉dev_id = strtoul(match_id, NULL, 16);␊ |
132 | ␉␉␉␉}␊ |
133 | ␉␉␉␉␊ |
134 | ␉␉␉␉if (sub_id) {␊ |
135 | ␉␉␉␉␉subdev_id = strtoul(sub_id, NULL, 16);␊ |
136 | ␉␉␉␉}␊ |
137 | ␉␉␉␉␊ |
138 | ␉␉␉␉if (vram_size) {␊ |
139 | ␉␉␉␉␉VramSize = strtoul(vram_size, NULL, 10);␊ |
140 | ␉␉␉␉}␊ |
141 | ␉␉␉␉␊ |
142 | ␉␉␉␉add_card(model_name, dev_id, subdev_id, VramSize);␉␉␉␉␉␉␉␉␊ |
143 | ␉␉␉}␊ |
144 | ␉␉}␉␊ |
145 | ␉}␉␊ |
146 | }␊ |
147 | |