162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright 2008 Advanced Micro Devices, Inc. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1262306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci * Author: Stanislaw Skowronek 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#ifndef ATOM_H 2662306a36Sopenharmony_ci#define ATOM_H 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#include <linux/types.h> 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistruct drm_device; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define ATOM_BIOS_MAGIC 0xAA55 3362306a36Sopenharmony_ci#define ATOM_ATI_MAGIC_PTR 0x30 3462306a36Sopenharmony_ci#define ATOM_ATI_MAGIC " 761295520" 3562306a36Sopenharmony_ci#define ATOM_ROM_TABLE_PTR 0x48 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define ATOM_ROM_MAGIC "ATOM" 3862306a36Sopenharmony_ci#define ATOM_ROM_MAGIC_PTR 4 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define ATOM_ROM_MSG_PTR 0x10 4162306a36Sopenharmony_ci#define ATOM_ROM_CMD_PTR 0x1E 4262306a36Sopenharmony_ci#define ATOM_ROM_DATA_PTR 0x20 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define ATOM_CMD_INIT 0 4562306a36Sopenharmony_ci#define ATOM_CMD_SETSCLK 0x0A 4662306a36Sopenharmony_ci#define ATOM_CMD_SETMCLK 0x0B 4762306a36Sopenharmony_ci#define ATOM_CMD_SETPCLK 0x0C 4862306a36Sopenharmony_ci#define ATOM_CMD_SPDFANCNTL 0x39 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define ATOM_DATA_FWI_PTR 0xC 5162306a36Sopenharmony_ci#define ATOM_DATA_IIO_PTR 0x32 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define ATOM_FWI_DEFSCLK_PTR 8 5462306a36Sopenharmony_ci#define ATOM_FWI_DEFMCLK_PTR 0xC 5562306a36Sopenharmony_ci#define ATOM_FWI_MAXSCLK_PTR 0x24 5662306a36Sopenharmony_ci#define ATOM_FWI_MAXMCLK_PTR 0x28 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define ATOM_CT_SIZE_PTR 0 5962306a36Sopenharmony_ci#define ATOM_CT_WS_PTR 4 6062306a36Sopenharmony_ci#define ATOM_CT_PS_PTR 5 6162306a36Sopenharmony_ci#define ATOM_CT_PS_MASK 0x7F 6262306a36Sopenharmony_ci#define ATOM_CT_CODE_PTR 6 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci#define ATOM_OP_CNT 127 6562306a36Sopenharmony_ci#define ATOM_OP_EOT 91 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci#define ATOM_CASE_MAGIC 0x63 6862306a36Sopenharmony_ci#define ATOM_CASE_END 0x5A5A 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci#define ATOM_ARG_REG 0 7162306a36Sopenharmony_ci#define ATOM_ARG_PS 1 7262306a36Sopenharmony_ci#define ATOM_ARG_WS 2 7362306a36Sopenharmony_ci#define ATOM_ARG_FB 3 7462306a36Sopenharmony_ci#define ATOM_ARG_ID 4 7562306a36Sopenharmony_ci#define ATOM_ARG_IMM 5 7662306a36Sopenharmony_ci#define ATOM_ARG_PLL 6 7762306a36Sopenharmony_ci#define ATOM_ARG_MC 7 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci#define ATOM_SRC_DWORD 0 8062306a36Sopenharmony_ci#define ATOM_SRC_WORD0 1 8162306a36Sopenharmony_ci#define ATOM_SRC_WORD8 2 8262306a36Sopenharmony_ci#define ATOM_SRC_WORD16 3 8362306a36Sopenharmony_ci#define ATOM_SRC_BYTE0 4 8462306a36Sopenharmony_ci#define ATOM_SRC_BYTE8 5 8562306a36Sopenharmony_ci#define ATOM_SRC_BYTE16 6 8662306a36Sopenharmony_ci#define ATOM_SRC_BYTE24 7 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci#define ATOM_WS_QUOTIENT 0x40 8962306a36Sopenharmony_ci#define ATOM_WS_REMAINDER 0x41 9062306a36Sopenharmony_ci#define ATOM_WS_DATAPTR 0x42 9162306a36Sopenharmony_ci#define ATOM_WS_SHIFT 0x43 9262306a36Sopenharmony_ci#define ATOM_WS_OR_MASK 0x44 9362306a36Sopenharmony_ci#define ATOM_WS_AND_MASK 0x45 9462306a36Sopenharmony_ci#define ATOM_WS_FB_WINDOW 0x46 9562306a36Sopenharmony_ci#define ATOM_WS_ATTRIBUTES 0x47 9662306a36Sopenharmony_ci#define ATOM_WS_REGPTR 0x48 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define ATOM_IIO_NOP 0 9962306a36Sopenharmony_ci#define ATOM_IIO_START 1 10062306a36Sopenharmony_ci#define ATOM_IIO_READ 2 10162306a36Sopenharmony_ci#define ATOM_IIO_WRITE 3 10262306a36Sopenharmony_ci#define ATOM_IIO_CLEAR 4 10362306a36Sopenharmony_ci#define ATOM_IIO_SET 5 10462306a36Sopenharmony_ci#define ATOM_IIO_MOVE_INDEX 6 10562306a36Sopenharmony_ci#define ATOM_IIO_MOVE_ATTR 7 10662306a36Sopenharmony_ci#define ATOM_IIO_MOVE_DATA 8 10762306a36Sopenharmony_ci#define ATOM_IIO_END 9 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define ATOM_IO_MM 0 11062306a36Sopenharmony_ci#define ATOM_IO_PCI 1 11162306a36Sopenharmony_ci#define ATOM_IO_SYSIO 2 11262306a36Sopenharmony_ci#define ATOM_IO_IIO 0x80 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#define STRLEN_NORMAL 32 11562306a36Sopenharmony_ci#define STRLEN_LONG 64 11662306a36Sopenharmony_ci#define STRLEN_VERYLONG 254 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistruct card_info { 11962306a36Sopenharmony_ci struct drm_device *dev; 12062306a36Sopenharmony_ci void (*reg_write)(struct card_info *info, 12162306a36Sopenharmony_ci u32 reg, uint32_t val); /* filled by driver */ 12262306a36Sopenharmony_ci uint32_t (*reg_read)(struct card_info *info, uint32_t reg); /* filled by driver */ 12362306a36Sopenharmony_ci void (*mc_write)(struct card_info *info, 12462306a36Sopenharmony_ci u32 reg, uint32_t val); /* filled by driver */ 12562306a36Sopenharmony_ci uint32_t (*mc_read)(struct card_info *info, uint32_t reg); /* filled by driver */ 12662306a36Sopenharmony_ci void (*pll_write)(struct card_info *info, 12762306a36Sopenharmony_ci u32 reg, uint32_t val); /* filled by driver */ 12862306a36Sopenharmony_ci uint32_t (*pll_read)(struct card_info *info, uint32_t reg); /* filled by driver */ 12962306a36Sopenharmony_ci}; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cistruct atom_context { 13262306a36Sopenharmony_ci struct card_info *card; 13362306a36Sopenharmony_ci struct mutex mutex; 13462306a36Sopenharmony_ci void *bios; 13562306a36Sopenharmony_ci uint32_t cmd_table, data_table; 13662306a36Sopenharmony_ci uint16_t *iio; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci uint16_t data_block; 13962306a36Sopenharmony_ci uint32_t fb_base; 14062306a36Sopenharmony_ci uint32_t divmul[2]; 14162306a36Sopenharmony_ci uint16_t io_attr; 14262306a36Sopenharmony_ci uint16_t reg_block; 14362306a36Sopenharmony_ci uint8_t shift; 14462306a36Sopenharmony_ci int cs_equal, cs_above; 14562306a36Sopenharmony_ci int io_mode; 14662306a36Sopenharmony_ci uint32_t *scratch; 14762306a36Sopenharmony_ci int scratch_size_bytes; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci uint8_t name[STRLEN_LONG]; 15062306a36Sopenharmony_ci uint8_t vbios_pn[STRLEN_LONG]; 15162306a36Sopenharmony_ci uint32_t version; 15262306a36Sopenharmony_ci uint8_t vbios_ver_str[STRLEN_NORMAL]; 15362306a36Sopenharmony_ci uint8_t date[STRLEN_NORMAL]; 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ciextern int amdgpu_atom_debug; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_cistruct atom_context *amdgpu_atom_parse(struct card_info *card, void *bios); 15962306a36Sopenharmony_ciint amdgpu_atom_execute_table(struct atom_context *ctx, int index, uint32_t *params); 16062306a36Sopenharmony_ciint amdgpu_atom_asic_init(struct atom_context *ctx); 16162306a36Sopenharmony_civoid amdgpu_atom_destroy(struct atom_context *ctx); 16262306a36Sopenharmony_cibool amdgpu_atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size, 16362306a36Sopenharmony_ci uint8_t *frev, uint8_t *crev, uint16_t *data_start); 16462306a36Sopenharmony_cibool amdgpu_atom_parse_cmd_header(struct atom_context *ctx, int index, 16562306a36Sopenharmony_ci uint8_t *frev, uint8_t *crev); 16662306a36Sopenharmony_ci#include "atom-types.h" 16762306a36Sopenharmony_ci#include "atombios.h" 16862306a36Sopenharmony_ci#include "ObjectID.h" 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci#endif 171