processor_core.c 25 KB

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