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