Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Populate sysfs with topology information
0003  *
0004  * Written by: Matthew Dobson, IBM Corporation
0005  * Original Code: Paul Dorwin, IBM Corporation, Patrick Mochel, OSDL
0006  *
0007  * Copyright (C) 2002, IBM Corp.
0008  *
0009  * All rights reserved.
0010  *
0011  * This program is free software; you can redistribute it and/or modify
0012  * it under the terms of the GNU General Public License as published by
0013  * the Free Software Foundation; either version 2 of the License, or
0014  * (at your option) any later version.
0015  *
0016  * This program is distributed in the hope that it will be useful, but
0017  * WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0019  * NON INFRINGEMENT.  See the GNU General Public License for more
0020  * details.
0021  *
0022  * You should have received a copy of the GNU General Public License
0023  * along with this program; if not, write to the Free Software
0024  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0025  *
0026  * Send feedback to <colpatch@us.ibm.com>
0027  */
0028 #include <linux/interrupt.h>
0029 #include <linux/nodemask.h>
0030 #include <linux/export.h>
0031 #include <linux/mmzone.h>
0032 #include <linux/init.h>
0033 #include <linux/smp.h>
0034 #include <linux/irq.h>
0035 #include <asm/io_apic.h>
0036 #include <asm/cpu.h>
0037 
0038 static DEFINE_PER_CPU(struct x86_cpu, cpu_devices);
0039 
0040 #ifdef CONFIG_HOTPLUG_CPU
0041 
0042 #ifdef CONFIG_BOOTPARAM_HOTPLUG_CPU0
0043 static int cpu0_hotpluggable = 1;
0044 #else
0045 static int cpu0_hotpluggable;
0046 static int __init enable_cpu0_hotplug(char *str)
0047 {
0048     cpu0_hotpluggable = 1;
0049     return 1;
0050 }
0051 
0052 __setup("cpu0_hotplug", enable_cpu0_hotplug);
0053 #endif
0054 
0055 #ifdef CONFIG_DEBUG_HOTPLUG_CPU0
0056 /*
0057  * This function offlines a CPU as early as possible and allows userspace to
0058  * boot up without the CPU. The CPU can be onlined back by user after boot.
0059  *
0060  * This is only called for debugging CPU offline/online feature.
0061  */
0062 int _debug_hotplug_cpu(int cpu, int action)
0063 {
0064     int ret;
0065 
0066     if (!cpu_is_hotpluggable(cpu))
0067         return -EINVAL;
0068 
0069     switch (action) {
0070     case 0:
0071         ret = remove_cpu(cpu);
0072         if (!ret)
0073             pr_info("DEBUG_HOTPLUG_CPU0: CPU %u is now offline\n", cpu);
0074         else
0075             pr_debug("Can't offline CPU%d.\n", cpu);
0076         break;
0077     case 1:
0078         ret = add_cpu(cpu);
0079         if (ret)
0080             pr_debug("Can't online CPU%d.\n", cpu);
0081 
0082         break;
0083     default:
0084         ret = -EINVAL;
0085     }
0086 
0087     return ret;
0088 }
0089 
0090 static int __init debug_hotplug_cpu(void)
0091 {
0092     _debug_hotplug_cpu(0, 0);
0093     return 0;
0094 }
0095 
0096 late_initcall_sync(debug_hotplug_cpu);
0097 #endif /* CONFIG_DEBUG_HOTPLUG_CPU0 */
0098 
0099 int arch_register_cpu(int num)
0100 {
0101     struct cpuinfo_x86 *c = &cpu_data(num);
0102 
0103     /*
0104      * Currently CPU0 is only hotpluggable on Intel platforms. Other
0105      * vendors can add hotplug support later.
0106      * Xen PV guests don't support CPU0 hotplug at all.
0107      */
0108     if (c->x86_vendor != X86_VENDOR_INTEL ||
0109         boot_cpu_has(X86_FEATURE_XENPV))
0110         cpu0_hotpluggable = 0;
0111 
0112     /*
0113      * Two known BSP/CPU0 dependencies: Resume from suspend/hibernate
0114      * depends on BSP. PIC interrupts depend on BSP.
0115      *
0116      * If the BSP dependencies are under control, one can tell kernel to
0117      * enable BSP hotplug. This basically adds a control file and
0118      * one can attempt to offline BSP.
0119      */
0120     if (num == 0 && cpu0_hotpluggable) {
0121         unsigned int irq;
0122         /*
0123          * We won't take down the boot processor on i386 if some
0124          * interrupts only are able to be serviced by the BSP in PIC.
0125          */
0126         for_each_active_irq(irq) {
0127             if (!IO_APIC_IRQ(irq) && irq_has_action(irq)) {
0128                 cpu0_hotpluggable = 0;
0129                 break;
0130             }
0131         }
0132     }
0133     if (num || cpu0_hotpluggable)
0134         per_cpu(cpu_devices, num).cpu.hotpluggable = 1;
0135 
0136     return register_cpu(&per_cpu(cpu_devices, num).cpu, num);
0137 }
0138 EXPORT_SYMBOL(arch_register_cpu);
0139 
0140 void arch_unregister_cpu(int num)
0141 {
0142     unregister_cpu(&per_cpu(cpu_devices, num).cpu);
0143 }
0144 EXPORT_SYMBOL(arch_unregister_cpu);
0145 #else /* CONFIG_HOTPLUG_CPU */
0146 
0147 static int __init arch_register_cpu(int num)
0148 {
0149     return register_cpu(&per_cpu(cpu_devices, num).cpu, num);
0150 }
0151 #endif /* CONFIG_HOTPLUG_CPU */
0152 
0153 static int __init topology_init(void)
0154 {
0155     int i;
0156 
0157     for_each_present_cpu(i)
0158         arch_register_cpu(i);
0159 
0160     return 0;
0161 }
0162 subsys_initcall(topology_init);