blob: fb88e4e5d625815ab213b1011392bce0ef96eae6 [file] [log] [blame]
Rex Zhue92a0372015-09-23 15:14:54 +08001/*
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
31static int pem_init(struct pp_eventmgr *eventmgr)
32{
33 int result = 0;
Bradley Pankow827108d2016-02-22 20:11:47 -050034 struct pem_event_data event_data = { {0} };
Rex Zhue92a0372015-09-23 15:14:54 +080035
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
53static void pem_fini(struct pp_eventmgr *eventmgr)
54{
Bradley Pankow827108d2016-02-22 20:11:47 -050055 struct pem_event_data event_data = { {0} };
Rex Zhue92a0372015-09-23 15:14:54 +080056
57 pem_uninit_featureInfo(eventmgr);
58 pem_unregister_interrupts(eventmgr);
59
60 pem_handle_event(eventmgr, AMD_PP_EVENT_UNINITIALIZE, &event_data);
Rex Zhue92a0372015-09-23 15:14:54 +080061}
62
63int 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
85int eventmgr_fini(struct pp_eventmgr *eventmgr)
86{
87 kfree(eventmgr);
88 return 0;
89}
90
91static 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
99int 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
108bool 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}