processor_core.c 29 KB

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