psci.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License version 2 as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * Copyright (C) 2015 ARM Limited
  12. */
  13. #define pr_fmt(fmt) "psci: " fmt
  14. #include <linux/acpi.h>
  15. #include <linux/arm-smccc.h>
  16. #include <linux/cpuidle.h>
  17. #include <linux/errno.h>
  18. #include <linux/linkage.h>
  19. #include <linux/of.h>
  20. #include <linux/pm.h>
  21. #include <linux/printk.h>
  22. #include <linux/psci.h>
  23. #include <linux/reboot.h>
  24. #include <linux/slab.h>
  25. #include <linux/suspend.h>
  26. #include <uapi/linux/psci.h>
  27. #include <asm/cpuidle.h>
  28. #include <asm/cputype.h>
  29. #include <asm/system_misc.h>
  30. #include <asm/smp_plat.h>
  31. #include <asm/suspend.h>
  32. /*
  33. * While a 64-bit OS can make calls with SMC32 calling conventions, for some
  34. * calls it is necessary to use SMC64 to pass or return 64-bit values.
  35. * For such calls PSCI_FN_NATIVE(version, name) will choose the appropriate
  36. * (native-width) function ID.
  37. */
  38. #ifdef CONFIG_64BIT
  39. #define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN64_##name
  40. #else
  41. #define PSCI_FN_NATIVE(version, name) PSCI_##version##_FN_##name
  42. #endif
  43. /*
  44. * The CPU any Trusted OS is resident on. The trusted OS may reject CPU_OFF
  45. * calls to its resident CPU, so we must avoid issuing those. We never migrate
  46. * a Trusted OS even if it claims to be capable of migration -- doing so will
  47. * require cooperation with a Trusted OS driver.
  48. */
  49. static int resident_cpu = -1;
  50. bool psci_tos_resident_on(int cpu)
  51. {
  52. return cpu == resident_cpu;
  53. }
  54. struct psci_operations psci_ops = {
  55. .conduit = PSCI_CONDUIT_NONE,
  56. .smccc_version = SMCCC_VERSION_1_0,
  57. };
  58. typedef unsigned long (psci_fn)(unsigned long, unsigned long,
  59. unsigned long, unsigned long);
  60. static psci_fn *invoke_psci_fn;
  61. enum psci_function {
  62. PSCI_FN_CPU_SUSPEND,
  63. PSCI_FN_CPU_ON,
  64. PSCI_FN_CPU_OFF,
  65. PSCI_FN_MIGRATE,
  66. PSCI_FN_MAX,
  67. };
  68. static u32 psci_function_id[PSCI_FN_MAX];
  69. #define PSCI_0_2_POWER_STATE_MASK \
  70. (PSCI_0_2_POWER_STATE_ID_MASK | \
  71. PSCI_0_2_POWER_STATE_TYPE_MASK | \
  72. PSCI_0_2_POWER_STATE_AFFL_MASK)
  73. #define PSCI_1_0_EXT_POWER_STATE_MASK \
  74. (PSCI_1_0_EXT_POWER_STATE_ID_MASK | \
  75. PSCI_1_0_EXT_POWER_STATE_TYPE_MASK)
  76. static u32 psci_cpu_suspend_feature;
  77. static inline bool psci_has_ext_power_state(void)
  78. {
  79. return psci_cpu_suspend_feature &
  80. PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK;
  81. }
  82. static inline bool psci_power_state_loses_context(u32 state)
  83. {
  84. const u32 mask = psci_has_ext_power_state() ?
  85. PSCI_1_0_EXT_POWER_STATE_TYPE_MASK :
  86. PSCI_0_2_POWER_STATE_TYPE_MASK;
  87. return state & mask;
  88. }
  89. static inline bool psci_power_state_is_valid(u32 state)
  90. {
  91. const u32 valid_mask = psci_has_ext_power_state() ?
  92. PSCI_1_0_EXT_POWER_STATE_MASK :
  93. PSCI_0_2_POWER_STATE_MASK;
  94. return !(state & ~valid_mask);
  95. }
  96. static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
  97. unsigned long arg0, unsigned long arg1,
  98. unsigned long arg2)
  99. {
  100. struct arm_smccc_res res;
  101. arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
  102. return res.a0;
  103. }
  104. static unsigned long __invoke_psci_fn_smc(unsigned long function_id,
  105. unsigned long arg0, unsigned long arg1,
  106. unsigned long arg2)
  107. {
  108. struct arm_smccc_res res;
  109. arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
  110. return res.a0;
  111. }
  112. static int psci_to_linux_errno(int errno)
  113. {
  114. switch (errno) {
  115. case PSCI_RET_SUCCESS:
  116. return 0;
  117. case PSCI_RET_NOT_SUPPORTED:
  118. return -EOPNOTSUPP;
  119. case PSCI_RET_INVALID_PARAMS:
  120. case PSCI_RET_INVALID_ADDRESS:
  121. return -EINVAL;
  122. case PSCI_RET_DENIED:
  123. return -EPERM;
  124. };
  125. return -EINVAL;
  126. }
  127. static u32 psci_get_version(void)
  128. {
  129. return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
  130. }
  131. static int psci_cpu_suspend(u32 state, unsigned long entry_point)
  132. {
  133. int err;
  134. u32 fn;
  135. fn = psci_function_id[PSCI_FN_CPU_SUSPEND];
  136. err = invoke_psci_fn(fn, state, entry_point, 0);
  137. return psci_to_linux_errno(err);
  138. }
  139. static int psci_cpu_off(u32 state)
  140. {
  141. int err;
  142. u32 fn;
  143. fn = psci_function_id[PSCI_FN_CPU_OFF];
  144. err = invoke_psci_fn(fn, state, 0, 0);
  145. return psci_to_linux_errno(err);
  146. }
  147. static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point)
  148. {
  149. int err;
  150. u32 fn;
  151. fn = psci_function_id[PSCI_FN_CPU_ON];
  152. err = invoke_psci_fn(fn, cpuid, entry_point, 0);
  153. return psci_to_linux_errno(err);
  154. }
  155. static int psci_migrate(unsigned long cpuid)
  156. {
  157. int err;
  158. u32 fn;
  159. fn = psci_function_id[PSCI_FN_MIGRATE];
  160. err = invoke_psci_fn(fn, cpuid, 0, 0);
  161. return psci_to_linux_errno(err);
  162. }
  163. static int psci_affinity_info(unsigned long target_affinity,
  164. unsigned long lowest_affinity_level)
  165. {
  166. return invoke_psci_fn(PSCI_FN_NATIVE(0_2, AFFINITY_INFO),
  167. target_affinity, lowest_affinity_level, 0);
  168. }
  169. static int psci_migrate_info_type(void)
  170. {
  171. return invoke_psci_fn(PSCI_0_2_FN_MIGRATE_INFO_TYPE, 0, 0, 0);
  172. }
  173. static unsigned long psci_migrate_info_up_cpu(void)
  174. {
  175. return invoke_psci_fn(PSCI_FN_NATIVE(0_2, MIGRATE_INFO_UP_CPU),
  176. 0, 0, 0);
  177. }
  178. static void set_conduit(enum psci_conduit conduit)
  179. {
  180. switch (conduit) {
  181. case PSCI_CONDUIT_HVC:
  182. invoke_psci_fn = __invoke_psci_fn_hvc;
  183. break;
  184. case PSCI_CONDUIT_SMC:
  185. invoke_psci_fn = __invoke_psci_fn_smc;
  186. break;
  187. default:
  188. WARN(1, "Unexpected PSCI conduit %d\n", conduit);
  189. }
  190. psci_ops.conduit = conduit;
  191. }
  192. static int get_set_conduit_method(struct device_node *np)
  193. {
  194. const char *method;
  195. pr_info("probing for conduit method from DT.\n");
  196. if (of_property_read_string(np, "method", &method)) {
  197. pr_warn("missing \"method\" property\n");
  198. return -ENXIO;
  199. }
  200. if (!strcmp("hvc", method)) {
  201. set_conduit(PSCI_CONDUIT_HVC);
  202. } else if (!strcmp("smc", method)) {
  203. set_conduit(PSCI_CONDUIT_SMC);
  204. } else {
  205. pr_warn("invalid \"method\" property: %s\n", method);
  206. return -EINVAL;
  207. }
  208. return 0;
  209. }
  210. static void psci_sys_reset(enum reboot_mode reboot_mode, const char *cmd)
  211. {
  212. invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
  213. }
  214. static void psci_sys_poweroff(void)
  215. {
  216. invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
  217. }
  218. static int __init psci_features(u32 psci_func_id)
  219. {
  220. return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES,
  221. psci_func_id, 0, 0);
  222. }
  223. #ifdef CONFIG_CPU_IDLE
  224. static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state);
  225. static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu)
  226. {
  227. int i, ret, count = 0;
  228. u32 *psci_states;
  229. struct device_node *state_node;
  230. /* Count idle states */
  231. while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states",
  232. count))) {
  233. count++;
  234. of_node_put(state_node);
  235. }
  236. if (!count)
  237. return -ENODEV;
  238. psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
  239. if (!psci_states)
  240. return -ENOMEM;
  241. for (i = 0; i < count; i++) {
  242. u32 state;
  243. state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i);
  244. ret = of_property_read_u32(state_node,
  245. "arm,psci-suspend-param",
  246. &state);
  247. if (ret) {
  248. pr_warn(" * %s missing arm,psci-suspend-param property\n",
  249. state_node->full_name);
  250. of_node_put(state_node);
  251. goto free_mem;
  252. }
  253. of_node_put(state_node);
  254. pr_debug("psci-power-state %#x index %d\n", state, i);
  255. if (!psci_power_state_is_valid(state)) {
  256. pr_warn("Invalid PSCI power state %#x\n", state);
  257. ret = -EINVAL;
  258. goto free_mem;
  259. }
  260. psci_states[i] = state;
  261. }
  262. /* Idle states parsed correctly, initialize per-cpu pointer */
  263. per_cpu(psci_power_state, cpu) = psci_states;
  264. return 0;
  265. free_mem:
  266. kfree(psci_states);
  267. return ret;
  268. }
  269. #ifdef CONFIG_ACPI
  270. #include <acpi/processor.h>
  271. static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu)
  272. {
  273. int i, count;
  274. u32 *psci_states;
  275. struct acpi_lpi_state *lpi;
  276. struct acpi_processor *pr = per_cpu(processors, cpu);
  277. if (unlikely(!pr || !pr->flags.has_lpi))
  278. return -EINVAL;
  279. count = pr->power.count - 1;
  280. if (count <= 0)
  281. return -ENODEV;
  282. psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
  283. if (!psci_states)
  284. return -ENOMEM;
  285. for (i = 0; i < count; i++) {
  286. u32 state;
  287. lpi = &pr->power.lpi_states[i + 1];
  288. /*
  289. * Only bits[31:0] represent a PSCI power_state while
  290. * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
  291. */
  292. state = lpi->address;
  293. if (!psci_power_state_is_valid(state)) {
  294. pr_warn("Invalid PSCI power state %#x\n", state);
  295. kfree(psci_states);
  296. return -EINVAL;
  297. }
  298. psci_states[i] = state;
  299. }
  300. /* Idle states parsed correctly, initialize per-cpu pointer */
  301. per_cpu(psci_power_state, cpu) = psci_states;
  302. return 0;
  303. }
  304. #else
  305. static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu)
  306. {
  307. return -EINVAL;
  308. }
  309. #endif
  310. int psci_cpu_init_idle(unsigned int cpu)
  311. {
  312. struct device_node *cpu_node;
  313. int ret;
  314. /*
  315. * If the PSCI cpu_suspend function hook has not been initialized
  316. * idle states must not be enabled, so bail out
  317. */
  318. if (!psci_ops.cpu_suspend)
  319. return -EOPNOTSUPP;
  320. if (!acpi_disabled)
  321. return psci_acpi_cpu_init_idle(cpu);
  322. cpu_node = of_get_cpu_node(cpu, NULL);
  323. if (!cpu_node)
  324. return -ENODEV;
  325. ret = psci_dt_cpu_init_idle(cpu_node, cpu);
  326. of_node_put(cpu_node);
  327. return ret;
  328. }
  329. static int psci_suspend_finisher(unsigned long index)
  330. {
  331. u32 *state = __this_cpu_read(psci_power_state);
  332. return psci_ops.cpu_suspend(state[index - 1],
  333. virt_to_phys(cpu_resume));
  334. }
  335. int psci_cpu_suspend_enter(unsigned long index)
  336. {
  337. int ret;
  338. u32 *state = __this_cpu_read(psci_power_state);
  339. /*
  340. * idle state index 0 corresponds to wfi, should never be called
  341. * from the cpu_suspend operations
  342. */
  343. if (WARN_ON_ONCE(!index))
  344. return -EINVAL;
  345. if (!psci_power_state_loses_context(state[index - 1]))
  346. ret = psci_ops.cpu_suspend(state[index - 1], 0);
  347. else
  348. ret = cpu_suspend(index, psci_suspend_finisher);
  349. return ret;
  350. }
  351. /* ARM specific CPU idle operations */
  352. #ifdef CONFIG_ARM
  353. static const struct cpuidle_ops psci_cpuidle_ops __initconst = {
  354. .suspend = psci_cpu_suspend_enter,
  355. .init = psci_dt_cpu_init_idle,
  356. };
  357. CPUIDLE_METHOD_OF_DECLARE(psci, "psci", &psci_cpuidle_ops);
  358. #endif
  359. #endif
  360. static int psci_system_suspend(unsigned long unused)
  361. {
  362. return invoke_psci_fn(PSCI_FN_NATIVE(1_0, SYSTEM_SUSPEND),
  363. virt_to_phys(cpu_resume), 0, 0);
  364. }
  365. static int psci_system_suspend_enter(suspend_state_t state)
  366. {
  367. return cpu_suspend(0, psci_system_suspend);
  368. }
  369. static const struct platform_suspend_ops psci_suspend_ops = {
  370. .valid = suspend_valid_only_mem,
  371. .enter = psci_system_suspend_enter,
  372. };
  373. static void __init psci_init_system_suspend(void)
  374. {
  375. int ret;
  376. if (!IS_ENABLED(CONFIG_SUSPEND))
  377. return;
  378. ret = psci_features(PSCI_FN_NATIVE(1_0, SYSTEM_SUSPEND));
  379. if (ret != PSCI_RET_NOT_SUPPORTED)
  380. suspend_set_ops(&psci_suspend_ops);
  381. }
  382. static void __init psci_init_cpu_suspend(void)
  383. {
  384. int feature = psci_features(psci_function_id[PSCI_FN_CPU_SUSPEND]);
  385. if (feature != PSCI_RET_NOT_SUPPORTED)
  386. psci_cpu_suspend_feature = feature;
  387. }
  388. /*
  389. * Detect the presence of a resident Trusted OS which may cause CPU_OFF to
  390. * return DENIED (which would be fatal).
  391. */
  392. static void __init psci_init_migrate(void)
  393. {
  394. unsigned long cpuid;
  395. int type, cpu = -1;
  396. type = psci_ops.migrate_info_type();
  397. if (type == PSCI_0_2_TOS_MP) {
  398. pr_info("Trusted OS migration not required\n");
  399. return;
  400. }
  401. if (type == PSCI_RET_NOT_SUPPORTED) {
  402. pr_info("MIGRATE_INFO_TYPE not supported.\n");
  403. return;
  404. }
  405. if (type != PSCI_0_2_TOS_UP_MIGRATE &&
  406. type != PSCI_0_2_TOS_UP_NO_MIGRATE) {
  407. pr_err("MIGRATE_INFO_TYPE returned unknown type (%d)\n", type);
  408. return;
  409. }
  410. cpuid = psci_migrate_info_up_cpu();
  411. if (cpuid & ~MPIDR_HWID_BITMASK) {
  412. pr_warn("MIGRATE_INFO_UP_CPU reported invalid physical ID (0x%lx)\n",
  413. cpuid);
  414. return;
  415. }
  416. cpu = get_logical_index(cpuid);
  417. resident_cpu = cpu >= 0 ? cpu : -1;
  418. pr_info("Trusted OS resident on physical CPU 0x%lx\n", cpuid);
  419. }
  420. static void __init psci_init_smccc(void)
  421. {
  422. u32 ver = ARM_SMCCC_VERSION_1_0;
  423. int feature;
  424. feature = psci_features(ARM_SMCCC_VERSION_FUNC_ID);
  425. if (feature != PSCI_RET_NOT_SUPPORTED) {
  426. u32 ret;
  427. ret = invoke_psci_fn(ARM_SMCCC_VERSION_FUNC_ID, 0, 0, 0);
  428. if (ret == ARM_SMCCC_VERSION_1_1) {
  429. psci_ops.smccc_version = SMCCC_VERSION_1_1;
  430. ver = ret;
  431. }
  432. }
  433. /*
  434. * Conveniently, the SMCCC and PSCI versions are encoded the
  435. * same way. No, this isn't accidental.
  436. */
  437. pr_info("SMC Calling Convention v%d.%d\n",
  438. PSCI_VERSION_MAJOR(ver), PSCI_VERSION_MINOR(ver));
  439. }
  440. static void __init psci_0_2_set_functions(void)
  441. {
  442. pr_info("Using standard PSCI v0.2 function IDs\n");
  443. psci_ops.get_version = psci_get_version;
  444. psci_function_id[PSCI_FN_CPU_SUSPEND] =
  445. PSCI_FN_NATIVE(0_2, CPU_SUSPEND);
  446. psci_ops.cpu_suspend = psci_cpu_suspend;
  447. psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF;
  448. psci_ops.cpu_off = psci_cpu_off;
  449. psci_function_id[PSCI_FN_CPU_ON] = PSCI_FN_NATIVE(0_2, CPU_ON);
  450. psci_ops.cpu_on = psci_cpu_on;
  451. psci_function_id[PSCI_FN_MIGRATE] = PSCI_FN_NATIVE(0_2, MIGRATE);
  452. psci_ops.migrate = psci_migrate;
  453. psci_ops.affinity_info = psci_affinity_info;
  454. psci_ops.migrate_info_type = psci_migrate_info_type;
  455. arm_pm_restart = psci_sys_reset;
  456. pm_power_off = psci_sys_poweroff;
  457. }
  458. /*
  459. * Probe function for PSCI firmware versions >= 0.2
  460. */
  461. static int __init psci_probe(void)
  462. {
  463. u32 ver = psci_get_version();
  464. pr_info("PSCIv%d.%d detected in firmware.\n",
  465. PSCI_VERSION_MAJOR(ver),
  466. PSCI_VERSION_MINOR(ver));
  467. if (PSCI_VERSION_MAJOR(ver) == 0 && PSCI_VERSION_MINOR(ver) < 2) {
  468. pr_err("Conflicting PSCI version detected.\n");
  469. return -EINVAL;
  470. }
  471. psci_0_2_set_functions();
  472. psci_init_migrate();
  473. if (PSCI_VERSION_MAJOR(ver) >= 1) {
  474. psci_init_smccc();
  475. psci_init_cpu_suspend();
  476. psci_init_system_suspend();
  477. }
  478. return 0;
  479. }
  480. typedef int (*psci_initcall_t)(const struct device_node *);
  481. /*
  482. * PSCI init function for PSCI versions >=0.2
  483. *
  484. * Probe based on PSCI PSCI_VERSION function
  485. */
  486. static int __init psci_0_2_init(struct device_node *np)
  487. {
  488. int err;
  489. err = get_set_conduit_method(np);
  490. if (err)
  491. goto out_put_node;
  492. /*
  493. * Starting with v0.2, the PSCI specification introduced a call
  494. * (PSCI_VERSION) that allows probing the firmware version, so
  495. * that PSCI function IDs and version specific initialization
  496. * can be carried out according to the specific version reported
  497. * by firmware
  498. */
  499. err = psci_probe();
  500. out_put_node:
  501. of_node_put(np);
  502. return err;
  503. }
  504. /*
  505. * PSCI < v0.2 get PSCI Function IDs via DT.
  506. */
  507. static int __init psci_0_1_init(struct device_node *np)
  508. {
  509. u32 id;
  510. int err;
  511. err = get_set_conduit_method(np);
  512. if (err)
  513. goto out_put_node;
  514. pr_info("Using PSCI v0.1 Function IDs from DT\n");
  515. if (!of_property_read_u32(np, "cpu_suspend", &id)) {
  516. psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
  517. psci_ops.cpu_suspend = psci_cpu_suspend;
  518. }
  519. if (!of_property_read_u32(np, "cpu_off", &id)) {
  520. psci_function_id[PSCI_FN_CPU_OFF] = id;
  521. psci_ops.cpu_off = psci_cpu_off;
  522. }
  523. if (!of_property_read_u32(np, "cpu_on", &id)) {
  524. psci_function_id[PSCI_FN_CPU_ON] = id;
  525. psci_ops.cpu_on = psci_cpu_on;
  526. }
  527. if (!of_property_read_u32(np, "migrate", &id)) {
  528. psci_function_id[PSCI_FN_MIGRATE] = id;
  529. psci_ops.migrate = psci_migrate;
  530. }
  531. out_put_node:
  532. of_node_put(np);
  533. return err;
  534. }
  535. static const struct of_device_id psci_of_match[] __initconst = {
  536. { .compatible = "arm,psci", .data = psci_0_1_init},
  537. { .compatible = "arm,psci-0.2", .data = psci_0_2_init},
  538. { .compatible = "arm,psci-1.0", .data = psci_0_2_init},
  539. {},
  540. };
  541. int __init psci_dt_init(void)
  542. {
  543. struct device_node *np;
  544. const struct of_device_id *matched_np;
  545. psci_initcall_t init_fn;
  546. np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np);
  547. if (!np)
  548. return -ENODEV;
  549. init_fn = (psci_initcall_t)matched_np->data;
  550. return init_fn(np);
  551. }
  552. #ifdef CONFIG_ACPI
  553. /*
  554. * We use PSCI 0.2+ when ACPI is deployed on ARM64 and it's
  555. * explicitly clarified in SBBR
  556. */
  557. int __init psci_acpi_init(void)
  558. {
  559. if (!acpi_psci_present()) {
  560. pr_info("is not implemented in ACPI.\n");
  561. return -EOPNOTSUPP;
  562. }
  563. pr_info("probing for conduit method from ACPI.\n");
  564. if (acpi_psci_use_hvc())
  565. set_conduit(PSCI_CONDUIT_HVC);
  566. else
  567. set_conduit(PSCI_CONDUIT_SMC);
  568. return psci_probe();
  569. }
  570. #endif