1 /* drm_agpsupport.h -- DRM support for AGP/GART backend -*- linux-c -*-
2 * Created: Mon Dec 13 09:56:45 1999 by faith@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Gareth Hughes <gareth@valinux.com>
30 * $FreeBSD: src/sys/dev/drm/drm_agpsupport.h,v 1.2.2.1 2003/04/26 07:05:28 anholt Exp $
31 * $DragonFly: src/sys/dev/drm/Attic/drm_agpsupport.h,v 1.2 2003/06/17 04:28:24 dillon Exp $
34 #include "dev/drm/drmP.h"
36 int DRM(agp_info
)(DRM_IOCTL_ARGS
)
39 struct agp_info
*kern
;
42 if (!dev
->agp
|| !dev
->agp
->acquired
)
45 kern
= &dev
->agp
->info
;
46 agp_get_info(dev
->agp
->agpdev
, kern
);
47 info
.agp_version_major
= 1;
48 info
.agp_version_minor
= 0;
49 info
.mode
= kern
->ai_mode
;
50 info
.aperture_base
= kern
->ai_aperture_base
;
51 info
.aperture_size
= kern
->ai_aperture_size
;
52 info
.memory_allowed
= kern
->ai_memory_allowed
;
53 info
.memory_used
= kern
->ai_memory_used
;
54 info
.id_vendor
= kern
->ai_devid
& 0xffff;
55 info
.id_device
= kern
->ai_devid
>> 16;
57 *(drm_agp_info_t
*) data
= info
;
61 int DRM(agp_acquire
)(DRM_IOCTL_ARGS
)
66 if (!dev
->agp
|| dev
->agp
->acquired
)
68 retcode
= agp_acquire(dev
->agp
->agpdev
);
71 dev
->agp
->acquired
= 1;
75 int DRM(agp_release
)(DRM_IOCTL_ARGS
)
79 if (!dev
->agp
|| !dev
->agp
->acquired
)
81 agp_release(dev
->agp
->agpdev
);
82 dev
->agp
->acquired
= 0;
87 void DRM(agp_do_release
)(void)
91 agpdev
= DRM_AGP_FIND_DEVICE();
96 int DRM(agp_enable
)(DRM_IOCTL_ARGS
)
101 if (!dev
->agp
|| !dev
->agp
->acquired
)
104 mode
= *(drm_agp_mode_t
*) data
;
106 dev
->agp
->mode
= mode
.mode
;
107 agp_enable(dev
->agp
->agpdev
, mode
.mode
);
108 dev
->agp
->base
= dev
->agp
->info
.ai_aperture_base
;
109 dev
->agp
->enabled
= 1;
113 int DRM(agp_alloc
)(DRM_IOCTL_ARGS
)
116 drm_agp_buffer_t request
;
117 drm_agp_mem_t
*entry
;
121 struct agp_memory_info info
;
123 if (!dev
->agp
|| !dev
->agp
->acquired
)
126 request
= *(drm_agp_buffer_t
*) data
;
128 if (!(entry
= DRM(alloc
)(sizeof(*entry
), DRM_MEM_AGPLISTS
)))
131 bzero(entry
, sizeof(*entry
));
133 pages
= (request
.size
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
134 type
= (u_int32_t
) request
.type
;
136 if (!(handle
= DRM(alloc_agp
)(pages
, type
))) {
137 DRM(free
)(entry
, sizeof(*entry
), DRM_MEM_AGPLISTS
);
141 entry
->handle
= handle
;
143 entry
->pages
= pages
;
145 entry
->next
= dev
->agp
->memory
;
146 if (dev
->agp
->memory
)
147 dev
->agp
->memory
->prev
= entry
;
148 dev
->agp
->memory
= entry
;
150 agp_memory_info(dev
->agp
->agpdev
, entry
->handle
, &info
);
152 request
.handle
= (unsigned long) entry
->handle
;
153 request
.physical
= info
.ami_physical
;
155 *(drm_agp_buffer_t
*) data
= request
;
160 static drm_agp_mem_t
* DRM(agp_lookup_entry
)(drm_device_t
*dev
, void *handle
)
162 drm_agp_mem_t
*entry
;
164 for (entry
= dev
->agp
->memory
; entry
; entry
= entry
->next
) {
165 if (entry
->handle
== handle
) return entry
;
170 int DRM(agp_unbind
)(DRM_IOCTL_ARGS
)
173 drm_agp_binding_t request
;
174 drm_agp_mem_t
*entry
;
177 if (!dev
->agp
|| !dev
->agp
->acquired
)
179 request
= *(drm_agp_binding_t
*) data
;
180 if (!(entry
= DRM(agp_lookup_entry
)(dev
, (void *) request
.handle
)))
182 if (!entry
->bound
) return EINVAL
;
183 retcode
=DRM(unbind_agp
)(entry
->handle
);
193 int DRM(agp_bind
)(DRM_IOCTL_ARGS
)
196 drm_agp_binding_t request
;
197 drm_agp_mem_t
*entry
;
201 DRM_DEBUG("agp_bind, page_size=%x\n", PAGE_SIZE
);
202 if (!dev
->agp
|| !dev
->agp
->acquired
)
204 request
= *(drm_agp_binding_t
*) data
;
205 if (!(entry
= DRM(agp_lookup_entry
)(dev
, (void *) request
.handle
)))
207 if (entry
->bound
) return EINVAL
;
208 page
= (request
.offset
+ PAGE_SIZE
- 1) / PAGE_SIZE
;
209 if ((retcode
= DRM(bind_agp
)(entry
->handle
, page
)))
211 entry
->bound
= dev
->agp
->base
+ (page
<< PAGE_SHIFT
);
215 int DRM(agp_free
)(DRM_IOCTL_ARGS
)
218 drm_agp_buffer_t request
;
219 drm_agp_mem_t
*entry
;
221 if (!dev
->agp
|| !dev
->agp
->acquired
)
223 request
= *(drm_agp_buffer_t
*) data
;
224 if (!(entry
= DRM(agp_lookup_entry
)(dev
, (void*) request
.handle
)))
227 DRM(unbind_agp
)(entry
->handle
);
230 entry
->prev
->next
= entry
->next
;
232 dev
->agp
->memory
= entry
->next
;
234 entry
->next
->prev
= entry
->prev
;
235 DRM(free_agp
)(entry
->handle
, entry
->pages
);
236 DRM(free
)(entry
, sizeof(*entry
), DRM_MEM_AGPLISTS
);
240 drm_agp_head_t
*DRM(agp_init
)(void)
243 drm_agp_head_t
*head
= NULL
;
244 int agp_available
= 1;
246 agpdev
= DRM_AGP_FIND_DEVICE();
250 DRM_DEBUG("agp_available = %d\n", agp_available
);
253 if (!(head
= DRM(alloc
)(sizeof(*head
), DRM_MEM_AGPLISTS
)))
255 bzero((void *)head
, sizeof(*head
));
256 head
->agpdev
= agpdev
;
257 agp_get_info(agpdev
, &head
->info
);
260 switch (head
->agp_info
.chipset
) {
261 case INTEL_GENERIC
: head
->chipset
= "Intel"; break;
262 case INTEL_LX
: head
->chipset
= "Intel 440LX"; break;
263 case INTEL_BX
: head
->chipset
= "Intel 440BX"; break;
264 case INTEL_GX
: head
->chipset
= "Intel 440GX"; break;
265 case INTEL_I810
: head
->chipset
= "Intel i810"; break;
266 case VIA_GENERIC
: head
->chipset
= "VIA"; break;
267 case VIA_VP3
: head
->chipset
= "VIA VP3"; break;
268 case VIA_MVP3
: head
->chipset
= "VIA MVP3"; break;
269 case VIA_APOLLO_PRO
: head
->chipset
= "VIA Apollo Pro"; break;
270 case SIS_GENERIC
: head
->chipset
= "SiS"; break;
271 case AMD_GENERIC
: head
->chipset
= "AMD"; break;
272 case AMD_IRONGATE
: head
->chipset
= "AMD Irongate"; break;
273 case ALI_GENERIC
: head
->chipset
= "ALi"; break;
274 case ALI_M1541
: head
->chipset
= "ALi M1541"; break;
278 DRM_INFO("AGP at 0x%08lx %dMB\n",
279 (long)head
->info
.ai_aperture_base
,
280 (int)(head
->info
.ai_aperture_size
>> 20));
285 void DRM(agp_uninit
)(void)
287 /* FIXME: What goes here */
291 agp_memory
*DRM(agp_allocate_memory
)(size_t pages
, u32 type
)
295 agpdev
= DRM_AGP_FIND_DEVICE();
299 return agp_alloc_memory(agpdev
, type
, pages
<< AGP_PAGE_SHIFT
);
302 int DRM(agp_free_memory
)(agp_memory
*handle
)
306 agpdev
= DRM_AGP_FIND_DEVICE();
307 if (!agpdev
|| !handle
)
310 agp_free_memory(agpdev
, handle
);
314 int DRM(agp_bind_memory
)(agp_memory
*handle
, off_t start
)
318 agpdev
= DRM_AGP_FIND_DEVICE();
319 if (!agpdev
|| !handle
)
322 return agp_bind_memory(agpdev
, handle
, start
* PAGE_SIZE
);
325 int DRM(agp_unbind_memory
)(agp_memory
*handle
)
329 agpdev
= DRM_AGP_FIND_DEVICE();
330 if (!agpdev
|| !handle
)
333 return agp_unbind_memory(agpdev
, handle
);