1254885Sdumbbell/*
2254885Sdumbbell * Copyright 2008 Advanced Micro Devices, Inc.
3254885Sdumbbell *
4254885Sdumbbell * Permission is hereby granted, free of charge, to any person obtaining a
5254885Sdumbbell * copy of this software and associated documentation files (the "Software"),
6254885Sdumbbell * to deal in the Software without restriction, including without limitation
7254885Sdumbbell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8254885Sdumbbell * and/or sell copies of the Software, and to permit persons to whom the
9254885Sdumbbell * Software is furnished to do so, subject to the following conditions:
10254885Sdumbbell *
11254885Sdumbbell * The above copyright notice and this permission notice shall be included in
12254885Sdumbbell * all copies or substantial portions of the Software.
13254885Sdumbbell *
14254885Sdumbbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15254885Sdumbbell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16254885Sdumbbell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17254885Sdumbbell * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18254885Sdumbbell * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19254885Sdumbbell * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20254885Sdumbbell * OTHER DEALINGS IN THE SOFTWARE.
21254885Sdumbbell *
22254885Sdumbbell * Author: Stanislaw Skowronek
23254885Sdumbbell */
24254885Sdumbbell
25254885Sdumbbell#include <sys/cdefs.h>
26254885Sdumbbell__FBSDID("$FreeBSD$");
27254885Sdumbbell
28254885Sdumbbell#ifndef ATOM_H
29254885Sdumbbell#define ATOM_H
30254885Sdumbbell
31254885Sdumbbell#include <dev/drm2/drmP.h>
32254885Sdumbbell
33254885Sdumbbell#define ATOM_BIOS_MAGIC		0xAA55
34254885Sdumbbell#define ATOM_ATI_MAGIC_PTR	0x30
35254885Sdumbbell#define ATOM_ATI_MAGIC		" 761295520"
36254885Sdumbbell#define ATOM_ROM_TABLE_PTR	0x48
37254885Sdumbbell
38254885Sdumbbell#define ATOM_ROM_MAGIC		"ATOM"
39254885Sdumbbell#define ATOM_ROM_MAGIC_PTR	4
40254885Sdumbbell
41254885Sdumbbell#define ATOM_ROM_MSG_PTR	0x10
42254885Sdumbbell#define ATOM_ROM_CMD_PTR	0x1E
43254885Sdumbbell#define ATOM_ROM_DATA_PTR	0x20
44254885Sdumbbell
45254885Sdumbbell#define ATOM_CMD_INIT		0
46254885Sdumbbell#define ATOM_CMD_SETSCLK	0x0A
47254885Sdumbbell#define ATOM_CMD_SETMCLK	0x0B
48254885Sdumbbell#define ATOM_CMD_SETPCLK	0x0C
49254885Sdumbbell#define ATOM_CMD_SPDFANCNTL	0x39
50254885Sdumbbell
51254885Sdumbbell#define ATOM_DATA_FWI_PTR	0xC
52254885Sdumbbell#define ATOM_DATA_IIO_PTR	0x32
53254885Sdumbbell
54254885Sdumbbell#define ATOM_FWI_DEFSCLK_PTR	8
55254885Sdumbbell#define ATOM_FWI_DEFMCLK_PTR	0xC
56254885Sdumbbell#define ATOM_FWI_MAXSCLK_PTR	0x24
57254885Sdumbbell#define ATOM_FWI_MAXMCLK_PTR	0x28
58254885Sdumbbell
59254885Sdumbbell#define ATOM_CT_SIZE_PTR	0
60254885Sdumbbell#define ATOM_CT_WS_PTR		4
61254885Sdumbbell#define ATOM_CT_PS_PTR		5
62254885Sdumbbell#define ATOM_CT_PS_MASK		0x7F
63254885Sdumbbell#define ATOM_CT_CODE_PTR	6
64254885Sdumbbell
65254885Sdumbbell#define ATOM_OP_CNT		123
66254885Sdumbbell#define ATOM_OP_EOT		91
67254885Sdumbbell
68254885Sdumbbell#define ATOM_CASE_MAGIC		0x63
69254885Sdumbbell#define ATOM_CASE_END		0x5A5A
70254885Sdumbbell
71254885Sdumbbell#define ATOM_ARG_REG		0
72254885Sdumbbell#define ATOM_ARG_PS		1
73254885Sdumbbell#define ATOM_ARG_WS		2
74254885Sdumbbell#define ATOM_ARG_FB		3
75254885Sdumbbell#define ATOM_ARG_ID		4
76254885Sdumbbell#define ATOM_ARG_IMM		5
77254885Sdumbbell#define ATOM_ARG_PLL		6
78254885Sdumbbell#define ATOM_ARG_MC		7
79254885Sdumbbell
80254885Sdumbbell#define ATOM_SRC_DWORD		0
81254885Sdumbbell#define ATOM_SRC_WORD0		1
82254885Sdumbbell#define ATOM_SRC_WORD8		2
83254885Sdumbbell#define ATOM_SRC_WORD16		3
84254885Sdumbbell#define ATOM_SRC_BYTE0		4
85254885Sdumbbell#define ATOM_SRC_BYTE8		5
86254885Sdumbbell#define ATOM_SRC_BYTE16		6
87254885Sdumbbell#define ATOM_SRC_BYTE24		7
88254885Sdumbbell
89254885Sdumbbell#define ATOM_WS_QUOTIENT	0x40
90254885Sdumbbell#define ATOM_WS_REMAINDER	0x41
91254885Sdumbbell#define ATOM_WS_DATAPTR		0x42
92254885Sdumbbell#define ATOM_WS_SHIFT		0x43
93254885Sdumbbell#define ATOM_WS_OR_MASK		0x44
94254885Sdumbbell#define ATOM_WS_AND_MASK	0x45
95254885Sdumbbell#define ATOM_WS_FB_WINDOW	0x46
96254885Sdumbbell#define ATOM_WS_ATTRIBUTES	0x47
97254885Sdumbbell#define ATOM_WS_REGPTR  	0x48
98254885Sdumbbell
99254885Sdumbbell#define ATOM_IIO_NOP		0
100254885Sdumbbell#define ATOM_IIO_START		1
101254885Sdumbbell#define ATOM_IIO_READ		2
102254885Sdumbbell#define ATOM_IIO_WRITE		3
103254885Sdumbbell#define ATOM_IIO_CLEAR		4
104254885Sdumbbell#define ATOM_IIO_SET		5
105254885Sdumbbell#define ATOM_IIO_MOVE_INDEX	6
106254885Sdumbbell#define ATOM_IIO_MOVE_ATTR	7
107254885Sdumbbell#define ATOM_IIO_MOVE_DATA	8
108254885Sdumbbell#define ATOM_IIO_END		9
109254885Sdumbbell
110254885Sdumbbell#define ATOM_IO_MM		0
111254885Sdumbbell#define ATOM_IO_PCI		1
112254885Sdumbbell#define ATOM_IO_SYSIO		2
113254885Sdumbbell#define ATOM_IO_IIO		0x80
114254885Sdumbbell
115254885Sdumbbellstruct card_info {
116254885Sdumbbell	struct drm_device *dev;
117254885Sdumbbell	void (* reg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
118254885Sdumbbell        uint32_t (* reg_read)(struct card_info *, uint32_t);          /*  filled by driver */
119254885Sdumbbell	void (* ioreg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
120254885Sdumbbell        uint32_t (* ioreg_read)(struct card_info *, uint32_t);          /*  filled by driver */
121254885Sdumbbell	void (* mc_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
122254885Sdumbbell        uint32_t (* mc_read)(struct card_info *, uint32_t);          /*  filled by driver */
123254885Sdumbbell	void (* pll_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
124254885Sdumbbell        uint32_t (* pll_read)(struct card_info *, uint32_t);          /*  filled by driver */
125254885Sdumbbell};
126254885Sdumbbell
127254885Sdumbbellstruct atom_context {
128254885Sdumbbell	struct card_info *card;
129254885Sdumbbell	struct sx mutex;
130254885Sdumbbell	void *bios;
131254885Sdumbbell	uint32_t cmd_table, data_table;
132254885Sdumbbell	uint16_t *iio;
133254885Sdumbbell
134254885Sdumbbell	uint16_t data_block;
135254885Sdumbbell	uint32_t fb_base;
136254885Sdumbbell	uint32_t divmul[2];
137254885Sdumbbell	uint16_t io_attr;
138254885Sdumbbell	uint16_t reg_block;
139254885Sdumbbell	uint8_t shift;
140254885Sdumbbell	int cs_equal, cs_above;
141254885Sdumbbell	int io_mode;
142254885Sdumbbell	uint32_t *scratch;
143254885Sdumbbell	int scratch_size_bytes;
144254885Sdumbbell};
145254885Sdumbbell
146254885Sdumbbellextern int atom_debug;
147254885Sdumbbell
148254885Sdumbbellstruct atom_context *atom_parse(struct card_info *, void *);
149254885Sdumbbellint atom_execute_table(struct atom_context *, int, uint32_t *);
150254885Sdumbbellint atom_asic_init(struct atom_context *);
151254885Sdumbbellvoid atom_destroy(struct atom_context *);
152254885Sdumbbellbool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
153254885Sdumbbell			    uint8_t *frev, uint8_t *crev, uint16_t *data_start);
154254885Sdumbbellbool atom_parse_cmd_header(struct atom_context *ctx, int index,
155254885Sdumbbell			   uint8_t *frev, uint8_t *crev);
156254885Sdumbbellint atom_allocate_fb_scratch(struct atom_context *ctx);
157254885Sdumbbell#include "atom-types.h"
158254885Sdumbbell#include "atombios.h"
159254885Sdumbbell#include "ObjectID.h"
160254885Sdumbbell
161254885Sdumbbell#endif
162