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 | */ | |
760285e7 DH |
24 | #include <drm/drmP.h> |
25 | #include <drm/via_drm.h> | |
22f579c6 DA |
26 | #include "via_drv.h" |
27 | ||
58c1e85a | 28 | static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init) |
22f579c6 | 29 | { |
92514243 | 30 | drm_via_private_t *dev_priv = dev->dev_private; |
22f579c6 | 31 | |
3e684eae | 32 | DRM_DEBUG("\n"); |
22f579c6 | 33 | |
da509d7a | 34 | dev_priv->sarea = drm_getsarea(dev); |
22f579c6 DA |
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 | ||
b5e89ed5 | 63 | via_init_futex(dev_priv); |
92514243 DA |
64 | |
65 | via_init_dmablit(dev); | |
22f579c6 DA |
66 | |
67 | dev->dev_private = (void *)dev_priv; | |
68 | return 0; | |
69 | } | |
70 | ||
58c1e85a | 71 | int via_do_cleanup_map(struct drm_device *dev) |
22f579c6 | 72 | { |
92514243 | 73 | via_dma_cleanup(dev); |
22f579c6 DA |
74 | |
75 | return 0; | |
76 | } | |
77 | ||
c153f45f | 78 | int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
22f579c6 | 79 | { |
c153f45f | 80 | drm_via_init_t *init = data; |
22f579c6 | 81 | |
3e684eae | 82 | DRM_DEBUG("\n"); |
22f579c6 | 83 | |
c153f45f | 84 | switch (init->func) { |
22f579c6 | 85 | case VIA_INIT_MAP: |
c153f45f | 86 | return via_do_init_map(dev, init); |
22f579c6 DA |
87 | case VIA_CLEANUP_MAP: |
88 | return via_do_cleanup_map(dev); | |
89 | } | |
90 | ||
91 | return -EINVAL; | |
92 | } | |
92514243 | 93 | |
84b1fd10 | 94 | int via_driver_load(struct drm_device *dev, unsigned long chipset) |
92514243 DA |
95 | { |
96 | drm_via_private_t *dev_priv; | |
ce65a44d | 97 | int ret = 0; |
92514243 | 98 | |
9a298b2a | 99 | dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL); |
92514243 | 100 | if (dev_priv == NULL) |
20caafa6 | 101 | return -ENOMEM; |
92514243 | 102 | |
ce020ea5 | 103 | idr_init(&dev_priv->object_idr); |
92514243 DA |
104 | dev->dev_private = (void *)dev_priv; |
105 | ||
689692e7 | 106 | dev_priv->chipset = chipset; |
92514243 | 107 | |
466e69b8 DA |
108 | pci_set_master(dev->pdev); |
109 | ||
52440211 KP |
110 | ret = drm_vblank_init(dev, 1); |
111 | if (ret) { | |
9a298b2a | 112 | kfree(dev_priv); |
52440211 KP |
113 | return ret; |
114 | } | |
115 | ||
116 | return 0; | |
92514243 DA |
117 | } |
118 | ||
84b1fd10 | 119 | int via_driver_unload(struct drm_device *dev) |
92514243 DA |
120 | { |
121 | drm_via_private_t *dev_priv = dev->dev_private; | |
122 | ||
6de8a748 | 123 | idr_destroy(&dev_priv->object_idr); |
ce65a44d | 124 | |
9a298b2a | 125 | kfree(dev_priv); |
92514243 DA |
126 | |
127 | return 0; | |
128 | } |