struct device *new_chip(struct device *parent, struct device *bus, char *path) { struct device *new_chip = new_dev(parent, bus); new_chip->chiph_exists = 1; new_chip->name = path; new_chip->name_underscore = translate_name(new_chip->name, UNSLASH); new_chip->type = chip; new_chip->chip = new_chip; struct stat st; char *chip_h = malloc(strlen(path)+18); sprintf(chip_h, "src/%s", path); if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) { if (strstr(path, "/root_complex")) { fprintf(stderr, "WARNING: Use of deprecated chip component %s\n", path); } else { fprintf(stderr, "ERROR: Chip component %s does not exist.\n", path); exit(1); } } if (scan_mode == STATIC_MODE) sprintf(chip_h, "src/%s/chip.h", path); else if (scan_mode == BOOTBLOCK_MODE) sprintf(chip_h, "src/%s/bootblock.c", path); if ((scan_mode == STATIC_MODE) || (scan_mode == BOOTBLOCK_MODE)) { if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) new_chip->chiph_exists = 0; } if (parent->latestchild) { parent->latestchild->next_sibling = new_chip; parent->latestchild->sibling = new_chip; } parent->latestchild = new_chip; if (!parent->children) parent->children = new_chip; free(chip_h); return new_chip; }
struct device *new_chip(struct device *parent, struct device *bus, char *path) { struct device *new_chip = new_dev(parent, bus); new_chip->chiph_exists = 1; new_chip->name = path; new_chip->name_underscore = translate_name(new_chip->name, UNSLASH); new_chip->type = chip; new_chip->chip = new_chip; struct stat st; char *chip_h = malloc(strlen(path) + 18); sprintf(chip_h, "src/%s", path); if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) { /* root_complex gets away without a separate directory, but * exists on on pretty much all AMD chipsets. */ if (!strstr(path, "/root_complex")) { fprintf(stderr, "ERROR: Chip component %s does not exist.\n", path); exit(1); } } sprintf(chip_h, "src/%s/chip.h", path); if ((stat(chip_h, &st) == -1) && (errno == ENOENT)) new_chip->chiph_exists = 0; if (parent->latestchild) { parent->latestchild->next_sibling = new_chip; parent->latestchild->sibling = new_chip; } parent->latestchild = new_chip; if (!parent->children) parent->children = new_chip; free(chip_h); return new_chip; }
struct device *new_device(struct device *parent, struct device *busdev, const int bus, const char *devnum, int enabled) { struct device *new_d = new_dev(parent, busdev); new_d->bustype = bus; char *tmp; new_d->path_a = strtol(strdup(devnum), &tmp, 16); if (*tmp == '.') { tmp++; new_d->path_b = strtol(tmp, NULL, 16); } char *name = malloc(10); sprintf(name, "_dev%d", new_d->id); new_d->name = name; new_d->name_underscore = name; // shouldn't be necessary, but avoid 0-ptr new_d->type = device; new_d->enabled = enabled; new_d->chip = new_d->parent->chip; if (parent->latestchild) { parent->latestchild->next_sibling = new_d; parent->latestchild->sibling = new_d; } parent->latestchild = new_d; if (!parent->children) parent->children = new_d; lastdev->nextdev = new_d; lastdev = new_d; switch(bus) { case PCI: new_d->path = ".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}"; break; case PNP: new_d->path = ".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}"; break; case I2C: new_d->path = ".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}"; break; case APIC: new_d->path = ".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}"; break; case CPU_CLUSTER: new_d->path = ".type=DEVICE_PATH_CPU_CLUSTER,{.cpu_cluster={ .cluster = 0x%x }}"; break; case DOMAIN: new_d->path = ".type=DEVICE_PATH_DOMAIN,{.domain={ .domain = 0x%x }}"; break; case IOAPIC: new_d->path = ".type=DEVICE_PATH_IOAPIC,{.ioapic={ .ioapic_id = 0x%x }}"; break; } return new_d; }