Home | History | Annotate | Line # | Download | only in via
      1 /*	$NetBSD: via_map.c,v 1.3 2021/12/18 23:45:44 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
      5  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
      6  *
      7  * Permission is hereby granted, free of charge, to any person obtaining a
      8  * copy of this software and associated documentation files (the "Software"),
      9  * to deal in the Software without restriction, including without limitation
     10  * the rights to use, copy, modify, merge, publish, distribute, sub license,
     11  * and/or sell copies of the Software, and to permit persons to whom the
     12  * Software is furnished to do so, subject to the following conditions:
     13  *
     14  * The above copyright notice and this permission notice (including the
     15  * next paragraph) shall be included in all copies or substantial portions
     16  * of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     21  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     24  * DEALINGS IN THE SOFTWARE.
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: via_map.c,v 1.3 2021/12/18 23:45:44 riastradh Exp $");
     29 
     30 #include <linux/pci.h>
     31 
     32 #include <drm/drm_device.h>
     33 #include <drm/drm_vblank.h>
     34 #include <drm/via_drm.h>
     35 
     36 #include "via_drv.h"
     37 
     38 static int via_do_init_map(struct drm_device *dev, drm_via_init_t *init)
     39 {
     40 	drm_via_private_t *dev_priv = dev->dev_private;
     41 
     42 	DRM_DEBUG("\n");
     43 
     44 	dev_priv->sarea = drm_legacy_getsarea(dev);
     45 	if (!dev_priv->sarea) {
     46 		DRM_ERROR("could not find sarea!\n");
     47 		dev->dev_private = (void *)dev_priv;
     48 		via_do_cleanup_map(dev);
     49 		return -EINVAL;
     50 	}
     51 
     52 	dev_priv->fb = drm_legacy_findmap(dev, init->fb_offset);
     53 	if (!dev_priv->fb) {
     54 		DRM_ERROR("could not find framebuffer!\n");
     55 		dev->dev_private = (void *)dev_priv;
     56 		via_do_cleanup_map(dev);
     57 		return -EINVAL;
     58 	}
     59 	dev_priv->mmio = drm_legacy_findmap(dev, init->mmio_offset);
     60 	if (!dev_priv->mmio) {
     61 		DRM_ERROR("could not find mmio region!\n");
     62 		dev->dev_private = (void *)dev_priv;
     63 		via_do_cleanup_map(dev);
     64 		return -EINVAL;
     65 	}
     66 
     67 	dev_priv->sarea_priv =
     68 	    (drm_via_sarea_t *) ((u8 *) dev_priv->sarea->handle +
     69 				 init->sarea_priv_offset);
     70 
     71 	dev_priv->agpAddr = init->agpAddr;
     72 
     73 	via_init_futex(dev_priv);
     74 
     75 	via_init_dmablit(dev);
     76 
     77 	dev->dev_private = (void *)dev_priv;
     78 	return 0;
     79 }
     80 
     81 int via_do_cleanup_map(struct drm_device *dev)
     82 {
     83 	via_dma_cleanup(dev);
     84 
     85 	return 0;
     86 }
     87 
     88 int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
     89 {
     90 	drm_via_init_t *init = data;
     91 
     92 	DRM_DEBUG("\n");
     93 
     94 	switch (init->func) {
     95 	case VIA_INIT_MAP:
     96 		return via_do_init_map(dev, init);
     97 	case VIA_CLEANUP_MAP:
     98 		return via_do_cleanup_map(dev);
     99 	}
    100 
    101 	return -EINVAL;
    102 }
    103 
    104 int via_driver_load(struct drm_device *dev, unsigned long chipset)
    105 {
    106 	drm_via_private_t *dev_priv;
    107 	int ret = 0;
    108 
    109 	dev_priv = kzalloc(sizeof(drm_via_private_t), GFP_KERNEL);
    110 	if (dev_priv == NULL)
    111 		return -ENOMEM;
    112 
    113 	idr_init(&dev_priv->object_idr);
    114 	dev->dev_private = (void *)dev_priv;
    115 
    116 	dev_priv->chipset = chipset;
    117 
    118 	pci_set_master(dev->pdev);
    119 
    120 	ret = drm_vblank_init(dev, 1);
    121 	if (ret) {
    122 		kfree(dev_priv);
    123 		return ret;
    124 	}
    125 
    126 	return 0;
    127 }
    128 
    129 void via_driver_unload(struct drm_device *dev)
    130 {
    131 	drm_via_private_t *dev_priv = dev->dev_private;
    132 
    133 	idr_destroy(&dev_priv->object_idr);
    134 
    135 	kfree(dev_priv);
    136 }
    137