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