Changes in 4.9.187 MIPS: ath79: fix ar933x uart parity mode MIPS: fix build on non-linux hosts arm64/efi: Mark __efistub_stext_offset as an absolute symbol explicitly dmaengine: imx-sdma: fix use-after-free on probe error path ath10k: Do not send probe response template for mesh ath9k: Check for errors when reading SREV register ath6kl: add some bounds checking ath: DFS JP domain W56 fixed pulse type 3 RADAR detection batman-adv: fix for leaked TVLV handler. media: dvb: usb: fix use after free in dvb_usb_device_exit crypto: talitos - fix skcipher failure due to wrong output IV media: marvell-ccic: fix DMA s/g desc number calculation media: vpss: fix a potential NULL pointer dereference media: media_device_enum_links32: clean a reserved field net: stmmac: dwmac1000: Clear unused address entries net: stmmac: dwmac4/5: Clear unused address entries signal/pid_namespace: Fix reboot_pid_ns to use send_sig not force_sig af_key: fix leaks in key_pol_get_resp and dump_sp. xfrm: Fix xfrm sel prefix length validation media: mc-device.c: don't memset __user pointer contents media: staging: media: davinci_vpfe: - Fix for memory leak if decoder initialization fails. net: phy: Check against net_device being NULL crypto: talitos - properly handle split ICV. crypto: talitos - Align SEC1 accesses to 32 bits boundaries. tua6100: Avoid build warnings. locking/lockdep: Fix merging of hlocks with non-zero references media: wl128x: Fix some error handling in fm_v4l2_init_video_device() cpupower : frequency-set -r option misses the last cpu in related cpu list net: fec: Do not use netdev messages too early net: axienet: Fix race condition causing TX hang s390/qdio: handle PENDING state for QEBSM devices perf cs-etm: Properly set the value of 'old' and 'head' in snapshot mode perf test 6: Fix missing kvm module load for s390 gpio: omap: fix lack of irqstatus_raw0 for OMAP4 gpio: omap: ensure irq is enabled before wakeup regmap: fix bulk writes on paged registers bpf: silence warning messages in core rcu: Force inlining of rcu_read_lock() blkcg, writeback: dead memcgs shouldn't contribute to writeback ownership arbitration xfrm: fix sa selector validation perf evsel: Make perf_evsel__name() accept a NULL argument vhost_net: disable zerocopy by default ipoib: correcly show a VF hardware address EDAC/sysfs: Fix memory leak when creating a csrow object ipsec: select crypto ciphers for xfrm_algo media: i2c: fix warning same module names ntp: Limit TAI-UTC offset timer_list: Guard procfs specific code acpi/arm64: ignore 5.1 FADTs that are reported as 5.0 media: coda: fix mpeg2 sequence number handling media: coda: increment sequence offset for the last returned frame mt7601u: do not schedule rx_tasklet when the device has been disconnected x86/build: Add 'set -e' to mkcapflags.sh to delete broken capflags.c mt7601u: fix possible memory leak when the device is disconnected ath10k: fix PCIE device wake up failed perf tools: Increase MAX_NR_CPUS and MAX_CACHES libata: don't request sense data on !ZAC ATA devices clocksource/drivers/exynos_mct: Increase priority over ARM arch timer rslib: Fix decoding of shortened codes rslib: Fix handling of of caller provided syndrome ixgbe: Check DDM existence in transceiver before access crypto: asymmetric_keys - select CRYPTO_HASH where needed EDAC: Fix global-out-of-bounds write when setting edac_mc_poll_msec bcache: check c->gc_thread by IS_ERR_OR_NULL in cache_set_flush() iwlwifi: mvm: Drop large non sta frames net: usb: asix: init MAC address buffers gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants Bluetooth: hci_bcsp: Fix memory leak in rx_skb Bluetooth: 6lowpan: search for destination address in all peers Bluetooth: Check state in l2cap_disconnect_rsp Bluetooth: validate BLE connection interval updates gtp: fix Illegal context switch in RCU read-side critical section. gtp: fix use-after-free in gtp_newlink() xen: let alloc_xenballooned_pages() fail if not enough memory free scsi: NCR5380: Reduce goto statements in NCR5380_select() scsi: NCR5380: Always re-enable reselection interrupt scsi: mac_scsi: Increase PIO/PDMA transfer length threshold crypto: ghash - fix unaligned memory access in ghash_setkey() crypto: arm64/sha1-ce - correct digest for empty data in finup crypto: arm64/sha2-ce - correct digest for empty data in finup crypto: chacha20poly1305 - fix atomic sleep when using async algorithm crypto: crypto4xx - fix a potential double free in ppc4xx_trng_probe Input: gtco - bounds check collection indent level regulator: s2mps11: Fix buck7 and buck8 wrong voltages arm64: tegra: Update Jetson TX1 GPU regulator timings iwlwifi: pcie: don't service an interrupt that was masked tracing/snapshot: Resize spare buffer if size changed NFSv4: Handle the special Linux file open access mode lib/scatterlist: Fix mapping iterator when sg->offset is greater than PAGE_SIZE ALSA: seq: Break too long mutex context in the write loop ALSA: hda/realtek: apply ALC891 headset fixup to one Dell machine media: v4l2: Test type instead of cfg->type in v4l2_ctrl_new_custom() media: coda: Remove unbalanced and unneeded mutex unlock KVM: x86/vPMU: refine kvm_pmu err msg when event creation failed arm64: tegra: Fix AGIC register range fs/proc/proc_sysctl.c: fix the default values of i_uid/i_gid on /proc/sys inodes. drm/nouveau/i2c: Enable i2c pads & busses during preinit padata: use smp_mb in padata_reorder to avoid orphaned padata jobs 9p/virtio: Add cleanup path in p9_virtio_init PCI: Do not poll for PME if the device is in D3cold Btrfs: add missing inode version, ctime and mtime updates when punching hole libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields take floppy compat ioctls to sodding floppy.c floppy: fix div-by-zero in setup_format_params floppy: fix out-of-bounds read in next_valid_format floppy: fix invalid pointer dereference in drive_name floppy: fix out-of-bounds read in copy_buffer coda: pass the host file in vma->vm_file on mmap gpu: ipu-v3: ipu-ic: Fix saturation bit offset in TPMEM crypto: ccp - Validate the the error value used to index error messages PCI: hv: Delete the device earlier from hbus->children for hot-remove PCI: hv: Fix a use-after-free bug in hv_eject_device_work() crypto: caam - limit output IV to CBC to work around CTR mode DMA issue um: Allow building and running on older hosts um: Fix FP register size for XSTATE/XSAVE parisc: Ensure userspace privilege for ptraced processes in regset functions parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1 powerpc/32s: fix suspend/resume when IBATs 4-7 are used powerpc/watchpoint: Restore NV GPRs while returning from exception eCryptfs: fix a couple type promotion bugs intel_th: msu: Fix single mode with disabled IOMMU Bluetooth: Add SMP workaround Microsoft Surface Precision Mouse bug usb: Handle USB3 remote wakeup for LPM enabled devices correctly dm bufio: fix deadlock with loop device compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() compiler.h: Add read_word_at_a_time() function. lib/strscpy: Shut up KASAN false-positives in strscpy() ext4: allow directory holes bnx2x: Prevent load reordering in tx completion processing bnx2x: Prevent ptp_task to be rescheduled indefinitely caif-hsi: fix possible deadlock in cfhsi_exit_module() igmp: fix memory leak in igmpv3_del_delrec() ipv4: don't set IPv6 only flags to IPv4 addresses net: bcmgenet: use promisc for unsupported filters net: dsa: mv88e6xxx: wait after reset deactivation net: neigh: fix multiple neigh timer scheduling net: openvswitch: fix csum updates for MPLS actions nfc: fix potential illegal memory access rxrpc: Fix send on a connected, but unbound socket sky2: Disable MSI on ASUS P6T vrf: make sure skb->data contains ip header to make routing macsec: fix use-after-free of skb during RX macsec: fix checksumming after decryption netrom: fix a memory leak in nr_rx_frame() netrom: hold sock when setting skb->destructor bonding: validate ip header before check IPPROTO_IGMP tcp: Reset bytes_acked and bytes_received when disconnecting net: bridge: mcast: fix stale nsrcs pointer in igmp3/mld2 report handling net: bridge: mcast: fix stale ipv6 hdr pointer when handling v6 query net: bridge: stp: don't cache eth dest pointer before skb pull perf/x86/amd/uncore: Rename 'L2' to 'LLC' perf/x86/amd/uncore: Get correct number of cores sharing last level cache perf/events/amd/uncore: Fix amd_uncore_llc ID to use pre-defined cpu_llc_id NFSv4: Fix open create exclusive when the server reboots nfsd: increase DRC cache limit nfsd: give out fewer session slots as limit approaches nfsd: fix performance-limiting session calculation nfsd: Fix overflow causing non-working mounts on 1 TB machines drm/panel: simple: Fix panel_simple_dsi_probe usb: core: hub: Disable hub-initiated U1/U2 tty: max310x: Fix invalid baudrate divisors calculator pinctrl: rockchip: fix leaked of_node references tty: serial: cpm_uart - fix init when SMC is relocated drm/bridge: tc358767: read display_props in get_modes() drm/bridge: sii902x: pixel clock unit is 10kHz instead of 1kHz memstick: Fix error cleanup path of memstick_init tty/serial: digicolor: Fix digicolor-usart already registered warning tty: serial: msm_serial: avoid system lockup condition serial: 8250: Fix TX interrupt handling condition drm/virtio: Add memory barriers for capset cache. phy: renesas: rcar-gen2: Fix memory leak at error paths drm/rockchip: Properly adjust to a true clock in adjusted_mode tty: serial_core: Set port active bit in uart_port_activate usb: gadget: Zero ffs_io_data powerpc/pci/of: Fix OF flags parsing for 64bit BARs PCI: sysfs: Ignore lockdep for remove attribute kbuild: Add -Werror=unknown-warning-option to CLANG_FLAGS PCI: xilinx-nwl: Fix Multi MSI data programming iio: iio-utils: Fix possible incorrect mask calculation recordmcount: Fix spurious mcount entries on powerpc mfd: core: Set fwnode for created devices mfd: arizona: Fix undefined behavior mfd: hi655x-pmic: Fix missing return value check for devm_regmap_init_mmio_clk um: Silence lockdep complaint about mmap_sem powerpc/4xx/uic: clear pending interrupt after irq type/pol change RDMA/i40iw: Set queue pair state when being queried serial: sh-sci: Terminate TX DMA during buffer flushing serial: sh-sci: Fix TX DMA buffer flushing and workqueue races kallsyms: exclude kasan local symbols on s390 perf test mmap-thread-lookup: Initialize variable to suppress memory sanitizer warning RDMA/rxe: Fill in wc byte_len with IB_WC_RECV_RDMA_WITH_IMM powerpc/boot: add {get, put}_unaligned_be32 to xz_config.h f2fs: avoid out-of-range memory access mailbox: handle failed named mailbox channel request powerpc/eeh: Handle hugepages in ioremap space sh: prevent warnings when using iounmap mm/kmemleak.c: fix check for softirq context 9p: pass the correct prototype to read_cache_page mm/mmu_notifier: use hlist_add_head_rcu() locking/lockdep: Fix lock used or unused stats error locking/lockdep: Hide unused 'class' variable usb: wusbcore: fix unbalanced get/put cluster_id usb: pci-quirks: Correct AMD PLL quirk detection x86/sysfb_efi: Add quirks for some devices with swapped width and height x86/speculation/mds: Apply more accurate check on hypervisor platform hpet: Fix division by zero in hpet_time_div() ALSA: line6: Fix wrong altsetting for LINE6_PODHD500_1 ALSA: hda - Add a conexant codec entry to let mute led work powerpc/tm: Fix oops on sigreturn on systems without TM access: avoid the RCU grace period for the temporary subjective credentials ipv6: check sk sk_type and protocol early in ip_mroute_set/getsockopt tcp: reset sk_send_head in tcp_write_queue_purge arm64: dts: marvell: Fix A37xx UART0 register size i2c: qup: fixed releasing dma without flush operation completion arm64: compat: Provide definition for COMPAT_SIGMINSTKSZ ISDN: hfcsusb: checking idx of ep configuration media: au0828: fix null dereference in error path media: cpia2_usb: first wake up, then free in disconnect media: radio-raremono: change devm_k*alloc to k*alloc Bluetooth: hci_uart: check for missing tty operations sched/fair: Don't free p->numa_faults with concurrent readers drivers/pps/pps.c: clear offset flags in PPS_SETPARAMS ioctl ceph: hold i_ceph_lock when removing caps for freeing inode Linux 4.9.187 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
568 lines
15 KiB
C
568 lines
15 KiB
C
/*
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
|
* All Rights Reserved.
|
|
*
|
|
* Authors:
|
|
* Dave Airlie
|
|
* Alon Levy
|
|
*
|
|
* 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, sublicense,
|
|
* 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 above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
|
|
*/
|
|
|
|
#include <drm/drmP.h>
|
|
#include "virtgpu_drv.h"
|
|
#include <drm/virtgpu_drm.h>
|
|
#include "ttm/ttm_execbuf_util.h"
|
|
|
|
static void convert_to_hw_box(struct virtio_gpu_box *dst,
|
|
const struct drm_virtgpu_3d_box *src)
|
|
{
|
|
dst->x = cpu_to_le32(src->x);
|
|
dst->y = cpu_to_le32(src->y);
|
|
dst->z = cpu_to_le32(src->z);
|
|
dst->w = cpu_to_le32(src->w);
|
|
dst->h = cpu_to_le32(src->h);
|
|
dst->d = cpu_to_le32(src->d);
|
|
}
|
|
|
|
static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file_priv)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct drm_virtgpu_map *virtio_gpu_map = data;
|
|
|
|
return virtio_gpu_mode_dumb_mmap(file_priv, vgdev->ddev,
|
|
virtio_gpu_map->handle,
|
|
&virtio_gpu_map->offset);
|
|
}
|
|
|
|
static int virtio_gpu_object_list_validate(struct ww_acquire_ctx *ticket,
|
|
struct list_head *head)
|
|
{
|
|
struct ttm_validate_buffer *buf;
|
|
struct ttm_buffer_object *bo;
|
|
struct virtio_gpu_object *qobj;
|
|
int ret;
|
|
|
|
ret = ttm_eu_reserve_buffers(ticket, head, true, NULL);
|
|
if (ret != 0)
|
|
return ret;
|
|
|
|
list_for_each_entry(buf, head, head) {
|
|
bo = buf->bo;
|
|
qobj = container_of(bo, struct virtio_gpu_object, tbo);
|
|
ret = ttm_bo_validate(bo, &qobj->placement, false, false);
|
|
if (ret) {
|
|
ttm_eu_backoff_reservation(ticket, head);
|
|
return ret;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void virtio_gpu_unref_list(struct list_head *head)
|
|
{
|
|
struct ttm_validate_buffer *buf;
|
|
struct ttm_buffer_object *bo;
|
|
struct virtio_gpu_object *qobj;
|
|
list_for_each_entry(buf, head, head) {
|
|
bo = buf->bo;
|
|
qobj = container_of(bo, struct virtio_gpu_object, tbo);
|
|
|
|
drm_gem_object_unreference_unlocked(&qobj->gem_base);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Usage of execbuffer:
|
|
* Relocations need to take into account the full VIRTIO_GPUDrawable size.
|
|
* However, the command as passed from user space must *not* contain the initial
|
|
* VIRTIO_GPUReleaseInfo struct (first XXX bytes)
|
|
*/
|
|
static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *drm_file)
|
|
{
|
|
struct drm_virtgpu_execbuffer *exbuf = data;
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct virtio_gpu_fpriv *vfpriv = drm_file->driver_priv;
|
|
struct drm_gem_object *gobj;
|
|
struct virtio_gpu_fence *fence;
|
|
struct virtio_gpu_object *qobj;
|
|
int ret;
|
|
uint32_t *bo_handles = NULL;
|
|
void __user *user_bo_handles = NULL;
|
|
struct list_head validate_list;
|
|
struct ttm_validate_buffer *buflist = NULL;
|
|
int i;
|
|
struct ww_acquire_ctx ticket;
|
|
void *buf;
|
|
|
|
if (vgdev->has_virgl_3d == false)
|
|
return -ENOSYS;
|
|
|
|
INIT_LIST_HEAD(&validate_list);
|
|
if (exbuf->num_bo_handles) {
|
|
|
|
bo_handles = drm_malloc_ab(exbuf->num_bo_handles,
|
|
sizeof(uint32_t));
|
|
buflist = drm_calloc_large(exbuf->num_bo_handles,
|
|
sizeof(struct ttm_validate_buffer));
|
|
if (!bo_handles || !buflist) {
|
|
drm_free_large(bo_handles);
|
|
drm_free_large(buflist);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
user_bo_handles = (void __user *)(uintptr_t)exbuf->bo_handles;
|
|
if (copy_from_user(bo_handles, user_bo_handles,
|
|
exbuf->num_bo_handles * sizeof(uint32_t))) {
|
|
ret = -EFAULT;
|
|
drm_free_large(bo_handles);
|
|
drm_free_large(buflist);
|
|
return ret;
|
|
}
|
|
|
|
for (i = 0; i < exbuf->num_bo_handles; i++) {
|
|
gobj = drm_gem_object_lookup(drm_file, bo_handles[i]);
|
|
if (!gobj) {
|
|
drm_free_large(bo_handles);
|
|
drm_free_large(buflist);
|
|
return -ENOENT;
|
|
}
|
|
|
|
qobj = gem_to_virtio_gpu_obj(gobj);
|
|
buflist[i].bo = &qobj->tbo;
|
|
|
|
list_add(&buflist[i].head, &validate_list);
|
|
}
|
|
drm_free_large(bo_handles);
|
|
}
|
|
|
|
ret = virtio_gpu_object_list_validate(&ticket, &validate_list);
|
|
if (ret)
|
|
goto out_free;
|
|
|
|
buf = memdup_user((void __user *)(uintptr_t)exbuf->command,
|
|
exbuf->size);
|
|
if (IS_ERR(buf)) {
|
|
ret = PTR_ERR(buf);
|
|
goto out_unresv;
|
|
}
|
|
virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,
|
|
vfpriv->ctx_id, &fence);
|
|
|
|
ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f);
|
|
|
|
/* fence the command bo */
|
|
virtio_gpu_unref_list(&validate_list);
|
|
drm_free_large(buflist);
|
|
fence_put(&fence->f);
|
|
return 0;
|
|
|
|
out_unresv:
|
|
ttm_eu_backoff_reservation(&ticket, &validate_list);
|
|
out_free:
|
|
virtio_gpu_unref_list(&validate_list);
|
|
drm_free_large(buflist);
|
|
return ret;
|
|
}
|
|
|
|
static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file_priv)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct drm_virtgpu_getparam *param = data;
|
|
int value;
|
|
|
|
switch (param->param) {
|
|
case VIRTGPU_PARAM_3D_FEATURES:
|
|
value = vgdev->has_virgl_3d == true ? 1 : 0;
|
|
break;
|
|
case VIRTGPU_PARAM_CAPSET_QUERY_FIX:
|
|
value = 1;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
if (copy_to_user((void __user *)(unsigned long)param->value,
|
|
&value, sizeof(int))) {
|
|
return -EFAULT;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file_priv)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct drm_virtgpu_resource_create *rc = data;
|
|
int ret;
|
|
uint32_t res_id;
|
|
struct virtio_gpu_object *qobj;
|
|
struct drm_gem_object *obj;
|
|
uint32_t handle = 0;
|
|
uint32_t size;
|
|
struct list_head validate_list;
|
|
struct ttm_validate_buffer mainbuf;
|
|
struct virtio_gpu_fence *fence = NULL;
|
|
struct ww_acquire_ctx ticket;
|
|
struct virtio_gpu_resource_create_3d rc_3d;
|
|
|
|
if (vgdev->has_virgl_3d == false) {
|
|
if (rc->depth > 1)
|
|
return -EINVAL;
|
|
if (rc->nr_samples > 1)
|
|
return -EINVAL;
|
|
if (rc->last_level > 1)
|
|
return -EINVAL;
|
|
if (rc->target != 2)
|
|
return -EINVAL;
|
|
if (rc->array_size > 1)
|
|
return -EINVAL;
|
|
}
|
|
|
|
INIT_LIST_HEAD(&validate_list);
|
|
memset(&mainbuf, 0, sizeof(struct ttm_validate_buffer));
|
|
|
|
virtio_gpu_resource_id_get(vgdev, &res_id);
|
|
|
|
size = rc->size;
|
|
|
|
/* allocate a single page size object */
|
|
if (size == 0)
|
|
size = PAGE_SIZE;
|
|
|
|
qobj = virtio_gpu_alloc_object(dev, size, false, false);
|
|
if (IS_ERR(qobj)) {
|
|
ret = PTR_ERR(qobj);
|
|
goto fail_id;
|
|
}
|
|
obj = &qobj->gem_base;
|
|
|
|
if (!vgdev->has_virgl_3d) {
|
|
virtio_gpu_cmd_create_resource(vgdev, res_id, rc->format,
|
|
rc->width, rc->height);
|
|
|
|
ret = virtio_gpu_object_attach(vgdev, qobj, res_id, NULL);
|
|
} else {
|
|
/* use a gem reference since unref list undoes them */
|
|
drm_gem_object_reference(&qobj->gem_base);
|
|
mainbuf.bo = &qobj->tbo;
|
|
list_add(&mainbuf.head, &validate_list);
|
|
|
|
ret = virtio_gpu_object_list_validate(&ticket, &validate_list);
|
|
if (ret) {
|
|
DRM_DEBUG("failed to validate\n");
|
|
goto fail_unref;
|
|
}
|
|
|
|
rc_3d.resource_id = cpu_to_le32(res_id);
|
|
rc_3d.target = cpu_to_le32(rc->target);
|
|
rc_3d.format = cpu_to_le32(rc->format);
|
|
rc_3d.bind = cpu_to_le32(rc->bind);
|
|
rc_3d.width = cpu_to_le32(rc->width);
|
|
rc_3d.height = cpu_to_le32(rc->height);
|
|
rc_3d.depth = cpu_to_le32(rc->depth);
|
|
rc_3d.array_size = cpu_to_le32(rc->array_size);
|
|
rc_3d.last_level = cpu_to_le32(rc->last_level);
|
|
rc_3d.nr_samples = cpu_to_le32(rc->nr_samples);
|
|
rc_3d.flags = cpu_to_le32(rc->flags);
|
|
|
|
virtio_gpu_cmd_resource_create_3d(vgdev, &rc_3d, NULL);
|
|
ret = virtio_gpu_object_attach(vgdev, qobj, res_id, &fence);
|
|
if (ret) {
|
|
ttm_eu_backoff_reservation(&ticket, &validate_list);
|
|
goto fail_unref;
|
|
}
|
|
ttm_eu_fence_buffer_objects(&ticket, &validate_list, &fence->f);
|
|
}
|
|
|
|
qobj->hw_res_handle = res_id;
|
|
|
|
ret = drm_gem_handle_create(file_priv, obj, &handle);
|
|
if (ret) {
|
|
|
|
drm_gem_object_release(obj);
|
|
if (vgdev->has_virgl_3d) {
|
|
virtio_gpu_unref_list(&validate_list);
|
|
fence_put(&fence->f);
|
|
}
|
|
return ret;
|
|
}
|
|
drm_gem_object_unreference_unlocked(obj);
|
|
|
|
rc->res_handle = res_id; /* similiar to a VM address */
|
|
rc->bo_handle = handle;
|
|
|
|
if (vgdev->has_virgl_3d) {
|
|
virtio_gpu_unref_list(&validate_list);
|
|
fence_put(&fence->f);
|
|
}
|
|
return 0;
|
|
fail_unref:
|
|
if (vgdev->has_virgl_3d) {
|
|
virtio_gpu_unref_list(&validate_list);
|
|
fence_put(&fence->f);
|
|
}
|
|
//fail_obj:
|
|
// drm_gem_object_handle_unreference_unlocked(obj);
|
|
fail_id:
|
|
virtio_gpu_resource_id_put(vgdev, res_id);
|
|
return ret;
|
|
}
|
|
|
|
static int virtio_gpu_resource_info_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file_priv)
|
|
{
|
|
struct drm_virtgpu_resource_info *ri = data;
|
|
struct drm_gem_object *gobj = NULL;
|
|
struct virtio_gpu_object *qobj = NULL;
|
|
|
|
gobj = drm_gem_object_lookup(file_priv, ri->bo_handle);
|
|
if (gobj == NULL)
|
|
return -ENOENT;
|
|
|
|
qobj = gem_to_virtio_gpu_obj(gobj);
|
|
|
|
ri->size = qobj->gem_base.size;
|
|
ri->res_handle = qobj->hw_res_handle;
|
|
drm_gem_object_unreference_unlocked(gobj);
|
|
return 0;
|
|
}
|
|
|
|
static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,
|
|
void *data,
|
|
struct drm_file *file)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
|
|
struct drm_virtgpu_3d_transfer_from_host *args = data;
|
|
struct drm_gem_object *gobj = NULL;
|
|
struct virtio_gpu_object *qobj = NULL;
|
|
struct virtio_gpu_fence *fence;
|
|
int ret;
|
|
u32 offset = args->offset;
|
|
struct virtio_gpu_box box;
|
|
|
|
if (vgdev->has_virgl_3d == false)
|
|
return -ENOSYS;
|
|
|
|
gobj = drm_gem_object_lookup(file, args->bo_handle);
|
|
if (gobj == NULL)
|
|
return -ENOENT;
|
|
|
|
qobj = gem_to_virtio_gpu_obj(gobj);
|
|
|
|
ret = virtio_gpu_object_reserve(qobj, false);
|
|
if (ret)
|
|
goto out;
|
|
|
|
ret = ttm_bo_validate(&qobj->tbo, &qobj->placement,
|
|
true, false);
|
|
if (unlikely(ret))
|
|
goto out_unres;
|
|
|
|
convert_to_hw_box(&box, &args->box);
|
|
virtio_gpu_cmd_transfer_from_host_3d
|
|
(vgdev, qobj->hw_res_handle,
|
|
vfpriv->ctx_id, offset, args->level,
|
|
&box, &fence);
|
|
reservation_object_add_excl_fence(qobj->tbo.resv,
|
|
&fence->f);
|
|
|
|
fence_put(&fence->f);
|
|
out_unres:
|
|
virtio_gpu_object_unreserve(qobj);
|
|
out:
|
|
drm_gem_object_unreference_unlocked(gobj);
|
|
return ret;
|
|
}
|
|
|
|
static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
|
|
struct drm_virtgpu_3d_transfer_to_host *args = data;
|
|
struct drm_gem_object *gobj = NULL;
|
|
struct virtio_gpu_object *qobj = NULL;
|
|
struct virtio_gpu_fence *fence;
|
|
struct virtio_gpu_box box;
|
|
int ret;
|
|
u32 offset = args->offset;
|
|
|
|
gobj = drm_gem_object_lookup(file, args->bo_handle);
|
|
if (gobj == NULL)
|
|
return -ENOENT;
|
|
|
|
qobj = gem_to_virtio_gpu_obj(gobj);
|
|
|
|
ret = virtio_gpu_object_reserve(qobj, false);
|
|
if (ret)
|
|
goto out;
|
|
|
|
ret = ttm_bo_validate(&qobj->tbo, &qobj->placement,
|
|
true, false);
|
|
if (unlikely(ret))
|
|
goto out_unres;
|
|
|
|
convert_to_hw_box(&box, &args->box);
|
|
if (!vgdev->has_virgl_3d) {
|
|
virtio_gpu_cmd_transfer_to_host_2d
|
|
(vgdev, qobj->hw_res_handle, offset,
|
|
box.w, box.h, box.x, box.y, NULL);
|
|
} else {
|
|
virtio_gpu_cmd_transfer_to_host_3d
|
|
(vgdev, qobj->hw_res_handle,
|
|
vfpriv ? vfpriv->ctx_id : 0, offset,
|
|
args->level, &box, &fence);
|
|
reservation_object_add_excl_fence(qobj->tbo.resv,
|
|
&fence->f);
|
|
fence_put(&fence->f);
|
|
}
|
|
|
|
out_unres:
|
|
virtio_gpu_object_unreserve(qobj);
|
|
out:
|
|
drm_gem_object_unreference_unlocked(gobj);
|
|
return ret;
|
|
}
|
|
|
|
static int virtio_gpu_wait_ioctl(struct drm_device *dev, void *data,
|
|
struct drm_file *file)
|
|
{
|
|
struct drm_virtgpu_3d_wait *args = data;
|
|
struct drm_gem_object *gobj = NULL;
|
|
struct virtio_gpu_object *qobj = NULL;
|
|
int ret;
|
|
bool nowait = false;
|
|
|
|
gobj = drm_gem_object_lookup(file, args->handle);
|
|
if (gobj == NULL)
|
|
return -ENOENT;
|
|
|
|
qobj = gem_to_virtio_gpu_obj(gobj);
|
|
|
|
if (args->flags & VIRTGPU_WAIT_NOWAIT)
|
|
nowait = true;
|
|
ret = virtio_gpu_object_wait(qobj, nowait);
|
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
|
return ret;
|
|
}
|
|
|
|
static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
|
|
void *data, struct drm_file *file)
|
|
{
|
|
struct virtio_gpu_device *vgdev = dev->dev_private;
|
|
struct drm_virtgpu_get_caps *args = data;
|
|
unsigned size, host_caps_size;
|
|
int i;
|
|
int found_valid = -1;
|
|
int ret;
|
|
struct virtio_gpu_drv_cap_cache *cache_ent;
|
|
void *ptr;
|
|
if (vgdev->num_capsets == 0)
|
|
return -ENOSYS;
|
|
|
|
/* don't allow userspace to pass 0 */
|
|
if (args->size == 0)
|
|
return -EINVAL;
|
|
|
|
spin_lock(&vgdev->display_info_lock);
|
|
for (i = 0; i < vgdev->num_capsets; i++) {
|
|
if (vgdev->capsets[i].id == args->cap_set_id) {
|
|
if (vgdev->capsets[i].max_version >= args->cap_set_ver) {
|
|
found_valid = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (found_valid == -1) {
|
|
spin_unlock(&vgdev->display_info_lock);
|
|
return -EINVAL;
|
|
}
|
|
|
|
host_caps_size = vgdev->capsets[found_valid].max_size;
|
|
/* only copy to user the minimum of the host caps size or the guest caps size */
|
|
size = min(args->size, host_caps_size);
|
|
|
|
list_for_each_entry(cache_ent, &vgdev->cap_cache, head) {
|
|
if (cache_ent->id == args->cap_set_id &&
|
|
cache_ent->version == args->cap_set_ver) {
|
|
ptr = cache_ent->caps_cache;
|
|
spin_unlock(&vgdev->display_info_lock);
|
|
goto copy_exit;
|
|
}
|
|
}
|
|
spin_unlock(&vgdev->display_info_lock);
|
|
|
|
/* not in cache - need to talk to hw */
|
|
virtio_gpu_cmd_get_capset(vgdev, found_valid, args->cap_set_ver,
|
|
&cache_ent);
|
|
|
|
ret = wait_event_timeout(vgdev->resp_wq,
|
|
atomic_read(&cache_ent->is_valid), 5 * HZ);
|
|
|
|
/* is_valid check must proceed before copy of the cache entry. */
|
|
smp_rmb();
|
|
|
|
ptr = cache_ent->caps_cache;
|
|
|
|
copy_exit:
|
|
if (copy_to_user((void __user *)(unsigned long)args->addr, ptr, size))
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS] = {
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_MAP, virtio_gpu_map_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_EXECBUFFER, virtio_gpu_execbuffer_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_GETPARAM, virtio_gpu_getparam_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_RESOURCE_CREATE,
|
|
virtio_gpu_resource_create_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_RESOURCE_INFO, virtio_gpu_resource_info_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
/* make transfer async to the main ring? - no sure, can we
|
|
thread these in the underlying GL */
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_TRANSFER_FROM_HOST,
|
|
virtio_gpu_transfer_from_host_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_TRANSFER_TO_HOST,
|
|
virtio_gpu_transfer_to_host_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_WAIT, virtio_gpu_wait_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
|
|
DRM_IOCTL_DEF_DRV(VIRTGPU_GET_CAPS, virtio_gpu_get_caps_ioctl,
|
|
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
|
|
};
|