1 /* $OpenBSD: drm_agpsupport.c,v 1.27 2019/04/14 10:14:51 jsg Exp $ */ 2 /*- 3 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 4 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 5 * 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, sublicense, 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 next 15 * paragraph) shall be included in all copies or substantial portions of the 16 * 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 NONINFRINGEMENT. IN NO EVENT SHALL 21 * VA LINUX SYSTEMS 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 24 * OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Author: 27 * Rickard E. (Rik) Faith <faith@valinux.com> 28 * Gareth Hughes <gareth@valinux.com> 29 * 30 */ 31 32 /* 33 * Support code for tying the kernel AGP support to DRM drivers. 34 */ 35 36 #include <drm/drmP.h> 37 38 #if IS_ENABLED(CONFIG_AGP) 39 40 int 41 drm_agp_info(struct drm_device * dev, struct drm_agp_info *info) 42 { 43 struct agp_info *kern; 44 45 if (dev->agp == NULL || !dev->agp->acquired) 46 return (EINVAL); 47 48 kern = &dev->agp->info; 49 agp_get_info(dev->agp->agpdev, kern); 50 info->agp_version_major = 1; 51 info->agp_version_minor = 0; 52 info->mode = kern->ai_mode; 53 info->aperture_base = kern->ai_aperture_base; 54 info->aperture_size = kern->ai_aperture_size; 55 info->memory_allowed = kern->ai_memory_allowed; 56 info->memory_used = kern->ai_memory_used; 57 info->id_vendor = kern->ai_devid & 0xffff; 58 info->id_device = kern->ai_devid >> 16; 59 60 return (0); 61 } 62 63 int 64 drm_agp_acquire(struct drm_device *dev) 65 { 66 int retcode; 67 68 if (dev->agp == NULL || dev->agp->acquired) 69 return (EINVAL); 70 71 retcode = agp_acquire(dev->agp->agpdev); 72 if (retcode) 73 return (retcode); 74 75 dev->agp->acquired = 1; 76 77 return (0); 78 } 79 80 int 81 drm_agp_release(struct drm_device * dev) 82 { 83 if (dev->agp == NULL || !dev->agp->acquired) 84 return (EINVAL); 85 agp_release(dev->agp->agpdev); 86 dev->agp->acquired = 0; 87 88 return (0); 89 } 90 91 int 92 drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode) 93 { 94 int retcode = 0; 95 96 if (dev->agp == NULL || !dev->agp->acquired) 97 return (EINVAL); 98 99 dev->agp->mode = mode.mode; 100 if ((retcode = agp_enable(dev->agp->agpdev, mode.mode)) == 0) 101 dev->agp->enabled = 1; 102 return (retcode); 103 } 104 105 void 106 drm_agp_takedown(struct drm_device *dev) 107 { 108 if (dev->agp == NULL) 109 return; 110 111 drm_agp_release(dev); 112 dev->agp->enabled = 0; 113 } 114 115 struct drm_agp_head * 116 drm_agp_init(void) 117 { 118 struct agp_softc *agpdev; 119 struct drm_agp_head *head = NULL; 120 int agp_available = 1; 121 122 agpdev = agp_find_device(0); 123 if (agpdev == NULL) 124 agp_available = 0; 125 126 DRM_DEBUG("agp_available = %d\n", agp_available); 127 128 if (agp_available) { 129 head = mallocarray(1, sizeof(*head), M_DRM, M_NOWAIT | M_ZERO); 130 if (head == NULL) 131 return (NULL); 132 head->agpdev = agpdev; 133 agp_get_info(agpdev, &head->info); 134 head->base = head->info.ai_aperture_base; 135 head->cant_use_aperture = (head->base == 0); 136 TAILQ_INIT(&head->memory); 137 } 138 return (head); 139 } 140 141 #endif /* IS_ENABLED(CONFIG_AGP) */ 142