| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [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 |  */ | 
 | 24 | #include "drmP.h" | 
 | 25 | #include "via_drm.h" | 
 | 26 | #include "via_drv.h" | 
 | 27 |  | 
| Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 28 | static int via_do_init_map(struct drm_device * dev, drm_via_init_t * init) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 29 | { | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 30 | 	drm_via_private_t *dev_priv = dev->dev_private; | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 31 |  | 
| Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 32 | 	DRM_DEBUG("\n"); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 33 |  | 
| Dave Airlie | da509d7 | 2007-05-26 05:04:51 +1000 | [diff] [blame] | 34 | 	dev_priv->sarea = drm_getsarea(dev); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 35 | 	if (!dev_priv->sarea) { | 
 | 36 | 		DRM_ERROR("could not find sarea!\n"); | 
 | 37 | 		dev->dev_private = (void *)dev_priv; | 
 | 38 | 		via_do_cleanup_map(dev); | 
 | 39 | 		return -EINVAL; | 
 | 40 | 	} | 
 | 41 |  | 
 | 42 | 	dev_priv->fb = drm_core_findmap(dev, init->fb_offset); | 
 | 43 | 	if (!dev_priv->fb) { | 
 | 44 | 		DRM_ERROR("could not find framebuffer!\n"); | 
 | 45 | 		dev->dev_private = (void *)dev_priv; | 
 | 46 | 		via_do_cleanup_map(dev); | 
 | 47 | 		return -EINVAL; | 
 | 48 | 	} | 
 | 49 | 	dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset); | 
 | 50 | 	if (!dev_priv->mmio) { | 
 | 51 | 		DRM_ERROR("could not find mmio region!\n"); | 
 | 52 | 		dev->dev_private = (void *)dev_priv; | 
 | 53 | 		via_do_cleanup_map(dev); | 
 | 54 | 		return -EINVAL; | 
 | 55 | 	} | 
 | 56 |  | 
 | 57 | 	dev_priv->sarea_priv = | 
 | 58 | 	    (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle + | 
 | 59 | 				 init->sarea_priv_offset); | 
 | 60 |  | 
 | 61 | 	dev_priv->agpAddr = init->agpAddr; | 
 | 62 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 63 | 	via_init_futex(dev_priv); | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 64 |  | 
 | 65 | 	via_init_dmablit(dev); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 66 |  | 
 | 67 | 	dev->dev_private = (void *)dev_priv; | 
 | 68 | 	return 0; | 
 | 69 | } | 
 | 70 |  | 
| Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 71 | int via_do_cleanup_map(struct drm_device * dev) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 72 | { | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 73 | 	via_dma_cleanup(dev); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 74 |  | 
 | 75 | 	return 0; | 
 | 76 | } | 
 | 77 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 78 | int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 79 | { | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 80 | 	drm_via_init_t *init = data; | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 81 |  | 
| Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 82 | 	DRM_DEBUG("\n"); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 83 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 84 | 	switch (init->func) { | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 85 | 	case VIA_INIT_MAP: | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 86 | 		return via_do_init_map(dev, init); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 87 | 	case VIA_CLEANUP_MAP: | 
 | 88 | 		return via_do_cleanup_map(dev); | 
 | 89 | 	} | 
 | 90 |  | 
 | 91 | 	return -EINVAL; | 
 | 92 | } | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 93 |  | 
| Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 94 | int via_driver_load(struct drm_device *dev, unsigned long chipset) | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 95 | { | 
 | 96 | 	drm_via_private_t *dev_priv; | 
| Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 97 | 	int ret = 0; | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 98 |  | 
 | 99 | 	dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER); | 
 | 100 | 	if (dev_priv == NULL) | 
| Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 101 | 		return -ENOMEM; | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 102 |  | 
 | 103 | 	dev->dev_private = (void *)dev_priv; | 
 | 104 |  | 
| Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 105 | 	dev_priv->chipset = chipset; | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 106 |  | 
| Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 107 | 	ret = drm_sman_init(&dev_priv->sman, 2, 12, 8); | 
 | 108 | 	if (ret) { | 
 | 109 | 		drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER); | 
 | 110 | 	} | 
 | 111 | 	return ret; | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 112 | } | 
 | 113 |  | 
| Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 114 | int via_driver_unload(struct drm_device *dev) | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 115 | { | 
 | 116 | 	drm_via_private_t *dev_priv = dev->dev_private; | 
 | 117 |  | 
| Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 118 | 	drm_sman_takedown(&dev_priv->sman); | 
 | 119 |  | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 120 | 	drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER); | 
 | 121 |  | 
 | 122 | 	return 0; | 
 | 123 | } |