open-src/kernel/drm/src/drm_gem.c
author Randy Fishel <Randy.Fishel@Oracle.COM>
Wed, 30 Nov 2016 21:57:49 -0800
changeset 1684 9f5a5146d91f
parent 1549 4b5a9782609e
permissions -rw-r--r--
25177273 Enable dumb_create in i915
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     1
/*
1684
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
     2
 * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     3
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     4
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     5
/*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     6
 * Copyright (c) 2009, 2013, Intel Corporation.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     7
 * All Rights Reserved.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     8
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
     9
 * Permission is hereby granted, free of charge, to any person obtaining a
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    10
 * copy of this software and associated documentation files (the "Software"),
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    11
 * to deal in the Software without restriction, including without limitation
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    12
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    13
 * and/or sell copies of the Software, and to permit persons to whom the
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    14
 * Software is furnished to do so, subject to the following conditions:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    15
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    16
 * The above copyright notice and this permission notice (including the next
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    17
 * paragraph) shall be included in all copies or substantial portions of the
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    18
 * Software.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    19
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    23
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    25
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    26
 * IN THE SOFTWARE.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    27
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    28
 * Authors:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    29
 *    Eric Anholt <[email protected]>
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    30
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    31
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    32
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    33
#include "drmP.h"
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    34
#include <vm/seg_kmem.h>
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    35
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    36
/** @file drm_gem.c
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    37
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    38
 * This file provides some of the base ioctls and library routines for
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    39
 * the graphics memory manager implemented by each device driver.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    40
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    41
 * Because various devices have different requirements in terms of
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    42
 * synchronization and migration strategies, implementing that is left up to
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    43
 * the driver, and all that the general API provides should be generic --
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    44
 * allocating objects, reading/writing data with the cpu, freeing objects.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    45
 * Even there, platform-dependent optimizations for reading/writing data with
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    46
 * the CPU mean we'll likely hook those out to driver-specific calls.  However,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    47
 * the DRI2 implementation wants to have at least allocate/mmap be generic.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    48
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    49
 * The goal was to have swap-backed object allocation managed through
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    50
 * struct file.  However, file descriptors as handles to a struct file have
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    51
 * two major failings:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    52
 * - Process limits prevent more than 1024 or so being used at a time by
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    53
 *   default.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    54
 * - Inability to allocate high fds will aggravate the X Server's select()
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    55
 *   handling, and likely that of many GL client applications as well.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    56
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    57
 * This led to a plan of using our own integer IDs (called handles, following
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    58
 * DRM terminology) to mimic fds, and implement the fd syscalls we need as
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    59
 * ioctls.  The objects themselves will still include the struct file so
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    60
 * that we can transition to fds if the required kernel infrastructure shows
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    61
 * up at a later date, and as our interface with shmfs for memory allocation.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    62
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    63
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    64
/*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    65
 * We make up offsets for buffer objects so we can recognize them at
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    66
 * mmap time.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    67
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    68
#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    69
#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    70
1549
4b5a9782609e 21256857 Update Xorg to the latest community version 1.17.2
Niveditha Rau <Niveditha.Rau@Oracle.COM>
parents: 1494
diff changeset
    71
int drm_use_mem_pool = 0;
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    72
/* memory pool is used for all platforms now */
1549
4b5a9782609e 21256857 Update Xorg to the latest community version 1.17.2
Niveditha Rau <Niveditha.Rau@Oracle.COM>
parents: 1494
diff changeset
    73
