Permalink
Browse files

Ported the nvidia plist helper

git-svn-id: http://forge.voodooprojects.org/svn/chameleon/trunk@2018 b5af796a-00a8-11df-919b-ffff7a100b7d
  • Loading branch information...
1 parent 44037a5 commit c9c7846cd6e4bb01a07293c6a98c9541a3ba9d39 cparm committed Jul 18, 2012
View
@@ -1,3 +1,4 @@
+- 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 !!!
@@ -1119,6 +1119,9 @@
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>"; };
@@ -3253,6 +3256,8 @@
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 */,
@@ -3479,6 +3484,7 @@
children = (
B0056E0711F3868000754B65 /* archive */,
B0056E0B11F3868000754B65 /* BootHelp.txt */,
+ AB47D38A15B702F00083D898 /* org.chameleon.Boot.nvidia.plist */,
B0056E0C11F3868000754B65 /* README */,
B0056E0D11F3868000754B65 /* themeinfo.png */,
B0056E0E11F3868000754B65 /* User_Guide_src */,
@@ -0,0 +1,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>
View
@@ -38,7 +38,7 @@ SAIO_OBJS = table.o asm.o bios.o biosfn.o \
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))
View
@@ -53,6 +53,7 @@
#include "platform.h"
#include "device_inject.h"
#include "nvidia.h"
+#include "nvidia_helper.h"
#ifndef DEBUG_NVIDIA
#define DEBUG_NVIDIA 0
@@ -2517,6 +2518,17 @@ static int patch_nvidia_rom(uint8_t *rom)
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))
@@ -2623,36 +2635,32 @@ int hex2bin(const char *hex, uint8_t *bin, int len)
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)
- {
- 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
+ // First check if any value exist in the plist
+ cardList_t * nvcard = FindCardWithIds(device_id, subsys_id);
+ if (nvcard)
{
- vram_size = REG32(NVC0_MEM_CTRLR_RAM_AMOUNT) << 20;
- vram_size *= REG32(NVC0_MEM_CTRLR_COUNT);
+ if (nvcard->videoRam > 0)
+ {
+ vram_size = nvcard->videoRam * 1024 * 1024;
+
+ return vram_size;
+ }
}
- // 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
@@ -2669,6 +2677,26 @@ unsigned long long mem_detect(volatile uint8_t *regs, uint8_t nvCardType, pci_dt
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;
}
@@ -2698,22 +2726,19 @@ bool setup_nvidia_devprop(pci_dt_t *nvda_dev)
const char *value;
bool doit;
+ 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,
@@ -2799,12 +2824,22 @@ bool setup_nvidia_devprop(pci_dt_t *nvda_dev)
{
// 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();
@@ -0,0 +1,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 int i, 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);
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit c9c7846

Please sign in to comment.