1 /**************************************************************************
3 * Copyright (c) 2007 Tungsten Graphics, Inc., Cedar Park, TX., USA,
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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 NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
35 struct drm_ttm_backend *via_create_ttm_backend_entry(struct drm_device * dev)
37 return drm_agp_init_ttm(dev);
40 int via_fence_types(struct drm_buffer_object *bo, uint32_t * fclass,
47 int via_invalidate_caches(struct drm_device * dev, uint64_t flags)
50 * FIXME: Invalidate texture caches here.
57 static int via_vram_info(struct drm_device *dev,
58 unsigned long *offset,
61 struct pci_dev *pdev = dev->pdev;
67 flags = pci_resource_flags(pdev, i);
68 if ((flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH)) ==
69 (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
76 DRM_ERROR("Could not find VRAM PCI resource\n");
80 *offset = pci_resource_start(pdev, i);
81 *size = pci_resource_end(pdev, i) - *offset + 1;
85 int via_init_mem_type(struct drm_device * dev, uint32_t type,
86 struct drm_mem_type_manager * man)
89 case DRM_BO_MEM_LOCAL:
92 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
93 _DRM_FLAG_MEMTYPE_CACHED;
94 man->drm_bus_maptype = 0;
98 /* Dynamic agpgart memory */
100 if (!(drm_core_has_AGP(dev) && dev->agp)) {
101 DRM_ERROR("AGP is not enabled for memory type %u\n",
105 man->io_offset = dev->agp->agp_info.aper_base;
106 man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
108 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
110 /* Only to get pte protection right. */
112 man->drm_bus_maptype = _DRM_AGP;
115 case DRM_BO_MEM_VRAM:
116 /* "On-card" video ram */
118 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
119 man->drm_bus_maptype = _DRM_FRAME_BUFFER;
121 return via_vram_info(dev, &man->io_offset, &man->io_size);
124 case DRM_BO_MEM_PRIV0:
125 /* Pre-bound agpgart memory */
127 if (!(drm_core_has_AGP(dev) && dev->agp)) {
128 DRM_ERROR("AGP is not enabled for memory type %u\n",
132 man->io_offset = dev->agp->agp_info.aper_base;
133 man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
135 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
136 _DRM_FLAG_MEMTYPE_FIXED | _DRM_FLAG_NEEDS_IOREMAP;
137 man->drm_bus_maptype = _DRM_AGP;
141 DRM_ERROR("Unsupported memory type %u\n", (unsigned)type);
147 uint32_t via_evict_mask(struct drm_buffer_object *bo)
149 switch (bo->mem.mem_type) {
150 case DRM_BO_MEM_LOCAL:
152 return DRM_BO_FLAG_MEM_LOCAL; /* Evict TT to local */
153 case DRM_BO_MEM_PRIV0: /* Evict pre-bound AGP to TT */
154 return DRM_BO_MEM_TT;
155 case DRM_BO_MEM_VRAM:
156 if (bo->mem.num_pages > 128)
157 return DRM_BO_MEM_TT;
159 return DRM_BO_MEM_LOCAL;
161 return DRM_BO_MEM_LOCAL;