1 /*        $NetBSD: drm_agpsupport.h,v 1.10 2022/07/19 22:24:34 riastradh Exp $  */
2 
3 /* SPDX-License-Identifier: GPL-2.0 */
4 #ifndef _DRM_AGPSUPPORT_H_
5 #define _DRM_AGPSUPPORT_H_
6 
7 #include <linux/agp_backend.h>
8 #include <linux/kernel.h>
9 #include <linux/list.h>
10 #include <linux/mm.h>
11 #include <linux/mutex.h>
12 #include <linux/types.h>
13 #include <uapi/drm/drm.h>
14 
15 #ifdef __NetBSD__
16 #include <drm/drm_agp_netbsd.h>
17 #endif
18 
19 struct drm_device;
20 struct drm_file;
21 
22 struct drm_agp_hooks {
23           void      (*agph_flush)(void);
24 
25           struct drm_agp_head *
26                     (*agph_init)(struct drm_device *);
27           void      (*agph_clear)(struct drm_device *);
28           int       (*agph_acquire)(struct drm_device *);
29           int       (*agph_release)(struct drm_device *);
30           int       (*agph_enable)(struct drm_device *, struct drm_agp_mode);
31           int       (*agph_info)(struct drm_device *, struct drm_agp_info *);
32           int       (*agph_alloc)(struct drm_device *, struct drm_agp_buffer *);
33           int       (*agph_free)(struct drm_device *, struct drm_agp_buffer *);
34           int       (*agph_bind)(struct drm_device *, struct drm_agp_binding *);
35           int       (*agph_unbind)(struct drm_device *, struct drm_agp_binding *);
36 
37           int       (*agph_acquire_ioctl)(struct drm_device *, void *,
38                         struct drm_file *);
39           int       (*agph_release_ioctl)(struct drm_device *, void *,
40                         struct drm_file *);
41           int       (*agph_enable_ioctl)(struct drm_device *, void *,
42                         struct drm_file *);
43           int       (*agph_info_ioctl)(struct drm_device *, void *,
44                         struct drm_file *);
45           int       (*agph_alloc_ioctl)(struct drm_device *, void *,
46                         struct drm_file *);
47           int       (*agph_free_ioctl)(struct drm_device *, void *,
48                         struct drm_file *);
49           int       (*agph_bind_ioctl)(struct drm_device *, void *,
50                         struct drm_file *);
51           int       (*agph_unbind_ioctl)(struct drm_device *, void *,
52                         struct drm_file *);
53 };
54 
55 struct drm_agp_head {
56           const struct drm_agp_hooks *hooks;
57           struct agp_kern_info agp_info;
58           struct list_head memory;
59           unsigned long mode;
60           struct agp_bridge_data *bridge;
61           int enabled;
62           int acquired;
63           unsigned long base;
64           int agp_mtrr;
65           int cant_use_aperture;
66           unsigned long page_mask;
67 };
68 
69 #if IS_ENABLED(CONFIG_AGP)
70 
71 #ifdef __NetBSD__
72 static inline void drm_free_agp(struct agp_bridge_data *, struct agp_memory *, int);
73 static inline int drm_bind_agp(struct agp_bridge_data *, struct agp_memory *, unsigned);
74 static inline int drm_unbind_agp(struct agp_bridge_data *, struct agp_memory *);
75 #else
76 void drm_free_agp(struct agp_memory * handle, int pages);
77 int drm_bind_agp(struct agp_memory * handle, unsigned int start);
78 int drm_unbind_agp(struct agp_memory * handle);
79 #endif
80 
81 struct drm_agp_head *drm_agp_init(struct drm_device *dev);
82 void drm_legacy_agp_clear(struct drm_device *dev);
83 int drm_agp_acquire(struct drm_device *dev);
84 int drm_agp_acquire_ioctl(struct drm_device *dev, void *data,
85                                 struct drm_file *file_priv);
86 int drm_agp_release(struct drm_device *dev);
87 int drm_agp_release_ioctl(struct drm_device *dev, void *data,
88                                 struct drm_file *file_priv);
89 int drm_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
90 int drm_agp_enable_ioctl(struct drm_device *dev, void *data,
91                                struct drm_file *file_priv);
92 int drm_agp_info(struct drm_device *dev, struct drm_agp_info *info);
93 int drm_agp_info_ioctl(struct drm_device *dev, void *data,
94                            struct drm_file *file_priv);
95 int drm_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
96 int drm_agp_alloc_ioctl(struct drm_device *dev, void *data,
97                               struct drm_file *file_priv);
98 int drm_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
99 int drm_agp_free_ioctl(struct drm_device *dev, void *data,
100                            struct drm_file *file_priv);
101 int drm_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
102 int drm_agp_unbind_ioctl(struct drm_device *dev, void *data,
103                                struct drm_file *file_priv);
104 int drm_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
105 int drm_agp_bind_ioctl(struct drm_device *dev, void *data,
106                            struct drm_file *file_priv);
107 
108 #ifdef __NetBSD__
109 void drm_agp_flush(void);
110 void drm_agp_fini(struct drm_device *);
111 int drm_agp_register(const struct drm_agp_hooks *);
112 int drm_agp_deregister(const struct drm_agp_hooks *);
113 void drm_agp_hooks_init(void);
114 void drm_agp_hooks_fini(void);
115 int drmkms_agp_guarantee_initialized(void);
116 #endif
117 
118 #else /* CONFIG_AGP */
119 
120 #if !defined(__NetBSD__)
121 
drm_free_agp(struct agp_memory * handle,int pages)122 static inline void drm_free_agp(struct agp_memory * handle, int pages)
123 {
124 }
125 
drm_bind_agp(struct agp_memory * handle,unsigned int start)126 static inline int drm_bind_agp(struct agp_memory * handle, unsigned int start)
127 {
128           return -ENODEV;
129 }
130 
drm_unbind_agp(struct agp_memory * handle)131 static inline int drm_unbind_agp(struct agp_memory * handle)
132 {
133           return -ENODEV;
134 }
135 #endif
136 
drm_agp_init(struct drm_device * dev)137 static inline struct drm_agp_head *drm_agp_init(struct drm_device *dev)
138 {
139           return NULL;
140 }
141 
drm_legacy_agp_clear(struct drm_device * dev)142 static inline void drm_legacy_agp_clear(struct drm_device *dev)
143 {
144 }
145 
drm_agp_acquire(struct drm_device * dev)146 static inline int drm_agp_acquire(struct drm_device *dev)
147 {
148           return -ENODEV;
149 }
150 
drm_agp_release(struct drm_device * dev)151 static inline int drm_agp_release(struct drm_device *dev)
152 {
153           return -ENODEV;
154 }
155 
drm_agp_enable(struct drm_device * dev,struct drm_agp_mode mode)156 static inline int drm_agp_enable(struct drm_device *dev,
157                                          struct drm_agp_mode mode)
158 {
159           return -ENODEV;
160 }
161 
drm_agp_info(struct drm_device * dev,struct drm_agp_info * info)162 static inline int drm_agp_info(struct drm_device *dev,
163                                      struct drm_agp_info *info)
164 {
165           return -ENODEV;
166 }
167 
drm_agp_alloc(struct drm_device * dev,struct drm_agp_buffer * request)168 static inline int drm_agp_alloc(struct drm_device *dev,
169                                         struct drm_agp_buffer *request)
170 {
171           return -ENODEV;
172 }
173 
drm_agp_free(struct drm_device * dev,struct drm_agp_buffer * request)174 static inline int drm_agp_free(struct drm_device *dev,
175                                      struct drm_agp_buffer *request)
176 {
177           return -ENODEV;
178 }
179 
drm_agp_unbind(struct drm_device * dev,struct drm_agp_binding * request)180 static inline int drm_agp_unbind(struct drm_device *dev,
181                                          struct drm_agp_binding *request)
182 {
183           return -ENODEV;
184 }
185 
drm_agp_bind(struct drm_device * dev,struct drm_agp_binding * request)186 static inline int drm_agp_bind(struct drm_device *dev,
187                                      struct drm_agp_binding *request)
188 {
189           return -ENODEV;
190 }
191 
192 #endif /* CONFIG_AGP */
193 
194 #endif /* _DRM_AGPSUPPORT_H_ */
195