"Devon push for Android 13" * tag 'MMI-T2SN33.73-22-3' of https://github.com/MotorolaMobilityLLC/kernel-msm: Revert "spi: spi-msm-geni: Keep device to suspend if PM call fails" BACKPORT: FROMGIT: binder: fix freeze race FROMGIT: binder: BINDER_GET_FROZEN_INFO ioctl binder: BINDER_FREEZE ioctl mm/rmap: Fix anon_vma->degree ambiguity leading to double-reuse techpack: add camera legacy support ANDROID: usb: f_accessory: Check buffer size when initialised via composite ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF video: fbdev: pxa3xx-gcu: Fix integer overflow in pxa3xx_gcu_write ext4: fix kernel infoleak via ext4_extent_header wifi: mac80211_hwsim: avoid mac80211 warning on bad rate fbcon: Disallow setting font bigger than screen size KVM: arm64: Allow SMCCC_ARCH_WORKAROUND_3 to be discovered and migrated arm64: Add Cortex-X2 CPU part definition arm64: Add Neoverse-N2, Cortex-A710 CPU part definition arm64: Add part number for Arm Cortex-A77 fget: check that the fd still exists after getting a ref to it fs: add fget_many() and fput_many() mm: fix misplaced unlock_page in do_wp_page() mm: do_wp_page() simplification mm/ksm: Remove reuse_ksm_page() mm: reuse only-pte-mapped KSM page in do_wp_page() Revert "mm:Fix conflict of speculative fault and MGLRU" mm:vmscan:Update the page scan prioritiy skip USB PHY reset on charger removal fuse:Porting fuse passthrough feature mm: mglru fix on qcom baseline mm:Clean page_io revert conflict Revert write back changes iio:add bc12 type read iio. [rhode]:Modify ldo driver voltage[2/2] configs:Enable multi generation LRU arm64: pgtable: Fix pte_accessible() mm: fix unexpected zeroed page mapping with zram swap mm:Fix conflict of speculative fault and MGLRU FROMLIST: mm: multi-gen LRU: design doc FROMLIST: mm: multi-gen LRU: admin guide FROMLIST: mm: multi-gen LRU: debugfs interface FROMLIST: mm: multi-gen LRU: thrashing prevention FROMLIST: mm: multi-gen LRU: kill switch FROMLIST: mm: multi-gen LRU: optimize multiple memcgs FROMLIST: mm: multi-gen LRU: support page table walks FROMLIST: mm: multi-gen LRU: exploit locality in rmap FROMLIST: mm: multi-gen LRU: minimal implementation FROMLIST: mm: multi-gen LRU: groundwork FROMLIST: mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG FROMLIST: mm: x86, arm64: add arch_has_hw_pte_young() BACKPORT: include/linux/mm_inline.h: fold page_lru_base_type() into its sole caller UPSTREAM: mm: VM_BUG_ON lru page flags BACKPORT: mm: add __clear_page_lru_flags() to replace page_off_lru() BACKPORT: mm/swap.c: don't pass "enum lru_list" to del_page_from_lru_list() UPSTREAM: mm/swap.c: don't pass "enum lru_list" to trace_mm_lru_insertion() BACKPORT: mm: don't pass "enum lru_list" to lru list addition functions BACKPORT: include/linux/mm_inline.h: shuffle lru list addition and deletion functions BACKPORT: mm/vmscan.c: use add_page_to_lru_list() BACKPORT: mm: use self-explanatory macros rather than "2" BACKPORT: mm: remove superfluous __ClearPageActive() BACKPORT: mm/swapcache: support to handle the shadow entries UPSTREAM: mm/vmscan.c: use update_lru_size() in update_lru_sizes() UPSTREAM: arm64: cpufeature: introduce helper cpu_has_hw_af() UPSTREAM: mm: replace list_move_tail() with add_page_to_lru_list_tail() kernel: add PD VDM VERIFY IIO channel. Low flashlight brightness bugfix Hawaii+ OLED: sim1+sim2+sd fast plugging cause phone hang kernel/config: hawao: usb: sim1+sim2+sd fast plugging cause phone hang arm/config: devon: add CONFIG_CAM_SENSOR_PROBE_RETRY shmem becomes bigger and bigger when launch apps driver/power: Add debug logs Hawao: Fix NFC power consumption in sleep mode. devon:charger bring up kernel:add bc12 detect channel definition Revert "(CR): drm: mipi: Disable the MIPI DSI commands 0x2E and 0x3E" devon4g: camera flash bringup FROMGIT: binder: fix test regression due to sender_euid change UPSTREAM: binder: use cred instead of task for getsecid BACKPORT: binder: use cred instead of task for selinux checks UPSTREAM: binder: use euid from cred instead of using task arm64/defconfig: add devon extra configs hawao: devconfig: enable CHACHA20 crypto configs rhode: devconfig: enable CHACHA20 crypto configs regulator: Force shutdown all regulators when system power off. arm64: defconfig: Flash compatible TZ: Distinguishes encrypted and unencrypted TZ logs interfaces. TZ: Fix build err Hawaii+OLED:remove CONFIG_QCOM_FSA4480_I2C defconfig: Disable SLAB_MERGE. arm64/config:Enable Zram writeback on hawao Enable LZ4 on Rhode4G and Hawao dts: rhode: remove CONFIG_QCOM_FSA4480_I2C mm: zram: fix build error when zram wb disabled mm : zram fix swapcached issue on Zram Writeback fs:proc:abort reclaim once process goes to foreground ip_gre: add validation for csum_start arm64/config:Enable Zram writeback on Rhode kernel:add charger termination definition rhode:kernel: add wt6670 get firmware num node kernel/config:hawao:remove FTS TP config to use module kernel/input:hawao:update to use TP module ko kernel: remove wt6670 isp macro definition for user version kernel/config:hawao: add new FTS config to fix build error input/touchscreen: add ft3519 source config input/ft3519: hawao touch driver bringup Revert "(CR) hawaii OLED: visionox ft3519 touch drvier bringup" kernel: add wt6670 macro definition to control i2c nack QC3P:add iio channel definition Rhode: define CONFIG_CAMERA_FLASH_PWM display: Modify LDO driver initialization voltage compatibility Hawao: NFC Bringup(4) - driver hawaii OLED: visionox ft3519 touch drvier bringup kernel: qc3p wt6760 isp download function kernel:add ADC_GPIO3_DIV3 adc channel display/config: Add LDO driver config into the kernel. display: Load the regulator driver directly into the kernel. kernel: use orderly_poweroff when usb plugged out tty:diag:Move tty_flip_buffer_push out of spinlock Revert "tty:revert the tty update from qcom for moto tty_diag driver" kernel:dwc3 delay extcon module registeration ANDROID: xt_quota2: set usersize in xt_match registration object ANDROID: xt_quota2: clear quota2_log message before sending ANDROID: xt_quota2: remove trailing junk which might have a digit in it arm/defconfig: add hawao extra config usb:diag:revert the f_diag update from qcom for moto tty_diag driver tty:revert the tty update from qcom for moto tty_diag driver : Enable samsung NFC driver : integrate samsung RN4V NFC driver Rhode4G: wide camera bring up kernel: add charger gki kernel: change spi gpio for i2c gpio for charger : Remove gpio3 from reserve list for rhode4g arm/defconfig: add rhode extra config Revert "(CR) guamp: emmc add ffu" Removing debug config [PATCH] qseecom: Call INIT_WORK() before flush_work() guamp: emmc add ffu Caprip: modify the actuator noise reduction work flow. Caprip: modify the actuator noise reduction work flow. APP data lost after first R upgrade Porting of (CR) replace WARN with pr_debug for IPA api MOTODESK-2239 Make NCM driver compatible with windows disable CONFIG_SLUB_DEBUG for user builds disable CONFIG_DEBUG_PANIC_ON_OOM in userdebug builds Include inlinecrypt at config.gz to fix Q->R upgrade usb: add xhci-hw-lpm-disable dt property support kernel:ram overwritten by TZ logs to cause random panics caprip: Add start/stop vibrating notification to actuator. arm64: defconfig: Actuator noise reduction. kernel: driver/vibrator: diff vol for long/short vib skip ipa assert for debug build (patch 2) skip ipa assert for debug build limit ion cache size Revert "(CR) power: Add wakeup source in battery historian logging" power: print active wakeup source before suspend. alarmtimer: add debug to identify alarmtimers charger:driver:fix non power off issue for factory kill. arm64/defconfig: capri: open nfc driver for capri arm64/defconfig: disable debug fs on user build charger:support typec high 2A current at non-turbo product arm/defconfig: enable CONFIG_DEBUG_LIST on R soc: qcom: service-locator: enlarge timeout value arm/defconfig: caprip: init kernel deconfig arm/defconfig: capri: init kernel deconfig Revert "Revert "msm: media: uapi: Redefine NV12 format with different alignment"" Revert "msm: media: uapi: Redefine NV12 format with different alignment" clear SDAM for new battery profile loading. disable DEBUG_PANIC_ON_OOM on 3G ram device driver:qg:enale QG_DEBUG_SOC. Charge: fix slab out of bounds risk charge: qc2.0 adapter charge slow charge: Handle QC2.0 charger vbus rise 12V BCL: Enable charge bcl feature arm: setup: support mem= memory limit arm: call idle notifiers in CPU idle charger:improve micro-b input current to 1.9A per HW Capri bring up kernel:distinguish type-c and microb cdp input setting disable SPLIT_RSS_COUNTING to fix zero RSS issue charger:add battery test mode support for cebu. spi: disable_depth > 0 when pm runtime get sync driver/spi: spi driver suspend changes kernel: panel_notifier: Add new panel notify event type mmc:host:sdhci:Fix host->claimer NULL pointer problem Change ION fill mark from 100M to 16M to reduce the Lost RAM arm/defconfig: cebu: init kernel deconfig : NFC VEN pin startup and shutdown sequence disable watermark boost charge:Config DCP 2A charge current tune memory configs charger:limit typec high to medium when hvdcp disabled charger:support 2A dcp charger arm64/defconfig: enable external usb camera power: reset: Use warm reset for dload mode Update kernel config of userdebug on Guam/GuamP to improve performance charger:duplicated apsd detection at pmi632 expose ssr_reason to ss_ramdump SD: print SD interrupt log charger:SW_ICL do not used at moto charger:factory image charging soc over 75% usb audio: Let the usb sound card index from 1 kernel:USB DRP connect debug accessory test charge: config: config batt NTC for bornr NA Kernel: add sys node for panel supplier gpu/drm: Create panelRegDA sysfs to expose panel's reg pwrkey: change printk level to output to console Reboot: trigger warm reset when receive hw_warmreset cmd disable CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS for sts test Revert (CR): power: smb5: Clear HDC AICL arm/defconfig: borneo: init kernel deconfig guam serials: remove kernel config for PASR Revert "mm, vmstat: hide /proc/pagetypeinfo from normal users" arm/defconfig: guamna: init kernel deconfig arm/defconfig: add 32bit debug config defconfig.mk: add arch specific debug enable psi for guam guamp Revert "defconfig: disable MEMCG for bengal 32" Fix QC rebase issue for dual role sysfs access issue ion: display ion total size in debufs node ion: dmabuf improve debugfs kernel:support huawei p10 5A cable bengal:Enable dual role usb interface smb5:Add dual role class support in smb5 usb:Add dual role class support sdcardfs: don't depend on reserved_mb to check free space sdcardfs: check the free space before creating files sdcardfs: copy inode size while getting attributes : remove nfc function for guam charger:allow APSD re-run at factory usb detection CONFIG_FPR_FPC disable for rebase fingerprint fix defconfig.mk: Don't force make defconfig gitignore: ignore dts link guamp: arm64/dtsi enable regulator_fixed_voltage power: Add wakeup source in battery historian logging arm64/defconfig: enable softlockup panic for debug : arm64/defconfig : enable NFC kernel:add OCP charger current limitation guam: add touch module support Revert "(CR): config: disable CONFIG_PANIC_ON_REFCOUNT_ERROR" arm64/defconfig: disable debug config config: disable CONFIG_PANIC_ON_REFCOUNT_ERROR arm64/configs: sm4250: Enable USB console tty: msm_geni_serial: Support the match() callback printk: Keep boot console on if enabled arm64/config: support UAS of usb storage arm64/defconfig: enable usbnet drivers usb:configfs:Set udc_name NULL if attach failed usb/dwc3: msm: Enable all Debug Logs gadget: bcdUSB version back to 2.0 when not SuperSpeed usb: configfs: synchronize the secure and udc_name state usb: configfs: skip unregister gadget in secure usb: gadget: f_mtp: Return error if count is negative usb: gadget: storage: Support READ_TOC for MacOS usb: configfs: Implement secure attribute usb: configfs: Reset the use_os_desc flag usb: mass_storage: Add support for SC_REBOOT usb: f_mtp: Handle OS descriptors only when bound config:remove unused smb1355 config guam: input add touch class support arm64/config: enable DIAG_OVER_TTY drivers: tty: add tty diag module char: diag: add write done sync function panel_notify: add api for touch state guam: defconfig: enable panel notifications video: Add panel_notifier framework drm: mipi: disable Elvss dim of HBM for MIPI DSI Add new macro MIPI_DSI_MSG_READ gpu/drm: Create sysfs to expose panel vendor infor drm: mipi: Disable the MIPI DSI commands 0x2E and 0x3E drm/dsi: Implement DCS set disp brightness 2bytes guam: input add drm support defconfig: bengal: enable pstore power: Add function to show active wakelocks power: suspend: Save snapshot of gpio, vreg when suspend PM/Suspend: Print wall time at suspend entry and exit - Do not unload prov TZ app. add system restart warm and panic mode printk: increase log buffer size to 2k qpnp-power-on: Print system timestamp on Power key event regulator: core: Add sysfs node for debug pinctrl: msm: Add sysfs node for debug watchdog_v2: export watchdog trigger pinctrl: pinctrl-msm: do not dump unallocated GPIOs of: conditional status property arm64/dt add kpanic modules kernel:moto charger/battery driver enable config:battery 10k ntc enable guamp: input add touch support input add touch support kernel:JK50 NTC 10K report wrong temp arm/defconfig: update debug option defconfig: enable CONFIG_MEMCG config defconfig: bengal: Add moto defconfigs msm-poweroff: Store restart reason power: pmic-voter: Export Interfaces Do not build moto config while building MSI kernel/config: Add Moto ext_config feature soc: qcom: kconfig opt to build moto dtbs soc: qcom: socinfo: Add sku sysfs support soc: qcom: socinfo: Add revision 16 support in socinfo structure net: qrtr: fifo: Add bounds check on tx path msm: ADSPRPC: Restrict untrusted applications from attaching to GuestOS msm: kgsl: Zap performance counters across context switches msm: kgsl: Add a sysfs node to control performance counter reads tzlog: update struct to get normal and fatal diag logs firmware: qcom: Remove garbage characters from qsee log firmware: qcom: add enlarged qsee log support firmware: qcom: encrypted tz and qsee log support serial: msm_geni_serial: Reduce stale delay added in stop_rx_sequencer clk: qcom: debugcc: Remove the gcc_camss_camnoc clocks defconfig: Enable CONFIG_ION_SYSTEM_HEAP for bengal f2fs: fix the periodic wakeups of discard thread f2fs: allow to change discard policy based on cached discard cmds msm: adsprpc: Lock list before removing node clk: qcom: gpucc: Update the post div ops for GPUCC PLL for KHAJE clk: qcom: clk-alpha-pll: Update implementation for Zonda PLL msm: kgsl: Use pid struct to find the process to reclaim mm: process_reclaim: pass pid struct instead of tgid msm: kgsl: Change vma->vm_file to shmem file mm: process_reclaim: skip target_vma net: qrtr: Excessive logging casuing boot failure Revert "msm: kgsl: Add GPUCC register dumps to A6xx GPU snapshot" defconfig: msm: Enable CONFIG_STATIC_USERMODEHELPER for bengal_32 fdt: Update CRC check for rng-seed defconfig: Enable blk-crypto-fallback to handle sw crypto request md: dm-default-key: Use system sector size for SDHCI devices msm: mink: Fix copy_to_user issue fix corrupt merge serial: msm_geni_serial: Disable irq only for HSUART usecase msm_geni_serial: Correct the DMA RX interrupt logic Conflicts: .gitignore arch/arm/include/asm/spectre.h arch/arm64/include/asm/cpufeature.h arch/arm64/include/asm/cputype.h drivers/gpu/drm/drm_mipi_dsi.c drivers/soc/qcom/socinfo.c drivers/usb/gadget/function/f_ncm.c drivers/usb/gadget/function/u_ncm.h drivers/video/fbdev/core/fbcon.c fs/file.c fs/fuse/dev.c fs/fuse/file.c fs/fuse/fuse_i.h fs/fuse/passthrough.c include/drm/drm_mipi_dsi.h include/linux/page-flags-layout.h include/linux/rmap.h include/uapi/linux/dma-buf.h include/uapi/linux/fuse.h mm/page_io.c mm/rmap.c Change-Id: I284de7199b3bfc44db2cfc89b2cd00a51bebdb6d
604 lines
21 KiB
C
604 lines
21 KiB
C
/*
|
|
* Header file for dma buffer sharing framework.
|
|
*
|
|
* Copyright(C) 2011 Linaro Limited. All rights reserved.
|
|
* Author: Sumit Semwal <sumit.semwal@ti.com>
|
|
*
|
|
* Many thanks to linaro-mm-sig list, and specially
|
|
* Arnd Bergmann <arnd@arndb.de>, Rob Clark <rob@ti.com> and
|
|
* Daniel Vetter <daniel@ffwll.ch> for their support in creation and
|
|
* refining of this idea.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef __DMA_BUF_H__
|
|
#define __DMA_BUF_H__
|
|
|
|
#include <linux/file.h>
|
|
#include <linux/err.h>
|
|
#include <linux/scatterlist.h>
|
|
#include <linux/list.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/dma-fence.h>
|
|
#include <linux/dma-buf-ref.h>
|
|
#include <linux/wait.h>
|
|
|
|
struct device;
|
|
struct dma_buf;
|
|
struct dma_buf_attachment;
|
|
|
|
/**
|
|
* struct dma_buf_ops - operations possible on struct dma_buf
|
|
* @map_atomic: [optional] maps a page from the buffer into kernel address
|
|
* space, users may not block until the subsequent unmap call.
|
|
* This callback must not sleep.
|
|
* @unmap_atomic: [optional] unmaps a atomically mapped page from the buffer.
|
|
* This Callback must not sleep.
|
|
* @map: [optional] maps a page from the buffer into kernel address space.
|
|
* @unmap: [optional] unmaps a page from the buffer.
|
|
* @vmap: [optional] creates a virtual mapping for the buffer into kernel
|
|
* address space. Same restrictions as for vmap and friends apply.
|
|
* @vunmap: [optional] unmaps a vmap from the buffer
|
|
*/
|
|
struct dma_buf_ops {
|
|
/**
|
|
* @attach:
|
|
*
|
|
* This is called from dma_buf_attach() to make sure that a given
|
|
* &dma_buf_attachment.dev can access the provided &dma_buf. Exporters
|
|
* which support buffer objects in special locations like VRAM or
|
|
* device-specific carveout areas should check whether the buffer could
|
|
* be move to system memory (or directly accessed by the provided
|
|
* device), and otherwise need to fail the attach operation.
|
|
*
|
|
* The exporter should also in general check whether the current
|
|
* allocation fullfills the DMA constraints of the new device. If this
|
|
* is not the case, and the allocation cannot be moved, it should also
|
|
* fail the attach operation.
|
|
*
|
|
* Any exporter-private housekeeping data can be stored in the
|
|
* &dma_buf_attachment.priv pointer.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success, negative error code on failure. It might return -EBUSY
|
|
* to signal that backing storage is already allocated and incompatible
|
|
* with the requirements of requesting device.
|
|
*/
|
|
int (*attach)(struct dma_buf *, struct dma_buf_attachment *);
|
|
|
|
/**
|
|
* @detach:
|
|
*
|
|
* This is called by dma_buf_detach() to release a &dma_buf_attachment.
|
|
* Provided so that exporters can clean up any housekeeping for an
|
|
* &dma_buf_attachment.
|
|
*
|
|
* This callback is optional.
|
|
*/
|
|
void (*detach)(struct dma_buf *, struct dma_buf_attachment *);
|
|
|
|
/**
|
|
* @map_dma_buf:
|
|
*
|
|
* This is called by dma_buf_map_attachment() and is used to map a
|
|
* shared &dma_buf into device address space, and it is mandatory. It
|
|
* can only be called if @attach has been called successfully. This
|
|
* essentially pins the DMA buffer into place, and it cannot be moved
|
|
* any more
|
|
*
|
|
* This call may sleep, e.g. when the backing storage first needs to be
|
|
* allocated, or moved to a location suitable for all currently attached
|
|
* devices.
|
|
*
|
|
* Note that any specific buffer attributes required for this function
|
|
* should get added to device_dma_parameters accessible via
|
|
* &device.dma_params from the &dma_buf_attachment. The @attach callback
|
|
* should also check these constraints.
|
|
*
|
|
* If this is being called for the first time, the exporter can now
|
|
* choose to scan through the list of attachments for this buffer,
|
|
* collate the requirements of the attached devices, and choose an
|
|
* appropriate backing storage for the buffer.
|
|
*
|
|
* Based on enum dma_data_direction, it might be possible to have
|
|
* multiple users accessing at the same time (for reading, maybe), or
|
|
* any other kind of sharing that the exporter might wish to make
|
|
* available to buffer-users.
|
|
*
|
|
* Returns:
|
|
*
|
|
* A &sg_table scatter list of or the backing storage of the DMA buffer,
|
|
* already mapped into the device address space of the &device attached
|
|
* with the provided &dma_buf_attachment.
|
|
*
|
|
* On failure, returns a negative error value wrapped into a pointer.
|
|
* May also return -EINTR when a signal was received while being
|
|
* blocked.
|
|
*/
|
|
struct sg_table * (*map_dma_buf)(struct dma_buf_attachment *,
|
|
enum dma_data_direction);
|
|
/**
|
|
* @unmap_dma_buf:
|
|
*
|
|
* This is called by dma_buf_unmap_attachment() and should unmap and
|
|
* release the &sg_table allocated in @map_dma_buf, and it is mandatory.
|
|
* It should also unpin the backing storage if this is the last mapping
|
|
* of the DMA buffer, it the exporter supports backing storage
|
|
* migration.
|
|
*/
|
|
void (*unmap_dma_buf)(struct dma_buf_attachment *,
|
|
struct sg_table *,
|
|
enum dma_data_direction);
|
|
|
|
/* TODO: Add try_map_dma_buf version, to return immed with -EBUSY
|
|
* if the call would block.
|
|
*/
|
|
|
|
/**
|
|
* @release:
|
|
*
|
|
* Called after the last dma_buf_put to release the &dma_buf, and
|
|
* mandatory.
|
|
*/
|
|
void (*release)(struct dma_buf *);
|
|
|
|
/**
|
|
* @begin_cpu_access:
|
|
*
|
|
* This is called from dma_buf_begin_cpu_access() and allows the
|
|
* exporter to ensure that the memory is actually available for cpu
|
|
* access - the exporter might need to allocate or swap-in and pin the
|
|
* backing storage. The exporter also needs to ensure that cpu access is
|
|
* coherent for the access direction. The direction can be used by the
|
|
* exporter to optimize the cache flushing, i.e. access with a different
|
|
* direction (read instead of write) might return stale or even bogus
|
|
* data (e.g. when the exporter needs to copy the data to temporary
|
|
* storage).
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* FIXME: This is both called through the DMA_BUF_IOCTL_SYNC command
|
|
* from userspace (where storage shouldn't be pinned to avoid handing
|
|
* de-factor mlock rights to userspace) and for the kernel-internal
|
|
* users of the various kmap interfaces, where the backing storage must
|
|
* be pinned to guarantee that the atomic kmap calls can succeed. Since
|
|
* there's no in-kernel users of the kmap interfaces yet this isn't a
|
|
* real problem.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. This can for
|
|
* example fail when the backing storage can't be allocated. Can also
|
|
* return -ERESTARTSYS or -EINTR when the call has been interrupted and
|
|
* needs to be restarted.
|
|
*/
|
|
int (*begin_cpu_access)(struct dma_buf *, enum dma_data_direction);
|
|
|
|
/**
|
|
* @begin_cpu_access_umapped:
|
|
*
|
|
* This is called as a result of the DMA_BUF_IOCTL_SYNC IOCTL being
|
|
* called with the DMA_BUF_SYNC_START and DMA_BUF_SYNC_USER_MAPPED flags
|
|
* set. It allows the exporter to ensure that the mmap(ed) portions of
|
|
* the buffer are available for cpu access - the exporter might need to
|
|
* allocate or swap-in and pin the backing storage.
|
|
* The exporter also needs to ensure that cpu access is
|
|
* coherent for the access direction. The direction can be used by the
|
|
* exporter to optimize the cache flushing, i.e. access with a different
|
|
* direction (read instead of write) might return stale or even bogus
|
|
* data (e.g. when the exporter needs to copy the data to temporary
|
|
* storage).
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. This can for
|
|
* example fail when the backing storage can't be allocated. Can also
|
|
* return -ERESTARTSYS or -EINTR when the call has been interrupted and
|
|
* needs to be restarted.
|
|
*/
|
|
int (*begin_cpu_access_umapped)(struct dma_buf *dmabuf,
|
|
enum dma_data_direction);
|
|
|
|
/**
|
|
* @begin_cpu_access_partial:
|
|
*
|
|
* This is called from dma_buf_begin_cpu_access_partial() and allows the
|
|
* exporter to ensure that the memory specified in the range is
|
|
* available for cpu access - the exporter might need to allocate or
|
|
* swap-in and pin the backing storage.
|
|
* The exporter also needs to ensure that cpu access is
|
|
* coherent for the access direction. The direction can be used by the
|
|
* exporter to optimize the cache flushing, i.e. access with a different
|
|
* direction (read instead of write) might return stale or even bogus
|
|
* data (e.g. when the exporter needs to copy the data to temporary
|
|
* storage).
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* FIXME: This is both called through the DMA_BUF_IOCTL_SYNC command
|
|
* from userspace (where storage shouldn't be pinned to avoid handing
|
|
* de-factor mlock rights to userspace) and for the kernel-internal
|
|
* users of the various kmap interfaces, where the backing storage must
|
|
* be pinned to guarantee that the atomic kmap calls can succeed. Since
|
|
* there's no in-kernel users of the kmap interfaces yet this isn't a
|
|
* real problem.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. This can for
|
|
* example fail when the backing storage can't be allocated. Can also
|
|
* return -ERESTARTSYS or -EINTR when the call has been interrupted and
|
|
* needs to be restarted.
|
|
*/
|
|
int (*begin_cpu_access_partial)(struct dma_buf *dmabuf,
|
|
enum dma_data_direction,
|
|
unsigned int offset, unsigned int len);
|
|
|
|
/**
|
|
* @end_cpu_access:
|
|
*
|
|
* This is called from dma_buf_end_cpu_access() when the importer is
|
|
* done accessing the CPU. The exporter can use this to flush caches and
|
|
* unpin any resources pinned in @begin_cpu_access.
|
|
* The result of any dma_buf kmap calls after end_cpu_access is
|
|
* undefined.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. Can return
|
|
* -ERESTARTSYS or -EINTR when the call has been interrupted and needs
|
|
* to be restarted.
|
|
*/
|
|
int (*end_cpu_access)(struct dma_buf *, enum dma_data_direction);
|
|
|
|
/**
|
|
* @end_cpu_access_umapped:
|
|
*
|
|
* This is called as result a of the DMA_BUF_IOCTL_SYNC IOCTL being
|
|
* called with the DMA_BUF_SYNC_END and DMA_BUF_SYNC_USER_MAPPED flags
|
|
* set. The exporter can use to limit cache flushing to only those parts
|
|
* of the buffer which are mmap(ed) and to unpin any resources pinned in
|
|
* @begin_cpu_access_umapped.
|
|
* The result of any dma_buf kmap calls after end_cpu_access_umapped is
|
|
* undefined.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. Can return
|
|
* -ERESTARTSYS or -EINTR when the call has been interrupted and needs
|
|
* to be restarted.
|
|
*/
|
|
int (*end_cpu_access_umapped)(struct dma_buf *dmabuf,
|
|
enum dma_data_direction);
|
|
|
|
/**
|
|
* @end_cpu_access_partial:
|
|
*
|
|
* This is called from dma_buf_end_cpu_access_partial() when the
|
|
* importer is done accessing the CPU. The exporter can use to limit
|
|
* cache flushing to only the range specefied and to unpin any
|
|
* resources pinned in @begin_cpu_access_umapped.
|
|
* The result of any dma_buf kmap calls after end_cpu_access_partial is
|
|
* undefined.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. Can return
|
|
* -ERESTARTSYS or -EINTR when the call has been interrupted and needs
|
|
* to be restarted.
|
|
*/
|
|
int (*end_cpu_access_partial)(struct dma_buf *dmabuf,
|
|
enum dma_data_direction,
|
|
unsigned int offset, unsigned int len);
|
|
|
|
void *(*map)(struct dma_buf *, unsigned long);
|
|
void (*unmap)(struct dma_buf *, unsigned long, void *);
|
|
|
|
/**
|
|
* @mmap:
|
|
*
|
|
* This callback is used by the dma_buf_mmap() function
|
|
*
|
|
* Note that the mapping needs to be incoherent, userspace is expected
|
|
* to braket CPU access using the DMA_BUF_IOCTL_SYNC interface.
|
|
*
|
|
* Because dma-buf buffers have invariant size over their lifetime, the
|
|
* dma-buf core checks whether a vma is too large and rejects such
|
|
* mappings. The exporter hence does not need to duplicate this check.
|
|
* Drivers do not need to check this themselves.
|
|
*
|
|
* If an exporter needs to manually flush caches and hence needs to fake
|
|
* coherency for mmap support, it needs to be able to zap all the ptes
|
|
* pointing at the backing storage. Now linux mm needs a struct
|
|
* address_space associated with the struct file stored in vma->vm_file
|
|
* to do that with the function unmap_mapping_range. But the dma_buf
|
|
* framework only backs every dma_buf fd with the anon_file struct file,
|
|
* i.e. all dma_bufs share the same file.
|
|
*
|
|
* Hence exporters need to setup their own file (and address_space)
|
|
* association by setting vma->vm_file and adjusting vma->vm_pgoff in
|
|
* the dma_buf mmap callback. In the specific case of a gem driver the
|
|
* exporter could use the shmem file already provided by gem (and set
|
|
* vm_pgoff = 0). Exporters can then zap ptes by unmapping the
|
|
* corresponding range of the struct address_space associated with their
|
|
* own file.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure.
|
|
*/
|
|
int (*mmap)(struct dma_buf *, struct vm_area_struct *vma);
|
|
|
|
void *(*vmap)(struct dma_buf *);
|
|
void (*vunmap)(struct dma_buf *, void *vaddr);
|
|
|
|
/**
|
|
* @get_uuid
|
|
*
|
|
* This is called by dma_buf_get_uuid to get the UUID which identifies
|
|
* the buffer to virtio devices.
|
|
*
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. On success uuid
|
|
* will be populated with the buffer's UUID.
|
|
*/
|
|
int (*get_uuid)(struct dma_buf *dmabuf, uuid_t *uuid);
|
|
|
|
/**
|
|
* @get_flags:
|
|
*
|
|
* This is called by dma_buf_get_flags and is used to get the buffer's
|
|
* flags.
|
|
* This callback is optional.
|
|
*
|
|
* Returns:
|
|
*
|
|
* 0 on success or a negative error code on failure. On success flags
|
|
* will be populated with the buffer's flags.
|
|
*/
|
|
int (*get_flags)(struct dma_buf *dmabuf, unsigned long *flags);
|
|
|
|
/**
|
|
* @import_buf_add_by_moto:
|
|
*
|
|
* This is called by gr_ion_alloc added by Motorola
|
|
*
|
|
* Returns:
|
|
* always return 0
|
|
*/
|
|
int (*import_buf_add_by_moto)(struct dma_buf *);
|
|
};
|
|
|
|
/**
|
|
* dma_buf_destructor - dma-buf destructor function
|
|
* @dmabuf: [in] pointer to dma-buf
|
|
* @dtor_data: [in] destructor data associated with this buffer
|
|
*
|
|
* The dma-buf destructor which is called when the dma-buf is freed.
|
|
*
|
|
* If the destructor returns an error the dma-buf's exporter release function
|
|
* won't be called.
|
|
*/
|
|
typedef int (*dma_buf_destructor)(struct dma_buf *dmabuf, void *dtor_data);
|
|
|
|
/**
|
|
* struct dma_buf - shared buffer object
|
|
* @size: size of the buffer
|
|
* @file: file pointer used for sharing buffers across, and for refcounting.
|
|
* @attachments: list of dma_buf_attachment that denotes all devices attached.
|
|
* @ops: dma_buf_ops associated with this buffer object.
|
|
* @lock: used internally to serialize list manipulation, attach/detach and
|
|
* vmap/unmap, and accesses to name
|
|
* @vmapping_counter: used internally to refcnt the vmaps
|
|
* @vmap_ptr: the current vmap ptr if vmapping_counter > 0
|
|
* @exp_name: name of the exporter; useful for debugging.
|
|
* @name: userspace-provided name; useful for accounting and debugging.
|
|
* @name_lock: lock to protect name.
|
|
* @ktime: time (in jiffies) at which the buffer was born
|
|
* @owner: pointer to exporter module; used for refcounting when exporter is a
|
|
* kernel module.
|
|
* @list_node: node for dma_buf accounting and debugging.
|
|
* @priv: exporter specific private data for this buffer object.
|
|
* @resv: reservation object linked to this dma-buf
|
|
* @poll: for userspace poll support
|
|
* @cb_excl: for userspace poll support
|
|
* @cb_shared: for userspace poll support
|
|
*
|
|
* This represents a shared buffer, created by calling dma_buf_export(). The
|
|
* userspace representation is a normal file descriptor, which can be created by
|
|
* calling dma_buf_fd().
|
|
*
|
|
* Shared dma buffers are reference counted using dma_buf_put() and
|
|
* get_dma_buf().
|
|
*
|
|
* Device DMA access is handled by the separate &struct dma_buf_attachment.
|
|
*/
|
|
struct dma_buf {
|
|
size_t size;
|
|
struct file *file;
|
|
struct list_head attachments;
|
|
const struct dma_buf_ops *ops;
|
|
struct mutex lock;
|
|
unsigned vmapping_counter;
|
|
void *vmap_ptr;
|
|
const char *exp_name;
|
|
const char *name;
|
|
spinlock_t name_lock;
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
ktime_t ktime;
|
|
#endif
|
|
struct module *owner;
|
|
struct list_head list_node;
|
|
void *priv;
|
|
struct reservation_object *resv;
|
|
|
|
/* poll support */
|
|
wait_queue_head_t poll;
|
|
|
|
struct dma_buf_poll_cb_t {
|
|
struct dma_fence_cb cb;
|
|
wait_queue_head_t *poll;
|
|
|
|
__poll_t active;
|
|
} cb_excl, cb_shared;
|
|
|
|
struct list_head refs;
|
|
dma_buf_destructor dtor;
|
|
void *dtor_data;
|
|
atomic_t dent_count;
|
|
};
|
|
|
|
/**
|
|
* struct dma_buf_attachment - holds device-buffer attachment data
|
|
* @dmabuf: buffer for this attachment.
|
|
* @dev: device attached to the buffer.
|
|
* @node: list of dma_buf_attachment.
|
|
* @priv: exporter specific attachment data.
|
|
* @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer
|
|
* through dma_buf_map_attachment.
|
|
*
|
|
* This structure holds the attachment information between the dma_buf buffer
|
|
* and its user device(s). The list contains one attachment struct per device
|
|
* attached to the buffer.
|
|
*
|
|
* An attachment is created by calling dma_buf_attach(), and released again by
|
|
* calling dma_buf_detach(). The DMA mapping itself needed to initiate a
|
|
* transfer is created by dma_buf_map_attachment() and freed again by calling
|
|
* dma_buf_unmap_attachment().
|
|
*/
|
|
struct dma_buf_attachment {
|
|
struct dma_buf *dmabuf;
|
|
struct device *dev;
|
|
struct list_head node;
|
|
void *priv;
|
|
unsigned long dma_map_attrs;
|
|
};
|
|
|
|
/**
|
|
* struct dma_buf_export_info - holds information needed to export a dma_buf
|
|
* @exp_name: name of the exporter - useful for debugging.
|
|
* @owner: pointer to exporter module - used for refcounting kernel module
|
|
* @ops: Attach allocator-defined dma buf ops to the new buffer
|
|
* @size: Size of the buffer
|
|
* @flags: mode flags for the file
|
|
* @resv: reservation-object, NULL to allocate default one
|
|
* @priv: Attach private data of allocator to this buffer
|
|
*
|
|
* This structure holds the information required to export the buffer. Used
|
|
* with dma_buf_export() only.
|
|
*/
|
|
struct dma_buf_export_info {
|
|
const char *exp_name;
|
|
struct module *owner;
|
|
const struct dma_buf_ops *ops;
|
|
size_t size;
|
|
int flags;
|
|
struct reservation_object *resv;
|
|
void *priv;
|
|
};
|
|
|
|
/**
|
|
* DEFINE_DMA_BUF_EXPORT_INFO - helper macro for exporters
|
|
* @name: export-info name
|
|
*
|
|
* DEFINE_DMA_BUF_EXPORT_INFO macro defines the &struct dma_buf_export_info,
|
|
* zeroes it out and pre-populates exp_name in it.
|
|
*/
|
|
#define DEFINE_DMA_BUF_EXPORT_INFO(name) \
|
|
struct dma_buf_export_info name = { .exp_name = KBUILD_MODNAME, \
|
|
.owner = THIS_MODULE }
|
|
|
|
/**
|
|
* get_dma_buf - convenience wrapper for get_file.
|
|
* @dmabuf: [in] pointer to dma_buf
|
|
*
|
|
* Increments the reference count on the dma-buf, needed in case of drivers
|
|
* that either need to create additional references to the dmabuf on the
|
|
* kernel side. For example, an exporter that needs to keep a dmabuf ptr
|
|
* so that subsequent exports don't create a new dmabuf.
|
|
*/
|
|
static inline void get_dma_buf(struct dma_buf *dmabuf)
|
|
{
|
|
get_file(dmabuf->file);
|
|
dma_buf_ref_mod(dmabuf, 1);
|
|
}
|
|
|
|
struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
|
|
struct device *dev);
|
|
void dma_buf_detach(struct dma_buf *dmabuf,
|
|
struct dma_buf_attachment *dmabuf_attach);
|
|
|
|
struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info);
|
|
|
|
int dma_buf_fd(struct dma_buf *dmabuf, int flags);
|
|
struct dma_buf *dma_buf_get(int fd);
|
|
void dma_buf_put(struct dma_buf *dmabuf);
|
|
|
|
struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *,
|
|
enum dma_data_direction);
|
|
void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *,
|
|
enum dma_data_direction);
|
|
int dma_buf_begin_cpu_access(struct dma_buf *dma_buf,
|
|
enum dma_data_direction dir);
|
|
int dma_buf_begin_cpu_access_partial(struct dma_buf *dma_buf,
|
|
enum dma_data_direction dir,
|
|
unsigned int offset,
|
|
unsigned int len);
|
|
int dma_buf_end_cpu_access(struct dma_buf *dma_buf,
|
|
enum dma_data_direction dir);
|
|
int dma_buf_end_cpu_access_partial(struct dma_buf *dma_buf,
|
|
enum dma_data_direction dir,
|
|
unsigned int offset, unsigned int len);
|
|
void *dma_buf_kmap(struct dma_buf *, unsigned long);
|
|
void dma_buf_kunmap(struct dma_buf *, unsigned long, void *);
|
|
|
|
int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *,
|
|
unsigned long);
|
|
void *dma_buf_vmap(struct dma_buf *);
|
|
void dma_buf_vunmap(struct dma_buf *, void *vaddr);
|
|
int dma_buf_get_flags(struct dma_buf *dma_buf, unsigned long *flags);
|
|
int dma_buf_get_uuid(struct dma_buf *dma_buf, uuid_t *uuid);
|
|
|
|
/**
|
|
* dma_buf_set_destructor - set the dma-buf's destructor
|
|
* @dmabuf: [in] pointer to dma-buf
|
|
* @dma_buf_destructor [in] the destructor function
|
|
* @dtor_data: [in] destructor data associated with this buffer
|
|
*/
|
|
static inline void dma_buf_set_destructor(struct dma_buf *dmabuf,
|
|
dma_buf_destructor dtor,
|
|
void *dtor_data)
|
|
{
|
|
dmabuf->dtor = dtor;
|
|
dmabuf->dtor_data = dtor_data;
|
|
}
|
|
|
|
#endif /* __DMA_BUF_H__ */
|