processor_driver.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. /*
  2. * acpi_processor.c - ACPI Processor Driver ($Revision: 71 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
  7. * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
  8. * - Added processor hotplug support
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or (at
  15. * your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. * TBD:
  28. * 1. Make # power states dynamic.
  29. * 2. Support duty_cycle values that span bit 4.
  30. * 3. Optimize by having scheduler determine business instead of
  31. * having us try to calculate it here.
  32. * 4. Need C1 timing -- must modify kernel (IRQ handler) to get this.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/types.h>
  38. #include <linux/pci.h>
  39. #include <linux/pm.h>
  40. #include <linux/cpufreq.h>
  41. #include <linux/cpu.h>
  42. #include <linux/dmi.h>
  43. #include <linux/moduleparam.h>
  44. #include <linux/cpuidle.h>
  45. #include <linux/slab.h>
  46. #include <asm/io.h>
  47. #include <asm/system.h>
  48. #include <asm/cpu.h>
  49. #include <asm/delay.h>
  50. #include <asm/uaccess.h>
  51. #include <asm/processor.h>
  52. #include <asm/smp.h>
  53. #include <asm/acpi.h>
  54. #include <acpi/acpi_bus.h>
  55. #include <acpi/acpi_drivers.h>
  56. #include <acpi/processor.h>
  57. #define PREFIX "ACPI: "
  58. #define ACPI_PROCESSOR_CLASS "processor"
  59. #define ACPI_PROCESSOR_DEVICE_NAME "Processor"
  60. #define ACPI_PROCESSOR_FILE_INFO "info"
  61. #define ACPI_PROCESSOR_FILE_THROTTLING "throttling"
  62. #define ACPI_PROCESSOR_FILE_LIMIT "limit"
  63. #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
  64. #define ACPI_PROCESSOR_NOTIFY_POWER 0x81
  65. #define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
  66. #define ACPI_PROCESSOR_LIMIT_USER 0
  67. #define ACPI_PROCESSOR_LIMIT_THERMAL 1
  68. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  69. ACPI_MODULE_NAME("processor_driver");
  70. MODULE_AUTHOR("Paul Diefenbaugh");
  71. MODULE_DESCRIPTION("ACPI Processor Driver");
  72. MODULE_LICENSE("GPL");
  73. static int acpi_processor_add(struct acpi_device *device);
  74. static int acpi_processor_remove(struct acpi_device *device, int type);
  75. static void acpi_processor_notify(struct acpi_device *device, u32 event);
  76. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
  77. static int acpi_processor_handle_eject(struct acpi_processor *pr);
  78. static const struct acpi_device_id processor_device_ids[] = {
  79. {ACPI_PROCESSOR_OBJECT_HID, 0},
  80. {"ACPI0007", 0},
  81. {"", 0},
  82. };
  83. MODULE_DEVICE_TABLE(acpi, processor_device_ids);
  84. static struct acpi_driver acpi_processor_driver = {
  85. .name = "processor",
  86. .class = ACPI_PROCESSOR_CLASS,
  87. .ids = processor_device_ids,
  88. .ops = {
  89. .add = acpi_processor_add,
  90. .remove = acpi_processor_remove,
  91. .suspend = acpi_processor_suspend,
  92. .resume = acpi_processor_resume,
  93. .notify = acpi_processor_notify,
  94. },
  95. };
  96. #define INSTALL_NOTIFY_HANDLER 1
  97. #define UNINSTALL_NOTIFY_HANDLER 2
  98. DEFINE_PER_CPU(struct acpi_processor *, processors);
  99. EXPORT_PER_CPU_SYMBOL(processors);
  100. struct acpi_processor_errata errata __read_mostly;
  101. /* --------------------------------------------------------------------------
  102. Errata Handling
  103. -------------------------------------------------------------------------- */
  104. static int acpi_processor_errata_piix4(struct pci_dev *dev)
  105. {
  106. u8 value1 = 0;
  107. u8 value2 = 0;
  108. if (!dev)
  109. return -EINVAL;
  110. /*
  111. * Note that 'dev' references the PIIX4 ACPI Controller.
  112. */
  113. switch (dev->revision) {
  114. case 0:
  115. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
  116. break;
  117. case 1:
  118. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
  119. break;
  120. case 2:
  121. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
  122. break;
  123. case 3:
  124. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
  125. break;
  126. default:
  127. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
  128. break;
  129. }
  130. switch (dev->revision) {
  131. case 0: /* PIIX4 A-step */
  132. case 1: /* PIIX4 B-step */
  133. /*
  134. * See specification changes #13 ("Manual Throttle Duty Cycle")
  135. * and #14 ("Enabling and Disabling Manual Throttle"), plus
  136. * erratum #5 ("STPCLK# Deassertion Time") from the January
  137. * 2002 PIIX4 specification update. Applies to only older
  138. * PIIX4 models.
  139. */
  140. errata.piix4.throttle = 1;
  141. case 2: /* PIIX4E */
  142. case 3: /* PIIX4M */
  143. /*
  144. * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
  145. * Livelock") from the January 2002 PIIX4 specification update.
  146. * Applies to all PIIX4 models.
  147. */
  148. /*
  149. * BM-IDE
  150. * ------
  151. * Find the PIIX4 IDE Controller and get the Bus Master IDE
  152. * Status register address. We'll use this later to read
  153. * each IDE controller's DMA status to make sure we catch all
  154. * DMA activity.
  155. */
  156. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  157. PCI_DEVICE_ID_INTEL_82371AB,
  158. PCI_ANY_ID, PCI_ANY_ID, NULL);
  159. if (dev) {
  160. errata.piix4.bmisx = pci_resource_start(dev, 4);
  161. pci_dev_put(dev);
  162. }
  163. /*
  164. * Type-F DMA
  165. * ----------
  166. * Find the PIIX4 ISA Controller and read the Motherboard
  167. * DMA controller's status to see if Type-F (Fast) DMA mode
  168. * is enabled (bit 7) on either channel. Note that we'll
  169. * disable C3 support if this is enabled, as some legacy
  170. * devices won't operate well if fast DMA is disabled.
  171. */
  172. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  173. PCI_DEVICE_ID_INTEL_82371AB_0,
  174. PCI_ANY_ID, PCI_ANY_ID, NULL);
  175. if (dev) {
  176. pci_read_config_byte(dev, 0x76, &value1);
  177. pci_read_config_byte(dev, 0x77, &value2);
  178. if ((value1 & 0x80) || (value2 & 0x80))
  179. errata.piix4.fdma = 1;
  180. pci_dev_put(dev);
  181. }
  182. break;
  183. }
  184. if (errata.piix4.bmisx)
  185. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  186. "Bus master activity detection (BM-IDE) erratum enabled\n"));
  187. if (errata.piix4.fdma)
  188. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  189. "Type-F DMA livelock erratum (C3 disabled)\n"));
  190. return 0;
  191. }
  192. static int acpi_processor_errata(struct acpi_processor *pr)
  193. {
  194. int result = 0;
  195. struct pci_dev *dev = NULL;
  196. if (!pr)
  197. return -EINVAL;
  198. /*
  199. * PIIX4
  200. */
  201. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  202. PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
  203. PCI_ANY_ID, NULL);
  204. if (dev) {
  205. result = acpi_processor_errata_piix4(dev);
  206. pci_dev_put(dev);
  207. }
  208. return result;
  209. }
  210. /* --------------------------------------------------------------------------
  211. Driver Interface
  212. -------------------------------------------------------------------------- */
  213. static int acpi_processor_get_info(struct acpi_device *device)
  214. {
  215. acpi_status status = 0;
  216. union acpi_object object = { 0 };
  217. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  218. struct acpi_processor *pr;
  219. int cpu_index, device_declaration = 0;
  220. static int cpu0_initialized;
  221. pr = acpi_driver_data(device);
  222. if (!pr)
  223. return -EINVAL;
  224. if (num_online_cpus() > 1)
  225. errata.smp = TRUE;
  226. acpi_processor_errata(pr);
  227. /*
  228. * Check to see if we have bus mastering arbitration control. This
  229. * is required for proper C3 usage (to maintain cache coherency).
  230. */
  231. if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
  232. pr->flags.bm_control = 1;
  233. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  234. "Bus mastering arbitration control present\n"));
  235. } else
  236. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  237. "No bus mastering arbitration control\n"));
  238. if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
  239. /* Declared with "Processor" statement; match ProcessorID */
  240. status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
  241. if (ACPI_FAILURE(status)) {
  242. printk(KERN_ERR PREFIX "Evaluating processor object\n");
  243. return -ENODEV;
  244. }
  245. /*
  246. * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
  247. * >>> 'acpi_get_processor_id(acpi_id, &id)' in
  248. * arch/xxx/acpi.c
  249. */
  250. pr->acpi_id = object.processor.proc_id;
  251. } else {
  252. /*
  253. * Declared with "Device" statement; match _UID.
  254. * Note that we don't handle string _UIDs yet.
  255. */
  256. unsigned long long value;
  257. status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
  258. NULL, &value);
  259. if (ACPI_FAILURE(status)) {
  260. printk(KERN_ERR PREFIX
  261. "Evaluating processor _UID [%#x]\n", status);
  262. return -ENODEV;
  263. }
  264. device_declaration = 1;
  265. pr->acpi_id = value;
  266. }
  267. cpu_index = acpi_get_cpuid(pr->handle, device_declaration, pr->acpi_id);
  268. /* Handle UP system running SMP kernel, with no LAPIC in MADT */
  269. if (!cpu0_initialized && (cpu_index == -1) &&
  270. (num_online_cpus() == 1)) {
  271. cpu_index = 0;
  272. }
  273. cpu0_initialized = 1;
  274. pr->id = cpu_index;
  275. /*
  276. * Extra Processor objects may be enumerated on MP systems with
  277. * less than the max # of CPUs. They should be ignored _iff
  278. * they are physically not present.
  279. */
  280. if (pr->id == -1) {
  281. if (ACPI_FAILURE
  282. (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
  283. return -ENODEV;
  284. }
  285. }
  286. /*
  287. * On some boxes several processors use the same processor bus id.
  288. * But they are located in different scope. For example:
  289. * \_SB.SCK0.CPU0
  290. * \_SB.SCK1.CPU0
  291. * Rename the processor device bus id. And the new bus id will be
  292. * generated as the following format:
  293. * CPU+CPU ID.
  294. */
  295. sprintf(acpi_device_bid(device), "CPU%X", pr->id);
  296. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
  297. pr->acpi_id));
  298. if (!object.processor.pblk_address)
  299. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
  300. else if (object.processor.pblk_length != 6)
  301. printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
  302. object.processor.pblk_length);
  303. else {
  304. pr->throttling.address = object.processor.pblk_address;
  305. pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
  306. pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
  307. pr->pblk = object.processor.pblk_address;
  308. /*
  309. * We don't care about error returns - we just try to mark
  310. * these reserved so that nobody else is confused into thinking
  311. * that this region might be unused..
  312. *
  313. * (In particular, allocating the IO range for Cardbus)
  314. */
  315. request_region(pr->throttling.address, 6, "ACPI CPU throttle");
  316. }
  317. /*
  318. * If ACPI describes a slot number for this CPU, we can use it
  319. * ensure we get the right value in the "physical id" field
  320. * of /proc/cpuinfo
  321. */
  322. status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
  323. if (ACPI_SUCCESS(status))
  324. arch_fix_phys_package_id(pr->id, object.integer.value);
  325. return 0;
  326. }
  327. static DEFINE_PER_CPU(void *, processor_device_array);
  328. static void acpi_processor_notify(struct acpi_device *device, u32 event)
  329. {
  330. struct acpi_processor *pr = acpi_driver_data(device);
  331. int saved;
  332. if (!pr)
  333. return;
  334. switch (event) {
  335. case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
  336. saved = pr->performance_platform_limit;
  337. acpi_processor_ppc_has_changed(pr, 1);
  338. if (saved == pr->performance_platform_limit)
  339. break;
  340. acpi_bus_generate_proc_event(device, event,
  341. pr->performance_platform_limit);
  342. acpi_bus_generate_netlink_event(device->pnp.device_class,
  343. dev_name(&device->dev), event,
  344. pr->performance_platform_limit);
  345. break;
  346. case ACPI_PROCESSOR_NOTIFY_POWER:
  347. acpi_processor_cst_has_changed(pr);
  348. acpi_bus_generate_proc_event(device, event, 0);
  349. acpi_bus_generate_netlink_event(device->pnp.device_class,
  350. dev_name(&device->dev), event, 0);
  351. break;
  352. case ACPI_PROCESSOR_NOTIFY_THROTTLING:
  353. acpi_processor_tstate_has_changed(pr);
  354. acpi_bus_generate_proc_event(device, event, 0);
  355. acpi_bus_generate_netlink_event(device->pnp.device_class,
  356. dev_name(&device->dev), event, 0);
  357. default:
  358. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  359. "Unsupported event [0x%x]\n", event));
  360. break;
  361. }
  362. return;
  363. }
  364. static int acpi_cpu_soft_notify(struct notifier_block *nfb,
  365. unsigned long action, void *hcpu)
  366. {
  367. unsigned int cpu = (unsigned long)hcpu;
  368. struct acpi_processor *pr = per_cpu(processors, cpu);
  369. if (action == CPU_ONLINE && pr) {
  370. acpi_processor_ppc_has_changed(pr, 0);
  371. acpi_processor_cst_has_changed(pr);
  372. acpi_processor_reevaluate_tstate(pr, action);
  373. acpi_processor_tstate_has_changed(pr);
  374. }
  375. if (action == CPU_DEAD && pr) {
  376. /* invalidate the flag.throttling after one CPU is offline */
  377. acpi_processor_reevaluate_tstate(pr, action);
  378. }
  379. return NOTIFY_OK;
  380. }
  381. static struct notifier_block acpi_cpu_notifier =
  382. {
  383. .notifier_call = acpi_cpu_soft_notify,
  384. };
  385. static int __cpuinit acpi_processor_add(struct acpi_device *device)
  386. {
  387. struct acpi_processor *pr = NULL;
  388. int result = 0;
  389. struct sys_device *sysdev;
  390. pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  391. if (!pr)
  392. return -ENOMEM;
  393. if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
  394. kfree(pr);
  395. return -ENOMEM;
  396. }
  397. pr->handle = device->handle;
  398. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  399. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  400. device->driver_data = pr;
  401. result = acpi_processor_get_info(device);
  402. if (result) {
  403. /* Processor is physically not present */
  404. return 0;
  405. }
  406. #ifdef CONFIG_SMP
  407. if (pr->id >= setup_max_cpus && pr->id != 0)
  408. return 0;
  409. #endif
  410. BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
  411. /*
  412. * Buggy BIOS check
  413. * ACPI id of processors can be reported wrongly by the BIOS.
  414. * Don't trust it blindly
  415. */
  416. if (per_cpu(processor_device_array, pr->id) != NULL &&
  417. per_cpu(processor_device_array, pr->id) != device) {
  418. printk(KERN_WARNING "BIOS reported wrong ACPI id "
  419. "for the processor\n");
  420. result = -ENODEV;
  421. goto err_free_cpumask;
  422. }
  423. per_cpu(processor_device_array, pr->id) = device;
  424. per_cpu(processors, pr->id) = pr;
  425. sysdev = get_cpu_sysdev(pr->id);
  426. if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
  427. result = -EFAULT;
  428. goto err_free_cpumask;
  429. }
  430. #ifdef CONFIG_CPU_FREQ
  431. acpi_processor_ppc_has_changed(pr, 0);
  432. #endif
  433. acpi_processor_get_throttling_info(pr);
  434. acpi_processor_get_limit_info(pr);
  435. if (cpuidle_get_driver() == &acpi_idle_driver)
  436. acpi_processor_power_init(pr, device);
  437. pr->cdev = thermal_cooling_device_register("Processor", device,
  438. &processor_cooling_ops);
  439. if (IS_ERR(pr->cdev)) {
  440. result = PTR_ERR(pr->cdev);
  441. goto err_power_exit;
  442. }
  443. dev_dbg(&device->dev, "registered as cooling_device%d\n",
  444. pr->cdev->id);
  445. result = sysfs_create_link(&device->dev.kobj,
  446. &pr->cdev->device.kobj,
  447. "thermal_cooling");
  448. if (result) {
  449. printk(KERN_ERR PREFIX "Create sysfs link\n");
  450. goto err_thermal_unregister;
  451. }
  452. result = sysfs_create_link(&pr->cdev->device.kobj,
  453. &device->dev.kobj,
  454. "device");
  455. if (result) {
  456. printk(KERN_ERR PREFIX "Create sysfs link\n");
  457. goto err_remove_sysfs;
  458. }
  459. return 0;
  460. err_remove_sysfs:
  461. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  462. err_thermal_unregister:
  463. thermal_cooling_device_unregister(pr->cdev);
  464. err_power_exit:
  465. acpi_processor_power_exit(pr, device);
  466. err_free_cpumask:
  467. free_cpumask_var(pr->throttling.shared_cpu_map);
  468. return result;
  469. }
  470. static int acpi_processor_remove(struct acpi_device *device, int type)
  471. {
  472. struct acpi_processor *pr = NULL;
  473. if (!device || !acpi_driver_data(device))
  474. return -EINVAL;
  475. pr = acpi_driver_data(device);
  476. if (pr->id >= nr_cpu_ids)
  477. goto free;
  478. if (type == ACPI_BUS_REMOVAL_EJECT) {
  479. if (acpi_processor_handle_eject(pr))
  480. return -EINVAL;
  481. }
  482. acpi_processor_power_exit(pr, device);
  483. sysfs_remove_link(&device->dev.kobj, "sysdev");
  484. if (pr->cdev) {
  485. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  486. sysfs_remove_link(&pr->cdev->device.kobj, "device");
  487. thermal_cooling_device_unregister(pr->cdev);
  488. pr->cdev = NULL;
  489. }
  490. per_cpu(processors, pr->id) = NULL;
  491. per_cpu(processor_device_array, pr->id) = NULL;
  492. free:
  493. free_cpumask_var(pr->throttling.shared_cpu_map);
  494. kfree(pr);
  495. return 0;
  496. }
  497. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  498. /****************************************************************************
  499. * Acpi processor hotplug support *
  500. ****************************************************************************/
  501. static int is_processor_present(acpi_handle handle)
  502. {
  503. acpi_status status;
  504. unsigned long long sta = 0;
  505. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  506. if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
  507. return 1;
  508. /*
  509. * _STA is mandatory for a processor that supports hot plug
  510. */
  511. if (status == AE_NOT_FOUND)
  512. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  513. "Processor does not support hot plug\n"));
  514. else
  515. ACPI_EXCEPTION((AE_INFO, status,
  516. "Processor Device is not present"));
  517. return 0;
  518. }
  519. static
  520. int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
  521. {
  522. acpi_handle phandle;
  523. struct acpi_device *pdev;
  524. if (acpi_get_parent(handle, &phandle)) {
  525. return -ENODEV;
  526. }
  527. if (acpi_bus_get_device(phandle, &pdev)) {
  528. return -ENODEV;
  529. }
  530. if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
  531. return -ENODEV;
  532. }
  533. return 0;
  534. }
  535. static void acpi_processor_hotplug_notify(acpi_handle handle,
  536. u32 event, void *data)
  537. {
  538. struct acpi_processor *pr;
  539. struct acpi_device *device = NULL;
  540. int result;
  541. switch (event) {
  542. case ACPI_NOTIFY_BUS_CHECK:
  543. case ACPI_NOTIFY_DEVICE_CHECK:
  544. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  545. "Processor driver received %s event\n",
  546. (event == ACPI_NOTIFY_BUS_CHECK) ?
  547. "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
  548. if (!is_processor_present(handle))
  549. break;
  550. if (acpi_bus_get_device(handle, &device)) {
  551. result = acpi_processor_device_add(handle, &device);
  552. if (result)
  553. printk(KERN_ERR PREFIX
  554. "Unable to add the device\n");
  555. break;
  556. }
  557. break;
  558. case ACPI_NOTIFY_EJECT_REQUEST:
  559. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  560. "received ACPI_NOTIFY_EJECT_REQUEST\n"));
  561. if (acpi_bus_get_device(handle, &device)) {
  562. printk(KERN_ERR PREFIX
  563. "Device don't exist, dropping EJECT\n");
  564. break;
  565. }
  566. pr = acpi_driver_data(device);
  567. if (!pr) {
  568. printk(KERN_ERR PREFIX
  569. "Driver data is NULL, dropping EJECT\n");
  570. return;
  571. }
  572. break;
  573. default:
  574. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  575. "Unsupported event [0x%x]\n", event));
  576. break;
  577. }
  578. return;
  579. }
  580. static acpi_status
  581. processor_walk_namespace_cb(acpi_handle handle,
  582. u32 lvl, void *context, void **rv)
  583. {
  584. acpi_status status;
  585. int *action = context;
  586. acpi_object_type type = 0;
  587. status = acpi_get_type(handle, &type);
  588. if (ACPI_FAILURE(status))
  589. return (AE_OK);
  590. if (type != ACPI_TYPE_PROCESSOR)
  591. return (AE_OK);
  592. switch (*action) {
  593. case INSTALL_NOTIFY_HANDLER:
  594. acpi_install_notify_handler(handle,
  595. ACPI_SYSTEM_NOTIFY,
  596. acpi_processor_hotplug_notify,
  597. NULL);
  598. break;
  599. case UNINSTALL_NOTIFY_HANDLER:
  600. acpi_remove_notify_handler(handle,
  601. ACPI_SYSTEM_NOTIFY,
  602. acpi_processor_hotplug_notify);
  603. break;
  604. default:
  605. break;
  606. }
  607. return (AE_OK);
  608. }
  609. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  610. {
  611. if (!is_processor_present(handle)) {
  612. return AE_ERROR;
  613. }
  614. if (acpi_map_lsapic(handle, p_cpu))
  615. return AE_ERROR;
  616. if (arch_register_cpu(*p_cpu)) {
  617. acpi_unmap_lsapic(*p_cpu);
  618. return AE_ERROR;
  619. }
  620. return AE_OK;
  621. }
  622. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  623. {
  624. if (cpu_online(pr->id))
  625. cpu_down(pr->id);
  626. arch_unregister_cpu(pr->id);
  627. acpi_unmap_lsapic(pr->id);
  628. return (0);
  629. }
  630. #else
  631. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  632. {
  633. return AE_ERROR;
  634. }
  635. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  636. {
  637. return (-EINVAL);
  638. }
  639. #endif
  640. static
  641. void acpi_processor_install_hotplug_notify(void)
  642. {
  643. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  644. int action = INSTALL_NOTIFY_HANDLER;
  645. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  646. ACPI_ROOT_OBJECT,
  647. ACPI_UINT32_MAX,
  648. processor_walk_namespace_cb, NULL, &action, NULL);
  649. #endif
  650. register_hotcpu_notifier(&acpi_cpu_notifier);
  651. }
  652. static
  653. void acpi_processor_uninstall_hotplug_notify(void)
  654. {
  655. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  656. int action = UNINSTALL_NOTIFY_HANDLER;
  657. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  658. ACPI_ROOT_OBJECT,
  659. ACPI_UINT32_MAX,
  660. processor_walk_namespace_cb, NULL, &action, NULL);
  661. #endif
  662. unregister_hotcpu_notifier(&acpi_cpu_notifier);
  663. }
  664. /*
  665. * We keep the driver loaded even when ACPI is not running.
  666. * This is needed for the powernow-k8 driver, that works even without
  667. * ACPI, but needs symbols from this driver
  668. */
  669. static int __init acpi_processor_init(void)
  670. {
  671. int result = 0;
  672. if (acpi_disabled)
  673. return 0;
  674. memset(&errata, 0, sizeof(errata));
  675. if (!cpuidle_register_driver(&acpi_idle_driver)) {
  676. printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
  677. acpi_idle_driver.name);
  678. } else {
  679. printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
  680. cpuidle_get_driver()->name);
  681. }
  682. result = acpi_bus_register_driver(&acpi_processor_driver);
  683. if (result < 0)
  684. goto out_cpuidle;
  685. acpi_processor_install_hotplug_notify();
  686. acpi_thermal_cpufreq_init();
  687. acpi_processor_ppc_init();
  688. acpi_processor_throttling_init();
  689. return 0;
  690. out_cpuidle:
  691. cpuidle_unregister_driver(&acpi_idle_driver);
  692. return result;
  693. }
  694. static void __exit acpi_processor_exit(void)
  695. {
  696. if (acpi_disabled)
  697. return;
  698. acpi_processor_ppc_exit();
  699. acpi_thermal_cpufreq_exit();
  700. acpi_processor_uninstall_hotplug_notify();
  701. acpi_bus_unregister_driver(&acpi_processor_driver);
  702. cpuidle_unregister_driver(&acpi_idle_driver);
  703. return;
  704. }
  705. module_init(acpi_processor_init);
  706. module_exit(acpi_processor_exit);
  707. MODULE_ALIAS("processor");