blob: c6a08e96285bf55c62a96480c7989ea0632a7419 [file] [log] [blame]
Dave Airlie22f579c2005-06-28 22:48:56 +10001/*
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
28static int via_do_init_map(drm_device_t * dev, drm_via_init_t * init)
29{
Dave Airlie92514242005-11-12 21:52:46 +110030 drm_via_private_t *dev_priv = dev->dev_private;
Dave Airlie22f579c2005-06-28 22:48:56 +100031
32 DRM_DEBUG("%s\n", __FUNCTION__);
33
Dave Airlie22f579c2005-06-28 22:48:56 +100034 DRM_GETSAREA();
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 Airlieb5e89ed2005-09-25 14:28:13 +100063 via_init_futex(dev_priv);
Dave Airlie92514242005-11-12 21:52:46 +110064
65 via_init_dmablit(dev);
Dave Airlie22f579c2005-06-28 22:48:56 +100066
67 dev->dev_private = (void *)dev_priv;
68 return 0;
69}
70
71int via_do_cleanup_map(drm_device_t * dev)
72{
Dave Airlie92514242005-11-12 21:52:46 +110073 via_dma_cleanup(dev);
Dave Airlie22f579c2005-06-28 22:48:56 +100074
75 return 0;
76}
77
78int via_map_init(DRM_IOCTL_ARGS)
79{
80 DRM_DEVICE;
81 drm_via_init_t init;
82
83 DRM_DEBUG("%s\n", __FUNCTION__);
84
Alexey Dobriyanbbaf3642005-07-27 11:43:56 -070085 DRM_COPY_FROM_USER_IOCTL(init, (drm_via_init_t __user *) data,
86 sizeof(init));
Dave Airlie22f579c2005-06-28 22:48:56 +100087
88 switch (init.func) {
89 case VIA_INIT_MAP:
90 return via_do_init_map(dev, &init);
91 case VIA_CLEANUP_MAP:
92 return via_do_cleanup_map(dev);
93 }
94
95 return -EINVAL;
96}
Dave Airlie92514242005-11-12 21:52:46 +110097
98int via_driver_load(drm_device_t *dev, unsigned long chipset)
99{
100 drm_via_private_t *dev_priv;
101
102 dev_priv = drm_calloc(1, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
103 if (dev_priv == NULL)
104 return DRM_ERR(ENOMEM);
105
106 dev->dev_private = (void *)dev_priv;
107
108 if (chipset == VIA_PRO_GROUP_A)
109 dev_priv->pro_group_a = 1;
110
111 return 0;
112}
113
114int via_driver_unload(drm_device_t *dev)
115{
116 drm_via_private_t *dev_priv = dev->dev_private;
117
118 drm_free(dev_priv, sizeof(drm_via_private_t), DRM_MEM_DRIVER);
119
120 return 0;
121}
122