blob: 0b3522dba6e862829c0a4b2abe5e1fefbc461515 [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 */
David Howells760285e2012-10-02 18:01:07 +010024#include <drm/drmP.h>
25#include <drm/via_drm.h>
Dave Airlie22f579c2005-06-28 22:48:56 +100026#include "via_drv.h"
27
Nicolas Kaiser58c1e852010-07-11 15:32:42 +020028static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init)
Dave Airlie22f579c2005-06-28 22:48:56 +100029{
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
Márton Németh3e684ea2008-01-24 15:58:57 +100032 DRM_DEBUG("\n");
Dave Airlie22f579c2005-06-28 22:48:56 +100033
David Herrmann9fc5cde2014-08-29 12:12:28 +020034 dev_priv->sarea = drm_legacy_getsarea(dev);
Dave Airlie22f579c2005-06-28 22:48:56 +100035 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
Daniel Vetter86c1fbd2014-09-10 12:43:56 +020042 dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset);
Dave Airlie22f579c2005-06-28 22:48:56 +100043 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 }
Daniel Vetter86c1fbd2014-09-10 12:43:56 +020049 dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset);
Dave Airlie22f579c2005-06-28 22:48:56 +100050 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
Nicolas Kaiser58c1e852010-07-11 15:32:42 +020071int via_do_cleanup_map(struct drm_device *dev)
Dave Airlie22f579c2005-06-28 22:48:56 +100072{
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
Eric Anholtc153f452007-09-03 12:06:45 +100078int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
Dave Airlie22f579c2005-06-28 22:48:56 +100079{
Eric Anholtc153f452007-09-03 12:06:45 +100080 drm_via_init_t *init = data;
Dave Airlie22f579c2005-06-28 22:48:56 +100081
Márton Németh3e684ea2008-01-24 15:58:57 +100082 DRM_DEBUG("\n");
Dave Airlie22f579c2005-06-28 22:48:56 +100083
Eric Anholtc153f452007-09-03 12:06:45 +100084 switch (init->func) {
Dave Airlie22f579c2005-06-28 22:48:56 +100085 case VIA_INIT_MAP:
Eric Anholtc153f452007-09-03 12:06:45 +100086 return via_do_init_map(dev, init);
Dave Airlie22f579c2005-06-28 22:48:56 +100087 case VIA_CLEANUP_MAP:
88 return via_do_cleanup_map(dev);
89 }
90
91 return -EINVAL;
92}
Dave Airlie92514242005-11-12 21:52:46 +110093
Dave Airlie84b1fd12007-07-11 15:53:27 +100094int via_driver_load(struct drm_device *dev, unsigned long chipset)
Dave Airlie92514242005-11-12 21:52:46 +110095{
96 drm_via_private_t *dev_priv;
Thomas Hellstromce65a442006-08-07 22:03:22 +100097 int ret = 0;
Dave Airlie92514242005-11-12 21:52:46 +110098
Eric Anholt9a298b22009-03-24 12:23:04 -070099 dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL);
Dave Airlie92514242005-11-12 21:52:46 +1100100 if (dev_priv == NULL)
Eric Anholt20caafa2007-08-25 19:22:43 +1000101 return -ENOMEM;
Dave Airlie92514242005-11-12 21:52:46 +1100102
Márton Némethce020ea2012-06-10 23:39:55 +0200103 idr_init(&dev_priv->object_idr);
Dave Airlie92514242005-11-12 21:52:46 +1100104 dev->dev_private = (void *)dev_priv;
105
Thomas Hellstrom689692e2007-01-08 21:19:57 +1100106 dev_priv->chipset = chipset;
Dave Airlie92514242005-11-12 21:52:46 +1100107
Dave Airlie466e69b2011-12-19 11:15:29 +0000108 pci_set_master(dev->pdev);
109
Keith Packard52440212008-11-18 09:30:25 -0800110 ret = drm_vblank_init(dev, 1);
111 if (ret) {
Eric Anholt9a298b22009-03-24 12:23:04 -0700112 kfree(dev_priv);
Keith Packard52440212008-11-18 09:30:25 -0800113 return ret;
114 }
115
116 return 0;
Dave Airlie92514242005-11-12 21:52:46 +1100117}
118
Dave Airlie84b1fd12007-07-11 15:53:27 +1000119int via_driver_unload(struct drm_device *dev)
Dave Airlie92514242005-11-12 21:52:46 +1100120{
121 drm_via_private_t *dev_priv = dev->dev_private;
122
Daniel Vetter6de8a742011-10-25 18:00:41 +0200123 idr_destroy(&dev_priv->object_idr);
Thomas Hellstromce65a442006-08-07 22:03:22 +1000124
Eric Anholt9a298b22009-03-24 12:23:04 -0700125 kfree(dev_priv);
Dave Airlie92514242005-11-12 21:52:46 +1100126
127 return 0;
128}