processor_core.c 25 KB

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