88316100389b114929d2374154bad46b5a10cf6f
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / nv04_instmem.c
1 #include "drmP.h"
2 #include "drm.h"
3 #include "nouveau_drv.h"
4 #include "nouveau_ramht.h"
5
6 /* returns the size of fifo context */
7 static int
8 nouveau_fifo_ctx_size(struct drm_device *dev)
9 {
10         struct drm_nouveau_private *dev_priv = dev->dev_private;
11
12         if (dev_priv->chipset >= 0x40)
13                 return 128;
14         else
15         if (dev_priv->chipset >= 0x17)
16                 return 64;
17
18         return 32;
19 }
20
21 int nv04_instmem_init(struct drm_device *dev)
22 {
23         struct drm_nouveau_private *dev_priv = dev->dev_private;
24         struct nouveau_gpuobj *ramht = NULL;
25         u32 offset, length;
26         int ret;
27
28         /* Setup shared RAMHT */
29         ret = nouveau_gpuobj_new_fake(dev, 0x10000, ~0, 4096,
30                                       NVOBJ_FLAG_ZERO_ALLOC, &ramht);
31         if (ret)
32                 return ret;
33
34         ret = nouveau_ramht_new(dev, ramht, &dev_priv->ramht);
35         nouveau_gpuobj_ref(NULL, &ramht);
36         if (ret)
37                 return ret;
38
39         /* And RAMRO */
40         ret = nouveau_gpuobj_new_fake(dev, 0x11200, ~0, 512,
41                                       NVOBJ_FLAG_ZERO_ALLOC, &dev_priv->ramro);
42         if (ret)
43                 return ret;
44
45         /* And RAMFC */
46         length = dev_priv->engine.fifo.channels * nouveau_fifo_ctx_size(dev);
47         switch (dev_priv->card_type) {
48         case NV_40:
49                 offset = 0x20000;
50                 break;
51         default:
52                 offset = 0x11400;
53                 break;
54         }
55
56         ret = nouveau_gpuobj_new_fake(dev, offset, ~0, length,
57                                       NVOBJ_FLAG_ZERO_ALLOC, &dev_priv->ramfc);
58         if (ret)
59                 return ret;
60
61         /* Only allow space after RAMFC to be used for object allocation */
62         offset += length;
63
64         /* It appears RAMRO (or something?) is controlled by 0x2220/0x2230
65          * on certain NV4x chipsets as well as RAMFC.  When 0x2230 == 0
66          * ("new style" control) the upper 16-bits of 0x2220 points at this
67          * other mysterious table that's clobbering important things.
68          *
69          * We're now pointing this at RAMIN+0x30000 to avoid RAMFC getting
70          * smashed to pieces on us, so reserve 0x30000-0x40000 too..
71          */
72         if (dev_priv->card_type >= NV_40) {
73                 if (offset < 0x40000)
74                         offset = 0x40000;
75         }
76
77         ret = drm_mm_init(&dev_priv->ramin_heap, offset,
78                           dev_priv->ramin_rsvd_vram - offset);
79         if (ret) {
80                 NV_ERROR(dev, "Failed to init RAMIN heap: %d\n", ret);
81                 return ret;
82         }
83
84         dev_priv->ramin_available = true;
85         return 0;
86 }
87
88 void
89 nv04_instmem_takedown(struct drm_device *dev)
90 {
91         struct drm_nouveau_private *dev_priv = dev->dev_private;
92
93         nouveau_ramht_ref(NULL, &dev_priv->ramht, NULL);
94         nouveau_gpuobj_ref(NULL, &dev_priv->ramro);
95         nouveau_gpuobj_ref(NULL, &dev_priv->ramfc);
96 }
97
98 int
99 nv04_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj,
100                       uint32_t *sz)
101 {
102         return 0;
103 }
104
105 void
106 nv04_instmem_clear(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
107 {
108 }
109
110 int
111 nv04_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
112 {
113         return 0;
114 }
115
116 int
117 nv04_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
118 {
119         return 0;
120 }
121
122 void
123 nv04_instmem_flush(struct drm_device *dev)
124 {
125 }
126
127 int
128 nv04_instmem_suspend(struct drm_device *dev)
129 {
130         return 0;
131 }
132
133 void
134 nv04_instmem_resume(struct drm_device *dev)
135 {
136 }
137