processor_core.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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_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, 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. u32 acpi_id, int *apic_id)
  368. {
  369. struct acpi_madt_local_sapic *lsapic =
  370. (struct acpi_madt_local_sapic *)entry;
  371. /* Only check enabled APICs*/
  372. if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
  373. /* First check against id */
  374. if (lsapic->processor_id == acpi_id) {
  375. *apic_id = (lsapic->id << 8) | lsapic->eid;
  376. return 1;
  377. /* Check against optional uid */
  378. } else if (entry->length >= 16 &&
  379. lsapic->uid == acpi_id) {
  380. *apic_id = lsapic->uid;
  381. return 1;
  382. }
  383. }
  384. return 0;
  385. }
  386. static int map_madt_entry(u32 acpi_id)
  387. {
  388. unsigned long madt_end, entry;
  389. int apic_id = -1;
  390. if (!madt)
  391. return apic_id;
  392. entry = (unsigned long)madt;
  393. madt_end = entry + madt->header.length;
  394. /* Parse all entries looking for a match. */
  395. entry += sizeof(struct acpi_table_madt);
  396. while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
  397. struct acpi_subtable_header *header =
  398. (struct acpi_subtable_header *)entry;
  399. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  400. if (map_lapic_id(header, acpi_id, &apic_id))
  401. break;
  402. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  403. if (map_lsapic_id(header, acpi_id, &apic_id))
  404. break;
  405. }
  406. entry += header->length;
  407. }
  408. return apic_id;
  409. }
  410. static int map_mat_entry(acpi_handle handle, u32 acpi_id)
  411. {
  412. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  413. union acpi_object *obj;
  414. struct acpi_subtable_header *header;
  415. int apic_id = -1;
  416. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  417. goto exit;
  418. if (!buffer.length || !buffer.pointer)
  419. goto exit;
  420. obj = buffer.pointer;
  421. if (obj->type != ACPI_TYPE_BUFFER ||
  422. obj->buffer.length < sizeof(struct acpi_subtable_header)) {
  423. goto exit;
  424. }
  425. header = (struct acpi_subtable_header *)obj->buffer.pointer;
  426. if (header->type == ACPI_MADT_TYPE_LOCAL_APIC) {
  427. map_lapic_id(header, acpi_id, &apic_id);
  428. } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
  429. map_lsapic_id(header, acpi_id, &apic_id);
  430. }
  431. exit:
  432. if (buffer.pointer)
  433. kfree(buffer.pointer);
  434. return apic_id;
  435. }
  436. static int get_cpu_id(acpi_handle handle, u32 acpi_id)
  437. {
  438. int i;
  439. int apic_id = -1;
  440. apic_id = map_mat_entry(handle, acpi_id);
  441. if (apic_id == -1)
  442. apic_id = map_madt_entry(acpi_id);
  443. if (apic_id == -1)
  444. return apic_id;
  445. for_each_possible_cpu(i) {
  446. if (cpu_physical_id(i) == apic_id)
  447. return i;
  448. }
  449. return -1;
  450. }
  451. #endif
  452. /* --------------------------------------------------------------------------
  453. Driver Interface
  454. -------------------------------------------------------------------------- */
  455. static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
  456. {
  457. acpi_status status = 0;
  458. union acpi_object object = { 0 };
  459. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  460. int cpu_index;
  461. static int cpu0_initialized;
  462. if (!pr)
  463. return -EINVAL;
  464. if (num_online_cpus() > 1)
  465. errata.smp = TRUE;
  466. acpi_processor_errata(pr);
  467. /*
  468. * Check to see if we have bus mastering arbitration control. This
  469. * is required for proper C3 usage (to maintain cache coherency).
  470. */
  471. if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
  472. pr->flags.bm_control = 1;
  473. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  474. "Bus mastering arbitration control present\n"));
  475. } else
  476. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  477. "No bus mastering arbitration control\n"));
  478. /* Check if it is a Device with HID and UID */
  479. if (has_uid) {
  480. unsigned long value;
  481. status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
  482. NULL, &value);
  483. if (ACPI_FAILURE(status)) {
  484. printk(KERN_ERR PREFIX "Evaluating processor _UID\n");
  485. return -ENODEV;
  486. }
  487. pr->acpi_id = value;
  488. } else {
  489. /*
  490. * Evalute the processor object. Note that it is common on SMP to
  491. * have the first (boot) processor with a valid PBLK address while
  492. * all others have a NULL address.
  493. */
  494. status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
  495. if (ACPI_FAILURE(status)) {
  496. printk(KERN_ERR PREFIX "Evaluating processor object\n");
  497. return -ENODEV;
  498. }
  499. /*
  500. * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
  501. * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
  502. */
  503. pr->acpi_id = object.processor.proc_id;
  504. }
  505. cpu_index = get_cpu_id(pr->handle, pr->acpi_id);
  506. /* Handle UP system running SMP kernel, with no LAPIC in MADT */
  507. if (!cpu0_initialized && (cpu_index == -1) &&
  508. (num_online_cpus() == 1)) {
  509. cpu_index = 0;
  510. }
  511. cpu0_initialized = 1;
  512. pr->id = cpu_index;
  513. /*
  514. * Extra Processor objects may be enumerated on MP systems with
  515. * less than the max # of CPUs. They should be ignored _iff
  516. * they are physically not present.
  517. */
  518. if (pr->id == -1) {
  519. if (ACPI_FAILURE
  520. (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
  521. return -ENODEV;
  522. }
  523. }
  524. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
  525. pr->acpi_id));
  526. if (!object.processor.pblk_address)
  527. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
  528. else if (object.processor.pblk_length != 6)
  529. printk(KERN_ERR PREFIX "Invalid PBLK length [%d]\n",
  530. object.processor.pblk_length);
  531. else {
  532. pr->throttling.address = object.processor.pblk_address;
  533. pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
  534. pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
  535. pr->pblk = object.processor.pblk_address;
  536. /*
  537. * We don't care about error returns - we just try to mark
  538. * these reserved so that nobody else is confused into thinking
  539. * that this region might be unused..
  540. *
  541. * (In particular, allocating the IO range for Cardbus)
  542. */
  543. request_region(pr->throttling.address, 6, "ACPI CPU throttle");
  544. }
  545. /*
  546. * If ACPI describes a slot number for this CPU, we can use it
  547. * ensure we get the right value in the "physical id" field
  548. * of /proc/cpuinfo
  549. */
  550. status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
  551. if (ACPI_SUCCESS(status))
  552. arch_fix_phys_package_id(pr->id, object.integer.value);
  553. return 0;
  554. }
  555. static DEFINE_PER_CPU(void *, processor_device_array);
  556. static int __cpuinit acpi_processor_start(struct acpi_device *device)
  557. {
  558. int result = 0;
  559. acpi_status status = AE_OK;
  560. struct acpi_processor *pr;
  561. struct sys_device *sysdev;
  562. pr = acpi_driver_data(device);
  563. result = acpi_processor_get_info(pr, device->flags.unique_id);
  564. if (result) {
  565. /* Processor is physically not present */
  566. return 0;
  567. }
  568. BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
  569. /*
  570. * Buggy BIOS check
  571. * ACPI id of processors can be reported wrongly by the BIOS.
  572. * Don't trust it blindly
  573. */
  574. if (per_cpu(processor_device_array, pr->id) != NULL &&
  575. per_cpu(processor_device_array, pr->id) != device) {
  576. printk(KERN_WARNING "BIOS reported wrong ACPI id "
  577. "for the processor\n");
  578. return -ENODEV;
  579. }
  580. per_cpu(processor_device_array, pr->id) = device;
  581. per_cpu(processors, pr->id) = pr;
  582. result = acpi_processor_add_fs(device);
  583. if (result)
  584. goto end;
  585. sysdev = get_cpu_sysdev(pr->id);
  586. if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev"))
  587. return -EFAULT;
  588. status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
  589. acpi_processor_notify, pr);
  590. /* _PDC call should be done before doing anything else (if reqd.). */
  591. arch_acpi_processor_init_pdc(pr);
  592. acpi_processor_set_pdc(pr);
  593. #ifdef CONFIG_CPU_FREQ
  594. acpi_processor_ppc_has_changed(pr);
  595. #endif
  596. acpi_processor_get_throttling_info(pr);
  597. acpi_processor_get_limit_info(pr);
  598. acpi_processor_power_init(pr, device);
  599. pr->cdev = thermal_cooling_device_register("Processor", device,
  600. &processor_cooling_ops);
  601. if (IS_ERR(pr->cdev)) {
  602. result = PTR_ERR(pr->cdev);
  603. goto end;
  604. }
  605. dev_info(&device->dev, "registered as cooling_device%d\n",
  606. pr->cdev->id);
  607. result = sysfs_create_link(&device->dev.kobj,
  608. &pr->cdev->device.kobj,
  609. "thermal_cooling");
  610. if (result)
  611. printk(KERN_ERR PREFIX "Create sysfs link\n");
  612. result = sysfs_create_link(&pr->cdev->device.kobj,
  613. &device->dev.kobj,
  614. "device");
  615. if (result)
  616. printk(KERN_ERR PREFIX "Create sysfs link\n");
  617. if (pr->flags.throttling) {
  618. printk(KERN_INFO PREFIX "%s [%s] (supports",
  619. acpi_device_name(device), acpi_device_bid(device));
  620. printk(" %d throttling states", pr->throttling.state_count);
  621. printk(")\n");
  622. }
  623. end:
  624. return result;
  625. }
  626. static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
  627. {
  628. struct acpi_processor *pr = data;
  629. struct acpi_device *device = NULL;
  630. int saved;
  631. if (!pr)
  632. return;
  633. if (acpi_bus_get_device(pr->handle, &device))
  634. return;
  635. switch (event) {
  636. case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
  637. saved = pr->performance_platform_limit;
  638. acpi_processor_ppc_has_changed(pr);
  639. if (saved == pr->performance_platform_limit)
  640. break;
  641. acpi_bus_generate_proc_event(device, event,
  642. pr->performance_platform_limit);
  643. acpi_bus_generate_netlink_event(device->pnp.device_class,
  644. device->dev.bus_id, event,
  645. pr->performance_platform_limit);
  646. break;
  647. case ACPI_PROCESSOR_NOTIFY_POWER:
  648. acpi_processor_cst_has_changed(pr);
  649. acpi_bus_generate_proc_event(device, event, 0);
  650. acpi_bus_generate_netlink_event(device->pnp.device_class,
  651. device->dev.bus_id, event, 0);
  652. break;
  653. case ACPI_PROCESSOR_NOTIFY_THROTTLING:
  654. acpi_processor_tstate_has_changed(pr);
  655. acpi_bus_generate_proc_event(device, event, 0);
  656. acpi_bus_generate_netlink_event(device->pnp.device_class,
  657. device->dev.bus_id, event, 0);
  658. default:
  659. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  660. "Unsupported event [0x%x]\n", event));
  661. break;
  662. }
  663. return;
  664. }
  665. static int acpi_cpu_soft_notify(struct notifier_block *nfb,
  666. unsigned long action, void *hcpu)
  667. {
  668. unsigned int cpu = (unsigned long)hcpu;
  669. struct acpi_processor *pr = per_cpu(processors, cpu);
  670. if (action == CPU_ONLINE && pr) {
  671. acpi_processor_ppc_has_changed(pr);
  672. acpi_processor_cst_has_changed(pr);
  673. acpi_processor_tstate_has_changed(pr);
  674. }
  675. return NOTIFY_OK;
  676. }
  677. static struct notifier_block acpi_cpu_notifier =
  678. {
  679. .notifier_call = acpi_cpu_soft_notify,
  680. };
  681. static int acpi_processor_add(struct acpi_device *device)
  682. {
  683. struct acpi_processor *pr = NULL;
  684. if (!device)
  685. return -EINVAL;
  686. pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  687. if (!pr)
  688. return -ENOMEM;
  689. pr->handle = device->handle;
  690. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  691. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  692. acpi_driver_data(device) = pr;
  693. return 0;
  694. }
  695. static int acpi_processor_remove(struct acpi_device *device, int type)
  696. {
  697. acpi_status status = AE_OK;
  698. struct acpi_processor *pr = NULL;
  699. if (!device || !acpi_driver_data(device))
  700. return -EINVAL;
  701. pr = acpi_driver_data(device);
  702. if (pr->id >= nr_cpu_ids) {
  703. kfree(pr);
  704. return 0;
  705. }
  706. if (type == ACPI_BUS_REMOVAL_EJECT) {
  707. if (acpi_processor_handle_eject(pr))
  708. return -EINVAL;
  709. }
  710. acpi_processor_power_exit(pr, device);
  711. status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
  712. acpi_processor_notify);
  713. sysfs_remove_link(&device->dev.kobj, "sysdev");
  714. acpi_processor_remove_fs(device);
  715. if (pr->cdev) {
  716. sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
  717. sysfs_remove_link(&pr->cdev->device.kobj, "device");
  718. thermal_cooling_device_unregister(pr->cdev);
  719. pr->cdev = NULL;
  720. }
  721. per_cpu(processors, pr->id) = NULL;
  722. per_cpu(processor_device_array, pr->id) = NULL;
  723. kfree(pr);
  724. return 0;
  725. }
  726. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  727. /****************************************************************************
  728. * Acpi processor hotplug support *
  729. ****************************************************************************/
  730. static int is_processor_present(acpi_handle handle)
  731. {
  732. acpi_status status;
  733. unsigned long sta = 0;
  734. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  735. if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
  736. return 1;
  737. /*
  738. * _STA is mandatory for a processor that supports hot plug
  739. */
  740. if (status == AE_NOT_FOUND)
  741. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  742. "Processor does not support hot plug\n"));
  743. else
  744. ACPI_EXCEPTION((AE_INFO, status,
  745. "Processor Device is not present"));
  746. return 0;
  747. }
  748. static
  749. int acpi_processor_device_add(acpi_handle handle, struct acpi_device **device)
  750. {
  751. acpi_handle phandle;
  752. struct acpi_device *pdev;
  753. struct acpi_processor *pr;
  754. if (acpi_get_parent(handle, &phandle)) {
  755. return -ENODEV;
  756. }
  757. if (acpi_bus_get_device(phandle, &pdev)) {
  758. return -ENODEV;
  759. }
  760. if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
  761. return -ENODEV;
  762. }
  763. acpi_bus_start(*device);
  764. pr = acpi_driver_data(*device);
  765. if (!pr)
  766. return -ENODEV;
  767. if ((pr->id >= 0) && (pr->id < nr_cpu_ids)) {
  768. kobject_uevent(&(*device)->dev.kobj, KOBJ_ONLINE);
  769. }
  770. return 0;
  771. }
  772. static void __ref acpi_processor_hotplug_notify(acpi_handle handle,
  773. u32 event, void *data)
  774. {
  775. struct acpi_processor *pr;
  776. struct acpi_device *device = NULL;
  777. int result;
  778. switch (event) {
  779. case ACPI_NOTIFY_BUS_CHECK:
  780. case ACPI_NOTIFY_DEVICE_CHECK:
  781. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  782. "Processor driver received %s event\n",
  783. (event == ACPI_NOTIFY_BUS_CHECK) ?
  784. "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
  785. if (!is_processor_present(handle))
  786. break;
  787. if (acpi_bus_get_device(handle, &device)) {
  788. result = acpi_processor_device_add(handle, &device);
  789. if (result)
  790. printk(KERN_ERR PREFIX
  791. "Unable to add the device\n");
  792. break;
  793. }
  794. pr = acpi_driver_data(device);
  795. if (!pr) {
  796. printk(KERN_ERR PREFIX "Driver data is NULL\n");
  797. break;
  798. }
  799. if (pr->id >= 0 && (pr->id < nr_cpu_ids)) {
  800. kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
  801. break;
  802. }
  803. result = acpi_processor_start(device);
  804. if ((!result) && ((pr->id >= 0) && (pr->id < nr_cpu_ids))) {
  805. kobject_uevent(&device->dev.kobj, KOBJ_ONLINE);
  806. } else {
  807. printk(KERN_ERR PREFIX "Device [%s] failed to start\n",
  808. acpi_device_bid(device));
  809. }
  810. break;
  811. case ACPI_NOTIFY_EJECT_REQUEST:
  812. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  813. "received ACPI_NOTIFY_EJECT_REQUEST\n"));
  814. if (acpi_bus_get_device(handle, &device)) {
  815. printk(KERN_ERR PREFIX
  816. "Device don't exist, dropping EJECT\n");
  817. break;
  818. }
  819. pr = acpi_driver_data(device);
  820. if (!pr) {
  821. printk(KERN_ERR PREFIX
  822. "Driver data is NULL, dropping EJECT\n");
  823. return;
  824. }
  825. if ((pr->id < nr_cpu_ids) && (cpu_present(pr->id)))
  826. kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE);
  827. break;
  828. default:
  829. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  830. "Unsupported event [0x%x]\n", event));
  831. break;
  832. }
  833. return;
  834. }
  835. static acpi_status
  836. processor_walk_namespace_cb(acpi_handle handle,
  837. u32 lvl, void *context, void **rv)
  838. {
  839. acpi_status status;
  840. int *action = context;
  841. acpi_object_type type = 0;
  842. status = acpi_get_type(handle, &type);
  843. if (ACPI_FAILURE(status))
  844. return (AE_OK);
  845. if (type != ACPI_TYPE_PROCESSOR)
  846. return (AE_OK);
  847. switch (*action) {
  848. case INSTALL_NOTIFY_HANDLER:
  849. acpi_install_notify_handler(handle,
  850. ACPI_SYSTEM_NOTIFY,
  851. acpi_processor_hotplug_notify,
  852. NULL);
  853. break;
  854. case UNINSTALL_NOTIFY_HANDLER:
  855. acpi_remove_notify_handler(handle,
  856. ACPI_SYSTEM_NOTIFY,
  857. acpi_processor_hotplug_notify);
  858. break;
  859. default:
  860. break;
  861. }
  862. return (AE_OK);
  863. }
  864. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  865. {
  866. if (!is_processor_present(handle)) {
  867. return AE_ERROR;
  868. }
  869. if (acpi_map_lsapic(handle, p_cpu))
  870. return AE_ERROR;
  871. if (arch_register_cpu(*p_cpu)) {
  872. acpi_unmap_lsapic(*p_cpu);
  873. return AE_ERROR;
  874. }
  875. return AE_OK;
  876. }
  877. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  878. {
  879. if (cpu_online(pr->id))
  880. cpu_down(pr->id);
  881. arch_unregister_cpu(pr->id);
  882. acpi_unmap_lsapic(pr->id);
  883. return (0);
  884. }
  885. #else
  886. static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu)
  887. {
  888. return AE_ERROR;
  889. }
  890. static int acpi_processor_handle_eject(struct acpi_processor *pr)
  891. {
  892. return (-EINVAL);
  893. }
  894. #endif
  895. static
  896. void acpi_processor_install_hotplug_notify(void)
  897. {
  898. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  899. int action = INSTALL_NOTIFY_HANDLER;
  900. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  901. ACPI_ROOT_OBJECT,
  902. ACPI_UINT32_MAX,
  903. processor_walk_namespace_cb, &action, NULL);
  904. #endif
  905. register_hotcpu_notifier(&acpi_cpu_notifier);
  906. }
  907. static
  908. void acpi_processor_uninstall_hotplug_notify(void)
  909. {
  910. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  911. int action = UNINSTALL_NOTIFY_HANDLER;
  912. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  913. ACPI_ROOT_OBJECT,
  914. ACPI_UINT32_MAX,
  915. processor_walk_namespace_cb, &action, NULL);
  916. #endif
  917. unregister_hotcpu_notifier(&acpi_cpu_notifier);
  918. }
  919. /*
  920. * We keep the driver loaded even when ACPI is not running.
  921. * This is needed for the powernow-k8 driver, that works even without
  922. * ACPI, but needs symbols from this driver
  923. */
  924. static int __init acpi_processor_init(void)
  925. {
  926. int result = 0;
  927. memset(&errata, 0, sizeof(errata));
  928. #ifdef CONFIG_SMP
  929. if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
  930. (struct acpi_table_header **)&madt)))
  931. madt = NULL;
  932. #endif
  933. acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
  934. if (!acpi_processor_dir)
  935. return -ENOMEM;
  936. acpi_processor_dir->owner = THIS_MODULE;
  937. /*
  938. * Check whether the system is DMI table. If yes, OSPM
  939. * should not use mwait for CPU-states.
  940. */
  941. dmi_check_system(processor_idle_dmi_table);
  942. result = cpuidle_register_driver(&acpi_idle_driver);
  943. if (result < 0)
  944. goto out_proc;
  945. result = acpi_bus_register_driver(&acpi_processor_driver);
  946. if (result < 0)
  947. goto out_cpuidle;
  948. acpi_processor_install_hotplug_notify();
  949. acpi_thermal_cpufreq_init();
  950. acpi_processor_ppc_init();
  951. acpi_processor_throttling_init();
  952. return 0;
  953. out_cpuidle:
  954. cpuidle_unregister_driver(&acpi_idle_driver);
  955. out_proc:
  956. remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
  957. return result;
  958. }
  959. static void __exit acpi_processor_exit(void)
  960. {
  961. acpi_processor_ppc_exit();
  962. acpi_thermal_cpufreq_exit();
  963. acpi_processor_uninstall_hotplug_notify();
  964. acpi_bus_unregister_driver(&acpi_processor_driver);
  965. cpuidle_unregister_driver(&acpi_idle_driver);
  966. remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
  967. return;
  968. }
  969. module_init(acpi_processor_init);
  970. module_exit(acpi_processor_exit);
  971. EXPORT_SYMBOL(acpi_processor_set_thermal_limit);
  972. MODULE_ALIAS("processor");