processor_core.c 23 KB

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