atom.h revision 1.1.1.2 1 /* $NetBSD: atom.h,v 1.1.1.2 2021/12/18 20:11:13 riastradh Exp $ */
2
3 /*
4 * Copyright 2008 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 * Author: Stanislaw Skowronek
25 */
26
27 #ifndef ATOM_H
28 #define ATOM_H
29
30 #include <linux/types.h>
31
32 struct drm_device;
33
34 #define ATOM_BIOS_MAGIC 0xAA55
35 #define ATOM_ATI_MAGIC_PTR 0x30
36 #define ATOM_ATI_MAGIC " 761295520"
37 #define ATOM_ROM_TABLE_PTR 0x48
38 #define ATOM_ROM_PART_NUMBER_PTR 0x6E
39
40 #define ATOM_ROM_MAGIC "ATOM"
41 #define ATOM_ROM_MAGIC_PTR 4
42
43 #define ATOM_ROM_MSG_PTR 0x10
44 #define ATOM_ROM_CMD_PTR 0x1E
45 #define ATOM_ROM_DATA_PTR 0x20
46
47 #define ATOM_CMD_INIT 0
48 #define ATOM_CMD_SETSCLK 0x0A
49 #define ATOM_CMD_SETMCLK 0x0B
50 #define ATOM_CMD_SETPCLK 0x0C
51 #define ATOM_CMD_SPDFANCNTL 0x39
52
53 #define ATOM_DATA_FWI_PTR 0xC
54 #define ATOM_DATA_IIO_PTR 0x32
55
56 #define ATOM_FWI_DEFSCLK_PTR 8
57 #define ATOM_FWI_DEFMCLK_PTR 0xC
58 #define ATOM_FWI_MAXSCLK_PTR 0x24
59 #define ATOM_FWI_MAXMCLK_PTR 0x28
60
61 #define ATOM_CT_SIZE_PTR 0
62 #define ATOM_CT_WS_PTR 4
63 #define ATOM_CT_PS_PTR 5
64 #define ATOM_CT_PS_MASK 0x7F
65 #define ATOM_CT_CODE_PTR 6
66
67 #define ATOM_OP_CNT 127
68 #define ATOM_OP_EOT 91
69
70 #define ATOM_CASE_MAGIC 0x63
71 #define ATOM_CASE_END 0x5A5A
72
73 #define ATOM_ARG_REG 0
74 #define ATOM_ARG_PS 1
75 #define ATOM_ARG_WS 2
76 #define ATOM_ARG_FB 3
77 #define ATOM_ARG_ID 4
78 #define ATOM_ARG_IMM 5
79 #define ATOM_ARG_PLL 6
80 #define ATOM_ARG_MC 7
81
82 #define ATOM_SRC_DWORD 0
83 #define ATOM_SRC_WORD0 1
84 #define ATOM_SRC_WORD8 2
85 #define ATOM_SRC_WORD16 3
86 #define ATOM_SRC_BYTE0 4
87 #define ATOM_SRC_BYTE8 5
88 #define ATOM_SRC_BYTE16 6
89 #define ATOM_SRC_BYTE24 7
90
91 #define ATOM_WS_QUOTIENT 0x40
92 #define ATOM_WS_REMAINDER 0x41
93 #define ATOM_WS_DATAPTR 0x42
94 #define ATOM_WS_SHIFT 0x43
95 #define ATOM_WS_OR_MASK 0x44
96 #define ATOM_WS_AND_MASK 0x45
97 #define ATOM_WS_FB_WINDOW 0x46
98 #define ATOM_WS_ATTRIBUTES 0x47
99 #define ATOM_WS_REGPTR 0x48
100
101 #define ATOM_IIO_NOP 0
102 #define ATOM_IIO_START 1
103 #define ATOM_IIO_READ 2
104 #define ATOM_IIO_WRITE 3
105 #define ATOM_IIO_CLEAR 4
106 #define ATOM_IIO_SET 5
107 #define ATOM_IIO_MOVE_INDEX 6
108 #define ATOM_IIO_MOVE_ATTR 7
109 #define ATOM_IIO_MOVE_DATA 8
110 #define ATOM_IIO_END 9
111
112 #define ATOM_IO_MM 0
113 #define ATOM_IO_PCI 1
114 #define ATOM_IO_SYSIO 2
115 #define ATOM_IO_IIO 0x80
116
117 struct card_info {
118 struct drm_device *dev;
119 void (* reg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */
120 uint32_t (* reg_read)(struct card_info *, uint32_t); /* filled by driver */
121 void (* ioreg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */
122 uint32_t (* ioreg_read)(struct card_info *, uint32_t); /* filled by driver */
123 void (* mc_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */
124 uint32_t (* mc_read)(struct card_info *, uint32_t); /* filled by driver */
125 void (* pll_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */
126 uint32_t (* pll_read)(struct card_info *, uint32_t); /* filled by driver */
127 };
128
129 struct atom_context {
130 struct card_info *card;
131 struct mutex mutex;
132 void *bios;
133 uint32_t cmd_table, data_table;
134 uint16_t *iio;
135
136 uint16_t data_block;
137 uint32_t fb_base;
138 uint32_t divmul[2];
139 uint16_t io_attr;
140 uint16_t reg_block;
141 uint8_t shift;
142 int cs_equal, cs_above;
143 int io_mode;
144 uint32_t *scratch;
145 int scratch_size_bytes;
146 char vbios_version[20];
147 };
148
149 extern int amdgpu_atom_debug;
150
151 struct atom_context *amdgpu_atom_parse(struct card_info *, void *);
152 int amdgpu_atom_execute_table(struct atom_context *, int, uint32_t *);
153 int amdgpu_atom_asic_init(struct atom_context *);
154 void amdgpu_atom_destroy(struct atom_context *);
155 bool amdgpu_atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
156 uint8_t *frev, uint8_t *crev, uint16_t *data_start);
157 bool amdgpu_atom_parse_cmd_header(struct atom_context *ctx, int index,
158 uint8_t *frev, uint8_t *crev);
159 #include "atom-types.h"
160 #include "atombios.h"
161 #include "ObjectID.h"
162
163 #endif
164