processor_core.c 28 KB

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