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