• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include "hifb_proc.h"
20 #include "proc_ext.h"
21 #include "securec.h"
22 #include "hifb_main.h"
23 #include "hifb_comm.h"
24 
25 #define MAX_PROC_ENTRIES 16
26 
27 static osal_proc_entry_t g_proc_items[MAX_PROC_ENTRIES];
28 
29 #ifdef CONFIG_HI_PROC_SHOW_SUPPORT
hifb_proc_add_module(const hi_char * entry_name,hi_u32 size,hifb_proc_show show,hifb_proc_write w,hi_void * data)30 hi_void hifb_proc_add_module(const hi_char *entry_name, hi_u32 size, hifb_proc_show show,
31                              hifb_proc_write w, hi_void *data)
32 {
33     hi_s32 i, ret;
34     osal_proc_entry_t* proc_item = HI_NULL;
35     hi_unused(size);
36 
37     for (i = 0; i < MAX_PROC_ENTRIES; i++) {
38         if (!g_proc_items[i].proc_dir_entry) {
39             break;
40         }
41     }
42     if (i == MAX_PROC_ENTRIES) {
43         osal_printk("hifb proc num full. \n");
44         return;
45     }
46 
47     proc_item = osal_create_proc_entry(entry_name, HI_NULL);
48     if (proc_item == HI_NULL) {
49         osal_printk("create proc err. \n");
50         return;
51     }
52 
53     proc_item->write = w;
54     proc_item->read = show,
55     proc_item->private = data;
56 
57     ret = memcpy_s(&g_proc_items[i], sizeof(osal_proc_entry_t), proc_item, sizeof(osal_proc_entry_t));
58     hifb_unequal_eok_return_void(ret);
59 }
60 
hifb_proc_remove_module(const char * entry_name)61 hi_void hifb_proc_remove_module(const char *entry_name)
62 {
63     hi_s32 i;
64 
65     for (i = 0; i < MAX_PROC_ENTRIES; i++) {
66         if (!strcmp(g_proc_items[i].name, entry_name)) {
67             break;
68         }
69     }
70 
71     if (i == MAX_PROC_ENTRIES) {
72         return;
73     }
74 
75     osal_remove_proc_entry(entry_name, HI_NULL);
76     (hi_void)memset_s(&g_proc_items[i], sizeof(osal_proc_entry_t), 0, sizeof(osal_proc_entry_t));
77 
78     return;
79 }
80 
hifb_proc_remove_all_module(hi_void)81 hi_void hifb_proc_remove_all_module(hi_void)
82 {
83     hi_s32 i;
84 
85     for (i = 0; i < MAX_PROC_ENTRIES; i++) {
86         if (g_proc_items[i].proc_dir_entry == HI_NULL) {
87             continue;
88         }
89 
90         osal_remove_proc_entry(g_proc_items[i].name, HI_NULL);
91         (hi_void)memset_s(&g_proc_items[i], sizeof(osal_proc_entry_t), 0, sizeof(osal_proc_entry_t));
92     }
93 }
94 
hifb_proc_init(hi_void)95 hi_void hifb_proc_init(hi_void)
96 {
97     /* hifb proc:Uniformly hang under umap, not separately under graphic */
98     (hi_void)memset_s(g_proc_items, sizeof(g_proc_items), 0, sizeof(g_proc_items));
99 }
100 
101 #endif
102