processor_driver.c 23 KB

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