#define	HAS_MEM_POOL(gen)	((gen > 30) && (drm_use_mem_pool))
4b5a9782609e 21256857 Update Xorg to the latest community version 1.17.2
Niveditha Rau <Niveditha.Rau@Oracle.COM>
parents: 1494
diff changeset
    74
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    75
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    76
 * Initialize the GEM device fields
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    77
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    78
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    79
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    80
drm_gem_init(struct drm_device *dev)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    81
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    82
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    83
	spin_lock_init(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    84
	idr_list_init(&dev->object_name_idr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    85
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    86
	gfxp_mempool_init();
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    87
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    88
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    89
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    90
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    91
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    92
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    93
drm_gem_destroy(struct drm_device *dev)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    94
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    95
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    96
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    97
static void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    98
drm_gem_object_free_internal(struct drm_gem_object *obj, int gen)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
    99
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   100
	if (obj->pfnarray != NULL)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   101
		kmem_free(obj->pfnarray, btopr(obj->real_size) * sizeof (pfn_t));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   102
	if (HAS_MEM_POOL(gen)) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   103
		gfxp_free_mempool(&obj->mempool_cookie, obj->kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   104
	} else {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   105
		(void) ddi_dma_unbind_handle(obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   106
		ddi_dma_mem_free(&obj->acc_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   107
		ddi_dma_free_handle(&obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   108
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   109
	obj->kaddr = NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   110
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   111
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   112
static ddi_dma_attr_t old_dma_attr = {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   113
	DMA_ATTR_V0,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   114
	0xff000U,			/* dma_attr_addr_lo */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   115
	0xffffffffU,			/* dma_attr_addr_hi */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   116
	0xffffffffU,			/* dma_attr_count_max */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   117
	4096,				/* dma_attr_align */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   118
	0x1fffU,			/* dma_attr_burstsizes */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   119
	1,				/* dma_attr_minxfer */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   120
	0xffffffffU,			/* dma_attr_maxxfer */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   121
	0xffffffffU,			/* dma_attr_seg */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   122
	1,				/* dma_attr_sgllen, variable */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   123
	4,				/* dma_attr_granular */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   124
	DDI_DMA_FLAGERR,		/* dma_attr_flags */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   125
};
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   126
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   127
static ddi_device_acc_attr_t old_acc_attr = {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   128
	DDI_DEVICE_ATTR_V0,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   129
	DDI_NEVERSWAP_ACC,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   130
	DDI_MERGING_OK_ACC,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   131
	DDI_FLAGERR_ACC
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   132
};
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   133
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   134
static int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   135
drm_gem_object_alloc_internal_normal(struct drm_device *dev, struct drm_gem_object *obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   136
				size_t size, int flag)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   137
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   138
	ddi_dma_cookie_t cookie;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   139
	uint_t cookie_cnt;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   140
	pgcnt_t real_pgcnt, pgcnt = btopr(size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   141
	uint64_t paddr, cookie_end;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   142
	int i, n;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   143
	int (*cb)(caddr_t);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   144
	ddi_device_acc_attr_t *acc_attr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   145
	ddi_dma_attr_t* dma_attr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   146
	uint_t mode_flag;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   147
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   148
	acc_attr = &old_acc_attr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   149
	dma_attr = &old_dma_attr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   150
	mode_flag = IOMEM_DATA_UC_WR_COMBINE;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   151
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   152
	cb = (flag == 0) ? DDI_DMA_DONTWAIT : DDI_DMA_SLEEP;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   153
	dma_attr->dma_attr_sgllen = (int)pgcnt;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   154
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   155
	if (ddi_dma_alloc_handle(dev->devinfo, dma_attr,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   156
	    cb, NULL, &obj->dma_hdl)) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   157
		DRM_ERROR("ddi_dma_alloc_handle failed");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   158
		goto err1;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   159
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   160
	if (ddi_dma_mem_alloc(obj->dma_hdl, ptob(pgcnt), acc_attr,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   161
	    mode_flag, cb, NULL,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   162
	    &obj->kaddr, &obj->real_size, &obj->acc_hdl)) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   163
		DRM_ERROR("ddi_dma_mem_alloc failed");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   164
		goto err2;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   165
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   166
	if (ddi_dma_addr_bind_handle(obj->dma_hdl, NULL,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   167
	    obj->kaddr, obj->real_size, DDI_DMA_RDWR,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   168
	    cb, NULL, &cookie, &cookie_cnt)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   169
	    != DDI_DMA_MAPPED) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   170
		DRM_ERROR("ddi_dma_addr_bind_handle failed");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   171
		goto err3;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   172
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   173
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   174
	real_pgcnt = btopr(obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   175
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   176
	obj->pfnarray = kmem_zalloc(real_pgcnt * sizeof (pfn_t), KM_NOSLEEP);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   177
	if (obj->pfnarray == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   178
		DRM_DEBUG("pfnarray == NULL");	
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   179
		goto err4;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   180
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   181
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   182
	for (n = 0, i = 1; ; i++) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   183
		for (paddr = cookie.dmac_laddress,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   184
		    cookie_end = cookie.dmac_laddress + cookie.dmac_size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   185
		    paddr < cookie_end;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   186
		    paddr += PAGESIZE) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   187
			obj->pfnarray[n++] = btop(paddr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   188
			if (n >= real_pgcnt)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   189
				return (0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   190
		}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   191
		if (i >= cookie_cnt)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   192
			break;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   193
		ddi_dma_nextcookie(obj->dma_hdl, &cookie);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   194
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   195
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   196
err4:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   197
	(void) ddi_dma_unbind_handle(obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   198
err3:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   199
	ddi_dma_mem_free(&obj->acc_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   200
err2:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   201
	ddi_dma_free_handle(&obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   202
err1:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   203
	return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   204
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   205
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   206
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   207
/* Alloc GEM object by memory pool */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   208
static int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   209
drm_gem_object_alloc_internal_mempool(struct drm_gem_object *obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   210
				size_t size, int flag)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   211
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   212
	int ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   213
	pgcnt_t pgcnt = btopr(size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   214
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   215
	obj->pfnarray = kmem_zalloc(pgcnt * sizeof (pfn_t), KM_NOSLEEP);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   216
	if (obj->pfnarray == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   217
		DRM_ERROR("Failed to allocate pfnarray ");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   218
		return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   219
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   220
	
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   221
	ret = gfxp_alloc_from_mempool(&obj->mempool_cookie, &obj->kaddr, 
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   222
					obj->pfnarray, pgcnt, flag);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   223
	if (ret) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   224
		DRM_ERROR("Failed to alloc pages from memory pool");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   225
		kmem_free(obj->pfnarray, pgcnt * sizeof (pfn_t));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   226
		return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   227
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   228
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   229
	obj->real_size = size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   230
	return (0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   231
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   232
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   233
static int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   234
drm_gem_object_internal(struct drm_device *dev, struct drm_gem_object *obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   235
			size_t size, int gen)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   236
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   237
	pfn_t tmp_pfn;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   238
	int ret, num = 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   239
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   240
alloc_again:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   241
	if (HAS_MEM_POOL(gen)) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   242
		uint32_t mode;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   243
		if (gen >= 60)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   244
			mode = GFXP_MEMORY_CACHED;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   245
		else
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   246
			mode = GFXP_MEMORY_WRITECOMBINED;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   247
		ret = drm_gem_object_alloc_internal_mempool(obj, size, mode);
1549
4b5a9782609e 21256857 Update Xorg to the latest community version 1.17.2
Niveditha Rau <Niveditha.Rau@Oracle.COM>
parents: 1494
diff changeset
   248
                if (ret) 
4b5a9782609e 21256857 Update Xorg to the latest community version 1.17.2
Niveditha Rau <Niveditha.Rau@Oracle.COM>
parents: 1494
diff changeset
   249
                        return (-1);
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   250
	} else {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   251
		ret = drm_gem_object_alloc_internal_normal(dev, obj, size, 0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   252
		if (ret)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   253
			return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   254
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   255
	tmp_pfn = hat_getpfnum(kas.a_hat, obj->kaddr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   256
	if (tmp_pfn != obj->pfnarray[0]) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   257
		DRM_ERROR("obj %p map incorrect 0x%lx != 0x%lx",
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   258
		    (void *)obj, tmp_pfn, obj->pfnarray[0]);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   259
		drm_gem_object_free_internal(obj, gen);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   260
		udelay(150);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   261
	
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   262
		if (num++ < 5)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   263
			goto alloc_again;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   264
		else
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   265
			return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   266
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   267
	
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   268
	return (0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   269
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   270
/*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   271
 * Initialize an already allocate GEM object of the specified size with
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   272
 * shmfs backing store.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   273
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   274
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   275
drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   276
				size_t size, int gen)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   277
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   278
	drm_local_map_t *map;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   279
	int ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   280
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   281
	if (size == 0) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   282
		DRM_DEBUG("size == 0");	
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   283
		return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   284
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   285
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   286
	obj->dev = dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   287
	obj->size = size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   288
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   289
	ret = drm_gem_object_internal(dev, obj, size, gen);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   290
	if (ret)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   291
		return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   292
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   293
	map = drm_alloc(sizeof (struct drm_local_map), DRM_MEM_MAPS);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   294
	if (map == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   295
		DRM_DEBUG("map == NULL");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   296
		goto err5;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   297
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   298
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   299
	map->handle = obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   300
	map->offset = (uintptr_t)map->handle;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   301
	map->offset &= 0xffffffffUL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   302
	map->size = obj->real_size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   303
	map->type = _DRM_GEM;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   304
	map->callback = 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   305
	map->flags = _DRM_WRITE_COMBINING | _DRM_REMOVABLE;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   306
	map->umem_cookie =
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   307
	    gfxp_umem_cookie_init(obj->kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   308
	if (map->umem_cookie == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   309
		DRM_DEBUG("umem_cookie == NULL");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   310
		goto err6;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   311
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   312
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   313
	obj->maplist.map = map;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   314
	if (drm_map_handle(dev, &obj->maplist)) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   315
		DRM_DEBUG("drm_map_handle failed");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   316
		goto err7;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   317
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   318
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   319
	kref_init(&obj->refcount);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   320
	atomic_set(&obj->handle_count, 0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   321
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   322
	if (MDB_TRACK_ENABLE) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   323
		INIT_LIST_HEAD(&obj->track_list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   324
		spin_lock(&dev->track_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   325
		list_add_tail(&obj->track_list, &dev->gem_objects_list, (caddr_t)obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   326
		spin_unlock(&dev->track_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   327
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   328
		INIT_LIST_HEAD(&obj->his_list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   329
		drm_gem_object_track(obj, "obj init", 0, 0, NULL);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   330
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   331
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   332
	INIT_LIST_HEAD(&obj->seg_list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   333
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   334
	return (0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   335
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   336
err7:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   337
	gfxp_umem_cookie_destroy(map->umem_cookie);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   338
err6:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   339
	drm_free(map, sizeof (struct drm_local_map), DRM_MEM_MAPS);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   340
err5:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   341
	drm_gem_object_free_internal(obj, gen);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   342
	return (-1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   343
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   344
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   345
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   346
 * Initialize an already allocated GEM object of the specified size with
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   347
 * no GEM provided backing store. Instead the caller is responsible for
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   348
 * backing the object and handling it.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   349
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   350
int drm_gem_private_object_init(struct drm_device *dev,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   351
			struct drm_gem_object *obj, size_t size)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   352
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   353
	BUG_ON((size & (PAGE_SIZE - 1)) != 0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   354
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   355
	obj->dev = dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   356
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   357
	kref_init(&obj->refcount);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   358
	atomic_set(&obj->handle_count, 0);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   359
	obj->size = size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   360
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   361
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   362
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   363
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   364
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   365
 * Allocate a GEM object of the specified size with shmfs backing store
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   366
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   367
struct drm_gem_object *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   368
drm_gem_object_alloc(struct drm_device *dev, size_t size)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   369
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   370
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   371
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   372
	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   373
	if (!obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   374
		goto free;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   375
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   376
	if (drm_gem_object_init(dev, obj, size, 0) != 0) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   377
		kmem_free(obj, sizeof (struct drm_gem_object));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   378
		return NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   379
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   380
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   381
	if (dev->driver->gem_init_object != NULL &&
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   382
	    dev->driver->gem_init_object(obj) != 0) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   383
		goto fput;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   384
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   385
	return obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   386
fput:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   387
	/* Object_init mangles the global counters - readjust them. */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   388
	drm_gem_object_release(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   389
	kfree(obj, sizeof(*obj));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   390
free:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   391
	return NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   392
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   393
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   394
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   395
 * Removes the mapping from handle to filp for this object.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   396
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   397
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   398
drm_gem_handle_delete(struct drm_file *filp, u32 handle)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   399
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   400
	struct drm_device *dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   401
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   402
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   403
	/* This is gross. The idr system doesn't let us try a delete and
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   404
	 * return an error code.  It just spews if you fail at deleting.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   405
	 * So, we have to grab a lock around finding the object and then
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   406
	 * doing the delete on it and dropping the refcount, or the user
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   407
	 * could race us to double-decrement the refcount and cause a
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   408
	 * use-after-free later.  Given the frequency of our handle lookups,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   409
	 * we may want to use ida for number allocation and a hash table
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   410
	 * for the pointers, anyway.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   411
	 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   412
	spin_lock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   413
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   414
	/* Check if we currently have a reference on the object */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   415
	obj = idr_list_find(&filp->object_idr, handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   416
	if (obj == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   417
		spin_unlock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   418
		return -EINVAL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   419
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   420
	dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   421
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   422
	/* Release reference and decrement refcount. */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   423
	(void) idr_list_remove(&filp->object_idr, handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   424
	spin_unlock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   425
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   426
	if (dev->driver->gem_close_object)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   427
		dev->driver->gem_close_object(obj, filp);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   428
	drm_gem_object_handle_unreference_unlocked(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   429
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   430
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   431
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   432
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   433
/**
1684
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   434
 * drm_gem_dumb_destroy - dumb fb callback helper for gem based drivers
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   435
 * @file: drm file-private structure to remove the dumb handle from
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   436
 * @dev: corresponding drm_device
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   437
 * @handle: the dumb handle to remove
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   438
 *      
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   439
 * This implements the ->dumb_destroy kms driver callback for drivers which use
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   440
 * gem to manage their backing storage.
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   441
 */
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   442
int drm_gem_dumb_destroy(struct drm_file *file,
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   443
			struct drm_device *dev,
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   444
			uint32_t handle)
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   445
{       
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   446
	return drm_gem_handle_delete(file, handle);
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   447
}       
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   448
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   449
/**
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   450
 * Create a handle for this object. This adds a handle reference
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   451
 * to the object, which includes a regular reference count. Callers
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   452
 * will likely want to dereference the object afterwards.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   453
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   454
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   455
drm_gem_handle_create(struct drm_file *file_priv,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   456
		       struct drm_gem_object *obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   457
		       u32 *handlep)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   458
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   459
	struct drm_device *dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   460
	int	ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   461
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   462
	/*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   463
	 * Get the user-visible handle using idr.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   464
	 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   465
again:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   466
	/* ensure there is space available to allocate a handle */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   467
	if (idr_list_pre_get(&file_priv->object_idr, GFP_KERNEL) == 0)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   468
		return -ENOMEM;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   469
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   470
	/* do the allocation under our spinlock */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   471
	spin_lock(&file_priv->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   472
	ret = idr_list_get_new_above(&file_priv->object_idr, (void *)obj, (int *)handlep);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   473
	spin_unlock(&file_priv->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   474
	if (ret == -EAGAIN)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   475
		goto again;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   476
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   477
	if (ret != 0)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   478
		return ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   479
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   480
	drm_gem_object_handle_reference(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   481
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   482
	if (dev->driver->gem_open_object) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   483
		ret = dev->driver->gem_open_object(obj, file_priv);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   484
		if (ret) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   485
			(void) drm_gem_handle_delete(file_priv, *handlep);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   486
			return ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   487
		}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   488
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   489
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   490
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   491
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   492
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   493
/** Returns a reference to the object named by the handle. */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   494
struct drm_gem_object *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   495
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   496
drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   497
		      u32 handle)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   498
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   499
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   500
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   501
	spin_lock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   502
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   503
	/* Check if we currently have a reference on the object */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   504
	obj = idr_list_find(&filp->object_idr, handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   505
	if (obj == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   506
		spin_unlock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   507
		return NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   508
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   509
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   510
	drm_gem_object_reference(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   511
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   512
	spin_unlock(&filp->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   513
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   514
	return obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   515
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   516
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   517
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   518
 * Releases the handle to an mm object.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   519
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   520
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   521
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   522
drm_gem_close_ioctl(DRM_IOCTL_ARGS)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   523
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   524
	struct drm_gem_close *args = data;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   525
	int ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   526
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   527
	if (!(dev->driver->driver_features & DRIVER_GEM))
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   528
		return -ENODEV;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   529
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   530
	ret = drm_gem_handle_delete(file, args->handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   531
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   532
	return ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   533
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   534
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   535
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   536
 * Create a global name for an object, returning the name.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   537
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   538
 * Note that the name does not hold a reference; when the object
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   539
 * is freed, the name goes away.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   540
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   541
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   542
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   543
drm_gem_flink_ioctl(DRM_IOCTL_ARGS)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   544
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   545
	struct drm_gem_flink *args = data;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   546
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   547
	int ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   548
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   549
	if (!(dev->driver->driver_features & DRIVER_GEM))
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   550
		return -ENODEV;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   551
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   552
	obj = drm_gem_object_lookup(dev, file, args->handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   553
	if (obj == NULL)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   554
		return -ENOENT;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   555
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   556
again:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   557
	if (idr_list_pre_get(&dev->object_name_idr, GFP_KERNEL) == 0) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   558
		ret = -ENOMEM;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   559
		goto err;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   560
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   561
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   562
	spin_lock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   563
	if (!obj->name) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   564
		ret = idr_list_get_new_above(&dev->object_name_idr, (void *) obj,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   565
					&obj->name);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   566
		args->name = (uint64_t) obj->name;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   567
		spin_unlock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   568
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   569
		if (ret == -EAGAIN)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   570
			goto again;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   571
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   572
		if (ret != 0)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   573
			goto err;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   574
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   575
		/* Allocate a reference for the name table.  */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   576
		drm_gem_object_reference(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   577
	} else {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   578
		args->name = (uint64_t) obj->name;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   579
		spin_unlock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   580
		ret = 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   581
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   582
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   583
err:
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   584
	drm_gem_object_unreference_unlocked(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   585
	return ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   586
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   587
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   588
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   589
 * Open an object using the global name, returning a handle and the size.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   590
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   591
 * This handle (of course) holds a reference to the object, so the object
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   592
 * will not go away until the handle is deleted.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   593
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   594
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   595
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   596
drm_gem_open_ioctl(DRM_IOCTL_ARGS)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   597
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   598
	struct drm_gem_open *args = data;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   599
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   600
	int ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   601
	u32 handle;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   602
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   603
	if (!(dev->driver->driver_features & DRIVER_GEM))
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   604
		return -ENODEV;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   605
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   606
	spin_lock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   607
	obj = idr_list_find(&dev->object_name_idr, (int) args->name);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   608
	if (obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   609
		drm_gem_object_reference(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   610
	spin_unlock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   611
	if (!obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   612
		return -ENOENT;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   613
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   614
	ret = drm_gem_handle_create(file, obj, &handle);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   615
	drm_gem_object_unreference_unlocked(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   616
	if (ret)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   617
		return ret;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   618
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   619
	args->handle = handle;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   620
	args->size = obj->size;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   621
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   622
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   623
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   624
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   625
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   626
 * Called at device open time, sets up the structure for handling refcounting
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   627
 * of mm objects.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   628
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   629
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   630
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   631
drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   632
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   633
	idr_list_init(&file_private->object_idr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   634
	spin_lock_init(&file_private->table_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   635
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   636
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   637
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   638
 * Called at device close to release the file's
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   639
 * handle references on objects.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   640
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   641
static int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   642
/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   643
drm_gem_object_release_handle(int id, void *ptr, void *data)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   644
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   645
	struct drm_file *file_priv = data;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   646
	struct drm_gem_object *obj = ptr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   647
	struct drm_device *dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   648
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   649
	if (dev->driver->gem_close_object)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   650
		dev->driver->gem_close_object(obj, file_priv);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   651
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   652
	drm_gem_object_handle_unreference_unlocked(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   653
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   654
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   655
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   656
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   657
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   658
 * Called at close time when the filp is going away.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   659
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   660
 * Releases any remaining references on objects by this filp.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   661
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   662
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   663
/* LINTED E_FUNC_ARG_UNUSED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   664
drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   665
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   666
	struct idr_list  *entry;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   667
	struct drm_gem_object *obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   668
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   669
	idr_list_for_each(entry, &file_private->object_idr) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   670
		obj = (struct drm_gem_object *)entry->obj;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   671
		(void) drm_gem_object_release_handle(obj->name, obj, (void *)file_private);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   672
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   673
	idr_list_free(&file_private->object_idr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   674
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   675
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   676
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   677
drm_gem_object_release(struct drm_gem_object *obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   678
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   679
	struct drm_device *dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   680
	struct drm_local_map *map = obj->maplist.map;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   681
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   682
	if (MDB_TRACK_ENABLE) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   683
		spin_lock(&dev->track_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   684
		list_del(&obj->track_list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   685
		spin_unlock(&dev->track_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   686
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   687
		struct drm_history_list *r_list, *list_temp;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   688
		list_for_each_entry_safe(r_list, list_temp, struct drm_history_list, &obj->his_list, head) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   689
			list_del(&r_list->head);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   690
			drm_free(r_list, sizeof (struct drm_history_list), DRM_MEM_MAPS);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   691
		}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   692
		list_del(&obj->his_list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   693
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   694
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   695
	(void) idr_remove(&dev->map_idr, obj->maplist.user_token >> PAGE_SHIFT);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   696
	gfxp_umem_cookie_destroy(map->umem_cookie);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   697
	drm_free(map, sizeof (struct drm_local_map), DRM_MEM_MAPS);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   698
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   699
	kmem_free(obj->pfnarray, btopr(obj->real_size) * sizeof (pfn_t));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   700
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   701
	if (obj->dma_hdl == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   702
		gfxp_free_mempool(&obj->mempool_cookie, obj->kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   703
	} else {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   704
		(void) ddi_dma_unbind_handle(obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   705
		ddi_dma_mem_free(&obj->acc_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   706
		ddi_dma_free_handle(&obj->dma_hdl);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   707
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   708
	obj->kaddr = NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   709
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   710
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   711
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   712
 * Called after the last reference to the object has been lost.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   713
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   714
 * Frees the object
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   715
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   716
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   717
drm_gem_object_free(struct kref *kref)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   718
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   719
	/* LINTED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   720
	struct drm_gem_object *obj = (struct drm_gem_object *) kref;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   721
	struct drm_device *dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   722
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   723
//	BUG_ON(!mutex_is_locked(&dev->struct_mutex));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   724
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   725
	if (dev->driver->gem_free_object != NULL)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   726
		dev->driver->gem_free_object(obj);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   727
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   728
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   729
/* LINTED E_FUNC_ARG_UNUSED */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   730
static void drm_gem_object_ref_bug(struct kref *list_kref)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   731
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   732
	BUG_ON(1);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   733
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   734
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   735
/**
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   736
 * Called after the last handle to the object has been closed
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   737
 *
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   738
 * Removes any name for the object. Note that this must be
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   739
 * called before drm_gem_object_free or we'll be touching
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   740
 * freed memory
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   741
 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   742
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   743
drm_gem_object_handle_free(struct drm_gem_object *obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   744
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   745
	struct drm_device *dev = obj->dev;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   746
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   747
	/* Remove any name for this object */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   748
	spin_lock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   749
	if (obj->name) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   750
		(void) idr_list_remove(&dev->object_name_idr, obj->name);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   751
		obj->name = 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   752
		spin_unlock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   753
		/*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   754
		 * The object name held a reference to this object, drop
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   755
		 * that now.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   756
		*
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   757
		* This cannot be the last reference, since the handle holds one too.
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   758
		 */
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   759
		kref_put(&obj->refcount, drm_gem_object_ref_bug);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   760
	} else
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   761
		spin_unlock(&dev->object_name_lock);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   762
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   763
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   764
1684
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   765
/*
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   766
 * XXXX FIXME - we shouldn't be alloc'ing space here for gtt_map_kaddr.  If
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   767
 * this element is actually needed, it should be part of a global GTT mapping,
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   768
 * and should only need "loading" at best.
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   769
 */
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   770
int
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   771
drm_gem_create_mmap_offset(struct drm_gem_object *obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   772
{
1684
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   773
	/*
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   774
	 * if already have a map, return.
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   775
	 */
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   776
	if (obj->gtt_map_kaddr != NULL)
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   777
		return 0;
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   778
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   779
	/*
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   780
	 * Otherwise, get us some kernel space.
9f5a5146d91f 25177273 Enable dumb_create in i915
Randy Fishel <Randy.Fishel@Oracle.COM>
parents: 1549
diff changeset
   781
	 */
1494
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   782
	obj->gtt_map_kaddr = gfxp_alloc_kernel_space(obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   783
	if (obj->gtt_map_kaddr == NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   784
		return -ENOMEM;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   785
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   786
	return 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   787
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   788
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   789
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   790
drm_gem_mmap(struct drm_gem_object *obj, pfn_t pfn)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   791
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   792
	gfxp_load_kernel_space(pfn, obj->real_size, GFXP_MEMORY_WRITECOMBINED, obj->gtt_map_kaddr);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   793
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   794
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   795
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   796
drm_gem_release_mmap(struct drm_gem_object *obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   797
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   798
	gfxp_unload_kernel_space(obj->gtt_map_kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   799
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   800
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   801
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   802
drm_gem_free_mmap_offset(struct drm_gem_object *obj)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   803
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   804
	struct ddi_umem_cookie *umem_cookie = obj->maplist.map->umem_cookie;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   805
	umem_cookie->cvaddr = obj->kaddr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   806
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   807
	if (obj->maplist.map->gtt_mmap == 0) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   808
		gfxp_free_kernel_space(obj->gtt_map_kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   809
		DRM_DEBUG("already freed, don't free more than once!");
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   810
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   811
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   812
	if (obj->maplist.map->gtt_mmap == 1) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   813
		gfxp_unmap_kernel_space(obj->gtt_map_kaddr, obj->real_size);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   814
		obj->maplist.map->gtt_mmap = 0;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   815
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   816
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   817
	obj->gtt_map_kaddr = NULL;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   818
}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   819
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   820
void
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   821
drm_gem_object_track(struct drm_gem_object *obj, const char *name,
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   822
                        uint32_t cur_seq, uint32_t last_seq, void* ptr)
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   823
{
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   824
	struct drm_history_list *list;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   825
	list = drm_alloc(sizeof (struct drm_history_list), DRM_MEM_MAPS);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   826
	if (list != NULL) {
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   827
		(void) memcpy(list->info, name, (strlen(name) * sizeof(char)));
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   828
		list->cur_seq = cur_seq;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   829
		list->last_seq = last_seq;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   830
		list->ring_ptr = ptr;
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   831
		list_add_tail(&list->head, &obj->his_list, (caddr_t)list);
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   832
	}
a72f39592745 PSARC 2014/148 Move DRM drivers to X11
Randy Fishel <Randy.Fishel@Oracle.COM>
parents:
diff changeset
   833
}