1 /*- 2 * Copyright (c) 2013, 2014 Robin Randhawa 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef _MACHINE_PSCI_H_ 28 #define _MACHINE_PSCI_H_ 29 30 #include <sys/types.h> 31 #include <dev/psci/smccc.h> 32 33 #ifdef _KERNEL 34 typedef int (*psci_initfn_t)(device_t dev, int default_version); 35 typedef int (*psci_callfn_t)(register_t, register_t, register_t, register_t, 36 register_t, register_t, register_t, register_t, 37 struct arm_smccc_res *res); 38 39 extern bool psci_present; 40 41 int psci_cpu_on(unsigned long, unsigned long, unsigned long); 42 int psci_cpu_off(void); /* Operates on caller. */ 43 void psci_reset(void); 44 int32_t psci_features(uint32_t); 45 int psci_get_version(void); 46 47 /* Handler to let us call into the PSCI/SMCCC firmware */ 48 extern psci_callfn_t psci_callfn; 49 static inline int 50 psci_call(register_t a, register_t b, register_t c, register_t d) 51 { 52 53 return (psci_callfn(a, b, c, d, 0, 0, 0, 0, NULL)); 54 } 55 #endif 56 57 /* 58 * PSCI return codes. 59 */ 60 #define PSCI_RETVAL_SUCCESS 0 61 #define PSCI_RETVAL_NOT_SUPPORTED -1 62 #define PSCI_RETVAL_INVALID_PARAMS -2 63 #define PSCI_RETVAL_DENIED -3 64 #define PSCI_RETVAL_ALREADY_ON -4 65 #define PSCI_RETVAL_ON_PENDING -5 66 #define PSCI_RETVAL_INTERNAL_FAILURE -6 67 #define PSCI_RETVAL_NOT_PRESENT -7 68 #define PSCI_RETVAL_DISABLED -8 69 /* 70 * Used to signal PSCI is not available, e.g. to start a CPU. 71 */ 72 #define PSCI_MISSING 1 73 74 /* 75 * PSCI function codes (as per PSCI v0.2). 76 */ 77 #ifdef __aarch64__ 78 #define PSCI_FNID_VERSION 0x84000000 79 #define PSCI_FNID_CPU_SUSPEND 0xc4000001 80 #define PSCI_FNID_CPU_OFF 0x84000002 81 #define PSCI_FNID_CPU_ON 0xc4000003 82 #define PSCI_FNID_AFFINITY_INFO 0xc4000004 83 #define PSCI_FNID_MIGRATE 0xc4000005 84 #define PSCI_FNID_MIGRATE_INFO_TYPE 0x84000006 85 #define PSCI_FNID_MIGRATE_INFO_UP_CPU 0xc4000007 86 #define PSCI_FNID_SYSTEM_OFF 0x84000008 87 #define PSCI_FNID_SYSTEM_RESET 0x84000009 88 #define PSCI_FNID_FEATURES 0x8400000a 89 #else 90 #define PSCI_FNID_VERSION 0x84000000 91 #define PSCI_FNID_CPU_SUSPEND 0x84000001 92 #define PSCI_FNID_CPU_OFF 0x84000002 93 #define PSCI_FNID_CPU_ON 0x84000003 94 #define PSCI_FNID_AFFINITY_INFO 0x84000004 95 #define PSCI_FNID_MIGRATE 0x84000005 96 #define PSCI_FNID_MIGRATE_INFO_TYPE 0x84000006 97 #define PSCI_FNID_MIGRATE_INFO_UP_CPU 0x84000007 98 #define PSCI_FNID_SYSTEM_OFF 0x84000008 99 #define PSCI_FNID_SYSTEM_RESET 0x84000009 100 #define PSCI_FNID_FEATURES 0x8400000a 101 #endif 102 103 #define PSCI_VER_MAJOR(v) (((v) >> 16) & 0xFF) 104 #define PSCI_VER_MINOR(v) ((v) & 0xFF) 105 #define PSCI_VER(maj, min) (((maj) << 16) | (min)) 106 107 #define PSCI_AFFINITY_INFO_ON 0 108 #define PSCI_AFFINITY_INFO_OFF 1 109 #define PSCI_AFFINITY_INFO_ON_PENDING 2 110 111 #ifdef _KERNEL 112 enum psci_fn { 113 PSCI_FN_VERSION, 114 PSCI_FN_CPU_SUSPEND, 115 PSCI_FN_CPU_OFF, 116 PSCI_FN_CPU_ON, 117 PSCI_FN_AFFINITY_INFO, 118 PSCI_FN_MIGRATE, 119 PSCI_FN_MIGRATE_INFO_TYPE, 120 PSCI_FN_MIGRATE_INFO_UP_CPU, 121 PSCI_FN_SYSTEM_OFF, 122 PSCI_FN_SYSTEM_RESET, 123 PSCI_FN_MAX 124 }; 125 #endif 126 127 #endif /* _MACHINE_PSCI_H_ */ 128