Line data Source code
1 : /* $OpenBSD: drm_agpsupport.c,v 1.26 2014/03/13 13:35:21 kettenis 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 "drmP.h"
37 :
38 : #if __OS_HAS_AGP
39 :
40 : int
41 0 : drm_agp_info(struct drm_device * dev, struct drm_agp_info *info)
42 : {
43 : struct agp_info *kern;
44 :
45 0 : if (dev->agp == NULL || !dev->agp->acquired)
46 0 : return (EINVAL);
47 :
48 0 : kern = &dev->agp->info;
49 0 : agp_get_info(dev->agp->agpdev, kern);
50 0 : info->agp_version_major = 1;
51 0 : info->agp_version_minor = 0;
52 0 : info->mode = kern->ai_mode;
53 0 : info->aperture_base = kern->ai_aperture_base;
54 0 : info->aperture_size = kern->ai_aperture_size;
55 0 : info->memory_allowed = kern->ai_memory_allowed;
56 0 : info->memory_used = kern->ai_memory_used;
57 0 : info->id_vendor = kern->ai_devid & 0xffff;
58 0 : info->id_device = kern->ai_devid >> 16;
59 :
60 0 : return (0);
61 0 : }
62 :
63 : int
64 0 : drm_agp_acquire(struct drm_device *dev)
65 : {
66 : int retcode;
67 :
68 0 : if (dev->agp == NULL || dev->agp->acquired)
69 0 : return (EINVAL);
70 :
71 0 : retcode = agp_acquire(dev->agp->agpdev);
72 0 : if (retcode)
73 0 : return (retcode);
74 :
75 0 : dev->agp->acquired = 1;
76 :
77 0 : return (0);
78 0 : }
79 :
80 : int
81 0 : drm_agp_release(struct drm_device * dev)
82 : {
83 0 : if (dev->agp == NULL || !dev->agp->acquired)
84 0 : return (EINVAL);
85 0 : agp_release(dev->agp->agpdev);
86 0 : dev->agp->acquired = 0;
87 :
88 0 : return (0);
89 0 : }
90 :
91 : int
92 0 : drm_agp_enable(struct drm_device *dev, drm_agp_mode_t mode)
93 : {
94 : int retcode = 0;
95 :
96 0 : if (dev->agp == NULL || !dev->agp->acquired)
97 0 : return (EINVAL);
98 :
99 0 : dev->agp->mode = mode.mode;
100 0 : if ((retcode = agp_enable(dev->agp->agpdev, mode.mode)) == 0)
101 0 : dev->agp->enabled = 1;
102 0 : return (retcode);
103 0 : }
104 :
105 : void
106 0 : drm_agp_takedown(struct drm_device *dev)
107 : {
108 0 : if (dev->agp == NULL)
109 : return;
110 :
111 0 : drm_agp_release(dev);
112 0 : dev->agp->enabled = 0;
113 0 : }
114 :
115 : struct drm_agp_head *
116 0 : drm_agp_init(void)
117 : {
118 : struct agp_softc *agpdev;
119 : struct drm_agp_head *head = NULL;
120 : int agp_available = 1;
121 :
122 0 : agpdev = agp_find_device(0);
123 0 : if (agpdev == NULL)
124 0 : agp_available = 0;
125 :
126 : DRM_DEBUG("agp_available = %d\n", agp_available);
127 :
128 0 : if (agp_available) {
129 0 : head = drm_calloc(1, sizeof(*head));
130 0 : if (head == NULL)
131 0 : return (NULL);
132 0 : head->agpdev = agpdev;
133 0 : agp_get_info(agpdev, &head->info);
134 0 : head->base = head->info.ai_aperture_base;
135 0 : head->cant_use_aperture = (head->base == 0);
136 0 : TAILQ_INIT(&head->memory);
137 0 : }
138 0 : return (head);
139 0 : }
140 :
141 : #endif /* __OS_HAS_AGP */
|