OSDN Git Service

nouveau/nv50: hack up initial channel context from current state
[android-x86/external-libdrm.git] / bsd-core / 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  */
31
32 #include "drmP.h"
33
34 #define ATI_PCIGART_PAGE_SIZE           4096    /* PCI GART page size */
35
36 int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
37 {
38         unsigned long pages;
39         u32 *pci_gart = NULL, page_base;
40         int i, j;
41
42         if (dev->sg == NULL) {
43                 DRM_ERROR( "no scatter/gather memory!\n" );
44                 return 0;
45         }
46
47         if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
48                 /* GART table in system memory */
49                 dev->sg->dmah = drm_pci_alloc(dev, gart_info->table_size, 0,
50                     0xfffffffful);
51                 if (dev->sg->dmah == NULL) {
52                         DRM_ERROR("cannot allocate PCI GART table!\n");
53                         return 0;
54                 }
55         
56                 gart_info->addr = (void *)dev->sg->dmah->vaddr;
57                 gart_info->bus_addr = dev->sg->dmah->busaddr;
58                 pci_gart = (u32 *)dev->sg->dmah->vaddr;
59         } else {
60                 /* GART table in framebuffer memory */
61                 pci_gart = gart_info->addr;
62         }
63         
64         pages = DRM_MIN(dev->sg->pages, gart_info->table_size / sizeof(u32));
65
66         bzero(pci_gart, gart_info->table_size);
67
68         KASSERT(PAGE_SIZE >= ATI_PCIGART_PAGE_SIZE, ("page size too small"));
69
70         for ( i = 0 ; i < pages ; i++ ) {
71                 page_base = (u32) dev->sg->busaddr[i];
72
73                 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
74                         switch(gart_info->gart_reg_if) {
75                         case DRM_ATI_GART_IGP:
76                                 *pci_gart = cpu_to_le32(page_base | 0xc);
77                                 break;
78                         case DRM_ATI_GART_PCIE:
79                                 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
80                                 break;
81                         default:
82                                 *pci_gart = cpu_to_le32(page_base);
83                                 break;
84                         }
85                         pci_gart++;
86                         page_base += ATI_PCIGART_PAGE_SIZE;
87                 }
88         }
89
90         DRM_MEMORYBARRIER();
91
92         return 1;
93 }
94
95 int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
96 {
97         if (dev->sg == NULL) {
98                 DRM_ERROR( "no scatter/gather memory!\n" );
99                 return 0;
100         }
101
102         drm_pci_free(dev, dev->sg->dmah);
103
104         return 1;
105 }