processor_core.c 26 KB

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