]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - drivers/gpu/drm/amd/powerplay/eventmgr/eventmgr.c
Merge tag 'mac80211-for-davem-2016-06-29-v2' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-focal-kernel.git] / drivers / gpu / drm / amd / powerplay / eventmgr / eventmgr.c
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 */
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include "eventmgr.h"
27 #include "hwmgr.h"
28 #include "eventinit.h"
29 #include "eventmanagement.h"
30
31 static int pem_init(struct pp_eventmgr *eventmgr)
32 {
33 int result = 0;
34 struct pem_event_data event_data = { {0} };
35
36 /* Initialize PowerPlay feature info */
37 pem_init_feature_info(eventmgr);
38
39 /* Initialize event action chains */
40 pem_init_event_action_chains(eventmgr);
41
42 /* Call initialization event */
43 result = pem_handle_event(eventmgr, AMD_PP_EVENT_INITIALIZE, &event_data);
44
45 if (0 != result)
46 return result;
47
48 /* Register interrupt callback functions */
49 result = pem_register_interrupts(eventmgr);
50 return 0;
51 }
52
53 static void pem_fini(struct pp_eventmgr *eventmgr)
54 {
55 struct pem_event_data event_data = { {0} };
56
57 pem_uninit_featureInfo(eventmgr);
58 pem_unregister_interrupts(eventmgr);
59
60 pem_handle_event(eventmgr, AMD_PP_EVENT_UNINITIALIZE, &event_data);
61 }
62
63 int eventmgr_init(struct pp_instance *handle)
64 {
65 int result = 0;
66 struct pp_eventmgr *eventmgr;
67
68 if (handle == NULL)
69 return -EINVAL;
70
71 eventmgr = kzalloc(sizeof(struct pp_eventmgr), GFP_KERNEL);
72 if (eventmgr == NULL)
73 return -ENOMEM;
74
75 eventmgr->hwmgr = handle->hwmgr;
76 handle->eventmgr = eventmgr;
77
78 eventmgr->platform_descriptor = &(eventmgr->hwmgr->platform_descriptor);
79 eventmgr->pp_eventmgr_init = pem_init;
80 eventmgr->pp_eventmgr_fini = pem_fini;
81
82 return result;
83 }
84
85 int eventmgr_fini(struct pp_eventmgr *eventmgr)
86 {
87 kfree(eventmgr);
88 return 0;
89 }
90
91 static int pem_handle_event_unlocked(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *data)
92 {
93 if (eventmgr == NULL || event >= AMD_PP_EVENT_MAX || data == NULL)
94 return -EINVAL;
95
96 return pem_excute_event_chain(eventmgr, eventmgr->event_chain[event], data);
97 }
98
99 int pem_handle_event(struct pp_eventmgr *eventmgr, enum amd_pp_event event, struct pem_event_data *event_data)
100 {
101 int r = 0;
102
103 r = pem_handle_event_unlocked(eventmgr, event, event_data);
104
105 return r;
106 }
107
108 bool pem_is_hw_access_blocked(struct pp_eventmgr *eventmgr)
109 {
110 return (eventmgr->block_adjust_power_state || phm_is_hw_access_blocked(eventmgr->hwmgr));
111 }