processor_driver.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  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(struct acpi_processor *pr);
  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(acpi_processor_hotadd_init(pr)))
  282. return -ENODEV;
  283. }
  284. /*
  285. * On some boxes several processors use the same processor bus id.
  286. * But they are located in different scope. For example:
  287. * \_SB.SCK0.CPU0
  288. * \_SB.SCK1.CPU0
  289. * Rename the processor device bus id. And the new bus id will be
  290. * generated as the following format:
  291. * CPU+CPU ID.
  292. */
  293. sprintf(acpi_device_bid(device), "CPU%X", pr->id);
  294. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
  295. pr->acpi_id));
  296. if (!object.processor.pblk_address)
  297. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
  298. else if (object.processor.pblk_length != 6)
  299. printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
  300. object.processor.pblk_length);
  301. else {
  302. pr->throttling.address = object.processor.pblk_address;
  303. pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
  304. pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
  305. pr->pblk = object.processor.pblk_address;
  306. /*
  307. * We don't care about error returns - we just try to mark
  308. * these reserved so that nobody else is confused into thinking
  309. * that this region might be unused..
  310. *
  311. * (In particular, allocating the IO range for Cardbus)
  312. */
  313. request_region(pr->throttling.address, 6, "ACPI CPU throttle");
  314. }
  315. /*
  316. * If ACPI describes a slot number for this CPU, we can use it
  317. * ensure we get the right value in the "physical id" field
  318. * of /proc/cpuinfo
  319. */
  320. status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
  321. if (ACPI_SUCCESS(status))
  322. arch_fix_phys_package_id(pr->id, object.integer.value);
  323. return 0;
  324. }
  325. static DEFINE_PER_CPU(void *, processor_device_array);
  326. static void acpi_processor_notify(struct acpi_device *device, u32 event)
  327. {
  328. struct acpi_processor *pr = acpi_driver_data(device);
  329. int saved;
  330. if (!pr)
  331. return;
  332. switch (event) {
  333. case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
  334. saved = pr->performance_platform_limit;
  335. acpi_processor_ppc_has_changed(pr, 1);
  336. if (saved == pr->performance_platform_limit)
  337. break;
  338. acpi_bus_generate_proc_event(device, event,
  339. pr->performance_platform_limit);
  340. acpi_bus_generate_netlink_event(device->pnp.device_class,
  341. dev_name(&device->dev), event,
  342. pr->performance_platform_limit);
  343. break;
  344. case ACPI_PROCESSOR_NOTIFY_POWER:
  345. acpi_processor_cst_has_changed(pr);
  346. acpi_bus_generate_proc_event(device, event, 0);
  347. acpi_bus_generate_netlink_event(device->pnp.device_class,
  348. dev_name(&device->dev), event, 0);
  349. break;
  350. case ACPI_PROCESSOR_NOTIFY_THROTTLING:
  351. acpi_processor_tstate_has_changed(pr);
  352. acpi_bus_generate_proc_event(device, event, 0);
  353. acpi_bus_generate_netlink_event(device->pnp.device_class,
  354. dev_name(&device->dev), event, 0);
  355. default:
  356. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  357. "Unsupported event [0x%x]\n", event));
  358. break;
  359. }
  360. return;
  361. }
  362. static int acpi_cpu_soft_notify(struct notifier_block *nfb,
  363. unsigned long action, void *hcpu)
  364. {
  365. unsigned int cpu = (unsigned long)hcpu;
  366. struct acpi_processor *pr = per_cpu(processors, cpu);
  367. if (action == CPU_ONLINE && pr) {
  368. acpi_processor_ppc_has_changed(pr, 0);
  369. acpi_processor_hotplug(pr);
  370. acpi_processor_reevaluate_tstate(pr, action);
  371. acpi_processor_tstate_has_changed(pr);
  372. }
  373. if (action == CPU_DEAD && pr) {
  374. /* invalidate the flag.throttling after one CPU is offline */
  375. acpi_processor_reevaluate_tstate(pr, action);
  376. }
  377. return NOTIFY_OK;
  378. }
  379. static struct notifier_block acpi_cpu_notifier =
  380. {
  381. .notifier_call = acpi_cpu_soft_notify,
  382. };
  383. static int __cpuinit acpi_processor_add(struct acpi_device *device)
  384. {
  385. struct acpi_processor *pr = NULL;
  386. int result = 0;
  387. struct device *dev;
  388. pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  389. if (!pr)
  390. return -ENOMEM;
  391. if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
  392. kfree(pr);
  393. return -ENOMEM;
  394. }
  395. pr->handle = device->handle;
  396. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  397. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  398. device->driver_data = pr;
  399. result = acpi_processor_get_info(device);
  400. if (result) {
  401. /* Processor is physically not present */
  402. return 0;
  403. }
  404. #ifdef CONFIG_SMP
  405. if (pr->id >= setup_max_cpus && pr->id != 0)
  406. return 0;
  407. #endif
  408. BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
  409. /*
  410. * Buggy BIOS check
  411. * ACPI id of processors can be reported wrongly by the BIOS.
  412. * Don't trust it blindly
  413. */
  414. if (per_cpu(processor_device_array, pr->id) != NULL &&
  415. per_cpu(processor_device_array, pr->id) != device) {
  416. printk(KERN_WARNING "BIOS reported wrong ACPI id "
  417. "for the processor\n");
  418. result = -ENODEV;
  419. goto err_free_cpumask;
  420. }
  421. per_cpu(processor_device_array, pr->id) = device;
  422. per_cpu(processors, pr->id) = pr;
  423. dev = get_cpu_device(pr->id);
  424. if (sysfs_create_link(&device->dev.kobj, &dev->kobj, "sysdev")) {
  425. result = -EFAULT;
  426. goto err_free_cpumask;
  427. }
  428. #ifdef CONFIG_CPU_FREQ
  429. acpi_processor_ppc_has_changed(pr, 0);
  430. #endif
  431. acpi_processor_get_throttling_info(pr);
  432. acpi_processor_get_limit_info(pr);
  433. if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
  434. acpi_processor_power_init(pr, device);
  435. pr->cdev = thermal_cooling_device_register("Processor", device,
  436. &processor_cooling_ops);
  437. if (IS_ERR(pr->cdev)) {
  438. result = PTR_ERR(pr->cdev);
  439. goto err_power_exit;
  440. }
  441. dev_dbg(&device->dev, "registered as cooling_device%d\n",
  442. pr->cdev->id);
  443. result = sysfs_create_link(&device->dev.kobj,
  444. &pr->cdev->device.kobj,
  445. "thermal_cooling");
  446. if (result) {
  447. printk(KERN_ERR PREFIX "Create sysfs link\n");
  448. goto err_thermal_unregister;
  449. }
  450. result = sysfs_create_link(&pr->cdev->device.kobj,
  451. &device->dev.kobj,
  452. "device");
  453. if (result) {
  454. printk(KERN_ERR PREFIX "Create sysfs link\n");
  455. goto err_remove_sysfs;
  456. }
  457. return 0;
  458. err_remove_sysfs:
  459. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  460. err_thermal_unregister:
  461. thermal_cooling_device_unregister(pr->cdev);
  462. err_power_exit:
  463. acpi_processor_power_exit(pr, device);
  464. sysfs_remove_link(&device->dev.kobj, "sysdev");
  465. err_free_cpumask:
  466. free_cpumask_var(pr->throttling.shared_cpu_map);
  467. return result;
  468. }
  469. static int acpi_processor_remove(struct acpi_device *device, int type)
  470. {
  471. struct acpi_processor *pr = NULL;
  472. if (!device || !acpi_driver_data(device))
  473. return -EINVAL;
  474. pr = acpi_driver_data(device);
  475. if (pr->id >= nr_cpu_ids)
  476. goto free;
  477. if (type == ACPI_BUS_REMOVAL_EJECT) {
  478. if (acpi_processor_handle_eject(pr))
  479. return -EINVAL;
  480. }
  481. acpi_processor_power_exit(pr, device);
  482. sysfs_remove_link(&device->dev.kobj, "sysdev");
  483. if (pr->cdev) {
  484. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  485. sysfs_remove_link(&pr->cdev->device.kobj, "device");
  486. thermal_cooling_device_unregister(pr->cdev);
  487. pr->cdev = NULL;
  488. }
  489. per_cpu(processors, pr->id) = NULL;
  490. per_cpu(processor_device_array, pr->id) = NULL;
  491. free:
  492. free_cpumask_var(pr->throttling.shared_cpu_map);
  493. kfree(pr);
  494. return 0;
  495. }
  496. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  497. /****************************************************************************
  498. * Acpi processor hotplug support *
  499. ****************************************************************************/
  500. static int is_processor_present(acpi_handle handle)
  501. {
  502. acpi_status status;
  503. unsigned long long sta = 0;
  504. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  505. if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
  506. return 1;
  507. /*
  508. * _STA is mandatory for a processor that supports hot plug
  509. */
  510. if (status == AE_NOT_FOUND)
  511. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  512. "Processor does not support hot plug\n"));
  513. else
  514. ACPI_EXCEPTION((AE_INFO, status,
  515. "Processor Device is not present"));
  516. return 0;
  517. }
  518. static
  519. int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
  520. {
  521. acpi_handle phandle;
  522. struct acpi_device *pdev;
  523. if (acpi_get_parent(handle, &phandle)) {
  524. return -ENODEV;
  525. }
  526. if (acpi_bus_get_device(phandle, &pdev)) {
  527. return -ENODEV;
  528. }
  529. if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
  530. return -ENODEV;
  531. }
  532. return 0;
  533. }
  534. static void acpi_processor_hotplug_notify(acpi_handle handle,
  535. u32 event, void *data)
  536. {
  537. struct acpi_processor *pr;
  538. struct acpi_device *device = NULL;
  539. int result;
  540. switch (event) {
  541. case ACPI_NOTIFY_BUS_CHECK:
  542. case ACPI_NOTIFY_DEVICE_CHECK:
  543. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  544. "Processor driver received %s event\n",
  545. (event == ACPI_NOTIFY_BUS_CHECK) ?
  546. "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
  547. if (!is_processor_present(handle))
  548. break;
  549. if (acpi_bus_get_device(handle, &device)) {
  550. result = acpi_processor_device_add(handle, &device);
  551. if (result)
  552. printk(KERN_ERR PREFIX
  553. "Unable to add the device\n");
  554. break;
  555. }
  556. break;
  557. case ACPI_NOTIFY_EJECT_REQUEST:
  558. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  559. "received ACPI_NOTIFY_EJECT_REQUEST\n"));
  560. if (acpi_bus_get_device(handle, &device)) {
  561. printk(KERN_ERR PREFIX
  562. "Device don't exist, dropping EJECT\n");
  563. break;
  564. }
  565. pr = acpi_driver_data(device);
  566. if (!pr) {
  567. printk(KERN_ERR PREFIX
  568. "Driver data is NULL, dropping EJECT\n");
  569. return;
  570. }
  571. break;
  572. default:
  573. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  574. "Unsupported event [0x%x]\n", event));
  575. break;
  576. }
  577. return;
  578. }
  579. static acpi_status
  580. processor_walk_namespace_cb(acpi_handle handle,
  581. u32 lvl, void *context, void **rv)
  582. {
  583. acpi_status status;
  584. int *action = context;
  585. acpi_object_type type = 0;
  586. status = acpi_get_type(handle, &type);
  587. if (ACPI_FAILURE(status))
  588. return (AE_OK);
  589. if (type != ACPI_TYPE_PROCESSOR)
  590. return (AE_OK);
  591. switch (*action) {
  592. case INSTALL_NOTIFY_HANDLER:
  593. acpi_install_notify_handler(handle,
  594. ACPI_SYSTEM_NOTIFY,
  595. acpi_processor_hotplug_notify,
  596. NULL);
  597. break;
  598. case UNINSTALL_NOTIFY_HANDLER:
  599. acpi_remove_notify_handler(handle,
  600. ACPI_SYSTEM_NOTIFY,
  601. acpi_processor_hotplug_notify);
  602. break;
  603. default:
  604. break;
  605. }
  606. return (AE_OK);
  607. }
  608. static acpi_status acpi_processor_hotadd_init(struct acpi_processor *pr)
  609. {
  610. acpi_handle handle = pr->handle;
  611. if (!is_processor_present(handle)) {
  612. return AE_ERROR;
  613. }
  614. if (acpi_map_lsapic(handle, &pr->id))
  615. return AE_ERROR;
  616. if (arch_register_cpu(pr->id)) {
  617. acpi_unmap_lsapic(pr->id);
  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(struct acpi_processor *pr)
  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. result = acpi_bus_register_driver(&acpi_processor_driver);
  676. if (result < 0)
  677. return result;
  678. acpi_processor_install_hotplug_notify();
  679. acpi_thermal_cpufreq_init();
  680. acpi_processor_ppc_init();
  681. acpi_processor_throttling_init();
  682. return 0;
  683. }
  684. static void __exit acpi_processor_exit(void)
  685. {
  686. if (acpi_disabled)
  687. return;
  688. acpi_processor_ppc_exit();
  689. acpi_thermal_cpufreq_exit();
  690. acpi_processor_uninstall_hotplug_notify();
  691. acpi_bus_unregister_driver(&acpi_processor_driver);
  692. return;
  693. }
  694. module_init(acpi_processor_init);
  695. module_exit(acpi_processor_exit);
  696. MODULE_ALIAS("processor");