1/*
2 * Copyright 2006-2007 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
23/*++
24
25Module Name:
26
27CD_Struct.h
28
29Abstract:
30
31Defines Script Language commands
32
33Revision History:
34
35NEG:26.08.2002	Initiated.
36--*/
37
38#ifndef _CD_STRUCTS_H_
39#define _CD_STRUCTS_H_
40
41#include "CD_binding.h"
42
43/* Endaianness should be specified before inclusion,
44 * default to little endian
45 */
46#ifndef ATOM_BIG_ENDIAN
47#error Endian not specified
48#endif
49
50#ifdef		UEFI_BUILD
51typedef	UINT16**	PTABLE_UNIT_TYPE;
52typedef	UINTN		TABLE_UNIT_TYPE;
53#else
54typedef	UINT16*		PTABLE_UNIT_TYPE;
55typedef	UINT16		TABLE_UNIT_TYPE;
56#endif
57
58#include <regsdef.h> //This important file is dynamically generated based on the ASIC!!!!
59
60#define PARSER_MAJOR_REVISION 5
61#define PARSER_MINOR_REVISION 0
62
63//#include "atombios.h"
64#if (PARSER_TYPE==DRIVER_TYPE_PARSER)
65#ifdef FGL_LINUX
66#pragma pack(push,1)
67#else
68#pragma pack(push)
69#pragma pack(1)
70#endif
71#endif
72
73#include "CD_Common_Types.h"
74#include "CD_Opcodes.h"
75typedef UINT16				WORK_SPACE_SIZE;
76typedef enum _CD_STATUS{
77    CD_SUCCESS,
78    CD_CALL_TABLE,
79    CD_COMPLETED=0x10,
80    CD_GENERAL_ERROR=0x80,
81    CD_INVALID_OPCODE,
82    CD_NOT_IMPLEMENTED,
83    CD_EXEC_TABLE_NOT_FOUND,
84    CD_EXEC_PARAMETER_ERROR,
85    CD_EXEC_PARSER_ERROR,
86    CD_INVALID_DESTINATION_TYPE,
87    CD_UNEXPECTED_BEHAVIOR,
88    CD_INVALID_SWITCH_OPERAND_SIZE
89}CD_STATUS;
90
91#define PARSER_STRINGS                  0
92#define PARSER_DEC                      1
93#define PARSER_HEX                      2
94
95#define DB_CURRENT_COMMAND_TABLE	0xFF
96
97#define TABLE_FORMAT_BIOS		0
98#define TABLE_FORMAT_EASF		1
99
100#define EASF_TABLE_INDEX_MASK		0xfc
101#define EASF_TABLE_ATTR_MASK		0x03
102
103#define CD_ERROR(a)    (((INTN) (a)) > CD_COMPLETED)
104#define CD_ERROR_OR_COMPLETED(a)    (((INTN) (a)) > CD_SUCCESS)
105
106
107#if (BIOS_PARSER==1)
108#ifdef _H2INC
109#define STACK_BASED
110#else
111extern __segment farstack;
112#define STACK_BASED __based(farstack)
113#endif
114#else
115#define STACK_BASED
116#endif
117
118typedef enum _COMPARE_FLAGS{
119    Below,
120    Equal,
121    Above,
122    NotEqual,
123    Overflow,
124    NoCondition
125}COMPARE_FLAGS;
126
127typedef UINT16 IO_BASE_ADDR;
128
129typedef struct _BUS_DEV_FUNC_PCI_ADDR{
130    UINT8   Register;
131    UINT8   Function;
132    UINT8   Device;
133    UINT8   Bus;
134} BUS_DEV_FUNC_PCI_ADDR;
135
136typedef struct _BUS_DEV_FUNC{
137    UINT8   Function : 3;
138    UINT8   Device   : 5;
139    UINT8   Bus;
140} BUS_DEV_FUNC;
141
142#ifndef	UEFI_BUILD
143typedef struct _PCI_CONFIG_ACCESS_CF8{
144    UINT32  Reg     : 8;
145    UINT32  Func    : 3;
146    UINT32  Dev     : 5;
147    UINT32  Bus     : 8;
148    UINT32  Reserved: 7;
149    UINT32  Enable  : 1;
150} PCI_CONFIG_ACCESS_CF8;
151#endif
152
153typedef enum _MEM_RESOURCE {
154    Stack_Resource,
155    FrameBuffer_Resource,
156    BIOS_Image_Resource
157}MEM_RESOURCE;
158
159typedef enum _PORTS{
160    ATI_RegsPort,
161    PCI_Port,
162    SystemIO_Port
163}PORTS;
164
165typedef enum _OPERAND_TYPE {
166    typeRegister,
167    typeParamSpace,
168    typeWorkSpace,
169    typeFrameBuffer,
170    typeIndirect,
171    typeDirect,
172    typePLL,
173    typeMC
174}OPERAND_TYPE;
175
176typedef enum _DESTINATION_OPERAND_TYPE {
177    destRegister,
178    destParamSpace,
179    destWorkSpace,
180    destFrameBuffer,
181    destPLL,
182    destMC
183}DESTINATION_OPERAND_TYPE;
184
185typedef enum _SOURCE_OPERAND_TYPE {
186    sourceRegister,
187    sourceParamSpace,
188    sourceWorkSpace,
189    sourceFrameBuffer,
190    sourceIndirect,
191    sourceDirect,
192    sourcePLL,
193    sourceMC
194}SOURCE_OPERAND_TYPE;
195
196typedef enum _ALIGNMENT_TYPE {
197    alignmentDword,
198    alignmentLowerWord,
199    alignmentMiddleWord,
200    alignmentUpperWord,
201    alignmentByte0,
202    alignmentByte1,
203    alignmentByte2,
204    alignmentByte3
205}ALIGNMENT_TYPE;
206
207
208#define INDIRECT_IO_READ    0
209#define INDIRECT_IO_WRITE   0x80
210#define INDIRECT_IO_MM      0
211#define INDIRECT_IO_PLL     1
212#define INDIRECT_IO_MC      2
213
214typedef struct _PARAMETERS_TYPE{
215    UINT8	Destination;
216    UINT8	Source;
217}PARAMETERS_TYPE;
218/* The following structures don't used to allocate any type of objects(variables).
219   they are serve the only purpose: Get proper access to data(commands), found in the tables*/
220typedef struct _PA_BYTE_BYTE{
221    UINT8		PA_Destination;
222    UINT8		PA_Source;
223    UINT8		PA_Padding[8];
224}PA_BYTE_BYTE;
225typedef struct _PA_BYTE_WORD{
226    UINT8		PA_Destination;
227    UINT16		PA_Source;
228    UINT8		PA_Padding[7];
229}PA_BYTE_WORD;
230typedef struct _PA_BYTE_DWORD{
231    UINT8		PA_Destination;
232    UINT32		PA_Source;
233    UINT8		PA_Padding[5];
234}PA_BYTE_DWORD;
235typedef struct _PA_WORD_BYTE{
236    UINT16		PA_Destination;
237    UINT8		PA_Source;
238    UINT8		PA_Padding[7];
239}PA_WORD_BYTE;
240typedef struct _PA_WORD_WORD{
241    UINT16		PA_Destination;
242    UINT16		PA_Source;
243    UINT8		PA_Padding[6];
244}PA_WORD_WORD;
245typedef struct _PA_WORD_DWORD{
246    UINT16		PA_Destination;
247    UINT32		PA_Source;
248    UINT8		PA_Padding[4];
249}PA_WORD_DWORD;
250typedef struct _PA_WORD_XX{
251    UINT16		PA_Destination;
252    UINT8		PA_Padding[8];
253}PA_WORD_XX;
254typedef struct _PA_BYTE_XX{
255    UINT8		PA_Destination;
256    UINT8		PA_Padding[9];
257}PA_BYTE_XX;
258/*The following 6 definitions used for Mask operation*/
259typedef struct _PA_BYTE_BYTE_BYTE{
260    UINT8		PA_Destination;
261    UINT8		PA_AndMaskByte;
262    UINT8		PA_OrMaskByte;
263    UINT8		PA_Padding[7];
264}PA_BYTE_BYTE_BYTE;
265typedef struct _PA_BYTE_WORD_WORD{
266    UINT8		PA_Destination;
267    UINT16		PA_AndMaskWord;
268    UINT16		PA_OrMaskWord;
269    UINT8		PA_Padding[5];
270}PA_BYTE_WORD_WORD;
271typedef struct _PA_BYTE_DWORD_DWORD{
272    UINT8		PA_Destination;
273    UINT32		PA_AndMaskDword;
274    UINT32		PA_OrMaskDword;
275    UINT8		PA_Padding;
276}PA_BYTE_DWORD_DWORD;
277typedef struct _PA_WORD_BYTE_BYTE{
278    UINT16		PA_Destination;
279    UINT8		PA_AndMaskByte;
280    UINT8		PA_OrMaskByte;
281    UINT8		PA_Padding[6];
282}PA_WORD_BYTE_BYTE;
283typedef struct _PA_WORD_WORD_WORD{
284    UINT16		PA_Destination;
285    UINT16		PA_AndMaskWord;
286    UINT16		PA_OrMaskWord;
287    UINT8		PA_Padding[4];
288}PA_WORD_WORD_WORD;
289typedef struct _PA_WORD_DWORD_DWORD{
290    UINT16		PA_Destination;
291    UINT32		PA_AndMaskDword;
292    UINT32		PA_OrMaskDword;
293}PA_WORD_DWORD_DWORD;
294
295
296typedef union _PARAMETER_ACCESS {
297    PA_BYTE_XX			ByteXX;
298    PA_BYTE_BYTE		ByteByte;
299    PA_BYTE_WORD		ByteWord;
300    PA_BYTE_DWORD		ByteDword;
301    PA_WORD_BYTE		WordByte;
302    PA_WORD_WORD		WordWord;
303    PA_WORD_DWORD		WordDword;
304    PA_WORD_XX			WordXX;
305/*The following 6 definitions used for Mask operation*/
306    PA_BYTE_BYTE_BYTE	ByteByteAndByteOr;
307    PA_BYTE_WORD_WORD	ByteWordAndWordOr;
308    PA_BYTE_DWORD_DWORD	ByteDwordAndDwordOr;
309    PA_WORD_BYTE_BYTE	WordByteAndByteOr;
310    PA_WORD_WORD_WORD	WordWordAndWordOr;
311    PA_WORD_DWORD_DWORD	WordDwordAndDwordOr;
312}PARAMETER_ACCESS;
313
314typedef	struct _COMMAND_ATTRIBUTE {
315#if ATOM_BIG_ENDIAN
316    UINT8		DestinationAlignment:2;
317    UINT8		SourceAlignment:3;
318    UINT8		Source:3;
319#else
320    UINT8		Source:3;
321    UINT8		SourceAlignment:3;
322    UINT8		DestinationAlignment:2;
323#endif
324}COMMAND_ATTRIBUTE;
325
326typedef struct _SOURCE_DESTINATION_ALIGNMENT{
327    UINT8					DestAlignment;
328    UINT8					SrcAlignment;
329}SOURCE_DESTINATION_ALIGNMENT;
330typedef struct _MULTIPLICATION_RESULT{
331    UINT32									Low32Bit;
332    UINT32									High32Bit;
333}MULTIPLICATION_RESULT;
334typedef struct _DIVISION_RESULT{
335    UINT32									Quotient32;
336    UINT32									Reminder32;
337}DIVISION_RESULT;
338typedef union _DIVISION_MULTIPLICATION_RESULT{
339    MULTIPLICATION_RESULT		Multiplication;
340    DIVISION_RESULT					Division;
341}DIVISION_MULTIPLICATION_RESULT;
342typedef struct _COMMAND_HEADER {
343    UINT8					Opcode;
344    COMMAND_ATTRIBUTE		Attribute;
345}COMMAND_HEADER;
346
347typedef struct _GENERIC_ATTRIBUTE_COMMAND{
348    COMMAND_HEADER			Header;
349    PARAMETER_ACCESS		Parameters;
350} GENERIC_ATTRIBUTE_COMMAND;
351
352typedef struct	_COMMAND_TYPE_1{
353    UINT8					Opcode;
354    PARAMETER_ACCESS		Parameters;
355} COMMAND_TYPE_1;
356
357typedef struct	_COMMAND_TYPE_OPCODE_OFFSET16{
358    UINT8					Opcode;
359    UINT16					CD_Offset16;
360} COMMAND_TYPE_OPCODE_OFFSET16;
361
362typedef struct	_COMMAND_TYPE_OPCODE_OFFSET32{
363    UINT8					Opcode;
364    UINT32					CD_Offset32;
365} COMMAND_TYPE_OPCODE_OFFSET32;
366
367typedef struct	_COMMAND_TYPE_OPCODE_VALUE_BYTE{
368    UINT8					Opcode;
369    UINT8					Value;
370} COMMAND_TYPE_OPCODE_VALUE_BYTE;
371
372typedef union  _COMMAND_SPECIFIC_UNION{
373    UINT8	ContinueSwitch;
374    UINT8	ControlOperandSourcePosition;
375    UINT8	IndexInMasterTable;
376} COMMAND_SPECIFIC_UNION;
377
378
379typedef struct _CD_GENERIC_BYTE{
380#if ATOM_BIG_ENDIAN
381    UINT16					PS_SizeInDwordsUsedByCallingTable:5;
382    UINT16					CurrentPort:2;
383    UINT16					CommandAccessType:3;
384    UINT16					CurrentParameterSize:3;
385    UINT16					CommandType:3;
386#else
387    UINT16					CommandType:3;
388    UINT16					CurrentParameterSize:3;
389    UINT16					CommandAccessType:3;
390    UINT16					CurrentPort:2;
391    UINT16					PS_SizeInDwordsUsedByCallingTable:5;
392#endif
393}CD_GENERIC_BYTE;
394
395typedef UINT8	COMMAND_TYPE_OPCODE_ONLY;
396
397typedef UINT8  COMMAND_HEADER_POINTER;
398
399
400#if (PARSER_TYPE==BIOS_TYPE_PARSER)
401
402typedef struct _DEVICE_DATA	{
403    UINT32	STACK_BASED		*pParameterSpace;
404    UINT8									*pBIOS_Image;
405    UINT8							format;
406#if (IO_INTERFACE==PARSER_INTERFACE)
407    IO_BASE_ADDR					IOBase;
408#endif
409}  DEVICE_DATA;
410
411#else
412
413typedef struct _DEVICE_DATA	{
414    UINT32							*pParameterSpace;
415    VOID								*CAIL;
416    UINT8 							*pBIOS_Image;
417    UINT32							format;
418} DEVICE_DATA;
419
420#endif
421
422struct _PARSER_TEMP_DATA;
423typedef UINT32 WORKSPACE_POINTER;
424
425struct	_WORKING_TABLE_DATA{
426    UINT8																		* pTableHead;
427    COMMAND_HEADER_POINTER									* IP;			// Commands pointer
428    WORKSPACE_POINTER	STACK_BASED						* pWorkSpace;
429    struct _WORKING_TABLE_DATA STACK_BASED  * prevWorkingTableData;
430};
431
432
433
434typedef struct	_PARSER_TEMP_DATA{
435    DEVICE_DATA	STACK_BASED							*pDeviceData;
436    struct _WORKING_TABLE_DATA STACK_BASED		*pWorkingTableData;
437    UINT32															SourceData32;
438    UINT32															DestData32;
439    DIVISION_MULTIPLICATION_RESULT			MultiplicationOrDivision;
440    UINT32															Index;
441    UINT32					                    CurrentFB_Window;
442    UINT32					                    IndirectData;
443    UINT16															CurrentRegBlock;
444    TABLE_UNIT_TYPE													CurrentDataBlock;
445    UINT16                              AttributesData;
446//  UINT8                               *IndirectIOTable;
447    UINT8                               *IndirectIOTablePointer;
448    GENERIC_ATTRIBUTE_COMMAND						*pCmd;			//CurrentCommand;
449    SOURCE_DESTINATION_ALIGNMENT  			CD_Mask;
450    PARAMETERS_TYPE											ParametersType;
451    CD_GENERIC_BYTE											Multipurpose;
452    UINT8																CompareFlags;
453    COMMAND_SPECIFIC_UNION							CommandSpecific;
454    CD_STATUS														Status;
455    UINT8                               Shift2MaskConverter;
456    UINT8															  CurrentPortID;
457} PARSER_TEMP_DATA;
458
459
460typedef struct _WORKING_TABLE_DATA  WORKING_TABLE_DATA;
461
462
463
464typedef VOID (*COMMANDS_DECODER)(PARSER_TEMP_DATA STACK_BASED * pParserTempData);
465typedef VOID (*WRITE_IO_FUNCTION)(PARSER_TEMP_DATA STACK_BASED * pParserTempData);
466typedef UINT32 (*READ_IO_FUNCTION)(PARSER_TEMP_DATA STACK_BASED * pParserTempData);
467typedef UINT32 (*CD_GET_PARAMETERS)(PARSER_TEMP_DATA STACK_BASED * pParserTempData);
468
469typedef struct _COMMANDS_PROPERTIES
470{
471    COMMANDS_DECODER  function;
472    UINT8             destination;
473    UINT8             headersize;
474} COMMANDS_PROPERTIES;
475
476typedef struct _INDIRECT_IO_PARSER_COMMANDS
477{
478    COMMANDS_DECODER  func;
479    UINT8             csize;
480} INDIRECT_IO_PARSER_COMMANDS;
481
482#if (PARSER_TYPE==DRIVER_TYPE_PARSER)
483#pragma pack(pop)
484#endif
485
486#endif
487