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 * type)
46 int via_invalidate_caches(struct drm_device * dev, uint64_t flags)
49 * FIXME: Invalidate texture caches here.
56 static int via_vram_info(struct drm_device *dev,
57 unsigned long *offset,
60 struct pci_dev *pdev = dev->pdev;
63 int ret = DRM_ERR(EINVAL);
66 flags = pci_resource_flags(pdev, i);
67 if ((flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH)) ==
68 (IORESOURCE_MEM | IORESOURCE_PREFETCH)) {
75 DRM_ERROR("Could not find VRAM PCI resource\n");
79 *offset = pci_resource_start(pdev, i);
80 *size = pci_resource_end(pdev, i) - *offset + 1;
84 int via_init_mem_type(struct drm_device * dev, uint32_t type,
85 struct drm_mem_type_manager * man)
88 case DRM_BO_MEM_LOCAL:
91 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
92 _DRM_FLAG_MEMTYPE_CACHED;
93 man->drm_bus_maptype = 0;
97 /* Dynamic agpgart memory */
99 if (!(drm_core_has_AGP(dev) && dev->agp)) {
100 DRM_ERROR("AGP is not enabled for memory type %u\n",
104 man->io_offset = dev->agp->agp_info.aper_base;
105 man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
107 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
109 /* Only to get pte protection right. */
111 man->drm_bus_maptype = _DRM_AGP;
114 case DRM_BO_MEM_VRAM:
115 /* "On-card" video ram */
117 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE | _DRM_FLAG_NEEDS_IOREMAP;
118 man->drm_bus_maptype = _DRM_FRAME_BUFFER;
120 return via_vram_info(dev, &man->io_offset, &man->io_size);
123 case DRM_BO_MEM_PRIV0:
124 /* Pre-bound agpgart memory */
126 if (!(drm_core_has_AGP(dev) && dev->agp)) {
127 DRM_ERROR("AGP is not enabled for memory type %u\n",
131 man->io_offset = dev->agp->agp_info.aper_base;
132 man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
134 man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
135 _DRM_FLAG_MEMTYPE_FIXED | _DRM_FLAG_NEEDS_IOREMAP;
136 man->drm_bus_maptype = _DRM_AGP;
140 DRM_ERROR("Unsupported memory type %u\n", (unsigned)type);
146 uint32_t via_evict_mask(struct drm_buffer_object *bo)
148 switch (bo->mem.mem_type) {
149 case DRM_BO_MEM_LOCAL:
151 return DRM_BO_FLAG_MEM_LOCAL; /* Evict TT to local */
152 case DRM_BO_MEM_PRIV0: /* Evict pre-bound AGP to TT */
153 return DRM_BO_MEM_TT;
154 case DRM_BO_MEM_VRAM:
155 if (bo->mem.num_pages > 128)
156 return DRM_BO_MEM_TT;
158 return DRM_BO_MEM_LOCAL;
160 return DRM_BO_MEM_LOCAL;