␊ |
char *efi_inject_get_devprop_string(uint32_t *len)␊ |
{␊ |
␉if(string) {␊ |
␉if(string)␊ |
␉{␊ |
␉␉*len = string->length;␊ |
␉␉return devprop_generate_string(string);␊ |
␉}␊ |
|
␊ |
void setupDeviceProperties(Node *node)␊ |
{␊ |
const char *val;␊ |
uint8_t *binStr;␊ |
int cnt, cnt2;␊ |
␊ |
static char DEVICE_PROPERTIES_PROP[] = "device-properties";␊ |
␊ |
/* Generate devprop string.␊ |
*/␊ |
uint32_t strlength;␊ |
char *string = efi_inject_get_devprop_string(&strlength);␊ |
␊ |
/* Use the static "device-properties" boot config key contents if available,␊ |
* otheriwse use the generated one.␊ |
*/ ␊ |
if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string)␊ |
{␊ |
val = (const char*)string;␊ |
cnt = strlength * 2;␊ |
} ␊ |
␉const char *val;␊ |
␉uint8_t *binStr;␊ |
␉int cnt, cnt2;␊ |
␉␊ |
␉static char DEVICE_PROPERTIES_PROP[] = "device-properties";␊ |
␉␊ |
␉/* Generate devprop string.␊ |
␉ */␊ |
␉uint32_t strlength;␊ |
␉char *string = efi_inject_get_devprop_string(&strlength);␊ |
␉␊ |
␉/* Use the static "device-properties" boot config key contents if available,␊ |
␉ * otheriwse use the generated one.␊ |
␉ */ ␊ |
␉if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string)␊ |
␉{␊ |
␉␉val = (const char*)string;␊ |
␉␉cnt = strlength * 2;␊ |
␉} ␊ |
␊ |
if (cnt > 1)␊ |
{␊ |
binStr = convertHexStr2Binary(val, &cnt2);␊ |
if (cnt2 > 0) DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, binStr);␊ |
}␊ |
␉if (cnt > 1)␊ |
␉{␊ |
␉␉binStr = convertHexStr2Binary(val, &cnt2);␊ |
␉␉if (cnt2 > 0) DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, binStr);␊ |
␉}␊ |
}␊ |
␊ |
struct DevPropString *devprop_create_string(void)␊ |
|
␉string = (struct DevPropString*)malloc(sizeof(struct DevPropString));␊ |
␉␊ |
␉if(string == NULL)␊ |
␉{␊ |
␉␉return NULL;␊ |
␉}␊ |
␉␊ |
␉memset(string, 0, sizeof(struct DevPropString));␊ |
␉string->length = 12;␊ |
␉string->WHAT2 = 0x01000000;␊ |
␉return string;␊ |
}␊ |
␊ |
␊ |
struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path)␊ |
{␊ |
␉struct DevPropDevice␉*device;␊ |
␉const char␉␉pciroot_string[] = "PciRoot(0x";␊ |
␉const char␉␉pci_device_string[] = "Pci(0x";␊ |
␊ |
␉␊ |
␉if (string == NULL || path == NULL) {␊ |
␉␉return NULL;␊ |
␉}␊ |
␉device = malloc(sizeof(struct DevPropDevice));␊ |
␊ |
␉␊ |
␉if (strncmp(path, pciroot_string, strlen(pciroot_string))) {␊ |
␉␉printf("ERROR parsing device path\n");␊ |
␉␉return NULL;␊ |
␉}␊ |
␊ |
␉␊ |
␉memset(device, 0, sizeof(struct DevPropDevice));␊ |
␉device->acpi_dev_path._UID = getPciRootUID();␊ |
␊ |
␉␊ |
␉int numpaths = 0;␊ |
␉int␉␉x, curr = 0;␊ |
␉char␉buff[] = "00";␊ |
␊ |
␉for (x = 0; x < strlen(path); x++) {␊ |
␉␉if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) {␊ |
␉␊ |
␉for (x = 0; x < strlen(path); x++) ␊ |
␉{␊ |
␉␉if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string)))␊ |
␉␉{␊ |
␉␉␉x+=strlen(pci_device_string);␊ |
␉␉␉curr=x;␊ |
␉␉␉while(path[++x] != ',');␊ |
␉␉␉if(x-curr == 2)␊ |
␉␉␉{␊ |
␉␉␉␉sprintf(buff, "%c%c", path[curr], path[curr+1]);␊ |
␉␉␉}␊ |
␉␉␉else if(x-curr == 1)␊ |
␉␉␉{␊ |
␉␉␉␉sprintf(buff, "%c", path[curr]);␊ |
␉␉␉}␊ |
␉␉␉else ␊ |
␉␉␉{␊ |
␉␉␉␉printf("ERROR parsing device path\n");␊ |
|
␉␉␉curr = x;␊ |
␉␉␉while(path[++x] != ')');␊ |
␉␉␉if(x-curr == 2)␊ |
␉␉␉{␊ |
␉␉␉␉sprintf(buff, "%c%c", path[curr], path[curr+1]);␊ |
␉␉␉}␊ |
␉␉␉else if(x-curr == 1)␊ |
␉␉␉{␊ |
␉␉␉␉sprintf(buff, "%c", path[curr]);␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉␉printf("ERROR parsing device path\n");␊ |
|
␉}␊ |
␉␊ |
␉if(!numpaths)␊ |
␉{␊ |
␉␉return NULL;␊ |
␉}␊ |
␉␊ |
␉device->numentries = 0x00;␊ |
␉␊ |
|
␉string->length += device->length;␊ |
␉␊ |
␉if(!string->entries)␊ |
␉{␊ |
␉␉if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)))== NULL)␊ |
␉␉{␊ |
␉␉␉return 0;␊ |
␉␉}␊ |
␉}␊ |
␉␊ |
␉string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));␊ |
␉string->entries[string->numentries-1] = device;␊ |
|
{␊ |
␉␊ |
␉if(!nm || !vl || !len)␊ |
␉{␊ |
␉␉return 0;␊ |
␉}␊ |
␉␊ |
␉uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2);␊ |
␉uint8_t *data = (uint8_t*)malloc(length);␊ |
␉{␊ |
␉␉if(!data)␊ |
␉␉{␊ |
␉␉␉return 0;␊ |
␉␉}␊ |
␉␉␊ |
␉␉memset(data, 0, length);␊ |
␉␉uint32_t off= 0;␊ |
|
␉␊ |
␉uint8_t *newdata = (uint8_t*)malloc((length + offset));␊ |
␉if(!newdata)␊ |
␉{␊ |
␉␉return 0;␊ |
␉}␊ |
␉if(device->data)␊ |
␉{␊ |
␉␉if(offset > 1)␊ |
␉␉{␊ |
␉␉␉memcpy(newdata, device->data, offset);␊ |
␊ |
␉␉}␊ |
␉}␊ |
␉␊ |
␉memcpy(newdata + offset, data, length);␊ |
␉␊ |
␉device->length += length;␊ |
|
␉device->numentries++;␊ |
␉␊ |
␉if(!device->data)␊ |
␉{␊ |
␉␉device->data = (uint8_t*)malloc(sizeof(uint8_t));␊ |
␉}␊ |
␉else␊ |
␉{␊ |
␉␉free(device->data);␊ |
␉}␊ |
␉␊ |
␉free(data);␊ |
␉device->data = newdata;␊ |
|
␉char *ptr = buffer;␊ |
␉␊ |
␉if(!buffer)␊ |
␉{␊ |
␉␉return NULL;␊ |
␊ |
␉}␊ |
␉␊ |
␉sprintf(buffer, "%08x%08x%04x%04x", dp_swap32(string->length), string->WHAT2,␊ |
␉␉␉dp_swap16(string->numentries), string->WHAT3);␊ |
␉buffer += 24;␊ |
|
␉␉␉␉dp_swap16(string->entries[i]->acpi_dev_path.length),␊ |
␉␉␉␉string->entries[i]->acpi_dev_path._HID,␊ |
␉␉␉␉dp_swap32(string->entries[i]->acpi_dev_path._UID));␊ |
␊ |
␉␉␊ |
␉␉buffer += 24;␊ |
␉␉for(x=0;x < string->entries[i]->num_pci_devpaths; x++)␊ |
␉␉{␊ |
|
void devprop_free_string(struct DevPropString *string)␊ |
{␊ |
␉if(!string)␊ |
␉{␊ |
␉␉return;␊ |
␉}␊ |
␉␊ |
␉int i;␊ |
␉for(i = 0; i < string->numentries; i++)␊ |