• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <common/bk_include.h>
16 #include <components/system.h>
17 #include <driver/prro.h>
18 #include <os/os.h>
19 #include <os/mem.h>
20 #include "prro_driver.h"
21 #include "prro_hal.h"
22 
23 typedef struct {
24 	prro_hal_t hal;
25 } prro_driver_t;
26 
27 #define PRRO_RETURN_ON_DRIVER_NOT_INIT() do {\
28 	if (!s_prro_driver_is_init) {\
29 		PRRO_LOGE("PRRO driver not init\r\n");\
30 		return BK_ERR_PRRO_DRIVER_NOT_INIT;\
31 	}\
32 } while(0)
33 
34 static prro_driver_t s_prro = {0};
35 static bool s_prro_driver_is_init = false;
36 
bk_prro_driver_init(void)37 bk_err_t bk_prro_driver_init(void)
38 {
39 	if (s_prro_driver_is_init) {
40 		return BK_OK;
41 	}
42 
43 	os_memset(&s_prro, 0, sizeof(s_prro));
44 	prro_hal_init(&s_prro.hal);
45 	s_prro_driver_is_init = true;
46 
47 	return BK_OK;
48 }
49 
bk_prro_driver_deinit(void)50 bk_err_t bk_prro_driver_deinit(void)
51 {
52 	if (!s_prro_driver_is_init) {
53 		return BK_OK;
54 	}
55 	os_memset(&s_prro, 0, sizeof(s_prro));
56 	s_prro_driver_is_init = false;
57 
58 	return BK_OK;
59 }
60 
bk_prro_set_privilege_attribute(prro_dev_t dev,prro_privilege_type_t privilege_type)61 bk_err_t bk_prro_set_privilege_attribute(prro_dev_t dev, prro_privilege_type_t privilege_type)
62 {
63 	PRRO_RETURN_ON_DRIVER_NOT_INIT();
64 	prro_hal_set_privilege_attribute(&s_prro.hal, dev, privilege_type);
65 
66 	return BK_OK;
67 }
68 
bk_prro_set_secure_attribute(prro_dev_t dev,prro_secure_type_t secure_type)69 bk_err_t bk_prro_set_secure_attribute(prro_dev_t dev, prro_secure_type_t secure_type)
70 {
71 	PRRO_RETURN_ON_DRIVER_NOT_INIT();
72 	prro_hal_set_secure_attribute(&s_prro.hal, dev, secure_type);
73 
74 	return BK_OK;
75 }
76 
77