processor_core.c 28 KB

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