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_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_OBJECT_HID, 0},
  82. {ACPI_PROCESSOR_HID, 0},
  83. {"", 0},
  84. };
  85. MODULE_DEVICE_TABLE(acpi, processor_device_ids);
  86. static struct acpi_driver acpi_processor_driver = {
  87. .name = "processor",
  88. .class = ACPI_PROCESSOR_CLASS,
  89. .ids = processor_device_ids,
  90. .ops = {
  91. .add = acpi_processor_add,
  92. .remove = acpi_processor_remove,
  93. .start = acpi_processor_start,
  94. .suspend = acpi_processor_suspend,
  95. .resume = acpi_processor_resume,
  96. },
  97. };
  98. #define INSTALL_NOTIFY_HANDLER 1
  99. #define UNINSTALL_NOTIFY_HANDLER 2
  100. static const struct file_operations acpi_processor_info_fops = {
  101. .owner = THIS_MODULE,
  102. .open = acpi_processor_info_open_fs,
  103. .read = seq_read,
  104. .llseek = seq_lseek,
  105. .release = single_release,
  106. };
  107. DEFINE_PER_CPU(struct acpi_processor *, processors);
  108. struct acpi_processor_errata errata __read_mostly;
  109. static int set_no_mwait(const struct dmi_system_id *id)
  110. {
  111. printk(KERN_NOTICE PREFIX "%s detected - "
  112. "disabling mwait for CPU C-states\n", id->ident);
  113. idle_nomwait = 1;
  114. return 0;
  115. }
  116. static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
  117. {
  118. set_no_mwait, "IFL91 board", {
  119. DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
  120. DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"),
  121. DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"),
  122. DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL},
  123. {
  124. set_no_mwait, "Extensa 5220", {
  125. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  126. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  127. DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
  128. DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
  129. {},
  130. };
  131. /* --------------------------------------------------------------------------
  132. Errata Handling
  133. -------------------------------------------------------------------------- */
  134. static int acpi_processor_errata_piix4(struct pci_dev *dev)
  135. {
  136. u8 value1 = 0;
  137. u8 value2 = 0;
  138. if (!dev)
  139. return -EINVAL;
  140. /*
  141. * Note that 'dev' references the PIIX4 ACPI Controller.
  142. */
  143. switch (dev->revision) {
  144. case 0:
  145. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
  146. break;
  147. case 1:
  148. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
  149. break;
  150. case 2:
  151. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
  152. break;
  153. case 3:
  154. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
  155. break;
  156. default:
  157. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
  158. break;
  159. }
  160. switch (dev->revision) {
  161. case 0: /* PIIX4 A-step */
  162. case 1: /* PIIX4 B-step */
  163. /*
  164. * See specification changes #13 ("Manual Throttle Duty Cycle")
  165. * and #14 ("Enabling and Disabling Manual Throttle"), plus
  166. * erratum #5 ("STPCLK# Deassertion Time") from the January
  167. * 2002 PIIX4 specification update. Applies to only older
  168. * PIIX4 models.
  169. */
  170. errata.piix4.throttle = 1;
  171. case 2: /* PIIX4E */
  172. case 3: /* PIIX4M */
  173. /*
  174. * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
  175. * Livelock") from the January 2002 PIIX4 specification update.
  176. * Applies to all PIIX4 models.
  177. */
  178. /*
  179. * BM-IDE
  180. * ------
  181. * Find the PIIX4 IDE Controller and get the Bus Master IDE
  182. * Status register address. We'll use this later to read
  183. * each IDE controller's DMA status to make sure we catch all
  184. * DMA activity.
  185. */
  186. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  187. PCI_DEVICE_ID_INTEL_82371AB,
  188. PCI_ANY_ID, PCI_ANY_ID, NULL);
  189. if (dev) {
  190. errata.piix4.bmisx = pci_resource_start(dev, 4);
  191. pci_dev_put(dev);
  192. }
  193. /*
  194. * Type-F DMA
  195. * ----------
  196. * Find the PIIX4 ISA Controller and read the Motherboard
  197. * DMA controller's status to see if Type-F (Fast) DMA mode
  198. * is enabled (bit 7) on either channel. Note that we'll
  199. * disable C3 support if this is enabled, as some legacy
  200. * devices won't operate well if fast DMA is disabled.
  201. */
  202. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  203. PCI_DEVICE_ID_INTEL_82371AB_0,
  204. PCI_ANY_ID, PCI_ANY_ID, NULL);
  205. if (dev) {
  206. pci_read_config_byte(dev, 0x76, &value1);
  207. pci_read_config_byte(dev, 0x77, &value2);
  208. if ((value1 & 0x80) || (value2 & 0x80))
  209. errata.piix4.fdma = 1;
  210. pci_dev_put(dev);
  211. }
  212. break;
  213. }
  214. if (errata.piix4.bmisx)
  215. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  216. "Bus master activity detection (BM-IDE) erratum enabled\n"));
  217. if (errata.piix4.fdma)
  218. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  219. "Type-F DMA livelock erratum (C3 disabled)\n"));
  220. return 0;
  221. }
  222. static int acpi_processor_errata(struct acpi_processor *pr)
  223. {
  224. int result = 0;
  225. struct pci_dev *dev = NULL;
  226. if (!pr)
  227. return -EINVAL;
  228. /*
  229. * PIIX4
  230. */
  231. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  232. PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
  233. PCI_ANY_ID, NULL);
  234. if (dev) {
  235. result = acpi_processor_errata_piix4(dev);
  236. pci_dev_put(dev);
  237. }
  238. return result;
  239. }
  240. /* --------------------------------------------------------------------------
  241. Common ACPI processor functions
  242. -------------------------------------------------------------------------- */
  243. /*
  244. * _PDC is required for a BIOS-OS handshake for most of the newer
  245. * ACPI processor features.
  246. */
  247. static int acpi_processor_set_pdc(struct acpi_processor *pr)
  248. {
  249. struct acpi_object_list *pdc_in = pr->pdc;
  250. acpi_status status = AE_OK;
  251. if (!pdc_in)
  252. return status;
  253. if (idle_nomwait) {
  254. /*
  255. * If mwait is disabled for CPU C-states, the C2C3_FFH access
  256. * mode will be disabled in the parameter of _PDC object.
  257. * Of course C1_FFH access mode will also be disabled.
  258. */
  259. union acpi_object *obj;
  260. u32 *buffer = NULL;
  261. obj = pdc_in->pointer;
  262. buffer = (u32 *)(obj->buffer.pointer);
  263. buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
  264. }
  265. status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL);
  266. if (ACPI_FAILURE(status))
  267. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  268. "Could not evaluate _PDC, using legacy perf. control...\n"));
  269. return status;
  270. }
  271. /* --------------------------------------------------------------------------
  272. FS Interface (/proc)
  273. -------------------------------------------------------------------------- */
  274. static struct proc_dir_entry *acpi_processor_dir = NULL;
  275. static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
  276. {
  277. struct acpi_processor *pr = seq->private;
  278. if (!pr)
  279. goto end;
  280. seq_printf(seq, "processor id: %d\n"
  281. "acpi id: %d\n"
  282. "bus mastering control: %s\n"
  283. "power management: %s\n"
  284. "throttling control: %s\n"
  285. "limit interface: %s\n",
  286. pr->id,
  287. pr->acpi_id,
  288. pr->flags.bm_control ? "yes" : "no",
  289. pr->flags.power ? "yes" : "no",
  290. pr->flags.throttling ? "yes" : "no",
  291. pr->flags.limit ? "yes" : "no");
  292. end:
  293. return 0;
  294. }
  295. static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
  296. {
  297. return single_open(file, acpi_processor_info_seq_show,
  298. PDE(inode)->data);
  299. }
  300. static int acpi_processor_add_fs(struct acpi_device *device)
  301. {
  302. struct proc_dir_entry *entry = NULL;
  303. if (!acpi_device_dir(device)) {
  304. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  305. acpi_processor_dir);
  306. if (!acpi_device_dir(device))
  307. return -ENODEV;
  308. }
  309. acpi_device_dir(device)->owner = THIS_MODULE;
  310. /* 'info' [R] */
  311. entry = proc_create_data(ACPI_PROCESSOR_FILE_INFO,
  312. S_IRUGO, acpi_device_dir(device),
  313. &acpi_processor_info_fops,
  314. acpi_driver_data(device));
  315. if (!entry)
  316. return -EIO;
  317. /* 'throttling' [R/W] */
  318. entry = proc_create_data(ACPI_PROCESSOR_FILE_THROTTLING,
  319. S_IFREG | S_IRUGO | S_IWUSR,
  320. acpi_device_dir(device),
  321. &acpi_processor_throttling_fops,
  322. acpi_driver_data(device));
  323. if (!entry)
  324. return -EIO;
  325. /* 'limit' [R/W] */
  326. entry = proc_create_data(ACPI_PROCESSOR_FILE_LIMIT,
  327. S_IFREG | S_IRUGO | S_IWUSR,
  328. acpi_device_dir(device),
  329. &acpi_processor_limit_fops,
  330. acpi_driver_data(device));
  331. if (!entry)
  332. return -EIO;
  333. return 0;
  334. }
  335. static int acpi_processor_remove_fs(struct acpi_device *device)
  336. {
  337. if (acpi_device_dir(device)) {
  338. remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,
  339. acpi_device_dir(device));
  340. remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
  341. acpi_device_dir(device));
  342. remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
  343. acpi_device_dir(device));
  344. remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
  345. acpi_device_dir(device) = NULL;
  346. }
  347. return 0;
  348. }
  349. /* Use the acpiid in MADT to map cpus in case of SMP */
  350. #ifndef CONFIG_SMP
  351. static int get_cpu_id(acpi_handle handle, int type, u32 acpi_id) { return -1; }
  352. #else
  353. static struct acpi_table_madt *madt;
  354. static int map_lapic_id(struct acpi_subtable_header *entry,
  355. u32 acpi_id, int *apic_id)
  356. {
  357. struct acpi_madt_local_apic *lapic =
  358. (struct acpi_madt_local_apic *)entry;
  359. if ((lapic->lapic_flags & ACPI_MADT_ENABLED) &&
  360. lapic->processor_id == acpi_id) {
  361. *apic_id = lapic->id;
  362. return 1;
  363. }
  364. return 0;
  365. }
  366. static int map_lsapic_id(struct acpi_subtable_header *entry,
  367. int device_declaration, u32 acpi_id, int *apic_id)
  368. {
  369. struct acpi_madt_local_sapic *lsapic =
  370. (struct acpi_madt_local_sapic *)entry;
  371. u32 tmp = (lsapic->id << 8) | lsapic->eid;
  372. /* Only check enabled APICs*/
  373. if (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))
  374. return 0;
  375. /* Device statement declaration type */
  376. if (device_declaration) {
  377. if (entry->length < 16)
  378. printk(KERN_ERR PREFIX
  379. "Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n",
  380. tmp);
  381. else if (lsapic->uid == acpi_id)
  382. goto found;
  383. /* Processor statement declaration type */
  384. } else if (lsapic->processor_id == acpi_id)
  385. goto found;
  386. return 0;
  387. found:
  388. *apic_id = tmp;
  389. return 1;
  390. }
  391. static int map_madt_entry(int type, u32 acpi_id)
  392. {
  393. unsigned long madt_end, entry;
  394. int apic_id = -1;
  395. if (!madt)
  396. return apic_id;
  397. entry = (unsigned long)madt;
  398. madt_end = entry + madt->header.length;
  399. /* Parse all entries looking for a match. */
  400. entry += sizeof(struct acpi_table_madt);
  401. while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
  402. struct acpi_subtable_header *header =
  403. (struct acpi_subtable_header *)entry;
  404. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  405. if (map_lapic_id(header, acpi_id, &apic_id))
  406. break;
  407. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  408. if (map_lsapic_id(header, type, acpi_id, &apic_id))
  409. break;
  410. }
  411. entry += header->length;
  412. }
  413. return apic_id;
  414. }
  415. static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
  416. {
  417. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  418. union acpi_object *obj;
  419. struct acpi_subtable_header *header;
  420. int apic_id = -1;
  421. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  422. goto exit;
  423. if (!buffer.length || !buffer.pointer)
  424. goto exit;
  425. obj = buffer.pointer;
  426. if (obj->type != ACPI_TYPE_BUFFER ||
  427. obj->buffer.length < sizeof(struct acpi_subtable_header)) {
  428. goto exit;
  429. }
  430. header = (struct acpi_subtable_header *)obj->buffer.pointer;
  431. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  432. map_lapic_id(header, acpi_id, &apic_id);
  433. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  434. map_lsapic_id(header, type, acpi_id, &apic_id);
  435. }
  436. exit:
  437. if (buffer.pointer)
  438. kfree(buffer.pointer);
  439. return apic_id;
  440. }
  441. static int get_cpu_id(acpi_handle handle, int type, u32 acpi_id)
  442. {
  443. int i;
  444. int apic_id = -1;
  445. apic_id = map_mat_entry(handle, type, acpi_id);
  446. if (apic_id == -1)
  447. apic_id = map_madt_entry(type, acpi_id);
  448. if (apic_id == -1)
  449. return apic_id;
  450. for_each_possible_cpu(i) {
  451. if (cpu_physical_id(i) == apic_id)
  452. return i;
  453. }
  454. return -1;
  455. }
  456. #endif
  457. /* --------------------------------------------------------------------------
  458. Driver Interface
  459. -------------------------------------------------------------------------- */
  460. static int acpi_processor_get_info(struct acpi_device *device)
  461. {
  462. acpi_status status = 0;
  463. union acpi_object object = { 0 };
  464. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  465. struct acpi_processor *pr;
  466. int cpu_index, device_declaration = 0;
  467. static int cpu0_initialized;
  468. pr = acpi_driver_data(device);
  469. if (!pr)
  470. return -EINVAL;
  471. if (num_online_cpus() > 1)
  472. errata.smp = TRUE;
  473. acpi_processor_errata(pr);
  474. /*
  475. * Check to see if we have bus mastering arbitration control. This
  476. * is required for proper C3 usage (to maintain cache coherency).
  477. */
  478. if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
  479. pr->flags.bm_control = 1;
  480. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  481. "Bus mastering arbitration control present\n"));
  482. } else
  483. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  484. "No bus mastering arbitration control\n"));
  485. if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_HID)) {
  486. /*
  487. * Declared with "Device" statement; match _UID.
  488. * Note that we don't handle string _UIDs yet.
  489. */
  490. unsigned long long value;
  491. status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
  492. NULL, &value);
  493. if (ACPI_FAILURE(status)) {
  494. printk(KERN_ERR PREFIX
  495. "Evaluating processor _UID [%#x]\n", status);
  496. return -ENODEV;
  497. }
  498. device_declaration = 1;
  499. pr->acpi_id = value;
  500. } else {
  501. /* Declared with "Processor" statement; match ProcessorID */
  502. status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
  503. if (ACPI_FAILURE(status)) {
  504. printk(KERN_ERR PREFIX "Evaluating processor object\n");
  505. return -ENODEV;
  506. }
  507. /*
  508. * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
  509. * >>> 'acpi_get_processor_id(acpi_id, &id)' in
  510. * 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. dev_name(&device->dev), 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. dev_name(&device->dev), 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. dev_name(&device->dev), 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");