radeon.h revision 1.3.32.2       1  1.3.32.2    martin /*	$NetBSD: radeon.h,v 1.3.32.2 2020/04/08 14:08:26 martin Exp $	*/
      2  1.3.32.1  christos 
      3       1.1  riastrad /*
      4       1.1  riastrad  * Copyright 2008 Advanced Micro Devices, Inc.
      5       1.1  riastrad  * Copyright 2008 Red Hat Inc.
      6       1.1  riastrad  * Copyright 2009 Jerome Glisse.
      7       1.1  riastrad  *
      8       1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9       1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     10       1.1  riastrad  * to deal in the Software without restriction, including without limitation
     11       1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     12       1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     13       1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     14       1.1  riastrad  *
     15       1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     16       1.1  riastrad  * all copies or substantial portions of the Software.
     17       1.1  riastrad  *
     18       1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19       1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20       1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     21       1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22       1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23       1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     24       1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     25       1.1  riastrad  *
     26       1.1  riastrad  * Authors: Dave Airlie
     27       1.1  riastrad  *          Alex Deucher
     28       1.1  riastrad  *          Jerome Glisse
     29       1.1  riastrad  */
     30       1.1  riastrad #ifndef __RADEON_H__
     31       1.1  riastrad #define __RADEON_H__
     32       1.1  riastrad 
     33       1.1  riastrad /* TODO: Here are things that needs to be done :
     34       1.1  riastrad  *	- surface allocator & initializer : (bit like scratch reg) should
     35       1.1  riastrad  *	  initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
     36       1.1  riastrad  *	  related to surface
     37       1.1  riastrad  *	- WB : write back stuff (do it bit like scratch reg things)
     38       1.1  riastrad  *	- Vblank : look at Jesse's rework and what we should do
     39       1.1  riastrad  *	- r600/r700: gart & cp
     40       1.1  riastrad  *	- cs : clean cs ioctl use bitmap & things like that.
     41       1.1  riastrad  *	- power management stuff
     42       1.1  riastrad  *	- Barrier in gart code
     43       1.1  riastrad  *	- Unmappabled vram ?
     44       1.1  riastrad  *	- TESTING, TESTING, TESTING
     45       1.1  riastrad  */
     46       1.1  riastrad 
     47       1.1  riastrad /* Initialization path:
     48       1.1  riastrad  *  We expect that acceleration initialization might fail for various
     49       1.1  riastrad  *  reasons even thought we work hard to make it works on most
     50       1.1  riastrad  *  configurations. In order to still have a working userspace in such
     51       1.1  riastrad  *  situation the init path must succeed up to the memory controller
     52       1.1  riastrad  *  initialization point. Failure before this point are considered as
     53       1.1  riastrad  *  fatal error. Here is the init callchain :
     54       1.1  riastrad  *      radeon_device_init  perform common structure, mutex initialization
     55       1.1  riastrad  *      asic_init           setup the GPU memory layout and perform all
     56       1.1  riastrad  *                          one time initialization (failure in this
     57       1.1  riastrad  *                          function are considered fatal)
     58       1.1  riastrad  *      asic_startup        setup the GPU acceleration, in order to
     59       1.1  riastrad  *                          follow guideline the first thing this
     60       1.1  riastrad  *                          function should do is setting the GPU
     61       1.1  riastrad  *                          memory controller (only MC setup failure
     62       1.1  riastrad  *                          are considered as fatal)
     63       1.1  riastrad  */
     64       1.1  riastrad 
     65       1.1  riastrad #include <linux/atomic.h>
     66       1.1  riastrad #include <linux/wait.h>
     67       1.1  riastrad #include <linux/list.h>
     68       1.1  riastrad #include <linux/kref.h>
     69  1.3.32.1  christos #include <linux/interval_tree.h>
     70  1.3.32.1  christos #include <linux/hashtable.h>
     71  1.3.32.1  christos #include <linux/fence.h>
     72       1.1  riastrad 
     73       1.1  riastrad #include <ttm/ttm_bo_api.h>
     74       1.1  riastrad #include <ttm/ttm_bo_driver.h>
     75       1.1  riastrad #include <ttm/ttm_placement.h>
     76       1.1  riastrad #include <ttm/ttm_module.h>
     77       1.1  riastrad #include <ttm/ttm_execbuf_util.h>
     78       1.1  riastrad 
     79  1.3.32.1  christos #include <drm/drm_gem.h>
     80  1.3.32.1  christos 
     81       1.1  riastrad #include "radeon_family.h"
     82       1.1  riastrad #include "radeon_mode.h"
     83       1.1  riastrad #include "radeon_reg.h"
     84       1.1  riastrad 
     85       1.1  riastrad /*
     86       1.1  riastrad  * Modules parameters.
     87       1.1  riastrad  */
     88       1.1  riastrad extern int radeon_no_wb;
     89       1.1  riastrad extern int radeon_modeset;
     90       1.1  riastrad extern int radeon_dynclks;
     91       1.1  riastrad extern int radeon_r4xx_atom;
     92       1.1  riastrad extern int radeon_agpmode;
     93       1.1  riastrad extern int radeon_vram_limit;
     94       1.1  riastrad extern int radeon_gart_size;
     95       1.1  riastrad extern int radeon_benchmarking;
     96       1.1  riastrad extern int radeon_testing;
     97       1.1  riastrad extern int radeon_connector_table;
     98       1.1  riastrad extern int radeon_tv;
     99       1.1  riastrad extern int radeon_audio;
    100       1.1  riastrad extern int radeon_disp_priority;
    101       1.1  riastrad extern int radeon_hw_i2c;
    102       1.1  riastrad extern int radeon_pcie_gen2;
    103       1.1  riastrad extern int radeon_msi;
    104       1.1  riastrad extern int radeon_lockup_timeout;
    105       1.1  riastrad extern int radeon_fastfb;
    106       1.1  riastrad extern int radeon_dpm;
    107       1.1  riastrad extern int radeon_aspm;
    108       1.1  riastrad extern int radeon_runtime_pm;
    109       1.1  riastrad extern int radeon_hard_reset;
    110  1.3.32.1  christos extern int radeon_vm_size;
    111  1.3.32.1  christos extern int radeon_vm_block_size;
    112  1.3.32.1  christos extern int radeon_deep_color;
    113  1.3.32.1  christos extern int radeon_use_pflipirq;
    114  1.3.32.1  christos extern int radeon_bapm;
    115  1.3.32.1  christos extern int radeon_backlight;
    116  1.3.32.1  christos extern int radeon_auxch;
    117  1.3.32.1  christos extern int radeon_mst;
    118       1.1  riastrad 
    119       1.1  riastrad /*
    120       1.1  riastrad  * Copy from radeon_drv.h so we don't have to include both and have conflicting
    121       1.1  riastrad  * symbol;
    122       1.1  riastrad  */
    123       1.1  riastrad #define RADEON_MAX_USEC_TIMEOUT			100000	/* 100 ms */
    124  1.3.32.2    martin #define RADEON_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
    125       1.1  riastrad /* RADEON_IB_POOL_SIZE must be a power of 2 */
    126       1.1  riastrad #define RADEON_IB_POOL_SIZE			16
    127       1.1  riastrad #define RADEON_DEBUGFS_MAX_COMPONENTS		32
    128       1.1  riastrad #define RADEONFB_CONN_LIMIT			4
    129       1.1  riastrad #define RADEON_BIOS_NUM_SCRATCH			8
    130       1.1  riastrad 
    131       1.1  riastrad /* internal ring indices */
    132       1.1  riastrad /* r1xx+ has gfx CP ring */
    133       1.1  riastrad #define RADEON_RING_TYPE_GFX_INDEX		0
    134       1.1  riastrad 
    135       1.1  riastrad /* cayman has 2 compute CP rings */
    136       1.1  riastrad #define CAYMAN_RING_TYPE_CP1_INDEX		1
    137       1.1  riastrad #define CAYMAN_RING_TYPE_CP2_INDEX		2
    138       1.1  riastrad 
    139       1.1  riastrad /* R600+ has an async dma ring */
    140       1.1  riastrad #define R600_RING_TYPE_DMA_INDEX		3
    141       1.1  riastrad /* cayman add a second async dma ring */
    142       1.1  riastrad #define CAYMAN_RING_TYPE_DMA1_INDEX		4
    143       1.1  riastrad 
    144       1.1  riastrad /* R600+ */
    145       1.1  riastrad #define R600_RING_TYPE_UVD_INDEX		5
    146       1.1  riastrad 
    147       1.1  riastrad /* TN+ */
    148       1.1  riastrad #define TN_RING_TYPE_VCE1_INDEX			6
    149       1.1  riastrad #define TN_RING_TYPE_VCE2_INDEX			7
    150       1.1  riastrad 
    151       1.1  riastrad /* max number of rings */
    152       1.1  riastrad #define RADEON_NUM_RINGS			8
    153       1.1  riastrad 
    154       1.1  riastrad /* number of hw syncs before falling back on blocking */
    155       1.1  riastrad #define RADEON_NUM_SYNCS			4
    156       1.1  riastrad 
    157       1.1  riastrad /* hardcode those limit for now */
    158       1.1  riastrad #define RADEON_VA_IB_OFFSET			(1 << 20)
    159       1.1  riastrad #define RADEON_VA_RESERVED_SIZE			(8 << 20)
    160       1.1  riastrad #define RADEON_IB_VM_MAX_SIZE			(64 << 10)
    161       1.1  riastrad 
    162       1.1  riastrad /* hard reset data */
    163       1.1  riastrad #define RADEON_ASIC_RESET_DATA                  0x39d5e86b
    164       1.1  riastrad 
    165       1.1  riastrad /* reset flags */
    166       1.1  riastrad #define RADEON_RESET_GFX			(1 << 0)
    167       1.1  riastrad #define RADEON_RESET_COMPUTE			(1 << 1)
    168       1.1  riastrad #define RADEON_RESET_DMA			(1 << 2)
    169       1.1  riastrad #define RADEON_RESET_CP				(1 << 3)
    170       1.1  riastrad #define RADEON_RESET_GRBM			(1 << 4)
    171       1.1  riastrad #define RADEON_RESET_DMA1			(1 << 5)
    172       1.1  riastrad #define RADEON_RESET_RLC			(1 << 6)
    173       1.1  riastrad #define RADEON_RESET_SEM			(1 << 7)
    174       1.1  riastrad #define RADEON_RESET_IH				(1 << 8)
    175       1.1  riastrad #define RADEON_RESET_VMC			(1 << 9)
    176       1.1  riastrad #define RADEON_RESET_MC				(1 << 10)
    177       1.1  riastrad #define RADEON_RESET_DISPLAY			(1 << 11)
    178       1.1  riastrad 
    179       1.1  riastrad /* CG block flags */
    180       1.1  riastrad #define RADEON_CG_BLOCK_GFX			(1 << 0)
    181       1.1  riastrad #define RADEON_CG_BLOCK_MC			(1 << 1)
    182       1.1  riastrad #define RADEON_CG_BLOCK_SDMA			(1 << 2)
    183       1.1  riastrad #define RADEON_CG_BLOCK_UVD			(1 << 3)
    184       1.1  riastrad #define RADEON_CG_BLOCK_VCE			(1 << 4)
    185       1.1  riastrad #define RADEON_CG_BLOCK_HDP			(1 << 5)
    186       1.1  riastrad #define RADEON_CG_BLOCK_BIF			(1 << 6)
    187       1.1  riastrad 
    188       1.1  riastrad /* CG flags */
    189       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_MGCG		(1 << 0)
    190       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_MGLS		(1 << 1)
    191       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_CGCG		(1 << 2)
    192       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_CGLS		(1 << 3)
    193       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_CGTS		(1 << 4)
    194       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_CGTS_LS		(1 << 5)
    195       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_CP_LS		(1 << 6)
    196       1.1  riastrad #define RADEON_CG_SUPPORT_GFX_RLC_LS		(1 << 7)
    197       1.1  riastrad #define RADEON_CG_SUPPORT_MC_LS			(1 << 8)
    198       1.1  riastrad #define RADEON_CG_SUPPORT_MC_MGCG		(1 << 9)
    199       1.1  riastrad #define RADEON_CG_SUPPORT_SDMA_LS		(1 << 10)
    200       1.1  riastrad #define RADEON_CG_SUPPORT_SDMA_MGCG		(1 << 11)
    201       1.1  riastrad #define RADEON_CG_SUPPORT_BIF_LS		(1 << 12)
    202       1.1  riastrad #define RADEON_CG_SUPPORT_UVD_MGCG		(1 << 13)
    203       1.1  riastrad #define RADEON_CG_SUPPORT_VCE_MGCG		(1 << 14)
    204       1.1  riastrad #define RADEON_CG_SUPPORT_HDP_LS		(1 << 15)
    205       1.1  riastrad #define RADEON_CG_SUPPORT_HDP_MGCG		(1 << 16)
    206       1.1  riastrad 
    207       1.1  riastrad /* PG flags */
    208       1.1  riastrad #define RADEON_PG_SUPPORT_GFX_PG		(1 << 0)
    209       1.1  riastrad #define RADEON_PG_SUPPORT_GFX_SMG		(1 << 1)
    210       1.1  riastrad #define RADEON_PG_SUPPORT_GFX_DMG		(1 << 2)
    211       1.1  riastrad #define RADEON_PG_SUPPORT_UVD			(1 << 3)
    212       1.1  riastrad #define RADEON_PG_SUPPORT_VCE			(1 << 4)
    213       1.1  riastrad #define RADEON_PG_SUPPORT_CP			(1 << 5)
    214       1.1  riastrad #define RADEON_PG_SUPPORT_GDS			(1 << 6)
    215       1.1  riastrad #define RADEON_PG_SUPPORT_RLC_SMU_HS		(1 << 7)
    216       1.1  riastrad #define RADEON_PG_SUPPORT_SDMA			(1 << 8)
    217       1.1  riastrad #define RADEON_PG_SUPPORT_ACP			(1 << 9)
    218       1.1  riastrad #define RADEON_PG_SUPPORT_SAMU			(1 << 10)
    219       1.1  riastrad 
    220       1.1  riastrad /* max cursor sizes (in pixels) */
    221       1.1  riastrad #define CURSOR_WIDTH 64
    222       1.1  riastrad #define CURSOR_HEIGHT 64
    223       1.1  riastrad 
    224       1.1  riastrad #define CIK_CURSOR_WIDTH 128
    225       1.1  riastrad #define CIK_CURSOR_HEIGHT 128
    226       1.1  riastrad 
    227       1.1  riastrad /*
    228       1.1  riastrad  * Errata workarounds.
    229       1.1  riastrad  */
    230       1.1  riastrad enum radeon_pll_errata {
    231       1.1  riastrad 	CHIP_ERRATA_R300_CG             = 0x00000001,
    232       1.1  riastrad 	CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
    233       1.1  riastrad 	CHIP_ERRATA_PLL_DELAY           = 0x00000004
    234       1.1  riastrad };
    235       1.1  riastrad 
    236       1.1  riastrad 
    237       1.1  riastrad struct radeon_device;
    238       1.1  riastrad 
    239       1.3  riastrad #ifdef __NetBSD__
    240       1.3  riastrad extern struct radeon_device *radeon_device_private(device_t);
    241       1.3  riastrad #endif
    242       1.1  riastrad 
    243       1.1  riastrad /*
    244       1.1  riastrad  * BIOS.
    245       1.1  riastrad  */
    246       1.1  riastrad bool radeon_get_bios(struct radeon_device *rdev);
    247       1.1  riastrad 
    248       1.1  riastrad /*
    249       1.1  riastrad  * Dummy page
    250       1.1  riastrad  */
    251       1.1  riastrad struct radeon_dummy_page {
    252  1.3.32.1  christos 	uint64_t	entry;
    253       1.2  riastrad #ifdef __NetBSD__
    254       1.2  riastrad 	bus_dma_segment_t	rdp_seg;
    255       1.2  riastrad 	bus_dmamap_t		rdp_map;
    256  1.3.32.2    martin 	void		*rdp_addr;
    257       1.2  riastrad #else
    258       1.1  riastrad 	struct page	*page;
    259       1.2  riastrad #endif
    260       1.1  riastrad 	dma_addr_t	addr;
    261       1.1  riastrad };
    262       1.1  riastrad int radeon_dummy_page_init(struct radeon_device *rdev);
    263       1.1  riastrad void radeon_dummy_page_fini(struct radeon_device *rdev);
    264       1.1  riastrad 
    265       1.1  riastrad 
    266       1.1  riastrad /*
    267       1.1  riastrad  * Clocks
    268       1.1  riastrad  */
    269       1.1  riastrad struct radeon_clock {
    270       1.1  riastrad 	struct radeon_pll p1pll;
    271       1.1  riastrad 	struct radeon_pll p2pll;
    272       1.1  riastrad 	struct radeon_pll dcpll;
    273       1.1  riastrad 	struct radeon_pll spll;
    274       1.1  riastrad 	struct radeon_pll mpll;
    275       1.1  riastrad 	/* 10 Khz units */
    276       1.1  riastrad 	uint32_t default_mclk;
    277       1.1  riastrad 	uint32_t default_sclk;
    278       1.1  riastrad 	uint32_t default_dispclk;
    279       1.1  riastrad 	uint32_t current_dispclk;
    280       1.1  riastrad 	uint32_t dp_extclk;
    281       1.1  riastrad 	uint32_t max_pixel_clock;
    282  1.3.32.1  christos 	uint32_t vco_freq;
    283       1.1  riastrad };
    284       1.1  riastrad 
    285       1.1  riastrad /*
    286       1.1  riastrad  * Power management
    287       1.1  riastrad  */
    288       1.1  riastrad int radeon_pm_init(struct radeon_device *rdev);
    289       1.1  riastrad int radeon_pm_late_init(struct radeon_device *rdev);
    290       1.1  riastrad void radeon_pm_fini(struct radeon_device *rdev);
    291       1.1  riastrad void radeon_pm_compute_clocks(struct radeon_device *rdev);
    292       1.1  riastrad void radeon_pm_suspend(struct radeon_device *rdev);
    293       1.1  riastrad void radeon_pm_resume(struct radeon_device *rdev);
    294       1.1  riastrad void radeon_combios_get_power_modes(struct radeon_device *rdev);
    295       1.1  riastrad void radeon_atombios_get_power_modes(struct radeon_device *rdev);
    296       1.1  riastrad int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
    297       1.1  riastrad 				   u8 clock_type,
    298       1.1  riastrad 				   u32 clock,
    299       1.1  riastrad 				   bool strobe_mode,
    300       1.1  riastrad 				   struct atom_clock_dividers *dividers);
    301       1.1  riastrad int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
    302       1.1  riastrad 					u32 clock,
    303       1.1  riastrad 					bool strobe_mode,
    304       1.1  riastrad 					struct atom_mpll_param *mpll_param);
    305       1.1  riastrad void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
    306       1.1  riastrad int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
    307       1.1  riastrad 					  u16 voltage_level, u8 voltage_type,
    308       1.1  riastrad 					  u32 *gpio_value, u32 *gpio_mask);
    309       1.1  riastrad void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
    310       1.1  riastrad 					 u32 eng_clock, u32 mem_clock);
    311       1.1  riastrad int radeon_atom_get_voltage_step(struct radeon_device *rdev,
    312       1.1  riastrad 				 u8 voltage_type, u16 *voltage_step);
    313       1.1  riastrad int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
    314       1.1  riastrad 			     u16 voltage_id, u16 *voltage);
    315       1.1  riastrad int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
    316       1.1  riastrad 						      u16 *voltage,
    317       1.1  riastrad 						      u16 leakage_idx);
    318       1.1  riastrad int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
    319       1.1  riastrad 					  u16 *leakage_id);
    320       1.1  riastrad int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
    321       1.1  riastrad 							 u16 *vddc, u16 *vddci,
    322       1.1  riastrad 							 u16 virtual_voltage_id,
    323       1.1  riastrad 							 u16 vbios_voltage_id);
    324  1.3.32.1  christos int radeon_atom_get_voltage_evv(struct radeon_device *rdev,
    325  1.3.32.1  christos 				u16 virtual_voltage_id,
    326  1.3.32.1  christos 				u16 *voltage);
    327       1.1  riastrad int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
    328       1.1  riastrad 				      u8 voltage_type,
    329       1.1  riastrad 				      u16 nominal_voltage,
    330       1.1  riastrad 				      u16 *true_voltage);
    331       1.1  riastrad int radeon_atom_get_min_voltage(struct radeon_device *rdev,
    332       1.1  riastrad 				u8 voltage_type, u16 *min_voltage);
    333       1.1  riastrad int radeon_atom_get_max_voltage(struct radeon_device *rdev,
    334       1.1  riastrad 				u8 voltage_type, u16 *max_voltage);
    335       1.1  riastrad int radeon_atom_get_voltage_table(struct radeon_device *rdev,
    336       1.1  riastrad 				  u8 voltage_type, u8 voltage_mode,
    337       1.1  riastrad 				  struct atom_voltage_table *voltage_table);
    338       1.1  riastrad bool radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
    339       1.1  riastrad 				 u8 voltage_type, u8 voltage_mode);
    340  1.3.32.1  christos int radeon_atom_get_svi2_info(struct radeon_device *rdev,
    341  1.3.32.1  christos 			      u8 voltage_type,
    342  1.3.32.1  christos 			      u8 *svd_gpio_id, u8 *svc_gpio_id);
    343       1.1  riastrad void radeon_atom_update_memory_dll(struct radeon_device *rdev,
    344       1.1  riastrad 				   u32 mem_clock);
    345       1.1  riastrad void radeon_atom_set_ac_timing(struct radeon_device *rdev,
    346       1.1  riastrad 			       u32 mem_clock);
    347       1.1  riastrad int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
    348       1.1  riastrad 				  u8 module_index,
    349       1.1  riastrad 				  struct atom_mc_reg_table *reg_table);
    350       1.1  riastrad int radeon_atom_get_memory_info(struct radeon_device *rdev,
    351       1.1  riastrad 				u8 module_index, struct atom_memory_info *mem_info);
    352       1.1  riastrad int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
    353       1.1  riastrad 				     bool gddr5, u8 module_index,
    354       1.1  riastrad 				     struct atom_memory_clock_range_table *mclk_range_table);
    355       1.1  riastrad int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
    356       1.1  riastrad 			     u16 voltage_id, u16 *voltage);
    357       1.1  riastrad void rs690_pm_info(struct radeon_device *rdev);
    358       1.1  riastrad extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
    359       1.1  riastrad 				    unsigned *bankh, unsigned *mtaspect,
    360       1.1  riastrad 				    unsigned *tile_split);
    361       1.1  riastrad 
    362       1.1  riastrad /*
    363       1.1  riastrad  * Fences.
    364       1.1  riastrad  */
    365       1.1  riastrad struct radeon_fence_driver {
    366  1.3.32.1  christos 	struct radeon_device		*rdev;
    367       1.1  riastrad 	uint32_t			scratch_reg;
    368       1.1  riastrad 	uint64_t			gpu_addr;
    369       1.1  riastrad 	volatile uint32_t		*cpu_addr;
    370       1.1  riastrad 	/* sync_seq is protected by ring emission lock */
    371       1.1  riastrad 	uint64_t			sync_seq[RADEON_NUM_RINGS];
    372       1.1  riastrad 	atomic64_t			last_seq;
    373  1.3.32.1  christos 	bool				initialized, delayed_irq;
    374  1.3.32.1  christos 	struct delayed_work		lockup_work;
    375       1.1  riastrad };
    376       1.1  riastrad 
    377       1.1  riastrad struct radeon_fence {
    378  1.3.32.1  christos 	struct fence		base;
    379  1.3.32.1  christos 
    380  1.3.32.1  christos 	struct radeon_device	*rdev;
    381  1.3.32.1  christos 	uint64_t		seq;
    382       1.1  riastrad 	/* RB, DMA, etc. */
    383  1.3.32.1  christos 	unsigned		ring;
    384  1.3.32.1  christos 	bool			is_vm_update;
    385  1.3.32.1  christos 
    386  1.3.32.1  christos #ifdef __NetBSD__
    387  1.3.32.1  christos 	TAILQ_ENTRY(radeon_fence)	fence_check;
    388  1.3.32.1  christos #else
    389  1.3.32.1  christos 	wait_queue_t		fence_wake;
    390  1.3.32.1  christos #endif
    391       1.1  riastrad };
    392       1.1  riastrad 
    393       1.1  riastrad int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
    394       1.1  riastrad int radeon_fence_driver_init(struct radeon_device *rdev);
    395       1.1  riastrad void radeon_fence_driver_fini(struct radeon_device *rdev);
    396  1.3.32.1  christos void radeon_fence_driver_force_completion(struct radeon_device *rdev, int ring);
    397       1.1  riastrad int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
    398  1.3.32.1  christos void radeon_fence_wakeup_locked(struct radeon_device *rdev);
    399       1.1  riastrad void radeon_fence_process(struct radeon_device *rdev, int ring);
    400       1.1  riastrad bool radeon_fence_signaled(struct radeon_fence *fence);
    401       1.1  riastrad int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
    402       1.1  riastrad int radeon_fence_wait_next(struct radeon_device *rdev, int ring);
    403       1.1  riastrad int radeon_fence_wait_empty(struct radeon_device *rdev, int ring);
    404       1.1  riastrad int radeon_fence_wait_any(struct radeon_device *rdev,
    405       1.1  riastrad 			  struct radeon_fence **fences,
    406       1.1  riastrad 			  bool intr);
    407       1.1  riastrad struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
    408       1.1  riastrad void radeon_fence_unref(struct radeon_fence **fence);
    409       1.1  riastrad unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
    410       1.1  riastrad bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
    411       1.1  riastrad void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
    412       1.1  riastrad static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
    413       1.1  riastrad 						      struct radeon_fence *b)
    414       1.1  riastrad {
    415       1.1  riastrad 	if (!a) {
    416       1.1  riastrad 		return b;
    417       1.1  riastrad 	}
    418       1.1  riastrad 
    419       1.1  riastrad 	if (!b) {
    420       1.1  riastrad 		return a;
    421       1.1  riastrad 	}
    422       1.1  riastrad 
    423       1.1  riastrad 	BUG_ON(a->ring != b->ring);
    424       1.1  riastrad 
    425       1.1  riastrad 	if (a->seq > b->seq) {
    426       1.1  riastrad 		return a;
    427       1.1  riastrad 	} else {
    428       1.1  riastrad 		return b;
    429       1.1  riastrad 	}
    430       1.1  riastrad }
    431       1.1  riastrad 
    432       1.1  riastrad static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
    433       1.1  riastrad 					   struct radeon_fence *b)
    434       1.1  riastrad {
    435       1.1  riastrad 	if (!a) {
    436       1.1  riastrad 		return false;
    437       1.1  riastrad 	}
    438       1.1  riastrad 
    439       1.1  riastrad 	if (!b) {
    440       1.1  riastrad 		return true;
    441       1.1  riastrad 	}
    442       1.1  riastrad 
    443       1.1  riastrad 	BUG_ON(a->ring != b->ring);
    444       1.1  riastrad 
    445       1.1  riastrad 	return a->seq < b->seq;
    446       1.1  riastrad }
    447       1.1  riastrad 
    448       1.1  riastrad /*
    449       1.1  riastrad  * Tiling registers
    450       1.1  riastrad  */
    451       1.1  riastrad struct radeon_surface_reg {
    452       1.1  riastrad 	struct radeon_bo *bo;
    453       1.1  riastrad };
    454       1.1  riastrad 
    455       1.1  riastrad #define RADEON_GEM_MAX_SURFACES 8
    456       1.1  riastrad 
    457       1.1  riastrad /*
    458       1.1  riastrad  * TTM.
    459       1.1  riastrad  */
    460       1.1  riastrad struct radeon_mman {
    461       1.1  riastrad 	struct ttm_bo_global_ref        bo_global_ref;
    462       1.1  riastrad 	struct drm_global_reference	mem_global_ref;
    463       1.1  riastrad 	struct ttm_bo_device		bdev;
    464       1.1  riastrad 	bool				mem_global_referenced;
    465       1.1  riastrad 	bool				initialized;
    466       1.1  riastrad 
    467       1.1  riastrad #if defined(CONFIG_DEBUG_FS)
    468       1.1  riastrad 	struct dentry			*vram;
    469       1.1  riastrad 	struct dentry			*gtt;
    470       1.1  riastrad #endif
    471       1.1  riastrad };
    472       1.1  riastrad 
    473  1.3.32.1  christos struct radeon_bo_list {
    474  1.3.32.1  christos 	struct radeon_bo		*robj;
    475  1.3.32.1  christos 	struct ttm_validate_buffer	tv;
    476  1.3.32.1  christos 	uint64_t			gpu_offset;
    477  1.3.32.1  christos 	unsigned			prefered_domains;
    478  1.3.32.1  christos 	unsigned			allowed_domains;
    479  1.3.32.1  christos 	uint32_t			tiling_flags;
    480  1.3.32.1  christos };
    481  1.3.32.1  christos 
    482       1.1  riastrad /* bo virtual address in a specific vm */
    483       1.1  riastrad struct radeon_bo_va {
    484       1.1  riastrad 	/* protected by bo being reserved */
    485       1.1  riastrad 	struct list_head		bo_list;
    486       1.1  riastrad 	uint32_t			flags;
    487  1.3.32.1  christos 	struct radeon_fence		*last_pt_update;
    488       1.1  riastrad 	unsigned			ref_count;
    489       1.1  riastrad 
    490       1.1  riastrad 	/* protected by vm mutex */
    491  1.3.32.1  christos 	struct interval_tree_node	it;
    492  1.3.32.1  christos 	struct list_head		vm_status;
    493       1.1  riastrad 
    494       1.1  riastrad 	/* constant after initialization */
    495       1.1  riastrad 	struct radeon_vm		*vm;
    496       1.1  riastrad 	struct radeon_bo		*bo;
    497       1.1  riastrad };
    498       1.1  riastrad 
    499       1.1  riastrad struct radeon_bo {
    500       1.1  riastrad 	/* Protected by gem.mutex */
    501       1.1  riastrad 	struct list_head		list;
    502       1.1  riastrad 	/* Protected by tbo.reserved */
    503       1.1  riastrad 	u32				initial_domain;
    504  1.3.32.1  christos 	struct ttm_place		placements[4];
    505       1.1  riastrad 	struct ttm_placement		placement;
    506       1.1  riastrad 	struct ttm_buffer_object	tbo;
    507       1.1  riastrad 	struct ttm_bo_kmap_obj		kmap;
    508  1.3.32.1  christos 	u32				flags;
    509       1.1  riastrad 	unsigned			pin_count;
    510       1.1  riastrad 	void				*kptr;
    511       1.1  riastrad 	u32				tiling_flags;
    512       1.1  riastrad 	u32				pitch;
    513       1.1  riastrad 	int				surface_reg;
    514       1.1  riastrad 	/* list of all virtual address to which this bo
    515       1.1  riastrad 	 * is associated to
    516       1.1  riastrad 	 */
    517       1.1  riastrad 	struct list_head		va;
    518       1.1  riastrad 	/* Constant after initialization */
    519       1.1  riastrad 	struct radeon_device		*rdev;
    520       1.1  riastrad 	struct drm_gem_object		gem_base;
    521       1.1  riastrad 
    522       1.1  riastrad 	struct ttm_bo_kmap_obj		dma_buf_vmap;
    523       1.2  riastrad #ifndef __NetBSD__		/* XXX pid???  */
    524       1.1  riastrad 	pid_t				pid;
    525       1.2  riastrad #endif
    526  1.3.32.1  christos 
    527  1.3.32.1  christos 	struct radeon_mn		*mn;
    528  1.3.32.1  christos 	struct list_head		mn_list;
    529       1.1  riastrad };
    530       1.1  riastrad #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
    531       1.1  riastrad 
    532       1.1  riastrad int radeon_gem_debugfs_init(struct radeon_device *rdev);
    533       1.1  riastrad 
    534       1.1  riastrad /* sub-allocation manager, it has to be protected by another lock.
    535       1.1  riastrad  * By conception this is an helper for other part of the driver
    536       1.1  riastrad  * like the indirect buffer or semaphore, which both have their
    537       1.1  riastrad  * locking.
    538       1.1  riastrad  *
    539       1.1  riastrad  * Principe is simple, we keep a list of sub allocation in offset
    540       1.1  riastrad  * order (first entry has offset == 0, last entry has the highest
    541       1.1  riastrad  * offset).
    542       1.1  riastrad  *
    543       1.1  riastrad  * When allocating new object we first check if there is room at
    544       1.1  riastrad  * the end total_size - (last_object_offset + last_object_size) >=
    545       1.1  riastrad  * alloc_size. If so we allocate new object there.
    546       1.1  riastrad  *
    547       1.1  riastrad  * When there is not enough room at the end, we start waiting for
    548       1.1  riastrad  * each sub object until we reach object_offset+object_size >=
    549       1.1  riastrad  * alloc_size, this object then become the sub object we return.
    550       1.1  riastrad  *
    551       1.1  riastrad  * Alignment can't be bigger than page size.
    552       1.1  riastrad  *
    553       1.1  riastrad  * Hole are not considered for allocation to keep things simple.
    554       1.1  riastrad  * Assumption is that there won't be hole (all object on same
    555       1.1  riastrad  * alignment).
    556       1.1  riastrad  */
    557       1.1  riastrad struct radeon_sa_manager {
    558       1.2  riastrad #ifdef __NetBSD__
    559       1.2  riastrad 	spinlock_t		wq_lock;
    560       1.2  riastrad 	drm_waitqueue_t		wq;
    561       1.2  riastrad #else
    562       1.1  riastrad 	wait_queue_head_t	wq;
    563       1.2  riastrad #endif
    564       1.1  riastrad 	struct radeon_bo	*bo;
    565       1.1  riastrad 	struct list_head	*hole;
    566       1.1  riastrad 	struct list_head	flist[RADEON_NUM_RINGS];
    567       1.1  riastrad 	struct list_head	olist;
    568       1.1  riastrad 	unsigned		size;
    569       1.1  riastrad 	uint64_t		gpu_addr;
    570       1.1  riastrad 	void			*cpu_ptr;
    571       1.1  riastrad 	uint32_t		domain;
    572       1.1  riastrad 	uint32_t		align;
    573       1.1  riastrad };
    574       1.1  riastrad 
    575       1.1  riastrad struct radeon_sa_bo;
    576       1.1  riastrad 
    577       1.1  riastrad /* sub-allocation buffer */
    578       1.1  riastrad struct radeon_sa_bo {
    579       1.1  riastrad 	struct list_head		olist;
    580       1.1  riastrad 	struct list_head		flist;
    581       1.1  riastrad 	struct radeon_sa_manager	*manager;
    582       1.1  riastrad 	unsigned			soffset;
    583       1.1  riastrad 	unsigned			eoffset;
    584       1.1  riastrad 	struct radeon_fence		*fence;
    585       1.1  riastrad };
    586       1.1  riastrad 
    587       1.1  riastrad /*
    588       1.1  riastrad  * GEM objects.
    589       1.1  riastrad  */
    590       1.1  riastrad struct radeon_gem {
    591       1.1  riastrad 	struct mutex		mutex;
    592       1.1  riastrad 	struct list_head	objects;
    593       1.1  riastrad };
    594       1.1  riastrad 
    595       1.1  riastrad int radeon_gem_init(struct radeon_device *rdev);
    596       1.1  riastrad void radeon_gem_fini(struct radeon_device *rdev);
    597  1.3.32.1  christos int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size,
    598       1.1  riastrad 				int alignment, int initial_domain,
    599  1.3.32.1  christos 				u32 flags, bool kernel,
    600       1.1  riastrad 				struct drm_gem_object **obj);
    601       1.1  riastrad 
    602       1.1  riastrad int radeon_mode_dumb_create(struct drm_file *file_priv,
    603       1.1  riastrad 			    struct drm_device *dev,
    604       1.1  riastrad 			    struct drm_mode_create_dumb *args);
    605       1.1  riastrad int radeon_mode_dumb_mmap(struct drm_file *filp,
    606       1.1  riastrad 			  struct drm_device *dev,
    607       1.1  riastrad 			  uint32_t handle, uint64_t *offset_p);
    608       1.1  riastrad 
    609       1.1  riastrad /*
    610       1.1  riastrad  * Semaphores.
    611       1.1  riastrad  */
    612       1.1  riastrad struct radeon_semaphore {
    613  1.3.32.1  christos 	struct radeon_sa_bo	*sa_bo;
    614  1.3.32.1  christos 	signed			waiters;
    615  1.3.32.1  christos 	uint64_t		gpu_addr;
    616       1.1  riastrad };
    617       1.1  riastrad 
    618       1.1  riastrad int radeon_semaphore_create(struct radeon_device *rdev,
    619       1.1  riastrad 			    struct radeon_semaphore **semaphore);
    620       1.1  riastrad bool radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
    621       1.1  riastrad 				  struct radeon_semaphore *semaphore);
    622       1.1  riastrad bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
    623       1.1  riastrad 				struct radeon_semaphore *semaphore);
    624       1.1  riastrad void radeon_semaphore_free(struct radeon_device *rdev,
    625       1.1  riastrad 			   struct radeon_semaphore **semaphore,
    626       1.1  riastrad 			   struct radeon_fence *fence);
    627       1.1  riastrad 
    628       1.1  riastrad /*
    629  1.3.32.1  christos  * Synchronization
    630  1.3.32.1  christos  */
    631  1.3.32.1  christos struct radeon_sync {
    632  1.3.32.1  christos 	struct radeon_semaphore *semaphores[RADEON_NUM_SYNCS];
    633  1.3.32.1  christos 	struct radeon_fence	*sync_to[RADEON_NUM_RINGS];
    634  1.3.32.1  christos 	struct radeon_fence	*last_vm_update;
    635  1.3.32.1  christos };
    636  1.3.32.1  christos 
    637  1.3.32.1  christos void radeon_sync_create(struct radeon_sync *sync);
    638  1.3.32.1  christos void radeon_sync_fence(struct radeon_sync *sync,
    639  1.3.32.1  christos 		       struct radeon_fence *fence);
    640  1.3.32.1  christos int radeon_sync_resv(struct radeon_device *rdev,
    641  1.3.32.1  christos 		     struct radeon_sync *sync,
    642  1.3.32.1  christos 		     struct reservation_object *resv,
    643  1.3.32.1  christos 		     bool shared);
    644  1.3.32.1  christos int radeon_sync_rings(struct radeon_device *rdev,
    645  1.3.32.1  christos 		      struct radeon_sync *sync,
    646  1.3.32.1  christos 		      int waiting_ring);
    647  1.3.32.1  christos void radeon_sync_free(struct radeon_device *rdev, struct radeon_sync *sync,
    648  1.3.32.1  christos 		      struct radeon_fence *fence);
    649  1.3.32.1  christos 
    650  1.3.32.1  christos /*
    651       1.1  riastrad  * GART structures, functions & helpers
    652       1.1  riastrad  */
    653       1.1  riastrad struct radeon_mc;
    654       1.1  riastrad 
    655       1.1  riastrad #define RADEON_GPU_PAGE_SIZE 4096
    656       1.1  riastrad #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
    657       1.1  riastrad #define RADEON_GPU_PAGE_SHIFT 12
    658       1.1  riastrad #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
    659       1.1  riastrad 
    660  1.3.32.1  christos #define RADEON_GART_PAGE_DUMMY  0
    661  1.3.32.1  christos #define RADEON_GART_PAGE_VALID	(1 << 0)
    662  1.3.32.1  christos #define RADEON_GART_PAGE_READ	(1 << 1)
    663  1.3.32.1  christos #define RADEON_GART_PAGE_WRITE	(1 << 2)
    664  1.3.32.1  christos #define RADEON_GART_PAGE_SNOOP	(1 << 3)
    665  1.3.32.1  christos 
    666       1.1  riastrad struct radeon_gart {
    667       1.2  riastrad #ifdef __NetBSD__
    668       1.2  riastrad 	bus_dma_segment_t		rg_table_seg;
    669       1.2  riastrad 	bus_dmamap_t			rg_table_map;
    670       1.2  riastrad #endif
    671       1.1  riastrad 	dma_addr_t			table_addr;
    672       1.1  riastrad 	struct radeon_bo		*robj;
    673       1.1  riastrad 	void				*ptr;
    674       1.1  riastrad 	unsigned			num_gpu_pages;
    675       1.1  riastrad 	unsigned			num_cpu_pages;
    676       1.1  riastrad 	unsigned			table_size;
    677       1.1  riastrad 	struct page			**pages;
    678  1.3.32.1  christos 	uint64_t			*pages_entry;
    679       1.1  riastrad 	bool				ready;
    680       1.1  riastrad };
    681       1.1  riastrad 
    682       1.1  riastrad int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
    683       1.1  riastrad void radeon_gart_table_ram_free(struct radeon_device *rdev);
    684       1.1  riastrad int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
    685       1.1  riastrad void radeon_gart_table_vram_free(struct radeon_device *rdev);
    686       1.1  riastrad int radeon_gart_table_vram_pin(struct radeon_device *rdev);
    687       1.1  riastrad void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
    688       1.1  riastrad int radeon_gart_init(struct radeon_device *rdev);
    689       1.1  riastrad void radeon_gart_fini(struct radeon_device *rdev);
    690       1.2  riastrad #ifdef __NetBSD__
    691       1.2  riastrad void radeon_gart_unbind(struct radeon_device *rdev, unsigned gpu_start,
    692       1.2  riastrad 			unsigned npages);
    693       1.2  riastrad int radeon_gart_bind(struct radeon_device *rdev, unsigned gpu_start,
    694       1.2  riastrad 		     unsigned npages, struct page **pages,
    695  1.3.32.1  christos 		     bus_dmamap_t dmamap, uint32_t flags);
    696       1.2  riastrad #else
    697       1.1  riastrad void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
    698       1.1  riastrad 			int pages);
    699       1.1  riastrad int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
    700       1.1  riastrad 		     int pages, struct page **pagelist,
    701  1.3.32.1  christos 		     dma_addr_t *dma_addr, uint32_t flags);
    702       1.2  riastrad #endif
    703       1.1  riastrad 
    704       1.1  riastrad 
    705       1.1  riastrad /*
    706       1.1  riastrad  * GPU MC structures, functions & helpers
    707       1.1  riastrad  */
    708       1.1  riastrad struct radeon_mc {
    709       1.1  riastrad 	resource_size_t		aper_size;
    710       1.1  riastrad 	resource_size_t		aper_base;
    711       1.1  riastrad 	resource_size_t		agp_base;
    712       1.1  riastrad 	/* for some chips with <= 32MB we need to lie
    713       1.1  riastrad 	 * about vram size near mc fb location */
    714       1.1  riastrad 	u64			mc_vram_size;
    715       1.1  riastrad 	u64			visible_vram_size;
    716       1.1  riastrad 	u64			gtt_size;
    717       1.1  riastrad 	u64			gtt_start;
    718       1.1  riastrad 	u64			gtt_end;
    719       1.1  riastrad 	u64			vram_start;
    720       1.1  riastrad 	u64			vram_end;
    721       1.1  riastrad 	unsigned		vram_width;
    722       1.1  riastrad 	u64			real_vram_size;
    723       1.1  riastrad 	int			vram_mtrr;
    724       1.1  riastrad 	bool			vram_is_ddr;
    725       1.1  riastrad 	bool			igp_sideport_enabled;
    726       1.1  riastrad 	u64                     gtt_base_align;
    727       1.1  riastrad 	u64                     mc_mask;
    728       1.1  riastrad };
    729       1.1  riastrad 
    730       1.1  riastrad bool radeon_combios_sideport_present(struct radeon_device *rdev);
    731       1.1  riastrad bool radeon_atombios_sideport_present(struct radeon_device *rdev);
    732       1.1  riastrad 
    733       1.1  riastrad /*
    734       1.1  riastrad  * GPU scratch registers structures, functions & helpers
    735       1.1  riastrad  */
    736       1.1  riastrad struct radeon_scratch {
    737       1.1  riastrad 	unsigned		num_reg;
    738       1.1  riastrad 	uint32_t                reg_base;
    739       1.1  riastrad 	bool			free[32];
    740       1.1  riastrad 	uint32_t		reg[32];
    741       1.1  riastrad };
    742       1.1  riastrad 
    743       1.1  riastrad int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
    744       1.1  riastrad void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
    745       1.1  riastrad 
    746       1.1  riastrad /*
    747       1.1  riastrad  * GPU doorbell structures, functions & helpers
    748       1.1  riastrad  */
    749       1.1  riastrad #define RADEON_MAX_DOORBELLS 1024	/* Reserve at most 1024 doorbell slots for radeon-owned rings. */
    750       1.1  riastrad 
    751       1.1  riastrad struct radeon_doorbell {
    752       1.1  riastrad 	/* doorbell mmio */
    753       1.1  riastrad 	resource_size_t		base;
    754       1.1  riastrad 	resource_size_t		size;
    755       1.2  riastrad #ifdef __NetBSD__
    756       1.2  riastrad 	bus_space_tag_t		bst;
    757       1.2  riastrad 	bus_space_handle_t	bsh;
    758       1.2  riastrad #else
    759       1.1  riastrad 	u32 __iomem		*ptr;
    760       1.2  riastrad #endif
    761       1.1  riastrad 	u32			num_doorbells;	/* Number of doorbells actually reserved for radeon. */
    762  1.3.32.1  christos 	DECLARE_BITMAP(used, RADEON_MAX_DOORBELLS);
    763       1.1  riastrad };
    764       1.1  riastrad 
    765       1.1  riastrad int radeon_doorbell_get(struct radeon_device *rdev, u32 *page);
    766       1.1  riastrad void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell);
    767  1.3.32.1  christos void radeon_doorbell_get_kfd_info(struct radeon_device *rdev,
    768  1.3.32.1  christos 				  phys_addr_t *aperture_base,
    769  1.3.32.1  christos 				  size_t *aperture_size,
    770  1.3.32.1  christos 				  size_t *start_offset);
    771       1.1  riastrad 
    772       1.1  riastrad /*
    773       1.1  riastrad  * IRQS.
    774       1.1  riastrad  */
    775       1.1  riastrad 
    776  1.3.32.1  christos struct radeon_flip_work {
    777  1.3.32.1  christos 	struct work_struct		flip_work;
    778  1.3.32.1  christos 	struct work_struct		unpin_work;
    779  1.3.32.1  christos 	struct radeon_device		*rdev;
    780  1.3.32.1  christos 	int				crtc_id;
    781  1.3.32.1  christos 	uint64_t			base;
    782       1.1  riastrad 	struct drm_pending_vblank_event *event;
    783  1.3.32.1  christos 	struct radeon_bo		*old_rbo;
    784  1.3.32.1  christos 	struct fence			*fence;
    785       1.1  riastrad };
    786       1.1  riastrad 
    787       1.1  riastrad struct r500_irq_stat_regs {
    788       1.1  riastrad 	u32 disp_int;
    789       1.1  riastrad 	u32 hdmi0_status;
    790       1.1  riastrad };
    791       1.1  riastrad 
    792       1.1  riastrad struct r600_irq_stat_regs {
    793       1.1  riastrad 	u32 disp_int;
    794       1.1  riastrad 	u32 disp_int_cont;
    795       1.1  riastrad 	u32 disp_int_cont2;
    796       1.1  riastrad 	u32 d1grph_int;
    797       1.1  riastrad 	u32 d2grph_int;
    798       1.1  riastrad 	u32 hdmi0_status;
    799       1.1  riastrad 	u32 hdmi1_status;
    800       1.1  riastrad };
    801       1.1  riastrad 
    802       1.1  riastrad struct evergreen_irq_stat_regs {
    803       1.1  riastrad 	u32 disp_int;
    804       1.1  riastrad 	u32 disp_int_cont;
    805       1.1  riastrad 	u32 disp_int_cont2;
    806       1.1  riastrad 	u32 disp_int_cont3;
    807       1.1  riastrad 	u32 disp_int_cont4;
    808       1.1  riastrad 	u32 disp_int_cont5;
    809       1.1  riastrad 	u32 d1grph_int;
    810       1.1  riastrad 	u32 d2grph_int;
    811       1.1  riastrad 	u32 d3grph_int;
    812       1.1  riastrad 	u32 d4grph_int;
    813       1.1  riastrad 	u32 d5grph_int;
    814       1.1  riastrad 	u32 d6grph_int;
    815       1.1  riastrad 	u32 afmt_status1;
    816       1.1  riastrad 	u32 afmt_status2;
    817       1.1  riastrad 	u32 afmt_status3;
    818       1.1  riastrad 	u32 afmt_status4;
    819       1.1  riastrad 	u32 afmt_status5;
    820       1.1  riastrad 	u32 afmt_status6;
    821       1.1  riastrad };
    822       1.1  riastrad 
    823       1.1  riastrad struct cik_irq_stat_regs {
    824       1.1  riastrad 	u32 disp_int;
    825       1.1  riastrad 	u32 disp_int_cont;
    826       1.1  riastrad 	u32 disp_int_cont2;
    827       1.1  riastrad 	u32 disp_int_cont3;
    828       1.1  riastrad 	u32 disp_int_cont4;
    829       1.1  riastrad 	u32 disp_int_cont5;
    830       1.1  riastrad 	u32 disp_int_cont6;
    831       1.1  riastrad 	u32 d1grph_int;
    832       1.1  riastrad 	u32 d2grph_int;
    833       1.1  riastrad 	u32 d3grph_int;
    834       1.1  riastrad 	u32 d4grph_int;
    835       1.1  riastrad 	u32 d5grph_int;
    836       1.1  riastrad 	u32 d6grph_int;
    837       1.1  riastrad };
    838       1.1  riastrad 
    839       1.1  riastrad union radeon_irq_stat_regs {
    840       1.1  riastrad 	struct r500_irq_stat_regs r500;
    841       1.1  riastrad 	struct r600_irq_stat_regs r600;
    842       1.1  riastrad 	struct evergreen_irq_stat_regs evergreen;
    843       1.1  riastrad 	struct cik_irq_stat_regs cik;
    844       1.1  riastrad };
    845       1.1  riastrad 
    846       1.1  riastrad struct radeon_irq {
    847       1.1  riastrad 	bool				installed;
    848       1.1  riastrad 	spinlock_t			lock;
    849       1.1  riastrad 	atomic_t			ring_int[RADEON_NUM_RINGS];
    850       1.1  riastrad 	bool				crtc_vblank_int[RADEON_MAX_CRTCS];
    851       1.1  riastrad 	atomic_t			pflip[RADEON_MAX_CRTCS];
    852       1.2  riastrad #ifdef __NetBSD__
    853       1.2  riastrad 	spinlock_t			vblank_lock;
    854       1.2  riastrad 	drm_waitqueue_t			vblank_queue;
    855       1.2  riastrad #else
    856       1.1  riastrad 	wait_queue_head_t		vblank_queue;
    857       1.2  riastrad #endif
    858       1.1  riastrad 	bool				hpd[RADEON_MAX_HPD_PINS];
    859       1.1  riastrad 	bool				afmt[RADEON_MAX_AFMT_BLOCKS];
    860       1.1  riastrad 	union radeon_irq_stat_regs	stat_regs;
    861       1.1  riastrad 	bool				dpm_thermal;
    862       1.1  riastrad };
    863       1.1  riastrad 
    864       1.1  riastrad int radeon_irq_kms_init(struct radeon_device *rdev);
    865       1.1  riastrad void radeon_irq_kms_fini(struct radeon_device *rdev);
    866       1.1  riastrad void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
    867  1.3.32.1  christos bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device *rdev, int ring);
    868       1.1  riastrad void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
    869       1.1  riastrad void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
    870       1.1  riastrad void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
    871       1.1  riastrad void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
    872       1.1  riastrad void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
    873       1.1  riastrad void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
    874       1.1  riastrad void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
    875       1.1  riastrad 
    876       1.1  riastrad /*
    877       1.1  riastrad  * CP & rings.
    878       1.1  riastrad  */
    879       1.1  riastrad 
    880       1.1  riastrad struct radeon_ib {
    881       1.1  riastrad 	struct radeon_sa_bo		*sa_bo;
    882       1.1  riastrad 	uint32_t			length_dw;
    883       1.1  riastrad 	uint64_t			gpu_addr;
    884       1.1  riastrad 	uint32_t			*ptr;
    885       1.1  riastrad 	int				ring;
    886       1.1  riastrad 	struct radeon_fence		*fence;
    887       1.1  riastrad 	struct radeon_vm		*vm;
    888       1.1  riastrad 	bool				is_const_ib;
    889  1.3.32.1  christos 	struct radeon_sync		sync;
    890       1.1  riastrad };
    891       1.1  riastrad 
    892       1.1  riastrad struct radeon_ring {
    893       1.1  riastrad 	struct radeon_bo	*ring_obj;
    894       1.1  riastrad 	volatile uint32_t	*ring;
    895       1.1  riastrad 	unsigned		rptr_offs;
    896       1.1  riastrad 	unsigned		rptr_save_reg;
    897       1.1  riastrad 	u64			next_rptr_gpu_addr;
    898       1.1  riastrad 	volatile u32		*next_rptr_cpu_addr;
    899       1.1  riastrad 	unsigned		wptr;
    900       1.1  riastrad 	unsigned		wptr_old;
    901       1.1  riastrad 	unsigned		ring_size;
    902       1.1  riastrad 	unsigned		ring_free_dw;
    903       1.1  riastrad 	int			count_dw;
    904       1.1  riastrad 	atomic_t		last_rptr;
    905       1.1  riastrad 	atomic64_t		last_activity;
    906       1.1  riastrad 	uint64_t		gpu_addr;
    907       1.1  riastrad 	uint32_t		align_mask;
    908       1.1  riastrad 	uint32_t		ptr_mask;
    909       1.1  riastrad 	bool			ready;
    910       1.1  riastrad 	u32			nop;
    911       1.1  riastrad 	u32			idx;
    912       1.1  riastrad 	u64			last_semaphore_signal_addr;
    913       1.1  riastrad 	u64			last_semaphore_wait_addr;
    914       1.1  riastrad 	/* for CIK queues */
    915       1.1  riastrad 	u32 me;
    916       1.1  riastrad 	u32 pipe;
    917       1.1  riastrad 	u32 queue;
    918       1.1  riastrad 	struct radeon_bo	*mqd_obj;
    919       1.1  riastrad 	u32 doorbell_index;
    920       1.1  riastrad 	unsigned		wptr_offs;
    921       1.1  riastrad };
    922       1.1  riastrad 
    923       1.1  riastrad struct radeon_mec {
    924       1.1  riastrad 	struct radeon_bo	*hpd_eop_obj;
    925       1.1  riastrad 	u64			hpd_eop_gpu_addr;
    926       1.1  riastrad 	u32 num_pipe;
    927       1.1  riastrad 	u32 num_mec;
    928       1.1  riastrad 	u32 num_queue;
    929       1.1  riastrad };
    930       1.1  riastrad 
    931       1.1  riastrad /*
    932       1.1  riastrad  * VM
    933       1.1  riastrad  */
    934       1.1  riastrad 
    935       1.1  riastrad /* maximum number of VMIDs */
    936       1.1  riastrad #define RADEON_NUM_VM	16
    937       1.1  riastrad 
    938       1.1  riastrad /* number of entries in page table */
    939  1.3.32.1  christos #define RADEON_VM_PTE_COUNT (1 << radeon_vm_block_size)
    940       1.1  riastrad 
    941       1.1  riastrad /* PTBs (Page Table Blocks) need to be aligned to 32K */
    942       1.1  riastrad #define RADEON_VM_PTB_ALIGN_SIZE   32768
    943       1.1  riastrad #define RADEON_VM_PTB_ALIGN_MASK (RADEON_VM_PTB_ALIGN_SIZE - 1)
    944       1.1  riastrad #define RADEON_VM_PTB_ALIGN(a) (((a) + RADEON_VM_PTB_ALIGN_MASK) & ~RADEON_VM_PTB_ALIGN_MASK)
    945       1.1  riastrad 
    946       1.1  riastrad #define R600_PTE_VALID		(1 << 0)
    947       1.1  riastrad #define R600_PTE_SYSTEM		(1 << 1)
    948       1.1  riastrad #define R600_PTE_SNOOPED	(1 << 2)
    949       1.1  riastrad #define R600_PTE_READABLE	(1 << 5)
    950       1.1  riastrad #define R600_PTE_WRITEABLE	(1 << 6)
    951       1.1  riastrad 
    952  1.3.32.1  christos /* PTE (Page Table Entry) fragment field for different page sizes */
    953  1.3.32.1  christos #define R600_PTE_FRAG_4KB	(0 << 7)
    954  1.3.32.1  christos #define R600_PTE_FRAG_64KB	(4 << 7)
    955  1.3.32.1  christos #define R600_PTE_FRAG_256KB	(6 << 7)
    956  1.3.32.1  christos 
    957  1.3.32.1  christos /* flags needed to be set so we can copy directly from the GART table */
    958  1.3.32.1  christos #define R600_PTE_GART_MASK	( R600_PTE_READABLE | R600_PTE_WRITEABLE | \
    959  1.3.32.1  christos 				  R600_PTE_SYSTEM | R600_PTE_VALID )
    960  1.3.32.1  christos 
    961       1.1  riastrad struct radeon_vm_pt {
    962       1.1  riastrad 	struct radeon_bo		*bo;
    963       1.1  riastrad 	uint64_t			addr;
    964       1.1  riastrad };
    965       1.1  riastrad 
    966  1.3.32.1  christos struct radeon_vm_id {
    967  1.3.32.1  christos 	unsigned		id;
    968  1.3.32.1  christos 	uint64_t		pd_gpu_addr;
    969  1.3.32.1  christos 	/* last flushed PD/PT update */
    970  1.3.32.1  christos 	struct radeon_fence	*flushed_updates;
    971  1.3.32.1  christos 	/* last use of vmid */
    972  1.3.32.1  christos 	struct radeon_fence	*last_id_use;
    973  1.3.32.1  christos };
    974  1.3.32.1  christos 
    975       1.1  riastrad struct radeon_vm {
    976  1.3.32.1  christos 	struct mutex		mutex;
    977  1.3.32.1  christos 
    978  1.3.32.1  christos 	struct rb_root		va;
    979  1.3.32.1  christos 
    980  1.3.32.1  christos 	/* protecting invalidated and freed */
    981  1.3.32.1  christos 	spinlock_t		status_lock;
    982  1.3.32.1  christos 
    983  1.3.32.1  christos 	/* BOs moved, but not yet updated in the PT */
    984  1.3.32.1  christos 	struct list_head	invalidated;
    985  1.3.32.1  christos 
    986  1.3.32.1  christos 	/* BOs freed, but not yet updated in the PT */
    987  1.3.32.1  christos 	struct list_head	freed;
    988  1.3.32.1  christos 
    989  1.3.32.1  christos 	/* BOs cleared in the PT */
    990  1.3.32.1  christos 	struct list_head	cleared;
    991       1.1  riastrad 
    992       1.1  riastrad 	/* contains the page directory */
    993  1.3.32.1  christos 	struct radeon_bo	*page_directory;
    994  1.3.32.1  christos 	unsigned		max_pde_used;
    995       1.1  riastrad 
    996       1.1  riastrad 	/* array of page tables, one for each page directory entry */
    997  1.3.32.1  christos 	struct radeon_vm_pt	*page_tables;
    998       1.1  riastrad 
    999  1.3.32.1  christos 	struct radeon_bo_va	*ib_bo_va;
   1000  1.3.32.1  christos 
   1001  1.3.32.1  christos 	/* for id and flush management per ring */
   1002  1.3.32.1  christos 	struct radeon_vm_id	ids[RADEON_NUM_RINGS];
   1003       1.1  riastrad };
   1004       1.1  riastrad 
   1005       1.1  riastrad struct radeon_vm_manager {
   1006       1.1  riastrad 	struct radeon_fence		*active[RADEON_NUM_VM];
   1007       1.1  riastrad 	uint32_t			max_pfn;
   1008       1.1  riastrad 	/* number of VMIDs */
   1009       1.1  riastrad 	unsigned			nvm;
   1010       1.1  riastrad 	/* vram base address for page table entry  */
   1011       1.1  riastrad 	u64				vram_base_offset;
   1012       1.1  riastrad 	/* is vm enabled? */
   1013       1.1  riastrad 	bool				enabled;
   1014  1.3.32.1  christos 	/* for hw to save the PD addr on suspend/resume */
   1015  1.3.32.1  christos 	uint32_t			saved_table_addr[RADEON_NUM_VM];
   1016       1.1  riastrad };
   1017       1.1  riastrad 
   1018       1.1  riastrad /*
   1019       1.1  riastrad  * file private structure
   1020       1.1  riastrad  */
   1021       1.1  riastrad struct radeon_fpriv {
   1022       1.1  riastrad 	struct radeon_vm		vm;
   1023       1.1  riastrad };
   1024       1.1  riastrad 
   1025       1.1  riastrad /*
   1026       1.1  riastrad  * R6xx+ IH ring
   1027       1.1  riastrad  */
   1028       1.1  riastrad struct r600_ih {
   1029       1.1  riastrad 	struct radeon_bo	*ring_obj;
   1030       1.1  riastrad 	volatile uint32_t	*ring;
   1031       1.1  riastrad 	unsigned		rptr;
   1032       1.1  riastrad 	unsigned		ring_size;
   1033       1.1  riastrad 	uint64_t		gpu_addr;
   1034       1.1  riastrad 	uint32_t		ptr_mask;
   1035       1.1  riastrad 	atomic_t		lock;
   1036       1.1  riastrad 	bool                    enabled;
   1037       1.1  riastrad };
   1038       1.1  riastrad 
   1039       1.1  riastrad /*
   1040       1.1  riastrad  * RLC stuff
   1041       1.1  riastrad  */
   1042       1.1  riastrad #include "clearstate_defs.h"
   1043       1.1  riastrad 
   1044       1.1  riastrad struct radeon_rlc {
   1045       1.1  riastrad 	/* for power gating */
   1046       1.1  riastrad 	struct radeon_bo	*save_restore_obj;
   1047       1.1  riastrad 	uint64_t		save_restore_gpu_addr;
   1048       1.1  riastrad 	volatile uint32_t	*sr_ptr;
   1049       1.1  riastrad 	const u32               *reg_list;
   1050       1.1  riastrad 	u32                     reg_list_size;
   1051       1.1  riastrad 	/* for clear state */
   1052       1.1  riastrad 	struct radeon_bo	*clear_state_obj;
   1053       1.1  riastrad 	uint64_t		clear_state_gpu_addr;
   1054       1.1  riastrad 	volatile uint32_t	*cs_ptr;
   1055       1.1  riastrad 	const struct cs_section_def   *cs_data;
   1056       1.1  riastrad 	u32                     clear_state_size;
   1057       1.1  riastrad 	/* for cp tables */
   1058       1.1  riastrad 	struct radeon_bo	*cp_table_obj;
   1059       1.1  riastrad 	uint64_t		cp_table_gpu_addr;
   1060       1.1  riastrad 	volatile uint32_t	*cp_table_ptr;
   1061       1.1  riastrad 	u32                     cp_table_size;
   1062       1.1  riastrad };
   1063       1.1  riastrad 
   1064       1.1  riastrad int radeon_ib_get(struct radeon_device *rdev, int ring,
   1065       1.1  riastrad 		  struct radeon_ib *ib, struct radeon_vm *vm,
   1066       1.1  riastrad 		  unsigned size);
   1067       1.1  riastrad void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
   1068       1.1  riastrad int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
   1069  1.3.32.1  christos 		       struct radeon_ib *const_ib, bool hdp_flush);
   1070       1.1  riastrad int radeon_ib_pool_init(struct radeon_device *rdev);
   1071       1.1  riastrad void radeon_ib_pool_fini(struct radeon_device *rdev);
   1072       1.1  riastrad int radeon_ib_ring_tests(struct radeon_device *rdev);
   1073       1.1  riastrad /* Ring access between begin & end cannot sleep */
   1074       1.1  riastrad bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
   1075       1.1  riastrad 				      struct radeon_ring *ring);
   1076       1.1  riastrad void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
   1077       1.1  riastrad int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
   1078       1.1  riastrad int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
   1079  1.3.32.1  christos void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp,
   1080  1.3.32.1  christos 			bool hdp_flush);
   1081  1.3.32.1  christos void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp,
   1082  1.3.32.1  christos 			       bool hdp_flush);
   1083       1.1  riastrad void radeon_ring_undo(struct radeon_ring *ring);
   1084       1.1  riastrad void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
   1085       1.1  riastrad int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
   1086       1.1  riastrad void radeon_ring_lockup_update(struct radeon_device *rdev,
   1087       1.1  riastrad 			       struct radeon_ring *ring);
   1088       1.1  riastrad bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
   1089       1.1  riastrad unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
   1090       1.1  riastrad 			    uint32_t **data);
   1091       1.1  riastrad int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
   1092       1.1  riastrad 			unsigned size, uint32_t *data);
   1093       1.1  riastrad int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
   1094       1.1  riastrad 		     unsigned rptr_offs, u32 nop);
   1095       1.1  riastrad void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
   1096       1.1  riastrad 
   1097       1.1  riastrad 
   1098       1.1  riastrad /* r600 async dma */
   1099       1.1  riastrad void r600_dma_stop(struct radeon_device *rdev);
   1100       1.1  riastrad int r600_dma_resume(struct radeon_device *rdev);
   1101       1.1  riastrad void r600_dma_fini(struct radeon_device *rdev);
   1102       1.1  riastrad 
   1103       1.1  riastrad void cayman_dma_stop(struct radeon_device *rdev);
   1104       1.1  riastrad int cayman_dma_resume(struct radeon_device *rdev);
   1105       1.1  riastrad void cayman_dma_fini(struct radeon_device *rdev);
   1106       1.1  riastrad 
   1107       1.1  riastrad /*
   1108       1.1  riastrad  * CS.
   1109       1.1  riastrad  */
   1110       1.1  riastrad struct radeon_cs_chunk {
   1111       1.1  riastrad 	uint32_t		length_dw;
   1112       1.1  riastrad 	uint32_t		*kdata;
   1113       1.1  riastrad 	void __user		*user_ptr;
   1114       1.1  riastrad };
   1115       1.1  riastrad 
   1116       1.1  riastrad struct radeon_cs_parser {
   1117       1.1  riastrad 	struct device		*dev;
   1118       1.1  riastrad 	struct radeon_device	*rdev;
   1119       1.1  riastrad 	struct drm_file		*filp;
   1120       1.1  riastrad 	/* chunks */
   1121       1.1  riastrad 	unsigned		nchunks;
   1122       1.1  riastrad 	struct radeon_cs_chunk	*chunks;
   1123       1.1  riastrad 	uint64_t		*chunks_array;
   1124       1.1  riastrad 	/* IB */
   1125       1.1  riastrad 	unsigned		idx;
   1126       1.1  riastrad 	/* relocations */
   1127       1.1  riastrad 	unsigned		nrelocs;
   1128  1.3.32.1  christos 	struct radeon_bo_list	*relocs;
   1129  1.3.32.1  christos 	struct radeon_bo_list	*vm_bos;
   1130       1.1  riastrad 	struct list_head	validated;
   1131       1.1  riastrad 	unsigned		dma_reloc_idx;
   1132       1.1  riastrad 	/* indices of various chunks */
   1133  1.3.32.1  christos 	struct radeon_cs_chunk  *chunk_ib;
   1134  1.3.32.1  christos 	struct radeon_cs_chunk  *chunk_relocs;
   1135  1.3.32.1  christos 	struct radeon_cs_chunk  *chunk_flags;
   1136  1.3.32.1  christos 	struct radeon_cs_chunk  *chunk_const_ib;
   1137       1.1  riastrad 	struct radeon_ib	ib;
   1138       1.1  riastrad 	struct radeon_ib	const_ib;
   1139       1.1  riastrad 	void			*track;
   1140       1.1  riastrad 	unsigned		family;
   1141       1.1  riastrad 	int			parser_error;
   1142       1.1  riastrad 	u32			cs_flags;
   1143       1.1  riastrad 	u32			ring;
   1144       1.1  riastrad 	s32			priority;
   1145       1.1  riastrad 	struct ww_acquire_ctx	ticket;
   1146       1.1  riastrad };
   1147       1.1  riastrad 
   1148       1.1  riastrad static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
   1149       1.1  riastrad {
   1150  1.3.32.1  christos 	struct radeon_cs_chunk *ibc = p->chunk_ib;
   1151       1.1  riastrad 
   1152       1.1  riastrad 	if (ibc->kdata)
   1153       1.1  riastrad 		return ibc->kdata[idx];
   1154       1.1  riastrad 	return p->ib.ptr[idx];
   1155       1.1  riastrad }
   1156       1.1  riastrad 
   1157       1.1  riastrad 
   1158       1.1  riastrad struct radeon_cs_packet {
   1159       1.1  riastrad 	unsigned	idx;
   1160       1.1  riastrad 	unsigned	type;
   1161       1.1  riastrad 	unsigned	reg;
   1162       1.1  riastrad 	unsigned	opcode;
   1163       1.1  riastrad 	int		count;
   1164       1.1  riastrad 	unsigned	one_reg_wr;
   1165       1.1  riastrad };
   1166       1.1  riastrad 
   1167       1.1  riastrad typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
   1168       1.1  riastrad 				      struct radeon_cs_packet *pkt,
   1169       1.1  riastrad 				      unsigned idx, unsigned reg);
   1170       1.1  riastrad typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
   1171       1.1  riastrad 				      struct radeon_cs_packet *pkt);
   1172       1.1  riastrad 
   1173       1.1  riastrad 
   1174       1.1  riastrad /*
   1175       1.1  riastrad  * AGP
   1176       1.1  riastrad  */
   1177       1.1  riastrad int radeon_agp_init(struct radeon_device *rdev);
   1178       1.1  riastrad void radeon_agp_resume(struct radeon_device *rdev);
   1179       1.1  riastrad void radeon_agp_suspend(struct radeon_device *rdev);
   1180       1.1  riastrad void radeon_agp_fini(struct radeon_device *rdev);
   1181       1.1  riastrad 
   1182       1.1  riastrad 
   1183       1.1  riastrad /*
   1184       1.1  riastrad  * Writeback
   1185       1.1  riastrad  */
   1186       1.1  riastrad struct radeon_wb {
   1187       1.1  riastrad 	struct radeon_bo	*wb_obj;
   1188       1.1  riastrad 	volatile uint32_t	*wb;
   1189       1.1  riastrad 	uint64_t		gpu_addr;
   1190       1.1  riastrad 	bool                    enabled;
   1191       1.1  riastrad 	bool                    use_event;
   1192       1.1  riastrad };
   1193       1.1  riastrad 
   1194       1.1  riastrad #define RADEON_WB_SCRATCH_OFFSET 0
   1195       1.1  riastrad #define RADEON_WB_RING0_NEXT_RPTR 256
   1196       1.1  riastrad #define RADEON_WB_CP_RPTR_OFFSET 1024
   1197       1.1  riastrad #define RADEON_WB_CP1_RPTR_OFFSET 1280
   1198       1.1  riastrad #define RADEON_WB_CP2_RPTR_OFFSET 1536
   1199       1.1  riastrad #define R600_WB_DMA_RPTR_OFFSET   1792
   1200       1.1  riastrad #define R600_WB_IH_WPTR_OFFSET   2048
   1201       1.1  riastrad #define CAYMAN_WB_DMA1_RPTR_OFFSET   2304
   1202       1.1  riastrad #define R600_WB_EVENT_OFFSET     3072
   1203       1.1  riastrad #define CIK_WB_CP1_WPTR_OFFSET     3328
   1204       1.1  riastrad #define CIK_WB_CP2_WPTR_OFFSET     3584
   1205  1.3.32.1  christos #define R600_WB_DMA_RING_TEST_OFFSET 3588
   1206  1.3.32.1  christos #define CAYMAN_WB_DMA1_RING_TEST_OFFSET 3592
   1207       1.1  riastrad 
   1208       1.1  riastrad /**
   1209       1.1  riastrad  * struct radeon_pm - power management datas
   1210       1.1  riastrad  * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
   1211       1.1  riastrad  * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
   1212       1.1  riastrad  * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
   1213       1.1  riastrad  * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
   1214       1.1  riastrad  * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
   1215       1.1  riastrad  * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
   1216       1.1  riastrad  * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
   1217       1.1  riastrad  * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
   1218       1.1  riastrad  * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
   1219       1.1  riastrad  * @sclk:          	GPU clock Mhz (core bandwidth depends of this clock)
   1220       1.1  riastrad  * @needed_bandwidth:   current bandwidth needs
   1221       1.1  riastrad  *
   1222       1.1  riastrad  * It keeps track of various data needed to take powermanagement decision.
   1223       1.1  riastrad  * Bandwidth need is used to determine minimun clock of the GPU and memory.
   1224       1.1  riastrad  * Equation between gpu/memory clock and available bandwidth is hw dependent
   1225       1.1  riastrad  * (type of memory, bus size, efficiency, ...)
   1226       1.1  riastrad  */
   1227       1.1  riastrad 
   1228       1.1  riastrad enum radeon_pm_method {
   1229       1.1  riastrad 	PM_METHOD_PROFILE,
   1230       1.1  riastrad 	PM_METHOD_DYNPM,
   1231       1.1  riastrad 	PM_METHOD_DPM,
   1232       1.1  riastrad };
   1233       1.1  riastrad 
   1234       1.1  riastrad enum radeon_dynpm_state {
   1235       1.1  riastrad 	DYNPM_STATE_DISABLED,
   1236       1.1  riastrad 	DYNPM_STATE_MINIMUM,
   1237       1.1  riastrad 	DYNPM_STATE_PAUSED,
   1238       1.1  riastrad 	DYNPM_STATE_ACTIVE,
   1239       1.1  riastrad 	DYNPM_STATE_SUSPENDED,
   1240       1.1  riastrad };
   1241       1.1  riastrad enum radeon_dynpm_action {
   1242       1.1  riastrad 	DYNPM_ACTION_NONE,
   1243       1.1  riastrad 	DYNPM_ACTION_MINIMUM,
   1244       1.1  riastrad 	DYNPM_ACTION_DOWNCLOCK,
   1245       1.1  riastrad 	DYNPM_ACTION_UPCLOCK,
   1246       1.1  riastrad 	DYNPM_ACTION_DEFAULT
   1247       1.1  riastrad };
   1248       1.1  riastrad 
   1249       1.1  riastrad enum radeon_voltage_type {
   1250       1.1  riastrad 	VOLTAGE_NONE = 0,
   1251       1.1  riastrad 	VOLTAGE_GPIO,
   1252       1.1  riastrad 	VOLTAGE_VDDC,
   1253       1.1  riastrad 	VOLTAGE_SW
   1254       1.1  riastrad };
   1255       1.1  riastrad 
   1256       1.1  riastrad enum radeon_pm_state_type {
   1257       1.1  riastrad 	/* not used for dpm */
   1258       1.1  riastrad 	POWER_STATE_TYPE_DEFAULT,
   1259       1.1  riastrad 	POWER_STATE_TYPE_POWERSAVE,
   1260       1.1  riastrad 	/* user selectable states */
   1261       1.1  riastrad 	POWER_STATE_TYPE_BATTERY,
   1262       1.1  riastrad 	POWER_STATE_TYPE_BALANCED,
   1263       1.1  riastrad 	POWER_STATE_TYPE_PERFORMANCE,
   1264       1.1  riastrad 	/* internal states */
   1265       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_UVD,
   1266       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_UVD_SD,
   1267       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_UVD_HD,
   1268       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_UVD_HD2,
   1269       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_UVD_MVC,
   1270       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_BOOT,
   1271       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_THERMAL,
   1272       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_ACPI,
   1273       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_ULV,
   1274       1.1  riastrad 	POWER_STATE_TYPE_INTERNAL_3DPERF,
   1275       1.1  riastrad };
   1276       1.1  riastrad 
   1277       1.1  riastrad enum radeon_pm_profile_type {
   1278       1.1  riastrad 	PM_PROFILE_DEFAULT,
   1279       1.1  riastrad 	PM_PROFILE_AUTO,
   1280       1.1  riastrad 	PM_PROFILE_LOW,
   1281       1.1  riastrad 	PM_PROFILE_MID,
   1282       1.1  riastrad 	PM_PROFILE_HIGH,
   1283       1.1  riastrad };
   1284       1.1  riastrad 
   1285       1.1  riastrad #define PM_PROFILE_DEFAULT_IDX 0
   1286       1.1  riastrad #define PM_PROFILE_LOW_SH_IDX  1
   1287       1.1  riastrad #define PM_PROFILE_MID_SH_IDX  2
   1288       1.1  riastrad #define PM_PROFILE_HIGH_SH_IDX 3
   1289       1.1  riastrad #define PM_PROFILE_LOW_MH_IDX  4
   1290       1.1  riastrad #define PM_PROFILE_MID_MH_IDX  5
   1291       1.1  riastrad #define PM_PROFILE_HIGH_MH_IDX 6
   1292       1.1  riastrad #define PM_PROFILE_MAX         7
   1293       1.1  riastrad 
   1294       1.1  riastrad struct radeon_pm_profile {
   1295       1.1  riastrad 	int dpms_off_ps_idx;
   1296       1.1  riastrad 	int dpms_on_ps_idx;
   1297       1.1  riastrad 	int dpms_off_cm_idx;
   1298       1.1  riastrad 	int dpms_on_cm_idx;
   1299       1.1  riastrad };
   1300       1.1  riastrad 
   1301       1.1  riastrad enum radeon_int_thermal_type {
   1302       1.1  riastrad 	THERMAL_TYPE_NONE,
   1303       1.1  riastrad 	THERMAL_TYPE_EXTERNAL,
   1304       1.1  riastrad 	THERMAL_TYPE_EXTERNAL_GPIO,
   1305       1.1  riastrad 	THERMAL_TYPE_RV6XX,
   1306       1.1  riastrad 	THERMAL_TYPE_RV770,
   1307       1.1  riastrad 	THERMAL_TYPE_ADT7473_WITH_INTERNAL,
   1308       1.1  riastrad 	THERMAL_TYPE_EVERGREEN,
   1309       1.1  riastrad 	THERMAL_TYPE_SUMO,
   1310       1.1  riastrad 	THERMAL_TYPE_NI,
   1311       1.1  riastrad 	THERMAL_TYPE_SI,
   1312       1.1  riastrad 	THERMAL_TYPE_EMC2103_WITH_INTERNAL,
   1313       1.1  riastrad 	THERMAL_TYPE_CI,
   1314       1.1  riastrad 	THERMAL_TYPE_KV,
   1315       1.1  riastrad };
   1316       1.1  riastrad 
   1317       1.1  riastrad struct radeon_voltage {
   1318       1.1  riastrad 	enum radeon_voltage_type type;
   1319       1.1  riastrad 	/* gpio voltage */
   1320       1.1  riastrad 	struct radeon_gpio_rec gpio;
   1321       1.1  riastrad 	u32 delay; /* delay in usec from voltage drop to sclk change */
   1322       1.1  riastrad 	bool active_high; /* voltage drop is active when bit is high */
   1323       1.1  riastrad 	/* VDDC voltage */
   1324       1.1  riastrad 	u8 vddc_id; /* index into vddc voltage table */
   1325       1.1  riastrad 	u8 vddci_id; /* index into vddci voltage table */
   1326       1.1  riastrad 	bool vddci_enabled;
   1327       1.1  riastrad 	/* r6xx+ sw */
   1328       1.1  riastrad 	u16 voltage;
   1329       1.1  riastrad 	/* evergreen+ vddci */
   1330       1.1  riastrad 	u16 vddci;
   1331       1.1  riastrad };
   1332       1.1  riastrad 
   1333       1.1  riastrad /* clock mode flags */
   1334       1.1  riastrad #define RADEON_PM_MODE_NO_DISPLAY          (1 << 0)
   1335       1.1  riastrad 
   1336       1.1  riastrad struct radeon_pm_clock_info {
   1337       1.1  riastrad 	/* memory clock */
   1338       1.1  riastrad 	u32 mclk;
   1339       1.1  riastrad 	/* engine clock */
   1340       1.1  riastrad 	u32 sclk;
   1341       1.1  riastrad 	/* voltage info */
   1342       1.1  riastrad 	struct radeon_voltage voltage;
   1343       1.1  riastrad 	/* standardized clock flags */
   1344       1.1  riastrad 	u32 flags;
   1345       1.1  riastrad };
   1346       1.1  riastrad 
   1347       1.1  riastrad /* state flags */
   1348       1.1  riastrad #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
   1349       1.1  riastrad 
   1350       1.1  riastrad struct radeon_power_state {
   1351       1.1  riastrad 	enum radeon_pm_state_type type;
   1352       1.1  riastrad 	struct radeon_pm_clock_info *clock_info;
   1353       1.1  riastrad 	/* number of valid clock modes in this power state */
   1354       1.1  riastrad 	int num_clock_modes;
   1355       1.1  riastrad 	struct radeon_pm_clock_info *default_clock_mode;
   1356       1.1  riastrad 	/* standardized state flags */
   1357       1.1  riastrad 	u32 flags;
   1358       1.1  riastrad 	u32 misc; /* vbios specific flags */
   1359       1.1  riastrad 	u32 misc2; /* vbios specific flags */
   1360       1.1  riastrad 	int pcie_lanes; /* pcie lanes */
   1361       1.1  riastrad };
   1362       1.1  riastrad 
   1363       1.1  riastrad /*
   1364       1.1  riastrad  * Some modes are overclocked by very low value, accept them
   1365       1.1  riastrad  */
   1366       1.1  riastrad #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
   1367       1.1  riastrad 
   1368       1.1  riastrad enum radeon_dpm_auto_throttle_src {
   1369       1.1  riastrad 	RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL,
   1370       1.1  riastrad 	RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
   1371       1.1  riastrad };
   1372       1.1  riastrad 
   1373       1.1  riastrad enum radeon_dpm_event_src {
   1374       1.1  riastrad 	RADEON_DPM_EVENT_SRC_ANALOG = 0,
   1375       1.1  riastrad 	RADEON_DPM_EVENT_SRC_EXTERNAL = 1,
   1376       1.1  riastrad 	RADEON_DPM_EVENT_SRC_DIGITAL = 2,
   1377       1.1  riastrad 	RADEON_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
   1378       1.1  riastrad 	RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
   1379       1.1  riastrad };
   1380       1.1  riastrad 
   1381       1.1  riastrad #define RADEON_MAX_VCE_LEVELS 6
   1382       1.1  riastrad 
   1383       1.1  riastrad enum radeon_vce_level {
   1384       1.1  riastrad 	RADEON_VCE_LEVEL_AC_ALL = 0,     /* AC, All cases */
   1385       1.1  riastrad 	RADEON_VCE_LEVEL_DC_EE = 1,      /* DC, entropy encoding */
   1386       1.1  riastrad 	RADEON_VCE_LEVEL_DC_LL_LOW = 2,  /* DC, low latency queue, res <= 720 */
   1387       1.1  riastrad 	RADEON_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
   1388       1.1  riastrad 	RADEON_VCE_LEVEL_DC_GP_LOW = 4,  /* DC, general purpose queue, res <= 720 */
   1389       1.1  riastrad 	RADEON_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
   1390       1.1  riastrad };
   1391       1.1  riastrad 
   1392       1.1  riastrad struct radeon_ps {
   1393       1.1  riastrad 	u32 caps; /* vbios flags */
   1394       1.1  riastrad 	u32 class; /* vbios flags */
   1395       1.1  riastrad 	u32 class2; /* vbios flags */
   1396       1.1  riastrad 	/* UVD clocks */
   1397       1.1  riastrad 	u32 vclk;
   1398       1.1  riastrad 	u32 dclk;
   1399       1.1  riastrad 	/* VCE clocks */
   1400       1.1  riastrad 	u32 evclk;
   1401       1.1  riastrad 	u32 ecclk;
   1402       1.1  riastrad 	bool vce_active;
   1403       1.1  riastrad 	enum radeon_vce_level vce_level;
   1404       1.1  riastrad 	/* asic priv */
   1405       1.1  riastrad 	void *ps_priv;
   1406       1.1  riastrad };
   1407       1.1  riastrad 
   1408       1.1  riastrad struct radeon_dpm_thermal {
   1409       1.1  riastrad 	/* thermal interrupt work */
   1410       1.1  riastrad 	struct work_struct work;
   1411       1.1  riastrad 	/* low temperature threshold */
   1412       1.1  riastrad 	int                min_temp;
   1413       1.1  riastrad 	/* high temperature threshold */
   1414       1.1  riastrad 	int                max_temp;
   1415       1.1  riastrad 	/* was interrupt low to high or high to low */
   1416       1.1  riastrad 	bool               high_to_low;
   1417       1.1  riastrad };
   1418       1.1  riastrad 
   1419       1.1  riastrad enum radeon_clk_action
   1420       1.1  riastrad {
   1421       1.1  riastrad 	RADEON_SCLK_UP = 1,
   1422       1.1  riastrad 	RADEON_SCLK_DOWN
   1423       1.1  riastrad };
   1424       1.1  riastrad 
   1425       1.1  riastrad struct radeon_blacklist_clocks
   1426       1.1  riastrad {
   1427       1.1  riastrad 	u32 sclk;
   1428       1.1  riastrad 	u32 mclk;
   1429       1.1  riastrad 	enum radeon_clk_action action;
   1430       1.1  riastrad };
   1431       1.1  riastrad 
   1432       1.1  riastrad struct radeon_clock_and_voltage_limits {
   1433       1.1  riastrad 	u32 sclk;
   1434       1.1  riastrad 	u32 mclk;
   1435       1.1  riastrad 	u16 vddc;
   1436       1.1  riastrad 	u16 vddci;
   1437       1.1  riastrad };
   1438       1.1  riastrad 
   1439       1.1  riastrad struct radeon_clock_array {
   1440       1.1  riastrad 	u32 count;
   1441       1.1  riastrad 	u32 *values;
   1442       1.1  riastrad };
   1443       1.1  riastrad 
   1444       1.1  riastrad struct radeon_clock_voltage_dependency_entry {
   1445       1.1  riastrad 	u32 clk;
   1446       1.1  riastrad 	u16 v;
   1447       1.1  riastrad };
   1448       1.1  riastrad 
   1449       1.1  riastrad struct radeon_clock_voltage_dependency_table {
   1450       1.1  riastrad 	u32 count;
   1451       1.1  riastrad 	struct radeon_clock_voltage_dependency_entry *entries;
   1452       1.1  riastrad };
   1453       1.1  riastrad 
   1454       1.1  riastrad union radeon_cac_leakage_entry {
   1455       1.1  riastrad 	struct {
   1456       1.1  riastrad 		u16 vddc;
   1457       1.1  riastrad 		u32 leakage;
   1458       1.1  riastrad 	};
   1459       1.1  riastrad 	struct {
   1460       1.1  riastrad 		u16 vddc1;
   1461       1.1  riastrad 		u16 vddc2;
   1462       1.1  riastrad 		u16 vddc3;
   1463       1.1  riastrad 	};
   1464       1.1  riastrad };
   1465       1.1  riastrad 
   1466       1.1  riastrad struct radeon_cac_leakage_table {
   1467       1.1  riastrad 	u32 count;
   1468       1.1  riastrad 	union radeon_cac_leakage_entry *entries;
   1469       1.1  riastrad };
   1470       1.1  riastrad 
   1471       1.1  riastrad struct radeon_phase_shedding_limits_entry {
   1472       1.1  riastrad 	u16 voltage;
   1473       1.1  riastrad 	u32 sclk;
   1474       1.1  riastrad 	u32 mclk;
   1475       1.1  riastrad };
   1476       1.1  riastrad 
   1477       1.1  riastrad struct radeon_phase_shedding_limits_table {
   1478       1.1  riastrad 	u32 count;
   1479       1.1  riastrad 	struct radeon_phase_shedding_limits_entry *entries;
   1480       1.1  riastrad };
   1481       1.1  riastrad 
   1482       1.1  riastrad struct radeon_uvd_clock_voltage_dependency_entry {
   1483       1.1  riastrad 	u32 vclk;
   1484       1.1  riastrad 	u32 dclk;
   1485       1.1  riastrad 	u16 v;
   1486       1.1  riastrad };
   1487       1.1  riastrad 
   1488       1.1  riastrad struct radeon_uvd_clock_voltage_dependency_table {
   1489       1.1  riastrad 	u8 count;
   1490       1.1  riastrad 	struct radeon_uvd_clock_voltage_dependency_entry *entries;
   1491       1.1  riastrad };
   1492       1.1  riastrad 
   1493       1.1  riastrad struct radeon_vce_clock_voltage_dependency_entry {
   1494       1.1  riastrad 	u32 ecclk;
   1495       1.1  riastrad 	u32 evclk;
   1496       1.1  riastrad 	u16 v;
   1497       1.1  riastrad };
   1498       1.1  riastrad 
   1499       1.1  riastrad struct radeon_vce_clock_voltage_dependency_table {
   1500       1.1  riastrad 	u8 count;
   1501       1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_entry *entries;
   1502       1.1  riastrad };
   1503       1.1  riastrad 
   1504       1.1  riastrad struct radeon_ppm_table {
   1505       1.1  riastrad 	u8 ppm_design;
   1506       1.1  riastrad 	u16 cpu_core_number;
   1507       1.1  riastrad 	u32 platform_tdp;
   1508       1.1  riastrad 	u32 small_ac_platform_tdp;
   1509       1.1  riastrad 	u32 platform_tdc;
   1510       1.1  riastrad 	u32 small_ac_platform_tdc;
   1511       1.1  riastrad 	u32 apu_tdp;
   1512       1.1  riastrad 	u32 dgpu_tdp;
   1513       1.1  riastrad 	u32 dgpu_ulv_power;
   1514       1.1  riastrad 	u32 tj_max;
   1515       1.1  riastrad };
   1516       1.1  riastrad 
   1517       1.1  riastrad struct radeon_cac_tdp_table {
   1518       1.1  riastrad 	u16 tdp;
   1519       1.1  riastrad 	u16 configurable_tdp;
   1520       1.1  riastrad 	u16 tdc;
   1521       1.1  riastrad 	u16 battery_power_limit;
   1522       1.1  riastrad 	u16 small_power_limit;
   1523       1.1  riastrad 	u16 low_cac_leakage;
   1524       1.1  riastrad 	u16 high_cac_leakage;
   1525       1.1  riastrad 	u16 maximum_power_delivery_limit;
   1526       1.1  riastrad };
   1527       1.1  riastrad 
   1528       1.1  riastrad struct radeon_dpm_dynamic_state {
   1529       1.1  riastrad 	struct radeon_clock_voltage_dependency_table vddc_dependency_on_sclk;
   1530       1.1  riastrad 	struct radeon_clock_voltage_dependency_table vddci_dependency_on_mclk;
   1531       1.1  riastrad 	struct radeon_clock_voltage_dependency_table vddc_dependency_on_mclk;
   1532       1.1  riastrad 	struct radeon_clock_voltage_dependency_table mvdd_dependency_on_mclk;
   1533       1.1  riastrad 	struct radeon_clock_voltage_dependency_table vddc_dependency_on_dispclk;
   1534       1.1  riastrad 	struct radeon_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
   1535       1.1  riastrad 	struct radeon_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
   1536       1.1  riastrad 	struct radeon_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
   1537       1.1  riastrad 	struct radeon_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
   1538       1.1  riastrad 	struct radeon_clock_array valid_sclk_values;
   1539       1.1  riastrad 	struct radeon_clock_array valid_mclk_values;
   1540       1.1  riastrad 	struct radeon_clock_and_voltage_limits max_clock_voltage_on_dc;
   1541       1.1  riastrad 	struct radeon_clock_and_voltage_limits max_clock_voltage_on_ac;
   1542       1.1  riastrad 	u32 mclk_sclk_ratio;
   1543       1.1  riastrad 	u32 sclk_mclk_delta;
   1544       1.1  riastrad 	u16 vddc_vddci_delta;
   1545       1.1  riastrad 	u16 min_vddc_for_pcie_gen2;
   1546       1.1  riastrad 	struct radeon_cac_leakage_table cac_leakage_table;
   1547       1.1  riastrad 	struct radeon_phase_shedding_limits_table phase_shedding_limits_table;
   1548       1.1  riastrad 	struct radeon_ppm_table *ppm_table;
   1549       1.1  riastrad 	struct radeon_cac_tdp_table *cac_tdp_table;
   1550       1.1  riastrad };
   1551       1.1  riastrad 
   1552       1.1  riastrad struct radeon_dpm_fan {
   1553       1.1  riastrad 	u16 t_min;
   1554       1.1  riastrad 	u16 t_med;
   1555       1.1  riastrad 	u16 t_high;
   1556       1.1  riastrad 	u16 pwm_min;
   1557       1.1  riastrad 	u16 pwm_med;
   1558       1.1  riastrad 	u16 pwm_high;
   1559       1.1  riastrad 	u8 t_hyst;
   1560       1.1  riastrad 	u32 cycle_delay;
   1561       1.1  riastrad 	u16 t_max;
   1562  1.3.32.1  christos 	u8 control_mode;
   1563  1.3.32.1  christos 	u16 default_max_fan_pwm;
   1564  1.3.32.1  christos 	u16 default_fan_output_sensitivity;
   1565  1.3.32.1  christos 	u16 fan_output_sensitivity;
   1566       1.1  riastrad 	bool ucode_fan_control;
   1567       1.1  riastrad };
   1568       1.1  riastrad 
   1569       1.1  riastrad enum radeon_pcie_gen {
   1570       1.1  riastrad 	RADEON_PCIE_GEN1 = 0,
   1571       1.1  riastrad 	RADEON_PCIE_GEN2 = 1,
   1572       1.1  riastrad 	RADEON_PCIE_GEN3 = 2,
   1573       1.1  riastrad 	RADEON_PCIE_GEN_INVALID = 0xffff
   1574       1.1  riastrad };
   1575       1.1  riastrad 
   1576       1.1  riastrad enum radeon_dpm_forced_level {
   1577       1.1  riastrad 	RADEON_DPM_FORCED_LEVEL_AUTO = 0,
   1578       1.1  riastrad 	RADEON_DPM_FORCED_LEVEL_LOW = 1,
   1579       1.1  riastrad 	RADEON_DPM_FORCED_LEVEL_HIGH = 2,
   1580       1.1  riastrad };
   1581       1.1  riastrad 
   1582       1.1  riastrad struct radeon_vce_state {
   1583       1.1  riastrad 	/* vce clocks */
   1584       1.1  riastrad 	u32 evclk;
   1585       1.1  riastrad 	u32 ecclk;
   1586       1.1  riastrad 	/* gpu clocks */
   1587       1.1  riastrad 	u32 sclk;
   1588       1.1  riastrad 	u32 mclk;
   1589       1.1  riastrad 	u8 clk_idx;
   1590       1.1  riastrad 	u8 pstate;
   1591       1.1  riastrad };
   1592       1.1  riastrad 
   1593       1.1  riastrad struct radeon_dpm {
   1594       1.1  riastrad 	struct radeon_ps        *ps;
   1595       1.1  riastrad 	/* number of valid power states */
   1596       1.1  riastrad 	int                     num_ps;
   1597       1.1  riastrad 	/* current power state that is active */
   1598       1.1  riastrad 	struct radeon_ps        *current_ps;
   1599       1.1  riastrad 	/* requested power state */
   1600       1.1  riastrad 	struct radeon_ps        *requested_ps;
   1601       1.1  riastrad 	/* boot up power state */
   1602       1.1  riastrad 	struct radeon_ps        *boot_ps;
   1603       1.1  riastrad 	/* default uvd power state */
   1604       1.1  riastrad 	struct radeon_ps        *uvd_ps;
   1605       1.1  riastrad 	/* vce requirements */
   1606       1.1  riastrad 	struct radeon_vce_state vce_states[RADEON_MAX_VCE_LEVELS];
   1607       1.1  riastrad 	enum radeon_vce_level vce_level;
   1608       1.1  riastrad 	enum radeon_pm_state_type state;
   1609       1.1  riastrad 	enum radeon_pm_state_type user_state;
   1610       1.1  riastrad 	u32                     platform_caps;
   1611       1.1  riastrad 	u32                     voltage_response_time;
   1612       1.1  riastrad 	u32                     backbias_response_time;
   1613       1.1  riastrad 	void                    *priv;
   1614       1.1  riastrad 	u32			new_active_crtcs;
   1615       1.1  riastrad 	int			new_active_crtc_count;
   1616       1.1  riastrad 	u32			current_active_crtcs;
   1617       1.1  riastrad 	int			current_active_crtc_count;
   1618  1.3.32.1  christos 	bool single_display;
   1619       1.1  riastrad 	struct radeon_dpm_dynamic_state dyn_state;
   1620       1.1  riastrad 	struct radeon_dpm_fan fan;
   1621       1.1  riastrad 	u32 tdp_limit;
   1622       1.1  riastrad 	u32 near_tdp_limit;
   1623       1.1  riastrad 	u32 near_tdp_limit_adjusted;
   1624       1.1  riastrad 	u32 sq_ramping_threshold;
   1625       1.1  riastrad 	u32 cac_leakage;
   1626       1.1  riastrad 	u16 tdp_od_limit;
   1627       1.1  riastrad 	u32 tdp_adjustment;
   1628       1.1  riastrad 	u16 load_line_slope;
   1629       1.1  riastrad 	bool power_control;
   1630       1.1  riastrad 	bool ac_power;
   1631       1.1  riastrad 	/* special states active */
   1632       1.1  riastrad 	bool                    thermal_active;
   1633       1.1  riastrad 	bool                    uvd_active;
   1634       1.1  riastrad 	bool                    vce_active;
   1635       1.1  riastrad 	/* thermal handling */
   1636       1.1  riastrad 	struct radeon_dpm_thermal thermal;
   1637       1.1  riastrad 	/* forced levels */
   1638       1.1  riastrad 	enum radeon_dpm_forced_level forced_level;
   1639       1.1  riastrad 	/* track UVD streams */
   1640       1.1  riastrad 	unsigned sd;
   1641       1.1  riastrad 	unsigned hd;
   1642       1.1  riastrad };
   1643       1.1  riastrad 
   1644       1.1  riastrad void radeon_dpm_enable_uvd(struct radeon_device *rdev, bool enable);
   1645       1.1  riastrad void radeon_dpm_enable_vce(struct radeon_device *rdev, bool enable);
   1646       1.1  riastrad 
   1647       1.1  riastrad struct radeon_pm {
   1648       1.1  riastrad 	struct mutex		mutex;
   1649       1.1  riastrad 	/* write locked while reprogramming mclk */
   1650       1.1  riastrad 	struct rw_semaphore	mclk_lock;
   1651       1.1  riastrad 	u32			active_crtcs;
   1652       1.1  riastrad 	int			active_crtc_count;
   1653       1.1  riastrad 	int			req_vblank;
   1654       1.1  riastrad 	bool			vblank_sync;
   1655       1.1  riastrad 	fixed20_12		max_bandwidth;
   1656       1.1  riastrad 	fixed20_12		igp_sideport_mclk;
   1657       1.1  riastrad 	fixed20_12		igp_system_mclk;
   1658       1.1  riastrad 	fixed20_12		igp_ht_link_clk;
   1659       1.1  riastrad 	fixed20_12		igp_ht_link_width;
   1660       1.1  riastrad 	fixed20_12		k8_bandwidth;
   1661       1.1  riastrad 	fixed20_12		sideport_bandwidth;
   1662       1.1  riastrad 	fixed20_12		ht_bandwidth;
   1663       1.1  riastrad 	fixed20_12		core_bandwidth;
   1664       1.1  riastrad 	fixed20_12		sclk;
   1665       1.1  riastrad 	fixed20_12		mclk;
   1666       1.1  riastrad 	fixed20_12		needed_bandwidth;
   1667       1.1  riastrad 	struct radeon_power_state *power_state;
   1668       1.1  riastrad 	/* number of valid power states */
   1669       1.1  riastrad 	int                     num_power_states;
   1670       1.1  riastrad 	int                     current_power_state_index;
   1671       1.1  riastrad 	int                     current_clock_mode_index;
   1672       1.1  riastrad 	int                     requested_power_state_index;
   1673       1.1  riastrad 	int                     requested_clock_mode_index;
   1674       1.1  riastrad 	int                     default_power_state_index;
   1675       1.1  riastrad 	u32                     current_sclk;
   1676       1.1  riastrad 	u32                     current_mclk;
   1677       1.1  riastrad 	u16                     current_vddc;
   1678       1.1  riastrad 	u16                     current_vddci;
   1679       1.1  riastrad 	u32                     default_sclk;
   1680       1.1  riastrad 	u32                     default_mclk;
   1681       1.1  riastrad 	u16                     default_vddc;
   1682       1.1  riastrad 	u16                     default_vddci;
   1683       1.1  riastrad 	struct radeon_i2c_chan *i2c_bus;
   1684       1.1  riastrad 	/* selected pm method */
   1685       1.1  riastrad 	enum radeon_pm_method     pm_method;
   1686       1.1  riastrad 	/* dynpm power management */
   1687       1.1  riastrad 	struct delayed_work	dynpm_idle_work;
   1688       1.1  riastrad 	enum radeon_dynpm_state	dynpm_state;
   1689       1.1  riastrad 	enum radeon_dynpm_action	dynpm_planned_action;
   1690       1.1  riastrad 	unsigned long		dynpm_action_timeout;
   1691       1.1  riastrad 	bool                    dynpm_can_upclock;
   1692       1.1  riastrad 	bool                    dynpm_can_downclock;
   1693       1.1  riastrad 	/* profile-based power management */
   1694       1.1  riastrad 	enum radeon_pm_profile_type profile;
   1695       1.1  riastrad 	int                     profile_index;
   1696       1.1  riastrad 	struct radeon_pm_profile profiles[PM_PROFILE_MAX];
   1697       1.1  riastrad 	/* internal thermal controller on rv6xx+ */
   1698       1.1  riastrad 	enum radeon_int_thermal_type int_thermal_type;
   1699       1.1  riastrad 	struct device	        *int_hwmon_dev;
   1700  1.3.32.1  christos 	/* fan control parameters */
   1701  1.3.32.1  christos 	bool                    no_fan;
   1702  1.3.32.1  christos 	u8                      fan_pulses_per_revolution;
   1703  1.3.32.1  christos 	u8                      fan_min_rpm;
   1704  1.3.32.1  christos 	u8                      fan_max_rpm;
   1705       1.1  riastrad 	/* dpm */
   1706       1.1  riastrad 	bool                    dpm_enabled;
   1707  1.3.32.1  christos 	bool                    sysfs_initialized;
   1708       1.1  riastrad 	struct radeon_dpm       dpm;
   1709       1.1  riastrad };
   1710       1.1  riastrad 
   1711       1.1  riastrad int radeon_pm_get_type_index(struct radeon_device *rdev,
   1712       1.1  riastrad 			     enum radeon_pm_state_type ps_type,
   1713       1.1  riastrad 			     int instance);
   1714       1.1  riastrad /*
   1715       1.1  riastrad  * UVD
   1716       1.1  riastrad  */
   1717       1.1  riastrad #define RADEON_MAX_UVD_HANDLES	10
   1718       1.1  riastrad #define RADEON_UVD_STACK_SIZE	(1024*1024)
   1719       1.1  riastrad #define RADEON_UVD_HEAP_SIZE	(1024*1024)
   1720       1.1  riastrad 
   1721       1.1  riastrad struct radeon_uvd {
   1722       1.1  riastrad 	struct radeon_bo	*vcpu_bo;
   1723       1.1  riastrad 	void			*cpu_addr;
   1724       1.1  riastrad 	uint64_t		gpu_addr;
   1725       1.1  riastrad 	atomic_t		handles[RADEON_MAX_UVD_HANDLES];
   1726       1.1  riastrad 	struct drm_file		*filp[RADEON_MAX_UVD_HANDLES];
   1727       1.1  riastrad 	unsigned		img_size[RADEON_MAX_UVD_HANDLES];
   1728       1.1  riastrad 	struct delayed_work	idle_work;
   1729       1.1  riastrad };
   1730       1.1  riastrad 
   1731       1.1  riastrad int radeon_uvd_init(struct radeon_device *rdev);
   1732       1.1  riastrad void radeon_uvd_fini(struct radeon_device *rdev);
   1733       1.1  riastrad int radeon_uvd_suspend(struct radeon_device *rdev);
   1734       1.1  riastrad int radeon_uvd_resume(struct radeon_device *rdev);
   1735       1.1  riastrad int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
   1736       1.1  riastrad 			      uint32_t handle, struct radeon_fence **fence);
   1737       1.1  riastrad int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
   1738       1.1  riastrad 			       uint32_t handle, struct radeon_fence **fence);
   1739  1.3.32.1  christos void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo,
   1740  1.3.32.1  christos 				       uint32_t allowed_domains);
   1741       1.1  riastrad void radeon_uvd_free_handles(struct radeon_device *rdev,
   1742       1.1  riastrad 			     struct drm_file *filp);
   1743       1.1  riastrad int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
   1744       1.1  riastrad void radeon_uvd_note_usage(struct radeon_device *rdev);
   1745       1.1  riastrad int radeon_uvd_calc_upll_dividers(struct radeon_device *rdev,
   1746       1.1  riastrad 				  unsigned vclk, unsigned dclk,
   1747       1.1  riastrad 				  unsigned vco_min, unsigned vco_max,
   1748       1.1  riastrad 				  unsigned fb_factor, unsigned fb_mask,
   1749       1.1  riastrad 				  unsigned pd_min, unsigned pd_max,
   1750       1.1  riastrad 				  unsigned pd_even,
   1751       1.1  riastrad 				  unsigned *optimal_fb_div,
   1752       1.1  riastrad 				  unsigned *optimal_vclk_div,
   1753       1.1  riastrad 				  unsigned *optimal_dclk_div);
   1754       1.1  riastrad int radeon_uvd_send_upll_ctlreq(struct radeon_device *rdev,
   1755       1.1  riastrad                                 unsigned cg_upll_func_cntl);
   1756       1.1  riastrad 
   1757       1.1  riastrad /*
   1758       1.1  riastrad  * VCE
   1759       1.1  riastrad  */
   1760       1.1  riastrad #define RADEON_MAX_VCE_HANDLES	16
   1761       1.1  riastrad 
   1762       1.1  riastrad struct radeon_vce {
   1763       1.1  riastrad 	struct radeon_bo	*vcpu_bo;
   1764       1.1  riastrad 	uint64_t		gpu_addr;
   1765       1.1  riastrad 	unsigned		fw_version;
   1766       1.1  riastrad 	unsigned		fb_version;
   1767       1.1  riastrad 	atomic_t		handles[RADEON_MAX_VCE_HANDLES];
   1768       1.1  riastrad 	struct drm_file		*filp[RADEON_MAX_VCE_HANDLES];
   1769       1.1  riastrad 	unsigned		img_size[RADEON_MAX_VCE_HANDLES];
   1770       1.1  riastrad 	struct delayed_work	idle_work;
   1771  1.3.32.1  christos 	uint32_t		keyselect;
   1772       1.1  riastrad };
   1773       1.1  riastrad 
   1774       1.1  riastrad int radeon_vce_init(struct radeon_device *rdev);
   1775       1.1  riastrad void radeon_vce_fini(struct radeon_device *rdev);
   1776       1.1  riastrad int radeon_vce_suspend(struct radeon_device *rdev);
   1777       1.1  riastrad int radeon_vce_resume(struct radeon_device *rdev);
   1778       1.1  riastrad int radeon_vce_get_create_msg(struct radeon_device *rdev, int ring,
   1779       1.1  riastrad 			      uint32_t handle, struct radeon_fence **fence);
   1780       1.1  riastrad int radeon_vce_get_destroy_msg(struct radeon_device *rdev, int ring,
   1781       1.1  riastrad 			       uint32_t handle, struct radeon_fence **fence);
   1782       1.1  riastrad void radeon_vce_free_handles(struct radeon_device *rdev, struct drm_file *filp);
   1783       1.1  riastrad void radeon_vce_note_usage(struct radeon_device *rdev);
   1784       1.1  riastrad int radeon_vce_cs_reloc(struct radeon_cs_parser *p, int lo, int hi, unsigned size);
   1785       1.1  riastrad int radeon_vce_cs_parse(struct radeon_cs_parser *p);
   1786       1.1  riastrad bool radeon_vce_semaphore_emit(struct radeon_device *rdev,
   1787       1.1  riastrad 			       struct radeon_ring *ring,
   1788       1.1  riastrad 			       struct radeon_semaphore *semaphore,
   1789       1.1  riastrad 			       bool emit_wait);
   1790       1.1  riastrad void radeon_vce_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib);
   1791       1.1  riastrad void radeon_vce_fence_emit(struct radeon_device *rdev,
   1792       1.1  riastrad 			   struct radeon_fence *fence);
   1793       1.1  riastrad int radeon_vce_ring_test(struct radeon_device *rdev, struct radeon_ring *ring);
   1794       1.1  riastrad int radeon_vce_ib_test(struct radeon_device *rdev, struct radeon_ring *ring);
   1795       1.1  riastrad 
   1796       1.1  riastrad struct r600_audio_pin {
   1797       1.1  riastrad 	int			channels;
   1798       1.1  riastrad 	int			rate;
   1799       1.1  riastrad 	int			bits_per_sample;
   1800       1.1  riastrad 	u8			status_bits;
   1801       1.1  riastrad 	u8			category_code;
   1802       1.1  riastrad 	u32			offset;
   1803       1.1  riastrad 	bool			connected;
   1804       1.1  riastrad 	u32			id;
   1805       1.1  riastrad };
   1806       1.1  riastrad 
   1807       1.1  riastrad struct r600_audio {
   1808       1.1  riastrad 	bool enabled;
   1809       1.1  riastrad 	struct r600_audio_pin pin[RADEON_MAX_AFMT_BLOCKS];
   1810       1.1  riastrad 	int num_pins;
   1811  1.3.32.1  christos 	struct radeon_audio_funcs *hdmi_funcs;
   1812  1.3.32.1  christos 	struct radeon_audio_funcs *dp_funcs;
   1813  1.3.32.1  christos 	struct radeon_audio_basic_funcs *funcs;
   1814       1.1  riastrad };
   1815       1.1  riastrad 
   1816       1.1  riastrad /*
   1817       1.1  riastrad  * Benchmarking
   1818       1.1  riastrad  */
   1819       1.1  riastrad void radeon_benchmark(struct radeon_device *rdev, int test_number);
   1820       1.1  riastrad 
   1821       1.1  riastrad 
   1822       1.1  riastrad /*
   1823       1.1  riastrad  * Testing
   1824       1.1  riastrad  */
   1825       1.1  riastrad void radeon_test_moves(struct radeon_device *rdev);
   1826       1.1  riastrad void radeon_test_ring_sync(struct radeon_device *rdev,
   1827       1.1  riastrad 			   struct radeon_ring *cpA,
   1828       1.1  riastrad 			   struct radeon_ring *cpB);
   1829       1.1  riastrad void radeon_test_syncing(struct radeon_device *rdev);
   1830       1.1  riastrad 
   1831  1.3.32.1  christos /*
   1832  1.3.32.1  christos  * MMU Notifier
   1833  1.3.32.1  christos  */
   1834  1.3.32.1  christos #if defined(CONFIG_MMU_NOTIFIER)
   1835  1.3.32.1  christos int radeon_mn_register(struct radeon_bo *bo, unsigned long addr);
   1836  1.3.32.1  christos void radeon_mn_unregister(struct radeon_bo *bo);
   1837  1.3.32.1  christos #else
   1838  1.3.32.1  christos static inline int radeon_mn_register(struct radeon_bo *bo, unsigned long addr)
   1839  1.3.32.1  christos {
   1840  1.3.32.1  christos 	return -ENODEV;
   1841  1.3.32.1  christos }
   1842  1.3.32.1  christos static inline void radeon_mn_unregister(struct radeon_bo *bo) {}
   1843  1.3.32.1  christos #endif
   1844       1.1  riastrad 
   1845       1.1  riastrad /*
   1846       1.1  riastrad  * Debugfs
   1847       1.1  riastrad  */
   1848       1.1  riastrad struct radeon_debugfs {
   1849       1.1  riastrad 	struct drm_info_list	*files;
   1850       1.1  riastrad 	unsigned		num_files;
   1851       1.1  riastrad };
   1852       1.1  riastrad 
   1853       1.1  riastrad int radeon_debugfs_add_files(struct radeon_device *rdev,
   1854       1.1  riastrad 			     struct drm_info_list *files,
   1855       1.1  riastrad 			     unsigned nfiles);
   1856       1.1  riastrad int radeon_debugfs_fence_init(struct radeon_device *rdev);
   1857       1.1  riastrad 
   1858       1.1  riastrad /*
   1859       1.1  riastrad  * ASIC ring specific functions.
   1860       1.1  riastrad  */
   1861       1.1  riastrad struct radeon_asic_ring {
   1862       1.1  riastrad 	/* ring read/write ptr handling */
   1863       1.1  riastrad 	u32 (*get_rptr)(struct radeon_device *rdev, struct radeon_ring *ring);
   1864       1.1  riastrad 	u32 (*get_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
   1865       1.1  riastrad 	void (*set_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
   1866       1.1  riastrad 
   1867       1.1  riastrad 	/* validating and patching of IBs */
   1868       1.1  riastrad 	int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
   1869       1.1  riastrad 	int (*cs_parse)(struct radeon_cs_parser *p);
   1870       1.1  riastrad 
   1871       1.1  riastrad 	/* command emmit functions */
   1872       1.1  riastrad 	void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
   1873       1.1  riastrad 	void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
   1874  1.3.32.1  christos 	void (*hdp_flush)(struct radeon_device *rdev, struct radeon_ring *ring);
   1875       1.1  riastrad 	bool (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
   1876       1.1  riastrad 			       struct radeon_semaphore *semaphore, bool emit_wait);
   1877  1.3.32.1  christos 	void (*vm_flush)(struct radeon_device *rdev, struct radeon_ring *ring,
   1878  1.3.32.1  christos 			 unsigned vm_id, uint64_t pd_addr);
   1879       1.1  riastrad 
   1880       1.1  riastrad 	/* testing functions */
   1881       1.1  riastrad 	int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
   1882       1.1  riastrad 	int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
   1883       1.1  riastrad 	bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
   1884       1.1  riastrad 
   1885       1.1  riastrad 	/* deprecated */
   1886       1.1  riastrad 	void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
   1887       1.1  riastrad };
   1888       1.1  riastrad 
   1889       1.1  riastrad /*
   1890       1.1  riastrad  * ASIC specific functions.
   1891       1.1  riastrad  */
   1892       1.1  riastrad struct radeon_asic {
   1893       1.1  riastrad 	int (*init)(struct radeon_device *rdev);
   1894       1.1  riastrad 	void (*fini)(struct radeon_device *rdev);
   1895       1.1  riastrad 	int (*resume)(struct radeon_device *rdev);
   1896       1.1  riastrad 	int (*suspend)(struct radeon_device *rdev);
   1897       1.1  riastrad 	void (*vga_set_state)(struct radeon_device *rdev, bool state);
   1898       1.1  riastrad 	int (*asic_reset)(struct radeon_device *rdev);
   1899  1.3.32.1  christos 	/* Flush the HDP cache via MMIO */
   1900  1.3.32.1  christos 	void (*mmio_hdp_flush)(struct radeon_device *rdev);
   1901       1.1  riastrad 	/* check if 3D engine is idle */
   1902       1.1  riastrad 	bool (*gui_idle)(struct radeon_device *rdev);
   1903       1.1  riastrad 	/* wait for mc_idle */
   1904       1.1  riastrad 	int (*mc_wait_for_idle)(struct radeon_device *rdev);
   1905       1.1  riastrad 	/* get the reference clock */
   1906       1.1  riastrad 	u32 (*get_xclk)(struct radeon_device *rdev);
   1907       1.1  riastrad 	/* get the gpu clock counter */
   1908       1.1  riastrad 	uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
   1909  1.3.32.1  christos 	/* get register for info ioctl */
   1910  1.3.32.1  christos 	int (*get_allowed_info_register)(struct radeon_device *rdev, u32 reg, u32 *val);
   1911       1.1  riastrad 	/* gart */
   1912       1.1  riastrad 	struct {
   1913       1.1  riastrad 		void (*tlb_flush)(struct radeon_device *rdev);
   1914  1.3.32.1  christos 		uint64_t (*get_page_entry)(uint64_t addr, uint32_t flags);
   1915  1.3.32.1  christos 		void (*set_page)(struct radeon_device *rdev, unsigned i,
   1916  1.3.32.1  christos 				 uint64_t entry);
   1917       1.1  riastrad 	} gart;
   1918       1.1  riastrad 	struct {
   1919       1.1  riastrad 		int (*init)(struct radeon_device *rdev);
   1920       1.1  riastrad 		void (*fini)(struct radeon_device *rdev);
   1921  1.3.32.1  christos 		void (*copy_pages)(struct radeon_device *rdev,
   1922  1.3.32.1  christos 				   struct radeon_ib *ib,
   1923  1.3.32.1  christos 				   uint64_t pe, uint64_t src,
   1924  1.3.32.1  christos 				   unsigned count);
   1925  1.3.32.1  christos 		void (*write_pages)(struct radeon_device *rdev,
   1926  1.3.32.1  christos 				    struct radeon_ib *ib,
   1927  1.3.32.1  christos 				    uint64_t pe,
   1928  1.3.32.1  christos 				    uint64_t addr, unsigned count,
   1929  1.3.32.1  christos 				    uint32_t incr, uint32_t flags);
   1930  1.3.32.1  christos 		void (*set_pages)(struct radeon_device *rdev,
   1931  1.3.32.1  christos 				  struct radeon_ib *ib,
   1932  1.3.32.1  christos 				  uint64_t pe,
   1933  1.3.32.1  christos 				  uint64_t addr, unsigned count,
   1934  1.3.32.1  christos 				  uint32_t incr, uint32_t flags);
   1935  1.3.32.1  christos 		void (*pad_ib)(struct radeon_ib *ib);
   1936       1.1  riastrad 	} vm;
   1937       1.1  riastrad 	/* ring specific callbacks */
   1938       1.1  riastrad 	struct radeon_asic_ring *ring[RADEON_NUM_RINGS];
   1939       1.1  riastrad 	/* irqs */
   1940       1.1  riastrad 	struct {
   1941       1.1  riastrad 		int (*set)(struct radeon_device *rdev);
   1942       1.1  riastrad 		int (*process)(struct radeon_device *rdev);
   1943       1.1  riastrad 	} irq;
   1944       1.1  riastrad 	/* displays */
   1945       1.1  riastrad 	struct {
   1946       1.1  riastrad 		/* display watermarks */
   1947       1.1  riastrad 		void (*bandwidth_update)(struct radeon_device *rdev);
   1948       1.1  riastrad 		/* get frame count */
   1949       1.1  riastrad 		u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
   1950       1.1  riastrad 		/* wait for vblank */
   1951       1.1  riastrad 		void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
   1952       1.1  riastrad 		/* set backlight level */
   1953       1.1  riastrad 		void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
   1954       1.1  riastrad 		/* get backlight level */
   1955       1.1  riastrad 		u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
   1956       1.1  riastrad 		/* audio callbacks */
   1957       1.1  riastrad 		void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
   1958       1.1  riastrad 		void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
   1959       1.1  riastrad 	} display;
   1960       1.1  riastrad 	/* copy functions for bo handling */
   1961       1.1  riastrad 	struct {
   1962  1.3.32.1  christos 		struct radeon_fence *(*blit)(struct radeon_device *rdev,
   1963  1.3.32.1  christos 					     uint64_t src_offset,
   1964  1.3.32.1  christos 					     uint64_t dst_offset,
   1965  1.3.32.1  christos 					     unsigned num_gpu_pages,
   1966  1.3.32.1  christos 					     struct reservation_object *resv);
   1967       1.1  riastrad 		u32 blit_ring_index;
   1968  1.3.32.1  christos 		struct radeon_fence *(*dma)(struct radeon_device *rdev,
   1969  1.3.32.1  christos 					    uint64_t src_offset,
   1970  1.3.32.1  christos 					    uint64_t dst_offset,
   1971  1.3.32.1  christos 					    unsigned num_gpu_pages,
   1972  1.3.32.1  christos 					    struct reservation_object *resv);
   1973       1.1  riastrad 		u32 dma_ring_index;
   1974       1.1  riastrad 		/* method used for bo copy */
   1975  1.3.32.1  christos 		struct radeon_fence *(*copy)(struct radeon_device *rdev,
   1976  1.3.32.1  christos 					     uint64_t src_offset,
   1977  1.3.32.1  christos 					     uint64_t dst_offset,
   1978  1.3.32.1  christos 					     unsigned num_gpu_pages,
   1979  1.3.32.1  christos 					     struct reservation_object *resv);
   1980       1.1  riastrad 		/* ring used for bo copies */
   1981       1.1  riastrad 		u32 copy_ring_index;
   1982       1.1  riastrad 	} copy;
   1983       1.1  riastrad 	/* surfaces */
   1984       1.1  riastrad 	struct {
   1985       1.1  riastrad 		int (*set_reg)(struct radeon_device *rdev, int reg,
   1986       1.1  riastrad 				       uint32_t tiling_flags, uint32_t pitch,
   1987       1.1  riastrad 				       uint32_t offset, uint32_t obj_size);
   1988       1.1  riastrad 		void (*clear_reg)(struct radeon_device *rdev, int reg);
   1989       1.1  riastrad 	} surface;
   1990       1.1  riastrad 	/* hotplug detect */
   1991       1.1  riastrad 	struct {
   1992       1.1  riastrad 		void (*init)(struct radeon_device *rdev);
   1993       1.1  riastrad 		void (*fini)(struct radeon_device *rdev);
   1994       1.1  riastrad 		bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
   1995       1.1  riastrad 		void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
   1996       1.1  riastrad 	} hpd;
   1997       1.1  riastrad 	/* static power management */
   1998       1.1  riastrad 	struct {
   1999       1.1  riastrad 		void (*misc)(struct radeon_device *rdev);
   2000       1.1  riastrad 		void (*prepare)(struct radeon_device *rdev);
   2001       1.1  riastrad 		void (*finish)(struct radeon_device *rdev);
   2002       1.1  riastrad 		void (*init_profile)(struct radeon_device *rdev);
   2003       1.1  riastrad 		void (*get_dynpm_state)(struct radeon_device *rdev);
   2004       1.1  riastrad 		uint32_t (*get_engine_clock)(struct radeon_device *rdev);
   2005       1.1  riastrad 		void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
   2006       1.1  riastrad 		uint32_t (*get_memory_clock)(struct radeon_device *rdev);
   2007       1.1  riastrad 		void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
   2008       1.1  riastrad 		int (*get_pcie_lanes)(struct radeon_device *rdev);
   2009       1.1  riastrad 		void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
   2010       1.1  riastrad 		void (*set_clock_gating)(struct radeon_device *rdev, int enable);
   2011       1.1  riastrad 		int (*set_uvd_clocks)(struct radeon_device *rdev, u32 vclk, u32 dclk);
   2012       1.1  riastrad 		int (*set_vce_clocks)(struct radeon_device *rdev, u32 evclk, u32 ecclk);
   2013       1.1  riastrad 		int (*get_temperature)(struct radeon_device *rdev);
   2014       1.1  riastrad 	} pm;
   2015       1.1  riastrad 	/* dynamic power management */
   2016       1.1  riastrad 	struct {
   2017       1.1  riastrad 		int (*init)(struct radeon_device *rdev);
   2018       1.1  riastrad 		void (*setup_asic)(struct radeon_device *rdev);
   2019       1.1  riastrad 		int (*enable)(struct radeon_device *rdev);
   2020       1.1  riastrad 		int (*late_enable)(struct radeon_device *rdev);
   2021       1.1  riastrad 		void (*disable)(struct radeon_device *rdev);
   2022       1.1  riastrad 		int (*pre_set_power_state)(struct radeon_device *rdev);
   2023       1.1  riastrad 		int (*set_power_state)(struct radeon_device *rdev);
   2024       1.1  riastrad 		void (*post_set_power_state)(struct radeon_device *rdev);
   2025       1.1  riastrad 		void (*display_configuration_changed)(struct radeon_device *rdev);
   2026       1.1  riastrad 		void (*fini)(struct radeon_device *rdev);
   2027       1.1  riastrad 		u32 (*get_sclk)(struct radeon_device *rdev, bool low);
   2028       1.1  riastrad 		u32 (*get_mclk)(struct radeon_device *rdev, bool low);
   2029       1.1  riastrad 		void (*print_power_state)(struct radeon_device *rdev, struct radeon_ps *ps);
   2030       1.1  riastrad 		void (*debugfs_print_current_performance_level)(struct radeon_device *rdev, struct seq_file *m);
   2031       1.1  riastrad 		int (*force_performance_level)(struct radeon_device *rdev, enum radeon_dpm_forced_level level);
   2032       1.1  riastrad 		bool (*vblank_too_short)(struct radeon_device *rdev);
   2033       1.1  riastrad 		void (*powergate_uvd)(struct radeon_device *rdev, bool gate);
   2034       1.1  riastrad 		void (*enable_bapm)(struct radeon_device *rdev, bool enable);
   2035  1.3.32.1  christos 		void (*fan_ctrl_set_mode)(struct radeon_device *rdev, u32 mode);
   2036  1.3.32.1  christos 		u32 (*fan_ctrl_get_mode)(struct radeon_device *rdev);
   2037  1.3.32.1  christos 		int (*set_fan_speed_percent)(struct radeon_device *rdev, u32 speed);
   2038  1.3.32.1  christos 		int (*get_fan_speed_percent)(struct radeon_device *rdev, u32 *speed);
   2039  1.3.32.1  christos 		u32 (*get_current_sclk)(struct radeon_device *rdev);
   2040  1.3.32.1  christos 		u32 (*get_current_mclk)(struct radeon_device *rdev);
   2041       1.1  riastrad 	} dpm;
   2042       1.1  riastrad 	/* pageflipping */
   2043       1.1  riastrad 	struct {
   2044  1.3.32.1  christos 		void (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
   2045  1.3.32.1  christos 		bool (*page_flip_pending)(struct radeon_device *rdev, int crtc);
   2046       1.1  riastrad 	} pflip;
   2047       1.1  riastrad };
   2048       1.1  riastrad 
   2049       1.1  riastrad /*
   2050       1.1  riastrad  * Asic structures
   2051       1.1  riastrad  */
   2052       1.1  riastrad struct r100_asic {
   2053       1.1  riastrad 	const unsigned		*reg_safe_bm;
   2054       1.1  riastrad 	unsigned		reg_safe_bm_size;
   2055       1.1  riastrad 	u32			hdp_cntl;
   2056       1.1  riastrad };
   2057       1.1  riastrad 
   2058       1.1  riastrad struct r300_asic {
   2059       1.1  riastrad 	const unsigned		*reg_safe_bm;
   2060       1.1  riastrad 	unsigned		reg_safe_bm_size;
   2061       1.1  riastrad 	u32			resync_scratch;
   2062       1.1  riastrad 	u32			hdp_cntl;
   2063       1.1  riastrad };
   2064       1.1  riastrad 
   2065       1.1  riastrad struct r600_asic {
   2066       1.1  riastrad 	unsigned		max_pipes;
   2067       1.1  riastrad 	unsigned		max_tile_pipes;
   2068       1.1  riastrad 	unsigned		max_simds;
   2069       1.1  riastrad 	unsigned		max_backends;
   2070       1.1  riastrad 	unsigned		max_gprs;
   2071       1.1  riastrad 	unsigned		max_threads;
   2072       1.1  riastrad 	unsigned		max_stack_entries;
   2073       1.1  riastrad 	unsigned		max_hw_contexts;
   2074       1.1  riastrad 	unsigned		max_gs_threads;
   2075       1.1  riastrad 	unsigned		sx_max_export_size;
   2076       1.1  riastrad 	unsigned		sx_max_export_pos_size;
   2077       1.1  riastrad 	unsigned		sx_max_export_smx_size;
   2078       1.1  riastrad 	unsigned		sq_num_cf_insts;
   2079       1.1  riastrad 	unsigned		tiling_nbanks;
   2080       1.1  riastrad 	unsigned		tiling_npipes;
   2081       1.1  riastrad 	unsigned		tiling_group_size;
   2082       1.1  riastrad 	unsigned		tile_config;
   2083       1.1  riastrad 	unsigned		backend_map;
   2084  1.3.32.1  christos 	unsigned		active_simds;
   2085       1.1  riastrad };
   2086       1.1  riastrad 
   2087       1.1  riastrad struct rv770_asic {
   2088       1.1  riastrad 	unsigned		max_pipes;
   2089       1.1  riastrad 	unsigned		max_tile_pipes;
   2090       1.1  riastrad 	unsigned		max_simds;
   2091       1.1  riastrad 	unsigned		max_backends;
   2092       1.1  riastrad 	unsigned		max_gprs;
   2093       1.1  riastrad 	unsigned		max_threads;
   2094       1.1  riastrad 	unsigned		max_stack_entries;
   2095       1.1  riastrad 	unsigned		max_hw_contexts;
   2096       1.1  riastrad 	unsigned		max_gs_threads;
   2097       1.1  riastrad 	unsigned		sx_max_export_size;
   2098       1.1  riastrad 	unsigned		sx_max_export_pos_size;
   2099       1.1  riastrad 	unsigned		sx_max_export_smx_size;
   2100       1.1  riastrad 	unsigned		sq_num_cf_insts;
   2101       1.1  riastrad 	unsigned		sx_num_of_sets;
   2102       1.1  riastrad 	unsigned		sc_prim_fifo_size;
   2103       1.1  riastrad 	unsigned		sc_hiz_tile_fifo_size;
   2104       1.1  riastrad 	unsigned		sc_earlyz_tile_fifo_fize;
   2105       1.1  riastrad 	unsigned		tiling_nbanks;
   2106       1.1  riastrad 	unsigned		tiling_npipes;
   2107       1.1  riastrad 	unsigned		tiling_group_size;
   2108       1.1  riastrad 	unsigned		tile_config;
   2109       1.1  riastrad 	unsigned		backend_map;
   2110  1.3.32.1  christos 	unsigned		active_simds;
   2111       1.1  riastrad };
   2112       1.1  riastrad 
   2113       1.1  riastrad struct evergreen_asic {
   2114       1.1  riastrad 	unsigned num_ses;
   2115       1.1  riastrad 	unsigned max_pipes;
   2116       1.1  riastrad 	unsigned max_tile_pipes;
   2117       1.1  riastrad 	unsigned max_simds;
   2118       1.1  riastrad 	unsigned max_backends;
   2119       1.1  riastrad 	unsigned max_gprs;
   2120       1.1  riastrad 	unsigned max_threads;
   2121       1.1  riastrad 	unsigned max_stack_entries;
   2122       1.1  riastrad 	unsigned max_hw_contexts;
   2123       1.1  riastrad 	unsigned max_gs_threads;
   2124       1.1  riastrad 	unsigned sx_max_export_size;
   2125       1.1  riastrad 	unsigned sx_max_export_pos_size;
   2126       1.1  riastrad 	unsigned sx_max_export_smx_size;
   2127       1.1  riastrad 	unsigned sq_num_cf_insts;
   2128       1.1  riastrad 	unsigned sx_num_of_sets;
   2129       1.1  riastrad 	unsigned sc_prim_fifo_size;
   2130       1.1  riastrad 	unsigned sc_hiz_tile_fifo_size;
   2131       1.1  riastrad 	unsigned sc_earlyz_tile_fifo_size;
   2132       1.1  riastrad 	unsigned tiling_nbanks;
   2133       1.1  riastrad 	unsigned tiling_npipes;
   2134       1.1  riastrad 	unsigned tiling_group_size;
   2135       1.1  riastrad 	unsigned tile_config;
   2136       1.1  riastrad 	unsigned backend_map;
   2137  1.3.32.1  christos 	unsigned active_simds;
   2138       1.1  riastrad };
   2139       1.1  riastrad 
   2140       1.1  riastrad struct cayman_asic {
   2141       1.1  riastrad 	unsigned max_shader_engines;
   2142       1.1  riastrad 	unsigned max_pipes_per_simd;
   2143       1.1  riastrad 	unsigned max_tile_pipes;
   2144       1.1  riastrad 	unsigned max_simds_per_se;
   2145       1.1  riastrad 	unsigned max_backends_per_se;
   2146       1.1  riastrad 	unsigned max_texture_channel_caches;
   2147       1.1  riastrad 	unsigned max_gprs;
   2148       1.1  riastrad 	unsigned max_threads;
   2149       1.1  riastrad 	unsigned max_gs_threads;
   2150       1.1  riastrad 	unsigned max_stack_entries;
   2151       1.1  riastrad 	unsigned sx_num_of_sets;
   2152       1.1  riastrad 	unsigned sx_max_export_size;
   2153       1.1  riastrad 	unsigned sx_max_export_pos_size;
   2154       1.1  riastrad 	unsigned sx_max_export_smx_size;
   2155       1.1  riastrad 	unsigned max_hw_contexts;
   2156       1.1  riastrad 	unsigned sq_num_cf_insts;
   2157       1.1  riastrad 	unsigned sc_prim_fifo_size;
   2158       1.1  riastrad 	unsigned sc_hiz_tile_fifo_size;
   2159       1.1  riastrad 	unsigned sc_earlyz_tile_fifo_size;
   2160       1.1  riastrad 
   2161       1.1  riastrad 	unsigned num_shader_engines;
   2162       1.1  riastrad 	unsigned num_shader_pipes_per_simd;
   2163       1.1  riastrad 	unsigned num_tile_pipes;
   2164       1.1  riastrad 	unsigned num_simds_per_se;
   2165       1.1  riastrad 	unsigned num_backends_per_se;
   2166       1.1  riastrad 	unsigned backend_disable_mask_per_asic;
   2167       1.1  riastrad 	unsigned backend_map;
   2168       1.1  riastrad 	unsigned num_texture_channel_caches;
   2169       1.1  riastrad 	unsigned mem_max_burst_length_bytes;
   2170       1.1  riastrad 	unsigned mem_row_size_in_kb;
   2171       1.1  riastrad 	unsigned shader_engine_tile_size;
   2172       1.1  riastrad 	unsigned num_gpus;
   2173       1.1  riastrad 	unsigned multi_gpu_tile_size;
   2174       1.1  riastrad 
   2175       1.1  riastrad 	unsigned tile_config;
   2176  1.3.32.1  christos 	unsigned active_simds;
   2177       1.1  riastrad };
   2178       1.1  riastrad 
   2179       1.1  riastrad struct si_asic {
   2180       1.1  riastrad 	unsigned max_shader_engines;
   2181       1.1  riastrad 	unsigned max_tile_pipes;
   2182       1.1  riastrad 	unsigned max_cu_per_sh;
   2183       1.1  riastrad 	unsigned max_sh_per_se;
   2184       1.1  riastrad 	unsigned max_backends_per_se;
   2185       1.1  riastrad 	unsigned max_texture_channel_caches;
   2186       1.1  riastrad 	unsigned max_gprs;
   2187       1.1  riastrad 	unsigned max_gs_threads;
   2188       1.1  riastrad 	unsigned max_hw_contexts;
   2189       1.1  riastrad 	unsigned sc_prim_fifo_size_frontend;
   2190       1.1  riastrad 	unsigned sc_prim_fifo_size_backend;
   2191       1.1  riastrad 	unsigned sc_hiz_tile_fifo_size;
   2192       1.1  riastrad 	unsigned sc_earlyz_tile_fifo_size;
   2193       1.1  riastrad 
   2194       1.1  riastrad 	unsigned num_tile_pipes;
   2195       1.1  riastrad 	unsigned backend_enable_mask;
   2196       1.1  riastrad 	unsigned backend_disable_mask_per_asic;
   2197       1.1  riastrad 	unsigned backend_map;
   2198       1.1  riastrad 	unsigned num_texture_channel_caches;
   2199       1.1  riastrad 	unsigned mem_max_burst_length_bytes;
   2200       1.1  riastrad 	unsigned mem_row_size_in_kb;
   2201       1.1  riastrad 	unsigned shader_engine_tile_size;
   2202       1.1  riastrad 	unsigned num_gpus;
   2203       1.1  riastrad 	unsigned multi_gpu_tile_size;
   2204       1.1  riastrad 
   2205       1.1  riastrad 	unsigned tile_config;
   2206       1.1  riastrad 	uint32_t tile_mode_array[32];
   2207  1.3.32.1  christos 	uint32_t active_cus;
   2208       1.1  riastrad };
   2209       1.1  riastrad 
   2210       1.1  riastrad struct cik_asic {
   2211       1.1  riastrad 	unsigned max_shader_engines;
   2212       1.1  riastrad 	unsigned max_tile_pipes;
   2213       1.1  riastrad 	unsigned max_cu_per_sh;
   2214       1.1  riastrad 	unsigned max_sh_per_se;
   2215       1.1  riastrad 	unsigned max_backends_per_se;
   2216       1.1  riastrad 	unsigned max_texture_channel_caches;
   2217       1.1  riastrad 	unsigned max_gprs;
   2218       1.1  riastrad 	unsigned max_gs_threads;
   2219       1.1  riastrad 	unsigned max_hw_contexts;
   2220       1.1  riastrad 	unsigned sc_prim_fifo_size_frontend;
   2221       1.1  riastrad 	unsigned sc_prim_fifo_size_backend;
   2222       1.1  riastrad 	unsigned sc_hiz_tile_fifo_size;
   2223       1.1  riastrad 	unsigned sc_earlyz_tile_fifo_size;
   2224       1.1  riastrad 
   2225       1.1  riastrad 	unsigned num_tile_pipes;
   2226       1.1  riastrad 	unsigned backend_enable_mask;
   2227       1.1  riastrad 	unsigned backend_disable_mask_per_asic;
   2228       1.1  riastrad 	unsigned backend_map;
   2229       1.1  riastrad 	unsigned num_texture_channel_caches;
   2230       1.1  riastrad 	unsigned mem_max_burst_length_bytes;
   2231       1.1  riastrad 	unsigned mem_row_size_in_kb;
   2232       1.1  riastrad 	unsigned shader_engine_tile_size;
   2233       1.1  riastrad 	unsigned num_gpus;
   2234       1.1  riastrad 	unsigned multi_gpu_tile_size;
   2235       1.1  riastrad 
   2236       1.1  riastrad 	unsigned tile_config;
   2237       1.1  riastrad 	uint32_t tile_mode_array[32];
   2238       1.1  riastrad 	uint32_t macrotile_mode_array[16];
   2239  1.3.32.1  christos 	uint32_t active_cus;
   2240       1.1  riastrad };
   2241       1.1  riastrad 
   2242       1.1  riastrad union radeon_asic_config {
   2243       1.1  riastrad 	struct r300_asic	r300;
   2244       1.1  riastrad 	struct r100_asic	r100;
   2245       1.1  riastrad 	struct r600_asic	r600;
   2246       1.1  riastrad 	struct rv770_asic	rv770;
   2247       1.1  riastrad 	struct evergreen_asic	evergreen;
   2248       1.1  riastrad 	struct cayman_asic	cayman;
   2249       1.1  riastrad 	struct si_asic		si;
   2250       1.1  riastrad 	struct cik_asic		cik;
   2251       1.1  riastrad };
   2252       1.1  riastrad 
   2253       1.1  riastrad /*
   2254       1.1  riastrad  * asic initizalization from radeon_asic.c
   2255       1.1  riastrad  */
   2256       1.1  riastrad void radeon_agp_disable(struct radeon_device *rdev);
   2257       1.1  riastrad int radeon_asic_init(struct radeon_device *rdev);
   2258       1.1  riastrad 
   2259       1.1  riastrad 
   2260       1.1  riastrad /*
   2261       1.1  riastrad  * IOCTL.
   2262       1.1  riastrad  */
   2263       1.1  riastrad int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
   2264       1.1  riastrad 			  struct drm_file *filp);
   2265       1.1  riastrad int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
   2266       1.1  riastrad 			    struct drm_file *filp);
   2267  1.3.32.1  christos int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
   2268  1.3.32.1  christos 			     struct drm_file *filp);
   2269       1.1  riastrad int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
   2270       1.1  riastrad 			 struct drm_file *file_priv);
   2271       1.1  riastrad int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
   2272       1.1  riastrad 			   struct drm_file *file_priv);
   2273       1.1  riastrad int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
   2274       1.1  riastrad 			    struct drm_file *file_priv);
   2275       1.1  riastrad int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
   2276       1.1  riastrad 			   struct drm_file *file_priv);
   2277       1.1  riastrad int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
   2278       1.1  riastrad 				struct drm_file *filp);
   2279       1.1  riastrad int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
   2280       1.1  riastrad 			  struct drm_file *filp);
   2281       1.1  riastrad int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
   2282       1.1  riastrad 			  struct drm_file *filp);
   2283       1.1  riastrad int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
   2284       1.1  riastrad 			      struct drm_file *filp);
   2285       1.1  riastrad int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
   2286       1.1  riastrad 			  struct drm_file *filp);
   2287       1.1  riastrad int radeon_gem_op_ioctl(struct drm_device *dev, void *data,
   2288       1.1  riastrad 			struct drm_file *filp);
   2289       1.1  riastrad int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
   2290       1.1  riastrad int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
   2291       1.1  riastrad 				struct drm_file *filp);
   2292       1.1  riastrad int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
   2293       1.1  riastrad 				struct drm_file *filp);
   2294       1.1  riastrad 
   2295       1.1  riastrad /* VRAM scratch page for HDP bug, default vram page */
   2296       1.1  riastrad struct r600_vram_scratch {
   2297       1.1  riastrad 	struct radeon_bo		*robj;
   2298       1.1  riastrad 	volatile uint32_t		*ptr;
   2299       1.1  riastrad 	u64				gpu_addr;
   2300       1.1  riastrad };
   2301       1.1  riastrad 
   2302       1.1  riastrad /*
   2303       1.1  riastrad  * ACPI
   2304       1.1  riastrad  */
   2305       1.1  riastrad struct radeon_atif_notification_cfg {
   2306       1.1  riastrad 	bool enabled;
   2307       1.1  riastrad 	int command_code;
   2308       1.1  riastrad };
   2309       1.1  riastrad 
   2310       1.1  riastrad struct radeon_atif_notifications {
   2311       1.1  riastrad 	bool display_switch;
   2312       1.1  riastrad 	bool expansion_mode_change;
   2313       1.1  riastrad 	bool thermal_state;
   2314       1.1  riastrad 	bool forced_power_state;
   2315       1.1  riastrad 	bool system_power_state;
   2316       1.1  riastrad 	bool display_conf_change;
   2317       1.1  riastrad 	bool px_gfx_switch;
   2318       1.1  riastrad 	bool brightness_change;
   2319       1.1  riastrad 	bool dgpu_display_event;
   2320       1.1  riastrad };
   2321       1.1  riastrad 
   2322       1.1  riastrad struct radeon_atif_functions {
   2323       1.1  riastrad 	bool system_params;
   2324       1.1  riastrad 	bool sbios_requests;
   2325       1.1  riastrad 	bool select_active_disp;
   2326       1.1  riastrad 	bool lid_state;
   2327       1.1  riastrad 	bool get_tv_standard;
   2328       1.1  riastrad 	bool set_tv_standard;
   2329       1.1  riastrad 	bool get_panel_expansion_mode;
   2330       1.1  riastrad 	bool set_panel_expansion_mode;
   2331       1.1  riastrad 	bool temperature_change;
   2332       1.1  riastrad 	bool graphics_device_types;
   2333       1.1  riastrad };
   2334       1.1  riastrad 
   2335       1.1  riastrad struct radeon_atif {
   2336       1.1  riastrad 	struct radeon_atif_notifications notifications;
   2337       1.1  riastrad 	struct radeon_atif_functions functions;
   2338       1.1  riastrad 	struct radeon_atif_notification_cfg notification_cfg;
   2339       1.1  riastrad 	struct radeon_encoder *encoder_for_bl;
   2340       1.1  riastrad };
   2341       1.1  riastrad 
   2342       1.1  riastrad struct radeon_atcs_functions {
   2343       1.1  riastrad 	bool get_ext_state;
   2344       1.1  riastrad 	bool pcie_perf_req;
   2345       1.1  riastrad 	bool pcie_dev_rdy;
   2346       1.1  riastrad 	bool pcie_bus_width;
   2347       1.1  riastrad };
   2348       1.1  riastrad 
   2349       1.1  riastrad struct radeon_atcs {
   2350       1.1  riastrad 	struct radeon_atcs_functions functions;
   2351       1.1  riastrad };
   2352       1.1  riastrad 
   2353       1.1  riastrad /*
   2354       1.1  riastrad  * Core structure, functions and helpers.
   2355       1.1  riastrad  */
   2356       1.1  riastrad typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
   2357       1.1  riastrad typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
   2358       1.1  riastrad 
   2359       1.1  riastrad struct radeon_device {
   2360       1.1  riastrad 	struct device			*dev;
   2361       1.1  riastrad 	struct drm_device		*ddev;
   2362       1.1  riastrad 	struct pci_dev			*pdev;
   2363       1.1  riastrad 	struct rw_semaphore		exclusive_lock;
   2364       1.1  riastrad 	/* ASIC */
   2365       1.1  riastrad 	union radeon_asic_config	config;
   2366       1.1  riastrad 	enum radeon_family		family;
   2367       1.1  riastrad 	unsigned long			flags;
   2368       1.1  riastrad 	int				usec_timeout;
   2369       1.1  riastrad 	enum radeon_pll_errata		pll_errata;
   2370       1.1  riastrad 	int				num_gb_pipes;
   2371       1.1  riastrad 	int				num_z_pipes;
   2372       1.1  riastrad 	int				disp_priority;
   2373       1.1  riastrad 	/* BIOS */
   2374       1.1  riastrad 	uint8_t				*bios;
   2375       1.1  riastrad 	bool				is_atom_bios;
   2376       1.1  riastrad 	uint16_t			bios_header_start;
   2377       1.1  riastrad 	struct radeon_bo		*stollen_vga_memory;
   2378       1.1  riastrad 	/* Register mmio */
   2379       1.2  riastrad #ifndef __NetBSD__
   2380       1.1  riastrad 	resource_size_t			rmmio_base;
   2381       1.1  riastrad 	resource_size_t			rmmio_size;
   2382       1.2  riastrad #endif
   2383       1.1  riastrad 	/* protects concurrent MM_INDEX/DATA based register access */
   2384       1.1  riastrad 	spinlock_t mmio_idx_lock;
   2385       1.1  riastrad 	/* protects concurrent SMC based register access */
   2386       1.1  riastrad 	spinlock_t smc_idx_lock;
   2387       1.1  riastrad 	/* protects concurrent PLL register access */
   2388       1.1  riastrad 	spinlock_t pll_idx_lock;
   2389       1.1  riastrad 	/* protects concurrent MC register access */
   2390       1.1  riastrad 	spinlock_t mc_idx_lock;
   2391       1.1  riastrad 	/* protects concurrent PCIE register access */
   2392       1.1  riastrad 	spinlock_t pcie_idx_lock;
   2393       1.1  riastrad 	/* protects concurrent PCIE_PORT register access */
   2394       1.1  riastrad 	spinlock_t pciep_idx_lock;
   2395       1.1  riastrad 	/* protects concurrent PIF register access */
   2396       1.1  riastrad 	spinlock_t pif_idx_lock;
   2397       1.1  riastrad 	/* protects concurrent CG register access */
   2398       1.1  riastrad 	spinlock_t cg_idx_lock;
   2399       1.1  riastrad 	/* protects concurrent UVD register access */
   2400       1.1  riastrad 	spinlock_t uvd_idx_lock;
   2401       1.1  riastrad 	/* protects concurrent RCU register access */
   2402       1.1  riastrad 	spinlock_t rcu_idx_lock;
   2403       1.1  riastrad 	/* protects concurrent DIDT register access */
   2404       1.1  riastrad 	spinlock_t didt_idx_lock;
   2405       1.1  riastrad 	/* protects concurrent ENDPOINT (audio) register access */
   2406       1.1  riastrad 	spinlock_t end_idx_lock;
   2407       1.2  riastrad #ifdef __NetBSD__
   2408       1.2  riastrad 	bus_space_tag_t			rmmio_bst;
   2409       1.2  riastrad 	bus_space_handle_t		rmmio_bsh;
   2410       1.2  riastrad 	bus_addr_t			rmmio_addr;
   2411       1.2  riastrad 	bus_size_t			rmmio_size;
   2412       1.2  riastrad #else
   2413       1.1  riastrad 	void __iomem			*rmmio;
   2414       1.2  riastrad #endif
   2415       1.1  riastrad 	radeon_rreg_t			mc_rreg;
   2416       1.1  riastrad 	radeon_wreg_t			mc_wreg;
   2417       1.1  riastrad 	radeon_rreg_t			pll_rreg;
   2418       1.1  riastrad 	radeon_wreg_t			pll_wreg;
   2419       1.1  riastrad 	uint32_t                        pcie_reg_mask;
   2420       1.1  riastrad 	radeon_rreg_t			pciep_rreg;
   2421       1.1  riastrad 	radeon_wreg_t			pciep_wreg;
   2422       1.1  riastrad 	/* io port */
   2423       1.2  riastrad #ifdef __NetBSD__
   2424       1.2  riastrad 	bus_space_tag_t			rio_mem_bst;
   2425       1.2  riastrad 	bus_space_handle_t		rio_mem_bsh;
   2426       1.2  riastrad 	bus_size_t			rio_mem_size;
   2427       1.2  riastrad #else
   2428       1.1  riastrad 	void __iomem                    *rio_mem;
   2429       1.1  riastrad 	resource_size_t			rio_mem_size;
   2430       1.2  riastrad #endif
   2431       1.1  riastrad 	struct radeon_clock             clock;
   2432       1.1  riastrad 	struct radeon_mc		mc;
   2433       1.1  riastrad 	struct radeon_gart		gart;
   2434       1.1  riastrad 	struct radeon_mode_info		mode_info;
   2435       1.1  riastrad 	struct radeon_scratch		scratch;
   2436       1.1  riastrad 	struct radeon_doorbell		doorbell;
   2437       1.1  riastrad 	struct radeon_mman		mman;
   2438       1.1  riastrad 	struct radeon_fence_driver	fence_drv[RADEON_NUM_RINGS];
   2439       1.2  riastrad #ifdef __NetBSD__
   2440       1.2  riastrad 	spinlock_t			fence_lock;
   2441       1.2  riastrad 	drm_waitqueue_t			fence_queue;
   2442  1.3.32.1  christos 	TAILQ_HEAD(, radeon_fence)	fence_check;
   2443       1.2  riastrad #else
   2444       1.1  riastrad 	wait_queue_head_t		fence_queue;
   2445       1.2  riastrad #endif
   2446  1.3.32.1  christos 	unsigned			fence_context;
   2447       1.1  riastrad 	struct mutex			ring_lock;
   2448       1.1  riastrad 	struct radeon_ring		ring[RADEON_NUM_RINGS];
   2449       1.1  riastrad 	bool				ib_pool_ready;
   2450       1.1  riastrad 	struct radeon_sa_manager	ring_tmp_bo;
   2451       1.1  riastrad 	struct radeon_irq		irq;
   2452       1.1  riastrad 	struct radeon_asic		*asic;
   2453       1.1  riastrad 	struct radeon_gem		gem;
   2454       1.1  riastrad 	struct radeon_pm		pm;
   2455       1.1  riastrad 	struct radeon_uvd		uvd;
   2456       1.1  riastrad 	struct radeon_vce		vce;
   2457       1.1  riastrad 	uint32_t			bios_scratch[RADEON_BIOS_NUM_SCRATCH];
   2458       1.1  riastrad 	struct radeon_wb		wb;
   2459       1.1  riastrad 	struct radeon_dummy_page	dummy_page;
   2460       1.1  riastrad 	bool				shutdown;
   2461       1.1  riastrad 	bool				suspend;
   2462       1.1  riastrad 	bool				need_dma32;
   2463       1.1  riastrad 	bool				accel_working;
   2464       1.1  riastrad 	bool				fastfb_working; /* IGP feature*/
   2465  1.3.32.1  christos 	bool				needs_reset, in_reset;
   2466       1.1  riastrad 	struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
   2467       1.1  riastrad 	const struct firmware *me_fw;	/* all family ME firmware */
   2468       1.1  riastrad 	const struct firmware *pfp_fw;	/* r6/700 PFP firmware */
   2469       1.1  riastrad 	const struct firmware *rlc_fw;	/* r6/700 RLC firmware */
   2470       1.1  riastrad 	const struct firmware *mc_fw;	/* NI MC firmware */
   2471       1.1  riastrad 	const struct firmware *ce_fw;	/* SI CE firmware */
   2472       1.1  riastrad 	const struct firmware *mec_fw;	/* CIK MEC firmware */
   2473  1.3.32.1  christos 	const struct firmware *mec2_fw;	/* KV MEC2 firmware */
   2474       1.1  riastrad 	const struct firmware *sdma_fw;	/* CIK SDMA firmware */
   2475       1.1  riastrad 	const struct firmware *smc_fw;	/* SMC firmware */
   2476       1.1  riastrad 	const struct firmware *uvd_fw;	/* UVD firmware */
   2477       1.1  riastrad 	const struct firmware *vce_fw;	/* VCE firmware */
   2478  1.3.32.1  christos 	bool new_fw;
   2479       1.1  riastrad 	struct r600_vram_scratch vram_scratch;
   2480       1.1  riastrad 	int msi_enabled; /* msi enabled */
   2481       1.1  riastrad 	struct r600_ih ih; /* r6/700 interrupt ring */
   2482       1.1  riastrad 	struct radeon_rlc rlc;
   2483       1.1  riastrad 	struct radeon_mec mec;
   2484  1.3.32.1  christos 	struct delayed_work hotplug_work;
   2485  1.3.32.1  christos 	struct work_struct dp_work;
   2486       1.1  riastrad 	struct work_struct audio_work;
   2487       1.1  riastrad 	int num_crtc; /* number of crtcs */
   2488       1.1  riastrad 	struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
   2489       1.1  riastrad 	bool has_uvd;
   2490       1.1  riastrad 	struct r600_audio audio; /* audio stuff */
   2491       1.1  riastrad 	struct notifier_block acpi_nb;
   2492       1.1  riastrad 	/* only one userspace can use Hyperz features or CMASK at a time */
   2493       1.1  riastrad 	struct drm_file *hyperz_filp;
   2494       1.1  riastrad 	struct drm_file *cmask_filp;
   2495       1.1  riastrad 	/* i2c buses */
   2496       1.1  riastrad 	struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
   2497       1.1  riastrad 	/* debugfs */
   2498       1.1  riastrad 	struct radeon_debugfs	debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
   2499       1.1  riastrad 	unsigned 		debugfs_count;
   2500       1.1  riastrad 	/* virtual memory */
   2501       1.1  riastrad 	struct radeon_vm_manager	vm_manager;
   2502       1.1  riastrad 	struct mutex			gpu_clock_mutex;
   2503       1.1  riastrad 	/* memory stats */
   2504       1.1  riastrad 	atomic64_t			vram_usage;
   2505       1.1  riastrad 	atomic64_t			gtt_usage;
   2506       1.1  riastrad 	atomic64_t			num_bytes_moved;
   2507  1.3.32.1  christos 	atomic_t			gpu_reset_counter;
   2508       1.1  riastrad 	/* ACPI interface */
   2509       1.1  riastrad 	struct radeon_atif		atif;
   2510       1.1  riastrad 	struct radeon_atcs		atcs;
   2511       1.1  riastrad 	/* srbm instance registers */
   2512       1.1  riastrad 	struct mutex			srbm_mutex;
   2513  1.3.32.1  christos 	/* GRBM index mutex. Protects concurrents access to GRBM index */
   2514  1.3.32.1  christos 	struct mutex			grbm_idx_mutex;
   2515       1.1  riastrad 	/* clock, powergating flags */
   2516       1.1  riastrad 	u32 cg_flags;
   2517       1.1  riastrad 	u32 pg_flags;
   2518       1.1  riastrad 
   2519       1.1  riastrad 	struct dev_pm_domain vga_pm_domain;
   2520       1.1  riastrad 	bool have_disp_power_ref;
   2521  1.3.32.1  christos 	u32 px_quirk_flags;
   2522  1.3.32.1  christos 
   2523  1.3.32.1  christos 	/* tracking pinned memory */
   2524  1.3.32.1  christos 	u64 vram_pin_size;
   2525  1.3.32.1  christos 	u64 gart_pin_size;
   2526  1.3.32.1  christos 
   2527  1.3.32.1  christos 	/* amdkfd interface */
   2528  1.3.32.1  christos 	struct kfd_dev		*kfd;
   2529  1.3.32.1  christos 
   2530  1.3.32.1  christos 	struct mutex	mn_lock;
   2531  1.3.32.1  christos 	DECLARE_HASHTABLE(mn_hash, 7);
   2532       1.1  riastrad };
   2533       1.1  riastrad 
   2534       1.1  riastrad bool radeon_is_px(struct drm_device *dev);
   2535       1.1  riastrad int radeon_device_init(struct radeon_device *rdev,
   2536       1.1  riastrad 		       struct drm_device *ddev,
   2537       1.1  riastrad 		       struct pci_dev *pdev,
   2538       1.1  riastrad 		       uint32_t flags);
   2539       1.1  riastrad void radeon_device_fini(struct radeon_device *rdev);
   2540       1.1  riastrad int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
   2541       1.1  riastrad 
   2542  1.3.32.1  christos #define RADEON_MIN_MMIO_SIZE 0x10000
   2543  1.3.32.1  christos 
   2544  1.3.32.1  christos uint32_t r100_mm_rreg_slow(struct radeon_device *rdev, uint32_t reg);
   2545  1.3.32.1  christos void r100_mm_wreg_slow(struct radeon_device *rdev, uint32_t reg, uint32_t v);
   2546  1.3.32.1  christos static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
   2547  1.3.32.1  christos 				    bool always_indirect)
   2548  1.3.32.1  christos {
   2549  1.3.32.1  christos 	/* The mmio size is 64kb at minimum. Allows the if to be optimized out. */
   2550  1.3.32.1  christos 	if ((reg < rdev->rmmio_size || reg < RADEON_MIN_MMIO_SIZE) && !always_indirect)
   2551  1.3.32.1  christos #ifdef __NetBSD__
   2552  1.3.32.1  christos 		return bus_space_read_4(rdev->rmmio_bst, rdev->rmmio_bsh, reg);
   2553  1.3.32.1  christos #else
   2554  1.3.32.1  christos 		return readl(((void __iomem *)rdev->rmmio) + reg);
   2555  1.3.32.1  christos #endif
   2556  1.3.32.1  christos 	else
   2557  1.3.32.1  christos 		return r100_mm_rreg_slow(rdev, reg);
   2558  1.3.32.1  christos }
   2559  1.3.32.1  christos static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
   2560  1.3.32.1  christos 				bool always_indirect)
   2561  1.3.32.1  christos {
   2562  1.3.32.1  christos 	if ((reg < rdev->rmmio_size || reg < RADEON_MIN_MMIO_SIZE) && !always_indirect)
   2563  1.3.32.1  christos #ifdef __NetBSD__
   2564  1.3.32.1  christos 		bus_space_write_4(rdev->rmmio_bst, rdev->rmmio_bsh, reg, v);
   2565  1.3.32.1  christos #else
   2566  1.3.32.1  christos 		writel(v, ((void __iomem *)rdev->rmmio) + reg);
   2567  1.3.32.1  christos #endif
   2568  1.3.32.1  christos 	else
   2569  1.3.32.1  christos 		r100_mm_wreg_slow(rdev, reg, v);
   2570  1.3.32.1  christos }
   2571  1.3.32.1  christos 
   2572       1.1  riastrad u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
   2573       1.1  riastrad void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2574       1.1  riastrad 
   2575       1.1  riastrad u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index);
   2576       1.1  riastrad void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v);
   2577       1.1  riastrad 
   2578       1.1  riastrad /*
   2579       1.1  riastrad  * Cast helper
   2580       1.1  riastrad  */
   2581  1.3.32.1  christos extern const struct fence_ops radeon_fence_ops;
   2582  1.3.32.1  christos 
   2583  1.3.32.1  christos static inline struct radeon_fence *to_radeon_fence(struct fence *f)
   2584  1.3.32.1  christos {
   2585  1.3.32.1  christos 	struct radeon_fence *__f = container_of(f, struct radeon_fence, base);
   2586  1.3.32.1  christos 
   2587  1.3.32.1  christos 	if (__f->base.ops == &radeon_fence_ops)
   2588  1.3.32.1  christos 		return __f;
   2589  1.3.32.1  christos 
   2590  1.3.32.1  christos 	return NULL;
   2591  1.3.32.1  christos }
   2592       1.1  riastrad 
   2593       1.1  riastrad /*
   2594       1.1  riastrad  * Registers read & write functions.
   2595       1.1  riastrad  */
   2596       1.2  riastrad #ifdef __NetBSD__
   2597       1.2  riastrad #define	RREG8(r) bus_space_read_1(rdev->rmmio_bst, rdev->rmmio_bsh, (r))
   2598       1.2  riastrad #define	WREG8(r, v) bus_space_write_1(rdev->rmmio_bst, rdev->rmmio_bsh, (r), (v))
   2599       1.2  riastrad #define	RREG16(r) bus_space_read_2(rdev->rmmio_bst, rdev->rmmio_bsh, (r))
   2600       1.2  riastrad #define	WREG16(r, v) bus_space_write_2(rdev->rmmio_bst, rdev->rmmio_bsh, (r), (v))
   2601       1.2  riastrad #else
   2602       1.1  riastrad #define RREG8(reg) readb((rdev->rmmio) + (reg))
   2603       1.1  riastrad #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
   2604       1.1  riastrad #define RREG16(reg) readw((rdev->rmmio) + (reg))
   2605       1.1  riastrad #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
   2606       1.2  riastrad #endif
   2607       1.1  riastrad #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
   2608       1.1  riastrad #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
   2609       1.1  riastrad #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
   2610       1.1  riastrad #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
   2611       1.1  riastrad #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
   2612       1.1  riastrad #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
   2613       1.1  riastrad #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
   2614       1.1  riastrad #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
   2615       1.1  riastrad #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
   2616       1.1  riastrad #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
   2617       1.1  riastrad #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
   2618       1.1  riastrad #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
   2619       1.1  riastrad #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
   2620       1.1  riastrad #define RREG32_PCIE_PORT(reg) rdev->pciep_rreg(rdev, (reg))
   2621       1.1  riastrad #define WREG32_PCIE_PORT(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
   2622       1.1  riastrad #define RREG32_SMC(reg) tn_smc_rreg(rdev, (reg))
   2623       1.1  riastrad #define WREG32_SMC(reg, v) tn_smc_wreg(rdev, (reg), (v))
   2624       1.1  riastrad #define RREG32_RCU(reg) r600_rcu_rreg(rdev, (reg))
   2625       1.1  riastrad #define WREG32_RCU(reg, v) r600_rcu_wreg(rdev, (reg), (v))
   2626       1.1  riastrad #define RREG32_CG(reg) eg_cg_rreg(rdev, (reg))
   2627       1.1  riastrad #define WREG32_CG(reg, v) eg_cg_wreg(rdev, (reg), (v))
   2628       1.1  riastrad #define RREG32_PIF_PHY0(reg) eg_pif_phy0_rreg(rdev, (reg))
   2629       1.1  riastrad #define WREG32_PIF_PHY0(reg, v) eg_pif_phy0_wreg(rdev, (reg), (v))
   2630       1.1  riastrad #define RREG32_PIF_PHY1(reg) eg_pif_phy1_rreg(rdev, (reg))
   2631       1.1  riastrad #define WREG32_PIF_PHY1(reg, v) eg_pif_phy1_wreg(rdev, (reg), (v))
   2632       1.1  riastrad #define RREG32_UVD_CTX(reg) r600_uvd_ctx_rreg(rdev, (reg))
   2633       1.1  riastrad #define WREG32_UVD_CTX(reg, v) r600_uvd_ctx_wreg(rdev, (reg), (v))
   2634       1.1  riastrad #define RREG32_DIDT(reg) cik_didt_rreg(rdev, (reg))
   2635       1.1  riastrad #define WREG32_DIDT(reg, v) cik_didt_wreg(rdev, (reg), (v))
   2636       1.1  riastrad #define WREG32_P(reg, val, mask)				\
   2637       1.1  riastrad 	do {							\
   2638       1.1  riastrad 		uint32_t tmp_ = RREG32(reg);			\
   2639       1.1  riastrad 		tmp_ &= (mask);					\
   2640       1.1  riastrad 		tmp_ |= ((val) & ~(mask));			\
   2641       1.1  riastrad 		WREG32(reg, tmp_);				\
   2642       1.1  riastrad 	} while (0)
   2643       1.1  riastrad #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
   2644       1.1  riastrad #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
   2645       1.1  riastrad #define WREG32_PLL_P(reg, val, mask)				\
   2646       1.1  riastrad 	do {							\
   2647       1.1  riastrad 		uint32_t tmp_ = RREG32_PLL(reg);		\
   2648       1.1  riastrad 		tmp_ &= (mask);					\
   2649       1.1  riastrad 		tmp_ |= ((val) & ~(mask));			\
   2650       1.1  riastrad 		WREG32_PLL(reg, tmp_);				\
   2651       1.1  riastrad 	} while (0)
   2652  1.3.32.1  christos #define WREG32_SMC_P(reg, val, mask)				\
   2653  1.3.32.1  christos 	do {							\
   2654  1.3.32.1  christos 		uint32_t tmp_ = RREG32_SMC(reg);		\
   2655  1.3.32.1  christos 		tmp_ &= (mask);					\
   2656  1.3.32.1  christos 		tmp_ |= ((val) & ~(mask));			\
   2657  1.3.32.1  christos 		WREG32_SMC(reg, tmp_);				\
   2658  1.3.32.1  christos 	} while (0)
   2659       1.1  riastrad #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
   2660       1.1  riastrad #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
   2661       1.1  riastrad #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
   2662       1.1  riastrad 
   2663       1.1  riastrad #define RDOORBELL32(index) cik_mm_rdoorbell(rdev, (index))
   2664       1.1  riastrad #define WDOORBELL32(index, v) cik_mm_wdoorbell(rdev, (index), (v))
   2665       1.1  riastrad 
   2666       1.1  riastrad /*
   2667  1.3.32.1  christos  * Indirect registers accessors.
   2668  1.3.32.1  christos  * They used to be inlined, but this increases code size by ~65 kbytes.
   2669  1.3.32.1  christos  * Since each performs a pair of MMIO ops
   2670  1.3.32.1  christos  * within a spin_lock_irqsave/spin_unlock_irqrestore region,
   2671  1.3.32.1  christos  * the cost of call+ret is almost negligible. MMIO and locking
   2672  1.3.32.1  christos  * costs several dozens of cycles each at best, call+ret is ~5 cycles.
   2673  1.3.32.1  christos  */
   2674  1.3.32.1  christos uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg);
   2675  1.3.32.1  christos void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v);
   2676  1.3.32.1  christos u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg);
   2677  1.3.32.1  christos void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2678  1.3.32.1  christos u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg);
   2679  1.3.32.1  christos void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2680  1.3.32.1  christos u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg);
   2681  1.3.32.1  christos void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2682  1.3.32.1  christos u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg);
   2683  1.3.32.1  christos void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2684  1.3.32.1  christos u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg);
   2685  1.3.32.1  christos void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2686  1.3.32.1  christos u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg);
   2687  1.3.32.1  christos void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2688  1.3.32.1  christos u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg);
   2689  1.3.32.1  christos void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v);
   2690       1.1  riastrad 
   2691       1.1  riastrad void r100_pll_errata_after_index(struct radeon_device *rdev);
   2692       1.1  riastrad 
   2693       1.1  riastrad 
   2694       1.1  riastrad /*
   2695       1.1  riastrad  * ASICs helpers.
   2696       1.1  riastrad  */
   2697       1.1  riastrad #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
   2698       1.1  riastrad 			    (rdev->pdev->device == 0x5969))
   2699       1.1  riastrad #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
   2700       1.1  riastrad 		(rdev->family == CHIP_RV200) || \
   2701       1.1  riastrad 		(rdev->family == CHIP_RS100) || \
   2702       1.1  riastrad 		(rdev->family == CHIP_RS200) || \
   2703       1.1  riastrad 		(rdev->family == CHIP_RV250) || \
   2704       1.1  riastrad 		(rdev->family == CHIP_RV280) || \
   2705       1.1  riastrad 		(rdev->family == CHIP_RS300))
   2706       1.1  riastrad #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  ||	\
   2707       1.1  riastrad 		(rdev->family == CHIP_RV350) ||			\
   2708       1.1  riastrad 		(rdev->family == CHIP_R350)  ||			\
   2709       1.1  riastrad 		(rdev->family == CHIP_RV380) ||			\
   2710       1.1  riastrad 		(rdev->family == CHIP_R420)  ||			\
   2711       1.1  riastrad 		(rdev->family == CHIP_R423)  ||			\
   2712       1.1  riastrad 		(rdev->family == CHIP_RV410) ||			\
   2713       1.1  riastrad 		(rdev->family == CHIP_RS400) ||			\
   2714       1.1  riastrad 		(rdev->family == CHIP_RS480))
   2715       1.1  riastrad #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
   2716       1.1  riastrad 		(rdev->ddev->pdev->device == 0x9443) || \
   2717       1.1  riastrad 		(rdev->ddev->pdev->device == 0x944B) || \
   2718       1.1  riastrad 		(rdev->ddev->pdev->device == 0x9506) || \
   2719       1.1  riastrad 		(rdev->ddev->pdev->device == 0x9509) || \
   2720       1.1  riastrad 		(rdev->ddev->pdev->device == 0x950F) || \
   2721       1.1  riastrad 		(rdev->ddev->pdev->device == 0x689C) || \
   2722       1.1  riastrad 		(rdev->ddev->pdev->device == 0x689D))
   2723       1.1  riastrad #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
   2724       1.1  riastrad #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600)  ||	\
   2725       1.1  riastrad 			    (rdev->family == CHIP_RS690)  ||	\
   2726       1.1  riastrad 			    (rdev->family == CHIP_RS740)  ||	\
   2727       1.1  riastrad 			    (rdev->family >= CHIP_R600))
   2728       1.1  riastrad #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
   2729       1.1  riastrad #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
   2730       1.1  riastrad #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
   2731       1.1  riastrad #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
   2732       1.1  riastrad 			     (rdev->flags & RADEON_IS_IGP))
   2733       1.1  riastrad #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
   2734       1.1  riastrad #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
   2735       1.1  riastrad #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
   2736       1.1  riastrad 			     (rdev->flags & RADEON_IS_IGP))
   2737       1.1  riastrad #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
   2738       1.1  riastrad #define ASIC_IS_NODCE(rdev) ((rdev->family == CHIP_HAINAN))
   2739       1.1  riastrad #define ASIC_IS_DCE8(rdev) ((rdev->family >= CHIP_BONAIRE))
   2740       1.1  riastrad #define ASIC_IS_DCE81(rdev) ((rdev->family == CHIP_KAVERI))
   2741       1.1  riastrad #define ASIC_IS_DCE82(rdev) ((rdev->family == CHIP_BONAIRE))
   2742       1.1  riastrad #define ASIC_IS_DCE83(rdev) ((rdev->family == CHIP_KABINI) || \
   2743       1.1  riastrad 			     (rdev->family == CHIP_MULLINS))
   2744       1.1  riastrad 
   2745       1.1  riastrad #define ASIC_IS_LOMBOK(rdev) ((rdev->ddev->pdev->device == 0x6849) || \
   2746       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6850) || \
   2747       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6858) || \
   2748       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6859) || \
   2749       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6840) || \
   2750       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6841) || \
   2751       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6842) || \
   2752       1.1  riastrad 			      (rdev->ddev->pdev->device == 0x6843))
   2753       1.1  riastrad 
   2754       1.1  riastrad /*
   2755       1.1  riastrad  * BIOS helpers.
   2756       1.1  riastrad  */
   2757       1.1  riastrad #define RBIOS8(i) (rdev->bios[i])
   2758       1.1  riastrad #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
   2759       1.1  riastrad #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
   2760       1.1  riastrad 
   2761       1.1  riastrad int radeon_combios_init(struct radeon_device *rdev);
   2762       1.1  riastrad void radeon_combios_fini(struct radeon_device *rdev);
   2763       1.1  riastrad int radeon_atombios_init(struct radeon_device *rdev);
   2764       1.1  riastrad void radeon_atombios_fini(struct radeon_device *rdev);
   2765       1.1  riastrad 
   2766       1.1  riastrad 
   2767       1.1  riastrad /*
   2768       1.1  riastrad  * RING helpers.
   2769       1.1  riastrad  */
   2770  1.3.32.1  christos 
   2771  1.3.32.1  christos /**
   2772  1.3.32.1  christos  * radeon_ring_write - write a value to the ring
   2773  1.3.32.1  christos  *
   2774  1.3.32.1  christos  * @ring: radeon_ring structure holding ring information
   2775  1.3.32.1  christos  * @v: dword (dw) value to write
   2776  1.3.32.1  christos  *
   2777  1.3.32.1  christos  * Write a value to the requested ring buffer (all asics).
   2778  1.3.32.1  christos  */
   2779       1.1  riastrad static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
   2780       1.1  riastrad {
   2781  1.3.32.1  christos 	if (ring->count_dw <= 0)
   2782  1.3.32.1  christos 		DRM_ERROR("radeon: writing more dwords to the ring than expected!\n");
   2783  1.3.32.1  christos 
   2784       1.1  riastrad 	ring->ring[ring->wptr++] = v;
   2785       1.1  riastrad 	ring->wptr &= ring->ptr_mask;
   2786       1.1  riastrad 	ring->count_dw--;
   2787       1.1  riastrad 	ring->ring_free_dw--;
   2788       1.1  riastrad }
   2789       1.1  riastrad 
   2790       1.1  riastrad /*
   2791       1.1  riastrad  * ASICs macro.
   2792       1.1  riastrad  */
   2793       1.1  riastrad #define radeon_init(rdev) (rdev)->asic->init((rdev))
   2794       1.1  riastrad #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
   2795       1.1  riastrad #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
   2796       1.1  riastrad #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
   2797       1.1  riastrad #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)]->cs_parse((p))
   2798       1.1  riastrad #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
   2799       1.1  riastrad #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
   2800       1.1  riastrad #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
   2801  1.3.32.1  christos #define radeon_gart_get_page_entry(a, f) (rdev)->asic->gart.get_page_entry((a), (f))
   2802  1.3.32.1  christos #define radeon_gart_set_page(rdev, i, e) (rdev)->asic->gart.set_page((rdev), (i), (e))
   2803       1.1  riastrad #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
   2804       1.1  riastrad #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
   2805  1.3.32.1  christos #define radeon_asic_vm_copy_pages(rdev, ib, pe, src, count) ((rdev)->asic->vm.copy_pages((rdev), (ib), (pe), (src), (count)))
   2806  1.3.32.1  christos #define radeon_asic_vm_write_pages(rdev, ib, pe, addr, count, incr, flags) ((rdev)->asic->vm.write_pages((rdev), (ib), (pe), (addr), (count), (incr), (flags)))
   2807  1.3.32.1  christos #define radeon_asic_vm_set_pages(rdev, ib, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_pages((rdev), (ib), (pe), (addr), (count), (incr), (flags)))
   2808  1.3.32.1  christos #define radeon_asic_vm_pad_ib(rdev, ib) ((rdev)->asic->vm.pad_ib((ib)))
   2809       1.1  riastrad #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_start((rdev), (cp))
   2810       1.1  riastrad #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_test((rdev), (cp))
   2811       1.1  riastrad #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ib_test((rdev), (cp))
   2812       1.1  riastrad #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_execute((rdev), (ib))
   2813       1.1  riastrad #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_parse((rdev), (ib))
   2814       1.1  riastrad #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)]->is_lockup((rdev), (cp))
   2815  1.3.32.1  christos #define radeon_ring_vm_flush(rdev, r, vm_id, pd_addr) (rdev)->asic->ring[(r)->idx]->vm_flush((rdev), (r), (vm_id), (pd_addr))
   2816       1.1  riastrad #define radeon_ring_get_rptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_rptr((rdev), (r))
   2817       1.1  riastrad #define radeon_ring_get_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_wptr((rdev), (r))
   2818       1.1  riastrad #define radeon_ring_set_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->set_wptr((rdev), (r))
   2819       1.1  riastrad #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
   2820       1.1  riastrad #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
   2821       1.1  riastrad #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
   2822       1.1  riastrad #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
   2823       1.1  riastrad #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
   2824       1.1  riastrad #define radeon_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
   2825       1.1  riastrad #define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
   2826       1.1  riastrad #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)]->emit_fence((rdev), (fence))
   2827       1.1  riastrad #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)]->emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
   2828  1.3.32.1  christos #define radeon_copy_blit(rdev, s, d, np, resv) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (resv))
   2829  1.3.32.1  christos #define radeon_copy_dma(rdev, s, d, np, resv) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (resv))
   2830  1.3.32.1  christos #define radeon_copy(rdev, s, d, np, resv) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (resv))
   2831       1.1  riastrad #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
   2832       1.1  riastrad #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
   2833       1.1  riastrad #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
   2834       1.1  riastrad #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
   2835       1.1  riastrad #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
   2836       1.1  riastrad #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
   2837       1.1  riastrad #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
   2838       1.1  riastrad #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
   2839       1.1  riastrad #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
   2840       1.1  riastrad #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
   2841       1.1  riastrad #define radeon_set_uvd_clocks(rdev, v, d) (rdev)->asic->pm.set_uvd_clocks((rdev), (v), (d))
   2842       1.1  riastrad #define radeon_set_vce_clocks(rdev, ev, ec) (rdev)->asic->pm.set_vce_clocks((rdev), (ev), (ec))
   2843       1.1  riastrad #define radeon_get_temperature(rdev) (rdev)->asic->pm.get_temperature((rdev))
   2844       1.1  riastrad #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
   2845       1.1  riastrad #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
   2846       1.1  riastrad #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
   2847       1.1  riastrad #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
   2848       1.1  riastrad #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
   2849       1.1  riastrad #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
   2850       1.1  riastrad #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
   2851       1.1  riastrad #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
   2852       1.1  riastrad #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
   2853       1.1  riastrad #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
   2854       1.1  riastrad #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
   2855       1.1  riastrad #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
   2856       1.1  riastrad #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
   2857       1.1  riastrad #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
   2858  1.3.32.1  christos #define radeon_page_flip_pending(rdev, crtc) (rdev)->asic->pflip.page_flip_pending((rdev), (crtc))
   2859       1.1  riastrad #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
   2860       1.1  riastrad #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
   2861       1.1  riastrad #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
   2862       1.1  riastrad #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
   2863  1.3.32.1  christos #define radeon_get_allowed_info_register(rdev, r, v) (rdev)->asic->get_allowed_info_register((rdev), (r), (v))
   2864       1.1  riastrad #define radeon_dpm_init(rdev) rdev->asic->dpm.init((rdev))
   2865       1.1  riastrad #define radeon_dpm_setup_asic(rdev) rdev->asic->dpm.setup_asic((rdev))
   2866       1.1  riastrad #define radeon_dpm_enable(rdev) rdev->asic->dpm.enable((rdev))
   2867       1.1  riastrad #define radeon_dpm_late_enable(rdev) rdev->asic->dpm.late_enable((rdev))
   2868       1.1  riastrad #define radeon_dpm_disable(rdev) rdev->asic->dpm.disable((rdev))
   2869       1.1  riastrad #define radeon_dpm_pre_set_power_state(rdev) rdev->asic->dpm.pre_set_power_state((rdev))
   2870       1.1  riastrad #define radeon_dpm_set_power_state(rdev) rdev->asic->dpm.set_power_state((rdev))
   2871       1.1  riastrad #define radeon_dpm_post_set_power_state(rdev) rdev->asic->dpm.post_set_power_state((rdev))
   2872       1.1  riastrad #define radeon_dpm_display_configuration_changed(rdev) rdev->asic->dpm.display_configuration_changed((rdev))
   2873       1.1  riastrad #define radeon_dpm_fini(rdev) rdev->asic->dpm.fini((rdev))
   2874       1.1  riastrad #define radeon_dpm_get_sclk(rdev, l) rdev->asic->dpm.get_sclk((rdev), (l))
   2875       1.1  riastrad #define radeon_dpm_get_mclk(rdev, l) rdev->asic->dpm.get_mclk((rdev), (l))
   2876       1.1  riastrad #define radeon_dpm_print_power_state(rdev, ps) rdev->asic->dpm.print_power_state((rdev), (ps))
   2877       1.1  riastrad #define radeon_dpm_debugfs_print_current_performance_level(rdev, m) rdev->asic->dpm.debugfs_print_current_performance_level((rdev), (m))
   2878       1.1  riastrad #define radeon_dpm_force_performance_level(rdev, l) rdev->asic->dpm.force_performance_level((rdev), (l))
   2879       1.1  riastrad #define radeon_dpm_vblank_too_short(rdev) rdev->asic->dpm.vblank_too_short((rdev))
   2880       1.1  riastrad #define radeon_dpm_powergate_uvd(rdev, g) rdev->asic->dpm.powergate_uvd((rdev), (g))
   2881       1.1  riastrad #define radeon_dpm_enable_bapm(rdev, e) rdev->asic->dpm.enable_bapm((rdev), (e))
   2882  1.3.32.1  christos #define radeon_dpm_get_current_sclk(rdev) rdev->asic->dpm.get_current_sclk((rdev))
   2883  1.3.32.1  christos #define radeon_dpm_get_current_mclk(rdev) rdev->asic->dpm.get_current_mclk((rdev))
   2884       1.1  riastrad 
   2885       1.1  riastrad /* Common functions */
   2886       1.1  riastrad /* AGP */
   2887       1.1  riastrad extern int radeon_gpu_reset(struct radeon_device *rdev);
   2888       1.1  riastrad extern void radeon_pci_config_reset(struct radeon_device *rdev);
   2889       1.1  riastrad extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
   2890       1.1  riastrad extern void radeon_agp_disable(struct radeon_device *rdev);
   2891       1.1  riastrad extern int radeon_modeset_init(struct radeon_device *rdev);
   2892       1.1  riastrad extern void radeon_modeset_fini(struct radeon_device *rdev);
   2893       1.1  riastrad extern bool radeon_card_posted(struct radeon_device *rdev);
   2894       1.1  riastrad extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
   2895       1.1  riastrad extern void radeon_update_display_priority(struct radeon_device *rdev);
   2896       1.1  riastrad extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
   2897       1.1  riastrad extern void radeon_scratch_init(struct radeon_device *rdev);
   2898       1.1  riastrad extern void radeon_wb_fini(struct radeon_device *rdev);
   2899       1.1  riastrad extern int radeon_wb_init(struct radeon_device *rdev);
   2900       1.1  riastrad extern void radeon_wb_disable(struct radeon_device *rdev);
   2901       1.1  riastrad extern void radeon_surface_init(struct radeon_device *rdev);
   2902       1.1  riastrad extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
   2903       1.1  riastrad extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
   2904       1.1  riastrad extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
   2905       1.1  riastrad extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
   2906       1.1  riastrad extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
   2907  1.3.32.1  christos extern int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
   2908  1.3.32.1  christos 				     uint32_t flags);
   2909  1.3.32.1  christos extern bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm);
   2910  1.3.32.1  christos extern bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm);
   2911       1.1  riastrad extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
   2912       1.1  riastrad extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
   2913       1.1  riastrad extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
   2914       1.1  riastrad extern int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
   2915       1.1  riastrad extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
   2916       1.1  riastrad extern void radeon_program_register_sequence(struct radeon_device *rdev,
   2917       1.1  riastrad 					     const u32 *registers,
   2918       1.1  riastrad 					     const u32 array_size);
   2919       1.1  riastrad 
   2920       1.1  riastrad /*
   2921       1.1  riastrad  * vm
   2922       1.1  riastrad  */
   2923       1.1  riastrad int radeon_vm_manager_init(struct radeon_device *rdev);
   2924       1.1  riastrad void radeon_vm_manager_fini(struct radeon_device *rdev);
   2925       1.1  riastrad int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
   2926       1.1  riastrad void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
   2927  1.3.32.1  christos struct radeon_bo_list *radeon_vm_get_bos(struct radeon_device *rdev,
   2928       1.1  riastrad 					  struct radeon_vm *vm,
   2929       1.1  riastrad                                           struct list_head *head);
   2930       1.1  riastrad struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
   2931       1.1  riastrad 				       struct radeon_vm *vm, int ring);
   2932       1.1  riastrad void radeon_vm_flush(struct radeon_device *rdev,
   2933       1.1  riastrad                      struct radeon_vm *vm,
   2934  1.3.32.1  christos 		     int ring, struct radeon_fence *fence);
   2935       1.1  riastrad void radeon_vm_fence(struct radeon_device *rdev,
   2936       1.1  riastrad 		     struct radeon_vm *vm,
   2937       1.1  riastrad 		     struct radeon_fence *fence);
   2938       1.1  riastrad uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
   2939       1.1  riastrad int radeon_vm_update_page_directory(struct radeon_device *rdev,
   2940       1.1  riastrad 				    struct radeon_vm *vm);
   2941  1.3.32.1  christos int radeon_vm_clear_freed(struct radeon_device *rdev,
   2942  1.3.32.1  christos 			  struct radeon_vm *vm);
   2943  1.3.32.1  christos int radeon_vm_clear_invalids(struct radeon_device *rdev,
   2944  1.3.32.1  christos 			     struct radeon_vm *vm);
   2945       1.1  riastrad int radeon_vm_bo_update(struct radeon_device *rdev,
   2946  1.3.32.1  christos 			struct radeon_bo_va *bo_va,
   2947       1.1  riastrad 			struct ttm_mem_reg *mem);
   2948       1.1  riastrad void radeon_vm_bo_invalidate(struct radeon_device *rdev,
   2949       1.1  riastrad 			     struct radeon_bo *bo);
   2950       1.1  riastrad struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
   2951       1.1  riastrad 				       struct radeon_bo *bo);
   2952       1.1  riastrad struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
   2953       1.1  riastrad 				      struct radeon_vm *vm,
   2954       1.1  riastrad 				      struct radeon_bo *bo);
   2955       1.1  riastrad int radeon_vm_bo_set_addr(struct radeon_device *rdev,
   2956       1.1  riastrad 			  struct radeon_bo_va *bo_va,
   2957       1.1  riastrad 			  uint64_t offset,
   2958       1.1  riastrad 			  uint32_t flags);
   2959  1.3.32.1  christos void radeon_vm_bo_rmv(struct radeon_device *rdev,
   2960  1.3.32.1  christos 		      struct radeon_bo_va *bo_va);
   2961       1.1  riastrad 
   2962       1.1  riastrad /* audio */
   2963       1.1  riastrad void r600_audio_update_hdmi(struct work_struct *work);
   2964       1.1  riastrad struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
   2965       1.1  riastrad struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
   2966       1.1  riastrad void r600_audio_enable(struct radeon_device *rdev,
   2967       1.1  riastrad 		       struct r600_audio_pin *pin,
   2968  1.3.32.1  christos 		       u8 enable_mask);
   2969       1.1  riastrad void dce6_audio_enable(struct radeon_device *rdev,
   2970       1.1  riastrad 		       struct r600_audio_pin *pin,
   2971  1.3.32.1  christos 		       u8 enable_mask);
   2972       1.1  riastrad 
   2973       1.1  riastrad /*
   2974       1.1  riastrad  * R600 vram scratch functions
   2975       1.1  riastrad  */
   2976       1.1  riastrad int r600_vram_scratch_init(struct radeon_device *rdev);
   2977       1.1  riastrad void r600_vram_scratch_fini(struct radeon_device *rdev);
   2978       1.1  riastrad 
   2979       1.1  riastrad /*
   2980       1.1  riastrad  * r600 cs checking helper
   2981       1.1  riastrad  */
   2982       1.1  riastrad unsigned r600_mip_minify(unsigned size, unsigned level);
   2983       1.1  riastrad bool r600_fmt_is_valid_color(u32 format);
   2984       1.1  riastrad bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
   2985       1.1  riastrad int r600_fmt_get_blocksize(u32 format);
   2986       1.1  riastrad int r600_fmt_get_nblocksx(u32 format, u32 w);
   2987       1.1  riastrad int r600_fmt_get_nblocksy(u32 format, u32 h);
   2988       1.1  riastrad 
   2989       1.1  riastrad /*
   2990       1.1  riastrad  * r600 functions used by radeon_encoder.c
   2991       1.1  riastrad  */
   2992       1.1  riastrad struct radeon_hdmi_acr {
   2993       1.1  riastrad 	u32 clock;
   2994       1.1  riastrad 
   2995       1.1  riastrad 	int n_32khz;
   2996       1.1  riastrad 	int cts_32khz;
   2997       1.1  riastrad 
   2998       1.1  riastrad 	int n_44_1khz;
   2999       1.1  riastrad 	int cts_44_1khz;
   3000       1.1  riastrad 
   3001       1.1  riastrad 	int n_48khz;
   3002       1.1  riastrad 	int cts_48khz;
   3003       1.1  riastrad 
   3004       1.1  riastrad };
   3005       1.1  riastrad 
   3006       1.1  riastrad extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
   3007       1.1  riastrad 
   3008       1.1  riastrad extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
   3009       1.1  riastrad 				     u32 tiling_pipe_num,
   3010       1.1  riastrad 				     u32 max_rb_num,
   3011       1.1  riastrad 				     u32 total_max_rb_num,
   3012       1.1  riastrad 				     u32 enabled_rb_mask);
   3013       1.1  riastrad 
   3014       1.1  riastrad /*
   3015       1.1  riastrad  * evergreen functions used by radeon_encoder.c
   3016       1.1  riastrad  */
   3017       1.1  riastrad 
   3018       1.1  riastrad extern int ni_init_microcode(struct radeon_device *rdev);
   3019       1.1  riastrad extern int ni_mc_load_microcode(struct radeon_device *rdev);
   3020       1.1  riastrad 
   3021       1.1  riastrad /* radeon_acpi.c */
   3022       1.1  riastrad #if defined(CONFIG_ACPI)
   3023       1.1  riastrad extern int radeon_acpi_init(struct radeon_device *rdev);
   3024       1.1  riastrad extern void radeon_acpi_fini(struct radeon_device *rdev);
   3025       1.1  riastrad extern bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev);
   3026       1.1  riastrad extern int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
   3027       1.1  riastrad 						u8 perf_req, bool advertise);
   3028       1.1  riastrad extern int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev);
   3029       1.1  riastrad #else
   3030       1.1  riastrad static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
   3031       1.1  riastrad static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
   3032       1.1  riastrad #endif
   3033       1.1  riastrad 
   3034       1.1  riastrad int radeon_cs_packet_parse(struct radeon_cs_parser *p,
   3035       1.1  riastrad 			   struct radeon_cs_packet *pkt,
   3036       1.1  riastrad 			   unsigned idx);
   3037       1.1  riastrad bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
   3038       1.1  riastrad void radeon_cs_dump_packet(struct radeon_cs_parser *p,
   3039       1.1  riastrad 			   struct radeon_cs_packet *pkt);
   3040       1.1  riastrad int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
   3041  1.3.32.1  christos 				struct radeon_bo_list **cs_reloc,
   3042       1.1  riastrad 				int nomm);
   3043       1.1  riastrad int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
   3044       1.1  riastrad 			       uint32_t *vline_start_end,
   3045       1.1  riastrad 			       uint32_t *vline_status);
   3046       1.1  riastrad 
   3047       1.1  riastrad #include "radeon_object.h"
   3048       1.1  riastrad 
   3049       1.1  riastrad #endif
   3050