Subversion Repositories Kolibri OS

Rev

Rev 1630 | Rev 2004 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2008 Advanced Micro Devices, Inc.
  3.  * Copyright 2008 Red Hat Inc.
  4.  * Copyright 2009 Jerome Glisse.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in
  14.  * all copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  19.  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22.  * OTHER DEALINGS IN THE SOFTWARE.
  23.  *
  24.  * Authors: Dave Airlie
  25.  *          Alex Deucher
  26.  *          Jerome Glisse
  27.  */
  28. #ifndef __RADEON_H__
  29. #define __RADEON_H__
  30.  
  31. /* TODO: Here are things that needs to be done :
  32.  *      - surface allocator & initializer : (bit like scratch reg) should
  33.  *        initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
  34.  *        related to surface
  35.  *      - WB : write back stuff (do it bit like scratch reg things)
  36.  *      - Vblank : look at Jesse's rework and what we should do
  37.  *      - r600/r700: gart & cp
  38.  *      - cs : clean cs ioctl use bitmap & things like that.
  39.  *      - power management stuff
  40.  *      - Barrier in gart code
  41.  *      - Unmappabled vram ?
  42.  *      - TESTING, TESTING, TESTING
  43.  */
  44.  
  45. /* Initialization path:
  46.  *  We expect that acceleration initialization might fail for various
  47.  *  reasons even thought we work hard to make it works on most
  48.  *  configurations. In order to still have a working userspace in such
  49.  *  situation the init path must succeed up to the memory controller
  50.  *  initialization point. Failure before this point are considered as
  51.  *  fatal error. Here is the init callchain :
  52.  *      radeon_device_init  perform common structure, mutex initialization
  53.  *      asic_init           setup the GPU memory layout and perform all
  54.  *                          one time initialization (failure in this
  55.  *                          function are considered fatal)
  56.  *      asic_startup        setup the GPU acceleration, in order to
  57.  *                          follow guideline the first thing this
  58.  *                          function should do is setting the GPU
  59.  *                          memory controller (only MC setup failure
  60.  *                          are considered as fatal)
  61.  */
  62.  
  63. #include <asm/atomic.h>
  64.  
  65. #include <linux/list.h>
  66. #include <linux/kref.h>
  67.  
  68. #include <ttm/ttm_bo_api.h>
  69. #include <ttm/ttm_bo_driver.h>
  70. #include <ttm/ttm_placement.h>
  71. #include <ttm/ttm_module.h>
  72.  
  73.  
  74. #include <pci.h>
  75.  
  76. #include <errno-base.h>
  77. #include "drm_edid.h"
  78.  
  79. #include "radeon_family.h"
  80. #include "radeon_mode.h"
  81. #include "radeon_reg.h"
  82.  
  83. #include <syscall.h>
  84.  
  85. extern unsigned long volatile jiffies;
  86.  
  87. /*
  88.  * Modules parameters.
  89.  */
  90. extern int radeon_no_wb;
  91. extern int radeon_modeset;
  92. extern int radeon_dynclks;
  93. extern int radeon_r4xx_atom;
  94. extern int radeon_agpmode;
  95. extern int radeon_vram_limit;
  96. extern int radeon_gart_size;
  97. extern int radeon_benchmarking;
  98. extern int radeon_testing;
  99. extern int radeon_connector_table;
  100. extern int radeon_tv;
  101. extern int radeon_audio;
  102. extern int radeon_disp_priority;
  103. extern int radeon_hw_i2c;
  104. extern int radeon_pcie_gen2;
  105. typedef struct pm_message {
  106.     int event;
  107. } pm_message_t;
  108.  
  109. typedef struct
  110. {
  111.   int width;
  112.   int height;
  113.   int bpp;
  114.   int freq;
  115. }videomode_t;
  116.  
  117. static inline uint8_t __raw_readb(const volatile void __iomem *addr)
  118. {
  119.     return *(const volatile uint8_t __force *) addr;
  120. }
  121.  
  122. static inline uint16_t __raw_readw(const volatile void __iomem *addr)
  123. {
  124.     return *(const volatile uint16_t __force *) addr;
  125. }
  126.  
  127. static inline uint32_t __raw_readl(const volatile void __iomem *addr)
  128. {
  129.     return *(const volatile uint32_t __force *) addr;
  130. }
  131.  
  132. #define readb __raw_readb
  133. #define readw __raw_readw
  134. #define readl __raw_readl
  135.  
  136.  
  137.  
  138. static inline void __raw_writeb(uint8_t b, volatile void __iomem *addr)
  139. {
  140.     *(volatile uint8_t __force *) addr = b;
  141. }
  142.  
  143. static inline void __raw_writew(uint16_t b, volatile void __iomem *addr)
  144. {
  145.     *(volatile uint16_t __force *) addr = b;
  146. }
  147.  
  148. static inline void __raw_writel(uint32_t b, volatile void __iomem *addr)
  149. {
  150.     *(volatile uint32_t __force *) addr = b;
  151. }
  152.  
  153. static inline void __raw_writeq(__u64 b, volatile void __iomem *addr)
  154. {
  155.         *(volatile __u64 *)addr = b;
  156. }
  157.  
  158. #define writeb __raw_writeb
  159. #define writew __raw_writew
  160. #define writel __raw_writel
  161. #define writeq __raw_writeq
  162.  
  163.  
  164. static inline u32 ioread32(const volatile void __iomem *addr)
  165. {
  166.     return in32((u32)addr);
  167. }
  168.  
  169. static inline void iowrite32(uint32_t b, volatile void __iomem *addr)
  170. {
  171.     out32((u32)addr, b);
  172. }
  173.  
  174. struct __wait_queue_head {
  175.         spinlock_t lock;
  176.         struct list_head task_list;
  177. };
  178. typedef struct __wait_queue_head wait_queue_head_t;
  179.  
  180.  
  181. /*
  182.  * Copy from radeon_drv.h so we don't have to include both and have conflicting
  183.  * symbol;
  184.  */
  185. #define RADEON_MAX_USEC_TIMEOUT         100000  /* 100 ms */
  186. #define RADEON_FENCE_JIFFIES_TIMEOUT    (HZ / 2)
  187. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  188. #define RADEON_IB_POOL_SIZE             16
  189. #define RADEON_DEBUGFS_MAX_NUM_FILES    32
  190. #define RADEONFB_CONN_LIMIT             4
  191. #define RADEON_BIOS_NUM_SCRATCH         8
  192.  
  193. /*
  194.  * Errata workarounds.
  195.  */
  196. enum radeon_pll_errata {
  197.     CHIP_ERRATA_R300_CG             = 0x00000001,
  198.     CHIP_ERRATA_PLL_DUMMYREADS      = 0x00000002,
  199.     CHIP_ERRATA_PLL_DELAY           = 0x00000004
  200. };
  201.  
  202.  
  203. struct radeon_device;
  204.  
  205.  
  206. /*
  207.  * BIOS.
  208.  */
  209. #define ATRM_BIOS_PAGE 4096
  210.  
  211. #if defined(CONFIG_VGA_SWITCHEROO)
  212. bool radeon_atrm_supported(struct pci_dev *pdev);
  213. int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
  214. #else
  215. static inline bool radeon_atrm_supported(struct pci_dev *pdev)
  216. {
  217.         return false;
  218. }
  219.  
  220. static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
  221.         return -EINVAL;
  222. }
  223. #endif
  224. bool radeon_get_bios(struct radeon_device *rdev);
  225.  
  226.  
  227. /*
  228.  * Dummy page
  229.  */
  230. struct radeon_dummy_page {
  231.         struct page     *page;
  232.         dma_addr_t      addr;
  233. };
  234. int radeon_dummy_page_init(struct radeon_device *rdev);
  235. void radeon_dummy_page_fini(struct radeon_device *rdev);
  236.  
  237.  
  238. /*
  239.  * Clocks
  240.  */
  241. struct radeon_clock {
  242.         struct radeon_pll p1pll;
  243.         struct radeon_pll p2pll;
  244.         struct radeon_pll dcpll;
  245.         struct radeon_pll spll;
  246.         struct radeon_pll mpll;
  247.         /* 10 Khz units */
  248.         uint32_t default_mclk;
  249.         uint32_t default_sclk;
  250.         uint32_t default_dispclk;
  251.         uint32_t dp_extclk;
  252.         uint32_t max_pixel_clock;
  253. };
  254.  
  255. /*
  256.  * Power management
  257.  */
  258. int radeon_pm_init(struct radeon_device *rdev);
  259. void radeon_pm_fini(struct radeon_device *rdev);
  260. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  261. void radeon_pm_suspend(struct radeon_device *rdev);
  262. void radeon_pm_resume(struct radeon_device *rdev);
  263. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  264. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  265. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  266. void rs690_pm_info(struct radeon_device *rdev);
  267. extern int rv6xx_get_temp(struct radeon_device *rdev);
  268. extern int rv770_get_temp(struct radeon_device *rdev);
  269. extern int evergreen_get_temp(struct radeon_device *rdev);
  270. extern int sumo_get_temp(struct radeon_device *rdev);
  271.  
  272. /*
  273.  * Fences.
  274.  */
  275. struct radeon_fence_driver {
  276.         uint32_t                        scratch_reg;
  277.         atomic_t                        seq;
  278.         uint32_t                        last_seq;
  279.         unsigned long                   last_jiffies;
  280.         unsigned long                   last_timeout;
  281.         wait_queue_head_t               queue;
  282.         rwlock_t                        lock;
  283.         struct list_head                created;
  284.         struct list_head                emited;
  285.         struct list_head                signaled;
  286.         bool                            initialized;
  287. };
  288.  
  289. struct radeon_fence {
  290.         struct radeon_device            *rdev;
  291.         struct kref                     kref;
  292.         struct list_head                list;
  293.         /* protected by radeon_fence.lock */
  294.         uint32_t                        seq;
  295.         bool                            emited;
  296.         bool                            signaled;
  297. };
  298.  
  299. int radeon_fence_driver_init(struct radeon_device *rdev);
  300. void radeon_fence_driver_fini(struct radeon_device *rdev);
  301. int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
  302. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
  303. void radeon_fence_process(struct radeon_device *rdev);
  304. bool radeon_fence_signaled(struct radeon_fence *fence);
  305. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  306. int radeon_fence_wait_next(struct radeon_device *rdev);
  307. int radeon_fence_wait_last(struct radeon_device *rdev);
  308. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  309. void radeon_fence_unref(struct radeon_fence **fence);
  310.  
  311. /*
  312.  * Tiling registers
  313.  */
  314. struct radeon_surface_reg {
  315.         struct radeon_bo *bo;
  316. };
  317.  
  318. #define RADEON_GEM_MAX_SURFACES 8
  319.  
  320. /*
  321.  * TTM.
  322.  */
  323. struct radeon_mman {
  324.         struct ttm_bo_global_ref        bo_global_ref;
  325. //      struct drm_global_reference     mem_global_ref;
  326.         struct ttm_bo_device            bdev;
  327.         bool                            mem_global_referenced;
  328.         bool                            initialized;
  329. };
  330.  
  331. struct radeon_bo {
  332.         /* Protected by gem.mutex */
  333.         struct list_head                list;
  334.         /* Protected by tbo.reserved */
  335.         u32                             placements[3];
  336.         struct ttm_placement            placement;
  337.         struct ttm_buffer_object        tbo;
  338.         struct ttm_bo_kmap_obj          kmap;
  339.     unsigned                    pin_count;
  340.     void                       *kptr;
  341.     u32                         cpu_addr;
  342.     u32                         tiling_flags;
  343.     u32                         pitch;
  344.     int                         surface_reg;
  345.         /* Constant after initialization */
  346.         struct radeon_device            *rdev;
  347.         struct drm_gem_object           gem_base;
  348.     u32                          domain;
  349. };
  350. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  351.  
  352. struct radeon_bo_list {
  353.         struct radeon_bo        *bo;
  354.         uint64_t                gpu_offset;
  355.         unsigned                rdomain;
  356.         unsigned                wdomain;
  357.         u32                     tiling_flags;
  358. };
  359.  
  360. /*
  361.  * GEM objects.
  362.  */
  363. struct radeon_gem {
  364.         struct mutex            mutex;
  365.         struct list_head        objects;
  366. };
  367.  
  368. int radeon_gem_init(struct radeon_device *rdev);
  369. void radeon_gem_fini(struct radeon_device *rdev);
  370. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  371.                              int alignment, int initial_domain,
  372.                              bool discardable, bool kernel,
  373.                              struct drm_gem_object **obj);
  374. int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
  375.                           uint64_t *gpu_addr);
  376. void radeon_gem_object_unpin(struct drm_gem_object *obj);
  377.  
  378.  
  379. /*
  380.  * GART structures, functions & helpers
  381.  */
  382. struct radeon_mc;
  383.  
  384. struct radeon_gart_table_ram {
  385.     volatile uint32_t       *ptr;
  386. };
  387.  
  388. struct radeon_gart_table_vram {
  389.         struct radeon_bo                *robj;
  390.     volatile uint32_t       *ptr;
  391. };
  392.  
  393. union radeon_gart_table {
  394.     struct radeon_gart_table_ram    ram;
  395.     struct radeon_gart_table_vram   vram;
  396. };
  397.  
  398. #define RADEON_GPU_PAGE_SIZE 4096
  399. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  400.  
  401. struct radeon_gart {
  402.     dma_addr_t          table_addr;
  403.     unsigned            num_gpu_pages;
  404.     unsigned            num_cpu_pages;
  405.     unsigned            table_size;
  406.     union radeon_gart_table     table;
  407.     struct page         **pages;
  408.     dma_addr_t          *pages_addr;
  409.         bool                            *ttm_alloced;
  410.     bool                ready;
  411. };
  412.  
  413. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  414. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  415. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  416. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  417. int radeon_gart_init(struct radeon_device *rdev);
  418. void radeon_gart_fini(struct radeon_device *rdev);
  419. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  420.                         int pages);
  421. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  422.             int pages, u32_t *pagelist);
  423.  
  424.  
  425. /*
  426.  * GPU MC structures, functions & helpers
  427.  */
  428. struct radeon_mc {
  429.     resource_size_t     aper_size;
  430.     resource_size_t     aper_base;
  431.     resource_size_t     agp_base;
  432.         /* for some chips with <= 32MB we need to lie
  433.          * about vram size near mc fb location */
  434.         u64                     mc_vram_size;
  435.         u64                     visible_vram_size;
  436.         u64                     gtt_size;
  437.         u64                     gtt_start;
  438.         u64                     gtt_end;
  439.         u64                     vram_start;
  440.         u64                     vram_end;
  441.     unsigned            vram_width;
  442.         u64                     real_vram_size;
  443.     int                 vram_mtrr;
  444.     bool                vram_is_ddr;
  445.         bool                    igp_sideport_enabled;
  446.         u64                     gtt_base_align;
  447. };
  448.  
  449. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  450. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  451.  
  452. /*
  453.  * GPU scratch registers structures, functions & helpers
  454.  */
  455. struct radeon_scratch {
  456.     unsigned        num_reg;
  457.         uint32_t                reg_base;
  458.     bool            free[32];
  459.     uint32_t        reg[32];
  460. };
  461.  
  462. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  463. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  464.  
  465.  
  466. /*
  467.  * IRQS.
  468.  */
  469. struct r500_irq_stat_regs {
  470.         u32 disp_int;
  471. };
  472.  
  473. struct r600_irq_stat_regs {
  474.         u32 disp_int;
  475.         u32 disp_int_cont;
  476.         u32 disp_int_cont2;
  477.         u32 d1grph_int;
  478.         u32 d2grph_int;
  479. };
  480.  
  481. struct evergreen_irq_stat_regs {
  482.         u32 disp_int;
  483.         u32 disp_int_cont;
  484.         u32 disp_int_cont2;
  485.         u32 disp_int_cont3;
  486.         u32 disp_int_cont4;
  487.         u32 disp_int_cont5;
  488.         u32 d1grph_int;
  489.         u32 d2grph_int;
  490.         u32 d3grph_int;
  491.         u32 d4grph_int;
  492.         u32 d5grph_int;
  493.         u32 d6grph_int;
  494. };
  495.  
  496. union radeon_irq_stat_regs {
  497.         struct r500_irq_stat_regs r500;
  498.         struct r600_irq_stat_regs r600;
  499.         struct evergreen_irq_stat_regs evergreen;
  500. };
  501.  
  502. struct radeon_irq {
  503.         bool            installed;
  504.         bool            sw_int;
  505.         /* FIXME: use a define max crtc rather than hardcode it */
  506.         bool            crtc_vblank_int[6];
  507.         bool            pflip[6];
  508.     wait_queue_head_t   vblank_queue;
  509.         /* FIXME: use defines for max hpd/dacs */
  510.         bool            hpd[6];
  511.         bool            gui_idle;
  512.         bool            gui_idle_acked;
  513.    wait_queue_head_t   idle_queue;
  514.         /* FIXME: use defines for max HDMI blocks */
  515.         bool            hdmi[2];
  516.     spinlock_t  sw_lock;
  517.         int sw_refcount;
  518.         union radeon_irq_stat_regs stat_regs;
  519.         spinlock_t pflip_lock[6];
  520.         int pflip_refcount[6];
  521. };
  522.  
  523. int radeon_irq_kms_init(struct radeon_device *rdev);
  524. void radeon_irq_kms_fini(struct radeon_device *rdev);
  525. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
  526. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
  527.  
  528. /*
  529.  * CP & ring.
  530.  */
  531. struct radeon_ib {
  532.     struct list_head    list;
  533.         unsigned                idx;
  534.     uint64_t            gpu_addr;
  535.         struct radeon_fence     *fence;
  536.     uint32_t            *ptr;
  537.     uint32_t            length_dw;
  538.         bool                    free;
  539. };
  540.  
  541. /*
  542.  * locking -
  543.  * mutex protects scheduled_ibs, ready, alloc_bm
  544.  */
  545. struct radeon_ib_pool {
  546.         struct mutex            mutex;
  547.         struct radeon_bo        *robj;
  548.         struct list_head        bogus_ib;
  549.         struct radeon_ib        ibs[RADEON_IB_POOL_SIZE];
  550.     bool                ready;
  551.         unsigned                head_id;
  552. };
  553.  
  554. struct radeon_cp {
  555.         struct radeon_bo        *ring_obj;
  556.         volatile uint32_t       *ring;
  557.     unsigned            rptr;
  558.     unsigned            wptr;
  559.     unsigned            wptr_old;
  560.     unsigned            ring_size;
  561.     unsigned            ring_free_dw;
  562.     int                 count_dw;
  563.     uint64_t            gpu_addr;
  564.     uint32_t            align_mask;
  565.     uint32_t            ptr_mask;
  566.         struct mutex            mutex;
  567.     bool                ready;
  568. };
  569.  
  570. /*
  571.  * R6xx+ IH ring
  572.  */
  573. struct r600_ih {
  574.         struct radeon_bo        *ring_obj;
  575.         volatile uint32_t       *ring;
  576.     unsigned            rptr;
  577.     unsigned            wptr;
  578.     unsigned            wptr_old;
  579.     unsigned            ring_size;
  580.     uint64_t            gpu_addr;
  581.     uint32_t            ptr_mask;
  582.     spinlock_t              lock;
  583.     bool                enabled;
  584. };
  585.  
  586. struct r600_blit {
  587.         struct mutex            mutex;
  588.         struct radeon_bo        *shader_obj;
  589.         u64 shader_gpu_addr;
  590.         u32 vs_offset, ps_offset;
  591.         u32 state_offset;
  592.         u32 state_len;
  593.         u32 vb_used, vb_total;
  594.         struct radeon_ib *vb_ib;
  595. };
  596.  
  597. int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
  598. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
  599. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  600. int radeon_ib_pool_init(struct radeon_device *rdev);
  601. void radeon_ib_pool_fini(struct radeon_device *rdev);
  602. int radeon_ib_test(struct radeon_device *rdev);
  603. extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
  604. /* Ring access between begin & end cannot sleep */
  605. void radeon_ring_free_size(struct radeon_device *rdev);
  606. int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
  607. int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
  608. void radeon_ring_commit(struct radeon_device *rdev);
  609. void radeon_ring_unlock_commit(struct radeon_device *rdev);
  610. void radeon_ring_unlock_undo(struct radeon_device *rdev);
  611. int radeon_ring_test(struct radeon_device *rdev);
  612. int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
  613. void radeon_ring_fini(struct radeon_device *rdev);
  614.  
  615.  
  616. /*
  617.  * CS.
  618.  */
  619. struct radeon_cs_reloc {
  620. //      struct drm_gem_object           *gobj;
  621.         struct radeon_bo                *robj;
  622.         struct radeon_bo_list           lobj;
  623.     uint32_t                handle;
  624.     uint32_t                flags;
  625. };
  626.  
  627. struct radeon_cs_chunk {
  628.         uint32_t                chunk_id;
  629.         uint32_t                length_dw;
  630.         int kpage_idx[2];
  631.         uint32_t                *kpage[2];
  632.         uint32_t                *kdata;
  633.         void __user *user_ptr;
  634.         int last_copied_page;
  635.         int last_page_index;
  636. };
  637.  
  638. struct radeon_cs_parser {
  639.         struct device           *dev;
  640.         struct radeon_device    *rdev;
  641. //      struct drm_file         *filp;
  642.         /* chunks */
  643.         unsigned                nchunks;
  644.         struct radeon_cs_chunk  *chunks;
  645.         uint64_t                *chunks_array;
  646.         /* IB */
  647.         unsigned                idx;
  648.         /* relocations */
  649.         unsigned                nrelocs;
  650.         struct radeon_cs_reloc  *relocs;
  651.         struct radeon_cs_reloc  **relocs_ptr;
  652.         struct list_head        validated;
  653.         /* indices of various chunks */
  654.         int                     chunk_ib_idx;
  655.         int                     chunk_relocs_idx;
  656.         struct radeon_ib        *ib;
  657.         void                    *track;
  658.         unsigned                family;
  659.         int parser_error;
  660. };
  661.  
  662. extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
  663. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  664.  
  665.  
  666. static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
  667. {
  668.         struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
  669.         u32 pg_idx, pg_offset;
  670.         u32 idx_value = 0;
  671.         int new_page;
  672.  
  673.         pg_idx = (idx * 4) / PAGE_SIZE;
  674.         pg_offset = (idx * 4) % PAGE_SIZE;
  675.  
  676.         if (ibc->kpage_idx[0] == pg_idx)
  677.                 return ibc->kpage[0][pg_offset/4];
  678.         if (ibc->kpage_idx[1] == pg_idx)
  679.                 return ibc->kpage[1][pg_offset/4];
  680.  
  681.         new_page = radeon_cs_update_pages(p, pg_idx);
  682.         if (new_page < 0) {
  683.                 p->parser_error = new_page;
  684.                 return 0;
  685.         }
  686.  
  687.         idx_value = ibc->kpage[new_page][pg_offset/4];
  688.         return idx_value;
  689. }
  690.  
  691. struct radeon_cs_packet {
  692.         unsigned        idx;
  693.         unsigned        type;
  694.         unsigned        reg;
  695.         unsigned        opcode;
  696.         int             count;
  697.         unsigned        one_reg_wr;
  698. };
  699.  
  700. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  701.                                       struct radeon_cs_packet *pkt,
  702.                                       unsigned idx, unsigned reg);
  703. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  704.                                       struct radeon_cs_packet *pkt);
  705.  
  706.  
  707. /*
  708.  * AGP
  709.  */
  710. int radeon_agp_init(struct radeon_device *rdev);
  711. void radeon_agp_resume(struct radeon_device *rdev);
  712. void radeon_agp_suspend(struct radeon_device *rdev);
  713. void radeon_agp_fini(struct radeon_device *rdev);
  714.  
  715.  
  716. /*
  717.  * Writeback
  718.  */
  719. struct radeon_wb {
  720.         struct radeon_bo        *wb_obj;
  721.         volatile uint32_t       *wb;
  722.         uint64_t                gpu_addr;
  723.         bool                    enabled;
  724.         bool                    use_event;
  725. };
  726.  
  727. #define RADEON_WB_SCRATCH_OFFSET 0
  728. #define RADEON_WB_CP_RPTR_OFFSET 1024
  729. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  730. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  731. #define R600_WB_IH_WPTR_OFFSET   2048
  732. #define R600_WB_EVENT_OFFSET     3072
  733.  
  734. /**
  735.  * struct radeon_pm - power management datas
  736.  * @max_bandwidth:      maximum bandwidth the gpu has (MByte/s)
  737.  * @igp_sideport_mclk:  sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  738.  * @igp_system_mclk:    system clock Mhz (rs690,rs740,rs780,rs880)
  739.  * @igp_ht_link_clk:    ht link clock Mhz (rs690,rs740,rs780,rs880)
  740.  * @igp_ht_link_width:  ht link width in bits (rs690,rs740,rs780,rs880)
  741.  * @k8_bandwidth:       k8 bandwidth the gpu has (MByte/s) (IGP)
  742.  * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  743.  * @ht_bandwidth:       ht bandwidth the gpu has (MByte/s) (IGP)
  744.  * @core_bandwidth:     core GPU bandwidth the gpu has (MByte/s) (IGP)
  745.  * @sclk:               GPU clock Mhz (core bandwidth depends of this clock)
  746.  * @needed_bandwidth:   current bandwidth needs
  747.  *
  748.  * It keeps track of various data needed to take powermanagement decision.
  749.  * Bandwidth need is used to determine minimun clock of the GPU and memory.
  750.  * Equation between gpu/memory clock and available bandwidth is hw dependent
  751.  * (type of memory, bus size, efficiency, ...)
  752.  */
  753.  
  754. enum radeon_pm_method {
  755.         PM_METHOD_PROFILE,
  756.         PM_METHOD_DYNPM,
  757. };
  758.  
  759. enum radeon_dynpm_state {
  760.         DYNPM_STATE_DISABLED,
  761.         DYNPM_STATE_MINIMUM,
  762.         DYNPM_STATE_PAUSED,
  763.         DYNPM_STATE_ACTIVE,
  764.         DYNPM_STATE_SUSPENDED,
  765. };
  766. enum radeon_dynpm_action {
  767.         DYNPM_ACTION_NONE,
  768.         DYNPM_ACTION_MINIMUM,
  769.         DYNPM_ACTION_DOWNCLOCK,
  770.         DYNPM_ACTION_UPCLOCK,
  771.         DYNPM_ACTION_DEFAULT
  772. };
  773.  
  774. enum radeon_voltage_type {
  775.         VOLTAGE_NONE = 0,
  776.         VOLTAGE_GPIO,
  777.         VOLTAGE_VDDC,
  778.         VOLTAGE_SW
  779. };
  780.  
  781. enum radeon_pm_state_type {
  782.         POWER_STATE_TYPE_DEFAULT,
  783.         POWER_STATE_TYPE_POWERSAVE,
  784.         POWER_STATE_TYPE_BATTERY,
  785.         POWER_STATE_TYPE_BALANCED,
  786.         POWER_STATE_TYPE_PERFORMANCE,
  787. };
  788.  
  789. enum radeon_pm_profile_type {
  790.         PM_PROFILE_DEFAULT,
  791.         PM_PROFILE_AUTO,
  792.         PM_PROFILE_LOW,
  793.         PM_PROFILE_MID,
  794.         PM_PROFILE_HIGH,
  795. };
  796.  
  797. #define PM_PROFILE_DEFAULT_IDX 0
  798. #define PM_PROFILE_LOW_SH_IDX  1
  799. #define PM_PROFILE_MID_SH_IDX  2
  800. #define PM_PROFILE_HIGH_SH_IDX 3
  801. #define PM_PROFILE_LOW_MH_IDX  4
  802. #define PM_PROFILE_MID_MH_IDX  5
  803. #define PM_PROFILE_HIGH_MH_IDX 6
  804. #define PM_PROFILE_MAX         7
  805.  
  806. struct radeon_pm_profile {
  807.         int dpms_off_ps_idx;
  808.         int dpms_on_ps_idx;
  809.         int dpms_off_cm_idx;
  810.         int dpms_on_cm_idx;
  811. };
  812.  
  813. enum radeon_int_thermal_type {
  814.         THERMAL_TYPE_NONE,
  815.         THERMAL_TYPE_RV6XX,
  816.         THERMAL_TYPE_RV770,
  817.         THERMAL_TYPE_EVERGREEN,
  818.         THERMAL_TYPE_SUMO,
  819.         THERMAL_TYPE_NI,
  820. };
  821.  
  822. struct radeon_voltage {
  823.         enum radeon_voltage_type type;
  824.         /* gpio voltage */
  825.         struct radeon_gpio_rec gpio;
  826.         u32 delay; /* delay in usec from voltage drop to sclk change */
  827.         bool active_high; /* voltage drop is active when bit is high */
  828.         /* VDDC voltage */
  829.         u8 vddc_id; /* index into vddc voltage table */
  830.         u8 vddci_id; /* index into vddci voltage table */
  831.         bool vddci_enabled;
  832.         /* r6xx+ sw */
  833.         u16 voltage;
  834.         /* evergreen+ vddci */
  835.         u16 vddci;
  836. };
  837.  
  838. /* clock mode flags */
  839. #define RADEON_PM_MODE_NO_DISPLAY          (1 << 0)
  840.  
  841. struct radeon_pm_clock_info {
  842.         /* memory clock */
  843.         u32 mclk;
  844.         /* engine clock */
  845.         u32 sclk;
  846.         /* voltage info */
  847.         struct radeon_voltage voltage;
  848.         /* standardized clock flags */
  849.         u32 flags;
  850. };
  851.  
  852. /* state flags */
  853. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  854.  
  855. struct radeon_power_state {
  856.         enum radeon_pm_state_type type;
  857.         /* XXX: use a define for num clock modes */
  858.         struct radeon_pm_clock_info clock_info[8];
  859.         /* number of valid clock modes in this power state */
  860.         int num_clock_modes;
  861.         struct radeon_pm_clock_info *default_clock_mode;
  862.         /* standardized state flags */
  863.         u32 flags;
  864.         u32 misc; /* vbios specific flags */
  865.         u32 misc2; /* vbios specific flags */
  866.         int pcie_lanes; /* pcie lanes */
  867. };
  868.  
  869. /*
  870.  * Some modes are overclocked by very low value, accept them
  871.  */
  872. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  873.  
  874. struct radeon_pm {
  875.         struct mutex            mutex;
  876.         u32                     active_crtcs;
  877.         int                     active_crtc_count;
  878.         int                     req_vblank;
  879.         bool                    vblank_sync;
  880.         bool                    gui_idle;
  881.         fixed20_12              max_bandwidth;
  882.         fixed20_12              igp_sideport_mclk;
  883.         fixed20_12              igp_system_mclk;
  884.         fixed20_12              igp_ht_link_clk;
  885.         fixed20_12              igp_ht_link_width;
  886.         fixed20_12              k8_bandwidth;
  887.         fixed20_12              sideport_bandwidth;
  888.         fixed20_12              ht_bandwidth;
  889.         fixed20_12              core_bandwidth;
  890.         fixed20_12              sclk;
  891.         fixed20_12              mclk;
  892.         fixed20_12              needed_bandwidth;
  893.         struct radeon_power_state *power_state;
  894.         /* number of valid power states */
  895.         int                     num_power_states;
  896.         int                     current_power_state_index;
  897.         int                     current_clock_mode_index;
  898.         int                     requested_power_state_index;
  899.         int                     requested_clock_mode_index;
  900.         int                     default_power_state_index;
  901.         u32                     current_sclk;
  902.         u32                     current_mclk;
  903.         u16                     current_vddc;
  904.         u16                     current_vddci;
  905.         u32                     default_sclk;
  906.         u32                     default_mclk;
  907.         u16                     default_vddc;
  908.         u16                     default_vddci;
  909.         struct radeon_i2c_chan *i2c_bus;
  910.         /* selected pm method */
  911.         enum radeon_pm_method     pm_method;
  912.         /* dynpm power management */
  913. //   struct delayed_work dynpm_idle_work;
  914.         enum radeon_dynpm_state dynpm_state;
  915.         enum radeon_dynpm_action        dynpm_planned_action;
  916.         unsigned long           dynpm_action_timeout;
  917.         bool                    dynpm_can_upclock;
  918.         bool                    dynpm_can_downclock;
  919.         /* profile-based power management */
  920.         enum radeon_pm_profile_type profile;
  921.         int                     profile_index;
  922.         struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  923.         /* internal thermal controller on rv6xx+ */
  924.         enum radeon_int_thermal_type int_thermal_type;
  925.         struct device           *int_hwmon_dev;
  926. };
  927.  
  928. /*
  929.  * ASIC specific functions.
  930.  */
  931. struct radeon_asic {
  932.         int (*init)(struct radeon_device *rdev);
  933.         void (*fini)(struct radeon_device *rdev);
  934.         int (*resume)(struct radeon_device *rdev);
  935.         int (*suspend)(struct radeon_device *rdev);
  936.         void (*vga_set_state)(struct radeon_device *rdev, bool state);
  937.         bool (*gpu_is_lockup)(struct radeon_device *rdev);
  938.         int (*asic_reset)(struct radeon_device *rdev);
  939.         void (*gart_tlb_flush)(struct radeon_device *rdev);
  940.         int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  941.         int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
  942.         void (*cp_fini)(struct radeon_device *rdev);
  943.         void (*cp_disable)(struct radeon_device *rdev);
  944.         void (*cp_commit)(struct radeon_device *rdev);
  945.         void (*ring_start)(struct radeon_device *rdev);
  946.         int (*ring_test)(struct radeon_device *rdev);
  947.         void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  948.         int (*irq_set)(struct radeon_device *rdev);
  949.         int (*irq_process)(struct radeon_device *rdev);
  950.         u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  951.         void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
  952.         int (*cs_parse)(struct radeon_cs_parser *p);
  953.         int (*copy_blit)(struct radeon_device *rdev,
  954.                          uint64_t src_offset,
  955.                          uint64_t dst_offset,
  956.                          unsigned num_pages,
  957.                          struct radeon_fence *fence);
  958.         int (*copy_dma)(struct radeon_device *rdev,
  959.                         uint64_t src_offset,
  960.                         uint64_t dst_offset,
  961.                         unsigned num_pages,
  962.                         struct radeon_fence *fence);
  963.         int (*copy)(struct radeon_device *rdev,
  964.                     uint64_t src_offset,
  965.                     uint64_t dst_offset,
  966.                     unsigned num_pages,
  967.                     struct radeon_fence *fence);
  968.         uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  969.         void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  970.         uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  971.         void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  972.         int (*get_pcie_lanes)(struct radeon_device *rdev);
  973.         void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  974.         void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  975.         int (*set_surface_reg)(struct radeon_device *rdev, int reg,
  976.                                uint32_t tiling_flags, uint32_t pitch,
  977.                                uint32_t offset, uint32_t obj_size);
  978.         void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
  979.         void (*bandwidth_update)(struct radeon_device *rdev);
  980.         void (*hpd_init)(struct radeon_device *rdev);
  981.         void (*hpd_fini)(struct radeon_device *rdev);
  982.         bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  983.         void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  984.         /* ioctl hw specific callback. Some hw might want to perform special
  985.          * operation on specific ioctl. For instance on wait idle some hw
  986.          * might want to perform and HDP flush through MMIO as it seems that
  987.          * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  988.          * through ring.
  989.          */
  990.         void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  991.         bool (*gui_idle)(struct radeon_device *rdev);
  992.         /* power management */
  993.         void (*pm_misc)(struct radeon_device *rdev);
  994.         void (*pm_prepare)(struct radeon_device *rdev);
  995.         void (*pm_finish)(struct radeon_device *rdev);
  996.         void (*pm_init_profile)(struct radeon_device *rdev);
  997.         void (*pm_get_dynpm_state)(struct radeon_device *rdev);
  998.         /* pageflipping */
  999.         void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1000.         u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1001.         void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1002. };
  1003.  
  1004. /*
  1005.  * Asic structures
  1006.  */
  1007. struct r100_gpu_lockup {
  1008.         unsigned long   last_jiffies;
  1009.         u32             last_cp_rptr;
  1010. };
  1011.  
  1012. struct r100_asic {
  1013.         const unsigned  *reg_safe_bm;
  1014.         unsigned        reg_safe_bm_size;
  1015.         u32             hdp_cntl;
  1016.         struct r100_gpu_lockup  lockup;
  1017. };
  1018.  
  1019. struct r300_asic {
  1020.         const unsigned  *reg_safe_bm;
  1021.         unsigned        reg_safe_bm_size;
  1022.         u32             resync_scratch;
  1023.         u32             hdp_cntl;
  1024.         struct r100_gpu_lockup  lockup;
  1025. };
  1026.  
  1027. struct r600_asic {
  1028.         unsigned max_pipes;
  1029.         unsigned max_tile_pipes;
  1030.         unsigned max_simds;
  1031.         unsigned max_backends;
  1032.         unsigned max_gprs;
  1033.         unsigned max_threads;
  1034.         unsigned max_stack_entries;
  1035.         unsigned max_hw_contexts;
  1036.         unsigned max_gs_threads;
  1037.         unsigned sx_max_export_size;
  1038.         unsigned sx_max_export_pos_size;
  1039.         unsigned sx_max_export_smx_size;
  1040.         unsigned sq_num_cf_insts;
  1041.         unsigned tiling_nbanks;
  1042.         unsigned tiling_npipes;
  1043.         unsigned tiling_group_size;
  1044.         unsigned                tile_config;
  1045.         struct r100_gpu_lockup  lockup;
  1046. };
  1047.  
  1048. struct rv770_asic {
  1049.         unsigned max_pipes;
  1050.         unsigned max_tile_pipes;
  1051.         unsigned max_simds;
  1052.         unsigned max_backends;
  1053.         unsigned max_gprs;
  1054.         unsigned max_threads;
  1055.         unsigned max_stack_entries;
  1056.         unsigned max_hw_contexts;
  1057.         unsigned max_gs_threads;
  1058.         unsigned sx_max_export_size;
  1059.         unsigned sx_max_export_pos_size;
  1060.         unsigned sx_max_export_smx_size;
  1061.         unsigned sq_num_cf_insts;
  1062.         unsigned sx_num_of_sets;
  1063.         unsigned sc_prim_fifo_size;
  1064.         unsigned sc_hiz_tile_fifo_size;
  1065.         unsigned sc_earlyz_tile_fifo_fize;
  1066.         unsigned tiling_nbanks;
  1067.         unsigned tiling_npipes;
  1068.         unsigned tiling_group_size;
  1069.         unsigned                tile_config;
  1070.         struct r100_gpu_lockup  lockup;
  1071. };
  1072.  
  1073. struct evergreen_asic {
  1074.         unsigned num_ses;
  1075.         unsigned max_pipes;
  1076.         unsigned max_tile_pipes;
  1077.         unsigned max_simds;
  1078.         unsigned max_backends;
  1079.         unsigned max_gprs;
  1080.         unsigned max_threads;
  1081.         unsigned max_stack_entries;
  1082.         unsigned max_hw_contexts;
  1083.         unsigned max_gs_threads;
  1084.         unsigned sx_max_export_size;
  1085.         unsigned sx_max_export_pos_size;
  1086.         unsigned sx_max_export_smx_size;
  1087.         unsigned sq_num_cf_insts;
  1088.         unsigned sx_num_of_sets;
  1089.         unsigned sc_prim_fifo_size;
  1090.         unsigned sc_hiz_tile_fifo_size;
  1091.         unsigned sc_earlyz_tile_fifo_size;
  1092.         unsigned tiling_nbanks;
  1093.         unsigned tiling_npipes;
  1094.         unsigned tiling_group_size;
  1095.         unsigned tile_config;
  1096.         struct r100_gpu_lockup  lockup;
  1097. };
  1098.  
  1099. struct cayman_asic {
  1100.         unsigned max_shader_engines;
  1101.         unsigned max_pipes_per_simd;
  1102.         unsigned max_tile_pipes;
  1103.         unsigned max_simds_per_se;
  1104.         unsigned max_backends_per_se;
  1105.         unsigned max_texture_channel_caches;
  1106.         unsigned max_gprs;
  1107.         unsigned max_threads;
  1108.         unsigned max_gs_threads;
  1109.         unsigned max_stack_entries;
  1110.         unsigned sx_num_of_sets;
  1111.         unsigned sx_max_export_size;
  1112.         unsigned sx_max_export_pos_size;
  1113.         unsigned sx_max_export_smx_size;
  1114.         unsigned max_hw_contexts;
  1115.         unsigned sq_num_cf_insts;
  1116.         unsigned sc_prim_fifo_size;
  1117.         unsigned sc_hiz_tile_fifo_size;
  1118.         unsigned sc_earlyz_tile_fifo_size;
  1119.  
  1120.         unsigned num_shader_engines;
  1121.         unsigned num_shader_pipes_per_simd;
  1122.         unsigned num_tile_pipes;
  1123.         unsigned num_simds_per_se;
  1124.         unsigned num_backends_per_se;
  1125.         unsigned backend_disable_mask_per_asic;
  1126.         unsigned backend_map;
  1127.         unsigned num_texture_channel_caches;
  1128.         unsigned mem_max_burst_length_bytes;
  1129.         unsigned mem_row_size_in_kb;
  1130.         unsigned shader_engine_tile_size;
  1131.         unsigned num_gpus;
  1132.         unsigned multi_gpu_tile_size;
  1133.  
  1134.         unsigned tile_config;
  1135.         struct r100_gpu_lockup  lockup;
  1136. };
  1137.  
  1138. union radeon_asic_config {
  1139.         struct r300_asic        r300;
  1140.         struct r100_asic        r100;
  1141.         struct r600_asic        r600;
  1142.         struct rv770_asic       rv770;
  1143.         struct evergreen_asic   evergreen;
  1144.         struct cayman_asic      cayman;
  1145. };
  1146.  
  1147. /*
  1148.  * asic initizalization from radeon_asic.c
  1149.  */
  1150. void radeon_agp_disable(struct radeon_device *rdev);
  1151. int radeon_asic_init(struct radeon_device *rdev);
  1152.  
  1153.  
  1154.  
  1155. /* VRAM scratch page for HDP bug */
  1156. struct r700_vram_scratch {
  1157.         struct radeon_bo                *robj;
  1158.         volatile uint32_t               *ptr;
  1159. };
  1160.  
  1161. /*
  1162.  * Core structure, functions and helpers.
  1163.  */
  1164. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1165. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1166.  
  1167. struct radeon_device {
  1168.         struct device                   *dev;
  1169.     struct drm_device          *ddev;
  1170.     struct pci_dev             *pdev;
  1171.     /* ASIC */
  1172.     union radeon_asic_config    config;
  1173.     enum radeon_family          family;
  1174.     unsigned long               flags;
  1175.     int                         usec_timeout;
  1176.     enum radeon_pll_errata      pll_errata;
  1177.     int                         num_gb_pipes;
  1178.         int                                         num_z_pipes;
  1179.     int                         disp_priority;
  1180.     /* BIOS */
  1181.     uint8_t                     *bios;
  1182.     bool                        is_atom_bios;
  1183.     uint16_t                    bios_header_start;
  1184.         struct radeon_bo                    *stollen_vga_memory;
  1185.     /* Register mmio */
  1186.         resource_size_t                 rmmio_base;
  1187.         resource_size_t                 rmmio_size;
  1188.     void                       *rmmio;
  1189.     radeon_rreg_t               mc_rreg;
  1190.     radeon_wreg_t               mc_wreg;
  1191.     radeon_rreg_t               pll_rreg;
  1192.     radeon_wreg_t               pll_wreg;
  1193.         uint32_t                        pcie_reg_mask;
  1194.     radeon_rreg_t               pciep_rreg;
  1195.     radeon_wreg_t               pciep_wreg;
  1196.         /* io port */
  1197.         void __iomem                    *rio_mem;
  1198.         resource_size_t                 rio_mem_size;
  1199.     struct radeon_clock         clock;
  1200.     struct radeon_mc            mc;
  1201.     struct radeon_gart          gart;
  1202.         struct radeon_mode_info         mode_info;
  1203.     struct radeon_scratch       scratch;
  1204.     struct radeon_mman          mman;
  1205.         struct radeon_fence_driver      fence_drv;
  1206.     struct radeon_cp            cp;
  1207.         /* cayman compute rings */
  1208.         struct radeon_cp                cp1;
  1209.         struct radeon_cp                cp2;
  1210.     struct radeon_ib_pool       ib_pool;
  1211.     struct radeon_irq       irq;
  1212.     struct radeon_asic         *asic;
  1213.     struct radeon_gem       gem;
  1214.         struct radeon_pm                pm;
  1215.         uint32_t                        bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1216.         struct mutex                    cs_mutex;
  1217.     struct radeon_wb        wb;
  1218.         struct radeon_dummy_page        dummy_page;
  1219.     bool                gpu_lockup;
  1220.     bool                shutdown;
  1221.     bool                suspend;
  1222.         bool                            need_dma32;
  1223.         bool                            accel_working;
  1224.         struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1225.         const struct firmware *me_fw;   /* all family ME firmware */
  1226.         const struct firmware *pfp_fw;  /* r6/700 PFP firmware */
  1227.         const struct firmware *rlc_fw;  /* r6/700 RLC firmware */
  1228.         const struct firmware *mc_fw;   /* NI MC firmware */
  1229.         struct r600_blit r600_blit;
  1230.         struct r700_vram_scratch vram_scratch;
  1231.         int msi_enabled; /* msi enabled */
  1232. //      struct r600_ih ih; /* r6/700 interrupt ring */
  1233. //      struct workqueue_struct *wq;
  1234. //      struct work_struct hotplug_work;
  1235.         int num_crtc; /* number of crtcs */
  1236.         struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1237.         struct mutex vram_mutex;
  1238.  
  1239.         /* audio stuff */
  1240.         bool                    audio_enabled;
  1241. //      struct timer_list       audio_timer;
  1242.         int                     audio_channels;
  1243.         int                     audio_rate;
  1244.         int                     audio_bits_per_sample;
  1245.         uint8_t                 audio_status_bits;
  1246.         uint8_t                 audio_category_code;
  1247.  
  1248.  
  1249.         /* i2c buses */
  1250.         struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1251. };
  1252.  
  1253. int radeon_device_init(struct radeon_device *rdev,
  1254.                        struct drm_device *ddev,
  1255.                        struct pci_dev *pdev,
  1256.                        uint32_t flags);
  1257. void radeon_device_fini(struct radeon_device *rdev);
  1258. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1259.  
  1260. static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
  1261. {
  1262.         if (reg < rdev->rmmio_size)
  1263.                 return readl(((void __iomem *)rdev->rmmio) + reg);
  1264.         else {
  1265.                 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
  1266.                 return readl(((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
  1267.         }
  1268. }
  1269.  
  1270. static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1271. {
  1272.         if (reg < rdev->rmmio_size)
  1273.                 writel(v, ((void __iomem *)rdev->rmmio) + reg);
  1274.         else {
  1275.                 writel(reg, ((void __iomem *)rdev->rmmio) + RADEON_MM_INDEX);
  1276.                 writel(v, ((void __iomem *)rdev->rmmio) + RADEON_MM_DATA);
  1277.         }
  1278. }
  1279.  
  1280. static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
  1281. {
  1282.         if (reg < rdev->rio_mem_size)
  1283.                 return ioread32(rdev->rio_mem + reg);
  1284.         else {
  1285.                 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1286.                 return ioread32(rdev->rio_mem + RADEON_MM_DATA);
  1287.         }
  1288. }
  1289.  
  1290. static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1291. {
  1292.         if (reg < rdev->rio_mem_size)
  1293.                 iowrite32(v, rdev->rio_mem + reg);
  1294.         else {
  1295.                 iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1296.                 iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
  1297.         }
  1298. }
  1299.  
  1300. /*
  1301.  * Cast helper
  1302.  */
  1303. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1304.  
  1305. /*
  1306.  * Registers read & write functions.
  1307.  */
  1308. #define RREG8(reg) readb(((void __iomem *)rdev->rmmio) + (reg))
  1309. #define WREG8(reg, v) writeb(v, ((void __iomem *)rdev->rmmio) + (reg))
  1310. #define RREG16(reg) readw(((void __iomem *)rdev->rmmio) + (reg))
  1311. #define WREG16(reg, v) writew(v, ((void __iomem *)rdev->rmmio) + (reg))
  1312. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1313. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1314. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1315. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1316. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1317. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1318. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1319. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1320. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1321. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1322. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1323. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1324. #define WREG32_P(reg, val, mask)                                \
  1325.         do {                                                    \
  1326.                 uint32_t tmp_ = RREG32(reg);                    \
  1327.                 tmp_ &= (mask);                                 \
  1328.                 tmp_ |= ((val) & ~(mask));                      \
  1329.                 WREG32(reg, tmp_);                              \
  1330.         } while (0)
  1331. #define WREG32_PLL_P(reg, val, mask)                            \
  1332.         do {                                                    \
  1333.                 uint32_t tmp_ = RREG32_PLL(reg);                \
  1334.                 tmp_ &= (mask);                                 \
  1335.                 tmp_ |= ((val) & ~(mask));                      \
  1336.                 WREG32_PLL(reg, tmp_);                          \
  1337.         } while (0)
  1338. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1339. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1340.  
  1341. /*
  1342.  * Indirect registers accessor
  1343.  */
  1344. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1345. {
  1346.         uint32_t r;
  1347.  
  1348.         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1349.         r = RREG32(RADEON_PCIE_DATA);
  1350.         return r;
  1351. }
  1352.  
  1353. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1354. {
  1355.         WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1356.         WREG32(RADEON_PCIE_DATA, (v));
  1357. }
  1358.  
  1359. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1360.  
  1361.  
  1362. /*
  1363.  * ASICs helpers.
  1364.  */
  1365. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1366.                             (rdev->pdev->device == 0x5969))
  1367. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1368.         (rdev->family == CHIP_RV200) || \
  1369.         (rdev->family == CHIP_RS100) || \
  1370.         (rdev->family == CHIP_RS200) || \
  1371.         (rdev->family == CHIP_RV250) || \
  1372.         (rdev->family == CHIP_RV280) || \
  1373.         (rdev->family == CHIP_RS300))
  1374. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300)  || \
  1375.         (rdev->family == CHIP_RV350) ||         \
  1376.         (rdev->family == CHIP_R350)  ||         \
  1377.         (rdev->family == CHIP_RV380) ||         \
  1378.         (rdev->family == CHIP_R420)  ||         \
  1379.         (rdev->family == CHIP_R423)  ||         \
  1380.         (rdev->family == CHIP_RV410) ||         \
  1381.         (rdev->family == CHIP_RS400) ||         \
  1382.         (rdev->family == CHIP_RS480))
  1383. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1384.                 (rdev->ddev->pdev->device == 0x9443) || \
  1385.                 (rdev->ddev->pdev->device == 0x944B) || \
  1386.                 (rdev->ddev->pdev->device == 0x9506) || \
  1387.                 (rdev->ddev->pdev->device == 0x9509) || \
  1388.                 (rdev->ddev->pdev->device == 0x950F) || \
  1389.                 (rdev->ddev->pdev->device == 0x689C) || \
  1390.                 (rdev->ddev->pdev->device == 0x689D))
  1391. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1392. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600)  ||    \
  1393.                             (rdev->family == CHIP_RS690)  ||    \
  1394.                             (rdev->family == CHIP_RS740)  ||    \
  1395.                             (rdev->family >= CHIP_R600))
  1396. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1397. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1398. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1399. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1400.                              (rdev->flags & RADEON_IS_IGP))
  1401. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1402.  
  1403. /*
  1404.  * BIOS helpers.
  1405.  */
  1406. #define RBIOS8(i) (rdev->bios[i])
  1407. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1408. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1409.  
  1410. int radeon_combios_init(struct radeon_device *rdev);
  1411. void radeon_combios_fini(struct radeon_device *rdev);
  1412. int radeon_atombios_init(struct radeon_device *rdev);
  1413. void radeon_atombios_fini(struct radeon_device *rdev);
  1414.  
  1415.  
  1416. /*
  1417.  * RING helpers.
  1418.  */
  1419. static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
  1420. {
  1421. #if DRM_DEBUG_CODE
  1422.         if (rdev->cp.count_dw <= 0) {
  1423.                 DRM_ERROR("radeon: writting more dword to ring than expected !\n");
  1424.         }
  1425. #endif
  1426.         rdev->cp.ring[rdev->cp.wptr++] = v;
  1427.         rdev->cp.wptr &= rdev->cp.ptr_mask;
  1428.         rdev->cp.count_dw--;
  1429.         rdev->cp.ring_free_dw--;
  1430. }
  1431.  
  1432.  
  1433. /*
  1434.  * ASICs macro.
  1435.  */
  1436. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1437. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1438. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1439. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1440. #define radeon_cs_parse(p) rdev->asic->cs_parse((p))
  1441. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1442. #define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
  1443. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1444. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
  1445. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
  1446. #define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
  1447. #define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
  1448. #define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
  1449. #define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
  1450. #define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
  1451. #define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
  1452. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
  1453. #define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
  1454. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
  1455. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
  1456. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
  1457. #define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
  1458. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
  1459. #define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
  1460. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
  1461. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
  1462. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
  1463. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
  1464. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
  1465. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
  1466. #define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
  1467. #define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
  1468. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
  1469. #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
  1470. #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
  1471. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1472. #define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
  1473. #define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
  1474. #define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
  1475. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
  1476. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
  1477. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
  1478. #define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
  1479. #define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
  1480.  
  1481. /* Common functions */
  1482. /* AGP */
  1483. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1484. extern void radeon_agp_disable(struct radeon_device *rdev);
  1485. extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  1486. extern void radeon_gart_restore(struct radeon_device *rdev);
  1487. extern int radeon_modeset_init(struct radeon_device *rdev);
  1488. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1489. extern bool radeon_card_posted(struct radeon_device *rdev);
  1490. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1491. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1492. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1493. extern void radeon_scratch_init(struct radeon_device *rdev);
  1494. extern void radeon_wb_fini(struct radeon_device *rdev);
  1495. extern int radeon_wb_init(struct radeon_device *rdev);
  1496. extern void radeon_wb_disable(struct radeon_device *rdev);
  1497. extern void radeon_surface_init(struct radeon_device *rdev);
  1498. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1499. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1500. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1501. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1502. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1503. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1504. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1505. extern int radeon_resume_kms(struct drm_device *dev);
  1506. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1507. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1508.  
  1509. /*
  1510.  * r600 functions used by radeon_encoder.c
  1511.  */
  1512. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1513. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1514. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1515.  
  1516. extern int ni_init_microcode(struct radeon_device *rdev);
  1517. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1518.  
  1519. /* radeon_acpi.c */
  1520. #if defined(CONFIG_ACPI)
  1521. extern int radeon_acpi_init(struct radeon_device *rdev);
  1522. #else
  1523. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1524. #endif
  1525.  
  1526. #include "radeon_object.h"
  1527.  
  1528. #define DRM_UDELAY(d)           udelay(d)
  1529.  
  1530. resource_size_t
  1531. drm_get_resource_start(struct drm_device *dev, unsigned int resource);
  1532. resource_size_t
  1533. drm_get_resource_len(struct drm_device *dev, unsigned int resource);
  1534.  
  1535. bool set_mode(struct drm_device *dev, struct drm_connector *connector,
  1536.               videomode_t *mode, bool strict);
  1537.  
  1538.  
  1539.  
  1540. struct work_struct;
  1541. typedef void (*work_func_t)(struct work_struct *work);
  1542.  
  1543. /*
  1544.  * The first word is the work queue pointer and the flags rolled into
  1545.  * one
  1546.  */
  1547. #define work_data_bits(work) ((unsigned long *)(&(work)->data))
  1548.  
  1549. struct work_struct {
  1550.         atomic_long_t data;
  1551. #define WORK_STRUCT_PENDING 0           /* T if work item pending execution */
  1552. #define WORK_STRUCT_FLAG_MASK (3UL)
  1553. #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
  1554.         struct list_head entry;
  1555.         work_func_t func;
  1556. };
  1557.  
  1558. #endif
  1559.