Skip to content

Commit 673a394

Browse files
anholtairlied
authored andcommitted
drm: Add GEM ("graphics execution manager") to i915 driver.
GEM allows the creation of persistent buffer objects accessible by the graphics device through new ioctls for managing execution of commands on the device. The userland API is almost entirely driver-specific to ensure that any driver building on this model can easily map the interface to individual driver requirements. GEM is used by the 2d driver for managing its internal state allocations and will be used for pixmap storage to reduce memory consumption and enable zero-copy GLX_EXT_texture_from_pixmap, and in the 3d driver is used to enable GL_EXT_framebuffer_object and GL_ARB_pixel_buffer_object. Signed-off-by: Eric Anholt <eric@anholt.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent d1d8c92 commit 673a394

23 files changed

Lines changed: 4832 additions & 62 deletions

‎drivers/gpu/drm/Makefile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
ccflags-y := -Iinclude/drm
66

7-
drm-y := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \
8-
drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \
7+
drm-y := drm_auth.o drm_bufs.o drm_cache.o \
8+
drm_context.o drm_dma.o drm_drawable.o \
9+
drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
910
drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
1011
drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
1112
drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o

‎drivers/gpu/drm/drm_agpsupport.c‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "drmP.h"
3535
#include <linux/module.h>
36+
#include <asm/agp.h>
3637

3738
#if __OS_HAS_AGP
3839

@@ -452,4 +453,52 @@ int drm_agp_unbind_memory(DRM_AGP_MEM * handle)
452453
return agp_unbind_memory(handle);
453454
}
454455

455-
#endif /* __OS_HAS_AGP */
456+
/**
457+
* Binds a collection of pages into AGP memory at the given offset, returning
458+
* the AGP memory structure containing them.
459+
*
460+
* No reference is held on the pages during this time -- it is up to the
461+
* caller to handle that.
462+
*/
463+
DRM_AGP_MEM *
464+
drm_agp_bind_pages(struct drm_device *dev,
465+
struct page **pages,
466+
unsigned long num_pages,
467+
uint32_t gtt_offset)
468+
{
469+
DRM_AGP_MEM *mem;
470+
int ret, i;
471+
472+
DRM_DEBUG("\n");
473+
474+
mem = drm_agp_allocate_memory(dev->agp->bridge, num_pages,
475+
AGP_USER_MEMORY);
476+
if (mem == NULL) {
477+
DRM_ERROR("Failed to allocate memory for %ld pages\n",
478+
num_pages);
479+
return NULL;
480+
}
481+
482+
for (i = 0; i < num_pages; i++)
483+
mem->memory[i] = phys_to_gart(page_to_phys(pages[i]));
484+
mem->page_count = num_pages;
485+
486+
mem->is_flushed = true;
487+
ret = drm_agp_bind_memory(mem, gtt_offset / PAGE_SIZE);
488+
if (ret != 0) {
489+
DRM_ERROR("Failed to bind AGP memory: %d\n", ret);
490+
agp_free_memory(mem);
491+
return NULL;
492+
}
493+
494+
return mem;
495+
}
496+
EXPORT_SYMBOL(drm_agp_bind_pages);
497+
498+
void drm_agp_chipset_flush(struct drm_device *dev)
499+
{
500+
agp_flush_chipset(dev->agp->bridge);
501+
}
502+
EXPORT_SYMBOL(drm_agp_chipset_flush);
503+
504+
#endif /* __OS_HAS_AGP */

‎drivers/gpu/drm/drm_cache.c‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**************************************************************************
2+
*
3+
* Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
4+
* All Rights Reserved.
5+
*
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:
13+
*
14+
* The above copyright notice and this permission notice (including the
15+
* next paragraph) shall be included in all copies or substantial portions
16+
* of the Software.
17+
*
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.
25+
*
26+
**************************************************************************/
27+
/*
28+
* Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
29+
*/
30+
31+
#include "drmP.h"
32+
33+
#if defined(CONFIG_X86)
34+
static void
35+
drm_clflush_page(struct page *page)
36+
{
37+
uint8_t *page_virtual;
38+
unsigned int i;
39+
40+
if (unlikely(page == NULL))
41+
return;
42+
43+
page_virtual = kmap_atomic(page, KM_USER0);
44+
for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
45+
clflush(page_virtual + i);
46+
kunmap_atomic(page_virtual, KM_USER0);
47+
}
48+
#endif
49+
50+
static void
51+
drm_clflush_ipi_handler(void *null)
52+
{
53+
wbinvd();
54+
}
55+
56+
void
57+
drm_clflush_pages(struct page *pages[], unsigned long num_pages)
58+
{
59+
60+
#if defined(CONFIG_X86)
61+
if (cpu_has_clflush) {
62+
unsigned long i;
63+
64+
mb();
65+
for (i = 0; i < num_pages; ++i)
66+
drm_clflush_page(*pages++);
67+
mb();
68+
69+
return;
70+
}
71+
#endif
72+
73+
if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
74+
DRM_ERROR("Timed out waiting for cache flush.\n");
75+
}
76+
EXPORT_SYMBOL(drm_clflush_pages);

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ static struct drm_ioctl_desc drm_ioctls[] = {
119119
DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_modeset_ctl, 0),
120120

121121
DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
122+
123+
DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, 0),
124+
DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH),
125+
DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH),
122126
};
123127

124128
#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )

‎drivers/gpu/drm/drm_fops.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ static int drm_open_helper(struct inode *inode, struct file *filp,
256256

257257
INIT_LIST_HEAD(&priv->lhead);
258258

259+
if (dev->driver->driver_features & DRIVER_GEM)
260+
drm_gem_open(dev, priv);
261+
259262
if (dev->driver->open) {
260263
ret = dev->driver->open(dev, priv);
261264
if (ret < 0)
@@ -400,6 +403,9 @@ int drm_release(struct inode *inode, struct file *filp)
400403
dev->driver->reclaim_buffers(dev, file_priv);
401404
}
402405

406+
if (dev->driver->driver_features & DRIVER_GEM)
407+
drm_gem_release(dev, file_priv);
408+
403409
drm_fasync(-1, filp, 0);
404410

405411
mutex_lock(&dev->ctxlist_mutex);

0 commit comments

Comments
 (0)