1 /* 2 * process.c 3 * 4 * The file is used for adaptation. 5 * 6 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the 10 * Free Software Foundation; either version 2 of the License, or (at your 11 * option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 23 #include <common.h> 24 25 #define CFG_MAX_SHUTDOWN 10 26 27 static struct shutdown_ctrl { 28 int count; 29 void (*shutdown[CFG_MAX_SHUTDOWN])(void); 30 } shutdown_ctrl = {0, {0}, }; 31 add_shutdown(void (* shutdown)(void))32void add_shutdown(void (*shutdown)(void)) 33 { 34 if (shutdown_ctrl.count >= CFG_MAX_SHUTDOWN) { 35 printf("Can't add shutdown function," 36 "Please increase CFG_MAX_SHUTDOWN count\n"); 37 return; 38 } 39 shutdown_ctrl.shutdown[shutdown_ctrl.count++] 40 = shutdown; 41 } 42 do_shutdown(void)43void do_shutdown(void) 44 { 45 int ix; 46 for (ix = 0; ix < shutdown_ctrl.count; ix++) 47 shutdown_ctrl.shutdown[ix](); 48 } 49