xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/amd/display/dc/bios/amdgpu_bios_parser_helper.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: amdgpu_bios_parser_helper.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2012-15 Advanced Micro Devices, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: AMD
25  *
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_bios_parser_helper.c,v 1.2 2021/12/18 23:45:00 riastradh Exp $");
30 
31 #include "dm_services.h"
32 
33 #include "atom.h"
34 
35 #include "include/bios_parser_types.h"
36 #include "bios_parser_helper.h"
37 #include "command_table_helper.h"
38 #include "command_table.h"
39 #include "bios_parser_types_internal.h"
40 
bios_get_image(struct dc_bios * bp,uint32_t offset,uint32_t size)41 uint8_t *bios_get_image(struct dc_bios *bp,
42 	uint32_t offset,
43 	uint32_t size)
44 {
45 	if (bp->bios && offset + size < bp->bios_size)
46 		return bp->bios + offset;
47 	else
48 		return NULL;
49 }
50 
51 #include "reg_helper.h"
52 
53 #define CTX \
54 	bios->ctx
55 #define REG(reg)\
56 	(bios->regs->reg)
57 
58 #undef FN
59 #define FN(reg_name, field_name) \
60 		ATOM_ ## field_name ## _SHIFT, ATOM_ ## field_name
61 
bios_is_accelerated_mode(struct dc_bios * bios)62 bool bios_is_accelerated_mode(
63 	struct dc_bios *bios)
64 {
65 	uint32_t acc_mode;
66 	REG_GET(BIOS_SCRATCH_6, S6_ACC_MODE, &acc_mode);
67 	return (acc_mode == 1);
68 }
69 
70 
bios_set_scratch_acc_mode_change(struct dc_bios * bios)71 void bios_set_scratch_acc_mode_change(
72 	struct dc_bios *bios)
73 {
74 	REG_UPDATE(BIOS_SCRATCH_6, S6_ACC_MODE, 1);
75 }
76 
77 
bios_set_scratch_critical_state(struct dc_bios * bios,bool state)78 void bios_set_scratch_critical_state(
79 	struct dc_bios *bios,
80 	bool state)
81 {
82 	uint32_t critial_state = state ? 1 : 0;
83 	REG_UPDATE(BIOS_SCRATCH_6, S6_CRITICAL_STATE, critial_state);
84 }
85 
bios_get_vga_enabled_displays(struct dc_bios * bios)86 uint32_t bios_get_vga_enabled_displays(
87 	struct dc_bios *bios)
88 {
89 	uint32_t active_disp = 1;
90 
91 	active_disp = REG_READ(BIOS_SCRATCH_3) & 0XFFFF;
92 	return active_disp;
93 }
94 
95