acpi_processor.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * acpi_processor.c - ACPI processor enumeration support
  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. * Copyright (C) 2013, Intel Corporation
  9. * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2 as published
  13. * by the Free Software Foundation.
  14. */
  15. #include <linux/acpi.h>
  16. #include <linux/device.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/pci.h>
  20. #include <acpi/processor.h>
  21. #include <asm/cpu.h>
  22. #include "internal.h"
  23. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  24. ACPI_MODULE_NAME("processor");
  25. DEFINE_PER_CPU(struct acpi_processor *, processors);
  26. EXPORT_PER_CPU_SYMBOL(processors);
  27. /* --------------------------------------------------------------------------
  28. Errata Handling
  29. -------------------------------------------------------------------------- */
  30. struct acpi_processor_errata errata __read_mostly;
  31. EXPORT_SYMBOL_GPL(errata);
  32. static int acpi_processor_errata_piix4(struct pci_dev *dev)
  33. {
  34. u8 value1 = 0;
  35. u8 value2 = 0;
  36. if (!dev)
  37. return -EINVAL;
  38. /*
  39. * Note that 'dev' references the PIIX4 ACPI Controller.
  40. */
  41. switch (dev->revision) {
  42. case 0:
  43. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 A-step\n"));
  44. break;
  45. case 1:
  46. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4 B-step\n"));
  47. break;
  48. case 2:
  49. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4E\n"));
  50. break;
  51. case 3:
  52. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found PIIX4M\n"));
  53. break;
  54. default:
  55. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found unknown PIIX4\n"));
  56. break;
  57. }
  58. switch (dev->revision) {
  59. case 0: /* PIIX4 A-step */
  60. case 1: /* PIIX4 B-step */
  61. /*
  62. * See specification changes #13 ("Manual Throttle Duty Cycle")
  63. * and #14 ("Enabling and Disabling Manual Throttle"), plus
  64. * erratum #5 ("STPCLK# Deassertion Time") from the January
  65. * 2002 PIIX4 specification update. Applies to only older
  66. * PIIX4 models.
  67. */
  68. errata.piix4.throttle = 1;
  69. /* fall through*/
  70. case 2: /* PIIX4E */
  71. case 3: /* PIIX4M */
  72. /*
  73. * See erratum #18 ("C3 Power State/BMIDE and Type-F DMA
  74. * Livelock") from the January 2002 PIIX4 specification update.
  75. * Applies to all PIIX4 models.
  76. */
  77. /*
  78. * BM-IDE
  79. * ------
  80. * Find the PIIX4 IDE Controller and get the Bus Master IDE
  81. * Status register address. We'll use this later to read
  82. * each IDE controller's DMA status to make sure we catch all
  83. * DMA activity.
  84. */
  85. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  86. PCI_DEVICE_ID_INTEL_82371AB,
  87. PCI_ANY_ID, PCI_ANY_ID, NULL);
  88. if (dev) {
  89. errata.piix4.bmisx = pci_resource_start(dev, 4);
  90. pci_dev_put(dev);
  91. }
  92. /*
  93. * Type-F DMA
  94. * ----------
  95. * Find the PIIX4 ISA Controller and read the Motherboard
  96. * DMA controller's status to see if Type-F (Fast) DMA mode
  97. * is enabled (bit 7) on either channel. Note that we'll
  98. * disable C3 support if this is enabled, as some legacy
  99. * devices won't operate well if fast DMA is disabled.
  100. */
  101. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  102. PCI_DEVICE_ID_INTEL_82371AB_0,
  103. PCI_ANY_ID, PCI_ANY_ID, NULL);
  104. if (dev) {
  105. pci_read_config_byte(dev, 0x76, &value1);
  106. pci_read_config_byte(dev, 0x77, &value2);
  107. if ((value1 & 0x80) || (value2 & 0x80))
  108. errata.piix4.fdma = 1;
  109. pci_dev_put(dev);
  110. }
  111. break;
  112. }
  113. if (errata.piix4.bmisx)
  114. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  115. "Bus master activity detection (BM-IDE) erratum enabled\n"));
  116. if (errata.piix4.fdma)
  117. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  118. "Type-F DMA livelock erratum (C3 disabled)\n"));
  119. return 0;
  120. }
  121. static int acpi_processor_errata(void)
  122. {
  123. int result = 0;
  124. struct pci_dev *dev = NULL;
  125. /*
  126. * PIIX4
  127. */
  128. dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
  129. PCI_DEVICE_ID_INTEL_82371AB_3, PCI_ANY_ID,
  130. PCI_ANY_ID, NULL);
  131. if (dev) {
  132. result = acpi_processor_errata_piix4(dev);
  133. pci_dev_put(dev);
  134. }
  135. return result;
  136. }
  137. /* --------------------------------------------------------------------------
  138. Initialization
  139. -------------------------------------------------------------------------- */
  140. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  141. int __weak acpi_map_cpu(acpi_handle handle,
  142. phys_cpuid_t physid, u32 acpi_id, int *pcpu)
  143. {
  144. return -ENODEV;
  145. }
  146. int __weak acpi_unmap_cpu(int cpu)
  147. {
  148. return -ENODEV;
  149. }
  150. int __weak arch_register_cpu(int cpu)
  151. {
  152. return -ENODEV;
  153. }
  154. void __weak arch_unregister_cpu(int cpu) {}
  155. static int acpi_processor_hotadd_init(struct acpi_processor *pr)
  156. {
  157. unsigned long long sta;
  158. acpi_status status;
  159. int ret;
  160. if (invalid_phys_cpuid(pr->phys_id))
  161. return -ENODEV;
  162. status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
  163. if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
  164. return -ENODEV;
  165. cpu_maps_update_begin();
  166. cpu_hotplug_begin();
  167. ret = acpi_map_cpu(pr->handle, pr->phys_id, pr->acpi_id, &pr->id);
  168. if (ret)
  169. goto out;
  170. ret = arch_register_cpu(pr->id);
  171. if (ret) {
  172. acpi_unmap_cpu(pr->id);
  173. goto out;
  174. }
  175. /*
  176. * CPU got hot-added, but cpu_data is not initialized yet. Set a flag
  177. * to delay cpu_idle/throttling initialization and do it when the CPU
  178. * gets online for the first time.
  179. */
  180. pr_info("CPU%d has been hot-added\n", pr->id);
  181. pr->flags.need_hotplug_init = 1;
  182. out:
  183. cpu_hotplug_done();
  184. cpu_maps_update_done();
  185. return ret;
  186. }
  187. #else
  188. static inline int acpi_processor_hotadd_init(struct acpi_processor *pr)
  189. {
  190. return -ENODEV;
  191. }
  192. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  193. static int acpi_processor_get_info(struct acpi_device *device)
  194. {
  195. union acpi_object object = { 0 };
  196. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  197. struct acpi_processor *pr = acpi_driver_data(device);
  198. int device_declaration = 0;
  199. acpi_status status = AE_OK;
  200. static int cpu0_initialized;
  201. unsigned long long value;
  202. acpi_processor_errata();
  203. /*
  204. * Check to see if we have bus mastering arbitration control. This
  205. * is required for proper C3 usage (to maintain cache coherency).
  206. */
  207. if (acpi_gbl_FADT.pm2_control_block && acpi_gbl_FADT.pm2_control_length) {
  208. pr->flags.bm_control = 1;
  209. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  210. "Bus mastering arbitration control present\n"));
  211. } else
  212. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  213. "No bus mastering arbitration control\n"));
  214. if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
  215. /* Declared with "Processor" statement; match ProcessorID */
  216. status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
  217. if (ACPI_FAILURE(status)) {
  218. dev_err(&device->dev,
  219. "Failed to evaluate processor object (0x%x)\n",
  220. status);
  221. return -ENODEV;
  222. }
  223. pr->acpi_id = object.processor.proc_id;
  224. } else {
  225. /*
  226. * Declared with "Device" statement; match _UID.
  227. * Note that we don't handle string _UIDs yet.
  228. */
  229. status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
  230. NULL, &value);
  231. if (ACPI_FAILURE(status)) {
  232. dev_err(&device->dev,
  233. "Failed to evaluate processor _UID (0x%x)\n",
  234. status);
  235. return -ENODEV;
  236. }
  237. device_declaration = 1;
  238. pr->acpi_id = value;
  239. }
  240. if (acpi_duplicate_processor_id(pr->acpi_id)) {
  241. if (pr->acpi_id == 0xff)
  242. dev_info_once(&device->dev,
  243. "Entry not well-defined, consider updating BIOS\n");
  244. else
  245. dev_err(&device->dev,
  246. "Failed to get unique processor _UID (0x%x)\n",
  247. pr->acpi_id);
  248. return -ENODEV;
  249. }
  250. pr->phys_id = acpi_get_phys_id(pr->handle, device_declaration,
  251. pr->acpi_id);
  252. if (invalid_phys_cpuid(pr->phys_id))
  253. acpi_handle_debug(pr->handle, "failed to get CPU physical ID.\n");
  254. pr->id = acpi_map_cpuid(pr->phys_id, pr->acpi_id);
  255. if (!cpu0_initialized && !acpi_has_cpu_in_madt()) {
  256. cpu0_initialized = 1;
  257. /*
  258. * Handle UP system running SMP kernel, with no CPU
  259. * entry in MADT
  260. */
  261. if (invalid_logical_cpuid(pr->id) && (num_online_cpus() == 1))
  262. pr->id = 0;
  263. }
  264. /*
  265. * Extra Processor objects may be enumerated on MP systems with
  266. * less than the max # of CPUs. They should be ignored _iff
  267. * they are physically not present.
  268. *
  269. * NOTE: Even if the processor has a cpuid, it may not be present
  270. * because cpuid <-> apicid mapping is persistent now.
  271. */
  272. if (invalid_logical_cpuid(pr->id) || !cpu_present(pr->id)) {
  273. int ret = acpi_processor_hotadd_init(pr);
  274. if (ret)
  275. return ret;
  276. }
  277. /*
  278. * On some boxes several processors use the same processor bus id.
  279. * But they are located in different scope. For example:
  280. * \_SB.SCK0.CPU0
  281. * \_SB.SCK1.CPU0
  282. * Rename the processor device bus id. And the new bus id will be
  283. * generated as the following format:
  284. * CPU+CPU ID.
  285. */
  286. sprintf(acpi_device_bid(device), "CPU%X", pr->id);
  287. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Processor [%d:%d]\n", pr->id,
  288. pr->acpi_id));
  289. if (!object.processor.pblk_address)
  290. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No PBLK (NULL address)\n"));
  291. else if (object.processor.pblk_length != 6)
  292. dev_err(&device->dev, "Invalid PBLK length [%d]\n",
  293. object.processor.pblk_length);
  294. else {
  295. pr->throttling.address = object.processor.pblk_address;
  296. pr->throttling.duty_offset = acpi_gbl_FADT.duty_offset;
  297. pr->throttling.duty_width = acpi_gbl_FADT.duty_width;
  298. pr->pblk = object.processor.pblk_address;
  299. }
  300. /*
  301. * If ACPI describes a slot number for this CPU, we can use it to
  302. * ensure we get the right value in the "physical id" field
  303. * of /proc/cpuinfo
  304. */
  305. status = acpi_evaluate_integer(pr->handle, "_SUN", NULL, &value);
  306. if (ACPI_SUCCESS(status))
  307. arch_fix_phys_package_id(pr->id, value);
  308. return 0;
  309. }
  310. /*
  311. * Do not put anything in here which needs the core to be online.
  312. * For example MSR access or setting up things which check for cpuinfo_x86
  313. * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc.
  314. * Such things have to be put in and set up by the processor driver's .probe().
  315. */
  316. static DEFINE_PER_CPU(void *, processor_device_array);
  317. static int acpi_processor_add(struct acpi_device *device,
  318. const struct acpi_device_id *id)
  319. {
  320. struct acpi_processor *pr;
  321. struct device *dev;
  322. int result = 0;
  323. pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
  324. if (!pr)
  325. return -ENOMEM;
  326. if (!zalloc_cpumask_var(&pr->throttling.shared_cpu_map, GFP_KERNEL)) {
  327. result = -ENOMEM;
  328. goto err_free_pr;
  329. }
  330. pr->handle = device->handle;
  331. strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
  332. strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
  333. device->driver_data = pr;
  334. result = acpi_processor_get_info(device);
  335. if (result) /* Processor is not physically present or unavailable */
  336. return 0;
  337. BUG_ON(pr->id >= nr_cpu_ids);
  338. /*
  339. * Buggy BIOS check.
  340. * ACPI id of processors can be reported wrongly by the BIOS.
  341. * Don't trust it blindly
  342. */
  343. if (per_cpu(processor_device_array, pr->id) != NULL &&
  344. per_cpu(processor_device_array, pr->id) != device) {
  345. dev_warn(&device->dev,
  346. "BIOS reported wrong ACPI id %d for the processor\n",
  347. pr->id);
  348. /* Give up, but do not abort the namespace scan. */
  349. goto err;
  350. }
  351. /*
  352. * processor_device_array is not cleared on errors to allow buggy BIOS
  353. * checks.
  354. */
  355. per_cpu(processor_device_array, pr->id) = device;
  356. per_cpu(processors, pr->id) = pr;
  357. dev = get_cpu_device(pr->id);
  358. if (!dev) {
  359. result = -ENODEV;
  360. goto err;
  361. }
  362. result = acpi_bind_one(dev, device);
  363. if (result)
  364. goto err;
  365. pr->dev = dev;
  366. /* Trigger the processor driver's .probe() if present. */
  367. if (device_attach(dev) >= 0)
  368. return 1;
  369. dev_err(dev, "Processor driver could not be attached\n");
  370. acpi_unbind_one(dev);
  371. err:
  372. free_cpumask_var(pr->throttling.shared_cpu_map);
  373. device->driver_data = NULL;
  374. per_cpu(processors, pr->id) = NULL;
  375. err_free_pr:
  376. kfree(pr);
  377. return result;
  378. }
  379. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  380. /* --------------------------------------------------------------------------
  381. Removal
  382. -------------------------------------------------------------------------- */
  383. static void acpi_processor_remove(struct acpi_device *device)
  384. {
  385. struct acpi_processor *pr;
  386. if (!device || !acpi_driver_data(device))
  387. return;
  388. pr = acpi_driver_data(device);
  389. if (pr->id >= nr_cpu_ids)
  390. goto out;
  391. /*
  392. * The only reason why we ever get here is CPU hot-removal. The CPU is
  393. * already offline and the ACPI device removal locking prevents it from
  394. * being put back online at this point.
  395. *
  396. * Unbind the driver from the processor device and detach it from the
  397. * ACPI companion object.
  398. */
  399. device_release_driver(pr->dev);
  400. acpi_unbind_one(pr->dev);
  401. /* Clean up. */
  402. per_cpu(processor_device_array, pr->id) = NULL;
  403. per_cpu(processors, pr->id) = NULL;
  404. cpu_maps_update_begin();
  405. cpu_hotplug_begin();
  406. /* Remove the CPU. */
  407. arch_unregister_cpu(pr->id);
  408. acpi_unmap_cpu(pr->id);
  409. cpu_hotplug_done();
  410. cpu_maps_update_done();
  411. try_offline_node(cpu_to_node(pr->id));
  412. out:
  413. free_cpumask_var(pr->throttling.shared_cpu_map);
  414. kfree(pr);
  415. }
  416. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  417. #ifdef CONFIG_X86
  418. static bool acpi_hwp_native_thermal_lvt_set;
  419. static acpi_status __init acpi_hwp_native_thermal_lvt_osc(acpi_handle handle,
  420. u32 lvl,
  421. void *context,
  422. void **rv)
  423. {
  424. u8 sb_uuid_str[] = "4077A616-290C-47BE-9EBD-D87058713953";
  425. u32 capbuf[2];
  426. struct acpi_osc_context osc_context = {
  427. .uuid_str = sb_uuid_str,
  428. .rev = 1,
  429. .cap.length = 8,
  430. .cap.pointer = capbuf,
  431. };
  432. if (acpi_hwp_native_thermal_lvt_set)
  433. return AE_CTRL_TERMINATE;
  434. capbuf[0] = 0x0000;
  435. capbuf[1] = 0x1000; /* set bit 12 */
  436. if (ACPI_SUCCESS(acpi_run_osc(handle, &osc_context))) {
  437. if (osc_context.ret.pointer && osc_context.ret.length > 1) {
  438. u32 *capbuf_ret = osc_context.ret.pointer;
  439. if (capbuf_ret[1] & 0x1000) {
  440. acpi_handle_info(handle,
  441. "_OSC native thermal LVT Acked\n");
  442. acpi_hwp_native_thermal_lvt_set = true;
  443. }
  444. }
  445. kfree(osc_context.ret.pointer);
  446. }
  447. return AE_OK;
  448. }
  449. void __init acpi_early_processor_osc(void)
  450. {
  451. if (boot_cpu_has(X86_FEATURE_HWP)) {
  452. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  453. ACPI_UINT32_MAX,
  454. acpi_hwp_native_thermal_lvt_osc,
  455. NULL, NULL, NULL);
  456. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID,
  457. acpi_hwp_native_thermal_lvt_osc,
  458. NULL, NULL);
  459. }
  460. }
  461. #endif
  462. /*
  463. * The following ACPI IDs are known to be suitable for representing as
  464. * processor devices.
  465. */
  466. static const struct acpi_device_id processor_device_ids[] = {
  467. { ACPI_PROCESSOR_OBJECT_HID, },
  468. { ACPI_PROCESSOR_DEVICE_HID, },
  469. { }
  470. };
  471. static struct acpi_scan_handler processor_handler = {
  472. .ids = processor_device_ids,
  473. .attach = acpi_processor_add,
  474. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  475. .detach = acpi_processor_remove,
  476. #endif
  477. .hotplug = {
  478. .enabled = true,
  479. },
  480. };
  481. static int acpi_processor_container_attach(struct acpi_device *dev,
  482. const struct acpi_device_id *id)
  483. {
  484. return 1;
  485. }
  486. static const struct acpi_device_id processor_container_ids[] = {
  487. { ACPI_PROCESSOR_CONTAINER_HID, },
  488. { }
  489. };
  490. static struct acpi_scan_handler processor_container_handler = {
  491. .ids = processor_container_ids,
  492. .attach = acpi_processor_container_attach,
  493. };
  494. /* The number of the unique processor IDs */
  495. static int nr_unique_ids __initdata;
  496. /* The number of the duplicate processor IDs */
  497. static int nr_duplicate_ids;
  498. /* Used to store the unique processor IDs */
  499. static int unique_processor_ids[] __initdata = {
  500. [0 ... NR_CPUS - 1] = -1,
  501. };
  502. /* Used to store the duplicate processor IDs */
  503. static int duplicate_processor_ids[] = {
  504. [0 ... NR_CPUS - 1] = -1,
  505. };
  506. static void __init processor_validated_ids_update(int proc_id)
  507. {
  508. int i;
  509. if (nr_unique_ids == NR_CPUS||nr_duplicate_ids == NR_CPUS)
  510. return;
  511. /*
  512. * Firstly, compare the proc_id with duplicate IDs, if the proc_id is
  513. * already in the IDs, do nothing.
  514. */
  515. for (i = 0; i < nr_duplicate_ids; i++) {
  516. if (duplicate_processor_ids[i] == proc_id)
  517. return;
  518. }
  519. /*
  520. * Secondly, compare the proc_id with unique IDs, if the proc_id is in
  521. * the IDs, put it in the duplicate IDs.
  522. */
  523. for (i = 0; i < nr_unique_ids; i++) {
  524. if (unique_processor_ids[i] == proc_id) {
  525. duplicate_processor_ids[nr_duplicate_ids] = proc_id;
  526. nr_duplicate_ids++;
  527. return;
  528. }
  529. }
  530. /*
  531. * Lastly, the proc_id is a unique ID, put it in the unique IDs.
  532. */
  533. unique_processor_ids[nr_unique_ids] = proc_id;
  534. nr_unique_ids++;
  535. }
  536. static acpi_status __init acpi_processor_ids_walk(acpi_handle handle,
  537. u32 lvl,
  538. void *context,
  539. void **rv)
  540. {
  541. acpi_status status;
  542. acpi_object_type acpi_type;
  543. unsigned long long uid;
  544. union acpi_object object = { 0 };
  545. struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
  546. status = acpi_get_type(handle, &acpi_type);
  547. if (ACPI_FAILURE(status))
  548. return status;
  549. switch (acpi_type) {
  550. case ACPI_TYPE_PROCESSOR:
  551. status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
  552. if (ACPI_FAILURE(status))
  553. goto err;
  554. uid = object.processor.proc_id;
  555. break;
  556. case ACPI_TYPE_DEVICE:
  557. status = acpi_evaluate_integer(handle, "_UID", NULL, &uid);
  558. if (ACPI_FAILURE(status))
  559. goto err;
  560. break;
  561. default:
  562. goto err;
  563. }
  564. processor_validated_ids_update(uid);
  565. return AE_OK;
  566. err:
  567. /* Exit on error, but don't abort the namespace walk */
  568. acpi_handle_info(handle, "Invalid processor object\n");
  569. return AE_OK;
  570. }
  571. static void __init acpi_processor_check_duplicates(void)
  572. {
  573. /* check the correctness for all processors in ACPI namespace */
  574. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
  575. ACPI_UINT32_MAX,
  576. acpi_processor_ids_walk,
  577. NULL, NULL, NULL);
  578. acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, acpi_processor_ids_walk,
  579. NULL, NULL);
  580. }
  581. bool acpi_duplicate_processor_id(int proc_id)
  582. {
  583. int i;
  584. /*
  585. * compare the proc_id with duplicate IDs, if the proc_id is already
  586. * in the duplicate IDs, return true, otherwise, return false.
  587. */
  588. for (i = 0; i < nr_duplicate_ids; i++) {
  589. if (duplicate_processor_ids[i] == proc_id)
  590. return true;
  591. }
  592. return false;
  593. }
  594. void __init acpi_processor_init(void)
  595. {
  596. acpi_processor_check_duplicates();
  597. acpi_scan_add_handler_with_hotplug(&processor_handler, "processor");
  598. acpi_scan_add_handler(&processor_container_handler);
  599. }