processor_core.c 30 KB

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