1 | #include "libsaio.h"␊ |
2 | #include "boot.h"␊ |
3 | #include "bootstruct.h"␊ |
4 | #include "pci.h"␊ |
5 | //#include "gma.h"␊ |
6 | //#include "nvidia.h"␊ |
7 | //#include "hda.h"␊ |
8 | #include "modules.h"␊ |
9 | //#include "device_inject.h"␊ |
10 | ␊ |
11 | extern bool setup_ati_devprop(pci_dt_t *ati_dev);␊ |
12 | extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev);␊ |
13 | extern bool setup_gma_devprop(pci_dt_t *gma_dev);␊ |
14 | extern bool setup_hda_devprop(pci_dt_t *hda_dev);␊ |
15 | extern void setup_eth_builtin(pci_dt_t *eth_dev);␊ |
16 | extern void setup_wifi_airport(pci_dt_t *wifi_dev);␊ |
17 | extern bool set_usb_devprop(pci_dt_t *usb_dev);␊ |
18 | extern void notify_usb_dev(pci_dt_t *pci_dev);␊ |
19 | extern void force_enable_hpet(pci_dt_t *lpc_dev);␊ |
20 | extern pci_dt_t *dram_controller_dev;␊ |
21 | ␊ |
22 | void setup_pci_devs(pci_dt_t *pci_dt)␊ |
23 | {␊ |
24 | ␉char *devicepath;␊ |
25 | ␉bool doit, do_eth_devprop, do_wifi_devprop, do_usb_devprop, do_gfx_devprop, do_enable_hpet, do_hda_devprop = false;␊ |
26 | ␉pci_dt_t *current = pci_dt;␊ |
27 | ␊ |
28 | ␉//do_eth_devprop = do_wifi_devprop = do_usb_devprop = do_gfx_devprop = do_enable_hpet = do_hda_devprop = false;␊ |
29 | ␊ |
30 | ␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->chameleonConfig);␊ |
31 | ␉getBoolForKey(kEnableWifi, &do_wifi_devprop, &bootInfo->chameleonConfig);␊ |
32 | ␉getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->chameleonConfig);␊ |
33 | ␉getBoolForKey(kUsbInject, &do_usb_devprop, &bootInfo->chameleonConfig);␊ |
34 | ␉getBoolForKey(kHDAEnabler, &do_hda_devprop, &bootInfo->chameleonConfig);␊ |
35 | ␉getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->chameleonConfig);␊ |
36 | ␊ |
37 | /* tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html␊ |
38 | ␉// Get some PCI stuff␊ |
39 | ␉if (hasPciToEfiMapping == -1) {␊ |
40 | ␉␉hasPciToEfiMapping = (loadSystemConfig("", &bootInfo->pciConfig, "pci.plist", true) == 0 ? 1 : 0);␊ |
41 | ␉␉if (hasPciToEfiMapping) {␊ |
42 | ␉␉␉verbose("pci.plist is found.\n");␊ |
43 | ␉␉}␊ |
44 | ␉}␊ |
45 | ␊ |
46 | ␉if (hasPciToEfiMapping) {␊ |
47 | ␉␉// Device ID override injection␊ |
48 | ␉␉memset(id_array, sizeof(id_array), 0);␊ |
49 | ␉␉sprintf(override_key, "pci%04x,%04x", current->vendor_id, current->device_id);␊ |
50 | ␉␉id_count = PciToEfiOverride(override_key, id_array, 4);␊ |
51 | ␉␉device = NULL;␊ |
52 | ␉␉for (i = 0; i < id_count; i++) {␊ |
53 | ␉␉␉uint8_t fourOctets[4];␊ |
54 | ␉␉␉uint32_t id = id_array[i];␊ |
55 | ␉␉␉if (id == 0) {␊ |
56 | ␉␉␉␉if (i == 0) {␊ |
57 | ␉␉␉␉␉id = current->vendor_id;␊ |
58 | ␉␉␉␉} else if (i == 1) {␊ |
59 | ␉␉␉␉␉id = current->device_id;␊ |
60 | ␉␉␉␉} else {␊ |
61 | ␉␉␉␉␉continue;␊ |
62 | ␉␉␉␉}␊ |
63 | ␉␉␉}␊ |
64 | ␊ |
65 | ␉␉␉fourOctets[0] = id;␊ |
66 | ␉␉␉fourOctets[1] = id >> 8;␊ |
67 | ␉␉␉fourOctets[2] = 0;␊ |
68 | ␉␉␉fourOctets[3] = 0;␊ |
69 | ␉␉␉if (id != 0) {␊ |
70 | ␉␉␉␉if (device == NULL) {␊ |
71 | ␉␉␉␉␉device = devprop_find_device(devicepath);␊ |
72 | ␉␉␉␉␉if (device == NULL) {␊ |
73 | ␉␉␉␉␉␉deviceString = devprop_create_string();␊ |
74 | ␉␉␉␉␉␉device = devprop_add_device(deviceString, devicepath);␊ |
75 | ␉␉␉␉␉}␊ |
76 | ␉␉␉␉}␊ |
77 | ␉␉␉␉devprop_add_value(device, id_keys[i], fourOctets, sizeof(fourOctets));␊ |
78 | ␉␉␉␉verbose("%s: %s 0x%02x\n", override_key, id_keys[i], id);␊ |
79 | ␉␉␉}␊ |
80 | ␉␉}␊ |
81 | ␉␉current = current->next;␊ |
82 | ␉}␊ |
83 | */ // tennisgeek http://forum.voodooprojects.org/index.php/topic,1333.0.html␊ |
84 | ␊ |
85 | ␉while (current) {␊ |
86 | ␉␉devicepath = get_pci_dev_path(current);␊ |
87 | ␊ |
88 | ␉␉switch (current->class_id) {␊ |
89 | ␉␉␉case PCI_CLASS_BRIDGE_HOST:␊ |
90 | ␉␉␉␉//DBG("Setup BRIDGE_HOST \n");␊ |
91 | ␉␉␉␉if (current->dev.addr == PCIADDR(0, 0, 0)) {␊ |
92 | ␉␉␉␉␉dram_controller_dev = current;␊ |
93 | ␉␉␉␉}␊ |
94 | ␉␉␉␉break;␊ |
95 | ␉␉␉␉␊ |
96 | ␉␉␉case PCI_CLASS_NETWORK_ETHERNET: ␊ |
97 | ␉␉␉␉//DBG("Setup ETHERNET %s enabled\n", do_eth_devprop?"":"no");␊ |
98 | ␉␉␉␉if (do_eth_devprop) {␊ |
99 | ␉␉␉␉␉setup_eth_builtin(current);␊ |
100 | ␉␉␉␉}␊ |
101 | ␉␉␉␉break;␊ |
102 | ␊ |
103 | ␉␉␉case PCI_CLASS_NETWORK_OTHER:␊ |
104 | ␉␉␉␉//DBG("Setup WIRELESS %s enabled\n", do_wifi_devprop?"":"no");␊ |
105 | ␉␉␉␉if (do_wifi_devprop) {␊ |
106 | ␉␉␉␉␉setup_wifi_airport(current);␊ |
107 | ␉␉␉␉}␊ |
108 | ␉␉␉␉break;␊ |
109 | ␊ |
110 | ␉␉␉case PCI_CLASS_DISPLAY_VGA:␊ |
111 | ␉␉␉␉//DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop?"":"no");␊ |
112 | ␉␉␉␉if (do_gfx_devprop) {␊ |
113 | ␉␉␉␉␉switch (current->vendor_id) {␊ |
114 | ␉␉␉␉␉␉case PCI_VENDOR_ID_ATI:␊ |
115 | ␉␉␉␉␉␉␉if (getBoolForKey(kSkipAtiGfx, &doit, &bootInfo->chameleonConfig) && doit) {␊ |
116 | ␉␉␉␉␉␉␉␉verbose("Skip ATi/AMD gfx device!\n");␊ |
117 | ␉␉␉␉␉␉␉} else {␊ |
118 | ␉␉␉␉␉␉␉␉setup_ati_devprop(current);␊ |
119 | ␉␉␉␉␉␉␉}␊ |
120 | ␉␉␉␉␉␉␉break;␊ |
121 | ␊ |
122 | ␉␉␉␉␉␉case PCI_VENDOR_ID_INTEL:␊ |
123 | ␉␉␉␉␉␉␉if (getBoolForKey(kSkipIntelGfx, &doit, &bootInfo->chameleonConfig) && doit) {␊ |
124 | ␉␉␉␉␉␉␉␉verbose("Skip Intel gfx device!\n");␊ |
125 | ␉␉␉␉␉␉␉} else {␊ |
126 | ␉␉␉␉␉␉␉␉setup_gma_devprop(current);␊ |
127 | ␉␉␉␉␉␉␉}␊ |
128 | ␉␉␉␉␉␉␉break;␊ |
129 | ␊ |
130 | ␉␉␉␉␉␉case PCI_VENDOR_ID_NVIDIA:␊ |
131 | ␉␉␉␉␉␉␉if (getBoolForKey(kSkipNvidiaGfx, &doit, &bootInfo->chameleonConfig) && doit) {␊ |
132 | ␉␉␉␉␉␉␉␉verbose("Skip Nvidia gfx device!\n");␊ |
133 | ␉␉␉␉␉␉␉} else {␊ |
134 | ␉␉␉␉␉␉␉␉setup_nvidia_devprop(current);␊ |
135 | ␉␉␉␉␉␉␉}␊ |
136 | ␉␉␉␉␉␉␉break;␊ |
137 | ␉␉␉␉␉␉}␊ |
138 | ␉␉␉␉␉}␊ |
139 | ␉␉␉␉␉break;␊ |
140 | ␊ |
141 | ␊ |
142 | ␉␉␉case PCI_CLASS_MULTIMEDIA_AUDIO_DEV:␊ |
143 | ␉␉␉␉//DBG("Setup HDEF %s enabled\n", do_hda_devprop?"":"no");␊ |
144 | ␉␉␉␉if (do_hda_devprop) {␊ |
145 | ␉␉␉␉␉setup_hda_devprop(current);␊ |
146 | ␉␉␉␉}␊ |
147 | ␉␉␉␉break;␊ |
148 | ␊ |
149 | ␉␉␉␉case PCI_CLASS_SERIAL_USB:␊ |
150 | ␉␉␉␉␉//DBG("USB fix \n");␊ |
151 | ␉␉␉␉␉notify_usb_dev(current);␊ |
152 | ␉␉␉ /*if (do_usb_devprop) {␊ |
153 | ␉␉␉␉ set_usb_devprop(current);␊ |
154 | ␉␉␉␉ }*/␊ |
155 | ␉␉␉␉␉break;␊ |
156 | ␊ |
157 | ␉␉␉␉case PCI_CLASS_BRIDGE_ISA:␊ |
158 | ␉␉␉␉␉//DBG("Force HPET %s enabled\n", do_enable_hpet?"":"no");␊ |
159 | ␉␉␉␉␉if (do_enable_hpet) {␊ |
160 | ␉␉␉␉␉␉force_enable_hpet(current);␊ |
161 | ␉␉␉␉␉}␊ |
162 | ␉␉␉␉␉break;␊ |
163 | ␉␉␉}␊ |
164 | ␉␉␊ |
165 | ␉␉execute_hook("PCIDevice", current, NULL, NULL, NULL);␊ |
166 | ␉␉//DBG("setup_pci_devs current devID=%08x\n", current->device_id);␊ |
167 | ␉␉setup_pci_devs(current->children);␊ |
168 | ␉␉current = current->next;␊ |
169 | ␉}␊ |
170 | }␊ |
171 | |