@@ -80,6 +80,14 @@ static u32 psci_cpu_suspend_feature;
8080static bool psci_system_reset2_supported ;
8181static bool psci_system_off2_hibernate_supported ;
8282
83+ struct psci_reset_param {
84+ const char * mode ;
85+ u32 reset_type ;
86+ u32 cookie ;
87+ };
88+ static struct psci_reset_param * psci_reset_params __ro_after_init ;
89+ static size_t num_psci_reset_params __ro_after_init ;
90+
8391static inline bool psci_has_ext_power_state (void )
8492{
8593 return psci_cpu_suspend_feature &
@@ -306,9 +314,39 @@ static int get_set_conduit_method(const struct device_node *np)
306314 return 0 ;
307315}
308316
317+ static int psci_vendor_system_reset2 (const char * cmd )
318+ {
319+ unsigned long ret ;
320+ size_t i ;
321+
322+ for (i = 0 ; i < num_psci_reset_params ; i ++ ) {
323+ if (!strcmp (psci_reset_params [i ].mode , cmd )) {
324+ ret = invoke_psci_fn (PSCI_FN_NATIVE (1 _1 , SYSTEM_RESET2 ),
325+ psci_reset_params [i ].reset_type ,
326+ psci_reset_params [i ].cookie , 0 );
327+ /*
328+ * if vendor reset fails, log it and fall back to
329+ * architecture reset types
330+ */
331+ pr_err ("failed to perform reset \"%s\": %ld\n" , cmd ,
332+ (long )ret );
333+ return 0 ;
334+ }
335+ }
336+
337+ return - ENOENT ;
338+ }
339+
309340static int psci_sys_reset (struct notifier_block * nb , unsigned long action ,
310341 void * data )
311342{
343+ /*
344+ * try to do the vendor system_reset2
345+ * If there wasn't a matching command, fall back to architectural resets
346+ */
347+ if (data && !psci_vendor_system_reset2 (data ))
348+ return NOTIFY_DONE ;
349+
312350 if ((reboot_mode == REBOOT_WARM || reboot_mode == REBOOT_SOFT ) &&
313351 psci_system_reset2_supported ) {
314352 /*
@@ -795,6 +833,73 @@ static const struct of_device_id psci_of_match[] __initconst = {
795833 {},
796834};
797835
836+ #define REBOOT_PREFIX "mode-"
837+
838+ static int __init psci_init_system_reset2_modes (void )
839+ {
840+ const size_t len = strlen (REBOOT_PREFIX );
841+ struct psci_reset_param * param ;
842+ struct device_node * psci_np __free (device_node ) = NULL ;
843+ struct device_node * np __free (device_node ) = NULL ;
844+ struct property * prop ;
845+ size_t count = 0 ;
846+ u32 magic [2 ];
847+ int num ;
848+
849+ if (!psci_system_reset2_supported )
850+ return 0 ;
851+
852+ psci_np = of_find_matching_node (NULL , psci_of_match );
853+ if (!psci_np )
854+ return 0 ;
855+
856+ np = of_find_node_by_name (psci_np , "reset-types" );
857+ if (!np )
858+ return 0 ;
859+
860+ for_each_property_of_node (np , prop ) {
861+ if (strncmp (prop -> name , REBOOT_PREFIX , len ))
862+ continue ;
863+ num = of_property_count_u32_elems (np , prop -> name );
864+ if (num != 1 && num != 2 )
865+ continue ;
866+
867+ count ++ ;
868+ }
869+
870+ param = psci_reset_params =
871+ kcalloc (count , sizeof (* psci_reset_params ), GFP_KERNEL );
872+ if (!psci_reset_params )
873+ return - ENOMEM ;
874+
875+ for_each_property_of_node (np , prop ) {
876+ if (strncmp (prop -> name , REBOOT_PREFIX , len ))
877+ continue ;
878+
879+ num = of_property_read_variable_u32_array (np , prop -> name , magic ,
880+ 1 , ARRAY_SIZE (magic ));
881+ if (num < 0 ) {
882+ pr_warn ("Failed to parse vendor reboot mode %s\n" ,
883+ param -> mode );
884+ kfree_const (param -> mode );
885+ continue ;
886+ }
887+
888+ param -> mode = kstrdup_const (prop -> name + len , GFP_KERNEL );
889+ if (!param -> mode )
890+ continue ;
891+
892+ /* Force reset type to be in vendor space */
893+ param -> reset_type = PSCI_1_1_RESET_TYPE_VENDOR_START | magic [0 ];
894+ param -> cookie = num > 1 ? magic [1 ] : 0 ;
895+ param ++ ;
896+ num_psci_reset_params ++ ;
897+ }
898+
899+ return 0 ;
900+ }
901+ arch_initcall (psci_init_system_reset2_modes );
902+
798903int __init psci_dt_init (void )
799904{
800905 struct device_node * np ;
0 commit comments