]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/drm/ati_pcigart.c
This commit was generated by cvs2svn to compensate for changes in r151513,
[FreeBSD/FreeBSD.git] / sys / dev / drm / ati_pcigart.c
1 /* ati_pcigart.h -- ATI PCI GART support -*- linux-c -*-
2  * Created: Wed Dec 13 21:52:19 2000 by gareth@valinux.com
3  */
4 /*-
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * All Rights Reserved.
7  *
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:
14  *
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
17  * Software.
18  *
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  * PRECISION INSIGHT 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 OTHER
25  * DEALINGS IN THE SOFTWARE.
26  *
27  * Authors:
28  *   Gareth Hughes <gareth@valinux.com>
29  *
30  * $FreeBSD$
31  */
32
33 #include "dev/drm/drmP.h"
34
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
44
45 # define ATI_MAX_PCIGART_PAGES          8192    /* 32 MB aperture, 4K pages */
46 # define ATI_PCIGART_PAGE_SIZE          4096    /* PCI GART page size */
47
48 int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr,
49                          dma_addr_t *bus_addr, int is_pcie)
50 {
51         drm_sg_mem_t *entry = dev->sg;
52         unsigned long address = 0;
53         unsigned long pages;
54         u32 *pci_gart=0, page_base, bus_address = 0;
55         int i, j, ret = 0;
56
57         if ( !entry ) {
58                 DRM_ERROR( "no scatter/gather memory!\n" );
59                 goto done;
60         }
61
62         address = (long)contigmalloc((1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, 
63             M_DRM, M_NOWAIT, 0ul, 0xfffffffful, PAGE_SIZE, 0);
64         if ( !address ) {
65                 DRM_ERROR( "cannot allocate PCI GART page!\n" );
66                 goto done;
67         }
68
69         /* XXX: we need to busdma this */
70         bus_address = vtophys( address );
71
72         pci_gart = (u32 *)address;
73
74         pages = ( entry->pages <= ATI_MAX_PCIGART_PAGES )
75                 ? entry->pages : ATI_MAX_PCIGART_PAGES;
76
77         bzero( pci_gart, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
78
79         for ( i = 0 ; i < pages ; i++ ) {
80                 entry->busaddr[i] = vtophys( entry->handle + (i*PAGE_SIZE) );
81                 page_base = (u32) entry->busaddr[i];
82
83                 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
84                         if (is_pcie) {
85                                 *pci_gart = (cpu_to_le32(page_base)>>8) | 0xc;
86                                 DRM_DEBUG("PCIE: %d %08X %08X to %p\n", i,
87                                     page_base, (cpu_to_le32(page_base)>>8)|0xc,
88                                     pci_gart);
89                         } else
90                                 *pci_gart = cpu_to_le32(page_base);
91                         pci_gart++;
92                         page_base += ATI_PCIGART_PAGE_SIZE;
93                 }
94         }
95
96         DRM_MEMORYBARRIER();
97
98         ret = 1;
99
100 done:
101         *addr = address;
102         *bus_addr = bus_address;
103         return ret;
104 }
105
106 int drm_ati_pcigart_cleanup(drm_device_t *dev, unsigned long addr,
107                             dma_addr_t bus_addr)
108 {
109         drm_sg_mem_t *entry = dev->sg;
110
111         /* we need to support large memory configurations */
112         if ( !entry ) {
113                 DRM_ERROR( "no scatter/gather memory!\n" );
114                 return 0;
115         }
116
117 #if __FreeBSD_version > 500000
118         /* Not available on 4.x */
119         contigfree((void *)addr, (1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE,
120                    M_DRM);
121 #endif
122         return 1;
123 }