processor_driver.c 25 KB

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