nouveau: simplify PRAMIN access
authorBen Skeggs <skeggsb@gmail.com>
Mon, 25 Jun 2007 05:16:19 +0000 (15:16 +1000)
committerBen Skeggs <skeggsb@gmail.com>
Wed, 27 Jun 2007 17:26:44 +0000 (03:26 +1000)
shared-core/nouveau_drv.h
shared-core/nouveau_mem.c
shared-core/nouveau_state.c

index f549e60..b2ddf0a 100644 (file)
@@ -220,11 +220,6 @@ extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
                                               uint32_t size, uint32_t align);
 extern void              nouveau_instmem_free(struct drm_device *dev,
                                              struct mem_block *block);
-extern uint32_t          nouveau_instmem_r32(drm_nouveau_private_t *dev_priv,
-                                            struct mem_block *mem, int index);
-extern void              nouveau_instmem_w32(drm_nouveau_private_t *dev_priv,
-                                            struct mem_block *mem, int index,
-                                            uint32_t val);
 
 /* nouveau_notifier.c */
 extern int  nouveau_notifier_init_channel(drm_device_t *, int channel, DRMFILE);
@@ -381,8 +376,17 @@ extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
 #endif
 
-#define INSTANCE_WR(mem,ofs,val) nouveau_instmem_w32(dev_priv,(mem),(ofs),(val))
-#define INSTANCE_RD(mem,ofs)     nouveau_instmem_r32(dev_priv,(mem),(ofs))
+/* PRAMIN access */
+#if defined(__powerpc__)
+#define NV_RI32(o) in_be32((void __iomem *)(dev_priv->ramin)->handle+(o))
+#define NV_WI32(o,v) out_be32((void __iomem*)(dev_priv->ramin)->handle+(o), (v))
+#else
+#define NV_RI32(o) DRM_READ32(dev_priv->ramin, (o))
+#define NV_WI32(o,v) DRM_WRITE32(dev_priv->ramin, (o), (v))
+#endif
+
+#define INSTANCE_RD(o,i) NV_RI32((o)->start + ((i)<<2))
+#define INSTANCE_WR(o,i,v) NV_WI32((o)->start + ((i)<<2), (v))
 
 #endif /* __NOUVEAU_DRV_H__ */
 
index edfc9d3..4c6d0d5 100644 (file)
@@ -602,38 +602,6 @@ void nouveau_instmem_free(struct drm_device *dev, struct mem_block *block)
        }
 }
 
-uint32_t nouveau_instmem_r32(drm_nouveau_private_t *dev_priv,
-                            struct mem_block *mem, int index)
-{
-       uint32_t ofs = (uint32_t)mem->start + (index<<2);
-
-       if (dev_priv->ramin) {
-#if defined(__powerpc__)
-               return in_be32((void __iomem *)(dev_priv->ramin)->handle + ofs);
-#else
-               return DRM_READ32(dev_priv->ramin, ofs);
-#endif
-       } else {
-               return NV_READ(NV_RAMIN+ofs);
-       }
-}
-
-void nouveau_instmem_w32(drm_nouveau_private_t *dev_priv,
-                        struct mem_block *mem, int index, uint32_t val)
-{
-       uint32_t ofs = (uint32_t)mem->start + (index<<2);
-
-       if (dev_priv->ramin) {
-#if defined(__powerpc__)
-               out_be32((void __iomem *)(dev_priv->ramin)->handle + ofs, val);
-#else
-               DRM_WRITE32(dev_priv->ramin, ofs, val);
-#endif
-       } else {
-               NV_WRITE(NV_RAMIN+ofs, val);
-       }
-}
-
 /*
  * Ioctls
  */
index 0cb8235..94d8081 100644 (file)
@@ -51,6 +51,7 @@ static int nouveau_init_card_mappings(drm_device_t *dev)
        DRM_DEBUG("regs mapped ok at 0x%lx\n", dev_priv->mmio->offset);
 
        /* map larger RAMIN aperture on NV40 cards */
+       dev_priv->ramin = NULL;
        if (dev_priv->card_type >= NV_40) {
                int ramin_resource = 2;
                if (drm_get_resource_len(dev, ramin_resource) == 0)
@@ -66,8 +67,21 @@ static int nouveau_init_card_mappings(drm_device_t *dev)
                                  "limited instance memory available\n");
                        dev_priv->ramin = NULL;
                }
-       } else
-               dev_priv->ramin = NULL;
+       }
+
+       /* On older cards (or if the above failed), create a map covering
+        * the BAR0 PRAMIN aperture */
+       if (!dev_priv->ramin) {
+               ret = drm_addmap(dev,
+                                drm_get_resource_start(dev, 0) + NV_RAMIN,
+                                (1*1024*1024),
+                                _DRM_REGISTERS, _DRM_READ_ONLY,
+                                &dev_priv->ramin);
+               if (ret) {
+                       DRM_ERROR("Failed to map BAR0 PRAMIN: %d\n", ret);
+                       return ret;
+               }
+       }
 
        return 0;
 }