processor_core.c 30 KB

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