1b843c749SSergey Zigachev /* 2b843c749SSergey Zigachev * Copyright 2008 Advanced Micro Devices, Inc. 3b843c749SSergey Zigachev * 4b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a 5b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"), 6b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation 7b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the 9b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions: 10b843c749SSergey Zigachev * 11b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in 12b843c749SSergey Zigachev * all copies or substantial portions of the Software. 13b843c749SSergey Zigachev * 14b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE. 21b843c749SSergey Zigachev * 22b843c749SSergey Zigachev * Author: Stanislaw Skowronek 23b843c749SSergey Zigachev */ 24b843c749SSergey Zigachev 25b843c749SSergey Zigachev #ifndef ATOM_H 26b843c749SSergey Zigachev #define ATOM_H 27b843c749SSergey Zigachev 28b843c749SSergey Zigachev #include <linux/types.h> 29b843c749SSergey Zigachev #include <drm/drmP.h> 30b843c749SSergey Zigachev 31b843c749SSergey Zigachev #define ATOM_BIOS_MAGIC 0xAA55 32b843c749SSergey Zigachev #define ATOM_ATI_MAGIC_PTR 0x30 33b843c749SSergey Zigachev #define ATOM_ATI_MAGIC " 761295520" 34b843c749SSergey Zigachev #define ATOM_ROM_TABLE_PTR 0x48 35b843c749SSergey Zigachev #define ATOM_ROM_PART_NUMBER_PTR 0x6E 36b843c749SSergey Zigachev 37b843c749SSergey Zigachev #define ATOM_ROM_MAGIC "ATOM" 38b843c749SSergey Zigachev #define ATOM_ROM_MAGIC_PTR 4 39b843c749SSergey Zigachev 40b843c749SSergey Zigachev #define ATOM_ROM_MSG_PTR 0x10 41b843c749SSergey Zigachev #define ATOM_ROM_CMD_PTR 0x1E 42b843c749SSergey Zigachev #define ATOM_ROM_DATA_PTR 0x20 43b843c749SSergey Zigachev 44b843c749SSergey Zigachev #define ATOM_CMD_INIT 0 45b843c749SSergey Zigachev #define ATOM_CMD_SETSCLK 0x0A 46b843c749SSergey Zigachev #define ATOM_CMD_SETMCLK 0x0B 47b843c749SSergey Zigachev #define ATOM_CMD_SETPCLK 0x0C 48b843c749SSergey Zigachev #define ATOM_CMD_SPDFANCNTL 0x39 49b843c749SSergey Zigachev 50b843c749SSergey Zigachev #define ATOM_DATA_FWI_PTR 0xC 51b843c749SSergey Zigachev #define ATOM_DATA_IIO_PTR 0x32 52b843c749SSergey Zigachev 53b843c749SSergey Zigachev #define ATOM_FWI_DEFSCLK_PTR 8 54b843c749SSergey Zigachev #define ATOM_FWI_DEFMCLK_PTR 0xC 55b843c749SSergey Zigachev #define ATOM_FWI_MAXSCLK_PTR 0x24 56b843c749SSergey Zigachev #define ATOM_FWI_MAXMCLK_PTR 0x28 57b843c749SSergey Zigachev 58b843c749SSergey Zigachev #define ATOM_CT_SIZE_PTR 0 59b843c749SSergey Zigachev #define ATOM_CT_WS_PTR 4 60b843c749SSergey Zigachev #define ATOM_CT_PS_PTR 5 61b843c749SSergey Zigachev #define ATOM_CT_PS_MASK 0x7F 62b843c749SSergey Zigachev #define ATOM_CT_CODE_PTR 6 63b843c749SSergey Zigachev 64b843c749SSergey Zigachev #define ATOM_OP_CNT 127 65b843c749SSergey Zigachev #define ATOM_OP_EOT 91 66b843c749SSergey Zigachev 67b843c749SSergey Zigachev #define ATOM_CASE_MAGIC 0x63 68b843c749SSergey Zigachev #define ATOM_CASE_END 0x5A5A 69b843c749SSergey Zigachev 70b843c749SSergey Zigachev #define ATOM_ARG_REG 0 71b843c749SSergey Zigachev #define ATOM_ARG_PS 1 72b843c749SSergey Zigachev #define ATOM_ARG_WS 2 73b843c749SSergey Zigachev #define ATOM_ARG_FB 3 74b843c749SSergey Zigachev #define ATOM_ARG_ID 4 75b843c749SSergey Zigachev #define ATOM_ARG_IMM 5 76b843c749SSergey Zigachev #define ATOM_ARG_PLL 6 77b843c749SSergey Zigachev #define ATOM_ARG_MC 7 78b843c749SSergey Zigachev 79b843c749SSergey Zigachev #define ATOM_SRC_DWORD 0 80b843c749SSergey Zigachev #define ATOM_SRC_WORD0 1 81b843c749SSergey Zigachev #define ATOM_SRC_WORD8 2 82b843c749SSergey Zigachev #define ATOM_SRC_WORD16 3 83b843c749SSergey Zigachev #define ATOM_SRC_BYTE0 4 84b843c749SSergey Zigachev #define ATOM_SRC_BYTE8 5 85b843c749SSergey Zigachev #define ATOM_SRC_BYTE16 6 86b843c749SSergey Zigachev #define ATOM_SRC_BYTE24 7 87b843c749SSergey Zigachev 88b843c749SSergey Zigachev #define ATOM_WS_QUOTIENT 0x40 89b843c749SSergey Zigachev #define ATOM_WS_REMAINDER 0x41 90b843c749SSergey Zigachev #define ATOM_WS_DATAPTR 0x42 91b843c749SSergey Zigachev #define ATOM_WS_SHIFT 0x43 92b843c749SSergey Zigachev #define ATOM_WS_OR_MASK 0x44 93b843c749SSergey Zigachev #define ATOM_WS_AND_MASK 0x45 94b843c749SSergey Zigachev #define ATOM_WS_FB_WINDOW 0x46 95b843c749SSergey Zigachev #define ATOM_WS_ATTRIBUTES 0x47 96b843c749SSergey Zigachev #define ATOM_WS_REGPTR 0x48 97b843c749SSergey Zigachev 98b843c749SSergey Zigachev #define ATOM_IIO_NOP 0 99b843c749SSergey Zigachev #define ATOM_IIO_START 1 100b843c749SSergey Zigachev #define ATOM_IIO_READ 2 101b843c749SSergey Zigachev #define ATOM_IIO_WRITE 3 102b843c749SSergey Zigachev #define ATOM_IIO_CLEAR 4 103b843c749SSergey Zigachev #define ATOM_IIO_SET 5 104b843c749SSergey Zigachev #define ATOM_IIO_MOVE_INDEX 6 105b843c749SSergey Zigachev #define ATOM_IIO_MOVE_ATTR 7 106b843c749SSergey Zigachev #define ATOM_IIO_MOVE_DATA 8 107b843c749SSergey Zigachev #define ATOM_IIO_END 9 108b843c749SSergey Zigachev 109b843c749SSergey Zigachev #define ATOM_IO_MM 0 110b843c749SSergey Zigachev #define ATOM_IO_PCI 1 111b843c749SSergey Zigachev #define ATOM_IO_SYSIO 2 112b843c749SSergey Zigachev #define ATOM_IO_IIO 0x80 113b843c749SSergey Zigachev 114b843c749SSergey Zigachev struct card_info { 115b843c749SSergey Zigachev struct drm_device *dev; 116b843c749SSergey Zigachev void (* reg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ 117b843c749SSergey Zigachev uint32_t (* reg_read)(struct card_info *, uint32_t); /* filled by driver */ 118b843c749SSergey Zigachev void (* ioreg_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ 119b843c749SSergey Zigachev uint32_t (* ioreg_read)(struct card_info *, uint32_t); /* filled by driver */ 120b843c749SSergey Zigachev void (* mc_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ 121b843c749SSergey Zigachev uint32_t (* mc_read)(struct card_info *, uint32_t); /* filled by driver */ 122b843c749SSergey Zigachev void (* pll_write)(struct card_info *, uint32_t, uint32_t); /* filled by driver */ 123b843c749SSergey Zigachev uint32_t (* pll_read)(struct card_info *, uint32_t); /* filled by driver */ 124b843c749SSergey Zigachev }; 125b843c749SSergey Zigachev 126b843c749SSergey Zigachev struct atom_context { 127b843c749SSergey Zigachev struct card_info *card; 128*78973132SSergey Zigachev struct lock mutex; 129b843c749SSergey Zigachev void *bios; 130b843c749SSergey Zigachev uint32_t cmd_table, data_table; 131b843c749SSergey Zigachev uint16_t *iio; 132b843c749SSergey Zigachev 133b843c749SSergey Zigachev uint16_t data_block; 134b843c749SSergey Zigachev uint32_t fb_base; 135b843c749SSergey Zigachev uint32_t divmul[2]; 136b843c749SSergey Zigachev uint16_t io_attr; 137b843c749SSergey Zigachev uint16_t reg_block; 138b843c749SSergey Zigachev uint8_t shift; 139b843c749SSergey Zigachev int cs_equal, cs_above; 140b843c749SSergey Zigachev int io_mode; 141b843c749SSergey Zigachev uint32_t *scratch; 142b843c749SSergey Zigachev int scratch_size_bytes; 143b843c749SSergey Zigachev char vbios_version[20]; 144b843c749SSergey Zigachev }; 145b843c749SSergey Zigachev 146b843c749SSergey Zigachev extern int amdgpu_atom_debug; 147b843c749SSergey Zigachev 148b843c749SSergey Zigachev struct atom_context *amdgpu_atom_parse(struct card_info *, void *); 149b843c749SSergey Zigachev int amdgpu_atom_execute_table(struct atom_context *, int, uint32_t *); 150b843c749SSergey Zigachev int amdgpu_atom_asic_init(struct atom_context *); 151b843c749SSergey Zigachev void amdgpu_atom_destroy(struct atom_context *); 152b843c749SSergey Zigachev bool amdgpu_atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size, 153b843c749SSergey Zigachev uint8_t *frev, uint8_t *crev, uint16_t *data_start); 154b843c749SSergey Zigachev bool amdgpu_atom_parse_cmd_header(struct atom_context *ctx, int index, 155b843c749SSergey Zigachev uint8_t *frev, uint8_t *crev); 156b843c749SSergey Zigachev #include "atom-types.h" 157b843c749SSergey Zigachev #include "atombios.h" 158b843c749SSergey Zigachev #include "ObjectID.h" 159b843c749SSergey Zigachev 160b843c749SSergey Zigachev #endif 161