processor_core.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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
  105. acpi_processor_errata_piix4 (
  106. struct pci_dev *dev)
  107. {
  108. u8 rev = 0;
  109. u8 value1 = 0;
  110. u8 value2 = 0;
  111. ACPI_FUNCTION_TRACE("acpi_processor_errata_piix4");
  112. if (!dev)
  113. return_VALUE(-EINVAL);
  114. /*
  115. * Note that 'dev' references the PIIX4 ACPI Controller.
  116. */
  117. pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
  118. switch (rev) {
  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 (rev) {
  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_VALUE(0);
  196. }
  197. int
  198. acpi_processor_errata (
  199. struct acpi_processor *pr)
  200. {
  201. int result = 0;
  202. struct pci_dev *dev = NULL;
  203. ACPI_FUNCTION_TRACE("acpi_processor_errata");
  204. if (!pr)
  205. return_VALUE(-EINVAL);
  206. /*
  207. * PIIX4
  208. */
  209. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  210. PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID, PCI_ANY_ID, NULL);
  211. if (dev) {
  212. result = acpi_processor_errata_piix4(dev);
  213. pci_dev_put(dev);
  214. }
  215. return_VALUE(result);
  216. }
  217. /* --------------------------------------------------------------------------
  218. FS Interface (/proc)
  219. -------------------------------------------------------------------------- */
  220. static struct proc_dir_entry *acpi_processor_dir = NULL;
  221. static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
  222. {
  223. struct acpi_processor *pr = (struct acpi_processor *)seq->private;
  224. ACPI_FUNCTION_TRACE("acpi_processor_info_seq_show");
  225. if (!pr)
  226. goto end;
  227. seq_printf(seq, "processor id: %d\n"
  228. "acpi id: %d\n"
  229. "bus mastering control: %s\n"
  230. "power management: %s\n"
  231. "throttling control: %s\n"
  232. "limit interface: %s\n",
  233. pr->id,
  234. pr->acpi_id,
  235. pr->flags.bm_control ? "yes" : "no",
  236. pr->flags.power ? "yes" : "no",
  237. pr->flags.throttling ? "yes" : "no",
  238. pr->flags.limit ? "yes" : "no");
  239. end:
  240. return_VALUE(0);
  241. }
  242. static int acpi_processor_info_open_fs(struct inode *inode, struct file *file)
  243. {
  244. return single_open(file, acpi_processor_info_seq_show,
  245. PDE(inode)->data);
  246. }
  247. static int
  248. acpi_processor_add_fs (
  249. struct acpi_device *device)
  250. {
  251. struct proc_dir_entry *entry = NULL;
  252. ACPI_FUNCTION_TRACE("acpi_processor_add_fs");
  253. if (!acpi_device_dir(device)) {
  254. acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
  255. acpi_processor_dir);
  256. if (!acpi_device_dir(device))
  257. return_VALUE(-ENODEV);
  258. }
  259. acpi_device_dir(device)->owner = THIS_MODULE;
  260. /* 'info' [R] */
  261. entry = create_proc_entry(ACPI_PROCESSOR_FILE_INFO,
  262. S_IRUGO, acpi_device_dir(device));
  263. if (!entry)
  264. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  265. "Unable to create '%s' fs entry\n",
  266. ACPI_PROCESSOR_FILE_INFO));
  267. else {
  268. entry->proc_fops = &acpi_processor_info_fops;
  269. entry->data = acpi_driver_data(device);
  270. entry->owner = THIS_MODULE;
  271. }
  272. /* 'throttling' [R/W] */
  273. entry = create_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
  274. S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
  275. if (!entry)
  276. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  277. "Unable to create '%s' fs entry\n",
  278. ACPI_PROCESSOR_FILE_THROTTLING));
  279. else {
  280. entry->proc_fops = &acpi_processor_throttling_fops;
  281. entry->proc_fops->write = acpi_processor_write_throttling;
  282. entry->data = acpi_driver_data(device);
  283. entry->owner = THIS_MODULE;
  284. }
  285. /* 'limit' [R/W] */
  286. entry = create_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,
  287. S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
  288. if (!entry)
  289. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  290. "Unable to create '%s' fs entry\n",
  291. ACPI_PROCESSOR_FILE_LIMIT));
  292. else {
  293. entry->proc_fops = &acpi_processor_limit_fops;
  294. entry->proc_fops->write = acpi_processor_write_limit;
  295. entry->data = acpi_driver_data(device);
  296. entry->owner = THIS_MODULE;
  297. }
  298. return_VALUE(0);
  299. }
  300. static int
  301. acpi_processor_remove_fs (
  302. struct acpi_device *device)
  303. {
  304. ACPI_FUNCTION_TRACE("acpi_processor_remove_fs");
  305. if (acpi_device_dir(device)) {
  306. remove_proc_entry(ACPI_PROCESSOR_FILE_INFO,acpi_device_dir(device));
  307. remove_proc_entry(ACPI_PROCESSOR_FILE_THROTTLING,
  308. acpi_device_dir(device));
  309. remove_proc_entry(ACPI_PROCESSOR_FILE_LIMIT,acpi_device_dir(device));
  310. remove_proc_entry(acpi_device_bid(device), acpi_processor_dir);
  311. acpi_device_dir(device) = NULL;
  312. }
  313. return_VALUE(0);
  314. }
  315. /* Use the acpiid in MADT to map cpus in case of SMP */
  316. #ifndef CONFIG_SMP
  317. #define convert_acpiid_to_cpu(acpi_id) (0xff)
  318. #else
  319. #ifdef CONFIG_IA64
  320. #define arch_acpiid_to_apicid ia64_acpiid_to_sapicid
  321. #define arch_cpu_to_apicid ia64_cpu_to_sapicid
  322. #define ARCH_BAD_APICID (0xffff)
  323. #else
  324. #define arch_acpiid_to_apicid x86_acpiid_to_apicid
  325. #define arch_cpu_to_apicid x86_cpu_to_apicid
  326. #define ARCH_BAD_APICID (0xff)
  327. #endif
  328. static u8 convert_acpiid_to_cpu(u8 acpi_id)
  329. {
  330. u16 apic_id;
  331. int i;
  332. apic_id = arch_acpiid_to_apicid[acpi_id];
  333. if (apic_id == ARCH_BAD_APICID)
  334. return -1;
  335. for (i = 0; i < NR_CPUS; i++) {
  336. if (arch_cpu_to_apicid[i] == apic_id)
  337. return i;
  338. }
  339. return -1;
  340. }
  341. #endif
  342. /* --------------------------------------------------------------------------
  343. Driver Interface
  344. -------------------------------------------------------------------------- */
  345. static int
  346. acpi_processor_get_info (
  347. struct acpi_processor *pr)
  348. {
  349. acpi_status status = 0;
  350. union acpi_object object = {0};
  351. struct acpi_buffer buffer = {sizeof(union acpi_object), &object};
  352. u8 cpu_index;
  353. static int cpu0_initialized;
  354. ACPI_FUNCTION_TRACE("acpi_processor_get_info");
  355. if (!pr)
  356. return_VALUE(-EINVAL);
  357. if (num_online_cpus() > 1)
  358. errata.smp = TRUE;
  359. acpi_processor_errata(pr);
  360. /*
  361. * Check to see if we have bus mastering arbitration control. This
  362. * is required for proper C3 usage (to maintain cache coherency).
  363. */
  364. if (acpi_fadt.V1_pm2_cnt_blk && acpi_fadt.pm2_cnt_len) {
  365. pr->flags.bm_control = 1;
  366. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  367. "Bus mastering arbitration control present\n"));
  368. }
  369. else
  370. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  371. "No bus mastering arbitration control\n"));
  372. /*
  373. * Evalute the processor object. Note that it is common on SMP to
  374. * have the first (boot) processor with a valid PBLK address while
  375. * all others have a NULL address.
  376. */
  377. status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
  378. if (ACPI_FAILURE(status)) {
  379. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  380. "Error evaluating processor object\n"));
  381. return_VALUE(-ENODEV);
  382. }
  383. /*
  384. * TBD: Synch processor ID (via LAPIC/LSAPIC structures) on SMP.
  385. * >>> 'acpi_get_processor_id(acpi_id, &id)' in arch/xxx/acpi.c
  386. */
  387. pr->acpi_id = object.processor.proc_id;
  388. cpu_index = convert_acpiid_to_cpu(pr->acpi_id);
  389. /* Handle UP system running SMP kernel, with no LAPIC in MADT */
  390. if ( !cpu0_initialized && (cpu_index == 0xff) &&
  391. (num_online_cpus() == 1)) {
  392. cpu_index = 0;
  393. }
  394. cpu0_initialized = 1;
  395. pr->id = cpu_index;
  396. /*
  397. * Extra Processor objects may be enumerated on MP systems with
  398. * less than the max # of CPUs. They should be ignored _iff
  399. * they are physically not present.
  400. */
  401. if (cpu_index >= NR_CPUS) {
  402. if (ACPI_FAILURE(acpi_processor_hotadd_init(pr->handle, &pr->id))) {
  403. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  404. "Error getting cpuindex for acpiid 0x%x\n",
  405. pr->acpi_id));
  406. return_VALUE(-ENODEV);
  407. }
  408. }
  409. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
  410. pr->acpi_id));
  411. if (!object.processor.pblk_address)
  412. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
  413. else if (object.processor.pblk_length != 6)
  414. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid PBLK length [%d]\n",
  415. object.processor.pblk_length));
  416. else {
  417. pr->throttling.address = object.processor.pblk_address;
  418. pr->throttling.duty_offset = acpi_fadt.duty_offset;
  419. pr->throttling.duty_width = acpi_fadt.duty_width;
  420. pr->pblk = object.processor.pblk_address;
  421. /*
  422. * We don't care about error returns - we just try to mark
  423. * these reserved so that nobody else is confused into thinking
  424. * that this region might be unused..
  425. *
  426. * (In particular, allocating the IO range for Cardbus)
  427. */
  428. request_region(pr->throttling.address, 6, "ACPI CPU throttle");
  429. }
  430. #ifdef CONFIG_CPU_FREQ
  431. acpi_processor_ppc_has_changed(pr);
  432. #endif
  433. acpi_processor_get_throttling_info(pr);
  434. acpi_processor_get_limit_info(pr);
  435. return_VALUE(0);
  436. }
  437. static int
  438. acpi_processor_start(
  439. struct acpi_device *device)
  440. {
  441. int result = 0;
  442. acpi_status status = AE_OK;
  443. struct acpi_processor *pr;
  444. ACPI_FUNCTION_TRACE("acpi_processor_start");
  445. pr = acpi_driver_data(device);
  446. result = acpi_processor_get_info(pr);
  447. if (result) {
  448. /* Processor is physically not present */
  449. return_VALUE(0);
  450. }
  451. BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0));
  452. processors[pr->id] = pr;
  453. result = acpi_processor_add_fs(device);
  454. if (result)
  455. goto end;
  456. status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
  457. acpi_processor_notify, pr);
  458. if (ACPI_FAILURE(status)) {
  459. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  460. "Error installing device notify handler\n"));
  461. }
  462. acpi_processor_power_init(pr, device);
  463. if (pr->flags.throttling) {
  464. printk(KERN_INFO PREFIX "%s [%s] (supports",
  465. acpi_device_name(device), acpi_device_bid(device));
  466. printk(" %d throttling states", pr->throttling.state_count);
  467. printk(")\n");
  468. }
  469. end:
  470. return_VALUE(result);
  471. }
  472. static void
  473. acpi_processor_notify (
  474. acpi_handle handle,
  475. u32 event,
  476. void *data)
  477. {
  478. struct acpi_processor *pr = (struct acpi_processor *) data;
  479. struct acpi_device *device = NULL;
  480. ACPI_FUNCTION_TRACE("acpi_processor_notify");
  481. if (!pr)
  482. return_VOID;
  483. if (acpi_bus_get_device(pr->handle, &device))
  484. return_VOID;
  485. switch (event) {
  486. case ACPI_PROCESSOR_NOTIFY_PERFORMANCE:
  487. acpi_processor_ppc_has_changed(pr);
  488. acpi_bus_generate_event(device, event,
  489. pr->performance_platform_limit);
  490. break;
  491. case ACPI_PROCESSOR_NOTIFY_POWER:
  492. acpi_processor_cst_has_changed(pr);
  493. acpi_bus_generate_event(device, event, 0);
  494. break;
  495. default:
  496. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  497. "Unsupported event [0x%x]\n", event));
  498. break;
  499. }
  500. return_VOID;
  501. }
  502. static int
  503. acpi_processor_add (
  504. struct acpi_device *device)
  505. {
  506. struct acpi_processor *pr = NULL;
  507. ACPI_FUNCTION_TRACE("acpi_processor_add");
  508. if (!device)
  509. return_VALUE(-EINVAL);
  510. pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  511. if (!pr)
  512. return_VALUE(-ENOMEM);
  513. memset(pr, 0, sizeof(struct acpi_processor));
  514. pr->handle = device->handle;
  515. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  516. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  517. acpi_driver_data(device) = pr;
  518. return_VALUE(0);
  519. }
  520. static int
  521. acpi_processor_remove (
  522. struct acpi_device *device,
  523. int type)
  524. {
  525. acpi_status status = AE_OK;
  526. struct acpi_processor *pr = NULL;
  527. ACPI_FUNCTION_TRACE("acpi_processor_remove");
  528. if (!device || !acpi_driver_data(device))
  529. return_VALUE(-EINVAL);
  530. pr = (struct acpi_processor *) acpi_driver_data(device);
  531. if (pr->id >= NR_CPUS) {
  532. kfree(pr);
  533. return_VALUE(0);
  534. }
  535. if (type == ACPI_BUS_REMOVAL_EJECT) {
  536. if (acpi_processor_handle_eject(pr))
  537. return_VALUE(-EINVAL);
  538. }
  539. acpi_processor_power_exit(pr, device);
  540. status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY,
  541. acpi_processor_notify);
  542. if (ACPI_FAILURE(status)) {
  543. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  544. "Error removing notify handler\n"));
  545. }
  546. acpi_processor_remove_fs(device);
  547. processors[pr->id] = NULL;
  548. kfree(pr);
  549. return_VALUE(0);
  550. }
  551. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  552. /****************************************************************************
  553. * Acpi processor hotplug support *
  554. ****************************************************************************/
  555. static int is_processor_present(acpi_handle handle);
  556. static int
  557. is_processor_present(
  558. acpi_handle handle)
  559. {
  560. acpi_status status;
  561. unsigned long sta = 0;
  562. ACPI_FUNCTION_TRACE("is_processor_present");
  563. status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
  564. if (ACPI_FAILURE(status) || !(sta & ACPI_STA_PRESENT)) {
  565. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  566. "Processor Device is not present\n"));
  567. return_VALUE(0);
  568. }
  569. return_VALUE(1);
  570. }
  571. static
  572. int acpi_processor_device_add(
  573. acpi_handle handle,
  574. struct acpi_device **device)
  575. {
  576. acpi_handle phandle;
  577. struct acpi_device *pdev;
  578. struct acpi_processor *pr;
  579. ACPI_FUNCTION_TRACE("acpi_processor_device_add");
  580. if (acpi_get_parent(handle, &phandle)) {
  581. return_VALUE(-ENODEV);
  582. }
  583. if (acpi_bus_get_device(phandle, &pdev)) {
  584. return_VALUE(-ENODEV);
  585. }
  586. if (acpi_bus_add(device, pdev, handle, ACPI_BUS_TYPE_PROCESSOR)) {
  587. return_VALUE(-ENODEV);
  588. }
  589. acpi_bus_start(*device);
  590. pr = acpi_driver_data(*device);
  591. if (!pr)
  592. return_VALUE(-ENODEV);
  593. if ((pr->id >=0) && (pr->id < NR_CPUS)) {
  594. kobject_hotplug(&(*device)->kobj, KOBJ_ONLINE);
  595. }
  596. return_VALUE(0);
  597. }
  598. static void
  599. acpi_processor_hotplug_notify (
  600. acpi_handle handle,
  601. u32 event,
  602. void *data)
  603. {
  604. struct acpi_processor *pr;
  605. struct acpi_device *device = NULL;
  606. int result;
  607. ACPI_FUNCTION_TRACE("acpi_processor_hotplug_notify");
  608. switch (event) {
  609. case ACPI_NOTIFY_BUS_CHECK:
  610. case ACPI_NOTIFY_DEVICE_CHECK:
  611. printk("Processor driver received %s event\n",
  612. (event==ACPI_NOTIFY_BUS_CHECK)?
  613. "ACPI_NOTIFY_BUS_CHECK":"ACPI_NOTIFY_DEVICE_CHECK");
  614. if (!is_processor_present(handle))
  615. break;
  616. if (acpi_bus_get_device(handle, &device)) {
  617. result = acpi_processor_device_add(handle, &device);
  618. if (result)
  619. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  620. "Unable to add the device\n"));
  621. break;
  622. }
  623. pr = acpi_driver_data(device);
  624. if (!pr) {
  625. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  626. "Driver data is NULL\n"));
  627. break;
  628. }
  629. if (pr->id >= 0 && (pr->id < NR_CPUS)) {
  630. kobject_hotplug(&device->kobj, KOBJ_OFFLINE);
  631. break;
  632. }
  633. result = acpi_processor_start(device);
  634. if ((!result) && ((pr->id >=0) && (pr->id < NR_CPUS))) {
  635. kobject_hotplug(&device->kobj, KOBJ_ONLINE);
  636. } else {
  637. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  638. "Device [%s] failed to start\n",
  639. acpi_device_bid(device)));
  640. }
  641. break;
  642. case ACPI_NOTIFY_EJECT_REQUEST:
  643. ACPI_DEBUG_PRINT((ACPI_DB_INFO,"received ACPI_NOTIFY_EJECT_REQUEST\n"));
  644. if (acpi_bus_get_device(handle, &device)) {
  645. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"Device don't exist, dropping EJECT\n"));
  646. break;
  647. }
  648. pr = acpi_driver_data(device);
  649. if (!pr) {
  650. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,"Driver data is NULL, dropping EJECT\n"));
  651. return_VOID;
  652. }
  653. if ((pr->id < NR_CPUS) && (cpu_present(pr->id)))
  654. kobject_hotplug(&device->kobj, KOBJ_OFFLINE);
  655. break;
  656. default:
  657. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  658. "Unsupported event [0x%x]\n", event));
  659. break;
  660. }
  661. return_VOID;
  662. }
  663. static acpi_status
  664. processor_walk_namespace_cb(acpi_handle handle,
  665. u32 lvl,
  666. void *context,
  667. void **rv)
  668. {
  669. acpi_status status;
  670. int *action = context;
  671. acpi_object_type type = 0;
  672. status = acpi_get_type(handle, &type);
  673. if (ACPI_FAILURE(status))
  674. return(AE_OK);
  675. if (type != ACPI_TYPE_PROCESSOR)
  676. return(AE_OK);
  677. switch(*action) {
  678. case INSTALL_NOTIFY_HANDLER:
  679. acpi_install_notify_handler(handle,
  680. ACPI_SYSTEM_NOTIFY,
  681. acpi_processor_hotplug_notify,
  682. NULL);
  683. break;
  684. case UNINSTALL_NOTIFY_HANDLER:
  685. acpi_remove_notify_handler(handle,
  686. ACPI_SYSTEM_NOTIFY,
  687. acpi_processor_hotplug_notify);
  688. break;
  689. default:
  690. break;
  691. }
  692. return(AE_OK);
  693. }
  694. static acpi_status
  695. acpi_processor_hotadd_init(
  696. acpi_handle handle,
  697. int *p_cpu)
  698. {
  699. ACPI_FUNCTION_TRACE("acpi_processor_hotadd_init");
  700. if (!is_processor_present(handle)) {
  701. return_VALUE(AE_ERROR);
  702. }
  703. if (acpi_map_lsapic(handle, p_cpu))
  704. return_VALUE(AE_ERROR);
  705. if (arch_register_cpu(*p_cpu)) {
  706. acpi_unmap_lsapic(*p_cpu);
  707. return_VALUE(AE_ERROR);
  708. }
  709. return_VALUE(AE_OK);
  710. }
  711. static int
  712. acpi_processor_handle_eject(struct acpi_processor *pr)
  713. {
  714. if (cpu_online(pr->id)) {
  715. return(-EINVAL);
  716. }
  717. arch_unregister_cpu(pr->id);
  718. acpi_unmap_lsapic(pr->id);
  719. return(0);
  720. }
  721. #else
  722. static acpi_status
  723. acpi_processor_hotadd_init(
  724. acpi_handle handle,
  725. int *p_cpu)
  726. {
  727. return AE_ERROR;
  728. }
  729. static int
  730. acpi_processor_handle_eject(struct acpi_processor *pr)
  731. {
  732. return(-EINVAL);
  733. }
  734. #endif
  735. static
  736. void acpi_processor_install_hotplug_notify(void)
  737. {
  738. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  739. int action = INSTALL_NOTIFY_HANDLER;
  740. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  741. ACPI_ROOT_OBJECT,
  742. ACPI_UINT32_MAX,
  743. processor_walk_namespace_cb,
  744. &action, NULL);
  745. #endif
  746. }
  747. static
  748. void acpi_processor_uninstall_hotplug_notify(void)
  749. {
  750. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  751. int action = UNINSTALL_NOTIFY_HANDLER;
  752. acpi_walk_namespace(ACPI_TYPE_PROCESSOR,
  753. ACPI_ROOT_OBJECT,
  754. ACPI_UINT32_MAX,
  755. processor_walk_namespace_cb,
  756. &action, NULL);
  757. #endif
  758. }
  759. /*
  760. * We keep the driver loaded even when ACPI is not running.
  761. * This is needed for the powernow-k8 driver, that works even without
  762. * ACPI, but needs symbols from this driver
  763. */
  764. static int __init
  765. acpi_processor_init (void)
  766. {
  767. int result = 0;
  768. ACPI_FUNCTION_TRACE("acpi_processor_init");
  769. memset(&processors, 0, sizeof(processors));
  770. memset(&errata, 0, sizeof(errata));
  771. acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
  772. if (!acpi_processor_dir)
  773. return_VALUE(0);
  774. acpi_processor_dir->owner = THIS_MODULE;
  775. result = acpi_bus_register_driver(&acpi_processor_driver);
  776. if (result < 0) {
  777. remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
  778. return_VALUE(0);
  779. }
  780. acpi_processor_install_hotplug_notify();
  781. acpi_thermal_cpufreq_init();
  782. acpi_processor_ppc_init();
  783. return_VALUE(0);
  784. }
  785. static void __exit
  786. 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");