Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * \file drm_dma.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * DMA IOCTL and function support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * \author Rickard E. (Rik) Faith <faith@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * \author Gareth Hughes <gareth@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Permission is hereby granted, free of charge, to any person obtaining a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * copy of this software and associated documentation files (the "Software"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * to deal in the Software without restriction, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * and/or sell copies of the Software, and to permit persons to whom the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Software is furnished to do so, subject to the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * The above copyright notice and this permission notice (including the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * paragraph) shall be included in all copies or substantial portions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * OTHER DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include "drm_legacy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * drm_legacy_dma_setup() - Initialize the DMA data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @dev: DRM device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Return: zero on success or a negative value on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Allocate and initialize a drm_device_dma structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) int drm_legacy_dma_setup(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	    !drm_core_check_feature(dev, DRIVER_LEGACY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	dev->buf_use = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	atomic_set(&dev->buf_alloc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	dev->dma = kzalloc(sizeof(*dev->dma), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (!dev->dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	for (i = 0; i <= DRM_MAX_ORDER; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * drm_legacy_dma_takedown() - Cleanup the DMA resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * @dev: DRM device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Free all pages associated with DMA buffers, the buffers and pages lists, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * finally the drm_device::dma structure itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) void drm_legacy_dma_takedown(struct drm_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct drm_device_dma *dma = dev->dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	    !drm_core_check_feature(dev, DRIVER_LEGACY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (!dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	/* Clear dma buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	for (i = 0; i <= DRM_MAX_ORDER; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (dma->bufs[i].seg_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			DRM_DEBUG("order %d: buf_count = %d,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				  " seg_count = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				  i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				  dma->bufs[i].buf_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				  dma->bufs[i].seg_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			for (j = 0; j < dma->bufs[i].seg_count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				if (dma->bufs[i].seglist[j]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 					drm_pci_free(dev, dma->bufs[i].seglist[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			kfree(dma->bufs[i].seglist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (dma->bufs[i].buf_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			for (j = 0; j < dma->bufs[i].buf_count; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				kfree(dma->bufs[i].buflist[j].dev_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			kfree(dma->bufs[i].buflist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	kfree(dma->buflist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	kfree(dma->pagelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	kfree(dev->dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	dev->dma = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * drm_legacy_free_buffer() - Free a buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * @dev: DRM device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @buf: buffer to free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * Resets the fields of \p buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void drm_legacy_free_buffer(struct drm_device *dev, struct drm_buf * buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	buf->waiting = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	buf->pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	buf->file_priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	buf->used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * drm_legacy_reclaim_buffers() - Reclaim the buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @dev: DRM device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @file_priv: DRM file private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * Frees each buffer associated with \p file_priv not already on the hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void drm_legacy_reclaim_buffers(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct drm_device_dma *dma = dev->dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (!dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	for (i = 0; i < dma->buf_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (dma->buflist[i]->file_priv == file_priv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			switch (dma->buflist[i]->list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			case DRM_LIST_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				drm_legacy_free_buffer(dev, dma->buflist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			case DRM_LIST_WAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				dma->buflist[i]->list = DRM_LIST_RECLAIM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				/* Buffer already on hardware. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }