GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / gpu / drm / amd / include / cgs_linux.h
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_irq_source_set_func() - Callback for enabling/disabling interrupt sources
31  * @private_data:  private data provided to cgs_add_irq_source
32  * @src_id:        interrupt source ID
33  * @type:          interrupt type
34  * @enabled:       0 = disable source, non-0 = enable source
35  *
36  * Return:  0 on success, -errno otherwise
37  */
38 typedef int (*cgs_irq_source_set_func_t)(void *private_data,
39                                          unsigned src_id, unsigned type,
40                                          int enabled);
41
42 /**
43  * cgs_irq_handler_func() - Interrupt handler callback
44  * @private_data:  private data provided to cgs_add_irq_source
45  * @src_id:        interrupt source ID
46  * @iv_entry:      pointer to raw ih ring entry
47  *
48  * This callback runs in interrupt context.
49  *
50  * Return:  0 on success, -errno otherwise
51  */
52 typedef int (*cgs_irq_handler_func_t)(void *private_data,
53                                       unsigned src_id, const uint32_t *iv_entry);
54
55 /**
56  * cgs_add_irq_source() - Add an IRQ source
57  * @cgs_device:    opaque device handle
58  * @src_id:        interrupt source ID
59  * @num_types:     number of interrupt types that can be independently enabled
60  * @set:           callback function to enable/disable an interrupt type
61  * @handler:       interrupt handler callback
62  * @private_data:  private data to pass to callback functions
63  *
64  * The same IRQ source can be added only once. Adding an IRQ source
65  * indicates ownership of that IRQ source and all its IRQ types.
66  *
67  * Return:  0 on success, -errno otherwise
68  */
69 typedef int (*cgs_add_irq_source_t)(void *cgs_device, unsigned client_id,
70                                     unsigned src_id,
71                                     unsigned num_types,
72                                     cgs_irq_source_set_func_t set,
73                                     cgs_irq_handler_func_t handler,
74                                     void *private_data);
75
76 /**
77  * cgs_irq_get() - Request enabling an IRQ source and type
78  * @cgs_device:  opaque device handle
79  * @src_id:      interrupt source ID
80  * @type:        interrupt type
81  *
82  * cgs_irq_get and cgs_irq_put calls must be balanced. They count
83  * "references" to IRQ sources.
84  *
85  * Return:  0 on success, -errno otherwise
86  */
87 typedef int (*cgs_irq_get_t)(void *cgs_device, unsigned client_id, unsigned src_id, unsigned type);
88
89 /**
90  * cgs_irq_put() - Indicate IRQ source is no longer needed
91  * @cgs_device:  opaque device handle
92  * @src_id:      interrupt source ID
93  * @type:        interrupt type
94  *
95  * cgs_irq_get and cgs_irq_put calls must be balanced. They count
96  * "references" to IRQ sources. Even after cgs_irq_put is called, the
97  * IRQ handler may still be called if there are more refecences to
98  * the IRQ source.
99  *
100  * Return:  0 on success, -errno otherwise
101  */
102 typedef int (*cgs_irq_put_t)(void *cgs_device, unsigned client_id, unsigned src_id, unsigned type);
103
104 struct cgs_os_ops {
105         /* IRQ handling */
106         cgs_add_irq_source_t add_irq_source;
107         cgs_irq_get_t irq_get;
108         cgs_irq_put_t irq_put;
109 };
110
111 #define cgs_add_irq_source(dev,client_id,src_id,num_types,set,handler,private_data) \
112         CGS_OS_CALL(add_irq_source,dev,client_id,src_id,num_types,set,handler, \
113                     private_data)
114 #define cgs_irq_get(dev,client_id,src_id,type)  \
115         CGS_OS_CALL(irq_get,dev,client_id,src_id,type)
116 #define cgs_irq_put(dev,client_id,src_id,type)  \
117         CGS_OS_CALL(irq_put,dev,client_id,src_id,type)
118
119 #endif /* _CGS_LINUX_H */