• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * osal_firmware.c
3  *
4  * osal driver
5  *
6  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  */
18 
19 #include "osal_firmware.h"
20 #include <linux/export.h>
21 #include <linux/firmware.h>
22 #include <linux/string.h>
23 #include "hdf_log.h"
24 
25 #define HDF_LOG_TAG osal_fw
26 
OsalRequestFirmware(struct OsalFirmware * fwPara,const char * fwName,void * device)27 int32_t OsalRequestFirmware(struct OsalFirmware *fwPara,
28 	const char *fwName, void *device)
29 {
30 	const struct firmware *fw = NULL;
31 	int ret;
32 
33 	if (fwPara == NULL || fwName == NULL) {
34 		HDF_LOGE("%s invalid param", __func__);
35 		return HDF_ERR_INVALID_PARAM;
36 	}
37 
38 	ret = request_firmware(&fw, fwName, device);
39 	if (ret < 0) {
40 		fwPara->fwSize = 0;
41 		fwPara->para = NULL;
42 		HDF_LOGE("%s failure to request firmware file", __func__);
43 		return HDF_FAILURE;
44 	}
45 	fwPara->fwSize = fw->size;
46 	fwPara->para = (void *)fw;
47 
48 	return HDF_SUCCESS;
49 }
50 EXPORT_SYMBOL(OsalRequestFirmware);
51 
OsalSeekFirmware(struct OsalFirmware * fwPara,uint32_t offset)52 int32_t OsalSeekFirmware(struct OsalFirmware *fwPara, uint32_t offset)
53 {
54 	(void)fwPara;
55 	(void)offset;
56 	return HDF_SUCCESS;
57 }
58 EXPORT_SYMBOL(OsalSeekFirmware);
59 
OsalReadFirmware(struct OsalFirmware * fwPara,struct OsalFwBlock * block)60 int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block)
61 {
62 	struct firmware *fw = NULL;
63 
64 	if (fwPara == NULL || fwPara->para == NULL || block == NULL) {
65 		HDF_LOGE("%s invalid param", __func__);
66 		return HDF_ERR_INVALID_PARAM;
67 	}
68 
69 	fw = (struct firmware *)fwPara->para;
70 	block->data = (uint8_t *)fw->data;
71 	block->dataSize = fwPara->fwSize;
72 	block->curOffset = 0;
73 	block->endFlag = true;
74 
75 	return HDF_SUCCESS;
76 }
77 EXPORT_SYMBOL(OsalReadFirmware);
78 
OsalReleaseFirmware(struct OsalFirmware * fwPara)79 int32_t OsalReleaseFirmware(struct OsalFirmware *fwPara)
80 {
81 	if (fwPara == NULL || fwPara->para == NULL) {
82 		HDF_LOGE("%s invalid param", __func__);
83 		return HDF_ERR_INVALID_PARAM;
84 	}
85 
86 	release_firmware((struct firmware *)fwPara->para);
87 	fwPara->para = NULL;
88 
89 	return HDF_SUCCESS;
90 }
91 EXPORT_SYMBOL(OsalReleaseFirmware);
92