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 for (function
= rt_table
->function_list
; NULL
!= *function
; function
++) {
38 int tmp
= (*function
)(hwmgr
, input
, output
, temp_storage
, result
);
40 if (tmp
== PP_Result_TableImmediateExit
)
45 if (rt_table
->exit_error
)
53 int phm_dispatch_table(struct pp_hwmgr
*hwmgr
,
54 struct phm_runtime_table_header
*rt_table
,
55 void *input
, void *output
)
58 void *temp_storage
= NULL
;
60 if (hwmgr
== NULL
|| rt_table
== NULL
|| rt_table
->function_list
== NULL
) {
61 printk(KERN_ERR
"[ powerplay ] Invalid Parameter!\n");
62 return 0; /*temp return ture because some function not implement on some asic */
65 if (0 != rt_table
->storage_size
) {
66 temp_storage
= kzalloc(rt_table
->storage_size
, GFP_KERNEL
);
67 if (temp_storage
== NULL
) {
68 printk(KERN_ERR
"[ powerplay ] Could not allocate table temporary storage\n");
73 result
= phm_run_table(hwmgr
, rt_table
, input
, output
, temp_storage
);
75 if (NULL
!= temp_storage
)
81 int phm_construct_table(struct pp_hwmgr
*hwmgr
,
82 struct phm_master_table_header
*master_table
,
83 struct phm_runtime_table_header
*rt_table
)
85 uint32_t function_count
= 0;
86 const struct phm_master_table_item
*table_item
;
88 phm_table_function
*run_time_list
;
89 phm_table_function
*rtf
;
91 if (hwmgr
== NULL
|| master_table
== NULL
|| rt_table
== NULL
) {
92 printk(KERN_ERR
"[ powerplay ] Invalid Parameter!\n");
96 for (table_item
= master_table
->master_list
;
97 NULL
!= table_item
->tableFunction
; table_item
++) {
98 if ((NULL
== table_item
->isFunctionNeededInRuntimeTable
) ||
99 (table_item
->isFunctionNeededInRuntimeTable(hwmgr
)))
103 size
= (function_count
+ 1) * sizeof(phm_table_function
);
104 run_time_list
= kzalloc(size
, GFP_KERNEL
);
106 if (NULL
== run_time_list
)
110 for (table_item
= master_table
->master_list
;
111 NULL
!= table_item
->tableFunction
; table_item
++) {
112 if ((rtf
- run_time_list
) > function_count
) {
113 printk(KERN_ERR
"[ powerplay ] Check function results have changed\n");
114 kfree(run_time_list
);
118 if ((NULL
== table_item
->isFunctionNeededInRuntimeTable
) ||
119 (table_item
->isFunctionNeededInRuntimeTable(hwmgr
))) {
120 *(rtf
++) = table_item
->tableFunction
;
124 if ((rtf
- run_time_list
) > function_count
) {
125 printk(KERN_ERR
"[ powerplay ] Check function results have changed\n");
126 kfree(run_time_list
);
131 rt_table
->function_list
= run_time_list
;
132 rt_table
->exit_error
= (0 != (master_table
->flags
& PHM_MasterTableFlag_ExitOnError
));
133 rt_table
->storage_size
= master_table
->storage_size
;
137 int phm_destroy_table(struct pp_hwmgr
*hwmgr
,
138 struct phm_runtime_table_header
*rt_table
)
140 if (hwmgr
== NULL
|| rt_table
== NULL
) {
141 printk(KERN_ERR
"[ powerplay ] Invalid Parameter\n");
145 if (NULL
== rt_table
->function_list
)
148 kfree(rt_table
->function_list
);
150 rt_table
->function_list
= NULL
;
151 rt_table
->storage_size
= 0;
152 rt_table
->exit_error
= false;