at v4.3-rc2 135 lines 4.8 kB view raw
1/* 2 * Copyright 2015 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * 23 */ 24#ifndef _CGS_LINUX_H 25#define _CGS_LINUX_H 26 27#include "cgs_common.h" 28 29/** 30 * cgs_import_gpu_mem() - Import dmabuf handle 31 * @cgs_device: opaque device handle 32 * @dmabuf_fd: DMABuf file descriptor 33 * @handle: memory handle (output) 34 * 35 * Must be called in the process context that dmabuf_fd belongs to. 36 * 37 * Return: 0 on success, -errno otherwise 38 */ 39typedef int (*cgs_import_gpu_mem_t)(void *cgs_device, int dmabuf_fd, 40 cgs_handle_t *handle); 41 42/** 43 * cgs_irq_source_set_func() - Callback for enabling/disabling interrupt sources 44 * @private_data: private data provided to cgs_add_irq_source 45 * @src_id: interrupt source ID 46 * @type: interrupt type 47 * @enabled: 0 = disable source, non-0 = enable source 48 * 49 * Return: 0 on success, -errno otherwise 50 */ 51typedef int (*cgs_irq_source_set_func_t)(void *private_data, 52 unsigned src_id, unsigned type, 53 int enabled); 54 55/** 56 * cgs_irq_handler_func() - Interrupt handler callback 57 * @private_data: private data provided to cgs_add_irq_source 58 * @src_id: interrupt source ID 59 * @iv_entry: pointer to raw ih ring entry 60 * 61 * This callback runs in interrupt context. 62 * 63 * Return: 0 on success, -errno otherwise 64 */ 65typedef int (*cgs_irq_handler_func_t)(void *private_data, 66 unsigned src_id, const uint32_t *iv_entry); 67 68/** 69 * cgs_add_irq_source() - Add an IRQ source 70 * @cgs_device: opaque device handle 71 * @src_id: interrupt source ID 72 * @num_types: number of interrupt types that can be independently enabled 73 * @set: callback function to enable/disable an interrupt type 74 * @handler: interrupt handler callback 75 * @private_data: private data to pass to callback functions 76 * 77 * The same IRQ source can be added only once. Adding an IRQ source 78 * indicates ownership of that IRQ source and all its IRQ types. 79 * 80 * Return: 0 on success, -errno otherwise 81 */ 82typedef int (*cgs_add_irq_source_t)(void *cgs_device, unsigned src_id, 83 unsigned num_types, 84 cgs_irq_source_set_func_t set, 85 cgs_irq_handler_func_t handler, 86 void *private_data); 87 88/** 89 * cgs_irq_get() - Request enabling an IRQ source and type 90 * @cgs_device: opaque device handle 91 * @src_id: interrupt source ID 92 * @type: interrupt type 93 * 94 * cgs_irq_get and cgs_irq_put calls must be balanced. They count 95 * "references" to IRQ sources. 96 * 97 * Return: 0 on success, -errno otherwise 98 */ 99typedef int (*cgs_irq_get_t)(void *cgs_device, unsigned src_id, unsigned type); 100 101/** 102 * cgs_irq_put() - Indicate IRQ source is no longer needed 103 * @cgs_device: opaque device handle 104 * @src_id: interrupt source ID 105 * @type: interrupt type 106 * 107 * cgs_irq_get and cgs_irq_put calls must be balanced. They count 108 * "references" to IRQ sources. Even after cgs_irq_put is called, the 109 * IRQ handler may still be called if there are more refecences to 110 * the IRQ source. 111 * 112 * Return: 0 on success, -errno otherwise 113 */ 114typedef int (*cgs_irq_put_t)(void *cgs_device, unsigned src_id, unsigned type); 115 116struct cgs_os_ops { 117 cgs_import_gpu_mem_t import_gpu_mem; 118 119 /* IRQ handling */ 120 cgs_add_irq_source_t add_irq_source; 121 cgs_irq_get_t irq_get; 122 cgs_irq_put_t irq_put; 123}; 124 125#define cgs_import_gpu_mem(dev,dmabuf_fd,handle) \ 126 CGS_OS_CALL(import_gpu_mem,dev,dmabuf_fd,handle) 127#define cgs_add_irq_source(dev,src_id,num_types,set,handler,private_data) \ 128 CGS_OS_CALL(add_irq_source,dev,src_id,num_types,set,handler, \ 129 private_data) 130#define cgs_irq_get(dev,src_id,type) \ 131 CGS_OS_CALL(irq_get,dev,src_id,type) 132#define cgs_irq_put(dev,src_id,type) \ 133 CGS_OS_CALL(irq_put,dev,src_id,type) 134 135#endif /* _CGS_LINUX_H */