Merge commit 'origin/drm-gem' into ms-gem
[platform/upstream/libdrm.git] / shared-core / radeon_ms_family.c
1 /*
2  * Copyright 2007 Jérôme Glisse
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * 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  * PRECISION INSIGHT AND/OR ITS SUPPLIERS 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 OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * Authors:
26  *    Jerome Glisse <glisse@freedesktop.org>
27  */
28 #include "drmP.h"
29 #include "drm.h"
30 #include "radeon_ms.h"
31
32 extern const uint32_t radeon_cp_microcode[];
33 extern const uint32_t r200_cp_microcode[];
34 extern const uint32_t r300_cp_microcode[];
35
36 static void radeon_flush_cache(struct drm_device *dev)
37 {
38         struct drm_radeon_private *dev_priv = dev->dev_private;
39         uint32_t cmd[6];
40         int i, ret;
41
42         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
43         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
44         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT, 0);
45         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
46         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT, 0);
47         cmd[5] = RB3D_ZCACHE_CTLSTAT__ZC_FLUSH;
48         /* try to wait but if we timeout we likely are in bad situation */
49         for (i = 0; i < dev_priv->usec_timeout; i++) {
50                 ret = radeon_ms_ring_emit(dev, cmd, 6);
51                 if (!ret) {
52                         break;
53                 }
54         }
55 }
56
57 static void r300_flush_cache(struct drm_device *dev)
58 {
59         struct drm_radeon_private *dev_priv = dev->dev_private;
60         uint32_t cmd[6];
61         int i, ret;
62
63         cmd[0] = CP_PACKET0(RB2D_DSTCACHE_CTLSTAT, 0);
64         cmd[1] = REG_S(RB2D_DSTCACHE_CTLSTAT, DC_FLUSH, 3);
65         cmd[2] = CP_PACKET0(RB3D_DSTCACHE_CTLSTAT_R3, 0);
66         cmd[3] = REG_S(RB3D_DSTCACHE_CTLSTAT_R3, DC_FLUSH, 3);
67         cmd[4] = CP_PACKET0(RB3D_ZCACHE_CTLSTAT_R3, 0);
68         cmd[5] = RB3D_ZCACHE_CTLSTAT_R3__ZC_FLUSH;
69         /* try to wait but if we timeout we likely are in bad situation */
70         for (i = 0; i < dev_priv->usec_timeout; i++) {
71                 ret = radeon_ms_ring_emit(dev, cmd, 6);
72                 if (!ret) {
73                         break;
74                 }
75         }
76 }
77
78 int radeon_ms_family_init(struct drm_device *dev)
79 {
80         struct drm_radeon_private *dev_priv = dev->dev_private;
81         int ret;
82
83         dev_priv->microcode = radeon_cp_microcode;
84         dev_priv->irq_emit = radeon_ms_irq_emit;
85
86         switch (dev_priv->family) {
87         case CHIP_R100:
88         case CHIP_R200:
89                 dev_priv->microcode = radeon_cp_microcode;
90                 dev_priv->flush_cache = radeon_flush_cache;
91                 break;
92         case CHIP_RV200:
93         case CHIP_RV250:
94         case CHIP_RV280:
95         case CHIP_RS300:
96                 dev_priv->microcode = r200_cp_microcode;
97                 dev_priv->flush_cache = radeon_flush_cache;
98                 break;
99         case CHIP_R300:
100         case CHIP_R350:
101         case CHIP_R360:
102         case CHIP_RV350:
103         case CHIP_RV370:
104         case CHIP_RV380:
105         case CHIP_RS400:
106         case CHIP_RV410:
107         case CHIP_R420:
108         case CHIP_R430:
109         case CHIP_R480:
110                 dev_priv->microcode = r300_cp_microcode;
111                 dev_priv->flush_cache = r300_flush_cache;
112                 break;
113         default:
114                 DRM_ERROR("Unknown radeon family, aborting\n");
115                 return -EINVAL;
116         }
117         switch (dev_priv->bus_type) {
118         case RADEON_AGP:
119                 dev_priv->create_ttm = drm_agp_init_ttm;
120                 dev_priv->bus_finish = radeon_ms_agp_finish;
121                 dev_priv->bus_init = radeon_ms_agp_init;
122                 dev_priv->bus_restore = radeon_ms_agp_restore;
123                 dev_priv->bus_save = radeon_ms_agp_save;
124                 break;
125         case RADEON_PCIE:
126                 dev_priv->create_ttm = radeon_ms_pcie_create_ttm;
127                 dev_priv->bus_finish = radeon_ms_pcie_finish;
128                 dev_priv->bus_init = radeon_ms_pcie_init;
129                 dev_priv->bus_restore = radeon_ms_pcie_restore;
130                 dev_priv->bus_save = radeon_ms_pcie_save;
131                 break;
132         default:
133                 DRM_ERROR("Unknown radeon bus type, aborting\n");
134                 return -EINVAL;
135         }
136         ret = radeon_ms_rom_init(dev);
137         if (ret) {
138                 return ret;
139         }
140         ret = radeon_ms_properties_init(dev);
141         return ret;
142 }