processor_driver.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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_tstate_has_changed(pr);
  373. }
  374. return NOTIFY_OK;
  375. }
  376. static struct notifier_block acpi_cpu_notifier =
  377. {
  378. .notifier_call = acpi_cpu_soft_notify,
  379. };
  380. static int __cpuinit acpi_processor_add(struct acpi_device *device)
  381. {
  382. struct acpi_processor *pr = NULL;
  383. int result = 0;
  384. struct sys_device *sysdev;
  385. pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  386. if (!pr)
  387. return -ENOMEM;
  388. if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
  389. kfree(pr);
  390. return -ENOMEM;
  391. }
  392. pr->handle = device->handle;
  393. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  394. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  395. device->driver_data = pr;
  396. result = acpi_processor_get_info(device);
  397. if (result) {
  398. /* Processor is physically not present */
  399. return 0;
  400. }
  401. #ifdef CONFIG_SMP
  402. if (pr->id >= setup_max_cpus && pr->id != 0)
  403. return 0;
  404. #endif
  405. BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
  406. /*
  407. * Buggy BIOS check
  408. * ACPI id of processors can be reported wrongly by the BIOS.
  409. * Don't trust it blindly
  410. */
  411. if (per_cpu(processor_device_array, pr->id) != NULL &&
  412. per_cpu(processor_device_array, pr->id) != device) {
  413. printk(KERN_WARNING "BIOS reported wrong ACPI id "
  414. "for the processor\n");
  415. result = -ENODEV;
  416. goto err_free_cpumask;
  417. }
  418. per_cpu(processor_device_array, pr->id) = device;
  419. per_cpu(processors, pr->id) = pr;
  420. sysdev = get_cpu_sysdev(pr->id);
  421. if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) {
  422. result = -EFAULT;
  423. goto err_free_cpumask;
  424. }
  425. #ifdef CONFIG_CPU_FREQ
  426. acpi_processor_ppc_has_changed(pr, 0);
  427. #endif
  428. acpi_processor_get_throttling_info(pr);
  429. acpi_processor_get_limit_info(pr);
  430. if (cpuidle_get_driver() == &acpi_idle_driver)
  431. acpi_processor_power_init(pr, device);
  432. pr->cdev = thermal_cooling_device_register("Processor", device,
  433. &processor_cooling_ops);
  434. if (IS_ERR(pr->cdev)) {
  435. result = PTR_ERR(pr->cdev);
  436. goto err_power_exit;
  437. }
  438. dev_dbg(&device->dev, "registered as cooling_device%d\n",
  439. pr->cdev->id);
  440. result = sysfs_create_link(&device->dev.kobj,
  441. &pr->cdev->device.kobj,
  442. "thermal_cooling");
  443. if (result) {
  444. printk(KERN_ERR PREFIX "Create sysfs link\n");
  445. goto err_thermal_unregister;
  446. }
  447. result = sysfs_create_link(&pr->cdev->device.kobj,
  448. &device->dev.kobj,
  449. "device");
  450. if (result) {
  451. printk(KERN_ERR PREFIX "Create sysfs link\n");
  452. goto err_remove_sysfs;
  453. }
  454. return 0;
  455. err_remove_sysfs:
  456. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  457. err_thermal_unregister:
  458. thermal_cooling_device_unregister(pr->cdev);
  459. err_power_exit:
  460. acpi_processor_power_exit(pr, device);
  461. err_free_cpumask:
  462. free_cpumask_var(pr->throttling.shared_cpu_map);
  463. return result;
  464. }
  465. static int acpi_processor_remove(struct acpi_device *device, int type)
  466. {
  467. struct acpi_processor *pr = NULL;
  468. if (!device || !acpi_driver_data(device))
  469. return -EINVAL;
  470. pr = acpi_driver_data(device);
  471. if (pr->id >= nr_cpu_ids)
  472. goto free;
  473. if (type == ACPI_BUS_REMOVAL_EJECT) {
  474. if (acpi_processor_handle_eject(pr))
  475. return -EINVAL;
  476. }
  477. acpi_processor_power_exit(pr, device);
  478. sysfs_remove_link(&device->dev.kobj, "sysdev");
  479. if (pr->cdev) {
  480. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  481. sysfs_remove_link(&pr->cdev->device.kobj, "device");
  482. thermal_cooling_device_unregister(pr->cdev);
  483. pr->cdev = NULL;
  484. }
  485. per_cpu(processors, pr->id) = NULL;
  486. per_cpu(processor_device_array, pr->id) = NULL;
  487. free:
  488. free_cpumask_var(pr->throttling.shared_cpu_map);
  489. kfree(pr);
  490. return 0;
  491. }
  492. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  493. /****************************************************************************
  494. * Acpi processor hotplug support *
  495. ****************************************************************************/
  496. static int is_processor_present(acpi_handle handle)
  497. {
  498. acpi_status status;
  499. unsigned long long sta = 0;
  500. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  501. if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
  502. return 1;
  503. /*
  504. * _STA is mandatory for a processor that supports hot plug
  505. */
  506. if (status == AE_NOT_FOUND)
  507. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  508. "Processor does not support hot plug\n"));
  509. else
  510. ACPI_EXCEPTION((AE_INFO, status,
  511. "Processor Device is not present"));
  512. return 0;
  513. }
  514. static
  515. int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
  516. {
  517. acpi_handle phandle;
  518. struct acpi_device *pdev;
  519. if (acpi_get_parent(handle, &phandle)) {
  520. return -ENODEV;
  521. }
  522. if (acpi_bus_get_device(phandle, &pdev)) {
  523. return -ENODEV;
  524. }
  525. if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
  526. return -ENODEV;
  527. }
  528. return 0;
  529. }
  530. static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
  531. u32 event, void *data)
  532. {
  533. struct acpi_processor *pr;
  534. struct acpi_device *device = NULL;
  535. int result;
  536. switch (event) {
  537. case ACPI_NOTIFY_BUS_CHECK:
  538. case ACPI_NOTIFY_DEVICE_CHECK:
  539. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  540. "Processor driver received %s event\n",
  541. (event == ACPI_NOTIFY_BUS_CHECK) ?
  542. "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
  543. if (!is_processor_present(handle))
  544. break;
  545. if (acpi_bus_get_device(handle, &device)) {
  546. result = acpi_processor_device_add(handle, &device);
  547. if (result)
  548. printk(KERN_ERR PREFIX
  549. "Unable to add the device\n");
  550. break;
  551. }
  552. break;
  553. case ACPI_NOTIFY_EJECT_REQUEST:
  554. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  555. "received ACPI_NOTIFY_EJECT_REQUEST\n"));
  556. if (acpi_bus_get_device(handle, &device)) {
  557. printk(KERN_ERR PREFIX
  558. "Device don't exist, dropping EJECT\n");
  559. break;
  560. }
  561. pr = acpi_driver_data(device);
  562. if (!pr) {
  563. printk(KERN_ERR PREFIX
  564. "Driver data is NULL, dropping EJECT\n");
  565. return;
  566. }
  567. break;
  568. default:
  569. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  570. "Unsupported event [0x%x]\n", event));
  571. break;
  572. }
  573. return;
  574. }
  575. static acpi_status
  576. processor_walk_namespace_cb(acpi_handle handle,
  577. u32 lvl, void *context, void **rv)
  578. {
  579. acpi_status status;
  580. int *action = context;
  581. acpi_object_type type = 0;
  582. status = acpi_get_type(handle, &type);
  583. if (ACPI_FAILURE(status))
  584. return (AE_OK);
  585. if (type != ACPI_TYPE_PROCESSOR)
  586. return (AE_OK);
  587. switch (*action) {
  588. case INSTALL_NOTIFY_HANDLER:
  589. acpi_install_notify_handler(handle,
  590. ACPI_SYSTEM_NOTIFY,
  591. acpi_processor_hotplug_notify,
  592. NULL);
  593. break;
  594. case UNINSTALL_NOTIFY_HANDLER:
  595. acpi_remove_notify_handler(handle,
  596. ACPI_SYSTEM_NOTIFY,
  597. acpi_processor_hotplug_notify);
  598. break;
  599. default:
  600. break;
  601. }
  602. return (AE_OK);
  603. }
  604. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  605. {
  606. if (!is_processor_present(handle)) {
  607. return AE_ERROR;
  608. }
  609. if (acpi_map_lsapic(handle, p_cpu))
  610. return AE_ERROR;
  611. if (arch_register_cpu(*p_cpu)) {
  612. acpi_unmap_lsapic(*p_cpu);
  613. return AE_ERROR;
  614. }
  615. return AE_OK;
  616. }
  617. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  618. {
  619. if (cpu_online(pr->id))
  620. cpu_down(pr->id);
  621. arch_unregister_cpu(pr->id);
  622. acpi_unmap_lsapic(pr->id);
  623. return (0);
  624. }
  625. #else
  626. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  627. {
  628. return AE_ERROR;
  629. }
  630. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  631. {
  632. return (-EINVAL);
  633. }
  634. #endif
  635. static
  636. void acpi_processor_install_hotplug_notify(void)
  637. {
  638. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  639. int action = INSTALL_NOTIFY_HANDLER;
  640. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  641. ACPI_ROOT_OBJECT,
  642. ACPI_UINT32_MAX,
  643. processor_walk_namespace_cb, NULL, &action, NULL);
  644. #endif
  645. register_hotcpu_notifier(&acpi_cpu_notifier);
  646. }
  647. static
  648. void acpi_processor_uninstall_hotplug_notify(void)
  649. {
  650. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  651. int action = UNINSTALL_NOTIFY_HANDLER;
  652. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  653. ACPI_ROOT_OBJECT,
  654. ACPI_UINT32_MAX,
  655. processor_walk_namespace_cb, NULL, &action, NULL);
  656. #endif
  657. unregister_hotcpu_notifier(&acpi_cpu_notifier);
  658. }
  659. /*
  660. * We keep the driver loaded even when ACPI is not running.
  661. * This is needed for the powernow-k8 driver, that works even without
  662. * ACPI, but needs symbols from this driver
  663. */
  664. static int __init acpi_processor_init(void)
  665. {
  666. int result = 0;
  667. if (acpi_disabled)
  668. return 0;
  669. memset(&errata, 0, sizeof(errata));
  670. if (!cpuidle_register_driver(&acpi_idle_driver)) {
  671. printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
  672. acpi_idle_driver.name);
  673. } else {
  674. printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
  675. cpuidle_get_driver()->name);
  676. }
  677. result = acpi_bus_register_driver(&acpi_processor_driver);
  678. if (result < 0)
  679. goto out_cpuidle;
  680. acpi_processor_install_hotplug_notify();
  681. acpi_thermal_cpufreq_init();
  682. acpi_processor_ppc_init();
  683. acpi_processor_throttling_init();
  684. return 0;
  685. out_cpuidle:
  686. cpuidle_unregister_driver(&acpi_idle_driver);
  687. return result;
  688. }
  689. static void __exit acpi_processor_exit(void)
  690. {
  691. if (acpi_disabled)
  692. return;
  693. acpi_processor_ppc_exit();
  694. acpi_thermal_cpufreq_exit();
  695. acpi_processor_uninstall_hotplug_notify();
  696. acpi_bus_unregister_driver(&acpi_processor_driver);
  697. cpuidle_unregister_driver(&acpi_idle_driver);
  698. return;
  699. }
  700. module_init(acpi_processor_init);
  701. module_exit(acpi_processor_exit);
  702. MODULE_ALIAS("processor");