mirror of
https://github.com/brain-hackers/linux-brain.git
synced 2024-06-09 23:36:23 +09:00
2454fcea33
UAPI Changes: Cross-subsystem Changes: - Add code to signal all dma-fences when freed with pending signals. - Annotate reservation object access in CONFIG_DEBUG_MUTEXES Core Changes: - Assorted documentation fixes. - Use irqsave/restore spinlock to add crc entry. - Move code around to drm_client, for internal modeset clients. - Make drm_crtc.h and drm_debugfs.h self-contained. - Remove drm_fb_helper_connector. - Add bootsplash to todo. - Fix lock ordering in pan_display_legacy. - Support pinning buffers to current location in gem-vram. - Remove the now unused locking functions from gem-vram. - Remove the now unused kmap-object argument from vram helpers. - Stop checking return value of debugfs_create. - Add atomic encoder enable/disable helpers. - pass drm_atomic_state to atomic connector check. - Add atomic support for bridge enable/disable. - Add self refresh helpers to core. Driver Changes: - Add extra delay to make MTP SDM845 work. - Small fixes to virtio, vkms, sii902x, sii9234, ast, mcde, analogix, rockchip. - Add zpos and ?BGR8888 support to meson. - More removals of drm_os_linux and drmP headers for amd, radeon, sti, r128, r128, savage, sis. - Allow synopsis to unwedge the i2c hdmi bus. - Add orientation quirks for GPD panels. - Edid cleanups and fixing handling for edid < 1.2. - Add runtime pm to stm. - Handle s/r in dw-hdmi. - Add hooks for power on/off to dsi for stm. - Remove virtio dirty tracking code, done in drm core. - Rework BO handling in ast and mgag200. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEuXvWqAysSYEJGuVH/lWMcqZwE8MFAl0DYU8ACgkQ/lWMcqZw E8NNWw/+MhcRakQmrNDMRIj4DvukzPW2efXbhRFuvthUvVN7rOHMzQZBc3le+gUb 2GGoEeUYG7XoA/Nj3ZQMUoalrjODywtLClBClC4Blped0mZ4JPiI7bTsrNILn1N1 hZ0+DbffMCAKqKN8TftK/TrFF9IEM8JSftqD/1RdkiXVcMH3NKuLABHZxzPxH2BH XuSqIL5lDyAtanixB53aDf2gw9iipUphYoFlKhdx9dr5Ql96RhiOcDgFhXnFiQu4 O9z3W6tRI2VPoCzsnhNy3Eah7rBDnZwvyfGa9YU/Q+VeHegb601p8OmNNwpshWE1 ohixBbADj0dr+K3T/lVW30kovg34i4L5K3O7MR0HxWYSA7+v3AHyG7/GWLxbBNQn AFHTRbBph8aP/Dn24ucbKaB7wHi31j7b0Hxj+oJR8RoGhuOYcMOuZrCHqpAxStto riSVDCRcq/KcPiuqZZ1UnzFWlQMhNFUwumloPiXFkJ4mcSdK9IbdKBd2eqbRdaU1 eTOA4istVgNgaNbgLvVB2ltjqXrsdio7/jh6RhobFPqHISiL7iMZg3C/KRBXrkUB lYMeGkiE3Wp77zdycdofuEbMfAYUwLts8EYjVsM6xo0BKlBYhpeVuBOYeQEkU7PV PpGYqQVeZUoD1OyGlMWIYoyb5Ya7OLUDpooOJdFqoPzUfDki31E= =4uQX -----END PGP SIGNATURE----- Merge tag 'drm-misc-next-2019-06-14' of git://anongit.freedesktop.org/drm/drm-misc into drm-next drm-misc-next for v5.3: UAPI Changes: Cross-subsystem Changes: - Add code to signal all dma-fences when freed with pending signals. - Annotate reservation object access in CONFIG_DEBUG_MUTEXES Core Changes: - Assorted documentation fixes. - Use irqsave/restore spinlock to add crc entry. - Move code around to drm_client, for internal modeset clients. - Make drm_crtc.h and drm_debugfs.h self-contained. - Remove drm_fb_helper_connector. - Add bootsplash to todo. - Fix lock ordering in pan_display_legacy. - Support pinning buffers to current location in gem-vram. - Remove the now unused locking functions from gem-vram. - Remove the now unused kmap-object argument from vram helpers. - Stop checking return value of debugfs_create. - Add atomic encoder enable/disable helpers. - pass drm_atomic_state to atomic connector check. - Add atomic support for bridge enable/disable. - Add self refresh helpers to core. Driver Changes: - Add extra delay to make MTP SDM845 work. - Small fixes to virtio, vkms, sii902x, sii9234, ast, mcde, analogix, rockchip. - Add zpos and ?BGR8888 support to meson. - More removals of drm_os_linux and drmP headers for amd, radeon, sti, r128, r128, savage, sis. - Allow synopsis to unwedge the i2c hdmi bus. - Add orientation quirks for GPD panels. - Edid cleanups and fixing handling for edid < 1.2. - Add runtime pm to stm. - Handle s/r in dw-hdmi. - Add hooks for power on/off to dsi for stm. - Remove virtio dirty tracking code, done in drm core. - Rework BO handling in ast and mgag200. Tiny conflict in drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c, needed #include <linux/slab.h> to make it compile. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/0e01de30-9797-853c-732f-4a5bd6e61445@linux.intel.com
333 lines
8.3 KiB
C
333 lines
8.3 KiB
C
/*
|
|
* Copyright 2015 Advanced Micro Devices, Inc.
|
|
* All Rights Reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the
|
|
* "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The above copyright notice and this permission notice (including the
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
* of the Software.
|
|
*
|
|
*/
|
|
/*
|
|
* Authors:
|
|
* Christian König <deathsimple@vodafone.de>
|
|
*/
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include "amdgpu.h"
|
|
#include "amdgpu_trace.h"
|
|
|
|
#define AMDGPU_BO_LIST_MAX_PRIORITY 32u
|
|
#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1)
|
|
|
|
static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
|
|
{
|
|
struct amdgpu_bo_list *list = container_of(rcu, struct amdgpu_bo_list,
|
|
rhead);
|
|
|
|
kvfree(list);
|
|
}
|
|
|
|
static void amdgpu_bo_list_free(struct kref *ref)
|
|
{
|
|
struct amdgpu_bo_list *list = container_of(ref, struct amdgpu_bo_list,
|
|
refcount);
|
|
struct amdgpu_bo_list_entry *e;
|
|
|
|
amdgpu_bo_list_for_each_entry(e, list) {
|
|
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo);
|
|
|
|
amdgpu_bo_unref(&bo);
|
|
}
|
|
|
|
call_rcu(&list->rhead, amdgpu_bo_list_free_rcu);
|
|
}
|
|
|
|
int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
|
|
struct drm_amdgpu_bo_list_entry *info,
|
|
unsigned num_entries, struct amdgpu_bo_list **result)
|
|
{
|
|
unsigned last_entry = 0, first_userptr = num_entries;
|
|
struct amdgpu_bo_list_entry *array;
|
|
struct amdgpu_bo_list *list;
|
|
uint64_t total_size = 0;
|
|
size_t size;
|
|
unsigned i;
|
|
int r;
|
|
|
|
if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
|
|
/ sizeof(struct amdgpu_bo_list_entry))
|
|
return -EINVAL;
|
|
|
|
size = sizeof(struct amdgpu_bo_list);
|
|
size += num_entries * sizeof(struct amdgpu_bo_list_entry);
|
|
list = kvmalloc(size, GFP_KERNEL);
|
|
if (!list)
|
|
return -ENOMEM;
|
|
|
|
kref_init(&list->refcount);
|
|
list->gds_obj = NULL;
|
|
list->gws_obj = NULL;
|
|
list->oa_obj = NULL;
|
|
|
|
array = amdgpu_bo_list_array_entry(list, 0);
|
|
memset(array, 0, num_entries * sizeof(struct amdgpu_bo_list_entry));
|
|
|
|
for (i = 0; i < num_entries; ++i) {
|
|
struct amdgpu_bo_list_entry *entry;
|
|
struct drm_gem_object *gobj;
|
|
struct amdgpu_bo *bo;
|
|
struct mm_struct *usermm;
|
|
|
|
gobj = drm_gem_object_lookup(filp, info[i].bo_handle);
|
|
if (!gobj) {
|
|
r = -ENOENT;
|
|
goto error_free;
|
|
}
|
|
|
|
bo = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj));
|
|
drm_gem_object_put_unlocked(gobj);
|
|
|
|
usermm = amdgpu_ttm_tt_get_usermm(bo->tbo.ttm);
|
|
if (usermm) {
|
|
if (usermm != current->mm) {
|
|
amdgpu_bo_unref(&bo);
|
|
r = -EPERM;
|
|
goto error_free;
|
|
}
|
|
entry = &array[--first_userptr];
|
|
} else {
|
|
entry = &array[last_entry++];
|
|
}
|
|
|
|
entry->priority = min(info[i].bo_priority,
|
|
AMDGPU_BO_LIST_MAX_PRIORITY);
|
|
entry->tv.bo = &bo->tbo;
|
|
|
|
if (bo->preferred_domains == AMDGPU_GEM_DOMAIN_GDS)
|
|
list->gds_obj = bo;
|
|
if (bo->preferred_domains == AMDGPU_GEM_DOMAIN_GWS)
|
|
list->gws_obj = bo;
|
|
if (bo->preferred_domains == AMDGPU_GEM_DOMAIN_OA)
|
|
list->oa_obj = bo;
|
|
|
|
total_size += amdgpu_bo_size(bo);
|
|
trace_amdgpu_bo_list_set(list, bo);
|
|
}
|
|
|
|
list->first_userptr = first_userptr;
|
|
list->num_entries = num_entries;
|
|
|
|
trace_amdgpu_cs_bo_status(list->num_entries, total_size);
|
|
|
|
*result = list;
|
|
return 0;
|
|
|
|
error_free:
|
|
while (i--) {
|
|
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(array[i].tv.bo);
|
|
|
|
amdgpu_bo_unref(&bo);
|
|
}
|
|
kvfree(list);
|
|
return r;
|
|
|
|
}
|
|
|
|
static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id)
|
|
{
|
|
struct amdgpu_bo_list *list;
|
|
|
|
mutex_lock(&fpriv->bo_list_lock);
|
|
list = idr_remove(&fpriv->bo_list_handles, id);
|
|
mutex_unlock(&fpriv->bo_list_lock);
|
|
if (list)
|
|
kref_put(&list->refcount, amdgpu_bo_list_free);
|
|
}
|
|
|
|
int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id,
|
|
struct amdgpu_bo_list **result)
|
|
{
|
|
rcu_read_lock();
|
|
*result = idr_find(&fpriv->bo_list_handles, id);
|
|
|
|
if (*result && kref_get_unless_zero(&(*result)->refcount)) {
|
|
rcu_read_unlock();
|
|
return 0;
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
return -ENOENT;
|
|
}
|
|
|
|
void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
|
|
struct list_head *validated)
|
|
{
|
|
/* This is based on the bucket sort with O(n) time complexity.
|
|
* An item with priority "i" is added to bucket[i]. The lists are then
|
|
* concatenated in descending order.
|
|
*/
|
|
struct list_head bucket[AMDGPU_BO_LIST_NUM_BUCKETS];
|
|
struct amdgpu_bo_list_entry *e;
|
|
unsigned i;
|
|
|
|
for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
|
|
INIT_LIST_HEAD(&bucket[i]);
|
|
|
|
/* Since buffers which appear sooner in the relocation list are
|
|
* likely to be used more often than buffers which appear later
|
|
* in the list, the sort mustn't change the ordering of buffers
|
|
* with the same priority, i.e. it must be stable.
|
|
*/
|
|
amdgpu_bo_list_for_each_entry(e, list) {
|
|
struct amdgpu_bo *bo = ttm_to_amdgpu_bo(e->tv.bo);
|
|
unsigned priority = e->priority;
|
|
|
|
if (!bo->parent)
|
|
list_add_tail(&e->tv.head, &bucket[priority]);
|
|
|
|
e->user_pages = NULL;
|
|
}
|
|
|
|
/* Connect the sorted buckets in the output list. */
|
|
for (i = 0; i < AMDGPU_BO_LIST_NUM_BUCKETS; i++)
|
|
list_splice(&bucket[i], validated);
|
|
}
|
|
|
|
void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
|
|
{
|
|
kref_put(&list->refcount, amdgpu_bo_list_free);
|
|
}
|
|
|
|
int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
|
|
struct drm_amdgpu_bo_list_entry **info_param)
|
|
{
|
|
const void __user *uptr = u64_to_user_ptr(in->bo_info_ptr);
|
|
const uint32_t info_size = sizeof(struct drm_amdgpu_bo_list_entry);
|
|
struct drm_amdgpu_bo_list_entry *info;
|
|
int r;
|
|
|
|
info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
|
|
if (!info)
|
|
return -ENOMEM;
|
|
|
|
/* copy the handle array from userspace to a kernel buffer */
|
|
r = -EFAULT;
|
|
if (likely(info_size == in->bo_info_size)) {
|
|
unsigned long bytes = in->bo_number *
|
|
in->bo_info_size;
|
|
|
|
if (copy_from_user(info, uptr, bytes))
|
|
goto error_free;
|
|
|
|
} else {
|
|
unsigned long bytes = min(in->bo_info_size, info_size);
|
|
unsigned i;
|
|
|
|
memset(info, 0, in->bo_number * info_size);
|
|
for (i = 0; i < in->bo_number; ++i) {
|
|
if (copy_from_user(&info[i], uptr, bytes))
|
|
goto error_free;
|
|
|
|
uptr += in->bo_info_size;
|
|
}
|
|
}
|
|
|
|
*info_param = info;
|
|
return 0;
|
|
|
|
error_free:
|
|
kvfree(info);
|
|
return r;
|
|
}
|
|
|
|
int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *filp)
|
|
{
|
|
struct amdgpu_device *adev = dev->dev_private;
|
|
struct amdgpu_fpriv *fpriv = filp->driver_priv;
|
|
union drm_amdgpu_bo_list *args = data;
|
|
uint32_t handle = args->in.list_handle;
|
|
struct drm_amdgpu_bo_list_entry *info = NULL;
|
|
struct amdgpu_bo_list *list, *old;
|
|
int r;
|
|
|
|
r = amdgpu_bo_create_list_entry_array(&args->in, &info);
|
|
if (r)
|
|
goto error_free;
|
|
|
|
switch (args->in.operation) {
|
|
case AMDGPU_BO_LIST_OP_CREATE:
|
|
r = amdgpu_bo_list_create(adev, filp, info, args->in.bo_number,
|
|
&list);
|
|
if (r)
|
|
goto error_free;
|
|
|
|
mutex_lock(&fpriv->bo_list_lock);
|
|
r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL);
|
|
mutex_unlock(&fpriv->bo_list_lock);
|
|
if (r < 0) {
|
|
amdgpu_bo_list_put(list);
|
|
return r;
|
|
}
|
|
|
|
handle = r;
|
|
break;
|
|
|
|
case AMDGPU_BO_LIST_OP_DESTROY:
|
|
amdgpu_bo_list_destroy(fpriv, handle);
|
|
handle = 0;
|
|
break;
|
|
|
|
case AMDGPU_BO_LIST_OP_UPDATE:
|
|
r = amdgpu_bo_list_create(adev, filp, info, args->in.bo_number,
|
|
&list);
|
|
if (r)
|
|
goto error_free;
|
|
|
|
mutex_lock(&fpriv->bo_list_lock);
|
|
old = idr_replace(&fpriv->bo_list_handles, list, handle);
|
|
mutex_unlock(&fpriv->bo_list_lock);
|
|
|
|
if (IS_ERR(old)) {
|
|
amdgpu_bo_list_put(list);
|
|
r = PTR_ERR(old);
|
|
goto error_free;
|
|
}
|
|
|
|
amdgpu_bo_list_put(old);
|
|
break;
|
|
|
|
default:
|
|
r = -EINVAL;
|
|
goto error_free;
|
|
}
|
|
|
|
memset(args, 0, sizeof(*args));
|
|
args->out.list_handle = handle;
|
|
kvfree(info);
|
|
|
|
return 0;
|
|
|
|
error_free:
|
|
if (info)
|
|
kvfree(info);
|
|
return r;
|
|
}
|