processor_driver.c 25 KB

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