processor_driver.c 23 KB

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