processor_core.c 30 KB

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