2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
28 static int phm_run_table(struct pp_hwmgr *hwmgr,
29 struct phm_runtime_table_header *rt_table,
35 phm_table_function *function;
37 if (rt_table->function_list == NULL) {
38 pr_debug("this function not implement!\n");
42 for (function = rt_table->function_list; NULL != *function; function++) {
43 int tmp = (*function)(hwmgr, input, output, temp_storage, result);
45 if (tmp == PP_Result_TableImmediateExit)
50 if (rt_table->exit_error)
58 int phm_dispatch_table(struct pp_hwmgr *hwmgr,
59 struct phm_runtime_table_header *rt_table,
60 void *input, void *output)
65 if (hwmgr == NULL || rt_table == NULL) {
66 pr_err("Invalid Parameter!\n");
70 if (0 != rt_table->storage_size) {
71 temp_storage = kzalloc(rt_table->storage_size, GFP_KERNEL);
72 if (temp_storage == NULL) {
73 pr_err("Could not allocate table temporary storage\n");
80 result = phm_run_table(hwmgr, rt_table, input, output, temp_storage);
87 int phm_construct_table(struct pp_hwmgr *hwmgr,
88 const struct phm_master_table_header *master_table,
89 struct phm_runtime_table_header *rt_table)
91 uint32_t function_count = 0;
92 const struct phm_master_table_item *table_item;
94 phm_table_function *run_time_list;
95 phm_table_function *rtf;
97 if (hwmgr == NULL || master_table == NULL || rt_table == NULL) {
98 pr_err("Invalid Parameter!\n");
102 for (table_item = master_table->master_list;
103 NULL != table_item->tableFunction; table_item++) {
104 if ((NULL == table_item->isFunctionNeededInRuntimeTable) ||
105 (table_item->isFunctionNeededInRuntimeTable(hwmgr)))
109 size = (function_count + 1) * sizeof(phm_table_function);
110 run_time_list = kzalloc(size, GFP_KERNEL);
112 if (NULL == run_time_list)
116 for (table_item = master_table->master_list;
117 NULL != table_item->tableFunction; table_item++) {
118 if ((rtf - run_time_list) > function_count) {
119 pr_err("Check function results have changed\n");
120 kfree(run_time_list);
124 if ((NULL == table_item->isFunctionNeededInRuntimeTable) ||
125 (table_item->isFunctionNeededInRuntimeTable(hwmgr))) {
126 *(rtf++) = table_item->tableFunction;
130 if ((rtf - run_time_list) > function_count) {
131 pr_err("Check function results have changed\n");
132 kfree(run_time_list);
137 rt_table->function_list = run_time_list;
138 rt_table->exit_error = (0 != (master_table->flags & PHM_MasterTableFlag_ExitOnError));
139 rt_table->storage_size = master_table->storage_size;
143 int phm_destroy_table(struct pp_hwmgr *hwmgr,
144 struct phm_runtime_table_header *rt_table)
146 if (hwmgr == NULL || rt_table == NULL) {
147 pr_err("Invalid Parameter\n");
151 if (NULL == rt_table->function_list)
154 kfree(rt_table->function_list);
156 rt_table->function_list = NULL;
157 rt_table->storage_size = 0;
158 rt_table->exit_error = false;