1 /*
2  * Copyright 2016 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  * Authors: AMD
23  *
24  */
25 
26 #include "dm_services.h"
27 #include "dm_helpers.h"
28 #include "core_types.h"
29 #include "resource.h"
30 #include "dce/dce_hwseq.h"
31 #include "vmid.h"
32 #include "reg_helper.h"
33 #include "hw/clk_mgr.h"
34 
35 
36 #define DC_LOGGER_INIT(logger)
37 
38 #define CTX \
39 	hws->ctx
40 #define REG(reg)\
41 	hws->regs->reg
42 
43 #undef FN
44 #define FN(reg_name, field_name) \
45 	hws->shifts->field_name, hws->masks->field_name
46 
47 /* Temporary read settings, future will get values from kmd directly */
48 static void mmhub_update_page_table_config(struct dcn_hubbub_phys_addr_config *config,
49 		struct dce_hwseq *hws)
50 {
51 	uint32_t page_table_base_hi;
52 	uint32_t page_table_base_lo;
53 
54 	REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_HI32,
55 			PAGE_DIRECTORY_ENTRY_HI32, &page_table_base_hi);
56 	REG_GET(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR_LO32,
57 			PAGE_DIRECTORY_ENTRY_LO32, &page_table_base_lo);
58 
59 	config->gart_config.page_table_base_addr = ((uint64_t)page_table_base_hi << 32) | page_table_base_lo;
60 
61 }
62 
63 int dcn21_init_sys_ctx(struct dce_hwseq *hws, struct dc *dc, struct dc_phy_addr_space_config *pa_config)
64 {
65 	struct dcn_hubbub_phys_addr_config config;
66 
67 	config.system_aperture.fb_top = pa_config->system_aperture.fb_top;
68 	config.system_aperture.fb_offset = pa_config->system_aperture.fb_offset;
69 	config.system_aperture.fb_base = pa_config->system_aperture.fb_base;
70 	config.system_aperture.agp_top = pa_config->system_aperture.agp_top;
71 	config.system_aperture.agp_bot = pa_config->system_aperture.agp_bot;
72 	config.system_aperture.agp_base = pa_config->system_aperture.agp_base;
73 	config.gart_config.page_table_start_addr = pa_config->gart_config.page_table_start_addr;
74 	config.gart_config.page_table_end_addr = pa_config->gart_config.page_table_end_addr;
75 	config.gart_config.page_table_base_addr = pa_config->gart_config.page_table_base_addr;
76 
77 	mmhub_update_page_table_config(&config, hws);
78 
79 	return dc->res_pool->hubbub->funcs->init_dchub_sys_ctx(dc->res_pool->hubbub, &config);
80 }
81 
82 // work around for Renoir s0i3, if register is programmed, bypass golden init.
83 
84 bool dcn21_s0i3_golden_init_wa(struct dc *dc)
85 {
86 	struct dce_hwseq *hws = dc->hwseq;
87 	uint32_t value = 0;
88 
89 	value = REG_READ(MICROSECOND_TIME_BASE_DIV);
90 
91 	return value != 0x00120464;
92 }
93 
94 void dcn21_exit_optimized_pwr_state(
95 		const struct dc *dc,
96 		struct dc_state *context)
97 {
98 	dc->clk_mgr->funcs->update_clocks(
99 			dc->clk_mgr,
100 			context,
101 			false);
102 }
103 
104 void dcn21_optimize_pwr_state(
105 		const struct dc *dc,
106 		struct dc_state *context)
107 {
108 	dc->clk_mgr->funcs->update_clocks(
109 			dc->clk_mgr,
110 			context,
111 			true);
112 }
113 
114