Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved. |
| 3 | * Copyright 2001-2003 S3 Graphics, Inc. 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, sub license, |
| 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 |
| 13 | * next paragraph) shall be included in all copies or substantial portions |
| 14 | * 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 NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * VIA, S3 GRAPHICS, 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 | */ |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 24 | #include "drmP.h" |
Dave Airlie | 8727326 | 2004-10-09 12:42:52 +0000 | [diff] [blame] | 25 | #include "via_drm.h" |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 26 | #include "via_drv.h" |
| 27 | |
Dave Airlie | 21ee6fb | 2007-07-16 12:32:51 +1000 | [diff] [blame] | 28 | static int via_do_init_map(struct drm_device * dev, drm_via_init_t * init) |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 29 | { |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 30 | drm_via_private_t *dev_priv = dev->dev_private; |
Thomas Hellstrom | e0f53e5 | 2007-02-16 20:22:24 +0100 | [diff] [blame] | 31 | int ret = 0; |
Jon Smirl | 9f9a8f1 | 2004-09-30 21:12:10 +0000 | [diff] [blame] | 32 | |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 33 | DRM_DEBUG("%s\n", __FUNCTION__); |
| 34 | |
Dave Airlie | 9f9c190 | 2007-04-28 14:49:27 +1000 | [diff] [blame] | 35 | dev_priv->sarea = drm_getsarea(dev); |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 36 | if (!dev_priv->sarea) { |
| 37 | DRM_ERROR("could not find sarea!\n"); |
| 38 | dev->dev_private = (void *)dev_priv; |
| 39 | via_do_cleanup_map(dev); |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | |
Dave Airlie | 5c9ed83 | 2004-08-17 13:10:05 +0000 | [diff] [blame] | 43 | dev_priv->fb = drm_core_findmap(dev, init->fb_offset); |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 44 | if (!dev_priv->fb) { |
| 45 | DRM_ERROR("could not find framebuffer!\n"); |
| 46 | dev->dev_private = (void *)dev_priv; |
| 47 | via_do_cleanup_map(dev); |
| 48 | return -EINVAL; |
| 49 | } |
Dave Airlie | 5c9ed83 | 2004-08-17 13:10:05 +0000 | [diff] [blame] | 50 | dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset); |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 51 | if (!dev_priv->mmio) { |
| 52 | DRM_ERROR("could not find mmio region!\n"); |
| 53 | dev->dev_private = (void *)dev_priv; |
| 54 | via_do_cleanup_map(dev); |
| 55 | return -EINVAL; |
| 56 | } |
Jon Smirl | 9f9a8f1 | 2004-09-30 21:12:10 +0000 | [diff] [blame] | 57 | |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 58 | dev_priv->sarea_priv = |
Jon Smirl | 9f9a8f1 | 2004-09-30 21:12:10 +0000 | [diff] [blame] | 59 | (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle + |
| 60 | init->sarea_priv_offset); |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 61 | |
| 62 | dev_priv->agpAddr = init->agpAddr; |
| 63 | |
Thomas Hellstrom | 532ccb9 | 2005-03-28 21:21:42 +0000 | [diff] [blame] | 64 | via_init_futex( dev_priv ); |
Thomas Hellstrom | 903e570 | 2005-09-25 12:54:12 +0000 | [diff] [blame] | 65 | #ifdef VIA_HAVE_DMABLIT |
| 66 | via_init_dmablit( dev ); |
| 67 | #endif |
Thomas Hellstrom | e0f53e5 | 2007-02-16 20:22:24 +0100 | [diff] [blame] | 68 | #ifdef VIA_HAVE_FENCE |
| 69 | dev_priv->emit_0_sequence = 0; |
| 70 | dev_priv->have_idlelock = 0; |
| 71 | spin_lock_init(&dev_priv->fence_lock); |
| 72 | init_timer(&dev_priv->fence_timer); |
| 73 | dev_priv->fence_timer.function = &via_fence_timer; |
| 74 | dev_priv->fence_timer.data = (unsigned long) dev; |
| 75 | #endif /* VIA_HAVE_FENCE */ |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 76 | dev->dev_private = (void *)dev_priv; |
Thomas Hellstrom | e0f53e5 | 2007-02-16 20:22:24 +0100 | [diff] [blame] | 77 | #ifdef VIA_HAVE_BUFFER |
| 78 | ret = drm_bo_driver_init(dev); |
| 79 | if (ret) |
| 80 | DRM_ERROR("Could not initialize buffer object driver.\n"); |
| 81 | #endif |
| 82 | return ret; |
| 83 | |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Dave Airlie | 21ee6fb | 2007-07-16 12:32:51 +1000 | [diff] [blame] | 86 | int via_do_cleanup_map(struct drm_device * dev) |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 87 | { |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 88 | via_dma_cleanup(dev); |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 93 | |
Eric Anholt | 5b38e13 | 2007-07-19 17:11:11 -0700 | [diff] [blame] | 94 | int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 95 | { |
Eric Anholt | 5b38e13 | 2007-07-19 17:11:11 -0700 | [diff] [blame] | 96 | drm_via_init_t *init = data; |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 97 | |
| 98 | DRM_DEBUG("%s\n", __FUNCTION__); |
| 99 | |
Eric Anholt | 5b38e13 | 2007-07-19 17:11:11 -0700 | [diff] [blame] | 100 | switch (init->func) { |
Jon Smirl | 9f9a8f1 | 2004-09-30 21:12:10 +0000 | [diff] [blame] | 101 | case VIA_INIT_MAP: |
Eric Anholt | 5b38e13 | 2007-07-19 17:11:11 -0700 | [diff] [blame] | 102 | return via_do_init_map(dev, init); |
Jon Smirl | 9f9a8f1 | 2004-09-30 21:12:10 +0000 | [diff] [blame] | 103 | case VIA_CLEANUP_MAP: |
Thomas Hellstrom | 6cd8831 | 2004-03-23 21:08:48 +0000 | [diff] [blame] | 104 | return via_do_cleanup_map(dev); |
| 105 | } |
| 106 | |
| 107 | return -EINVAL; |
| 108 | } |
| 109 | |
Dave Airlie | 21ee6fb | 2007-07-16 12:32:51 +1000 | [diff] [blame] | 110 | int via_driver_load(struct drm_device *dev, unsigned long chipset) |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 111 | { |
| 112 | drm_via_private_t *dev_priv; |
Thomas Hellstrom | 6bacb18 | 2006-06-06 14:19:00 +0000 | [diff] [blame] | 113 | int ret = 0; |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 114 | |
| 115 | dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER); |
| 116 | if (dev_priv == NULL) |
Eric Anholt | e39286e | 2007-07-19 17:00:17 -0700 | [diff] [blame] | 117 | return -ENOMEM; |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 118 | |
| 119 | dev->dev_private = (void *)dev_priv; |
| 120 | |
Thomas Hellstrom | a16a8a4 | 2006-12-28 22:17:08 +0100 | [diff] [blame] | 121 | dev_priv->chipset = chipset; |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 122 | |
Thomas Hellstrom | 6bacb18 | 2006-06-06 14:19:00 +0000 | [diff] [blame] | 123 | #ifdef VIA_HAVE_CORE_MM |
| 124 | ret = drm_sman_init(&dev_priv->sman, 2, 12, 8); |
| 125 | if (ret) { |
| 126 | drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER); |
| 127 | } |
| 128 | #endif |
| 129 | return ret; |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Dave Airlie | 21ee6fb | 2007-07-16 12:32:51 +1000 | [diff] [blame] | 132 | int via_driver_unload(struct drm_device *dev) |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 133 | { |
| 134 | drm_via_private_t *dev_priv = dev->dev_private; |
| 135 | |
Thomas Hellstrom | 6bacb18 | 2006-06-06 14:19:00 +0000 | [diff] [blame] | 136 | #ifdef VIA_HAVE_CORE_MM |
| 137 | drm_sman_takedown(&dev_priv->sman); |
| 138 | #endif |
Eric Anholt | 8c21b78 | 2005-08-15 18:07:12 +0000 | [diff] [blame] | 139 | drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER); |
| 140 | |
| 141 | return 0; |
| 142 | } |
Thomas Hellstrom | d2fd920 | 2005-03-14 22:50:21 +0000 | [diff] [blame] | 143 | |