Home | History | Annotate | Line # | Download | only in amdgpu
      1  1.10       tnn /*	$NetBSD: amdgpu.h,v 1.10 2025/05/09 20:18:25 tnn Exp $	*/
      2   1.1  riastrad 
      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 __AMDGPU_H__
     31   1.1  riastrad #define __AMDGPU_H__
     32   1.1  riastrad 
     33   1.4  riastrad #ifdef _KERNEL_OPT
     34   1.4  riastrad #include "opt_amdgpu_cik.h"
     35  1.10       tnn #include "opt_amdgpu_si.h"
     36   1.4  riastrad #endif
     37   1.4  riastrad 
     38   1.4  riastrad #ifdef AMDGPU_CIK
     39   1.4  riastrad #define	CONFIG_DRM_AMDGPU_CIK	1
     40   1.4  riastrad #endif
     41  1.10       tnn #ifdef AMDGPU_SI
     42  1.10       tnn #define	CONFIG_DRM_AMDGPU_SI	1
     43  1.10       tnn #endif
     44   1.5  riastrad #include "amdgpu_ctx.h"
     45   1.4  riastrad 
     46   1.1  riastrad #include <linux/atomic.h>
     47   1.1  riastrad #include <linux/wait.h>
     48   1.1  riastrad #include <linux/list.h>
     49   1.1  riastrad #include <linux/kref.h>
     50   1.5  riastrad #include <linux/rbtree.h>
     51   1.1  riastrad #include <linux/hashtable.h>
     52   1.5  riastrad #include <linux/dma-fence.h>
     53   1.9  riastrad #include <linux/acpi.h>
     54   1.1  riastrad 
     55   1.5  riastrad #include <drm/ttm/ttm_bo_api.h>
     56   1.5  riastrad #include <drm/ttm/ttm_bo_driver.h>
     57   1.5  riastrad #include <drm/ttm/ttm_placement.h>
     58   1.5  riastrad #include <drm/ttm/ttm_module.h>
     59   1.5  riastrad #include <drm/ttm/ttm_execbuf_util.h>
     60   1.1  riastrad 
     61   1.5  riastrad #include <drm/amdgpu_drm.h>
     62   1.1  riastrad #include <drm/drm_gem.h>
     63   1.5  riastrad #include <drm/drm_ioctl.h>
     64   1.5  riastrad #include <drm/gpu_scheduler.h>
     65   1.5  riastrad 
     66   1.5  riastrad #include <kgd_kfd_interface.h>
     67   1.5  riastrad #include "dm_pp_interface.h"
     68   1.5  riastrad #include "kgd_pp_interface.h"
     69   1.1  riastrad 
     70   1.1  riastrad #include "amd_shared.h"
     71   1.1  riastrad #include "amdgpu_mode.h"
     72   1.1  riastrad #include "amdgpu_ih.h"
     73   1.1  riastrad #include "amdgpu_irq.h"
     74   1.1  riastrad #include "amdgpu_ucode.h"
     75   1.5  riastrad #include "amdgpu_ttm.h"
     76   1.5  riastrad #include "amdgpu_psp.h"
     77   1.1  riastrad #include "amdgpu_gds.h"
     78   1.5  riastrad #include "amdgpu_sync.h"
     79   1.5  riastrad #include "amdgpu_ring.h"
     80   1.5  riastrad #include "amdgpu_vm.h"
     81   1.5  riastrad #include "amdgpu_dpm.h"
     82   1.5  riastrad #include "amdgpu_acp.h"
     83   1.5  riastrad #include "amdgpu_uvd.h"
     84   1.5  riastrad #include "amdgpu_vce.h"
     85   1.5  riastrad #include "amdgpu_vcn.h"
     86   1.5  riastrad #include "amdgpu_jpeg.h"
     87   1.5  riastrad #include "amdgpu_mn.h"
     88   1.5  riastrad #include "amdgpu_gmc.h"
     89   1.5  riastrad #include "amdgpu_gfx.h"
     90   1.5  riastrad #include "amdgpu_sdma.h"
     91   1.5  riastrad #include "amdgpu_nbio.h"
     92   1.5  riastrad #include "amdgpu_dm.h"
     93   1.5  riastrad #include "amdgpu_virt.h"
     94   1.5  riastrad #include "amdgpu_csa.h"
     95   1.5  riastrad #include "amdgpu_gart.h"
     96   1.5  riastrad #include "amdgpu_debugfs.h"
     97   1.5  riastrad #include "amdgpu_job.h"
     98   1.5  riastrad #include "amdgpu_bo_list.h"
     99   1.5  riastrad #include "amdgpu_gem.h"
    100   1.5  riastrad #include "amdgpu_doorbell.h"
    101   1.5  riastrad #include "amdgpu_amdkfd.h"
    102   1.5  riastrad #include "amdgpu_smu.h"
    103   1.5  riastrad #include "amdgpu_discovery.h"
    104   1.5  riastrad #include "amdgpu_mes.h"
    105   1.5  riastrad #include "amdgpu_umc.h"
    106   1.5  riastrad #include "amdgpu_mmhub.h"
    107   1.5  riastrad #include "amdgpu_df.h"
    108   1.5  riastrad 
    109   1.5  riastrad #define MAX_GPU_INSTANCE		16
    110   1.5  riastrad 
    111   1.5  riastrad struct amdgpu_gpu_instance
    112   1.5  riastrad {
    113   1.5  riastrad 	struct amdgpu_device		*adev;
    114   1.5  riastrad 	int				mgpu_fan_enabled;
    115   1.5  riastrad };
    116   1.5  riastrad 
    117   1.5  riastrad struct amdgpu_mgpu_info
    118   1.5  riastrad {
    119   1.5  riastrad 	struct amdgpu_gpu_instance	gpu_ins[MAX_GPU_INSTANCE];
    120   1.5  riastrad 	struct mutex			mutex;
    121   1.5  riastrad 	uint32_t			num_gpu;
    122   1.5  riastrad 	uint32_t			num_dgpu;
    123   1.5  riastrad 	uint32_t			num_apu;
    124   1.5  riastrad };
    125   1.1  riastrad 
    126   1.5  riastrad #define AMDGPU_MAX_TIMEOUT_PARAM_LENGTH	256
    127   1.1  riastrad 
    128   1.1  riastrad /*
    129   1.1  riastrad  * Modules parameters.
    130   1.1  riastrad  */
    131   1.1  riastrad extern int amdgpu_modeset;
    132   1.1  riastrad extern int amdgpu_vram_limit;
    133   1.5  riastrad extern int amdgpu_vis_vram_limit;
    134   1.1  riastrad extern int amdgpu_gart_size;
    135   1.5  riastrad extern int amdgpu_gtt_size;
    136   1.5  riastrad extern int amdgpu_moverate;
    137   1.1  riastrad extern int amdgpu_benchmarking;
    138   1.1  riastrad extern int amdgpu_testing;
    139   1.1  riastrad extern int amdgpu_audio;
    140   1.1  riastrad extern int amdgpu_disp_priority;
    141   1.1  riastrad extern int amdgpu_hw_i2c;
    142   1.1  riastrad extern int amdgpu_pcie_gen2;
    143   1.1  riastrad extern int amdgpu_msi;
    144   1.5  riastrad extern char amdgpu_lockup_timeout[AMDGPU_MAX_TIMEOUT_PARAM_LENGTH];
    145   1.1  riastrad extern int amdgpu_dpm;
    146   1.5  riastrad extern int amdgpu_fw_load_type;
    147   1.1  riastrad extern int amdgpu_aspm;
    148   1.1  riastrad extern int amdgpu_runtime_pm;
    149   1.5  riastrad extern uint amdgpu_ip_block_mask;
    150   1.1  riastrad extern int amdgpu_bapm;
    151   1.1  riastrad extern int amdgpu_deep_color;
    152   1.1  riastrad extern int amdgpu_vm_size;
    153   1.1  riastrad extern int amdgpu_vm_block_size;
    154   1.5  riastrad extern int amdgpu_vm_fragment_size;
    155   1.1  riastrad extern int amdgpu_vm_fault_stop;
    156   1.1  riastrad extern int amdgpu_vm_debug;
    157   1.5  riastrad extern int amdgpu_vm_update_mode;
    158   1.5  riastrad extern int amdgpu_exp_hw_support;
    159   1.5  riastrad extern int amdgpu_dc;
    160   1.1  riastrad extern int amdgpu_sched_jobs;
    161   1.1  riastrad extern int amdgpu_sched_hw_submission;
    162   1.5  riastrad extern uint amdgpu_pcie_gen_cap;
    163   1.5  riastrad extern uint amdgpu_pcie_lane_cap;
    164   1.5  riastrad extern uint amdgpu_cg_mask;
    165   1.5  riastrad extern uint amdgpu_pg_mask;
    166   1.5  riastrad extern uint amdgpu_sdma_phase_quantum;
    167   1.5  riastrad extern char *amdgpu_disable_cu;
    168   1.5  riastrad extern char *amdgpu_virtual_display;
    169   1.5  riastrad extern uint amdgpu_pp_feature_mask;
    170   1.5  riastrad extern uint amdgpu_force_long_training;
    171   1.5  riastrad extern int amdgpu_job_hang_limit;
    172   1.5  riastrad extern int amdgpu_lbpw;
    173   1.5  riastrad extern int amdgpu_compute_multipipe;
    174   1.5  riastrad extern int amdgpu_gpu_recovery;
    175   1.5  riastrad extern int amdgpu_emu_mode;
    176   1.5  riastrad extern uint amdgpu_smu_memory_pool_size;
    177   1.5  riastrad extern uint amdgpu_dc_feature_mask;
    178   1.5  riastrad extern uint amdgpu_dm_abm_level;
    179   1.5  riastrad extern struct amdgpu_mgpu_info mgpu_info;
    180   1.5  riastrad extern int amdgpu_ras_enable;
    181   1.5  riastrad extern uint amdgpu_ras_mask;
    182   1.5  riastrad extern int amdgpu_async_gfx_ring;
    183   1.5  riastrad extern int amdgpu_mcbp;
    184   1.5  riastrad extern int amdgpu_discovery;
    185   1.5  riastrad extern int amdgpu_mes;
    186   1.5  riastrad extern int amdgpu_noretry;
    187   1.5  riastrad extern int amdgpu_force_asic_type;
    188   1.5  riastrad #ifdef CONFIG_HSA_AMD
    189   1.5  riastrad extern int sched_policy;
    190   1.5  riastrad #else
    191   1.5  riastrad static const int sched_policy = KFD_SCHED_POLICY_HWS;
    192   1.5  riastrad #endif
    193   1.5  riastrad 
    194   1.5  riastrad #ifdef CONFIG_DRM_AMDGPU_SI
    195   1.5  riastrad extern int amdgpu_si_support;
    196   1.5  riastrad #endif
    197   1.5  riastrad #ifdef CONFIG_DRM_AMDGPU_CIK
    198   1.5  riastrad extern int amdgpu_cik_support;
    199   1.5  riastrad #endif
    200   1.1  riastrad 
    201   1.5  riastrad #define AMDGPU_VM_MAX_NUM_CTX			4096
    202   1.5  riastrad #define AMDGPU_SG_THRESHOLD			(256*1024*1024)
    203   1.5  riastrad #define AMDGPU_DEFAULT_GTT_SIZE_MB		3072ULL /* 3GB by default */
    204   1.1  riastrad #define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS	        3000
    205   1.1  riastrad #define AMDGPU_MAX_USEC_TIMEOUT			100000	/* 100 ms */
    206   1.1  riastrad #define AMDGPU_FENCE_JIFFIES_TIMEOUT		(HZ / 2)
    207   1.1  riastrad /* AMDGPU_IB_POOL_SIZE must be a power of 2 */
    208   1.1  riastrad #define AMDGPU_IB_POOL_SIZE			16
    209   1.1  riastrad #define AMDGPU_DEBUGFS_MAX_COMPONENTS		32
    210   1.1  riastrad #define AMDGPUFB_CONN_LIMIT			4
    211   1.5  riastrad #define AMDGPU_BIOS_NUM_SCRATCH			16
    212   1.1  riastrad 
    213   1.1  riastrad /* hard reset data */
    214   1.1  riastrad #define AMDGPU_ASIC_RESET_DATA                  0x39d5e86b
    215   1.1  riastrad 
    216   1.1  riastrad /* reset flags */
    217   1.1  riastrad #define AMDGPU_RESET_GFX			(1 << 0)
    218   1.1  riastrad #define AMDGPU_RESET_COMPUTE			(1 << 1)
    219   1.1  riastrad #define AMDGPU_RESET_DMA			(1 << 2)
    220   1.1  riastrad #define AMDGPU_RESET_CP				(1 << 3)
    221   1.1  riastrad #define AMDGPU_RESET_GRBM			(1 << 4)
    222   1.1  riastrad #define AMDGPU_RESET_DMA1			(1 << 5)
    223   1.1  riastrad #define AMDGPU_RESET_RLC			(1 << 6)
    224   1.1  riastrad #define AMDGPU_RESET_SEM			(1 << 7)
    225   1.1  riastrad #define AMDGPU_RESET_IH				(1 << 8)
    226   1.1  riastrad #define AMDGPU_RESET_VMC			(1 << 9)
    227   1.1  riastrad #define AMDGPU_RESET_MC				(1 << 10)
    228   1.1  riastrad #define AMDGPU_RESET_DISPLAY			(1 << 11)
    229   1.1  riastrad #define AMDGPU_RESET_UVD			(1 << 12)
    230   1.1  riastrad #define AMDGPU_RESET_VCE			(1 << 13)
    231   1.1  riastrad #define AMDGPU_RESET_VCE1			(1 << 14)
    232   1.1  riastrad 
    233   1.1  riastrad /* max cursor sizes (in pixels) */
    234   1.1  riastrad #define CIK_CURSOR_WIDTH 128
    235   1.1  riastrad #define CIK_CURSOR_HEIGHT 128
    236   1.1  riastrad 
    237   1.1  riastrad struct amdgpu_device;
    238   1.1  riastrad struct amdgpu_ib;
    239   1.1  riastrad struct amdgpu_cs_parser;
    240   1.1  riastrad struct amdgpu_job;
    241   1.1  riastrad struct amdgpu_irq_src;
    242   1.1  riastrad struct amdgpu_fpriv;
    243   1.5  riastrad struct amdgpu_bo_va_mapping;
    244   1.5  riastrad struct amdgpu_atif;
    245   1.5  riastrad struct kfd_vm_fault_info;
    246   1.1  riastrad 
    247   1.1  riastrad enum amdgpu_cp_irq {
    248   1.5  riastrad 	AMDGPU_CP_IRQ_GFX_ME0_PIPE0_EOP = 0,
    249   1.5  riastrad 	AMDGPU_CP_IRQ_GFX_ME0_PIPE1_EOP,
    250   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
    251   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
    252   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
    253   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
    254   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
    255   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
    256   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
    257   1.1  riastrad 	AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
    258   1.1  riastrad 
    259   1.1  riastrad 	AMDGPU_CP_IRQ_LAST
    260   1.1  riastrad };
    261   1.1  riastrad 
    262   1.1  riastrad enum amdgpu_thermal_irq {
    263   1.1  riastrad 	AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
    264   1.1  riastrad 	AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
    265   1.1  riastrad 
    266   1.1  riastrad 	AMDGPU_THERMAL_IRQ_LAST
    267   1.1  riastrad };
    268   1.1  riastrad 
    269   1.5  riastrad enum amdgpu_kiq_irq {
    270   1.5  riastrad 	AMDGPU_CP_KIQ_IRQ_DRIVER0 = 0,
    271   1.5  riastrad 	AMDGPU_CP_KIQ_IRQ_LAST
    272   1.5  riastrad };
    273   1.5  riastrad 
    274   1.5  riastrad #define MAX_KIQ_REG_WAIT       5000 /* in usecs, 5ms */
    275   1.5  riastrad #define MAX_KIQ_REG_BAILOUT_INTERVAL   5 /* in msecs, 5ms */
    276   1.5  riastrad #define MAX_KIQ_REG_TRY 80 /* 20 -> 80 */
    277   1.5  riastrad 
    278   1.5  riastrad int amdgpu_device_ip_set_clockgating_state(void *dev,
    279   1.5  riastrad 					   enum amd_ip_block_type block_type,
    280   1.5  riastrad 					   enum amd_clockgating_state state);
    281   1.5  riastrad int amdgpu_device_ip_set_powergating_state(void *dev,
    282   1.5  riastrad 					   enum amd_ip_block_type block_type,
    283   1.5  riastrad 					   enum amd_powergating_state state);
    284   1.5  riastrad void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
    285   1.5  riastrad 					    u32 *flags);
    286   1.5  riastrad int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
    287   1.5  riastrad 				   enum amd_ip_block_type block_type);
    288   1.5  riastrad bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
    289   1.5  riastrad 			      enum amd_ip_block_type block_type);
    290   1.5  riastrad 
    291   1.5  riastrad #define AMDGPU_MAX_IP_NUM 16
    292   1.5  riastrad 
    293   1.5  riastrad struct amdgpu_ip_block_status {
    294   1.5  riastrad 	bool valid;
    295   1.5  riastrad 	bool sw;
    296   1.5  riastrad 	bool hw;
    297   1.5  riastrad 	bool late_initialized;
    298   1.5  riastrad 	bool hang;
    299   1.5  riastrad };
    300   1.1  riastrad 
    301   1.1  riastrad struct amdgpu_ip_block_version {
    302   1.5  riastrad 	const enum amd_ip_block_type type;
    303   1.5  riastrad 	const u32 major;
    304   1.5  riastrad 	const u32 minor;
    305   1.5  riastrad 	const u32 rev;
    306   1.1  riastrad 	const struct amd_ip_funcs *funcs;
    307   1.1  riastrad };
    308   1.1  riastrad 
    309   1.5  riastrad #define HW_REV(_Major, _Minor, _Rev) \
    310   1.5  riastrad 	((((uint32_t) (_Major)) << 16) | ((uint32_t) (_Minor) << 8) | ((uint32_t) (_Rev)))
    311   1.5  riastrad 
    312   1.5  riastrad struct amdgpu_ip_block {
    313   1.5  riastrad 	struct amdgpu_ip_block_status status;
    314   1.5  riastrad 	const struct amdgpu_ip_block_version *version;
    315   1.1  riastrad };
    316   1.1  riastrad 
    317   1.5  riastrad int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
    318   1.5  riastrad 				       enum amd_ip_block_type type,
    319   1.5  riastrad 				       u32 major, u32 minor);
    320   1.5  riastrad 
    321   1.5  riastrad struct amdgpu_ip_block *
    322   1.5  riastrad amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
    323   1.5  riastrad 			      enum amd_ip_block_type type);
    324   1.5  riastrad 
    325   1.5  riastrad int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
    326   1.5  riastrad 			       const struct amdgpu_ip_block_version *ip_block_version);
    327   1.5  riastrad 
    328   1.1  riastrad /*
    329   1.1  riastrad  * BIOS.
    330   1.1  riastrad  */
    331   1.1  riastrad bool amdgpu_get_bios(struct amdgpu_device *adev);
    332   1.1  riastrad bool amdgpu_read_bios(struct amdgpu_device *adev);
    333   1.1  riastrad 
    334   1.1  riastrad /*
    335   1.1  riastrad  * Clocks
    336   1.1  riastrad  */
    337   1.1  riastrad 
    338   1.1  riastrad #define AMDGPU_MAX_PPLL 3
    339   1.1  riastrad 
    340   1.1  riastrad struct amdgpu_clock {
    341   1.1  riastrad 	struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
    342   1.1  riastrad 	struct amdgpu_pll spll;
    343   1.1  riastrad 	struct amdgpu_pll mpll;
    344   1.1  riastrad 	/* 10 Khz units */
    345   1.1  riastrad 	uint32_t default_mclk;
    346   1.1  riastrad 	uint32_t default_sclk;
    347   1.1  riastrad 	uint32_t default_dispclk;
    348   1.1  riastrad 	uint32_t current_dispclk;
    349   1.1  riastrad 	uint32_t dp_extclk;
    350   1.1  riastrad 	uint32_t max_pixel_clock;
    351   1.1  riastrad };
    352   1.1  riastrad 
    353   1.1  riastrad /* sub-allocation manager, it has to be protected by another lock.
    354   1.1  riastrad  * By conception this is an helper for other part of the driver
    355   1.1  riastrad  * like the indirect buffer or semaphore, which both have their
    356   1.1  riastrad  * locking.
    357   1.1  riastrad  *
    358   1.1  riastrad  * Principe is simple, we keep a list of sub allocation in offset
    359   1.1  riastrad  * order (first entry has offset == 0, last entry has the highest
    360   1.1  riastrad  * offset).
    361   1.1  riastrad  *
    362   1.1  riastrad  * When allocating new object we first check if there is room at
    363   1.1  riastrad  * the end total_size - (last_object_offset + last_object_size) >=
    364   1.1  riastrad  * alloc_size. If so we allocate new object there.
    365   1.1  riastrad  *
    366   1.1  riastrad  * When there is not enough room at the end, we start waiting for
    367   1.1  riastrad  * each sub object until we reach object_offset+object_size >=
    368   1.1  riastrad  * alloc_size, this object then become the sub object we return.
    369   1.1  riastrad  *
    370   1.1  riastrad  * Alignment can't be bigger than page size.
    371   1.1  riastrad  *
    372   1.1  riastrad  * Hole are not considered for allocation to keep things simple.
    373   1.1  riastrad  * Assumption is that there won't be hole (all object on same
    374   1.1  riastrad  * alignment).
    375   1.1  riastrad  */
    376   1.5  riastrad 
    377   1.5  riastrad #define AMDGPU_SA_NUM_FENCE_LISTS	32
    378   1.5  riastrad 
    379   1.1  riastrad struct amdgpu_sa_manager {
    380   1.3  riastrad 	spinlock_t		wq_lock;
    381   1.3  riastrad 	drm_waitqueue_t		wq;
    382   1.1  riastrad 	struct amdgpu_bo	*bo;
    383   1.1  riastrad 	struct list_head	*hole;
    384   1.5  riastrad 	struct list_head	flist[AMDGPU_SA_NUM_FENCE_LISTS];
    385   1.1  riastrad 	struct list_head	olist;
    386   1.1  riastrad 	unsigned		size;
    387   1.1  riastrad 	uint64_t		gpu_addr;
    388   1.1  riastrad 	void			*cpu_ptr;
    389   1.1  riastrad 	uint32_t		domain;
    390   1.1  riastrad 	uint32_t		align;
    391   1.1  riastrad };
    392   1.1  riastrad 
    393   1.1  riastrad /* sub-allocation buffer */
    394   1.1  riastrad struct amdgpu_sa_bo {
    395   1.1  riastrad 	struct list_head		olist;
    396   1.1  riastrad 	struct list_head		flist;
    397   1.1  riastrad 	struct amdgpu_sa_manager	*manager;
    398   1.1  riastrad 	unsigned			soffset;
    399   1.1  riastrad 	unsigned			eoffset;
    400   1.5  riastrad 	struct dma_fence	        *fence;
    401   1.1  riastrad };
    402   1.1  riastrad 
    403   1.5  riastrad int amdgpu_fence_slab_init(void);
    404   1.5  riastrad void amdgpu_fence_slab_fini(void);
    405   1.1  riastrad 
    406   1.1  riastrad /*
    407   1.1  riastrad  * IRQS.
    408   1.1  riastrad  */
    409   1.1  riastrad 
    410   1.1  riastrad struct amdgpu_flip_work {
    411   1.5  riastrad 	struct delayed_work		flip_work;
    412   1.1  riastrad 	struct work_struct		unpin_work;
    413   1.1  riastrad 	struct amdgpu_device		*adev;
    414   1.1  riastrad 	int				crtc_id;
    415   1.5  riastrad 	u32				target_vblank;
    416   1.1  riastrad 	uint64_t			base;
    417   1.1  riastrad 	struct drm_pending_vblank_event *event;
    418   1.5  riastrad 	struct amdgpu_bo		*old_abo;
    419   1.5  riastrad 	struct dma_fence		*excl;
    420   1.1  riastrad 	unsigned			shared_count;
    421   1.5  riastrad 	struct dma_fence		**shared;
    422   1.5  riastrad 	struct dma_fence_cb		cb;
    423   1.5  riastrad 	bool				async;
    424   1.1  riastrad };
    425   1.1  riastrad 
    426   1.1  riastrad 
    427   1.1  riastrad /*
    428   1.1  riastrad  * CP & rings.
    429   1.1  riastrad  */
    430   1.1  riastrad 
    431   1.1  riastrad struct amdgpu_ib {
    432   1.1  riastrad 	struct amdgpu_sa_bo		*sa_bo;
    433   1.1  riastrad 	uint32_t			length_dw;
    434   1.1  riastrad 	uint64_t			gpu_addr;
    435   1.1  riastrad 	uint32_t			*ptr;
    436   1.1  riastrad 	uint32_t			flags;
    437   1.1  riastrad };
    438   1.1  riastrad 
    439   1.5  riastrad extern const struct drm_sched_backend_ops amdgpu_sched_ops;
    440   1.1  riastrad 
    441   1.1  riastrad /*
    442   1.1  riastrad  * file private structure
    443   1.1  riastrad  */
    444   1.1  riastrad 
    445   1.1  riastrad struct amdgpu_fpriv {
    446   1.1  riastrad 	struct amdgpu_vm	vm;
    447   1.5  riastrad 	struct amdgpu_bo_va	*prt_va;
    448   1.5  riastrad 	struct amdgpu_bo_va	*csa_va;
    449   1.1  riastrad 	struct mutex		bo_list_lock;
    450   1.1  riastrad 	struct idr		bo_list_handles;
    451   1.1  riastrad 	struct amdgpu_ctx_mgr	ctx_mgr;
    452   1.1  riastrad };
    453   1.1  riastrad 
    454   1.5  riastrad int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
    455   1.1  riastrad 
    456   1.5  riastrad int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
    457   1.1  riastrad 		  unsigned size, struct amdgpu_ib *ib);
    458   1.5  riastrad void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
    459   1.5  riastrad 		    struct dma_fence *f);
    460   1.5  riastrad int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
    461   1.5  riastrad 		       struct amdgpu_ib *ibs, struct amdgpu_job *job,
    462   1.5  riastrad 		       struct dma_fence **f);
    463   1.1  riastrad int amdgpu_ib_pool_init(struct amdgpu_device *adev);
    464   1.1  riastrad void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
    465   1.1  riastrad int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
    466   1.1  riastrad 
    467   1.1  riastrad /*
    468   1.1  riastrad  * CS.
    469   1.1  riastrad  */
    470   1.1  riastrad struct amdgpu_cs_chunk {
    471   1.1  riastrad 	uint32_t		chunk_id;
    472   1.1  riastrad 	uint32_t		length_dw;
    473   1.5  riastrad 	void			*kdata;
    474   1.5  riastrad };
    475   1.5  riastrad 
    476   1.5  riastrad struct amdgpu_cs_post_dep {
    477   1.5  riastrad 	struct drm_syncobj *syncobj;
    478   1.5  riastrad 	struct dma_fence_chain *chain;
    479   1.5  riastrad 	u64 point;
    480   1.1  riastrad };
    481   1.1  riastrad 
    482   1.1  riastrad struct amdgpu_cs_parser {
    483   1.1  riastrad 	struct amdgpu_device	*adev;
    484   1.1  riastrad 	struct drm_file		*filp;
    485   1.1  riastrad 	struct amdgpu_ctx	*ctx;
    486   1.5  riastrad 
    487   1.1  riastrad 	/* chunks */
    488   1.1  riastrad 	unsigned		nchunks;
    489   1.1  riastrad 	struct amdgpu_cs_chunk	*chunks;
    490   1.1  riastrad 
    491   1.5  riastrad 	/* scheduler job object */
    492   1.5  riastrad 	struct amdgpu_job	*job;
    493   1.5  riastrad 	struct drm_sched_entity	*entity;
    494   1.5  riastrad 
    495   1.5  riastrad 	/* buffer objects */
    496   1.5  riastrad 	struct ww_acquire_ctx		ticket;
    497   1.5  riastrad 	struct amdgpu_bo_list		*bo_list;
    498   1.5  riastrad 	struct amdgpu_mn		*mn;
    499   1.5  riastrad 	struct amdgpu_bo_list_entry	vm_pd;
    500   1.5  riastrad 	struct list_head		validated;
    501   1.5  riastrad 	struct dma_fence		*fence;
    502   1.5  riastrad 	uint64_t			bytes_moved_threshold;
    503   1.5  riastrad 	uint64_t			bytes_moved_vis_threshold;
    504   1.5  riastrad 	uint64_t			bytes_moved;
    505   1.5  riastrad 	uint64_t			bytes_moved_vis;
    506   1.1  riastrad 
    507   1.1  riastrad 	/* user fence */
    508   1.1  riastrad 	struct amdgpu_bo_list_entry	uf_entry;
    509   1.5  riastrad 
    510   1.5  riastrad 	unsigned			num_post_deps;
    511   1.5  riastrad 	struct amdgpu_cs_post_dep	*post_deps;
    512   1.1  riastrad };
    513   1.1  riastrad 
    514   1.5  riastrad static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
    515   1.5  riastrad 				      uint32_t ib_idx, int idx)
    516   1.5  riastrad {
    517   1.5  riastrad 	return p->job->ibs[ib_idx].ptr[idx];
    518   1.5  riastrad }
    519   1.1  riastrad 
    520   1.5  riastrad static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
    521   1.5  riastrad 				       uint32_t ib_idx, int idx,
    522   1.5  riastrad 				       uint32_t value)
    523   1.1  riastrad {
    524   1.5  riastrad 	p->job->ibs[ib_idx].ptr[idx] = value;
    525   1.1  riastrad }
    526   1.1  riastrad 
    527   1.1  riastrad /*
    528   1.1  riastrad  * Writeback
    529   1.1  riastrad  */
    530   1.5  riastrad #define AMDGPU_MAX_WB 128	/* Reserve at most 128 WB slots for amdgpu-owned rings. */
    531   1.1  riastrad 
    532   1.1  riastrad struct amdgpu_wb {
    533   1.1  riastrad 	struct amdgpu_bo	*wb_obj;
    534   1.1  riastrad 	volatile uint32_t	*wb;
    535   1.1  riastrad 	uint64_t		gpu_addr;
    536   1.1  riastrad 	u32			num_wb;	/* Number of wb slots actually reserved for amdgpu. */
    537   1.3  riastrad 	unsigned long		used[DIV_ROUND_UP(AMDGPU_MAX_WB, NBBY*sizeof(unsigned long))];
    538   1.1  riastrad };
    539   1.1  riastrad 
    540   1.5  riastrad int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb);
    541   1.5  riastrad void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb);
    542   1.1  riastrad 
    543   1.1  riastrad /*
    544   1.1  riastrad  * Benchmarking
    545   1.1  riastrad  */
    546   1.1  riastrad void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
    547   1.1  riastrad 
    548   1.1  riastrad 
    549   1.1  riastrad /*
    550   1.1  riastrad  * Testing
    551   1.1  riastrad  */
    552   1.1  riastrad void amdgpu_test_moves(struct amdgpu_device *adev);
    553   1.1  riastrad 
    554   1.1  riastrad /*
    555   1.1  riastrad  * ASIC specific register table accessible by UMD
    556   1.1  riastrad  */
    557   1.1  riastrad struct amdgpu_allowed_register_entry {
    558   1.1  riastrad 	uint32_t reg_offset;
    559   1.1  riastrad 	bool grbm_indexed;
    560   1.1  riastrad };
    561   1.1  riastrad 
    562   1.5  riastrad enum amd_reset_method {
    563   1.5  riastrad 	AMD_RESET_METHOD_LEGACY = 0,
    564   1.5  riastrad 	AMD_RESET_METHOD_MODE0,
    565   1.5  riastrad 	AMD_RESET_METHOD_MODE1,
    566   1.5  riastrad 	AMD_RESET_METHOD_MODE2,
    567   1.5  riastrad 	AMD_RESET_METHOD_BACO
    568   1.1  riastrad };
    569   1.1  riastrad 
    570   1.1  riastrad /*
    571   1.1  riastrad  * ASIC specific functions.
    572   1.1  riastrad  */
    573   1.1  riastrad struct amdgpu_asic_funcs {
    574   1.1  riastrad 	bool (*read_disabled_bios)(struct amdgpu_device *adev);
    575   1.5  riastrad 	bool (*read_bios_from_rom)(struct amdgpu_device *adev,
    576   1.5  riastrad 				   u8 *bios, u32 length_bytes);
    577   1.1  riastrad 	int (*read_register)(struct amdgpu_device *adev, u32 se_num,
    578   1.1  riastrad 			     u32 sh_num, u32 reg_offset, u32 *value);
    579   1.1  riastrad 	void (*set_vga_state)(struct amdgpu_device *adev, bool state);
    580   1.1  riastrad 	int (*reset)(struct amdgpu_device *adev);
    581   1.5  riastrad 	enum amd_reset_method (*reset_method)(struct amdgpu_device *adev);
    582   1.1  riastrad 	/* get the reference clock */
    583   1.1  riastrad 	u32 (*get_xclk)(struct amdgpu_device *adev);
    584   1.1  riastrad 	/* MM block clocks */
    585   1.1  riastrad 	int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
    586   1.1  riastrad 	int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
    587   1.5  riastrad 	/* static power management */
    588   1.5  riastrad 	int (*get_pcie_lanes)(struct amdgpu_device *adev);
    589   1.5  riastrad 	void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes);
    590   1.5  riastrad 	/* get config memsize register */
    591   1.5  riastrad 	u32 (*get_config_memsize)(struct amdgpu_device *adev);
    592   1.5  riastrad 	/* flush hdp write queue */
    593   1.5  riastrad 	void (*flush_hdp)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
    594   1.5  riastrad 	/* invalidate hdp read cache */
    595   1.5  riastrad 	void (*invalidate_hdp)(struct amdgpu_device *adev,
    596   1.5  riastrad 			       struct amdgpu_ring *ring);
    597   1.5  riastrad 	/* check if the asic needs a full reset of if soft reset will work */
    598   1.5  riastrad 	bool (*need_full_reset)(struct amdgpu_device *adev);
    599   1.5  riastrad 	/* initialize doorbell layout for specific asic*/
    600   1.5  riastrad 	void (*init_doorbell_index)(struct amdgpu_device *adev);
    601   1.5  riastrad 	/* PCIe bandwidth usage */
    602   1.5  riastrad 	void (*get_pcie_usage)(struct amdgpu_device *adev, uint64_t *count0,
    603   1.5  riastrad 			       uint64_t *count1);
    604   1.5  riastrad 	/* do we need to reset the asic at init time (e.g., kexec) */
    605   1.5  riastrad 	bool (*need_reset_on_init)(struct amdgpu_device *adev);
    606   1.5  riastrad 	/* PCIe replay counter */
    607   1.5  riastrad 	uint64_t (*get_pcie_replay_count)(struct amdgpu_device *adev);
    608   1.5  riastrad 	/* device supports BACO */
    609   1.5  riastrad 	bool (*supports_baco)(struct amdgpu_device *adev);
    610   1.1  riastrad };
    611   1.1  riastrad 
    612   1.1  riastrad /*
    613   1.1  riastrad  * IOCTL.
    614   1.1  riastrad  */
    615   1.1  riastrad int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
    616   1.1  riastrad 				struct drm_file *filp);
    617   1.1  riastrad 
    618   1.1  riastrad int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
    619   1.5  riastrad int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data,
    620   1.5  riastrad 				    struct drm_file *filp);
    621   1.1  riastrad int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
    622   1.5  riastrad int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
    623   1.1  riastrad 				struct drm_file *filp);
    624   1.1  riastrad 
    625   1.1  riastrad /* VRAM scratch page for HDP bug, default vram page */
    626   1.1  riastrad struct amdgpu_vram_scratch {
    627   1.1  riastrad 	struct amdgpu_bo		*robj;
    628   1.1  riastrad 	volatile uint32_t		*ptr;
    629   1.1  riastrad 	u64				gpu_addr;
    630   1.1  riastrad };
    631   1.1  riastrad 
    632   1.1  riastrad /*
    633   1.1  riastrad  * ACPI
    634   1.1  riastrad  */
    635   1.1  riastrad struct amdgpu_atcs_functions {
    636   1.1  riastrad 	bool get_ext_state;
    637   1.1  riastrad 	bool pcie_perf_req;
    638   1.1  riastrad 	bool pcie_dev_rdy;
    639   1.1  riastrad 	bool pcie_bus_width;
    640   1.1  riastrad };
    641   1.1  riastrad 
    642   1.1  riastrad struct amdgpu_atcs {
    643   1.1  riastrad 	struct amdgpu_atcs_functions functions;
    644   1.1  riastrad };
    645   1.1  riastrad 
    646   1.1  riastrad /*
    647   1.5  riastrad  * Firmware VRAM reservation
    648   1.5  riastrad  */
    649   1.5  riastrad struct amdgpu_fw_vram_usage {
    650   1.5  riastrad 	u64 start_offset;
    651   1.5  riastrad 	u64 size;
    652   1.5  riastrad 	struct amdgpu_bo *reserved_bo;
    653   1.5  riastrad 	void *va;
    654   1.5  riastrad 
    655   1.5  riastrad 	/* GDDR6 training support flag.
    656   1.5  riastrad 	*/
    657   1.5  riastrad 	bool mem_train_support;
    658   1.5  riastrad };
    659   1.5  riastrad 
    660   1.5  riastrad /*
    661   1.1  riastrad  * CGS
    662   1.1  riastrad  */
    663   1.5  riastrad struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
    664   1.5  riastrad void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
    665   1.1  riastrad 
    666   1.1  riastrad /*
    667   1.1  riastrad  * Core structure, functions and helpers.
    668   1.1  riastrad  */
    669   1.1  riastrad typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
    670   1.1  riastrad typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
    671   1.1  riastrad 
    672   1.5  riastrad typedef uint64_t (*amdgpu_rreg64_t)(struct amdgpu_device*, uint32_t);
    673   1.5  riastrad typedef void (*amdgpu_wreg64_t)(struct amdgpu_device*, uint32_t, uint64_t);
    674   1.5  riastrad 
    675   1.1  riastrad typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
    676   1.1  riastrad typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
    677   1.1  riastrad 
    678   1.5  riastrad struct amdgpu_mmio_remap {
    679   1.5  riastrad 	u32 reg_offset;
    680   1.5  riastrad 	resource_size_t bus_addr;
    681   1.5  riastrad };
    682   1.5  riastrad 
    683   1.5  riastrad /* Define the HW IP blocks will be used in driver , add more if necessary */
    684   1.5  riastrad enum amd_hw_ip_block_type {
    685   1.5  riastrad 	GC_HWIP = 1,
    686   1.5  riastrad 	HDP_HWIP,
    687   1.5  riastrad 	SDMA0_HWIP,
    688   1.5  riastrad 	SDMA1_HWIP,
    689   1.5  riastrad 	SDMA2_HWIP,
    690   1.5  riastrad 	SDMA3_HWIP,
    691   1.5  riastrad 	SDMA4_HWIP,
    692   1.5  riastrad 	SDMA5_HWIP,
    693   1.5  riastrad 	SDMA6_HWIP,
    694   1.5  riastrad 	SDMA7_HWIP,
    695   1.5  riastrad 	MMHUB_HWIP,
    696   1.5  riastrad 	ATHUB_HWIP,
    697   1.5  riastrad 	NBIO_HWIP,
    698   1.5  riastrad 	MP0_HWIP,
    699   1.5  riastrad 	MP1_HWIP,
    700   1.5  riastrad 	UVD_HWIP,
    701   1.5  riastrad 	VCN_HWIP = UVD_HWIP,
    702   1.5  riastrad 	JPEG_HWIP = VCN_HWIP,
    703   1.5  riastrad 	VCE_HWIP,
    704   1.5  riastrad 	DF_HWIP,
    705   1.5  riastrad 	DCE_HWIP,
    706   1.5  riastrad 	OSSSYS_HWIP,
    707   1.5  riastrad 	SMUIO_HWIP,
    708   1.5  riastrad 	PWR_HWIP,
    709   1.5  riastrad 	NBIF_HWIP,
    710   1.5  riastrad 	THM_HWIP,
    711   1.5  riastrad 	CLK_HWIP,
    712   1.5  riastrad 	UMC_HWIP,
    713   1.5  riastrad 	RSMU_HWIP,
    714   1.5  riastrad 	MAX_HWIP
    715   1.5  riastrad };
    716   1.5  riastrad 
    717   1.5  riastrad #define HWIP_MAX_INSTANCE	8
    718   1.5  riastrad 
    719   1.5  riastrad struct amd_powerplay {
    720   1.5  riastrad 	void *pp_handle;
    721   1.5  riastrad 	const struct amd_pm_funcs *pp_funcs;
    722   1.1  riastrad };
    723   1.1  riastrad 
    724   1.5  riastrad #define AMDGPU_RESET_MAGIC_NUM 64
    725   1.5  riastrad #define AMDGPU_MAX_DF_PERFMONS 4
    726   1.1  riastrad struct amdgpu_device {
    727   1.1  riastrad 	struct device			*dev;
    728   1.1  riastrad 	struct drm_device		*ddev;
    729   1.1  riastrad 	struct pci_dev			*pdev;
    730   1.1  riastrad 
    731   1.5  riastrad #ifdef CONFIG_DRM_AMD_ACP
    732   1.5  riastrad 	struct amdgpu_acp		acp;
    733   1.5  riastrad #endif
    734   1.5  riastrad 
    735   1.1  riastrad 	/* ASIC */
    736   1.1  riastrad 	enum amd_asic_type		asic_type;
    737   1.1  riastrad 	uint32_t			family;
    738   1.1  riastrad 	uint32_t			rev_id;
    739   1.1  riastrad 	uint32_t			external_rev_id;
    740   1.1  riastrad 	unsigned long			flags;
    741   1.1  riastrad 	int				usec_timeout;
    742   1.1  riastrad 	const struct amdgpu_asic_funcs	*asic_funcs;
    743   1.1  riastrad 	bool				shutdown;
    744   1.5  riastrad 	bool				need_swiotlb;
    745   1.1  riastrad 	bool				accel_working;
    746   1.1  riastrad 	struct notifier_block		acpi_nb;
    747   1.1  riastrad 	struct amdgpu_i2c_chan		*i2c_bus[AMDGPU_MAX_I2C_BUS];
    748   1.1  riastrad 	struct amdgpu_debugfs		debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
    749   1.5  riastrad 	unsigned			debugfs_count;
    750   1.1  riastrad #if defined(CONFIG_DEBUG_FS)
    751   1.5  riastrad 	struct dentry                   *debugfs_preempt;
    752   1.5  riastrad 	struct dentry			*debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
    753   1.1  riastrad #endif
    754   1.5  riastrad 	struct amdgpu_atif		*atif;
    755   1.1  riastrad 	struct amdgpu_atcs		atcs;
    756   1.1  riastrad 	struct mutex			srbm_mutex;
    757   1.1  riastrad 	/* GRBM index mutex. Protects concurrent access to GRBM index */
    758   1.1  riastrad 	struct mutex                    grbm_idx_mutex;
    759   1.1  riastrad 	struct dev_pm_domain		vga_pm_domain;
    760   1.1  riastrad 	bool				have_disp_power_ref;
    761   1.5  riastrad 	bool                            have_atomics_support;
    762   1.1  riastrad 
    763   1.1  riastrad 	/* BIOS */
    764   1.5  riastrad 	bool				is_atom_fw;
    765   1.1  riastrad 	uint8_t				*bios;
    766   1.5  riastrad 	uint32_t			bios_size;
    767   1.5  riastrad 	struct amdgpu_bo		*stolen_vga_memory;
    768   1.5  riastrad 	struct amdgpu_bo		*discovery_memory;
    769   1.5  riastrad 	uint32_t			bios_scratch_reg_offset;
    770   1.1  riastrad 	uint32_t			bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
    771   1.1  riastrad 
    772   1.1  riastrad 	/* Register/doorbell mmio */
    773   1.3  riastrad #ifdef __NetBSD__
    774   1.3  riastrad 	bus_space_tag_t			rmmiot;
    775   1.3  riastrad 	bus_space_handle_t		rmmioh;
    776   1.3  riastrad 	bus_addr_t			rmmio_base;
    777   1.3  riastrad 	bus_size_t			rmmio_size;
    778   1.3  riastrad #else
    779   1.1  riastrad 	resource_size_t			rmmio_base;
    780   1.1  riastrad 	resource_size_t			rmmio_size;
    781   1.1  riastrad 	void __iomem			*rmmio;
    782   1.3  riastrad #endif
    783   1.1  riastrad 	/* protects concurrent MM_INDEX/DATA based register access */
    784   1.1  riastrad 	spinlock_t mmio_idx_lock;
    785   1.5  riastrad 	struct amdgpu_mmio_remap        rmmio_remap;
    786   1.1  riastrad 	/* protects concurrent SMC based register access */
    787   1.1  riastrad 	spinlock_t smc_idx_lock;
    788   1.1  riastrad 	amdgpu_rreg_t			smc_rreg;
    789   1.1  riastrad 	amdgpu_wreg_t			smc_wreg;
    790   1.1  riastrad 	/* protects concurrent PCIE register access */
    791   1.1  riastrad 	spinlock_t pcie_idx_lock;
    792   1.1  riastrad 	amdgpu_rreg_t			pcie_rreg;
    793   1.1  riastrad 	amdgpu_wreg_t			pcie_wreg;
    794   1.5  riastrad 	amdgpu_rreg_t			pciep_rreg;
    795   1.5  riastrad 	amdgpu_wreg_t			pciep_wreg;
    796   1.5  riastrad 	amdgpu_rreg64_t			pcie_rreg64;
    797   1.5  riastrad 	amdgpu_wreg64_t			pcie_wreg64;
    798   1.1  riastrad 	/* protects concurrent UVD register access */
    799   1.1  riastrad 	spinlock_t uvd_ctx_idx_lock;
    800   1.1  riastrad 	amdgpu_rreg_t			uvd_ctx_rreg;
    801   1.1  riastrad 	amdgpu_wreg_t			uvd_ctx_wreg;
    802   1.1  riastrad 	/* protects concurrent DIDT register access */
    803   1.1  riastrad 	spinlock_t didt_idx_lock;
    804   1.1  riastrad 	amdgpu_rreg_t			didt_rreg;
    805   1.1  riastrad 	amdgpu_wreg_t			didt_wreg;
    806   1.5  riastrad 	/* protects concurrent gc_cac register access */
    807   1.5  riastrad 	spinlock_t gc_cac_idx_lock;
    808   1.5  riastrad 	amdgpu_rreg_t			gc_cac_rreg;
    809   1.5  riastrad 	amdgpu_wreg_t			gc_cac_wreg;
    810   1.5  riastrad 	/* protects concurrent se_cac register access */
    811   1.5  riastrad 	spinlock_t se_cac_idx_lock;
    812   1.5  riastrad 	amdgpu_rreg_t			se_cac_rreg;
    813   1.5  riastrad 	amdgpu_wreg_t			se_cac_wreg;
    814   1.1  riastrad 	/* protects concurrent ENDPOINT (audio) register access */
    815   1.1  riastrad 	spinlock_t audio_endpt_idx_lock;
    816   1.1  riastrad 	amdgpu_block_rreg_t		audio_endpt_rreg;
    817   1.1  riastrad 	amdgpu_block_wreg_t		audio_endpt_wreg;
    818   1.3  riastrad #ifdef __NetBSD__
    819   1.3  riastrad 	bus_space_tag_t			rio_memt;
    820   1.3  riastrad 	bus_space_handle_t		rio_memh;
    821   1.3  riastrad 	bus_size_t			rio_mem_size;
    822   1.3  riastrad #else
    823   1.1  riastrad 	void __iomem                    *rio_mem;
    824   1.1  riastrad 	resource_size_t			rio_mem_size;
    825   1.3  riastrad #endif
    826   1.1  riastrad 	struct amdgpu_doorbell		doorbell;
    827   1.1  riastrad 
    828   1.1  riastrad 	/* clock/pll info */
    829   1.1  riastrad 	struct amdgpu_clock            clock;
    830   1.1  riastrad 
    831   1.1  riastrad 	/* MC */
    832   1.5  riastrad 	struct amdgpu_gmc		gmc;
    833   1.1  riastrad 	struct amdgpu_gart		gart;
    834   1.5  riastrad #ifdef __NetBSD__
    835   1.5  riastrad 	bus_dma_segment_t		dummy_page_seg;
    836   1.5  riastrad 	bus_dmamap_t			dummy_page_map;
    837   1.5  riastrad #endif
    838   1.5  riastrad 	dma_addr_t			dummy_page_addr;
    839   1.1  riastrad 	struct amdgpu_vm_manager	vm_manager;
    840   1.5  riastrad 	struct amdgpu_vmhub             vmhub[AMDGPU_MAX_VMHUBS];
    841   1.5  riastrad 	unsigned			num_vmhubs;
    842   1.1  riastrad 
    843   1.1  riastrad 	/* memory management */
    844   1.1  riastrad 	struct amdgpu_mman		mman;
    845   1.1  riastrad 	struct amdgpu_vram_scratch	vram_scratch;
    846   1.1  riastrad 	struct amdgpu_wb		wb;
    847   1.1  riastrad 	atomic64_t			num_bytes_moved;
    848   1.5  riastrad 	atomic64_t			num_evictions;
    849   1.5  riastrad 	atomic64_t			num_vram_cpu_page_faults;
    850   1.1  riastrad 	atomic_t			gpu_reset_counter;
    851   1.5  riastrad 	atomic_t			vram_lost_counter;
    852   1.5  riastrad 
    853   1.5  riastrad 	/* data for buffer migration throttling */
    854   1.5  riastrad 	struct {
    855   1.5  riastrad 		spinlock_t		lock;
    856   1.5  riastrad 		s64			last_update_us;
    857   1.5  riastrad 		s64			accum_us; /* accumulated microseconds */
    858   1.5  riastrad 		s64			accum_us_vis; /* for visible VRAM */
    859   1.5  riastrad 		u32			log2_max_MBps;
    860   1.5  riastrad 	} mm_stats;
    861   1.1  riastrad 
    862   1.1  riastrad 	/* display */
    863   1.5  riastrad 	bool				enable_virtual_display;
    864   1.1  riastrad 	struct amdgpu_mode_info		mode_info;
    865   1.5  riastrad 	/* For pre-DCE11. DCE11 and later are in "struct amdgpu_device->dm" */
    866   1.1  riastrad 	struct work_struct		hotplug_work;
    867   1.1  riastrad 	struct amdgpu_irq_src		crtc_irq;
    868   1.5  riastrad 	struct amdgpu_irq_src		vupdate_irq;
    869   1.1  riastrad 	struct amdgpu_irq_src		pageflip_irq;
    870   1.1  riastrad 	struct amdgpu_irq_src		hpd_irq;
    871   1.1  riastrad 
    872   1.1  riastrad 	/* rings */
    873   1.5  riastrad 	u64				fence_context;
    874   1.1  riastrad 	unsigned			num_rings;
    875   1.1  riastrad 	struct amdgpu_ring		*rings[AMDGPU_MAX_RINGS];
    876   1.1  riastrad 	bool				ib_pool_ready;
    877   1.1  riastrad 	struct amdgpu_sa_manager	ring_tmp_bo;
    878   1.1  riastrad 
    879   1.1  riastrad 	/* interrupts */
    880   1.1  riastrad 	struct amdgpu_irq		irq;
    881   1.1  riastrad 
    882   1.5  riastrad 	/* powerplay */
    883   1.5  riastrad 	struct amd_powerplay		powerplay;
    884   1.5  riastrad 	bool				pp_force_state_enabled;
    885   1.5  riastrad 
    886   1.5  riastrad 	/* smu */
    887   1.5  riastrad 	struct smu_context		smu;
    888   1.5  riastrad 
    889   1.1  riastrad 	/* dpm */
    890   1.1  riastrad 	struct amdgpu_pm		pm;
    891   1.1  riastrad 	u32				cg_flags;
    892   1.1  riastrad 	u32				pg_flags;
    893   1.1  riastrad 
    894   1.5  riastrad 	/* nbio */
    895   1.5  riastrad 	struct amdgpu_nbio		nbio;
    896   1.5  riastrad 
    897   1.5  riastrad 	/* mmhub */
    898   1.5  riastrad 	struct amdgpu_mmhub		mmhub;
    899   1.1  riastrad 
    900   1.1  riastrad 	/* gfx */
    901   1.1  riastrad 	struct amdgpu_gfx		gfx;
    902   1.1  riastrad 
    903   1.1  riastrad 	/* sdma */
    904   1.1  riastrad 	struct amdgpu_sdma		sdma;
    905   1.1  riastrad 
    906   1.1  riastrad 	/* uvd */
    907   1.1  riastrad 	struct amdgpu_uvd		uvd;
    908   1.1  riastrad 
    909   1.1  riastrad 	/* vce */
    910   1.1  riastrad 	struct amdgpu_vce		vce;
    911   1.1  riastrad 
    912   1.5  riastrad 	/* vcn */
    913   1.5  riastrad 	struct amdgpu_vcn		vcn;
    914   1.5  riastrad 
    915   1.5  riastrad 	/* jpeg */
    916   1.5  riastrad 	struct amdgpu_jpeg		jpeg;
    917   1.5  riastrad 
    918   1.1  riastrad 	/* firmwares */
    919   1.1  riastrad 	struct amdgpu_firmware		firmware;
    920   1.1  riastrad 
    921   1.5  riastrad 	/* PSP */
    922   1.5  riastrad 	struct psp_context		psp;
    923   1.5  riastrad 
    924   1.1  riastrad 	/* GDS */
    925   1.1  riastrad 	struct amdgpu_gds		gds;
    926   1.1  riastrad 
    927   1.5  riastrad 	/* KFD */
    928   1.5  riastrad 	struct amdgpu_kfd_dev		kfd;
    929   1.5  riastrad 
    930   1.5  riastrad 	/* UMC */
    931   1.5  riastrad 	struct amdgpu_umc		umc;
    932   1.5  riastrad 
    933   1.5  riastrad 	/* display related functionality */
    934   1.5  riastrad 	struct amdgpu_display_manager dm;
    935   1.5  riastrad 
    936   1.5  riastrad 	/* discovery */
    937   1.5  riastrad 	uint8_t				*discovery;
    938   1.5  riastrad 
    939   1.5  riastrad 	/* mes */
    940   1.5  riastrad 	bool                            enable_mes;
    941   1.5  riastrad 	struct amdgpu_mes               mes;
    942   1.5  riastrad 
    943   1.5  riastrad 	/* df */
    944   1.5  riastrad 	struct amdgpu_df                df;
    945   1.5  riastrad 
    946   1.5  riastrad 	struct amdgpu_ip_block          ip_blocks[AMDGPU_MAX_IP_NUM];
    947   1.1  riastrad 	int				num_ip_blocks;
    948   1.1  riastrad 	struct mutex	mn_lock;
    949   1.1  riastrad 	DECLARE_HASHTABLE(mn_hash, 7);
    950   1.1  riastrad 
    951   1.1  riastrad 	/* tracking pinned memory */
    952   1.5  riastrad 	atomic64_t vram_pin_size;
    953   1.5  riastrad 	atomic64_t visible_pin_size;
    954   1.5  riastrad 	atomic64_t gart_pin_size;
    955   1.5  riastrad 
    956   1.5  riastrad 	/* soc15 register offset based on ip, instance and  segment */
    957   1.7  riastrad 	const uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
    958   1.5  riastrad 
    959   1.5  riastrad 	/* delayed work_func for deferring clockgating during resume */
    960   1.5  riastrad 	struct delayed_work     delayed_init_work;
    961   1.5  riastrad 
    962   1.5  riastrad 	struct amdgpu_virt	virt;
    963   1.5  riastrad 	/* firmware VRAM reservation */
    964   1.5  riastrad 	struct amdgpu_fw_vram_usage fw_vram_usage;
    965   1.5  riastrad 
    966   1.5  riastrad 	/* link all shadow bo */
    967   1.5  riastrad 	struct list_head                shadow_list;
    968   1.5  riastrad 	struct mutex                    shadow_list_lock;
    969   1.5  riastrad 	/* keep an lru list of rings by HW IP */
    970   1.5  riastrad 	struct list_head		ring_lru_list;
    971   1.5  riastrad 	spinlock_t			ring_lru_list_lock;
    972   1.5  riastrad 
    973   1.5  riastrad 	/* record hw reset is performed */
    974   1.5  riastrad 	bool has_hw_reset;
    975   1.5  riastrad 	u8				reset_magic[AMDGPU_RESET_MAGIC_NUM];
    976   1.5  riastrad 
    977   1.5  riastrad 	/* s3/s4 mask */
    978   1.5  riastrad 	bool                            in_suspend;
    979   1.5  riastrad 
    980   1.5  riastrad 	/* record last mm index being written through WREG32*/
    981   1.5  riastrad 	unsigned long last_mm_index;
    982   1.5  riastrad 	bool                            in_gpu_reset;
    983   1.5  riastrad 	enum pp_mp1_state               mp1_state;
    984   1.5  riastrad 	struct mutex  lock_reset;
    985   1.5  riastrad 	struct amdgpu_doorbell_index doorbell_index;
    986   1.5  riastrad 
    987   1.5  riastrad 	struct mutex			notifier_lock;
    988   1.1  riastrad 
    989   1.5  riastrad 	int asic_reset_res;
    990   1.5  riastrad 	struct work_struct		xgmi_reset_work;
    991   1.1  riastrad 
    992   1.5  riastrad 	long				gfx_timeout;
    993   1.5  riastrad 	long				sdma_timeout;
    994   1.5  riastrad 	long				video_timeout;
    995   1.5  riastrad 	long				compute_timeout;
    996   1.5  riastrad 
    997   1.5  riastrad 	uint64_t			unique_id;
    998   1.5  riastrad 	uint64_t	df_perfmon_config_assign_mask[AMDGPU_MAX_DF_PERFMONS];
    999   1.5  riastrad 
   1000   1.5  riastrad 	/* device pstate */
   1001   1.5  riastrad 	int				pstate;
   1002   1.5  riastrad 	/* enable runtime pm on the device */
   1003   1.5  riastrad 	bool                            runpm;
   1004   1.5  riastrad 
   1005   1.5  riastrad 	bool                            pm_sysfs_en;
   1006   1.5  riastrad 	bool                            ucode_sysfs_en;
   1007   1.1  riastrad };
   1008   1.1  riastrad 
   1009   1.5  riastrad static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
   1010   1.5  riastrad {
   1011   1.5  riastrad 	return container_of(bdev, struct amdgpu_device, mman.bdev);
   1012   1.5  riastrad }
   1013   1.5  riastrad 
   1014   1.1  riastrad int amdgpu_device_init(struct amdgpu_device *adev,
   1015   1.1  riastrad 		       struct drm_device *ddev,
   1016   1.1  riastrad 		       struct pci_dev *pdev,
   1017   1.1  riastrad 		       uint32_t flags);
   1018   1.1  riastrad void amdgpu_device_fini(struct amdgpu_device *adev);
   1019   1.1  riastrad int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
   1020   1.1  riastrad 
   1021   1.5  riastrad void amdgpu_device_vram_access(struct amdgpu_device *adev, loff_t pos,
   1022   1.5  riastrad 			       uint32_t *buf, size_t size, bool write);
   1023   1.1  riastrad uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
   1024   1.5  riastrad 			uint32_t acc_flags);
   1025   1.1  riastrad void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
   1026   1.5  riastrad 		    uint32_t acc_flags);
   1027   1.5  riastrad void amdgpu_mm_wreg8(struct amdgpu_device *adev, uint32_t offset, uint8_t value);
   1028   1.5  riastrad uint8_t amdgpu_mm_rreg8(struct amdgpu_device *adev, uint32_t offset);
   1029   1.5  riastrad 
   1030   1.1  riastrad u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
   1031   1.1  riastrad void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
   1032   1.1  riastrad 
   1033   1.5  riastrad bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type);
   1034   1.5  riastrad bool amdgpu_device_has_dc_support(struct amdgpu_device *adev);
   1035   1.1  riastrad 
   1036   1.5  riastrad int emu_soc_asic_init(struct amdgpu_device *adev);
   1037   1.1  riastrad 
   1038   1.1  riastrad /*
   1039   1.1  riastrad  * Registers read & write functions.
   1040   1.1  riastrad  */
   1041   1.5  riastrad 
   1042   1.5  riastrad #define AMDGPU_REGS_IDX       (1<<0)
   1043   1.5  riastrad #define AMDGPU_REGS_NO_KIQ    (1<<1)
   1044   1.5  riastrad #define AMDGPU_REGS_KIQ       (1<<2)
   1045   1.5  riastrad 
   1046   1.5  riastrad #define RREG32_NO_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_NO_KIQ)
   1047   1.5  riastrad #define WREG32_NO_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_NO_KIQ)
   1048   1.5  riastrad 
   1049   1.5  riastrad #define RREG32_KIQ(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_KIQ)
   1050   1.5  riastrad #define WREG32_KIQ(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_KIQ)
   1051   1.5  riastrad 
   1052   1.5  riastrad #define RREG8(reg) amdgpu_mm_rreg8(adev, (reg))
   1053   1.5  riastrad #define WREG8(reg, v) amdgpu_mm_wreg8(adev, (reg), (v))
   1054   1.5  riastrad 
   1055   1.5  riastrad #define RREG32(reg) amdgpu_mm_rreg(adev, (reg), 0)
   1056   1.5  riastrad #define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), AMDGPU_REGS_IDX)
   1057   1.5  riastrad #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), 0))
   1058   1.5  riastrad #define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), 0)
   1059   1.5  riastrad #define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), AMDGPU_REGS_IDX)
   1060   1.1  riastrad #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
   1061   1.1  riastrad #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
   1062   1.1  riastrad #define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
   1063   1.1  riastrad #define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
   1064   1.5  riastrad #define RREG32_PCIE_PORT(reg) adev->pciep_rreg(adev, (reg))
   1065   1.5  riastrad #define WREG32_PCIE_PORT(reg, v) adev->pciep_wreg(adev, (reg), (v))
   1066   1.5  riastrad #define RREG64_PCIE(reg) adev->pcie_rreg64(adev, (reg))
   1067   1.5  riastrad #define WREG64_PCIE(reg, v) adev->pcie_wreg64(adev, (reg), (v))
   1068   1.1  riastrad #define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
   1069   1.1  riastrad #define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
   1070   1.1  riastrad #define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
   1071   1.1  riastrad #define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
   1072   1.1  riastrad #define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
   1073   1.1  riastrad #define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
   1074   1.5  riastrad #define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
   1075   1.5  riastrad #define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
   1076   1.5  riastrad #define RREG32_SE_CAC(reg) adev->se_cac_rreg(adev, (reg))
   1077   1.5  riastrad #define WREG32_SE_CAC(reg, v) adev->se_cac_wreg(adev, (reg), (v))
   1078   1.1  riastrad #define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
   1079   1.1  riastrad #define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
   1080   1.1  riastrad #define WREG32_P(reg, val, mask)				\
   1081   1.1  riastrad 	do {							\
   1082   1.1  riastrad 		uint32_t tmp_ = RREG32(reg);			\
   1083   1.1  riastrad 		tmp_ &= (mask);					\
   1084   1.1  riastrad 		tmp_ |= ((val) & ~(mask));			\
   1085   1.1  riastrad 		WREG32(reg, tmp_);				\
   1086   1.1  riastrad 	} while (0)
   1087   1.1  riastrad #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
   1088   1.1  riastrad #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
   1089   1.1  riastrad #define WREG32_PLL_P(reg, val, mask)				\
   1090   1.1  riastrad 	do {							\
   1091   1.1  riastrad 		uint32_t tmp_ = RREG32_PLL(reg);		\
   1092   1.1  riastrad 		tmp_ &= (mask);					\
   1093   1.1  riastrad 		tmp_ |= ((val) & ~(mask));			\
   1094   1.1  riastrad 		WREG32_PLL(reg, tmp_);				\
   1095   1.1  riastrad 	} while (0)
   1096   1.1  riastrad #define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
   1097   1.1  riastrad #define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
   1098   1.1  riastrad #define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
   1099   1.1  riastrad 
   1100   1.1  riastrad #define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
   1101   1.1  riastrad #define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
   1102   1.1  riastrad 
   1103   1.1  riastrad #define REG_SET_FIELD(orig_val, reg, field, field_val)			\
   1104   1.1  riastrad 	(((orig_val) & ~REG_FIELD_MASK(reg, field)) |			\
   1105   1.1  riastrad 	 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
   1106   1.1  riastrad 
   1107   1.1  riastrad #define REG_GET_FIELD(value, reg, field)				\
   1108   1.1  riastrad 	(((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
   1109   1.1  riastrad 
   1110   1.5  riastrad #define WREG32_FIELD(reg, field, val)	\
   1111   1.5  riastrad 	WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
   1112   1.5  riastrad 
   1113   1.5  riastrad #define WREG32_FIELD_OFFSET(reg, offset, field, val)	\
   1114   1.5  riastrad 	WREG32(mm##reg + offset, (RREG32(mm##reg + offset) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
   1115   1.5  riastrad 
   1116   1.1  riastrad /*
   1117   1.1  riastrad  * BIOS helpers.
   1118   1.1  riastrad  */
   1119   1.1  riastrad #define RBIOS8(i) (adev->bios[i])
   1120   1.1  riastrad #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
   1121   1.1  riastrad #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
   1122   1.1  riastrad 
   1123   1.1  riastrad /*
   1124   1.1  riastrad  * ASICs macro.
   1125   1.1  riastrad  */
   1126   1.1  riastrad #define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
   1127   1.1  riastrad #define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
   1128   1.5  riastrad #define amdgpu_asic_reset_method(adev) (adev)->asic_funcs->reset_method((adev))
   1129   1.1  riastrad #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
   1130   1.1  riastrad #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
   1131   1.1  riastrad #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
   1132   1.5  riastrad #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev))
   1133   1.5  riastrad #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l))
   1134   1.1  riastrad #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev))
   1135   1.1  riastrad #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
   1136   1.5  riastrad #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
   1137   1.1  riastrad #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v)))
   1138   1.5  riastrad #define amdgpu_asic_get_config_memsize(adev) (adev)->asic_funcs->get_config_memsize((adev))
   1139   1.5  riastrad #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), (r))
   1140   1.5  riastrad #define amdgpu_asic_invalidate_hdp(adev, r) (adev)->asic_funcs->invalidate_hdp((adev), (r))
   1141   1.5  riastrad #define amdgpu_asic_need_full_reset(adev) (adev)->asic_funcs->need_full_reset((adev))
   1142   1.5  riastrad #define amdgpu_asic_init_doorbell_index(adev) (adev)->asic_funcs->init_doorbell_index((adev))
   1143   1.5  riastrad #define amdgpu_asic_get_pcie_usage(adev, cnt0, cnt1) ((adev)->asic_funcs->get_pcie_usage((adev), (cnt0), (cnt1)))
   1144   1.5  riastrad #define amdgpu_asic_need_reset_on_init(adev) (adev)->asic_funcs->need_reset_on_init((adev))
   1145   1.5  riastrad #define amdgpu_asic_get_pcie_replay_count(adev) ((adev)->asic_funcs->get_pcie_replay_count((adev)))
   1146   1.5  riastrad #define amdgpu_asic_supports_baco(adev) (adev)->asic_funcs->supports_baco((adev))
   1147   1.1  riastrad 
   1148   1.5  riastrad #define amdgpu_inc_vram_lost(adev) atomic_inc(&((adev)->vram_lost_counter));
   1149   1.1  riastrad 
   1150   1.1  riastrad /* Common functions */
   1151   1.5  riastrad bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
   1152   1.5  riastrad int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
   1153   1.5  riastrad 			      struct amdgpu_job* job);
   1154   1.5  riastrad void amdgpu_device_pci_config_reset(struct amdgpu_device *adev);
   1155   1.5  riastrad bool amdgpu_device_need_post(struct amdgpu_device *adev);
   1156   1.5  riastrad 
   1157   1.5  riastrad void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
   1158   1.5  riastrad 				  u64 num_vis_bytes);
   1159   1.5  riastrad int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev);
   1160   1.5  riastrad void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
   1161   1.1  riastrad 					     const u32 *registers,
   1162   1.1  riastrad 					     const u32 array_size);
   1163   1.3  riastrad int amdgpu_ttm_init(struct amdgpu_device *adev);
   1164   1.3  riastrad void amdgpu_ttm_fini(struct amdgpu_device *adev);
   1165   1.1  riastrad 
   1166   1.5  riastrad bool amdgpu_device_supports_boco(struct drm_device *dev);
   1167   1.5  riastrad bool amdgpu_device_supports_baco(struct drm_device *dev);
   1168   1.5  riastrad bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
   1169   1.5  riastrad 				      struct amdgpu_device *peer_adev);
   1170   1.5  riastrad int amdgpu_device_baco_enter(struct drm_device *dev);
   1171   1.5  riastrad int amdgpu_device_baco_exit(struct drm_device *dev);
   1172   1.5  riastrad 
   1173   1.1  riastrad /* atpx handler */
   1174   1.1  riastrad #if defined(CONFIG_VGA_SWITCHEROO)
   1175   1.1  riastrad void amdgpu_register_atpx_handler(void);
   1176   1.1  riastrad void amdgpu_unregister_atpx_handler(void);
   1177   1.5  riastrad bool amdgpu_has_atpx_dgpu_power_cntl(void);
   1178   1.5  riastrad bool amdgpu_is_atpx_hybrid(void);
   1179   1.5  riastrad bool amdgpu_atpx_dgpu_req_power_for_displays(void);
   1180   1.5  riastrad bool amdgpu_has_atpx(void);
   1181   1.1  riastrad #else
   1182   1.1  riastrad static inline void amdgpu_register_atpx_handler(void) {}
   1183   1.1  riastrad static inline void amdgpu_unregister_atpx_handler(void) {}
   1184   1.5  riastrad static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
   1185   1.5  riastrad static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
   1186   1.5  riastrad static inline bool amdgpu_atpx_dgpu_req_power_for_displays(void) { return false; }
   1187   1.5  riastrad static inline bool amdgpu_has_atpx(void) { return false; }
   1188   1.5  riastrad #endif
   1189   1.5  riastrad 
   1190   1.5  riastrad #if defined(CONFIG_VGA_SWITCHEROO) && defined(CONFIG_ACPI)
   1191   1.5  riastrad void *amdgpu_atpx_get_dhandle(void);
   1192   1.5  riastrad #else
   1193   1.5  riastrad static inline void *amdgpu_atpx_get_dhandle(void) { return NULL; }
   1194   1.1  riastrad #endif
   1195   1.1  riastrad 
   1196   1.1  riastrad /*
   1197   1.1  riastrad  * KMS
   1198   1.1  riastrad  */
   1199   1.1  riastrad extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
   1200   1.5  riastrad extern const int amdgpu_max_kms_ioctl;
   1201   1.1  riastrad 
   1202   1.1  riastrad int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
   1203   1.5  riastrad void amdgpu_driver_unload_kms(struct drm_device *dev);
   1204   1.1  riastrad void amdgpu_driver_lastclose_kms(struct drm_device *dev);
   1205   1.1  riastrad int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
   1206   1.1  riastrad void amdgpu_driver_postclose_kms(struct drm_device *dev,
   1207   1.1  riastrad 				 struct drm_file *file_priv);
   1208   1.5  riastrad int amdgpu_device_ip_suspend(struct amdgpu_device *adev);
   1209   1.5  riastrad int amdgpu_device_suspend(struct drm_device *dev, bool fbcon);
   1210   1.5  riastrad int amdgpu_device_resume(struct drm_device *dev, bool fbcon);
   1211   1.1  riastrad u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
   1212   1.1  riastrad int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
   1213   1.1  riastrad void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
   1214   1.1  riastrad long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
   1215   1.1  riastrad 			     unsigned long arg);
   1216   1.1  riastrad 
   1217   1.1  riastrad /*
   1218   1.1  riastrad  * functions used by amdgpu_encoder.c
   1219   1.1  riastrad  */
   1220   1.1  riastrad struct amdgpu_afmt_acr {
   1221   1.1  riastrad 	u32 clock;
   1222   1.1  riastrad 
   1223   1.1  riastrad 	int n_32khz;
   1224   1.1  riastrad 	int cts_32khz;
   1225   1.1  riastrad 
   1226   1.1  riastrad 	int n_44_1khz;
   1227   1.1  riastrad 	int cts_44_1khz;
   1228   1.1  riastrad 
   1229   1.1  riastrad 	int n_48khz;
   1230   1.1  riastrad 	int cts_48khz;
   1231   1.1  riastrad 
   1232   1.1  riastrad };
   1233   1.1  riastrad 
   1234   1.1  riastrad struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
   1235   1.1  riastrad 
   1236   1.1  riastrad /* amdgpu_acpi.c */
   1237   1.1  riastrad #if defined(CONFIG_ACPI)
   1238   1.1  riastrad int amdgpu_acpi_init(struct amdgpu_device *adev);
   1239   1.1  riastrad void amdgpu_acpi_fini(struct amdgpu_device *adev);
   1240   1.1  riastrad bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
   1241   1.1  riastrad int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
   1242   1.1  riastrad 						u8 perf_req, bool advertise);
   1243   1.1  riastrad int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
   1244   1.5  riastrad 
   1245   1.5  riastrad void amdgpu_acpi_get_backlight_caps(struct amdgpu_device *adev,
   1246   1.5  riastrad 		struct amdgpu_dm_backlight_caps *caps);
   1247   1.1  riastrad #else
   1248   1.1  riastrad static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
   1249   1.1  riastrad static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
   1250   1.1  riastrad #endif
   1251   1.1  riastrad 
   1252   1.5  riastrad int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
   1253   1.5  riastrad 			   uint64_t addr, struct amdgpu_bo **bo,
   1254   1.5  riastrad 			   struct amdgpu_bo_va_mapping **mapping);
   1255   1.5  riastrad 
   1256   1.5  riastrad #if defined(CONFIG_DRM_AMD_DC)
   1257   1.5  riastrad int amdgpu_dm_display_resume(struct amdgpu_device *adev );
   1258   1.5  riastrad #else
   1259   1.5  riastrad static inline int amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }
   1260   1.5  riastrad #endif
   1261   1.5  riastrad 
   1262   1.5  riastrad 
   1263   1.5  riastrad void amdgpu_register_gpu_instance(struct amdgpu_device *adev);
   1264   1.5  riastrad void amdgpu_unregister_gpu_instance(struct amdgpu_device *adev);
   1265   1.1  riastrad 
   1266   1.1  riastrad #include "amdgpu_object.h"
   1267   1.1  riastrad 
   1268   1.6  riastrad #ifdef __NetBSD__	       /* XXX amdgpu sysfs */
   1269   1.6  riastrad #define	AMDGPU_PMU_ATTR(_name, _object) CTASSERT(1)
   1270   1.6  riastrad #else
   1271   1.5  riastrad /* used by df_v3_6.c and amdgpu_pmu.c */
   1272   1.5  riastrad #define AMDGPU_PMU_ATTR(_name, _object)					\
   1273   1.5  riastrad static ssize_t								\
   1274   1.5  riastrad _name##_show(struct device *dev,					\
   1275   1.5  riastrad 			       struct device_attribute *attr,		\
   1276   1.5  riastrad 			       char *page)				\
   1277   1.5  riastrad {									\
   1278   1.5  riastrad 	BUILD_BUG_ON(sizeof(_object) >= PAGE_SIZE - 1);			\
   1279   1.5  riastrad 	return sprintf(page, _object "\n");				\
   1280   1.5  riastrad }									\
   1281   1.5  riastrad 									\
   1282   1.5  riastrad static struct device_attribute pmu_attr_##_name = __ATTR_RO(_name)
   1283   1.6  riastrad #endif
   1284   1.5  riastrad 
   1285   1.1  riastrad #endif
   1286   1.5  riastrad 
   1287