/** * See if a device structure already exists and if not allocate it. * * @param parent The bus to find the device on. * @param path The relative path from the bus to the appropriate device. * @return Pointer to a device structure for the device on bus at path. */ device_t alloc_find_dev(struct bus *parent, struct device_path *path) { device_t child; spin_lock(&dev_lock); child = find_dev_path(parent, path); if (!child) child = __alloc_dev(parent, path); spin_unlock(&dev_lock); return child; }
device_t add_cpu_device(struct bus *cpu_bus, unsigned apic_id, int enabled) { struct device_path cpu_path; device_t cpu; /* Build the cpu device path */ cpu_path.type = DEVICE_PATH_APIC; cpu_path.apic.apic_id = apic_id; /* Update CPU in devicetree. */ if (enabled) cpu = alloc_find_dev(cpu_bus, &cpu_path); else cpu = find_dev_path(cpu_bus, &cpu_path); if (!cpu) return NULL; cpu->enabled = enabled; printk(BIOS_DEBUG, "CPU: %s %s\n", dev_path(cpu), cpu->enabled?"enabled":"disabled"); return cpu; }