]>
Commit | Line | Data |
---|---|---|
22f579c6 DA |
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 | */ | |
0005cbda | 24 | |
02c484a8 TZ |
25 | #include <linux/pci.h> |
26 | ||
0005cbda | 27 | #include <drm/drm_device.h> |
0005cbda | 28 | #include <drm/drm_vblank.h> |
760285e7 | 29 | #include <drm/via_drm.h> |
0005cbda | 30 | |
22f579c6 DA |
31 | #include "via_drv.h" |
32 | ||
58c1e85a | 33 | static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init) |
22f579c6 | 34 | { |
92514243 | 35 | drm_via_private_t *dev_priv = dev->dev_private; |
22f579c6 | 36 | |
3e684eae | 37 | DRM_DEBUG("\n"); |
22f579c6 | 38 | |
9fc5cde7 | 39 | dev_priv->sarea = drm_legacy_getsarea(dev); |
22f579c6 DA |
40 | if (!dev_priv->sarea) { |
41 | DRM_ERROR("could not find sarea!\n"); | |
42 | dev->dev_private = (void *)dev_priv; | |
43 | via_do_cleanup_map(dev); | |
44 | return -EINVAL; | |
45 | } | |
46 | ||
86c1fbd5 | 47 | dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset); |
22f579c6 DA |
48 | if (!dev_priv->fb) { |
49 | DRM_ERROR("could not find framebuffer!\n"); | |
50 | dev->dev_private = (void *)dev_priv; | |
51 | via_do_cleanup_map(dev); | |
52 | return -EINVAL; | |
53 | } | |
86c1fbd5 | 54 | dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset); |
22f579c6 DA |
55 | if (!dev_priv->mmio) { |
56 | DRM_ERROR("could not find mmio region!\n"); | |
57 | dev->dev_private = (void *)dev_priv; | |
58 | via_do_cleanup_map(dev); | |
59 | return -EINVAL; | |
60 | } | |
61 | ||
62 | dev_priv->sarea_priv = | |
63 | (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle + | |
64 | init->sarea_priv_offset); | |
65 | ||
66 | dev_priv->agpAddr = init->agpAddr; | |
67 | ||
b5e89ed5 | 68 | via_init_futex(dev_priv); |
92514243 DA |
69 | |
70 | via_init_dmablit(dev); | |
22f579c6 DA |
71 | |
72 | dev->dev_private = (void *)dev_priv; | |
73 | return 0; | |
74 | } | |
75 | ||
58c1e85a | 76 | int via_do_cleanup_map(struct drm_device *dev) |
22f579c6 | 77 | { |
92514243 | 78 | via_dma_cleanup(dev); |
22f579c6 DA |
79 | |
80 | return 0; | |
81 | } | |
82 | ||
c153f45f | 83 | int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
22f579c6 | 84 | { |
c153f45f | 85 | drm_via_init_t *init = data; |
22f579c6 | 86 | |
3e684eae | 87 | DRM_DEBUG("\n"); |
22f579c6 | 88 | |
c153f45f | 89 | switch (init->func) { |
22f579c6 | 90 | case VIA_INIT_MAP: |
c153f45f | 91 | return via_do_init_map(dev, init); |
22f579c6 DA |
92 | case VIA_CLEANUP_MAP: |
93 | return via_do_cleanup_map(dev); | |
94 | } | |
95 | ||
96 | return -EINVAL; | |
97 | } | |
92514243 | 98 | |
84b1fd10 | 99 | int via_driver_load(struct drm_device *dev, unsigned long chipset) |
92514243 DA |
100 | { |
101 | drm_via_private_t *dev_priv; | |
ce65a44d | 102 | int ret = 0; |
92514243 | 103 | |
9a298b2a | 104 | dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL); |
92514243 | 105 | if (dev_priv == NULL) |
20caafa6 | 106 | return -ENOMEM; |
92514243 | 107 | |
ce020ea5 | 108 | idr_init(&dev_priv->object_idr); |
92514243 DA |
109 | dev->dev_private = (void *)dev_priv; |
110 | ||
689692e7 | 111 | dev_priv->chipset = chipset; |
92514243 | 112 | |
466e69b8 DA |
113 | pci_set_master(dev->pdev); |
114 | ||
52440211 KP |
115 | ret = drm_vblank_init(dev, 1); |
116 | if (ret) { | |
9a298b2a | 117 | kfree(dev_priv); |
52440211 KP |
118 | return ret; |
119 | } | |
120 | ||
121 | return 0; | |
92514243 DA |
122 | } |
123 | ||
11b3c20b | 124 | void via_driver_unload(struct drm_device *dev) |
92514243 DA |
125 | { |
126 | drm_via_private_t *dev_priv = dev->dev_private; | |
127 | ||
6de8a748 | 128 | idr_destroy(&dev_priv->object_idr); |
ce65a44d | 129 | |
9a298b2a | 130 | kfree(dev_priv); |
92514243 | 131 | } |