Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
0003  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sub license,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice (including the
0013  * next paragraph) shall be included in all copies or substantial portions
0014  * of the Software.
0015  *
0016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0019  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0020  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0021  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0022  * DEALINGS IN THE SOFTWARE.
0023  */
0024 
0025 #include <linux/pci.h>
0026 
0027 #include <drm/drm_device.h>
0028 #include <drm/drm_vblank.h>
0029 #include <drm/via_drm.h>
0030 
0031 #include "via_drv.h"
0032 
0033 static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init)
0034 {
0035     drm_via_private_t *dev_priv = dev->dev_private;
0036 
0037     DRM_DEBUG("\n");
0038 
0039     dev_priv->sarea = drm_legacy_getsarea(dev);
0040     if (!dev_priv->sarea) {
0041         DRM_ERROR("could not find sarea!\n");
0042         dev->dev_private = (void *)dev_priv;
0043         via_do_cleanup_map(dev);
0044         return -EINVAL;
0045     }
0046 
0047     dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset);
0048     if (!dev_priv->fb) {
0049         DRM_ERROR("could not find framebuffer!\n");
0050         dev->dev_private = (void *)dev_priv;
0051         via_do_cleanup_map(dev);
0052         return -EINVAL;
0053     }
0054     dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset);
0055     if (!dev_priv->mmio) {
0056         DRM_ERROR("could not find mmio region!\n");
0057         dev->dev_private = (void *)dev_priv;
0058         via_do_cleanup_map(dev);
0059         return -EINVAL;
0060     }
0061 
0062     dev_priv->sarea_priv =
0063         (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
0064                  init->sarea_priv_offset);
0065 
0066     dev_priv->agpAddr = init->agpAddr;
0067 
0068     via_init_futex(dev_priv);
0069 
0070     via_init_dmablit(dev);
0071 
0072     dev->dev_private = (void *)dev_priv;
0073     return 0;
0074 }
0075 
0076 int via_do_cleanup_map(struct drm_device *dev)
0077 {
0078     via_dma_cleanup(dev);
0079 
0080     return 0;
0081 }
0082 
0083 int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
0084 {
0085     drm_via_init_t *init = data;
0086 
0087     DRM_DEBUG("\n");
0088 
0089     switch (init->func) {
0090     case VIA_INIT_MAP:
0091         return via_do_init_map(dev, init);
0092     case VIA_CLEANUP_MAP:
0093         return via_do_cleanup_map(dev);
0094     }
0095 
0096     return -EINVAL;
0097 }
0098 
0099 int via_driver_load(struct drm_device *dev, unsigned long chipset)
0100 {
0101     struct pci_dev *pdev = to_pci_dev(dev->dev);
0102     drm_via_private_t *dev_priv;
0103     int ret = 0;
0104 
0105     dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL);
0106     if (dev_priv == NULL)
0107         return -ENOMEM;
0108 
0109     idr_init(&dev_priv->object_idr);
0110     dev->dev_private = (void *)dev_priv;
0111 
0112     dev_priv->chipset = chipset;
0113 
0114     pci_set_master(pdev);
0115 
0116     ret = drm_vblank_init(dev, 1);
0117     if (ret) {
0118         kfree(dev_priv);
0119         return ret;
0120     }
0121 
0122     return 0;
0123 }
0124 
0125 void via_driver_unload(struct drm_device *dev)
0126 {
0127     drm_via_private_t *dev_priv = dev->dev_private;
0128 
0129     idr_destroy(&dev_priv->object_idr);
0130 
0131     kfree(dev_priv);
0132 }