1e656c62eSopenharmony_ci/*
2e656c62eSopenharmony_ci * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3e656c62eSopenharmony_ci * Licensed under the Mulan PSL v2.
4e656c62eSopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2.
5e656c62eSopenharmony_ci * You may obtain a copy of Mulan PSL v2 at:
6e656c62eSopenharmony_ci *     http://license.coscl.org.cn/MulanPSL2
7e656c62eSopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8e656c62eSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9e656c62eSopenharmony_ci * PURPOSE.
10e656c62eSopenharmony_ci * See the Mulan PSL v2 for more details.
11e656c62eSopenharmony_ci */
12e656c62eSopenharmony_ci
13e656c62eSopenharmony_ci#include "late_init_agent.h"
14e656c62eSopenharmony_ci#include <errno.h>
15e656c62eSopenharmony_ci#include <fcntl.h>
16e656c62eSopenharmony_ci#include <sys/ioctl.h>
17e656c62eSopenharmony_ci#include <sys/types.h>
18e656c62eSopenharmony_ci#include <time.h>
19e656c62eSopenharmony_ci#include <unistd.h>
20e656c62eSopenharmony_ci#include "fs_work_agent.h"
21e656c62eSopenharmony_ci#include "tc_ns_client.h"
22e656c62eSopenharmony_ci#include "tee_log.h"
23e656c62eSopenharmony_ci
24e656c62eSopenharmony_ci#ifdef LOG_TAG
25e656c62eSopenharmony_ci#undef LOG_TAG
26e656c62eSopenharmony_ci#endif
27e656c62eSopenharmony_ci#define LOG_TAG "teecd_agent"
28e656c62eSopenharmony_ci
29e656c62eSopenharmony_civoid *InitLateWorkThread(void *dummy)
30e656c62eSopenharmony_ci{
31e656c62eSopenharmony_ci    (void)dummy;
32e656c62eSopenharmony_ci    unsigned int index = FS_LATE_INIT;
33e656c62eSopenharmony_ci
34e656c62eSopenharmony_ci    tlogd("now start to late init\n");
35e656c62eSopenharmony_ci
36e656c62eSopenharmony_ci    int fd = open(TC_PRIVATE_DEV_NAME, O_RDWR);
37e656c62eSopenharmony_ci    if (fd < 0) {
38e656c62eSopenharmony_ci        tloge("open tee client dev failed, fd is %d\n", fd);
39e656c62eSopenharmony_ci        return NULL;
40e656c62eSopenharmony_ci    }
41e656c62eSopenharmony_ci
42e656c62eSopenharmony_ci    int ret = ioctl(fd, (int)TC_NS_CLIENT_IOCTL_LATEINIT, index);
43e656c62eSopenharmony_ci    if (ret) {
44e656c62eSopenharmony_ci        tloge("failed to set late init, errno = %d\n", errno);
45e656c62eSopenharmony_ci    }
46e656c62eSopenharmony_ci
47e656c62eSopenharmony_ci    close(fd);
48e656c62eSopenharmony_ci    return NULL;
49e656c62eSopenharmony_ci}
50