Nuke device_ptr_t, USBBASEDEVICE, USBDEVNAME(), USBDEVUNIT(), USBGETSOFTC(),
[dragonfly/vkernel-mp.git] / sys / dev / drm / ati_pcigart.h
blob5aa25babae6f53464431e6931592cf5b877b8317
1 /* ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
2 * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
4 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
5 * All Rights Reserved.
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:
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.
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 * PRECISION INSIGHT 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.
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
29 * $FreeBSD: src/sys/dev/drm/ati_pcigart.h,v 1.1.2.1 2003/04/26 07:05:27 anholt Exp $
30 * $DragonFly: src/sys/dev/drm/ati_pcigart.h,v 1.3 2004/02/13 02:23:57 joerg Exp $
33 #include "dev/drm/drmP.h"
35 #if PAGE_SIZE == 8192
36 # define ATI_PCIGART_TABLE_ORDER 2
37 # define ATI_PCIGART_TABLE_PAGES (1 << 2)
38 #elif PAGE_SIZE == 4096
39 # define ATI_PCIGART_TABLE_ORDER 3
40 # define ATI_PCIGART_TABLE_PAGES (1 << 3)
41 #elif
42 # error - PAGE_SIZE not 8K or 4K
43 #endif
45 # define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
46 # define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
48 int DRM(ati_pcigart_init)( drm_device_t *dev,
49 unsigned long *addr,
50 dma_addr_t *bus_addr)
52 drm_sg_mem_t *entry = dev->sg;
53 unsigned long address = 0;
54 unsigned long pages;
55 u32 *pci_gart=0, page_base, bus_address = 0;
56 int i, j, ret = 0;
58 if ( !entry ) {
59 DRM_ERROR( "no scatter/gather memory!\n" );
60 goto done;
63 address = (long)contigmalloc((1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE,
64 DRM(M_DRM), M_WAITOK, 0ul, 0xfffffffful, PAGE_SIZE, 0);
65 if ( !address ) {
66 DRM_ERROR( "cannot allocate PCI GART page!\n" );
67 goto done;
70 /* XXX: we need to busdma this */
71 bus_address = vtophys( address );
73 pci_gart = (u32 *)address;
75 pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
76 ? entry->pages : ATI_MAX_PCIGART_PAGES;
78 bzero( pci_gart, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
80 for ( i = 0 ; i < pages ; i++ ) {
81 entry->busaddr[i] = vtophys( entry->handle + (i*PAGE_SIZE) );
82 page_base = (u32) entry->busaddr[i];
84 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
85 *pci_gart++ = cpu_to_le32( page_base );
86 page_base += ATI_PCIGART_PAGE_SIZE;
90 ret = 1;
92 done:
93 *addr = address;
94 *bus_addr = bus_address;
95 return ret;
98 int DRM(ati_pcigart_cleanup)( drm_device_t *dev,
99 unsigned long addr,
100 dma_addr_t bus_addr)
102 drm_sg_mem_t *entry = dev->sg;
104 /* we need to support large memory configurations */
105 if ( !entry ) {
106 DRM_ERROR( "no scatter/gather memory!\n" );
107 return 0;
110 #if defined(__FreeBSD__) && __FreeBSD_version > 500000
111 contigfree( (void *)addr, (1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, DRM(M_DRM)); /* Not available on 4.x */
112 #endif
113 return 1;